@@ -71,12 +71,12 @@ const (
7171Automation: {{ .AutomationObject }}
7272
7373Files:
74- {{ range $filename, $_ := .Changed.ImageResult.Files -}}
74+ {{ range $filename, $_ := .Changed.FileChanges -}}
7575- {{ $filename }}
7676{{ end -}}
7777
7878Objects:
79- {{ range $resource, $_ := .Changed.ImageResult. Objects -}}
79+ {{ range $resource, $_ := .Changed.Objects -}}
8080{{ if eq $resource.Kind "Deployment" -}}
8181- {{ $resource.Kind | lower }} {{ $resource.Name | lower }}
8282{{ else -}}
@@ -85,8 +85,10 @@ Objects:
8585{{ end -}}
8686
8787Images:
88- {{ range .Changed.ImageResult.Images -}}
89- - {{.}} ({{.Policy.Name}})
88+ {{ range .Changed.Changes -}}
89+ {{ if .Setter -}}
90+ - {{.NewValue}} ({{.Setter}})
91+ {{ end -}}
9092{{ end -}}
9193`
9294 testCommitMessageFmt = `Commit summary
@@ -98,7 +100,7 @@ Files:
98100Objects:
99101- deployment test
100102Images:
101- - helloworld:v1.0.0 (%s)
103+ - helloworld:v1.0.0 (%s:%s )
102104`
103105)
104106
@@ -727,7 +729,7 @@ func TestImageUpdateAutomationReconciler_commitMessage(t *testing.T) {
727729 name : "template with update Result" ,
728730 template : testCommitTemplate ,
729731 wantCommitMsg : func (policyName , policyNS string ) string {
730- return fmt .Sprintf (testCommitMessageFmt , policyNS , policyName )
732+ return fmt .Sprintf (testCommitMessageFmt , policyNS , policyNS , policyName )
731733 },
732734 },
733735 {
@@ -841,11 +843,8 @@ Automation: %s/update-test
841843 }
842844}
843845
844- // TestImageUpdateAutomationReconciler_removedTemplateField tests removed .Updated template field usage.
846+ // TestImageUpdateAutomationReconciler_removedTemplateField tests removed template field usage (.Updated and .Changed.ImageResult) .
845847func TestImageUpdateAutomationReconciler_removedTemplateField (t * testing.T ) {
846- g := NewWithT (t )
847- ctx := context .TODO ()
848-
849848 policySpec := imagev1_reflect.ImagePolicySpec {
850849 ImageRepositoryRef : meta.NamespacedObjectReference {
851850 Name : "not-expected-to-exist" ,
@@ -859,7 +858,14 @@ func TestImageUpdateAutomationReconciler_removedTemplateField(t *testing.T) {
859858 fixture := "testdata/appconfig"
860859 latest := "helloworld:v1.0.0"
861860
862- removedTemplate := `Commit summary
861+ testCases := []struct {
862+ name string
863+ template string
864+ expectedErrMsg string
865+ }{
866+ {
867+ name : ".Updated field" ,
868+ template : `Commit summary
863869
864870Automation: {{ .AutomationObject }}
865871
@@ -881,55 +887,88 @@ Images:
881887{{ range .Updated.Images -}}
882888- {{.}} ({{.Policy.Name}})
883889{{ end -}}
884- `
890+ ` ,
891+ expectedErrMsg : "template uses removed '.Updated' field" ,
892+ },
893+ {
894+ name : ".Changed.ImageResult field" ,
895+ template : `Commit summary
885896
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 ()) }()
897+ Automation: {{ .AutomationObject }}
889898
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- })
899+ Files:
900+ {{ range $filename, $_ := .Changed.ImageResult.Files -}}
901+ - {{ $filename }}
902+ {{ end -}}
900903
901- preChangeCommitId := testutil .CommitIdFromBranch (localRepo , s .branch )
902- waitForNewHead (g , localRepo , s .branch , preChangeCommitId )
903- preChangeCommitId = testutil .CommitIdFromBranch (localRepo , s .branch )
904+ Objects:
905+ {{ range $resource, $_ := .Changed.ImageResult.Objects -}}
906+ - {{ $resource.Kind }} {{ $resource.Name }}
907+ {{ end -}}
904908
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+ Images:
910+ {{ range .Changed.ImageResult.Images -}}
911+ - {{.}} ({{.Policy.Name}})
912+ {{ end -}}
913+ ` ,
914+ expectedErrMsg : "template uses removed '.Changed.ImageResult' field" ,
915+ },
916+ }
917+
918+ for _ , tc := range testCases {
919+ t .Run (tc .name , func (t * testing.T ) {
920+ g := NewWithT (t )
921+ ctx := context .TODO ()
922+
923+ namespace , err := testEnv .CreateNamespace (ctx , "image-auto-test" )
909924 g .Expect (err ).ToNot (HaveOccurred ())
910- defer func () {
911- g .Expect (deleteImageUpdateAutomation (ctx , testEnv , "update-test" , s .namespace )).To (Succeed ())
912- }()
925+ defer func () { g .Expect (testEnv .Delete (ctx , namespace )).To (Succeed ()) }()
913926
914- imageUpdateKey := types.NamespacedName {
915- Namespace : s .namespace ,
916- Name : "update-test" ,
917- }
927+ testWithRepoAndImagePolicy (
928+ ctx , g , testEnv , namespace .Name , fixture , policySpec , latest ,
929+ func (g * WithT , s repoAndPolicyArgs , repoURL string , localRepo * extgogit.Repository ) {
930+ policyKey := types.NamespacedName {
931+ Name : s .imagePolicyName ,
932+ Namespace : s .namespace ,
933+ }
934+ _ = testutil .CommitInRepo (ctx , g , repoURL , s .branch , originRemote , "Install setter marker" , func (tmp string ) {
935+ g .Expect (testutil .ReplaceMarker (filepath .Join (tmp , "deploy.yaml" ), policyKey )).To (Succeed ())
936+ })
918937
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 ())
938+ preChangeCommitId := testutil .CommitIdFromBranch (localRepo , s .branch )
939+ waitForNewHead (g , localRepo , s .branch , preChangeCommitId )
940+ preChangeCommitId = testutil .CommitIdFromBranch (localRepo , s .branch )
928941
929- head , _ := localRepo .Head ()
930- g .Expect (head .Hash ().String ()).To (Equal (preChangeCommitId ))
931- },
932- )
942+ updateStrategy := & imagev1.UpdateStrategy {
943+ Strategy : imagev1 .UpdateStrategySetters ,
944+ }
945+ err := createImageUpdateAutomation (ctx , testEnv , "update-test" , s .namespace , s .gitRepoName , s .gitRepoNamespace , s .branch , s .branch , "" , tc .template , "" , updateStrategy )
946+ g .Expect (err ).ToNot (HaveOccurred ())
947+ defer func () {
948+ g .Expect (deleteImageUpdateAutomation (ctx , testEnv , "update-test" , s .namespace )).To (Succeed ())
949+ }()
950+
951+ imageUpdateKey := types.NamespacedName {
952+ Namespace : s .namespace ,
953+ Name : "update-test" ,
954+ }
955+
956+ g .Eventually (func () bool {
957+ var imageUpdate imagev1.ImageUpdateAutomation
958+ _ = testEnv .Get (context .TODO (), imageUpdateKey , & imageUpdate )
959+ stalledCondition := apimeta .FindStatusCondition (imageUpdate .Status .Conditions , meta .StalledCondition )
960+ return stalledCondition != nil &&
961+ stalledCondition .Status == metav1 .ConditionTrue &&
962+ stalledCondition .Reason == imagev1 .RemovedTemplateFieldReason &&
963+ strings .Contains (stalledCondition .Message , tc .expectedErrMsg )
964+ }, timeout ).Should (BeTrue ())
965+
966+ head , _ := localRepo .Head ()
967+ g .Expect (head .Hash ().String ()).To (Equal (preChangeCommitId ))
968+ },
969+ )
970+ })
971+ }
933972}
934973
935974func TestImageUpdateAutomationReconciler_crossNamespaceRef (t * testing.T ) {
@@ -966,7 +1005,7 @@ func TestImageUpdateAutomationReconciler_crossNamespaceRef(t *testing.T) {
9661005 testWithCustomRepoAndImagePolicy (
9671006 ctx , g , testEnv , fixture , policySpec , latest , args ,
9681007 func (g * WithT , s repoAndPolicyArgs , repoURL string , localRepo * extgogit.Repository ) {
969- commitMessage := fmt .Sprintf (testCommitMessageFmt , s .namespace , s .imagePolicyName )
1008+ commitMessage := fmt .Sprintf (testCommitMessageFmt , s .namespace , s .namespace , s . imagePolicyName )
9701009
9711010 // Update the setter marker in the repo.
9721011 policyKey := types.NamespacedName {
0 commit comments