Skip to content

Commit eb7ca1f

Browse files
committed
Record the last pushed SHA1 and the time it was pushed
This adds fields to the ImageUpdateAutomation status for recording the commit last pushed; handy to see when you are expecting a change. It also adapts the "steady state" message of the ready condition to mention the last commit, in case that's where people are looking. Signed-off-by: Michael Bridgen <[email protected]>
1 parent 0756eee commit eb7ca1f

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

api/v1alpha1/imageupdateautomation_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ type ImageUpdateAutomationStatus struct {
9494
// made).
9595
// +optional
9696
LastAutomationRunTime *metav1.Time `json:"lastAutomationRunTime,omitempty"`
97+
// LastPushCommit records the SHA1 of the last commit made by the
98+
// controller, for this automation object
99+
// +optional
100+
LastPushCommit string `json:"lastPushCommit,omitempty"`
101+
// LastPushTime records the time of the last pushed change.
102+
// +optional
103+
LastPushTime *metav1.Time `json:"lastPushTime,omitempty"`
97104
// +optional
98105
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
99106
// +optional

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/image.toolkit.fluxcd.io_imageupdateautomations.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ spec:
187187
description: LastHandledReconcileAt holds the value of the most recent
188188
reconcile request value, so a change can be detected.
189189
type: string
190+
lastPushCommit:
191+
description: LastPushCommit records the SHA1 of the last commit made
192+
by the controller, for this automation object
193+
type: string
194+
lastPushTime:
195+
description: LastPushTime records the time of the last pushed change.
196+
format: date-time
197+
type: string
190198
observedGeneration:
191199
format: int64
192200
type: integer

controllers/imageupdateautomation_controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,17 @@ func (r *ImageUpdateAutomationReconciler) Reconcile(req ctrl.Request) (ctrl.Resu
199199
r.event(auto, events.EventSeverityInfo, "no updates made")
200200
log.V(debug).Info("no changes made in working directory; no commit")
201201
statusMessage = "no updates made"
202+
if lastCommit, lastTime := auto.Status.LastPushCommit, auto.Status.LastPushTime; lastCommit != "" {
203+
statusMessage = fmt.Sprintf("%s; last commit %s at %s", statusMessage, lastCommit, lastTime.Format(time.RFC3339))
204+
}
202205
} else {
203206
return failWithError(err)
204207
}
205208
} else {
206209
r.event(auto, events.EventSeverityInfo, "committed and pushed change "+rev)
207210
log.Info("pushed commit to origin", "revision", rev)
211+
auto.Status.LastPushCommit = rev
212+
auto.Status.LastPushTime = &metav1.Time{Time: now}
208213
statusMessage = "committed and pushed " + rev
209214
}
210215

controllers/update_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ var _ = Describe("ImageUpdateAutomation", func() {
241241
Expect(err).ToNot(HaveOccurred())
242242
Expect(commit.Message).To(Equal(commitMessage))
243243

244+
var newObj imagev1.ImageUpdateAutomation
245+
Expect(k8sClient.Get(context.Background(), updateKey, &newObj)).To(Succeed())
246+
Expect(newObj.Status.LastPushCommit).To(Equal(head.Hash().String()))
247+
Expect(newObj.Status.LastPushTime).ToNot(BeNil())
248+
244249
compareRepoWithExpected(repoURL, branch, "testdata/appconfig-setters-expected", func(tmp string) {
245250
replaceMarker(tmp, policyKey)
246251
})

0 commit comments

Comments
 (0)