Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2babf81
added common code
kartik-579 Jan 16, 2025
dbfa22f
added license
kartik-579 Jan 16, 2025
f479613
Merge branch 'main' into app-gitopsconfig-migrate
prkhrkat Jan 16, 2025
d72c7e8
minor changes
kartik-579 Jan 22, 2025
56456a7
oss/ent change
kartik-579 Jan 22, 2025
8b726d1
oss/ent change
kartik-579 Jan 22, 2025
606164e
Merge branch 'main' into app-gitopsconfig-migrate
kartik-579 Jan 22, 2025
084df2b
oss/ent change
kartik-579 Jan 22, 2025
627beeb
oss/ent change
kartik-579 Jan 22, 2025
cc36d74
oss/ent change
kartik-579 Jan 22, 2025
78f1814
moved fetchAllEnv to common lib
kartik-579 Jan 22, 2025
d01a4f2
updated common lib hash
kartik-579 Jan 22, 2025
01c7d03
Merge pull request #6317 from devtron-labs/env-change-common-lib
kartik-579 Jan 22, 2025
2512e9e
chore: Skipping multiarch check for casbin and scoop image (#6304)
YashasviDevtron Jan 23, 2025
962dbfe
misc: deployment, reference and statefulset updated versions (#6284)
SATYAsasini Jan 23, 2025
1fe5b1e
Merge branch 'main' into app-gitopsconfig-migrate
kartik-579 Jan 23, 2025
69390cc
Merge pull request #6297 from devtron-labs/app-gitopsconfig-migrate
kartik-579 Jan 23, 2025
f9a24c5
Merge branch 'main' into scoped-var-appEnv-oss-ent
kartik-579 Jan 23, 2025
018e7cb
Merge pull request #6319 from devtron-labs/scoped-var-appEnv-oss-ent
kartik-579 Jan 23, 2025
db327ea
fix for appDetail data rest
kartik-579 Jan 24, 2025
564fe99
Merge pull request #6322 from devtron-labs/fix-appDetail
vikramdevtron Jan 24, 2025
0e2d87c
Merge branch 'main' into main-develop-sync-27jan-1
kartik-579 Jan 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/multiarch_new.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ jobs:
local image="$1"
local image_ref=$(echo $image | sed 's/:.*//')

# skipping the check for 'inception', 'postgres' , 'postgres_exporter' and 'workflow-controller' images
if [[ "$image_ref" == "inception" || "$image_ref" == "postgres" || "$image_ref" == "postgres_exporter" || "$image_ref" == "workflow-controller" ]]; then
# skipping the check for 'inception', 'postgres' , 'postgres_exporter', 'workflow-controller', 'casbin' and 'scoop' images
if [[ "$image_ref" == "inception" || "$image_ref" == "postgres" || "$image_ref" == "postgres_exporter" || "$image_ref" == "workflow-controller" || "$image_ref" == "casbin" || "$image_ref" == "scoop" ]]; then
return
fi

Expand Down
2 changes: 1 addition & 1 deletion api/restHandler/app/appList/AppListingRestHandler_ent.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ func (handler AppListingRestHandlerImpl) GetAllAppEnvsFromResourceNames(w http.R
}

func (handler AppListingRestHandlerImpl) updateApprovalConfigDataInAppDetailResp(appDetail AppView.AppDetailContainer, appId, envId int) (AppView.AppDetailContainer, error) {
return AppView.AppDetailContainer{}, nil
return appDetail, nil
}
205 changes: 2 additions & 203 deletions fetchAllEnv/fetchAllEnv.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,210 +17,9 @@
package main

import (
"encoding/json"
"errors"
"go/ast"
"go/parser"
"go/token"
"log"
"os"
"path/filepath"
"reflect"
"sort"
"strings"
"text/template"
"github.com/devtron-labs/common-lib/fetchAllEnv"
)

type EnvField struct {
Env string
EnvType string
EnvValue string
EnvDescription string
Example string
Deprecated string
}

type CategoryField struct {
Category string
Fields []EnvField
}

const (
categoryCommentStructPrefix = "CATEGORY="
defaultCategory = "DEVTRON"
deprecatedDefaultValue = "false"

envFieldTypeTag = "env"
envDefaultFieldTypeTag = "envDefault"
envDescriptionFieldTypeTag = "description"
envPossibleValuesFieldTypeTag = "example"
envDeprecatedFieldTypeTag = "deprecated"
MARKDOWN_FILENAME = "env_gen.md"
MARKDOWN_JSON_FILENAME = "env_gen.json"
)

const MarkdownTemplate = `
{{range . }}
## {{ .Category }} Related Environment Variables
| Key | Type | Default Value | Description | Example | Deprecated |
|-------|----------|-------------------|-------------------|-----------------------|------------------|
{{range .Fields }} | {{ .Env }} | {{ .EnvType }} |{{ .EnvValue }} | {{ .EnvDescription }} | {{ .Example }} | {{ .Deprecated }} |
{{end}}
{{end}}`

func main() {
WalkThroughProject()
return
}

func WalkThroughProject() {
categoryFieldsMap := make(map[string][]EnvField)
uniqueKeys := make(map[string]bool)
err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() && strings.HasSuffix(path, ".go") {
err = processGoFile(path, categoryFieldsMap, uniqueKeys)
if err != nil {
log.Println("error in processing go file", err)
return err
}
}
return nil
})
if err != nil {
return
}
writeToFile(categoryFieldsMap)
}

