@@ -1219,6 +1219,49 @@ kustomize:
1219
1219
assert .Equal (t , strings .TrimSpace (expected ), strings .TrimSpace (string (yaml )))
1220
1220
})
1221
1221
1222
+ t .Run ("Merge images param" , func (t * testing.T ) {
1223
+ expected := `
1224
+ kustomize:
1225
+ images:
1226
+ - existing:latest
1227
+ - updated:latest
1228
+ - new
1229
+ `
1230
+ app := v1alpha1.Application {
1231
+ ObjectMeta : v1.ObjectMeta {
1232
+ Name : "testapp" ,
1233
+ Annotations : map [string ]string {
1234
+ "argocd-image-updater.argoproj.io/image-list" : "nginx" ,
1235
+ },
1236
+ },
1237
+ Spec : v1alpha1.ApplicationSpec {
1238
+ Source : & v1alpha1.ApplicationSource {
1239
+ RepoURL : "https://example.com/example" ,
1240
+ TargetRevision : "main" ,
1241
+ Kustomize : & v1alpha1.ApplicationSourceKustomize {
1242
+ Images : v1alpha1.KustomizeImages {
1243
+ "new" ,
1244
+ "updated:latest" ,
1245
+ },
1246
+ },
1247
+ },
1248
+ },
1249
+ Status : v1alpha1.ApplicationStatus {
1250
+ SourceType : v1alpha1 .ApplicationSourceTypeKustomize ,
1251
+ },
1252
+ }
1253
+ originalData := []byte (`
1254
+ kustomize:
1255
+ images:
1256
+ - existing:latest
1257
+ - updated:old
1258
+ ` )
1259
+ yaml , err := marshalParamsOverride (& app , originalData )
1260
+ require .NoError (t , err )
1261
+ assert .NotEmpty (t , yaml )
1262
+ assert .Equal (t , strings .TrimSpace (expected ), strings .TrimSpace (string (yaml )))
1263
+ })
1264
+
1222
1265
t .Run ("Empty Kustomize source" , func (t * testing.T ) {
1223
1266
app := v1alpha1.Application {
1224
1267
ObjectMeta : v1.ObjectMeta {
@@ -3643,3 +3686,61 @@ func Test_GetRepositoryLock(t *testing.T) {
3643
3686
require .NotNil (t , state .repositoryLocks [repo2 ])
3644
3687
require .Equal (t , lock3 , state .repositoryLocks [repo2 ])
3645
3688
}
3689
+
3690
+ func Test_mergeKustomizeOverride (t * testing.T ) {
3691
+ tests := []struct {
3692
+ name string
3693
+ existing v1alpha1.KustomizeImages
3694
+ new v1alpha1.KustomizeImages
3695
+ expected v1alpha1.KustomizeImages
3696
+ }{
3697
+ {"with-tag" , []v1alpha1.KustomizeImage {"nginx:foo" },
3698
+ []v1alpha1.KustomizeImage {"nginx:foo" },
3699
+ []v1alpha1.KustomizeImage {"nginx:foo" }},
3700
+ {"no-tag" , []v1alpha1.KustomizeImage {"nginx:foo" },
3701
+ []v1alpha1.KustomizeImage {"nginx" },
3702
+ []v1alpha1.KustomizeImage {"nginx:foo" }},
3703
+ {"with-tag-1" , []v1alpha1.KustomizeImage {"nginx" },
3704
+ []v1alpha1.KustomizeImage {"nginx:latest" },
3705
+ []v1alpha1.KustomizeImage {"nginx:latest" }},
3706
+ {"with-tag-sha" , []v1alpha1.KustomizeImage {"nginx:latest" },
3707
+ []v1alpha1.KustomizeImage {"nginx:latest@sha256:91734281c0ebfc6f1aea979cffeed5079cfe786228a71cc6f1f46a228cde6e34" },
3708
+ []v1alpha1.KustomizeImage {"nginx:latest@sha256:91734281c0ebfc6f1aea979cffeed5079cfe786228a71cc6f1f46a228cde6e34" }},
3709
+
3710
+ {"2-images" , []v1alpha1.KustomizeImage {"nginx:latest" ,
3711
+ "bitnami/nginx:latest@sha256:1a2fe3f9f6d1d38d5a7ee35af732fdb7d15266ec3dbc79bbc0355742cd24d3ec" },
3712
+ []v1alpha1.KustomizeImage {"nginx:latest@sha256:91734281c0ebfc6f1aea979cffeed5079cfe786228a71cc6f1f46a228cde6e34" ,
3713
+ "bitnami/nginx@sha256:1a2fe3f9f6d1d38d5a7ee35af732fdb7d15266ec3dbc79bbc0355742cd24d3ec" },
3714
+ []v1alpha1.KustomizeImage {"nginx:latest@sha256:91734281c0ebfc6f1aea979cffeed5079cfe786228a71cc6f1f46a228cde6e34" ,
3715
+ "bitnami/nginx:latest@sha256:1a2fe3f9f6d1d38d5a7ee35af732fdb7d15266ec3dbc79bbc0355742cd24d3ec" }},
3716
+
3717
+ {"with-registry" , []v1alpha1.KustomizeImage {"quay.io/nginx:latest" },
3718
+ []v1alpha1.KustomizeImage {"quay.io/nginx:latest" },
3719
+ []v1alpha1.KustomizeImage {"quay.io/nginx:latest" }},
3720
+ {"with-registry-1" , []v1alpha1.KustomizeImage {"quay.io/nginx:latest" },
3721
+ []v1alpha1.KustomizeImage {"docker.io/nginx:latest" },
3722
+ []v1alpha1.KustomizeImage {"docker.io/nginx:latest" , "quay.io/nginx:latest" }},
3723
+ }
3724
+ for _ , tt := range tests {
3725
+ t .Run (tt .name , func (t * testing.T ) {
3726
+ existingImages := kustomizeOverride {
3727
+ Kustomize : kustomizeImages {
3728
+ Images : & tt .existing ,
3729
+ },
3730
+ }
3731
+ newImages := kustomizeOverride {
3732
+ Kustomize : kustomizeImages {
3733
+ Images : & tt .new ,
3734
+ },
3735
+ }
3736
+ expectedImages := kustomizeOverride {
3737
+ Kustomize : kustomizeImages {
3738
+ Images : & tt .expected ,
3739
+ },
3740
+ }
3741
+
3742
+ mergeKustomizeOverride (& existingImages , & newImages )
3743
+ assert .ElementsMatch (t , * expectedImages .Kustomize .Images , * existingImages .Kustomize .Images )
3744
+ })
3745
+ }
3746
+ }
0 commit comments