Skip to content

Commit

Permalink
allow arbitrary labels to be set on operator and console resources (#…
Browse files Browse the repository at this point in the history
…2069)

* use console-labels on console resources

* add operator labels to operator cluster role

* allow arbitrary labels to be set on operator and console resources

* only apply selector labels to deployments

* fix syntax errors

* Removed unused helpers

* Simplified adding labels and only use selector labels where appropriate

---------

Co-authored-by: Ramon de Klein <mail@ramondeklein.nl>
  • Loading branch information
ChrisVanLawAtFanatics and ramondeklein committed Apr 22, 2024
1 parent fb6ceb8 commit 01c56a5
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 99 deletions.
17 changes: 7 additions & 10 deletions helm/operator/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ If release name contains chart name it will be used as a full name.
{{- end -}}
{{- end -}}

{{/*
Expand the name of the Operator Console.
*/}}
{{- define "minio-operator.console-name" -}}
{{- printf "%s-%s" .Chart.Name "console" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified console name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
Expand All @@ -48,11 +41,13 @@ Common labels for operator
*/}}
{{- define "minio-operator.labels" -}}
helm.sh/chart: {{ include "minio-operator.chart" . }}
{{ include "minio-operator.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- range $key, $val := .Values.operator.additionalLabels }}
{{ $key }}: {{ $val | quote }}
{{- end }}
{{- end -}}

{{/*
Expand All @@ -68,15 +63,17 @@ Common labels for console
*/}}
{{- define "minio-operator.console-labels" -}}
helm.sh/chart: {{ include "minio-operator.chart" . }}
{{ include "minio-operator.console-selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- range $key, $val := .Values.console.additionalLabels }}
{{ $key }}: {{ $val | quote }}
{{- end }}
{{- end -}}

{{/*
Selector labels Operator
Selector labels Console
*/}}
{{- define "minio-operator.console-selectorLabels" -}}
app.kubernetes.io/name: {{ include "minio-operator.name" . }}
Expand Down
1 change: 1 addition & 0 deletions helm/operator/templates/console-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: console-sa-role
labels: {{- include "minio-operator.console-labels" . | nindent 4 }}
rules:
- apiGroups:
- ""
Expand Down
1 change: 1 addition & 0 deletions helm/operator/templates/console-clusterrolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: console-sa-binding
labels: {{- include "minio-operator.console-labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
Expand Down
1 change: 1 addition & 0 deletions helm/operator/templates/console-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: ConfigMap
metadata:
name: console-env
namespace: {{ .Release.Namespace }}
labels: {{- include "minio-operator.console-labels" . | nindent 4 }}
data:
CONSOLE_PORT: "9090"
CONSOLE_TLS_PORT: "9443"
Expand Down
6 changes: 4 additions & 2 deletions helm/operator/templates/console-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ kind: Deployment
metadata:
name: console
namespace: {{ .Release.Namespace }}
labels: {{- include "minio-operator.labels" . | nindent 4 }}
labels: {{- include "minio-operator.console-labels" . | nindent 4 }}
spec:
replicas: {{ .Values.console.replicaCount }}
selector:
matchLabels: {{- include "minio-operator.console-selectorLabels" . | nindent 6 }}
template:
metadata:
labels: {{- include "minio-operator.console-selectorLabels" . | nindent 8 }}
labels:
{{- include "minio-operator.console-labels" . | nindent 8 }}
{{- include "minio-operator.console-selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.console.imagePullSecrets }}
imagePullSecrets: {{- toYaml . | nindent 8 }}
Expand Down
1 change: 1 addition & 0 deletions helm/operator/templates/console-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ metadata:
namespace: {{ .Release.Namespace }}
annotations:
kubernetes.io/service-account.name: console-sa
labels: {{- include "minio-operator.console-labels" . | nindent 4 }}
type: kubernetes.io/service-account-token
{{- end }}
2 changes: 1 addition & 1 deletion helm/operator/templates/console-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: Service
metadata:
name: console
namespace: {{ .Release.Namespace }}
labels: {{- include "minio-operator.labels" . | nindent 4 }}
labels: {{- include "minio-operator.console-labels" . | nindent 4 }}
spec:
ports:
- name: http
Expand Down
1 change: 1 addition & 0 deletions helm/operator/templates/console-serviceaccount.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ kind: ServiceAccount
metadata:
name: console-sa
namespace: {{ .Release.Namespace }}
labels: {{- include "minio-operator.console-labels" . | nindent 4 }}
{{- end }}
1 change: 1 addition & 0 deletions helm/operator/templates/operator-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: minio-operator-role
labels: {{- include "minio-operator.labels" . | nindent 4 }}
rules:
- apiGroups:
- "apiextensions.k8s.io"
Expand Down
1 change: 1 addition & 0 deletions helm/operator/templates/operator-clusterrolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: minio-operator-binding
labels: {{- include "minio-operator.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
Expand Down
4 changes: 3 additions & 1 deletion helm/operator/templates/operator-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ spec:
matchLabels: {{- include "minio-operator.selectorLabels" . | nindent 6 }}
template:
metadata:
labels: {{- include "minio-operator.selectorLabels" . | nindent 8 }}
labels:
{{- include "minio-operator.labels" . | nindent 8 }}
{{- include "minio-operator.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.operator.imagePullSecrets }}
imagePullSecrets: {{- toYaml . | nindent 8 }}
Expand Down
4 changes: 4 additions & 0 deletions helm/operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ operator:
value: "off"
# An array of additional annotations to be applied to the operator service account
serviceAccountAnnotations: []
# additional labels to be applied to operator resources
additionalLabels: {}
###
# Specify the Operator container image to use for the deployment.
# ``image.tag``
Expand Down Expand Up @@ -177,6 +179,8 @@ console:
#
# If the Operator Console is disabled, all management of Operator Tenants must be done through the Kubernetes API.
enabled: true
# additional labels to include for console resources
additionalLabels: {}
###
# Specify the Operator Console container image to use for the deployment.
# ``image.tag``
Expand Down
85 changes: 0 additions & 85 deletions helm/tenant/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,89 +1,4 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "minio-operator.name" -}}
{{- default .Chart.Name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "minio-operator.fullname" -}}
{{- $name := default .Chart.Name -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}

{{/*
Expand the name of the Operator Console.
*/}}
{{- define "minio-operator.console-name" -}}
{{- printf "%s-%s" .Chart.Name "console" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified console name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "minio-operator.console-fullname" -}}
{{- printf "%s-%s" .Release.Name "console" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "minio-operator.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Common labels for operator
*/}}
{{- define "minio-operator.labels" -}}
helm.sh/chart: {{ include "minio-operator.chart" . }}
{{ include "minio-operator.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

{{/*
Selector labels Operator
*/}}
{{- define "minio-operator.selectorLabels" -}}
app.kubernetes.io/name: {{ include "minio-operator.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}

{{/*
Common labels for console
*/}}
{{- define "minio-operator.console-labels" -}}
helm.sh/chart: {{ include "minio-operator.chart" . }}
{{ include "minio-operator.console-selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

{{/*
Selector labels Operator
*/}}
{{- define "minio-operator.console-selectorLabels" -}}
app.kubernetes.io/name: {{ include "minio-operator.name" . }}
app.kubernetes.io/instance: {{ printf "%s-%s" .Release.Name "console" }}
{{- end -}}


{{/*
Renders a value that contains template.
Usage:
Expand Down

0 comments on commit 01c56a5

Please sign in to comment.