From fa05e68502e855d7b895fcb3c70ae8c919dbbfb4 Mon Sep 17 00:00:00 2001 From: rasebo Date: Thu, 7 Dec 2023 12:50:26 +0200 Subject: [PATCH] Add helper to include namespaceOverride, fix rbac namespace for wathNamespaces list. --- deploy/helm/grafana-operator/Chart.yaml | 2 +- deploy/helm/grafana-operator/README.md | 7 ++++--- .../helm/grafana-operator/templates/_helpers.tpl | 7 +++++++ deploy/helm/grafana-operator/templates/cm.yaml | 2 +- .../grafana-operator/templates/deployment.yaml | 2 +- deploy/helm/grafana-operator/templates/rbac.yaml | 15 +++++++-------- .../helm/grafana-operator/templates/service.yaml | 2 +- .../templates/serviceaccount.yaml | 2 +- deploy/helm/grafana-operator/values.yaml | 6 ++++++ 9 files changed, 29 insertions(+), 16 deletions(-) diff --git a/deploy/helm/grafana-operator/Chart.yaml b/deploy/helm/grafana-operator/Chart.yaml index 2bbf10b1f..b48e30773 100644 --- a/deploy/helm/grafana-operator/Chart.yaml +++ b/deploy/helm/grafana-operator/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.1.2 +version: 0.1.3 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/deploy/helm/grafana-operator/README.md b/deploy/helm/grafana-operator/README.md index f543761f9..aa867690f 100644 --- a/deploy/helm/grafana-operator/README.md +++ b/deploy/helm/grafana-operator/README.md @@ -7,7 +7,7 @@ linkTitle: "Helm installation" [grafana-operator](https://github.com/grafana/grafana-operator) for Kubernetes to manage Grafana instances and grafana resources. -![Version: 0.1.2](https://img.shields.io/badge/Version-0.1.2-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v5.6.0](https://img.shields.io/badge/AppVersion-v5.6.0-informational?style=flat-square) +![Version: 0.1.3](https://img.shields.io/badge/Version-0.1.3-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v5.6.0](https://img.shields.io/badge/AppVersion-v5.6.0-informational?style=flat-square) ## Installation @@ -38,7 +38,7 @@ It's easier to just manage this configuration outside of the operator. | additionalLabels | object | `{}` | additional labels to add to all resources | | affinity | object | `{}` | pod affinity | | env | list | `[]` | Additional environment variables | -| fullnameOverride | string | `""` | | +| fullnameOverride | string | `""` | Overrides the fully qualified app name. | | image.pullPolicy | string | `"IfNotPresent"` | The image pull policy to use in grafana operator container | | image.repository | string | `"ghcr.io/grafana-operator/grafana-operator"` | grafana operator image repository | | image.tag | string | `""` | Overrides the image tag whose default is the chart appVersion. | @@ -46,7 +46,8 @@ It's easier to just manage this configuration outside of the operator. | leaderElect | bool | `false` | If you want to run multiple replicas of the grafana-operator, this is not recommended. | | metricsService.metricsPort | int | `9090` | metrics service port | | metricsService.type | string | `"ClusterIP"` | metrics service type | -| nameOverride | string | `""` | | +| nameOverride | string | `""` | Overrides the name of the chart. | +| namespaceOverride | string | `""` | Overrides the namespace name. | | namespaceScope | bool | `false` | If the operator should run in namespace-scope or not, if true the operator will only be able to manage instances in the same namespace | | nodeSelector | object | `{}` | pod node selector | | podAnnotations | object | `{}` | pod annotations | diff --git a/deploy/helm/grafana-operator/templates/_helpers.tpl b/deploy/helm/grafana-operator/templates/_helpers.tpl index f082bf0fb..dbf65f4dd 100644 --- a/deploy/helm/grafana-operator/templates/_helpers.tpl +++ b/deploy/helm/grafana-operator/templates/_helpers.tpl @@ -23,6 +23,13 @@ If release name contains chart name it will be used as a full name. {{- end }} {{- end }} +{{/* +Allow the release namespace to be overridden +*/}} +{{- define "grafana-operator.namespace" -}} +{{ .Values.namespaceOverride | default .Release.Namespace }} +{{- end -}} + {{/* Create chart name and version as used by the chart label. */}} diff --git a/deploy/helm/grafana-operator/templates/cm.yaml b/deploy/helm/grafana-operator/templates/cm.yaml index cc4866e2d..e2f54540a 100644 --- a/deploy/helm/grafana-operator/templates/cm.yaml +++ b/deploy/helm/grafana-operator/templates/cm.yaml @@ -3,7 +3,7 @@ apiVersion: v1 kind: ConfigMap metadata: name: {{ include "grafana-operator.fullname" . }} - namespace: {{ .Release.Namespace | quote }} + namespace: {{ include "grafana-operator.namespace" . }} labels: {{- with .Values.additionalLabels }} {{- toYaml . | nindent 4 }} diff --git a/deploy/helm/grafana-operator/templates/deployment.yaml b/deploy/helm/grafana-operator/templates/deployment.yaml index b22be24e1..3e817e2ca 100644 --- a/deploy/helm/grafana-operator/templates/deployment.yaml +++ b/deploy/helm/grafana-operator/templates/deployment.yaml @@ -2,7 +2,7 @@ apiVersion: apps/v1 kind: Deployment metadata: name: {{ include "grafana-operator.fullname" . }} - namespace: {{ .Release.Namespace | quote }} + namespace: {{ include "grafana-operator.namespace" . }} labels: {{- include "grafana-operator.labels" . | nindent 4 }} {{- with .Values.additionalLabels }} diff --git a/deploy/helm/grafana-operator/templates/rbac.yaml b/deploy/helm/grafana-operator/templates/rbac.yaml index 983e45e6c..578efb74a 100644 --- a/deploy/helm/grafana-operator/templates/rbac.yaml +++ b/deploy/helm/grafana-operator/templates/rbac.yaml @@ -1,18 +1,17 @@ -{{- $watchNamespaces := coalesce .Values.watchNamespaces .Release.Namespace }} +{{- $watchNamespaces := coalesce .Values.watchNamespaces .Values.namespaceOverride .Release.Namespace }} {{- $namespaceScoped := false }} {{- if or (.Values.namespaceScope) (.Values.watchNamespaces) }} {{- $namespaceScoped = true }} {{- end }} -{{- $operatorNamespace := .Release.Namespace }} {{- range ( split "," $watchNamespaces ) }} --- apiVersion: rbac.authorization.k8s.io/v1 kind: {{ if not $namespaceScoped }}Cluster{{ end }}Role metadata: {{- if $namespaceScoped }} - namespace: {{ $operatorNamespace }} + namespace: {{ . }} {{- end }} - name: grafana-operator-permissions + name: {{ include "grafana-operator.fullname" $ }} labels: {{- include "grafana-operator.labels" $ | nindent 4 }} {{- with $.Values.additionalLabels }} @@ -232,9 +231,9 @@ rules: apiVersion: rbac.authorization.k8s.io/v1 kind: {{ if not $namespaceScoped }}Cluster{{ end }}RoleBinding metadata: - name: grafana-operator-permissions + name: {{ include "grafana-operator.fullname" $ }} {{- if $namespaceScoped }} - namespace: {{ $operatorNamespace }} + namespace: {{ . }} {{- end }} labels: {{- include "grafana-operator.labels" $ | nindent 4 }} @@ -244,9 +243,9 @@ metadata: subjects: - kind: ServiceAccount name: {{ include "grafana-operator.serviceAccountName" $ }} - namespace: {{ $operatorNamespace }} + namespace: {{ include "grafana-operator.namespace" $ }} roleRef: kind: {{ if not $namespaceScoped }}Cluster{{ end }}Role - name: grafana-operator-permissions + name: {{ include "grafana-operator.fullname" $ }} apiGroup: rbac.authorization.k8s.io {{- end }} diff --git a/deploy/helm/grafana-operator/templates/service.yaml b/deploy/helm/grafana-operator/templates/service.yaml index f765c94bc..d7ad43f49 100644 --- a/deploy/helm/grafana-operator/templates/service.yaml +++ b/deploy/helm/grafana-operator/templates/service.yaml @@ -2,7 +2,7 @@ apiVersion: v1 kind: Service metadata: name: {{ include "grafana-operator.fullname" . }}-metrics-service - namespace: {{ .Release.Namespace | quote }} + namespace: {{ include "grafana-operator.namespace" . }} labels: {{- include "grafana-operator.labels" . | nindent 4 }} {{- with .Values.additionalLabels }} diff --git a/deploy/helm/grafana-operator/templates/serviceaccount.yaml b/deploy/helm/grafana-operator/templates/serviceaccount.yaml index 1b31f3130..9be898849 100644 --- a/deploy/helm/grafana-operator/templates/serviceaccount.yaml +++ b/deploy/helm/grafana-operator/templates/serviceaccount.yaml @@ -3,7 +3,7 @@ apiVersion: v1 kind: ServiceAccount metadata: name: {{ include "grafana-operator.serviceAccountName" . }} - namespace: {{ .Release.Namespace | quote }} + namespace: {{ include "grafana-operator.namespace" . }} labels: {{- include "grafana-operator.labels" . | nindent 4 }} {{- with .Values.additionalLabels }} diff --git a/deploy/helm/grafana-operator/values.yaml b/deploy/helm/grafana-operator/values.yaml index 0a3df1e58..7253894e9 100644 --- a/deploy/helm/grafana-operator/values.yaml +++ b/deploy/helm/grafana-operator/values.yaml @@ -29,9 +29,15 @@ image: # -- image pull secrets imagePullSecrets: [] +# -- Overrides the name of the chart. nameOverride: "" + +# -- Overrides the fully qualified app name. fullnameOverride: "" +# -- Overrides the namespace name. +namespaceOverride: "" + serviceAccount: # -- Specifies whether a service account should be created create: true