From 2dd68ca241898a1fb893b5d615df3c709670b05a Mon Sep 17 00:00:00 2001 From: Alessandro Cattapan Date: Wed, 2 Oct 2024 23:52:39 +0200 Subject: [PATCH 1/4] Aligned all _supplemental files of backingservices chart with new definition tolerations --- .../constellation-messaging/templates/_supplemental.tpl | 8 ++++++++ .../charts/constellation/templates/_supplemental.tpl | 8 ++++++++ charts/backingservices/templates/_supplemental.tpl | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/charts/backingservices/charts/constellation-messaging/templates/_supplemental.tpl b/charts/backingservices/charts/constellation-messaging/templates/_supplemental.tpl index 85a9215a3..62515a7f4 100644 --- a/charts/backingservices/charts/constellation-messaging/templates/_supplemental.tpl +++ b/charts/backingservices/charts/constellation-messaging/templates/_supplemental.tpl @@ -5,6 +5,7 @@ deploymentName tlssecretsnippet backingservices.gke.backendConfig podAffinity +tolerations are copied from backingservices/templates/_supplemental.tpl because helm lint requires charts to render standalone. See: https://github.com/helm/helm/issues/11260 for more details. */}} @@ -63,4 +64,11 @@ spec: affinity: {{- toYaml .affinity | nindent 2 }} {{- end }} +{{ end }} + +{{- define "tolerations" }} +{{- if .tolerations }} +tolerations: +{{- toYaml .tolerations | nindent 2 }} +{{- end }} {{ end }} \ No newline at end of file diff --git a/charts/backingservices/charts/constellation/templates/_supplemental.tpl b/charts/backingservices/charts/constellation/templates/_supplemental.tpl index 85a9215a3..62515a7f4 100644 --- a/charts/backingservices/charts/constellation/templates/_supplemental.tpl +++ b/charts/backingservices/charts/constellation/templates/_supplemental.tpl @@ -5,6 +5,7 @@ deploymentName tlssecretsnippet backingservices.gke.backendConfig podAffinity +tolerations are copied from backingservices/templates/_supplemental.tpl because helm lint requires charts to render standalone. See: https://github.com/helm/helm/issues/11260 for more details. */}} @@ -63,4 +64,11 @@ spec: affinity: {{- toYaml .affinity | nindent 2 }} {{- end }} +{{ end }} + +{{- define "tolerations" }} +{{- if .tolerations }} +tolerations: +{{- toYaml .tolerations | nindent 2 }} +{{- end }} {{ end }} \ No newline at end of file diff --git a/charts/backingservices/templates/_supplemental.tpl b/charts/backingservices/templates/_supplemental.tpl index 0c1477177..54488afb9 100644 --- a/charts/backingservices/templates/_supplemental.tpl +++ b/charts/backingservices/templates/_supplemental.tpl @@ -5,6 +5,7 @@ deploymentName tlssecretsnippet backingservices.gke.backendConfig podAffinity +tolerations are copied from backingservices/templates/_supplemental.tpl because helm lint requires charts to render standalone. See: https://github.com/helm/helm/issues/11260 for more details. */}} @@ -63,4 +64,11 @@ spec: affinity: {{- toYaml .affinity | nindent 2 }} {{- end }} +{{ end }} + +{{- define "tolerations" }} +{{- if .tolerations }} +tolerations: +{{- toYaml .tolerations | nindent 2 }} +{{- end }} {{ end }} \ No newline at end of file From 73fc6a0c9a169ae24aa8ab60c4c484efcc19bbcf Mon Sep 17 00:00:00 2001 From: Alessandro Cattapan Date: Wed, 2 Oct 2024 23:54:07 +0200 Subject: [PATCH 2/4] Added tolerations to deployments of constellation and constellation messaging charts --- .../constellation-messaging/templates/messaging-deployment.yaml | 1 + .../charts/constellation/templates/clln-deployment.yaml | 1 + 2 files changed, 2 insertions(+) diff --git a/charts/backingservices/charts/constellation-messaging/templates/messaging-deployment.yaml b/charts/backingservices/charts/constellation-messaging/templates/messaging-deployment.yaml index 0a4ae8b0e..48ba0f86d 100644 --- a/charts/backingservices/charts/constellation-messaging/templates/messaging-deployment.yaml +++ b/charts/backingservices/charts/constellation-messaging/templates/messaging-deployment.yaml @@ -65,4 +65,5 @@ spec: ports: - containerPort: {{ $srvTargetPort }} {{- include "podAffinity" .Values | indent 6 }} +{{- include "tolerations" .Values | indent 6 }} {{ end }} diff --git a/charts/backingservices/charts/constellation/templates/clln-deployment.yaml b/charts/backingservices/charts/constellation/templates/clln-deployment.yaml index 2dcb3dc41..602de0068 100644 --- a/charts/backingservices/charts/constellation/templates/clln-deployment.yaml +++ b/charts/backingservices/charts/constellation/templates/clln-deployment.yaml @@ -76,4 +76,5 @@ spec: ports: - containerPort: {{ .Values.service.targetPort }} {{- include "podAffinity" .Values | indent 6 }} +{{- include "tolerations" .Values | indent 6 }} {{ end }} \ No newline at end of file From 6c3f34e8f41b7365653242325db39b88daa85ed1 Mon Sep 17 00:00:00 2001 From: Alessandro Cattapan Date: Thu, 3 Oct 2024 00:00:07 +0200 Subject: [PATCH 3/4] Updated docuemntation of constellation --- .../backingservices/charts/constellation-messaging/README.md | 1 + charts/backingservices/charts/constellation/README.md | 3 +++ 2 files changed, 4 insertions(+) diff --git a/charts/backingservices/charts/constellation-messaging/README.md b/charts/backingservices/charts/constellation-messaging/README.md index 88e7058c8..dd42d61c9 100644 --- a/charts/backingservices/charts/constellation-messaging/README.md +++ b/charts/backingservices/charts/constellation-messaging/README.md @@ -18,6 +18,7 @@ Complete information on the design of the service including architecture, scalab | `deployment.name` | Specify the name of your messaging service. Your deployment creates resources prefixed with this string. | | `imagePullSecretNames` | Deprected, use `docker.imagePullSecretNames`. List pre-existing secrets to be used for pulling docker images. | | `affinity` | Define pod affinity so that it is restricted to run on particular node(s), or to prefer to run on particular nodes. | +| `tolerations` | Define pod tolerations so that it is allowed to run on node(s) with particular taints. | | `docker.imagePullSecretNames` | List pre-existing secrets to be used for pulling docker images. | | `docker.registry.url` | Specify the image registry url. | | `docker.registry.username` | Specify the username for the docker registry. | diff --git a/charts/backingservices/charts/constellation/README.md b/charts/backingservices/charts/constellation/README.md index 341179bf1..043955372 100644 --- a/charts/backingservices/charts/constellation/README.md +++ b/charts/backingservices/charts/constellation/README.md @@ -67,6 +67,9 @@ The values.yaml file provides configuration options to define the values for the | `docker.messaging.imagePullPolicy` | Specify the image pull policy configurations for the image. | | `affinity` | Specify the pod affinity so that pods are restricted to run on particular node(s), or to prefer to run on particular nodes. | +| `tolerations` | Specify pod tolerations so that it is allowed to run on node(s) with particular taints. + | + Example: From fd30c001d2bd2978baa8d2cbe72bdb82a076c568 Mon Sep 17 00:00:00 2001 From: Alessandro Cattapan Date: Thu, 3 Oct 2024 00:17:25 +0200 Subject: [PATCH 4/4] Created Unit Test for new implementation and created additional controls on previous test in order to check backward compatibility of the new feature --- ...constellation-messaging-deployment_test.go | 29 +++++++++++++++++++ .../constellation-static-depoyment_test.go | 28 ++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/terratest/src/test/backingservices/constellation-messaging-deployment_test.go b/terratest/src/test/backingservices/constellation-messaging-deployment_test.go index 868a8dba6..e47fa2348 100644 --- a/terratest/src/test/backingservices/constellation-messaging-deployment_test.go +++ b/terratest/src/test/backingservices/constellation-messaging-deployment_test.go @@ -32,4 +32,33 @@ func TestConstellationMessagingDeploymentWithAffinity(t *testing.T) { require.Equal(t, "kubernetes.io/os", deploymentAffinity.NodeSelectorTerms[0].MatchExpressions[0].Key) require.Equal(t, "In", string(deploymentAffinity.NodeSelectorTerms[0].MatchExpressions[0].Operator)) require.Equal(t, "linux", deploymentAffinity.NodeSelectorTerms[0].MatchExpressions[0].Values[0]) + require.Empty(t, cllnMessagingDeploymentObj.Spec.Template.Spec.Tolerations) +} + +func TestConstellationMessagingDeploymentWithTolerations(t *testing.T) { + + helmChartParser := NewHelmConfigParser( + NewHelmTestFromTemplate(t, helmChartRelativePath, map[string]string{ + "constellation-messaging.enabled": "true", + "constellation-messaging.name": "constellation-messaging", + "constellation-messaging.tolerations[0].key": "key1", + "constellation-messaging.tolerations[0].value": "value1", + "constellation-messaging.tolerations[0].operator": "Equal", + "constellation-messaging.tolerations[0].effect": "NotSchedule", + }, + []string{"charts/constellation-messaging/templates/messaging-deployment.yaml"}), + ) + + var cllnMessagingDeploymentObj appsv1.Deployment + helmChartParser.getResourceYAML(SearchResourceOption{ + Name: "constellation-messaging", + Kind: "Deployment", + }, &cllnMessagingDeploymentObj) + + deploymentTolerations := cllnMessagingDeploymentObj.Spec.Template.Spec.Tolerations + require.Equal(t, "key1", deploymentTolerations[0].Key) + require.Equal(t, "value1", deploymentTolerations[0].Value) + require.Equal(t, "Equal", string(deploymentTolerations[0].Operator)) + require.Equal(t, "NotSchedule", string(deploymentTolerations[0].Effect)) + require.Empty(t, cllnMessagingDeploymentObj.Spec.Template.Spec.Affinity) } diff --git a/terratest/src/test/backingservices/constellation-static-depoyment_test.go b/terratest/src/test/backingservices/constellation-static-depoyment_test.go index bb8ee18ac..36573192d 100644 --- a/terratest/src/test/backingservices/constellation-static-depoyment_test.go +++ b/terratest/src/test/backingservices/constellation-static-depoyment_test.go @@ -31,4 +31,32 @@ func TestConstellationStaticDeploymentWithAffinity(t *testing.T) { require.Equal(t, "kubernetes.io/os", deploymentAffinity.NodeSelectorTerms[0].MatchExpressions[0].Key) require.Equal(t, "In", string(deploymentAffinity.NodeSelectorTerms[0].MatchExpressions[0].Operator)) require.Equal(t, "linux", deploymentAffinity.NodeSelectorTerms[0].MatchExpressions[0].Values[0]) + require.Empty(t, cllnDeploymentObj.Spec.Template.Spec.Tolerations) +} + +func TestConstellationStaticDeploymentWithTolerations(t *testing.T) { + + helmChartParser := NewHelmConfigParser( + NewHelmTestFromTemplate(t, helmChartRelativePath, map[string]string{ + "constellation.enabled": "true", + "constellation.tolerations[0].key": "key1", + "constellation.tolerations[0].value": "value1", + "constellation.tolerations[0].operator": "Equal", + "constellation.tolerations[0].effect": "NotSchedule", + }, + []string{"charts/constellation/templates/clln-deployment.yaml"}), + ) + + var cllnDeploymentObj appsv1.Deployment + helmChartParser.getResourceYAML(SearchResourceOption{ + Name: "constellation", + Kind: "Deployment", + }, &cllnDeploymentObj) + + deploymentTolerations := cllnDeploymentObj.Spec.Template.Spec.Tolerations + require.Equal(t, "key1", deploymentTolerations[0].Key) + require.Equal(t, "value1", deploymentTolerations[0].Value) + require.Equal(t, "Equal", string(deploymentTolerations[0].Operator)) + require.Equal(t, "NotSchedule", string(deploymentTolerations[0].Effect)) + require.Empty(t, cllnDeploymentObj.Spec.Template.Spec.Affinity) }