func processGoFile(filePath string, categoryFieldsMap map[string][]EnvField, uniqueKeys map[string]bool) error {
fset := token.NewFileSet()
node, err := parser.ParseFile(fset, filePath, nil, parser.ParseComments)
if err != nil {
log.Println("error parsing file:", err)
return err
}
ast.Inspect(node, func(n ast.Node) bool {
if genDecl, ok := n.(*ast.GenDecl); ok {
// checking if type declaration, one of [func, map, struct, array, channel, interface]
if genDecl.Tok == token.TYPE {
for _, spec := range genDecl.Specs {
if typeSpec, ok := spec.(*ast.TypeSpec); ok {
// only checking struct type declarations
if structType, ok2 := typeSpec.Type.(*ast.StructType); ok2 {
allFields := make([]EnvField, 0, len(structType.Fields.List))
for _, field := range structType.Fields.List {
if field.Tag != nil {
envField := getEnvKeyAndValue(field)
envKey := envField.Env
if len(envKey) == 0 || uniqueKeys[envKey] {
continue
}
allFields = append(allFields, envField)
uniqueKeys[envKey] = true
}
}
if len(allFields) > 0 {
category := getCategoryForAStruct(genDecl)
categoryFieldsMap[category] = append(categoryFieldsMap[category], allFields...)
}
}
}
}
}
}
return true
})
return nil
}

func getEnvKeyAndValue(field *ast.Field) EnvField {
tag := reflect.StructTag(strings.Trim(field.Tag.Value, "`")) // remove surrounding backticks

envKey := addReadmeTableDelimiterEscapeChar(tag.Get(envFieldTypeTag))
envValue := addReadmeTableDelimiterEscapeChar(tag.Get(envDefaultFieldTypeTag))
envDescription := addReadmeTableDelimiterEscapeChar(tag.Get(envDescriptionFieldTypeTag))
envPossibleValues := addReadmeTableDelimiterEscapeChar(tag.Get(envPossibleValuesFieldTypeTag))
envDeprecated := addReadmeTableDelimiterEscapeChar(tag.Get(envDeprecatedFieldTypeTag))
// check if there exist any value provided in env for this field
if value, ok := os.LookupEnv(envKey); ok {
envValue = value
}
env := EnvField{
Env: envKey,
EnvValue: envValue,
EnvDescription: envDescription,
Example: envPossibleValues,
Deprecated: envDeprecated,
}
if indent, ok := field.Type.(*ast.Ident); ok && indent != nil {
env.EnvType = indent.Name
}
if len(envDeprecated) == 0 {
env.Deprecated = deprecatedDefaultValue
}
return env
}

func getCategoryForAStruct(genDecl *ast.GenDecl) string {
category := defaultCategory
if genDecl.Doc != nil {
commentTexts := strings.Split(genDecl.Doc.Text(), "\n")
for _, comment := range commentTexts {
commentText := strings.TrimPrefix(strings.ReplaceAll(comment, " ", ""), "//") // this can happen if comment group is in /* */
if strings.HasPrefix(commentText, categoryCommentStructPrefix) {
categories := strings.Split(strings.TrimPrefix(commentText, categoryCommentStructPrefix), ",")
if len(categories) > 0 && len(categories[0]) > 0 { //only supporting one category as of now
category = categories[0] //overriding category
break
}
}
}
}
return category
}

func addReadmeTableDelimiterEscapeChar(s string) string {
return strings.ReplaceAll(s, "|", `\|`)
}

