@@ -71,12 +71,12 @@ const (
7171Automation: {{ .AutomationObject }}
7272
7373Files:
74- {{ range $filename, $_ := .Updated .Files -}}
74+ {{ range $filename, $_ := .Changed.ImageResult .Files -}}
7575- {{ $filename }}
7676{{ end -}}
7777
7878Objects:
79- {{ range $resource, $_ := .Updated .Objects -}}
79+ {{ range $resource, $_ := .Changed.ImageResult .Objects -}}
8080{{ if eq $resource.Kind "Deployment" -}}
8181- {{ $resource.Kind | lower }} {{ $resource.Name | lower }}
8282{{ else -}}
@@ -85,7 +85,7 @@ Objects:
8585{{ end -}}
8686
8787Images:
88- {{ range .Updated .Images -}}
88+ {{ range .Changed.ImageResult .Images -}}
8989- {{.}} ({{.Policy.Name}})
9090{{ end -}}
9191`
@@ -841,6 +841,97 @@ Automation: %s/update-test
841841 }
842842}
843843
844+ // TestImageUpdateAutomationReconciler_removedTemplateField tests removed .Updated template field usage.
845+ func TestImageUpdateAutomationReconciler_removedTemplateField (t * testing.T ) {
846+ g := NewWithT (t )
847+ ctx := context .TODO ()
848+
849+ policySpec := imagev1_reflect.ImagePolicySpec {
850+ ImageRepositoryRef : meta.NamespacedObjectReference {
851+ Name : "not-expected-to-exist" ,
852+ },
853+ Policy : imagev1_reflect.ImagePolicyChoice {
854+ SemVer : & imagev1_reflect.SemVerPolicy {
855+ Range : "1.x" ,
856+ },
857+ },
858+ }
859+ fixture := "testdata/appconfig"
860+ latest := "helloworld:v1.0.0"
861+
862+ removedTemplate := `Commit summary
863+
864+ Automation: {{ .AutomationObject }}
865+
866+ Files:
867+ {{ range $filename, $_ := .Updated.Files -}}
868+ - {{ $filename }}
869+ {{ end -}}
870+
871+ Objects:
872+ {{ range $resource, $_ := .Updated.Objects -}}
873+ {{ if eq $resource.Kind "Deployment" -}}
874+ - {{ $resource.Kind | lower }} {{ $resource.Name | lower }}
875+ {{ else -}}
876+ - {{ $resource.Kind }} {{ $resource.Name }}
877+ {{ end -}}
878+ {{ end -}}
879+
880+ Images:
881+ {{ range .Updated.Images -}}
882+ - {{.}} ({{.Policy.Name}})
883+ {{ end -}}
884+ `
885+
886+ namespace , err := testEnv .CreateNamespace (ctx , "image-auto-test" )
887+ g .Expect (err ).ToNot (HaveOccurred ())
888+ defer func () { g .Expect (testEnv .Delete (ctx , namespace )).To (Succeed ()) }()
889+
890+ testWithRepoAndImagePolicy (
891+ ctx , g , testEnv , namespace .Name , fixture , policySpec , latest ,
892+ func (g * WithT , s repoAndPolicyArgs , repoURL string , localRepo * extgogit.Repository ) {
893+ policyKey := types.NamespacedName {
894+ Name : s .imagePolicyName ,
895+ Namespace : s .namespace ,
896+ }
897+ _ = testutil .CommitInRepo (ctx , g , repoURL , s .branch , originRemote , "Install setter marker" , func (tmp string ) {
898+ g .Expect (testutil .ReplaceMarker (filepath .Join (tmp , "deploy.yaml" ), policyKey )).To (Succeed ())
899+ })
900+
901+ preChangeCommitId := testutil .CommitIdFromBranch (localRepo , s .branch )
902+ waitForNewHead (g , localRepo , s .branch , preChangeCommitId )
903+ preChangeCommitId = testutil .CommitIdFromBranch (localRepo , s .branch )
904+
905+ updateStrategy := & imagev1.UpdateStrategy {
906+ Strategy : imagev1 .UpdateStrategySetters ,
907+ }
908+ err := createImageUpdateAutomation (ctx , testEnv , "update-test" , s .namespace , s .gitRepoName , s .gitRepoNamespace , s .branch , s .branch , "" , removedTemplate , "" , updateStrategy )
909+ g .Expect (err ).ToNot (HaveOccurred ())
910+ defer func () {
911+ g .Expect (deleteImageUpdateAutomation (ctx , testEnv , "update-test" , s .namespace )).To (Succeed ())
912+ }()
913+
914+ imageUpdateKey := types.NamespacedName {
915+ Namespace : s .namespace ,
916+ Name : "update-test" ,
917+ }
918+
919+ g .Eventually (func () bool {
920+ var imageUpdate imagev1.ImageUpdateAutomation
921+ _ = testEnv .Get (context .TODO (), imageUpdateKey , & imageUpdate )
922+ stalledCondition := apimeta .FindStatusCondition (imageUpdate .Status .Conditions , meta .StalledCondition )
923+ return stalledCondition != nil &&
924+ stalledCondition .Status == metav1 .ConditionTrue &&
925+ stalledCondition .Reason == imagev1 .RemovedTemplateFieldReason &&
926+ strings .Contains (stalledCondition .Message , "template uses removed '.Updated' field" )
927+ }, timeout ).Should (BeTrue ())
928+
929+ head , _ := localRepo .Head ()
930+ g .Expect (head .Hash ().String ()).To (Equal (preChangeCommitId ))
931+ },
932+ )
933+ }
934+
844935func TestImageUpdateAutomationReconciler_crossNamespaceRef (t * testing.T ) {
845936 g := NewWithT (t )
846937 policySpec := imagev1_reflect.ImagePolicySpec {
0 commit comments