Skip to content

Commit c710ab1

Browse files
committed
Record middleware update events in status history
1 parent d0a7294 commit c710ab1

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

internal/controller/function_controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ func (r *FunctionReconciler) handleMiddlewareUpdate(ctx context.Context, functio
266266
function.Status.Middleware.PendingRebuild = false
267267
function.Status.Middleware.LastRebuild = metav1.Now()
268268

269+
function.RecordHistoryEvent(fmt.Sprintf("Middleware updated from %q to %q", functionDescribe.Middleware.Version, latestMiddleware))
270+
269271
// After successful deployment, middleware is now up-to-date
270272
function.MarkMiddlewareUpToDate()
271273
function.Status.Middleware.Available = nil // if function is on latest, we don't need to show this field

internal/controller/function_controller_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,49 @@ var _ = Describe("Function Controller", func() {
354354
Expect(readyCond.Status).To(Equal(metav1.ConditionFalse))
355355
},
356356
}),
357+
Entry("should record history event when middleware is redeployed", reconcileTestCase{
358+
spec: defaultSpec,
359+
configureMocks: func(funcMock *funccli.MockManager, gitMock *git.MockManager) {
360+
funcMock.EXPECT().Describe(mock.Anything, functionName, resourceNamespace).Return(functions.Instance{
361+
Middleware: functions.Middleware{
362+
Version: "v1.0.0",
363+
},
364+
}, nil)
365+
funcMock.EXPECT().GetLatestMiddlewareVersion(mock.Anything, mock.Anything, mock.Anything).Return("v2.0.0", nil)
366+
funcMock.EXPECT().GetMiddlewareVersion(mock.Anything, functionName, resourceNamespace).Return("v1.0.0", nil)
367+
funcMock.EXPECT().Deploy(mock.Anything, mock.Anything, resourceNamespace, funccli.DeployOptions{}).Return(nil)
368+
369+
gitMock.EXPECT().CloneRepository(mock.Anything, "https://github.com/foo/bar", "", "my-branch", mock.Anything).Return(createTmpGitRepo(functions.Function{Name: "func-go"}), nil)
370+
},
371+
statusChecks: func(status *functionsdevv1alpha1.FunctionStatus) {
372+
messages := make([]string, len(status.History))
373+
for i, entry := range status.History {
374+
messages[i] = entry.Message
375+
}
376+
Expect(messages).To(ContainElement(`Middleware updated from "v1.0.0" to "v2.0.0"`))
377+
},
378+
}),
379+
Entry("should not record middleware history event when middleware is already up to date", reconcileTestCase{
380+
spec: defaultSpec,
381+
configureMocks: func(funcMock *funccli.MockManager, gitMock *git.MockManager) {
382+
funcMock.EXPECT().Describe(mock.Anything, functionName, resourceNamespace).Return(functions.Instance{
383+
Middleware: functions.Middleware{
384+
Version: "v1.0.0",
385+
},
386+
}, nil)
387+
funcMock.EXPECT().GetLatestMiddlewareVersion(mock.Anything, mock.Anything, mock.Anything).Return("v1.0.0", nil)
388+
funcMock.EXPECT().GetMiddlewareVersion(mock.Anything, functionName, resourceNamespace).Return("v1.0.0", nil)
389+
390+
gitMock.EXPECT().CloneRepository(mock.Anything, "https://github.com/foo/bar", "", "my-branch", mock.Anything).Return(createTmpGitRepo(functions.Function{Name: "func-go"}), nil)
391+
},
392+
statusChecks: func(status *functionsdevv1alpha1.FunctionStatus) {
393+
messages := make([]string, len(status.History))
394+
for i, entry := range status.History {
395+
messages[i] = entry.Message
396+
}
397+
Expect(messages).ToNot(ContainElement(ContainSubstring("Middleware updated")))
398+
},
399+
}),
357400
Entry("should set ServiceReady condition to false with unknown reason when ready status is empty", reconcileTestCase{
358401
spec: defaultSpec,
359402
configureMocks: func(funcMock *funccli.MockManager, gitMock *git.MockManager) {

0 commit comments

Comments
 (0)