From 30ec81c4566f04a22e534396133ea338cc66a12e Mon Sep 17 00:00:00 2001 From: Fabiano Arruda Date: Mon, 25 Mar 2024 07:59:42 +0100 Subject: [PATCH] Improve Helm chart to be rendered locally and on machines where is not the application target (#2706) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(helm): add issuer group to create the certificate without wait for the previous created issuer Signed-off-by: Fabiano Arruda Ferreira das Graças * fix(helm): remove condition that can prevent the helm chart be rendered on machines where monitoring.coreos.com is not installed or is not the end target of the helm template command Signed-off-by: fafg * fix(helm): lint - remove blank line Signed-off-by: fafg * add(helm): missing service monitor test files Signed-off-by: fafg * add(helm): add missing cert-manager test files Signed-off-by: fafg * fix(helm): lint - add missing blank lines Signed-off-by: fafg * fix(helm): rebase Signed-off-by: fafg * Revert "fix(helm): rebase" This reverts commit c4ce16b76ec27b8f68acbcccb22c4ad2b22e5972. * fix(helm): fix service monitor namespace rendering Signed-off-by: fafg * fix(helm): add missing up to date golden file Signed-off-by: fafg * fix(helm): merge upstream Signed-off-by: fafg * update golden files * also install prom operator dependencies * also install cert-manager * skip cert-manager chart * skip cert-manager value * remove CI TLS files * fix formatting * fix formatting * fix actions --------- Signed-off-by: Fabiano Arruda Ferreira das Graças Signed-off-by: fafg Co-authored-by: Tarun Pothulapati Co-authored-by: Tarun Pothulapati --- .github/actions/lint-test-chart/action.yml | 6 + .../ci/service-monitor-values.golden.yaml | 146 ++++++++++++++++++ .../dragonfly/ci/service-monitor-values.yaml | 8 + contrib/charts/dragonfly/golden_test.go | 6 +- .../dragonfly/templates/certificate.yaml | 1 + .../dragonfly/templates/servicemonitor.yaml | 8 +- contrib/charts/dragonfly/values.yaml | 3 + 7 files changed, 171 insertions(+), 7 deletions(-) create mode 100644 contrib/charts/dragonfly/ci/service-monitor-values.golden.yaml create mode 100644 contrib/charts/dragonfly/ci/service-monitor-values.yaml diff --git a/.github/actions/lint-test-chart/action.yml b/.github/actions/lint-test-chart/action.yml index a0583d315..49271bc30 100644 --- a/.github/actions/lint-test-chart/action.yml +++ b/.github/actions/lint-test-chart/action.yml @@ -45,6 +45,12 @@ runs: - name: Create kind cluster uses: helm/kind-action@v1 + - name: Install Dependencies + shell: bash + run: | + LATEST=$(curl -s https://api.github.com/repos/prometheus-operator/prometheus-operator/releases/latest | jq -cr .tag_name) + curl -sL https://github.com/prometheus-operator/prometheus-operator/releases/download/${LATEST}/bundle.yaml | kubectl create -f - + - name: Getting cluster ready shell: bash run: | diff --git a/contrib/charts/dragonfly/ci/service-monitor-values.golden.yaml b/contrib/charts/dragonfly/ci/service-monitor-values.golden.yaml new file mode 100644 index 000000000..1115ca9ce --- /dev/null +++ b/contrib/charts/dragonfly/ci/service-monitor-values.golden.yaml @@ -0,0 +1,146 @@ +--- +# Source: dragonfly/templates/serviceaccount.yaml +apiVersion: v1 +kind: ServiceAccount +metadata: + name: test-dragonfly + namespace: default + labels: + app.kubernetes.io/name: dragonfly + app.kubernetes.io/instance: test + app.kubernetes.io/version: "v1.15.1" + app.kubernetes.io/managed-by: Helm +--- +# Source: dragonfly/templates/metrics-service.yaml +apiVersion: v1 +kind: Service +metadata: + name: test-dragonfly-metrics + namespace: default + labels: + app.kubernetes.io/name: dragonfly + app.kubernetes.io/instance: test + app.kubernetes.io/version: "v1.15.1" + app.kubernetes.io/managed-by: Helm + type: metrics +spec: + type: ClusterIP + ports: + - name: metrics + port: 6379 + targetPort: 6379 + protocol: TCP + selector: + app.kubernetes.io/name: dragonfly + app.kubernetes.io/instance: test +--- +# Source: dragonfly/templates/service.yaml +apiVersion: v1 +kind: Service +metadata: + name: test-dragonfly + namespace: default + labels: + app.kubernetes.io/name: dragonfly + app.kubernetes.io/instance: test + app.kubernetes.io/version: "v1.15.1" + app.kubernetes.io/managed-by: Helm +spec: + type: ClusterIP + ports: + - port: 6379 + targetPort: dragonfly + protocol: TCP + name: dragonfly + selector: + app.kubernetes.io/name: dragonfly + app.kubernetes.io/instance: test +--- +# Source: dragonfly/templates/deployment.yaml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-dragonfly + namespace: default + labels: + app.kubernetes.io/name: dragonfly + app.kubernetes.io/instance: test + app.kubernetes.io/version: "v1.15.1" + app.kubernetes.io/managed-by: Helm +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: dragonfly + app.kubernetes.io/instance: test + template: + metadata: + annotations: + labels: + app.kubernetes.io/name: dragonfly + app.kubernetes.io/instance: test + spec: + serviceAccountName: test-dragonfly + containers: + - name: dragonfly + image: "docker.dragonflydb.io/dragonflydb/dragonfly:v1.15.1" + imagePullPolicy: IfNotPresent + ports: + - name: dragonfly + containerPort: 6379 + protocol: TCP + livenessProbe: + exec: + command: + - /bin/sh + - /usr/local/bin/healthcheck.sh + failureThreshold: 3 + initialDelaySeconds: 10 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 5 + readinessProbe: + exec: + command: + - /bin/sh + - /usr/local/bin/healthcheck.sh + failureThreshold: 3 + initialDelaySeconds: 10 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 5 + args: + - "--alsologtostderr" + resources: + limits: {} + requests: {} +--- +# Source: dragonfly/templates/servicemonitor.yaml +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: test-dragonfly-metrics + namespace: default + labels: + release: prometheus-stack + app.kubernetes.io/name: dragonfly + app.kubernetes.io/instance: test + app.kubernetes.io/version: "v1.15.1" + app.kubernetes.io/managed-by: Helm +spec: + endpoints: + - interval: 10s + scrapeTimeout: 10s + honorLabels: true + port: metrics + path: /metrics + scheme: http + jobLabel: "test" + selector: + matchLabels: + app.kubernetes.io/name: dragonfly + app.kubernetes.io/instance: test + type: metrics + namespaceSelector: + matchNames: + - default diff --git a/contrib/charts/dragonfly/ci/service-monitor-values.yaml b/contrib/charts/dragonfly/ci/service-monitor-values.yaml new file mode 100644 index 000000000..b35e51ad8 --- /dev/null +++ b/contrib/charts/dragonfly/ci/service-monitor-values.yaml @@ -0,0 +1,8 @@ +serviceMonitor: + enabled: true + namespace: "" + labels: + release: prometheus-stack + annotations: {} + interval: 10s + scrapeTimeout: 10s diff --git a/contrib/charts/dragonfly/golden_test.go b/contrib/charts/dragonfly/golden_test.go index d704e60f0..f63cbc552 100644 --- a/contrib/charts/dragonfly/golden_test.go +++ b/contrib/charts/dragonfly/golden_test.go @@ -3,7 +3,6 @@ package golden import ( "flag" "fmt" - "io/ioutil" "os" "path/filepath" "regexp" @@ -40,13 +39,13 @@ func TestHelmRender(t *testing.T) { output = fmt.Sprintf("%s\n", string(bytes)) if *update { - err := ioutil.WriteFile(goldenFile, []byte(output), 0644) + err := os.WriteFile(goldenFile, []byte(output), 0644) if err != nil { t.Fatal(err) } } - expected, err := ioutil.ReadFile(goldenFile) + expected, err := os.ReadFile(goldenFile) if err != nil { t.Fatal(err) } @@ -55,6 +54,5 @@ func TestHelmRender(t *testing.T) { t.Fatalf("Expected %s, but got %s\n. Update golden files by running `go test -v ./... -update`", string(expected), output) } } - } } diff --git a/contrib/charts/dragonfly/templates/certificate.yaml b/contrib/charts/dragonfly/templates/certificate.yaml index be421874c..cbf4a5338 100644 --- a/contrib/charts/dragonfly/templates/certificate.yaml +++ b/contrib/charts/dragonfly/templates/certificate.yaml @@ -21,6 +21,7 @@ spec: issuerRef: kind: {{ required "tls.issuer.kind is required, if createCerts is enabled" .Values.tls.issuer.kind }} name: {{ required "tls.issuer.name is required, if createCerts is enabled" .Values.tls.issuer.name }} + group: {{ .Values.tls.issuer.group }} secretName: '{{ include "dragonfly.fullname" . }}-server-tls' usages: - client auth diff --git a/contrib/charts/dragonfly/templates/servicemonitor.yaml b/contrib/charts/dragonfly/templates/servicemonitor.yaml index db6faa051..a45440f81 100644 --- a/contrib/charts/dragonfly/templates/servicemonitor.yaml +++ b/contrib/charts/dragonfly/templates/servicemonitor.yaml @@ -1,10 +1,12 @@ -{{- if and ( .Capabilities.APIVersions.Has "monitoring.coreos.com/v1" ) .Values.serviceMonitor.enabled }} +{{- if .Values.serviceMonitor.enabled }} apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: {{ template "dragonfly.fullname" . }}-metrics - {{- with .Values.serviceMonitor.namespace }} - namespace: {{ . }} + {{- if .Values.serviceMonitor.namespace }} + namespace: {{ .Values.serviceMonitor.namespace }} + {{- else }} + namespace: {{ .Release.Namespace }} {{- end }} {{- with .Values.serviceMonitor.annotations }} annotations: diff --git a/contrib/charts/dragonfly/values.yaml b/contrib/charts/dragonfly/values.yaml index b5a0ee959..0e1e433bd 100644 --- a/contrib/charts/dragonfly/values.yaml +++ b/contrib/charts/dragonfly/values.yaml @@ -105,6 +105,9 @@ tls: kind: ClusterIssuer # -- name of the referenced issuer name: selfsigned + # -- group of the referenced issuer + # if you are using an external issuer, change this to that issuer group. + group: cert-manager.io # -- use TLS certificates from existing secret existing_secret: "" # -- TLS certificate