@@ -69,6 +69,13 @@ const defaultMessageTemplate = `Update from image update automation`
6969const repoRefKey = ".spec.gitRepository"
7070const imagePolicyKey = ".spec.update.imagePolicy"
7171
72+ // TemplateData is the type of the value given to the commit message
73+ // template.
74+ type TemplateData struct {
75+ AutomationObject types.NamespacedName
76+ Updated update.Result
77+ }
78+
7279// ImageUpdateAutomationReconciler reconciles a ImageUpdateAutomation object
7380type ImageUpdateAutomationReconciler struct {
7481 client.Client
@@ -85,6 +92,7 @@ type ImageUpdateAutomationReconciler struct {
8592func (r * ImageUpdateAutomationReconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (ctrl.Result , error ) {
8693 log := logr .FromContext (ctx )
8794 now := time .Now ()
95+ var templateValues TemplateData
8896
8997 var auto imagev1.ImageUpdateAutomation
9098 if err := r .Get (ctx , req .NamespacedName , & auto ); err != nil {
@@ -96,6 +104,8 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
96104 return ctrl.Result {}, nil
97105 }
98106
107+ templateValues .AutomationObject = req .NamespacedName
108+
99109 // Record readiness metric when exiting; if there's any points at
100110 // which the readiness is updated _without also exiting_, they
101111 // should also record the readiness.
@@ -178,8 +188,10 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
178188 return failWithError (err )
179189 }
180190
181- if err := updateAccordingToSetters (ctx , tmp , policies .Items ); err != nil {
191+ if result , err := updateAccordingToSetters (ctx , tmp , policies .Items ); err != nil {
182192 return failWithError (err )
193+ } else {
194+ templateValues .Updated = result
183195 }
184196 default :
185197 log .Info ("no update strategy given in the spec" )
@@ -197,7 +209,7 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(ctx context.Context, req ctr
197209 // The status message depends on what happens next. Since there's
198210 // more than one way to succeed, there's some if..else below, and
199211 // early returns only on failure.
200- if rev , err := commitAll (ctx , repo , & auto .Spec .Commit ); err != nil {
212+ if rev , err := commitAll (ctx , repo , & auto .Spec .Commit , templateValues ); err != nil {
201213 if err == errNoChanges {
202214 r .event (ctx , auto , events .EventSeverityInfo , "no updates made" )
203215 log .V (debug ).Info ("no changes made in working directory; no commit" )
@@ -348,7 +360,7 @@ func cloneInto(ctx context.Context, access repoAccess, branch, path, impl string
348360
349361var errNoChanges error = errors .New ("no changes made to working directory" )
350362
351- func commitAll (ctx context.Context , repo * gogit.Repository , commit * imagev1.CommitSpec ) (string , error ) {
363+ func commitAll (ctx context.Context , repo * gogit.Repository , commit * imagev1.CommitSpec , values TemplateData ) (string , error ) {
352364 working , err := repo .Worktree ()
353365 if err != nil {
354366 return "" , err
@@ -370,7 +382,7 @@ func commitAll(ctx context.Context, repo *gogit.Repository, commit *imagev1.Comm
370382 return "" , err
371383 }
372384 buf := & strings.Builder {}
373- if err := tmpl .Execute (buf , "no data! yet" ); err != nil {
385+ if err := tmpl .Execute (buf , values ); err != nil {
374386 return "" , err
375387 }
376388
@@ -523,6 +535,6 @@ func (r *ImageUpdateAutomationReconciler) recordReadinessMetric(ctx context.Cont
523535
524536// updateAccordingToSetters updates files under the root by treating
525537// the given image policies as kyaml setters.
526- func updateAccordingToSetters (ctx context.Context , path string , policies []imagev1_reflect.ImagePolicy ) error {
538+ func updateAccordingToSetters (ctx context.Context , path string , policies []imagev1_reflect.ImagePolicy ) (update. Result , error ) {
527539 return update .UpdateWithSetters (path , path , policies )
528540}
0 commit comments