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

Add support for deployment annotations #582

Conversation

mark-hofmeijer
Copy link
Contributor

@mark-hofmeijer mark-hofmeijer commented Oct 3, 2024

What was changed

This PR adds support to define deployment annotations for the server, admintools and web components. The setup is similar to the recent implemented resource labels.

NOTE: this PR partly replaces #537, however this PR needs revision because of the templatization in PR #539.

Why?

Currently there is no option to define deployment annotations.

Checklist

  1. How was this tested:
    helm install -f values.yaml --set server.deploymentAnnotations.deployAnnotation1="serverDeploymentAnnotation" --set admintools.deploymentAnnotations.deployAnnotation1="adminDeploymentAnnotation" --set web.deploymentAnnotations.deployAnnotation1="webDeploymentAnnotation" debug . --dry-run --debug
  • In the current situation, this adds no deployment annotations on any of the components.
  • In the new situation, a deployment annotation deployAnnotation1 is added to all server services and admintools and web components.

helm install -f values.yaml --set server.deploymentAnnotations.serverAnnotation1="serverDeploymentAnnotation" --set server.frontend.deploymentAnnotations.resourceAnnotation1="resourceDeploymentAnnotation" debug . --dry-run --debug

  • In the current situation, this adds no deployment annotations on the server frontend service.
  • In the new situation, a deployment annotation resourceAnnotation1 is added to the server frontend service. The deployment annotations on server level are ignored correctly.
  • In the new situation, a deployment annotation serverAnnotation1 is added to the other server services (history, matching, worker).
  1. Any docs updates needed?
    No.

@mark-hofmeijer mark-hofmeijer requested a review from a team as a code owner October 3, 2024 20:53
@mark-hofmeijer
Copy link
Contributor Author

Refactored the helper method to the new approach introduced in #584. Also added a test.

Noted that a new line is added in front of the annotations (both on deployment and pod level), but did not manage to remove it although the setup looks the same as for labels. Maybe you can take a quick look @robholland ?

@@ -3,6 +3,10 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "temporal.componentname" (list $ "web") }}
{{- if or $.Values.additionalAnnotations $.Values.admintools.deploymentAnnotations }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{{- if or $.Values.additionalAnnotations $.Values.admintools.deploymentAnnotations }}
{{- if or $.Values.additionalAnnotations $.Values.web.deploymentAnnotations }}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On seconds thoughts lets remove the gating.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the gating.

{{- end -}}

{{/*
Additonal user specified annotations for all resources
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this just be inlined above? It's never called on it's own.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed the label version is split out. That should be inlined also, but don't worry about that for this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was indeed intended to align with the approach on the labels. But agree that inline is better, because it's not called on it's own.

@@ -3,6 +3,10 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "temporal.componentname" (list $ "admintools") }}
{{- if or $.Values.additionalAnnotations $.Values.admintools.deploymentAnnotations }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove the gating, we can just allow annotations: to be empty, it's valid syntax.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the gating.

Comment on lines 107 to 137

func TestTemplateServerDeploymentAnnotations(t *testing.T) {
// t.Parallel()

helmChartPath, err := filepath.Abs("../")
releaseName := "temporal"
require.NoError(t, err)

namespaceName := "temporal-" + strings.ToLower(random.UniqueId())

var deployment appsv1.Deployment

options := &helm.Options{
SetValues: map[string]string{
"server.frontend.deploymentAnnotations.one": "three",
"server.frontend.deploymentAnnotations.four": "four",
"server.deploymentAnnotations.one": "one",
"server.deploymentAnnotations.two": "two",
},
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
BuildDependencies: true,
}

output := helm.RenderTemplate(t, options, helmChartPath, releaseName, []string{"templates/server-deployment.yaml"})

helm.UnmarshalK8SYaml(t, output, &deployment)

require.Equal(t, "three", deployment.ObjectMeta.Annotations["one"])
require.Equal(t, "two", deployment.ObjectMeta.Annotations["two"])
require.Equal(t, "four", deployment.ObjectMeta.Annotations["four"])
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did add a value test on the additional annotations as well.

Copy link
Contributor

@robholland robholland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice :)

@robholland
Copy link
Contributor

Please merge master to get the CI fix.

@robholland robholland merged commit f380239 into temporalio:main Oct 14, 2024
3 checks passed
asproul pushed a commit to asproul/helm-charts that referenced this pull request Dec 16, 2024
* feat: add deployment annotations support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants