Skip to content

Commit e0ce143

Browse files
committed
Add the value of the last-deployed annotation to the deployment status
1 parent 241f7fb commit e0ce143

3 files changed

Lines changed: 39 additions & 2 deletions

File tree

internal/controller/function_controller.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"os"
2323
"strconv"
2424
"strings"
25+
"time"
2526

2627
"github.com/functions-dev/func-operator/internal/funccli"
2728
fn "github.com/functions-dev/func-operator/internal/function"
@@ -52,6 +53,9 @@ import (
5253
const (
5354
deployFunctionRoleName = "func-operator-deploy-function"
5455
controllerConfigName = "func-operator-controller-config"
56+
57+
funcAnnotationPrefix = "functions.knative.dev/"
58+
funcAnnotationLastDeployed = funcAnnotationPrefix + "last-deployed"
5559
)
5660

5761
// FunctionReconciler reconciles a Function object
@@ -161,6 +165,16 @@ func (r *FunctionReconciler) reconcile(ctx context.Context, function *v1alpha1.F
161165

162166
function.Status.Name = metadata.Name
163167

168+
if val, ok := function.Annotations[funcAnnotationLastDeployed]; ok {
169+
t, err := time.Parse(time.RFC3339, val)
170+
if err != nil {
171+
// log a warning, but don't return error, as this can't resolve on its own
172+
log.FromContext(ctx).Info("could not parse "+funcAnnotationLastDeployed+" annotation", "error", err)
173+
} else {
174+
function.Status.Deployment.ImageBuilt = metav1.NewTime(t)
175+
}
176+
}
177+
164178
if err := r.ensureDeployment(ctx, function, repo, metadata); err != nil {
165179
return fmt.Errorf("deploying function failed: %w", err)
166180
}
@@ -295,6 +309,7 @@ func (r *FunctionReconciler) handleMiddlewareUpdate(ctx context.Context, functio
295309

296310
function.Status.Middleware.PendingRebuild = false
297311
function.Status.Middleware.LastRebuild = metav1.Now()
312+
function.Status.Deployment.ImageBuilt = metav1.Now()
298313

299314
function.RecordHistoryEvent(fmt.Sprintf("Middleware updated from %q to %q", functionDescribe.Middleware.Version, latestMiddleware))
300315

internal/controller/function_controller_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"os"
2323
"path/filepath"
24+
"time"
2425

2526
"github.com/functions-dev/func-operator/internal/funccli"
2627
"github.com/functions-dev/func-operator/internal/git"
@@ -463,6 +464,29 @@ var _ = Describe("Function Controller", func() {
463464
Expect(annotations).NotTo(HaveKey("functions.knative.dev/reason"))
464465
},
465466
}),
467+
468+
Entry("should add last-deployed annotation in deployment status details", reconcileTestCase{
469+
spec: defaultSpec,
470+
annotations: map[string]string{
471+
funcAnnotationLastDeployed: "2026-01-02T15:04:05+06:00",
472+
},
473+
configureMocks: func(funcMock *funccli.MockManager, gitMock *git.MockManager) {
474+
funcMock.EXPECT().Describe(mock.Anything, functionName, resourceNamespace).Return(functions.Instance{
475+
Middleware: functions.Middleware{
476+
Version: "v1.0.0",
477+
},
478+
}, nil)
479+
funcMock.EXPECT().GetLatestMiddlewareVersion(mock.Anything, mock.Anything, mock.Anything).Return("v1.0.0", nil)
480+
funcMock.EXPECT().GetMiddlewareVersion(mock.Anything, functionName, resourceNamespace).Return("v1.0.0", nil)
481+
482+
gitMock.EXPECT().CloneRepository(mock.Anything, "https://github.com/foo/bar", "", "my-branch", mock.Anything).Return(createTmpGitRepo(functions.Function{Name: "func-go"}), nil)
483+
},
484+
statusChecks: func(status *functionsdevv1alpha1.FunctionStatus) {
485+
expectedTime, err := time.Parse(time.RFC3339, "2026-01-02T15:04:05+06:00")
486+
Expect(err).NotTo(HaveOccurred())
487+
Expect(status.Deployment.ImageBuilt.UTC()).To(Equal(expectedTime.UTC()))
488+
},
489+
}),
466490
Entry("should set ServiceReady condition to false with unknown reason when ready status is empty", reconcileTestCase{
467491
spec: defaultSpec,
468492
configureMocks: func(funcMock *funccli.MockManager, gitMock *git.MockManager) {

internal/controller/function_predicate.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import (
2424
"sigs.k8s.io/controller-runtime/pkg/predicate"
2525
)
2626

27-
const funcAnnotationPrefix = "functions.knative.dev/"
28-
2927
// FuncAnnotationChangedPredicate triggers reconciliation when annotations
3028
// with the "functions.knative.dev/" prefix are added or changed.
3129
type FuncAnnotationChangedPredicate struct {

0 commit comments

Comments
 (0)