Skip to content

Commit 1f5f76e

Browse files
Merge pull request #6326 from devtron-labs/main-develop-sync-27jan-1
chore: Main develop sync
2 parents b77e05d + 0e2d87c commit 1f5f76e

File tree

64 files changed

+1228
-385
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1228
-385
lines changed

.github/workflows/multiarch_new.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ jobs:
4141
local image="$1"
4242
local image_ref=$(echo $image | sed 's/:.*//')
4343
44-
# skipping the check for 'inception', 'postgres' , 'postgres_exporter' and 'workflow-controller' images
45-
if [[ "$image_ref" == "inception" || "$image_ref" == "postgres" || "$image_ref" == "postgres_exporter" || "$image_ref" == "workflow-controller" ]]; then
44+
# skipping the check for 'inception', 'postgres' , 'postgres_exporter', 'workflow-controller', 'casbin' and 'scoop' images
45+
if [[ "$image_ref" == "inception" || "$image_ref" == "postgres" || "$image_ref" == "postgres_exporter" || "$image_ref" == "workflow-controller" || "$image_ref" == "casbin" || "$image_ref" == "scoop" ]]; then
4646
return
4747
fi
4848

api/restHandler/app/appList/AppListingRestHandler_ent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ func (handler AppListingRestHandlerImpl) GetAllAppEnvsFromResourceNames(w http.R
1515
}
1616

1717
func (handler AppListingRestHandlerImpl) updateApprovalConfigDataInAppDetailResp(appDetail AppView.AppDetailContainer, appId, envId int) (AppView.AppDetailContainer, error) {
18-
return AppView.AppDetailContainer{}, nil
18+
return appDetail, nil
1919
}

fetchAllEnv/fetchAllEnv.go

Lines changed: 2 additions & 203 deletions
Original file line numberDiff line numberDiff line change
@@ -17,210 +17,9 @@
1717
package main
1818

1919
import (
20-
"encoding/json"
21-
"errors"
22-
"go/ast"
23-
"go/parser"
24-
"go/token"
25-
"log"
26-
"os"
27-
"path/filepath"
28-
"reflect"
29-
"sort"
30-
"strings"
31-
"text/template"
20+
"github.com/devtron-labs/common-lib/fetchAllEnv"
3221
)
3322

