@@ -71,12 +71,12 @@ const (
71
71
Automation: {{ .AutomationObject }}
72
72
73
73
Files:
74
- {{ range $filename, $_ := .Changed.ImageResult.Files -}}
74
+ {{ range $filename, $_ := .Changed.FileChanges -}}
75
75
- {{ $filename }}
76
76
{{ end -}}
77
77
78
78
Objects:
79
- {{ range $resource, $_ := .Changed.ImageResult. 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 .Changed.ImageResult.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,11 +843,8 @@ Automation: %s/update-test
841
843
}
842
844
}
843
845
844
- // TestImageUpdateAutomationReconciler_removedTemplateField tests removed .Updated template field usage.
846
+ // TestImageUpdateAutomationReconciler_removedTemplateField tests removed template field usage (.Updated and .Changed.ImageResult) .
845
847
func TestImageUpdateAutomationReconciler_removedTemplateField (t * testing.T ) {
846
- g := NewWithT (t )
847
- ctx := context .TODO ()
848
-
849
848
policySpec := imagev1_reflect.ImagePolicySpec {
850
849
ImageRepositoryRef : meta.NamespacedObjectReference {
851
850
Name : "not-expected-to-exist" ,
@@ -859,7 +858,14 @@ func TestImageUpdateAutomationReconciler_removedTemplateField(t *testing.T) {
859
858
fixture := "testdata/appconfig"
860
859
latest := "helloworld:v1.0.0"
861
860
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
863
869
864
870
Automation: {{ .AutomationObject }}
865
871
@@ -881,55 +887,88 @@ Images:
881
887
{{ range .Updated.Images -}}
882
888
- {{.}} ({{.Policy.Name}})
883
889
{{ end -}}
884
- `
890
+ ` ,
891
+ expectedErrMsg : "template uses removed '.Updated' field" ,
892
+ },
893
+ {
894
+ name : ".Changed.ImageResult field" ,
895
+ template : `Commit summary
885
896
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 }}
889
898
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 -}}
900
903
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 -}}
904
908
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" )
909
924
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 ()) }()
913
926
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
+ })
918
937
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 )
928
941
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
+ }
933
972
}
934
973
935
974
func TestImageUpdateAutomationReconciler_crossNamespaceRef (t * testing.T ) {
@@ -966,7 +1005,7 @@ func TestImageUpdateAutomationReconciler_crossNamespaceRef(t *testing.T) {
966
1005
testWithCustomRepoAndImagePolicy (
967
1006
ctx , g , testEnv , fixture , policySpec , latest , args ,
968
1007
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 )
970
1009
971
1010
// Update the setter marker in the repo.
972
1011
policyKey := types.NamespacedName {
0 commit comments