diff --git a/docs/installation/01_installation.adoc b/docs/installation/01_installation.adoc index d9d2b2d3..be27dad6 100644 --- a/docs/installation/01_installation.adoc +++ b/docs/installation/01_installation.adoc @@ -26,6 +26,8 @@ easily be installed into a Kubernetes cluster. *** <> *** <> *** <> +*** <> +*** <> *** <> ** <> ** <> @@ -433,6 +435,196 @@ helm install \ coherence/coherence-operator ---- +[#helm-labels] +=== Set Additional Labels + +When installing the Operator with Helm, it is possible to set additional labels to be applied to the Operator Pods +and to the Operator Deployment. + +==== Adding Pod Labels + +To add labels to the Operator Pods set the `labels` value, either on the command line using `--set` or in the values file. + +[NOTE] +==== +Setting `labels` will only apply the additional labels to the Operator Pods, they will not be applied to any other resource created by the Helm chart. +==== + +For example, using the command line: + +[source,bash] +---- +helm install \ + --namespace \ + --set labels.one=value-one \ + --set labels.two=value-two \ + coherence \ + coherence/coherence-operator +---- + +The command above would add the following additional labels `one` and `two` to the Operator Pod as shown below: + +[source,yaml] +---- +apiVersion: v1 +kind: Pod +metadata: + name: coherence-operator + labels: + one: value-one + two: value-two +---- + +The same labels could also be specified in a values file: + +[source] +.add-labels-values.yaml +---- +labels: + one: value-one + two: value-two +---- + +==== Adding Deployment Labels + +To add labels to the Operator Deployment set the `deploymentLabels` value, either on the command line using `--set` or in the values file. + +[NOTE] +==== +Setting `deploymentLabels` will only apply the additional labels to the Deployment, they will not be applied to any other resource created by the Helm chart. +==== + +For example, using the command line: + +[source,bash] +---- +helm install \ + --namespace \ + --set deploymentLabels.one=value-one \ + --set deploymentLabels.two=value-two \ + coherence \ + coherence/coherence-operator +---- + +The command above would add the following additional labels `one` and `two` to the Operator Pod as shown below: + +[source,yaml] +---- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: coherence-operator + labels: + one: value-one + two: value-two +---- + +The same labels could also be specified in a values file: + +[source] +.add-labels-values.yaml +---- +deploymentLabels: + one: value-one + two: value-two +---- + + +[#helm-annotations] +=== Set Additional Annotations + +When installing the Operator with Helm, it is possible to set additional annotations to be applied to the Operator Pods +and to the Operator Deployment. + +==== Adding Pod Annotations + +To add annotations to the Operator Pods set the `annotations` value, either on the command line using `--set` or in the values file. + +[NOTE] +==== +Setting `annotations` will only apply the additional annotations to the Operator Pods, they will not be applied to any other resource created by the Helm chart. +==== + +For example, using the command line: + +[source,bash] +---- +helm install \ + --namespace \ + --set annotations.one=value-one \ + --set annotations.two=value-two \ + coherence \ + coherence/coherence-operator +---- + +The command above would add the following additional annotations `one` and `two` to the Operator Pod as shown below: + +[source,yaml] +---- +apiVersion: v1 +kind: Pod +metadata: + name: coherence-operator + annotations: + one: value-one + two: value-two +---- + +The same annotations could also be specified in a values file: + +[source] +.add-annotations-values.yaml +---- +annotations: + one: value-one + two: value-two +---- + +==== Adding Deployment Annotations + +To add annotations to the Operator Deployment set the `deploymentAnnotations` value, either on the command line using `--set` or in the values file. + +[NOTE] +==== +Setting `deploymentAnnotations` will only apply the additional annotations to the Deployment, they will not be applied to any other resource created by the Helm chart. +==== + +For example, using the command line: + +[source,bash] +---- +helm install \ + --namespace \ + --set deploymentAnnotations.one=value-one \ + --set deploymentAnnotations.two=value-two \ + coherence \ + coherence/coherence-operator +---- + +The command above would add the following additional annotations `one` and `two` to the Operator Pod as shown below: + +[source,yaml] +---- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: coherence-operator + annotations: + one: value-one + two: value-two +---- + +The same annotations could also be specified in a values file: + +[source] +.add-annotations-values.yaml +---- +deploymentAnnotations: + one: value-one + two: value-two +---- + + [#helm-uninstall] === Uninstall the Coherence Operator Helm chart diff --git a/helm-charts/coherence-operator/templates/deployment.yaml b/helm-charts/coherence-operator/templates/deployment.yaml index a3b1f119..7bb025e7 100644 --- a/helm-charts/coherence-operator/templates/deployment.yaml +++ b/helm-charts/coherence-operator/templates/deployment.yaml @@ -69,6 +69,13 @@ metadata: app.kubernetes.io/part-of: coherence-operator app.kubernetes.io/managed-by: helm app.kubernetes.io/created-by: controller-manager +{{- if .Values.deploymentLabels }} +{{ toYaml .Values.deploymentLabels | indent 4 }} +{{- end }} +{{- if .Values.deploymentAnnotations }} + annotations: +{{ toYaml .Values.deploymentAnnotations | indent 4 }} +{{- end }} spec: replicas: {{ default 3 .Values.replicas }} selector: @@ -85,6 +92,13 @@ spec: app.kubernetes.io/part-of: coherence-operator app.kubernetes.io/managed-by: helm app.kubernetes.io/created-by: controller-manager +{{- if .Values.labels }} +{{ toYaml .Values.labels | indent 8 }} +{{- end }} +{{- if .Values.annotations }} + annotations: +{{ toYaml .Values.annotations | indent 8 }} +{{- end }} spec: serviceAccountName: {{ default "coherence-operator" .Values.serviceAccountName }} {{- if .Values.podSecurityContext }} diff --git a/helm-charts/coherence-operator/values.yaml b/helm-charts/coherence-operator/values.yaml index 6798a7dc..1126bf86 100644 --- a/helm-charts/coherence-operator/values.yaml +++ b/helm-charts/coherence-operator/values.yaml @@ -44,6 +44,22 @@ replicas: 3 # - name: "bar" imagePullSecrets: +# --------------------------------------------------------------------------- +# Additional labels that are added to the Operator Pods. +labels: + +# --------------------------------------------------------------------------- +# Additional annotations that are added to the Operator Pods. +annotations: + +# --------------------------------------------------------------------------- +# Additional labels that are added to the Operator Deployment. +deploymentLabels: + +# --------------------------------------------------------------------------- +# Additional annotations that are added to the Operator Deployment. +deploymentAnnotations: + # --------------------------------------------------------------------------- # Operator Pod securityContext # This sets the securityContext configuration for the Pod, for example diff --git a/test/e2e/helm/helm_test.go b/test/e2e/helm/helm_test.go index 95cf73e8..b83e1b78 100644 --- a/test/e2e/helm/helm_test.go +++ b/test/e2e/helm/helm_test.go @@ -364,6 +364,194 @@ func TestSetNonRootUser(t *testing.T) { AssertHelmInstallWithSubTest(t, "basic", cmd, g, AssertThreeReplicas) } +func TestSetAdditionalPodLabel(t *testing.T) { + g := NewGomegaWithT(t) + result, err := helmInstall("--set", "labels.foo=bar") + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(result).NotTo(BeNil()) + + dep := &appsv1.Deployment{} + err = result.Get("coherence-operator", dep) + g.Expect(err).NotTo(HaveOccurred()) + + labels := dep.Spec.Template.Labels + actual, found := labels["control-plane"] + g.Expect(found).To(BeTrue()) + g.Expect(actual).To(Equal("coherence")) + actual, found = labels["foo"] + g.Expect(found).To(BeTrue()) + g.Expect(actual).To(Equal("bar")) + + labels = dep.Labels + _, found = labels["foo"] + g.Expect(found).To(BeFalse()) +} + +func TestSetAdditionalPodLabels(t *testing.T) { + g := NewGomegaWithT(t) + result, err := helmInstall("--set", "labels.one=value-one", "--set", "labels.two=value-two") + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(result).NotTo(BeNil()) + + dep := &appsv1.Deployment{} + err = result.Get("coherence-operator", dep) + g.Expect(err).NotTo(HaveOccurred()) + + labels := dep.Spec.Template.Labels + actual, found := labels["control-plane"] + g.Expect(found).To(BeTrue()) + g.Expect(actual).To(Equal("coherence")) + actual, found = labels["one"] + g.Expect(found).To(BeTrue()) + g.Expect(actual).To(Equal("value-one")) + actual, found = labels["two"] + g.Expect(found).To(BeTrue()) + g.Expect(actual).To(Equal("value-two")) + + labels = dep.Labels + _, found = labels["one"] + g.Expect(found).To(BeFalse()) + _, found = labels["two"] + g.Expect(found).To(BeFalse()) +} + +func TestSetAdditionalPodAnnotation(t *testing.T) { + g := NewGomegaWithT(t) + result, err := helmInstall("--set", "annotations.foo=bar") + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(result).NotTo(BeNil()) + + dep := &appsv1.Deployment{} + err = result.Get("coherence-operator", dep) + g.Expect(err).NotTo(HaveOccurred()) + + annotations := dep.Spec.Template.Annotations + g.Expect(len(annotations)).To(Equal(1)) + actual, found := annotations["foo"] + g.Expect(found).To(BeTrue()) + g.Expect(actual).To(Equal("bar")) + + annotations = dep.Annotations + g.Expect(len(annotations)).To(BeZero()) +} + +func TestSetAdditionalPodAnnotations(t *testing.T) { + g := NewGomegaWithT(t) + result, err := helmInstall("--set", "annotations.one=value-one", "--set", "annotations.two=value-two") + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(result).NotTo(BeNil()) + + dep := &appsv1.Deployment{} + err = result.Get("coherence-operator", dep) + g.Expect(err).NotTo(HaveOccurred()) + + annotations := dep.Spec.Template.Annotations + g.Expect(len(annotations)).To(Equal(2)) + actual, found := annotations["one"] + g.Expect(found).To(BeTrue()) + g.Expect(actual).To(Equal("value-one")) + actual, found = annotations["two"] + g.Expect(found).To(BeTrue()) + g.Expect(actual).To(Equal("value-two")) + + annotations = dep.Annotations + g.Expect(len(annotations)).To(BeZero()) +} + +func TestSetAdditionalDeploymentLabel(t *testing.T) { + g := NewGomegaWithT(t) + result, err := helmInstall("--set", "deploymentLabels.foo=bar") + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(result).NotTo(BeNil()) + + dep := &appsv1.Deployment{} + err = result.Get("coherence-operator", dep) + g.Expect(err).NotTo(HaveOccurred()) + + labels := dep.Labels + actual, found := labels["control-plane"] + g.Expect(found).To(BeTrue()) + g.Expect(actual).To(Equal("coherence")) + actual, found = labels["foo"] + g.Expect(found).To(BeTrue()) + g.Expect(actual).To(Equal("bar")) + + labels = dep.Spec.Template.Labels + _, found = labels["foo"] + g.Expect(found).To(BeFalse()) +} + +func TestSetAdditionalDeploymentLabels(t *testing.T) { + g := NewGomegaWithT(t) + result, err := helmInstall("--set", "deploymentLabels.one=value-one", "--set", "deploymentLabels.two=value-two") + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(result).NotTo(BeNil()) + + dep := &appsv1.Deployment{} + err = result.Get("coherence-operator", dep) + g.Expect(err).NotTo(HaveOccurred()) + + labels := dep.Labels + actual, found := labels["control-plane"] + g.Expect(found).To(BeTrue()) + g.Expect(actual).To(Equal("coherence")) + actual, found = labels["one"] + g.Expect(found).To(BeTrue()) + g.Expect(actual).To(Equal("value-one")) + actual, found = labels["two"] + g.Expect(found).To(BeTrue()) + g.Expect(actual).To(Equal("value-two")) + + labels = dep.Spec.Template.Labels + _, found = labels["one"] + g.Expect(found).To(BeFalse()) + _, found = labels["two"] + g.Expect(found).To(BeFalse()) +} + +func TestSetAdditionalDeploymentAnnotation(t *testing.T) { + g := NewGomegaWithT(t) + result, err := helmInstall("--set", "deploymentAnnotations.foo=bar") + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(result).NotTo(BeNil()) + + dep := &appsv1.Deployment{} + err = result.Get("coherence-operator", dep) + g.Expect(err).NotTo(HaveOccurred()) + + annotations := dep.Annotations + g.Expect(len(annotations)).To(Equal(1)) + actual, found := annotations["foo"] + g.Expect(found).To(BeTrue()) + g.Expect(actual).To(Equal("bar")) + + annotations = dep.Spec.Template.Annotations + g.Expect(len(annotations)).To(BeZero()) +} + +func TestSetAdditionalDeploymentAnnotations(t *testing.T) { + g := NewGomegaWithT(t) + result, err := helmInstall("--set", "deploymentAnnotations.one=value-one", "--set", "deploymentAnnotations.two=value-two") + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(result).NotTo(BeNil()) + + dep := &appsv1.Deployment{} + err = result.Get("coherence-operator", dep) + g.Expect(err).NotTo(HaveOccurred()) + + annotations := dep.Annotations + g.Expect(len(annotations)).To(Equal(2)) + actual, found := annotations["one"] + g.Expect(found).To(BeTrue()) + g.Expect(actual).To(Equal("value-one")) + actual, found = annotations["two"] + g.Expect(found).To(BeTrue()) + g.Expect(actual).To(Equal("value-two")) + + annotations = dep.Spec.Template.Annotations + g.Expect(len(annotations)).To(BeZero()) +} + func AssertResources() error { ns := helper.GetTestNamespace() pods, err := helper.ListOperatorPods(testContext, ns)