@@ -349,3 +349,109 @@ metadata:
349349 g .Expect (resultSA .Labels ["shape" ]).To (Equal ("square" ))
350350 })
351351}
352+
353+ func TestKustomizationReconciler_VarsubNumberBool (t * testing.T ) {
354+ ctx := context .Background ()
355+
356+ g := NewWithT (t )
357+ id := "vars-" + randStringRunes (5 )
358+ revision := "v1.0.0/" + randStringRunes (7 )
359+
360+ err := createNamespace (id )
361+ g .Expect (err ).NotTo (HaveOccurred (), "failed to create test namespace" )
362+
363+ err = createKubeConfigSecret (id )
364+ g .Expect (err ).NotTo (HaveOccurred (), "failed to create kubeconfig secret" )
365+
366+ manifests := func (name string ) []testserver.File {
367+ return []testserver.File {
368+ {
369+ Name : "service-account.yaml" ,
370+ Body : fmt .Sprintf (`
371+ apiVersion: v1
372+ kind: ServiceAccount
373+ metadata:
374+ name: %[1]s
375+ namespace: %[1]s
376+ labels:
377+ id: ${numberStr}
378+ enabled: ${booleanStr}
379+ annotations:
380+ id: ${q}${number}${q}
381+ enabled: ${q}${boolean}${q}
382+ ` , name ),
383+ },
384+ }
385+ }
386+
387+ artifact , err := testServer .ArtifactFromFiles (manifests (id ))
388+ g .Expect (err ).NotTo (HaveOccurred ())
389+
390+ repositoryName := types.NamespacedName {
391+ Name : randStringRunes (5 ),
392+ Namespace : id ,
393+ }
394+
395+ err = applyGitRepository (repositoryName , artifact , revision )
396+ g .Expect (err ).NotTo (HaveOccurred ())
397+
398+ inputK := & kustomizev1.Kustomization {
399+ ObjectMeta : metav1.ObjectMeta {
400+ Name : id ,
401+ Namespace : id ,
402+ },
403+ Spec : kustomizev1.KustomizationSpec {
404+ KubeConfig : & meta.KubeConfigReference {
405+ SecretRef : meta.SecretKeyReference {
406+ Name : "kubeconfig" ,
407+ },
408+ },
409+ Interval : metav1.Duration {Duration : reconciliationInterval },
410+ Path : "./" ,
411+ Prune : true ,
412+ SourceRef : kustomizev1.CrossNamespaceSourceReference {
413+ Kind : sourcev1 .GitRepositoryKind ,
414+ Name : repositoryName .Name ,
415+ },
416+ PostBuild : & kustomizev1.PostBuild {
417+ Substitute : map [string ]string {
418+ "q" : `"` ,
419+
420+ "numberStr" : "!!str 123" ,
421+ "number" : "123" ,
422+ "booleanStr" : "!!str true" ,
423+ "boolean" : "true" ,
424+ },
425+ },
426+ Wait : true ,
427+ },
428+ }
429+ g .Expect (k8sClient .Create (ctx , inputK )).Should (Succeed ())
430+
431+ resultSA := & corev1.ServiceAccount {}
432+
433+ ensureReconciles := func (nameSuffix string ) {
434+ t .Run ("reconciles successfully" + nameSuffix , func (t * testing.T ) {
435+ g .Eventually (func () bool {
436+ resultK := & kustomizev1.Kustomization {}
437+ _ = k8sClient .Get (ctx , client .ObjectKeyFromObject (inputK ), resultK )
438+ for _ , c := range resultK .Status .Conditions {
439+ if c .Reason == kustomizev1 .ReconciliationSucceededReason {
440+ return true
441+ }
442+ }
443+ return false
444+ }, timeout , interval ).Should (BeTrue ())
445+
446+ g .Expect (k8sClient .Get (ctx , types.NamespacedName {Name : id , Namespace : id }, resultSA )).Should (Succeed ())
447+ })
448+ }
449+
450+ ensureReconciles (" with optional ConfigMap" )
451+ t .Run ("replaces vars from optional ConfigMap" , func (t * testing.T ) {
452+ g .Expect (resultSA .Labels ["id" ]).To (Equal ("123" ))
453+ g .Expect (resultSA .Annotations ["id" ]).To (Equal ("123" ))
454+ g .Expect (resultSA .Labels ["enabled" ]).To (Equal ("true" ))
455+ g .Expect (resultSA .Annotations ["enabled" ]).To (Equal ("true" ))
456+ })
457+ }
0 commit comments