Skip to content

Commit

Permalink
Cherry-Pick: Support adding any annotation to functions spec annotati…
Browse files Browse the repository at this point in the history
…ons (#1353)
  • Loading branch information
pPrecel authored Dec 31, 2024
1 parent 0a0419a commit 7e0deed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7e0deed

Please sign in to comment.