From 846dea6a92ced6d2c5eb0431e0dada4dfe8f14f1 Mon Sep 17 00:00:00 2001 From: Maven35 Date: Sat, 18 May 2024 23:04:12 +0000 Subject: [PATCH] added boilerplate for the change in values --- charts/kube-state-metrics/templates/_helpers.tpl | 12 ++++++++++++ .../templates/clusterrolebinding.yaml | 4 ++-- .../templates/psp-clusterrole.yaml | 2 +- .../templates/psp-clusterrolebinding.yaml | 4 ++-- charts/kube-state-metrics/values.yaml | 4 ++++ 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/charts/kube-state-metrics/templates/_helpers.tpl b/charts/kube-state-metrics/templates/_helpers.tpl index a4358c87a106..19493d4a6305 100644 --- a/charts/kube-state-metrics/templates/_helpers.tpl +++ b/charts/kube-state-metrics/templates/_helpers.tpl @@ -35,6 +35,18 @@ Create the name of the service account to use {{- end -}} {{- end -}} +{{/* +Create a fully qualified ClusterRole name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +*/}} +{{- define "kube-state-metrics.clusterRoleName" -}} +{{- if .Values.rbac.clusterRoleNameOverride -}} +{{ .Values.rbac.clusterRoleNameOverride | trunc 63 | trimSuffix "-" }} +{{- else -}} +{{ include "kube-state-metrics.fullname" . }} +{{- end -}} +{{- end -}} + {{/* Allow the release namespace to be overridden for multi-namespace deployments in combined charts */}} diff --git a/charts/kube-state-metrics/templates/clusterrolebinding.yaml b/charts/kube-state-metrics/templates/clusterrolebinding.yaml index cf9f628d041d..2c097b8c3e24 100644 --- a/charts/kube-state-metrics/templates/clusterrolebinding.yaml +++ b/charts/kube-state-metrics/templates/clusterrolebinding.yaml @@ -4,14 +4,14 @@ kind: ClusterRoleBinding metadata: labels: {{- include "kube-state-metrics.labels" . | indent 4 }} - name: {{ template "kube-state-metrics.fullname" . }} + name: {{ include "kube-state-metrics.clusterRoleName" . }} roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole {{- if .Values.rbac.useExistingRole }} name: {{ .Values.rbac.useExistingRole }} {{- else }} - name: {{ template "kube-state-metrics.fullname" . }} + name: {{ include "kube-state-metrics.clusterRoleName" . }} {{- end }} subjects: - kind: ServiceAccount diff --git a/charts/kube-state-metrics/templates/psp-clusterrole.yaml b/charts/kube-state-metrics/templates/psp-clusterrole.yaml index 654e4a3d57f6..71365d1f8074 100644 --- a/charts/kube-state-metrics/templates/psp-clusterrole.yaml +++ b/charts/kube-state-metrics/templates/psp-clusterrole.yaml @@ -4,7 +4,7 @@ kind: ClusterRole metadata: labels: {{- include "kube-state-metrics.labels" . | indent 4 }} - name: psp-{{ template "kube-state-metrics.fullname" . }} + name: psp-{{ include "kube-state-metrics.clusterRoleName" . }} rules: {{- $kubeTargetVersion := default .Capabilities.KubeVersion.GitVersion .Values.kubeTargetVersionOverride }} {{- if semverCompare "> 1.15.0-0" $kubeTargetVersion }} diff --git a/charts/kube-state-metrics/templates/psp-clusterrolebinding.yaml b/charts/kube-state-metrics/templates/psp-clusterrolebinding.yaml index 5b62a18bdf12..09b625748b26 100644 --- a/charts/kube-state-metrics/templates/psp-clusterrolebinding.yaml +++ b/charts/kube-state-metrics/templates/psp-clusterrolebinding.yaml @@ -4,11 +4,11 @@ kind: ClusterRoleBinding metadata: labels: {{- include "kube-state-metrics.labels" . | indent 4 }} - name: psp-{{ template "kube-state-metrics.fullname" . }} + name: psp-{{ include "kube-state-metrics.clusterRoleName" . }} roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole - name: psp-{{ template "kube-state-metrics.fullname" . }} + name: psp-{{ include "kube-state-metrics.clusterRoleName" . }} subjects: - kind: ServiceAccount name: {{ template "kube-state-metrics.serviceAccountName" . }} diff --git a/charts/kube-state-metrics/values.yaml b/charts/kube-state-metrics/values.yaml index 2e8283a89469..9a44694d0bc6 100644 --- a/charts/kube-state-metrics/values.yaml +++ b/charts/kube-state-metrics/values.yaml @@ -89,6 +89,10 @@ rbac: # If set to false - Run without Cluteradmin privs needed - ONLY works if namespace is also set (if useExistingRole is set this name is used as ClusterRole or Role to bind to) useClusterRole: true + ## If set it will override prometheus.server.fullname value for ClusterRole and ClusterRoleBinding + ## + clusterRoleNameOverride: "" + # Add permissions for CustomResources' apiGroups in Role/ClusterRole. Should be used in conjunction with Custom Resource State Metrics configuration # Example: # - apiGroups: ["monitoring.coreos.com"]