From fbf05893a507dcf805304036422e86997a009d29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9na=C3=AFc=20Huard?= Date: Fri, 13 Dec 2019 18:25:08 +0100 Subject: [PATCH] [stable/datadog] Add validity checks on clusterName (#19327) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cluster name parameter has been introduced to disambiguate nodes having the same name in different clusters. Cluster names are, for ex., used to build hostnames and must therefore comply with some rules. We enforce here the same rules as the ones enforced by GKE: https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#Cluster.FIELDS.name The DataDog agent itself is already checking the validity of cluster names since DataDog/datadog-agent#4492. The goal of this change in the helm chart is to catch issues as early as possible because having a clear error message from helm is smarter than having to dig in the logs of a failing agent. Signed-off-by: Lénaïc Huard --- stable/datadog/Chart.yaml | 2 +- stable/datadog/templates/cluster-agent-deployment.yaml | 3 +++ stable/datadog/templates/container-agent.yaml | 3 +++ stable/datadog/templates/container-agents.yaml | 3 +++ stable/datadog/values.yaml | 6 ++++++ 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/stable/datadog/Chart.yaml b/stable/datadog/Chart.yaml index 24f5749c30..bf3c64250c 100644 --- a/stable/datadog/Chart.yaml +++ b/stable/datadog/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v1 name: datadog -version: 1.38.11 +version: 1.38.12 appVersion: "6" description: DataDog Agent keywords: diff --git a/stable/datadog/templates/cluster-agent-deployment.yaml b/stable/datadog/templates/cluster-agent-deployment.yaml index 289d6e045e..a39a789c4a 100644 --- a/stable/datadog/templates/cluster-agent-deployment.yaml +++ b/stable/datadog/templates/cluster-agent-deployment.yaml @@ -101,6 +101,9 @@ spec: value: "kube_services" {{- end }} {{- if .Values.datadog.clusterName }} + {{- if not (regexMatch "^[a-z]([a-z0-9\\-]{0,38}[a-z0-9])?$" .Values.datadog.clusterName) }} + {{- fail "Your `clusterName` isn’t valid. It must start with a lowercase letter followed by up to 39 lowercase letters, numbers, or hyphens and cannot end with a hyphen."}} + {{- end}} - name: DD_CLUSTER_NAME value: {{ .Values.datadog.clusterName | quote }} {{- end }} diff --git a/stable/datadog/templates/container-agent.yaml b/stable/datadog/templates/container-agent.yaml index 1ae03a1dd7..516e535246 100644 --- a/stable/datadog/templates/container-agent.yaml +++ b/stable/datadog/templates/container-agent.yaml @@ -15,6 +15,9 @@ env: {{- include "containers-common-env" . | nindent 4 }} {{- if .Values.datadog.clusterName }} + {{- if not (regexMatch "^[a-z]([a-z0-9\\-]{0,38}[a-z0-9])?$" .Values.datadog.clusterName) }} + {{- fail "Your `clusterName` isn’t valid. It must start with a lowercase letter followed by up to 39 lowercase letters, numbers, or hyphens and cannot end with a hyphen."}} + {{- end}} - name: DD_CLUSTER_NAME value: {{ .Values.datadog.clusterName | quote }} {{- end }} diff --git a/stable/datadog/templates/container-agents.yaml b/stable/datadog/templates/container-agents.yaml index 4c293138c5..845176163a 100644 --- a/stable/datadog/templates/container-agents.yaml +++ b/stable/datadog/templates/container-agents.yaml @@ -26,6 +26,9 @@ name: {{ template "datadog.apiSecretName" . }} key: api-key {{- if .Values.datadog.clusterName }} + {{- if not (regexMatch "^[a-z]([a-z0-9\\-]{0,38}[a-z0-9])?$" .Values.datadog.clusterName) }} + {{- fail "Your `clusterName` isn’t valid. It must start with a lowercase letter followed by up to 39 lowercase letters, numbers, or hyphens and cannot end with a hyphen."}} + {{- end}} - name: DD_CLUSTER_NAME value: {{ .Values.datadog.clusterName | quote }} {{- end }} diff --git a/stable/datadog/values.yaml b/stable/datadog/values.yaml index 40baa5450e..2e60735444 100644 --- a/stable/datadog/values.yaml +++ b/stable/datadog/values.yaml @@ -71,6 +71,12 @@ datadog: ## @param clusterName - string - optional ## Set a unique cluster name to allow scoping hosts and Cluster Checks easily + ## The name must be unique and can be up to 40 characters with the following restrictions: + ## * Lowercase letters, numbers, and hyphens only. + ## * Must start with a letter. + ## * Must end with a number or a letter. + ## These are the same rules as the one enforced by GKE on the same cluster name parameter: + ## https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#Cluster.FIELDS.name # # clusterName: