Skip to content

Commit 9e0f52f

Browse files
committed
fix(helmvalues): git write-back to helmvalues file produces wrong structure (#1339)
Signed-off-by: Cheng Fang <[email protected]>
1 parent ac4f1ca commit 9e0f52f

File tree

5 files changed

+23
-20
lines changed

5 files changed

+23
-20
lines changed

pkg/argocd/argocd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ func getApplicationType(app *argocdapi.Application, wbc *WriteBackConfig) Applic
890890
// getApplicationSourceType returns the source type of the application
891891
func getApplicationSourceType(app *argocdapi.Application, wbc *WriteBackConfig) argocdapi.ApplicationSourceType {
892892
if wbc != nil {
893-
if target := wbc.Target; strings.HasPrefix(target, common.KustomizationPrefix) {
893+
if wbc.KustomizeBase != "" {
894894
return argocdapi.ApplicationSourceTypeKustomize
895895
}
896896
}

pkg/argocd/argocd_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func Test_GetApplicationType(t *testing.T) {
221221
}
222222
// Create a WriteBackConfig with kustomization target to test the logic
223223
wbc := &WriteBackConfig{
224-
Target: "kustomization:.",
224+
KustomizeBase: ".",
225225
}
226226
appType := GetApplicationType(application, wbc)
227227
assert.Equal(t, ApplicationTypeKustomize, appType)
@@ -302,7 +302,7 @@ func Test_GetApplicationSourceType(t *testing.T) {
302302

303303
// Create a WriteBackConfig with kustomization target to test the logic
304304
wbc := &WriteBackConfig{
305-
Target: "kustomization:.",
305+
KustomizeBase: ".",
306306
}
307307

308308
appType := GetApplicationSourceType(application, wbc)

pkg/argocd/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ func marshalParamsOverride(ctx context.Context, applicationImages *ApplicationIm
379379
return []byte{}, nil
380380
}
381381

382-
if wbc != nil && strings.HasPrefix(wbc.Target, common.HelmPrefix) {
382+
if wbc != nil && !strings.HasPrefix(filepath.Base(wbc.Target), common.DefaultTargetFilePrefix) {
383383
images := GetImagesAndAliasesFromApplication(applicationImages)
384384

385385
var helmNewValues yaml.Node

pkg/argocd/update_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@ replicas: 1
16171617
Application: app,
16181618
Images: ImageList{im},
16191619
WriteBackConfig: &WriteBackConfig{
1620-
Target: "helmvalues:./test-values.yaml",
1620+
Target: "./test-values.yaml",
16211621
},
16221622
}
16231623

@@ -1672,7 +1672,7 @@ replicas: 1
16721672
Application: app,
16731673
Images: ImageList{im},
16741674
WriteBackConfig: &WriteBackConfig{
1675-
Target: "helmvalues:./test-values.yaml",
1675+
Target: "./test-values.yaml",
16761676
},
16771677
}
16781678

@@ -1782,7 +1782,7 @@ replicas: 1
17821782
Application: app,
17831783
Images: ImageList{imNginx, imRedis},
17841784
WriteBackConfig: &WriteBackConfig{
1785-
Target: "helmvalues:./test-values.yaml",
1785+
Target: "./test-values.yaml",
17861786
},
17871787
}
17881788

@@ -1913,7 +1913,7 @@ replicas: 1
19131913
Application: app,
19141914
Images: ImageList{imFoo, imBar, imBbb},
19151915
WriteBackConfig: &WriteBackConfig{
1916-
Target: "helmvalues:./test-values.yaml",
1916+
Target: "./test-values.yaml",
19171917
},
19181918
}
19191919

@@ -1981,7 +1981,7 @@ replicas: 1
19811981
Application: app,
19821982
Images: ImageList{im},
19831983
WriteBackConfig: &WriteBackConfig{
1984-
Target: "helmvalues:./test-values.yaml",
1984+
Target: "./test-values.yaml",
19851985
},
19861986
}
19871987

@@ -2046,7 +2046,7 @@ replicas: 1
20462046
Application: app,
20472047
Images: ImageList{im},
20482048
WriteBackConfig: &WriteBackConfig{
2049-
Target: "helmvalues:./test-values.yaml",
2049+
Target: "./test-values.yaml",
20502050
},
20512051
}
20522052

@@ -2100,7 +2100,7 @@ replicas: 1
21002100
Application: app,
21012101
Images: ImageList{im},
21022102
WriteBackConfig: &WriteBackConfig{
2103-
Target: "helmvalues:./test-values.yaml",
2103+
Target: "./test-values.yaml",
21042104
},
21052105
}
21062106

@@ -2152,7 +2152,7 @@ replicas: 1
21522152
Application: app,
21532153
Images: ImageList{im},
21542154
WriteBackConfig: &WriteBackConfig{
2155-
Target: "helmvalues:./test-values.yaml",
2155+
Target: "./test-values.yaml",
21562156
},
21572157
}
21582158

@@ -2205,7 +2205,7 @@ replicas: 1
22052205
Application: app,
22062206
Images: ImageList{im},
22072207
WriteBackConfig: &WriteBackConfig{
2208-
Target: "helmvalues:./test-values.yaml",
2208+
Target: "./test-values.yaml",
22092209
},
22102210
}
22112211

@@ -2257,7 +2257,7 @@ replicas: 1
22572257
Application: app,
22582258
Images: ImageList{im},
22592259
WriteBackConfig: &WriteBackConfig{
2260-
Target: "helmvalues:./test-values.yaml",
2260+
Target: "./test-values.yaml",
22612261
},
22622262
}
22632263

@@ -2311,7 +2311,7 @@ replicas: 1
23112311
Images: ImageList{im},
23122312
WriteBackConfig: &WriteBackConfig{
23132313
Method: WriteBackGit,
2314-
Target: "helmvalues:./test-values.yaml",
2314+
Target: "./test-values.yaml",
23152315
},
23162316
}
23172317

@@ -2362,7 +2362,7 @@ replicas: 1
23622362
Images: ImageList{im},
23632363
WriteBackConfig: &WriteBackConfig{
23642364
Method: WriteBackGit,
2365-
Target: "helmvalues:./test-values.yaml",
2365+
Target: "./test-values.yaml",
23662366
},
23672367
}
23682368
_, err := marshalParamsOverride(context.Background(), applicationImages, nil)
@@ -2469,7 +2469,7 @@ nginx:
24692469
Application: app,
24702470
Images: ImageList{im},
24712471
WriteBackConfig: &WriteBackConfig{
2472-
Target: "helmvalues:./test-values.yaml",
2472+
Target: "./test-values.yaml",
24732473
},
24742474
}
24752475
yaml, err := marshalParamsOverride(context.Background(), applicationImages, originalData)
@@ -2537,7 +2537,7 @@ replicas: 1
25372537
Images: ImageList{im},
25382538
WriteBackConfig: &WriteBackConfig{
25392539
Method: WriteBackGit,
2540-
Target: "helmvalues:./test-values.yaml",
2540+
Target: "./test-values.yaml",
25412541
},
25422542
}
25432543

@@ -2604,7 +2604,7 @@ replicas: 1
26042604
Images: ImageList{im},
26052605
WriteBackConfig: &WriteBackConfig{
26062606
Method: WriteBackGit,
2607-
Target: "helmvalues:./test-values.yaml",
2607+
Target: "./test-values.yaml",
26082608
},
26092609
}
26102610

@@ -2673,7 +2673,7 @@ replicas: 1
26732673
Images: ImageList{im},
26742674
WriteBackConfig: &WriteBackConfig{
26752675
Method: WriteBackGit,
2676-
Target: "helmvalues:./test-values.yaml",
2676+
Target: "./test-values.yaml",
26772677
},
26782678
}
26792679

pkg/common/constants.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ const (
1818
DefaultHelmImageTag = "image.tag"
1919
)
2020

21+
// DefaultTargetFilePrefix the prefix of the default git write-back target
22+
const DefaultTargetFilePrefix = ".argocd-source-"
23+
2124
// DefaultTargetFilePattern configurations related to the write-back functionality
2225
const DefaultTargetFilePattern = ".argocd-source-%s_%s.yaml"
2326
const DefaultTargetFilePatternWithoutNamespace = ".argocd-source-%s.yaml"

0 commit comments

Comments
 (0)