@@ -472,8 +472,8 @@ func TestReconcileApplicationSet_Deployments_SpecOverride(t *testing.T) {
472472 {
473473 name : "verify env var substitution overrides default" ,
474474 appSetField : & argoproj.ArgoCDApplicationSet {},
475- envVars : map [string ]string {common .ArgoCDImageEnvName : "custom-env-image " },
476- expectedContainerImage : "custom-env-image " ,
475+ envVars : map [string ]string {common .ArgoCDImageEnvName : "docker.io/library/ubuntu:latest " },
476+ expectedContainerImage : "docker.io/library/ubuntu:latest " ,
477477 },
478478
479479 {
@@ -482,16 +482,16 @@ func TestReconcileApplicationSet_Deployments_SpecOverride(t *testing.T) {
482482 Image : "custom-image" ,
483483 Version : "custom-version" ,
484484 },
485- envVars : map [string ]string {common .ArgoCDImageEnvName : "custom-env-image " },
485+ envVars : map [string ]string {common .ArgoCDImageEnvName : "docker.io/library/ubuntu:latest " },
486486 expectedContainerImage : "custom-image:custom-version" ,
487487 },
488488 {
489489 name : "ensure scm tls cert mount is present" ,
490490 appSetField : & argoproj.ArgoCDApplicationSet {
491491 SCMRootCAConfigMap : "test-scm-tls-mount" ,
492492 },
493- envVars : map [string ]string {common .ArgoCDImageEnvName : "custom-env-image " },
494- expectedContainerImage : "custom-env-image " ,
493+ envVars : map [string ]string {common .ArgoCDImageEnvName : "docker.io/library/ubuntu:latest " },
494+ expectedContainerImage : "docker.io/library/ubuntu:latest " ,
495495 },
496496 }
497497
@@ -1349,3 +1349,105 @@ func TestArgoCDApplicationSet_removeUnmanagedApplicationSetSourceNamespaceResour
13491349 assert .True (t , found )
13501350 assert .Equal (t , a .Namespace , val )
13511351}
1352+
1353+ func TestGetApplicationSetContainerImage (t * testing.T ) {
1354+ logf .SetLogger (ZapLogger (true ))
1355+
1356+ // when env var is set and spec fields are not set, env var should be returned
1357+ cr := argoproj.ArgoCD {}
1358+ cr .Spec = argoproj.ArgoCDSpec {}
1359+ cr .Spec .ApplicationSet = & argoproj.ArgoCDApplicationSet {}
1360+ os .Setenv (common .ArgoCDImageEnvName , "testingimage@sha:123456" )
1361+ out := getApplicationSetContainerImage (& cr )
1362+ assert .Equal (t , "testingimage@sha:123456" , out )
1363+
1364+ // when env var is set and also spec image and version fields are set, spec fields should be returned
1365+ cr .Spec .Image = "customimage"
1366+ cr .Spec .Version = "sha256:7e0aa2f42232f6b2f0a9d5f98b2e3a9a6b8c9b7f3a4c1d2e5f6a7b8c9d0e1f2a"
1367+ os .Setenv (common .ArgoCDImageEnvName , "quay.io/project/registry@sha256:7e0aa2f42232f6b2f0a9d5f98b2e3a9a6b8c9b7f3a4c1d2e5f6a7b8c9d0e1f2a" )
1368+ out = getApplicationSetContainerImage (& cr )
1369+ assert .Equal (t , "customimage@sha256:7e0aa2f42232f6b2f0a9d5f98b2e3a9a6b8c9b7f3a4c1d2e5f6a7b8c9d0e1f2a" , out )
1370+
1371+ // when spec.image and spec.applicationset.image is passed and also env is passed, container level image should take priority
1372+ cr .Spec .Image = "customimage"
1373+ cr .Spec .Version = "sha256:7e0aa2f42232f6b2f0a9d5f98b2e3a9a6b8c9b7f3a4c1d2e5f6a7b8c9d0e1f2a"
1374+ cr .Spec .ApplicationSet .Image = "containerImage"
1375+ cr .Spec .ApplicationSet .Version = "sha256:7e0aa2f42232f6b2f0a9d5f98b2e3a9a6b8c9b7f3a4c1d2e5f6a7b8c9d0e1f2b"
1376+ os .Setenv (common .ArgoCDImageEnvName , "quay.io/project/registry@sha256:7e0aa2f42232f6b2f0a9d5f98b2e3a9a6b8c9b7f3a4c1d2e5f6a7b8c9d0e1f2c" )
1377+ out = getApplicationSetContainerImage (& cr )
1378+ assert .Equal (t , "containerImage@sha256:7e0aa2f42232f6b2f0a9d5f98b2e3a9a6b8c9b7f3a4c1d2e5f6a7b8c9d0e1f2b" , out )
1379+
1380+ // when env var is set and also spec version field is set but image field is not set, should return env var image with spec version
1381+ cr .Spec .Image = ""
1382+ cr .Spec .Version = "sha256:7e0aa2f42232f6b2f0a9d5f98b2e3a9a6b8c9b7f3a4c1d2e5f6a7b8c9d0e1f2a"
1383+ cr .Spec .ApplicationSet .Image = ""
1384+ cr .Spec .ApplicationSet .Version = ""
1385+ os .Setenv (common .ArgoCDImageEnvName , "quay.io/project/registry@sha256:7e0aa2f42232f6b2f0a9d5f98b2e3a9a6b8c9b7f3a4c1d2e5f6a7b8c9d0e1f2b" )
1386+ out = getApplicationSetContainerImage (& cr )
1387+ assert .Equal (t , "quay.io/project/registry@sha256:7e0aa2f42232f6b2f0a9d5f98b2e3a9a6b8c9b7f3a4c1d2e5f6a7b8c9d0e1f2a" , out )
1388+
1389+ // when env var in wrong format is set and also spec version field is set but image field is not set
1390+ cr .Spec .Image = ""
1391+ cr .Spec .Version = "sha256:7e0aa2f42232f6b2f0a9d5f98b2e3a9a6b8c9b7f3a4c1d2e5f6a7b8c9d0e1f2a"
1392+ os .Setenv (common .ArgoCDImageEnvName , "quay.io/project/registry:latest" )
1393+ out = getApplicationSetContainerImage (& cr )
1394+ assert .Equal (t , "quay.io/project/registry@sha256:7e0aa2f42232f6b2f0a9d5f98b2e3a9a6b8c9b7f3a4c1d2e5f6a7b8c9d0e1f2a" , out )
1395+
1396+ cr .Spec .Image = ""
1397+ cr .Spec .Version = ""
1398+ os .Setenv (common .ArgoCDImageEnvName , "quay.io/project/registry:latest@sha256:7e0aa2f42232f6b2f0a9d5f98b2e3a9a6b8c9b7f3a4c1d2e5f6a7b8c9d0e1f2a" )
1399+ out = getApplicationSetContainerImage (& cr )
1400+ assert .Equal (t , "quay.io/project/registry:latest@sha256:7e0aa2f42232f6b2f0a9d5f98b2e3a9a6b8c9b7f3a4c1d2e5f6a7b8c9d0e1f2a" , out )
1401+
1402+ cr .Spec .Image = ""
1403+ cr .Spec .Version = ""
1404+ os .Setenv (common .ArgoCDImageEnvName , "docker.io/library/ubuntu" )
1405+ out = getApplicationSetContainerImage (& cr )
1406+ assert .Equal (t , "docker.io/library/ubuntu" , out )
1407+
1408+ cr .Spec .Image = ""
1409+ cr .Spec .Version = "v0.0.1"
1410+ os .Setenv (common .ArgoCDImageEnvName , "quay.io/project/registry:latest@sha256:7e0aa2f42232f6b2f0a9d5f98b2e3a9a6b8c9b7f3a4c1d2e5f6a7b8c9d0e1f2a" )
1411+ out = getApplicationSetContainerImage (& cr )
1412+ assert .Equal (t , "quay.io/project/registry:v0.0.1" , out )
1413+
1414+ cr .Spec .Image = ""
1415+ cr .Spec .Version = "v0.0.1"
1416+ os .Setenv (common .ArgoCDImageEnvName , "docker.io/library/ubuntu" )
1417+ out = getApplicationSetContainerImage (& cr )
1418+ assert .Equal (t , "docker.io/library/ubuntu:v0.0.1" , out )
1419+
1420+ cr .Spec .Image = ""
1421+ cr .Spec .Version = "v0.0.1"
1422+ os .Setenv (common .ArgoCDImageEnvName , "ubuntu" )
1423+ out = getApplicationSetContainerImage (& cr )
1424+ assert .Equal (t , "ubuntu:v0.0.1" , out )
1425+
1426+ // when env var is not set and spec image and version fields are not set, default image should be returned
1427+ os .Setenv (common .ArgoCDImageEnvName , "" )
1428+ cr .Spec .Image = ""
1429+ cr .Spec .Version = ""
1430+ out = getApplicationSetContainerImage (& cr )
1431+ assert .Equal (t , "quay.io/argoproj/argocd@sha256:2815b045273dc14b271c40d01a75ae2efa88613c90300e778d5ad5171e2b0f7f" , out )
1432+
1433+ // when env var is not set and spec image and version fields are set, spec fields should be returned
1434+ cr .Spec .Image = "customimage"
1435+ cr .Spec .Version = "sha256:1234567890abcdef"
1436+ os .Setenv (common .ArgoCDImageEnvName , "" )
1437+ out = getApplicationSetContainerImage (& cr )
1438+ assert .Equal (t , "customimage@sha256:1234567890abcdef" , out )
1439+
1440+ // when env var is not set and spec version field is set but image field is not set, should return default image with spec version tag
1441+ cr .Spec .Image = ""
1442+ cr .Spec .Version = "customversion"
1443+ os .Setenv (common .ArgoCDImageEnvName , "" )
1444+ out = getApplicationSetContainerImage (& cr )
1445+ assert .Equal (t , "quay.io/argoproj/argocd:customversion" , out )
1446+
1447+ // when env var is not set and spec image field is set but version field is not set, should return spec image with default tag
1448+ cr .Spec .Image = "customimage"
1449+ cr .Spec .Version = ""
1450+ os .Setenv (common .ArgoCDImageEnvName , "" )
1451+ out = getApplicationSetContainerImage (& cr )
1452+ assert .Equal (t , "customimage@sha256:2815b045273dc14b271c40d01a75ae2efa88613c90300e778d5ad5171e2b0f7f" , out )
1453+ }
0 commit comments