diff --git a/components/serverless/internal/controllers/serverless/function_reconcile_test.go b/components/serverless/internal/controllers/serverless/function_reconcile_test.go index f93801c6e..66caddc44 100644 --- a/components/serverless/internal/controllers/serverless/function_reconcile_test.go +++ b/components/serverless/internal/controllers/serverless/function_reconcile_test.go @@ -1324,7 +1324,7 @@ func TestFunctionReconciler_Reconcile(t *testing.T) { assertSuccessfulFunctionBuild(t, resourceClient, reconciler, request, fnLabels) assertSuccessfulFunctionDeployment(t, resourceClient, reconciler, request, fnLabels) - t.Log("updating deployment.spec.template.metadata.annotations, e.g. by using kubectl rollout restart command") + t.Log("updating deployment.spec.template.metadata.annotations, e.g. by using kubectl rollout restart command and one custom annotation") deployments := &appsv1.DeploymentList{} g.Expect(resourceClient.ListByLabel(context.TODO(), request.Namespace, fnLabels, deployments)).To(gomega.Succeed()) g.Expect(len(deployments.Items)).To(gomega.Equal(1)) @@ -1336,8 +1336,11 @@ func TestFunctionReconciler_Reconcile(t *testing.T) { copiedDeploy := deployment.DeepCopy() const restartedAtAnnotationKey = "kubectl.kubernetes.io/restartedAt" const restartedAtAnnotationValue = "2021-03-10T11:28:01+01:00" + const customAnnotationKey = "test" + const customAnnotationValue = "value" restartedAtAnnotation := map[string]string{ restartedAtAnnotationKey: restartedAtAnnotationValue, // example annotation added by kubectl + customAnnotationKey: customAnnotationValue, } copiedDeploy.Spec.Template.Annotations = restartedAtAnnotation g.Expect(resourceClient.Update(context.Background(), copiedDeploy)) @@ -1373,6 +1376,7 @@ func TestFunctionReconciler_Reconcile(t *testing.T) { g.Expect(deployment).ToNot(gomega.BeNil()) g.Expect(deployment.Spec.Template.Annotations).To(gomega.HaveKeyWithValue(restartedAtAnnotationKey, restartedAtAnnotationValue)) + g.Expect(deployment.Spec.Template.Annotations).To(gomega.HaveKeyWithValue(customAnnotationKey, customAnnotationValue)) }) t.Run("should reconcile function with RuntimeImageOverride", func(t *testing.T) { diff --git a/components/serverless/internal/controllers/serverless/system_state.go b/components/serverless/internal/controllers/serverless/system_state.go index 680b0a497..735e7ecb8 100644 --- a/components/serverless/internal/controllers/serverless/system_state.go +++ b/components/serverless/internal/controllers/serverless/system_state.go @@ -386,25 +386,20 @@ func (s *systemState) podAnnotations() map[string]string { if s.instance.Spec.Annotations != nil { result = labels.Merge(s.instance.Spec.Annotations, result) } - result = labels.Merge(s.specialDeploymentAnnotations(), result) + + // merge old and new annotations to allow other components to annotate functions deployment + // for example in case when someone use `kubectl rollout restart` on it + result = labels.Merge(s.currentAnnotations(), result) return result } -func (s *systemState) specialDeploymentAnnotations() map[string]string { +func (s *systemState) currentAnnotations() map[string]string { deployments := s.deployments.Items if len(deployments) == 0 { return map[string]string{} } - deploymentAnnotations := deployments[0].Spec.Template.GetAnnotations() - specialDeploymentAnnotations := map[string]string{} - for _, k := range []string{ - "kubectl.kubernetes.io/restartedAt", - } { - if v, found := deploymentAnnotations[k]; found { - specialDeploymentAnnotations[k] = v - } - } - return specialDeploymentAnnotations + + return deployments[0].Spec.Template.GetAnnotations() } type buildDeploymentArgs struct {