Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support adding any annotation to functions spec annotations #1346

Merged
merged 2 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading