Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper for namespace handling, fix rbac for watchNamespaces #1329

Merged
merged 3 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deploy/helm/grafana-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions deploy/helm/grafana-operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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/grafana-operator"` | grafana operator image repository |
| image.tag | string | `""` | Overrides the image tag whose default is the chart appVersion. |
Expand All @@ -47,7 +47,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 |
Expand Down
7 changes: 7 additions & 0 deletions deploy/helm/grafana-operator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/}}
Expand Down
2 changes: 1 addition & 1 deletion deploy/helm/grafana-operator/templates/cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion deploy/helm/grafana-operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
14 changes: 7 additions & 7 deletions deploy/helm/grafana-operator/templates/rbac.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- $watchNamespaces := coalesce .Values.watchNamespaces .Release.Namespace }}
{{- $watchNamespaces := coalesce .Values.watchNamespaces .Values.namespaceOverride .Release.Namespace }}
{{- $namespaceScoped := false }}
{{- $isOpenShift := false }}
{{- if or (.Values.namespaceScope) (.Values.watchNamespaces) }}
Expand All @@ -14,9 +14,9 @@ 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 }}
Expand Down Expand Up @@ -238,9 +238,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 }}
Expand All @@ -250,9 +250,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 }}
2 changes: 1 addition & 1 deletion deploy/helm/grafana-operator/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
6 changes: 6 additions & 0 deletions deploy/helm/grafana-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,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
Expand Down