@@ -71,12 +71,12 @@ const (
71
71
Automation: {{ .AutomationObject }}
72
72
73
73
Files:
74
- {{ range $filename, $_ := .Updated.Files -}}
74
+ {{ range $filename, $_ := .Changed.FileChanges -}}
75
75
- {{ $filename }}
76
76
{{ end -}}
77
77
78
78
Objects:
79
- {{ range $resource, $_ := .Updated .Objects -}}
79
+ {{ range $resource, $_ := .Changed .Objects -}}
80
80
{{ if eq $resource.Kind "Deployment" -}}
81
81
- {{ $resource.Kind | lower }} {{ $resource.Name | lower }}
82
82
{{ else -}}
@@ -85,8 +85,10 @@ Objects:
85
85
{{ end -}}
86
86
87
87
Images:
88
- {{ range .Updated.Images -}}
89
- - {{.}} ({{.Policy.Name}})
88
+ {{ range .Changed.Changes -}}
89
+ {{ if .Setter -}}
90
+ - {{.NewValue}} ({{.Setter}})
91
+ {{ end -}}
90
92
{{ end -}}
91
93
`
92
94
testCommitMessageFmt = `Commit summary
@@ -98,7 +100,7 @@ Files:
98
100
Objects:
99
101
- deployment test
100
102
Images:
101
- - helloworld:v1.0.0 (%s)
103
+ - helloworld:v1.0.0 (%s:%s )
102
104
`
103
105
)
104
106
@@ -727,7 +729,7 @@ func TestImageUpdateAutomationReconciler_commitMessage(t *testing.T) {
727
729
name : "template with update Result" ,
728
730
template : testCommitTemplate ,
729
731
wantCommitMsg : func (policyName , policyNS string ) string {
730
- return fmt .Sprintf (testCommitMessageFmt , policyNS , policyName )
732
+ return fmt .Sprintf (testCommitMessageFmt , policyNS , policyNS , policyName )
731
733
},
732
734
},
733
735
{
@@ -841,6 +843,134 @@ Automation: %s/update-test
841
843
}
842
844
}
843
845
846
+ // TestImageUpdateAutomationReconciler_removedTemplateField tests removed template field usage (.Updated and .Changed.ImageResult).
847
+ func TestImageUpdateAutomationReconciler_removedTemplateField (t * testing.T ) {
848
+ policySpec := imagev1_reflect.ImagePolicySpec {
849
+ ImageRepositoryRef : meta.NamespacedObjectReference {
850
+ Name : "not-expected-to-exist" ,
851
+ },
852
+ Policy : imagev1_reflect.ImagePolicyChoice {
853
+ SemVer : & imagev1_reflect.SemVerPolicy {
854
+ Range : "1.x" ,
855
+ },
856
+ },
857
+ }
858
+ fixture := "testdata/appconfig"
859
+ latest := "helloworld:v1.0.0"
860
+
861
+ testCases := []struct {
862
+ name string
863
+ template string
864
+ expectedErrMsg string
865
+ }{
866
+ {
867
+ name : ".Updated field" ,
868
+ template : `Commit summary
869
+
870
+ Automation: {{ .AutomationObject }}
871
+
872
+ Files:
873
+ {{ range $filename, $_ := .Updated.Files -}}
874
+ - {{ $filename }}
875
+ {{ end -}}
876
+
877
+ Objects:
878
+ {{ range $resource, $_ := .Updated.Objects -}}
879
+ {{ if eq $resource.Kind "Deployment" -}}
880
+ - {{ $resource.Kind | lower }} {{ $resource.Name | lower }}
881
+ {{ else -}}
882
+ - {{ $resource.Kind }} {{ $resource.Name }}
883
+ {{ end -}}
884
+ {{ end -}}
885
+
886
+ Images:
887
+ {{ range .Updated.Images -}}
888
+ - {{.}} ({{.Policy.Name}})
889
+ {{ end -}}
890
+ ` ,
891
+ expectedErrMsg : "template uses removed '.Updated' field" ,
892
+ },
893
+ {
894
+ name : ".Changed.ImageResult field" ,
895
+ template : `Commit summary
896
+
897
+ Automation: {{ .AutomationObject }}
898
+
899
+ Files:
900
+ {{ range $filename, $_ := .Changed.ImageResult.Files -}}
901
+ - {{ $filename }}
902
+ {{ end -}}
903
+
904
+ Objects:
905
+ {{ range $resource, $_ := .Changed.ImageResult.Objects -}}
906
+ - {{ $resource.Kind }} {{ $resource.Name }}
907
+ {{ end -}}
908
+
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" )
924
+ g .Expect (err ).ToNot (HaveOccurred ())
925
+ defer func () { g .Expect (testEnv .Delete (ctx , namespace )).To (Succeed ()) }()
926
+
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
+ })
937
+
938
+ preChangeCommitId := testutil .CommitIdFromBranch (localRepo , s .branch )
939
+ waitForNewHead (g , localRepo , s .branch , preChangeCommitId )
940
+ preChangeCommitId = testutil .CommitIdFromBranch (localRepo , s .branch )
941
+
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
+ }
972
+ }
973
+
844
974
func TestImageUpdateAutomationReconciler_crossNamespaceRef (t * testing.T ) {
845
975
g := NewWithT (t )
846
976
policySpec := imagev1_reflect.ImagePolicySpec {
@@ -875,7 +1005,7 @@ func TestImageUpdateAutomationReconciler_crossNamespaceRef(t *testing.T) {
875
1005
testWithCustomRepoAndImagePolicy (
876
1006
ctx , g , testEnv , fixture , policySpec , latest , args ,
877
1007
func (g * WithT , s repoAndPolicyArgs , repoURL string , localRepo * extgogit.Repository ) {
878
- commitMessage := fmt .Sprintf (testCommitMessageFmt , s .namespace , s .imagePolicyName )
1008
+ commitMessage := fmt .Sprintf (testCommitMessageFmt , s .namespace , s .namespace , s . imagePolicyName )
879
1009
880
1010
// Update the setter marker in the repo.
881
1011
policyKey := types.NamespacedName {
0 commit comments