func writeToFile(categoryFieldsMap map[string][]EnvField) {
cfs := make([]CategoryField, 0, len(categoryFieldsMap))
for category, allFields := range categoryFieldsMap {
sort.Slice(allFields, func(i, j int) bool {
return allFields[i].Env < allFields[j].Env
})

cfs = append(cfs, CategoryField{
Category: category,
Fields: allFields,
})
}
sort.Slice(cfs, func(i, j int) bool {
return cfs[i].Category < cfs[j].Category
})
file, err := os.Create(MARKDOWN_FILENAME)
if err != nil && !errors.Is(err, os.ErrExist) {
panic(err)
}
defer file.Close()
tmpl, err := template.New("markdown").Parse(MarkdownTemplate)
if err != nil {
panic(err)
}
err = tmpl.Execute(file, cfs)
if err != nil {
panic(err)
}
cfsMarshaled, err := json.Marshal(cfs)
if err != nil {
log.Println("error marshalling category fields:", err)
panic(err)
}
err = os.WriteFile(MARKDOWN_JSON_FILENAME, cfsMarshaled, 0644)
if err != nil {
panic(err)
}
fetchAllEnv.FetchEnvAndWriteToFile()
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ require gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect

replace (
github.com/argoproj/argo-workflows/v3 v3.5.10 => github.com/devtron-labs/argo-workflows/v3 v3.5.13
github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250127090829-f050f9c05226
github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250127090829-f050f9c05226
github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250127104410-85d6bfe0b45f
github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250127104410-85d6bfe0b45f
github.com/go-check/check => github.com/go-check/check v0.0.0-20180628173108-788fd7840127
github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.5.5
k8s.io/api => k8s.io/api v0.29.7
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -792,10 +792,10 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq
github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
github.com/devtron-labs/argo-workflows/v3 v3.5.13 h1:3pINq0gXOSeTw2z/vYe+j80lRpSN5Rp/8mfQORh8SmU=
github.com/devtron-labs/argo-workflows/v3 v3.5.13/go.mod h1:/vqxcovDPT4zqr4DjR5v7CF8ggpY1l3TSa2CIG3jmjA=
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250127090829-f050f9c05226 h1:67Im8ME0J2Ukd8xbKuR+0rzT3oO0Obcd58keDb80C3I=
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250127090829-f050f9c05226/go.mod h1:5lv4Wfj5ERhhvDGXe2IeES6qxjvUVCcohaRwKnWBMNo=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250127090829-f050f9c05226 h1:yYHCt3F0xLW0VlBGXqAsXLJElLcnEJCUkpQJxmgkTb4=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250127090829-f050f9c05226/go.mod h1:1QJJLpgJSkb5Jm9xPeKAk+kXb0QgBOOOgJj0cgYhAVA=
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250127104410-85d6bfe0b45f h1:8nYP02cYX/9e3H8YfBV4b8hP4WwbGY/dUMNu+N9cH1Q=
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250127104410-85d6bfe0b45f/go.mod h1:5lv4Wfj5ERhhvDGXe2IeES6qxjvUVCcohaRwKnWBMNo=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250127104410-85d6bfe0b45f h1:4wUbt+83DmpZFqYS69CJxNtBpSuCb58UwqOrWsZG82s=
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250127104410-85d6bfe0b45f/go.mod h1:1QJJLpgJSkb5Jm9xPeKAk+kXb0QgBOOOgJj0cgYhAVA=
github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU=
github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y=
github.com/devtron-labs/protos v0.0.3-0.20240802105333-92ee9bb85d80 h1:xwbTeijNTf4/j1v+tSfwVqwLVnReas/NqEKeQHvSTys=
Expand Down
45 changes: 38 additions & 7 deletions internal/sql/repository/deploymentConfig/repository.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (c) 2020-2024. Devtron Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package deploymentConfig

import (
Expand Down Expand Up @@ -29,7 +45,7 @@ type DeploymentConfig struct {
ConfigType string `sql:"config_type"`
RepoUrl string `sql:"repo_url"`
RepoName string `sql:"repo_name"`
ReleaseMode string `json:"release_mode"`
ReleaseMode string `sql:"release_mode"`
Active bool `sql:"active,notnull"`
sql.AuditLog
}
Expand All @@ -46,6 +62,7 @@ type Repository interface {
GetAppAndEnvLevelConfigsInBulk(appIdToEnvIdsMap map[int][]int) ([]*DeploymentConfig, error)
GetByAppIdAndEnvIdEvenIfInactive(appId, envId int) (*DeploymentConfig, error)
UpdateRepoUrlByAppIdAndEnvId(repoUrl string, appId, envId int) error
GetConfigByAppIds(appIds []int) ([]*DeploymentConfig, error)
}

type RepositoryImpl struct {
Expand Down Expand Up @@ -86,14 +103,19 @@ func (impl *RepositoryImpl) Update(tx *pg.Tx, config *DeploymentConfig) (*Deploy
return config, err
}

func (impl *RepositoryImpl) UpdateAll(tx *pg.Tx, config []*DeploymentConfig) ([]*DeploymentConfig, error) {
func (impl *RepositoryImpl) UpdateAll(tx *pg.Tx, configs []*DeploymentConfig) ([]*DeploymentConfig, error) {
var err error
if tx != nil {
err = tx.Update(config)
} else {
err = impl.dbConnection.Update(config)
for _, config := range configs {
if tx != nil {
_, err = tx.Model(config).WherePK().UpdateNotNull()
} else {
_, err = impl.dbConnection.Model(&config).UpdateNotNull()
}
if err != nil {
return nil, err
}
}
return config, err
return configs, err
}

func (impl *RepositoryImpl) GetById(id int) (*DeploymentConfig, error) {
Expand Down Expand Up @@ -172,3 +194,12 @@ func (impl *RepositoryImpl) UpdateRepoUrlByAppIdAndEnvId(repoUrl string, appId,
Update()
return err
}

func (impl *RepositoryImpl) GetConfigByAppIds(appIds []int) ([]*DeploymentConfig, error) {
var results []*DeploymentConfig
err := impl.dbConnection.Model(&results).
Where("app_id in (?) ", pg.In(appIds)).
Where("active = ?", true).
Select()
return results, err
}
Loading
Loading