34-
type EnvField struct {
35-
Env string
36-
EnvType string
37-
EnvValue string
38-
EnvDescription string
39-
Example string
40-
Deprecated string
41-
}
42-
43-
type CategoryField struct {
44-
Category string
45-
Fields []EnvField
46-
}
47-
48-
const (
49-
categoryCommentStructPrefix = "CATEGORY="
50-
defaultCategory = "DEVTRON"
51-
deprecatedDefaultValue = "false"
52-
53-
envFieldTypeTag = "env"
54-
envDefaultFieldTypeTag = "envDefault"
55-
envDescriptionFieldTypeTag = "description"
56-
envPossibleValuesFieldTypeTag = "example"
57-
envDeprecatedFieldTypeTag = "deprecated"
58-
MARKDOWN_FILENAME = "env_gen.md"
59-
MARKDOWN_JSON_FILENAME = "env_gen.json"
60-
)
61-
62-
const MarkdownTemplate = `
63-
{{range . }}
64-
## {{ .Category }} Related Environment Variables
65-
| Key | Type | Default Value | Description | Example | Deprecated |
66-
|-------|----------|-------------------|-------------------|-----------------------|------------------|
67-
{{range .Fields }} | {{ .Env }} | {{ .EnvType }} |{{ .EnvValue }} | {{ .EnvDescription }} | {{ .Example }} | {{ .Deprecated }} |
68-
{{end}}
69-
{{end}}`
70-
7123
func main() {
72-
WalkThroughProject()
73-
return
74-
}
75-
76-
func WalkThroughProject() {
77-
categoryFieldsMap := make(map[string][]EnvField)
78-
uniqueKeys := make(map[string]bool)
79-
err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
80-
if err != nil {
81-
return err
82-
}
83-
if !info.IsDir() && strings.HasSuffix(path, ".go") {
84-
err = processGoFile(path, categoryFieldsMap, uniqueKeys)
85-
if err != nil {
86-
log.Println("error in processing go file", err)
87-
return err
88-
}
89-
}
90-
return nil
91-
})
92-
if err != nil {
93-
return
94-
}
95-
writeToFile(categoryFieldsMap)
96-
}
97-
98-
func processGoFile(filePath string, categoryFieldsMap map[string][]EnvField, uniqueKeys map[string]bool) error {
99-
fset := token.NewFileSet()
100-
node, err := parser.ParseFile(fset, filePath, nil, parser.ParseComments)
101-
if err != nil {
102-
log.Println("error parsing file:", err)
103-
return err
104-
}
105-
ast.Inspect(node, func(n ast.Node) bool {
106-
if genDecl, ok := n.(*ast.GenDecl); ok {
107-
// checking if type declaration, one of [func, map, struct, array, channel, interface]
108-
if genDecl.Tok == token.TYPE {
109-
for _, spec := range genDecl.Specs {
110-
if typeSpec, ok := spec.(*ast.TypeSpec); ok {
111-
// only checking struct type declarations
112-
if structType, ok2 := typeSpec.Type.(*ast.StructType); ok2 {
113-
allFields := make([]EnvField, 0, len(structType.Fields.List))
114-
for _, field := range structType.Fields.List {
115-
if field.Tag != nil {
116-
envField := getEnvKeyAndValue(field)
117-
envKey := envField.Env
118-
if len(envKey) == 0 || uniqueKeys[envKey] {
119-
continue
120-
}
121-
allFields = append(allFields, envField)
122-
uniqueKeys[envKey] = true
123-
}
124-
}
125-
if len(allFields) > 0 {
126-
category := getCategoryForAStruct(genDecl)
127-
categoryFieldsMap[category] = append(categoryFieldsMap[category], allFields...)
128-
}
129-
}
130-
}
131-
}
132-
}
133-
}
134-
return true
135-
})
136-
return nil
137-
}
138-
139-
func getEnvKeyAndValue(field *ast.Field) EnvField {
140-
tag := reflect.StructTag(strings.Trim(field.Tag.Value, "`")) // remove surrounding backticks
141-
142-
envKey := addReadmeTableDelimiterEscapeChar(tag.Get(envFieldTypeTag))
143-
envValue := addReadmeTableDelimiterEscapeChar(tag.Get(envDefaultFieldTypeTag))
144-
envDescription := addReadmeTableDelimiterEscapeChar(tag.Get(envDescriptionFieldTypeTag))
145-
envPossibleValues := addReadmeTableDelimiterEscapeChar(tag.Get(envPossibleValuesFieldTypeTag))
146-
envDeprecated := addReadmeTableDelimiterEscapeChar(tag.Get(envDeprecatedFieldTypeTag))
147-
// check if there exist any value provided in env for this field
148-
if value, ok := os.LookupEnv(envKey); ok {
149-
envValue = value
150-
}
151-
env := EnvField{
152-
Env: envKey,
153-
EnvValue: envValue,
154-
EnvDescription: envDescription,
155-
Example: envPossibleValues,
156-
Deprecated: envDeprecated,
157-
}
158-
if indent, ok := field.Type.(*ast.Ident); ok && indent != nil {
159-
env.EnvType = indent.Name
160-
}
161-
if len(envDeprecated) == 0 {
162-
env.Deprecated = deprecatedDefaultValue
163-
}
164-
return env
165-
}
166-
167-
func getCategoryForAStruct(genDecl *ast.GenDecl) string {
168-
category := defaultCategory
169-
if genDecl.Doc != nil {
170-
commentTexts := strings.Split(genDecl.Doc.Text(), "\n")
171-
for _, comment := range commentTexts {
172-
commentText := strings.TrimPrefix(strings.ReplaceAll(comment, " ", ""), "//") // this can happen if comment group is in /* */
173-
if strings.HasPrefix(commentText, categoryCommentStructPrefix) {
174-
categories := strings.Split(strings.TrimPrefix(commentText, categoryCommentStructPrefix), ",")
175-
if len(categories) > 0 && len(categories[0]) > 0 { //only supporting one category as of now
176-
category = categories[0] //overriding category
177-
break
178-
}
179-
}
180-
}
181-
}
182-
return category
183-
}
184-
185-
func addReadmeTableDelimiterEscapeChar(s string) string {
186-
return strings.ReplaceAll(s, "|", `\|`)
187-
}
188-
189-
func writeToFile(categoryFieldsMap map[string][]EnvField) {
190-
cfs := make([]CategoryField, 0, len(categoryFieldsMap))
191-
for category, allFields := range categoryFieldsMap {
192-
sort.Slice(allFields, func(i, j int) bool {
193-
return allFields[i].Env < allFields[j].Env
194-
})
195-
196-
cfs = append(cfs, CategoryField{
197-
Category: category,
198-
Fields: allFields,
199-
})
200-
}
201-
sort.Slice(cfs, func(i, j int) bool {
202-
return cfs[i].Category < cfs[j].Category
203-
})
204-
file, err := os.Create(MARKDOWN_FILENAME)
205-
if err != nil && !errors.Is(err, os.ErrExist) {
206-
panic(err)
207-
}
208-
defer file.Close()
209-
tmpl, err := template.New("markdown").Parse(MarkdownTemplate)
210-
if err != nil {
211-
panic(err)
212-
}
213-
err = tmpl.Execute(file, cfs)
214-
if err != nil {
215-
panic(err)
216-
}
217-
cfsMarshaled, err := json.Marshal(cfs)
218-
if err != nil {
219-
log.Println("error marshalling category fields:", err)
220-
panic(err)
221-
}
222-
err = os.WriteFile(MARKDOWN_JSON_FILENAME, cfsMarshaled, 0644)
223-
if err != nil {
224-
panic(err)
225-
}
24+
fetchAllEnv.FetchEnvAndWriteToFile()
22625
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ require gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
288288

289289
replace (
290290
github.com/argoproj/argo-workflows/v3 v3.5.10 => github.com/devtron-labs/argo-workflows/v3 v3.5.13
291-
github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250127090829-f050f9c05226
292-
github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250127090829-f050f9c05226
291+
github.com/devtron-labs/authenticator => github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250127104410-85d6bfe0b45f
292+
github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250127104410-85d6bfe0b45f
293293
github.com/go-check/check => github.com/go-check/check v0.0.0-20180628173108-788fd7840127
294294
github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.5.5
295295
k8s.io/api => k8s.io/api v0.29.7

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -792,10 +792,10 @@ github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc h1:VRRKCwnzq
792792
github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
793793
github.com/devtron-labs/argo-workflows/v3 v3.5.13 h1:3pINq0gXOSeTw2z/vYe+j80lRpSN5Rp/8mfQORh8SmU=
794794
github.com/devtron-labs/argo-workflows/v3 v3.5.13/go.mod h1:/vqxcovDPT4zqr4DjR5v7CF8ggpY1l3TSa2CIG3jmjA=
795-
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250127090829-f050f9c05226 h1:67Im8ME0J2Ukd8xbKuR+0rzT3oO0Obcd58keDb80C3I=
796-
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250127090829-f050f9c05226/go.mod h1:5lv4Wfj5ERhhvDGXe2IeES6qxjvUVCcohaRwKnWBMNo=
797-
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250127090829-f050f9c05226 h1:yYHCt3F0xLW0VlBGXqAsXLJElLcnEJCUkpQJxmgkTb4=
798-
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250127090829-f050f9c05226/go.mod h1:1QJJLpgJSkb5Jm9xPeKAk+kXb0QgBOOOgJj0cgYhAVA=
795+
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250127104410-85d6bfe0b45f h1:8nYP02cYX/9e3H8YfBV4b8hP4WwbGY/dUMNu+N9cH1Q=
796+
github.com/devtron-labs/devtron-services/authenticator v0.0.0-20250127104410-85d6bfe0b45f/go.mod h1:5lv4Wfj5ERhhvDGXe2IeES6qxjvUVCcohaRwKnWBMNo=
797+
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250127104410-85d6bfe0b45f h1:4wUbt+83DmpZFqYS69CJxNtBpSuCb58UwqOrWsZG82s=
798+
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20250127104410-85d6bfe0b45f/go.mod h1:1QJJLpgJSkb5Jm9xPeKAk+kXb0QgBOOOgJj0cgYhAVA=
799799
github.com/devtron-labs/go-bitbucket v0.9.60-beta h1:VEx1jvDgdtDPS6A1uUFoaEi0l1/oLhbr+90xOwr6sDU=
800800
github.com/devtron-labs/go-bitbucket v0.9.60-beta/go.mod h1:GnuiCesvh8xyHeMCb+twm8lBR/kQzJYSKL28ZfObp1Y=
801801
github.com/devtron-labs/protos v0.0.3-0.20240802105333-92ee9bb85d80 h1:xwbTeijNTf4/j1v+tSfwVqwLVnReas/NqEKeQHvSTys=

internal/sql/repository/deploymentConfig/repository.go

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2020-2024. Devtron Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package deploymentConfig
218

319
import (
@@ -29,7 +45,7 @@ type DeploymentConfig struct {
2945
ConfigType string `sql:"config_type"`
3046
RepoUrl string `sql:"repo_url"`
3147
RepoName string `sql:"repo_name"`
32-
ReleaseMode string `json:"release_mode"`
48+
ReleaseMode string `sql:"release_mode"`
3349
Active bool `sql:"active,notnull"`
3450
sql.AuditLog
3551
}
@@ -46,6 +62,7 @@ type Repository interface {
4662
GetAppAndEnvLevelConfigsInBulk(appIdToEnvIdsMap map[int][]int) ([]*DeploymentConfig, error)
4763
GetByAppIdAndEnvIdEvenIfInactive(appId, envId int) (*DeploymentConfig, error)
4864
UpdateRepoUrlByAppIdAndEnvId(repoUrl string, appId, envId int) error
65+
GetConfigByAppIds(appIds []int) ([]*DeploymentConfig, error)
4966
}
5067

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

89-
func (impl *RepositoryImpl) UpdateAll(tx *pg.Tx, config []*DeploymentConfig) ([]*DeploymentConfig, error) {
106+
func (impl *RepositoryImpl) UpdateAll(tx *pg.Tx, configs []*DeploymentConfig) ([]*DeploymentConfig, error) {
90107
var err error
91-
if tx != nil {
92-
err = tx.Update(config)
93-
} else {
94-
err = impl.dbConnection.Update(config)
108+
for _, config := range configs {
109+
if tx != nil {
110+
_, err = tx.Model(config).WherePK().UpdateNotNull()
111+
} else {
112+
_, err = impl.dbConnection.Model(&config).UpdateNotNull()
113+
}
114+
if err != nil {
115+
return nil, err
116+
}
95117
}
96-
return config, err
118+
return configs, err
97119
}
98120

99121
func (impl *RepositoryImpl) GetById(id int) (*DeploymentConfig, error) {
@@ -172,3 +194,12 @@ func (impl *RepositoryImpl) UpdateRepoUrlByAppIdAndEnvId(repoUrl string, appId,
172194
Update()
173195
return err
174196
}
197+
198+
func (impl *RepositoryImpl) GetConfigByAppIds(appIds []int) ([]*DeploymentConfig, error) {
199+
var results []*DeploymentConfig
200+
err := impl.dbConnection.Model(&results).
201+
Where("app_id in (?) ", pg.In(appIds)).
202+
Where("active = ?", true).
203+
Select()
204+
return results, err
205+
}

0 commit comments

Comments
 (0)