From 494d73bb8e23b35b214fce961a74baefc67b25f9 Mon Sep 17 00:00:00 2001 From: parth-gr Date: Thu, 9 Sep 2021 20:31:32 +0530 Subject: [PATCH] build: create resources with k8s recommended labels Adding Recommended Labels on the rook resources, for better visuals and management of k8s object Closes: https://github.com/rook/rook/issues/8400 Signed-off-by: parth-gr --- .../charts/rook-ceph/templates/_helpers.tpl | 10 ++++++- .../rook-ceph/templates/clusterrole.yaml | 29 +++++++++---------- .../templates/clusterrolebinding.yaml | 20 ++++++------- .../rook-ceph/templates/deployment.yaml | 4 +-- cluster/charts/rook-ceph/templates/role.yaml | 4 +-- .../rook-ceph/templates/rolebinding.yaml | 3 +- .../rook-ceph/templates/serviceaccount.yaml | 16 +++++----- tests/integration/ceph_base_file_test.go | 4 +-- 8 files changed, 48 insertions(+), 42 deletions(-) diff --git a/cluster/charts/rook-ceph/templates/_helpers.tpl b/cluster/charts/rook-ceph/templates/_helpers.tpl index 529b4901755eb..62fe7ca429915 100644 --- a/cluster/charts/rook-ceph/templates/_helpers.tpl +++ b/cluster/charts/rook-ceph/templates/_helpers.tpl @@ -18,9 +18,17 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this {{/* Define imagePullSecrets option to pass to all service accounts */}} -{{- define "imagePullSecrets" }} +{{- define "imagePullSecrets" -}} {{- if .Values.imagePullSecrets -}} imagePullSecrets: {{ toYaml .Values.imagePullSecrets }} {{- end -}} {{- end -}} + +{{/* +Common labels +*/}} +{{- define "rook-ceph.labels" -}} +app.kubernetes.io/operator: {{ "rook" -}} +app.kubernetes.io/storage-backend: {{ "ceph" -}} +{{- end -}} diff --git a/cluster/charts/rook-ceph/templates/clusterrole.yaml b/cluster/charts/rook-ceph/templates/clusterrole.yaml index d9565da51fbf9..e9c204dcd06d0 100644 --- a/cluster/charts/rook-ceph/templates/clusterrole.yaml +++ b/cluster/charts/rook-ceph/templates/clusterrole.yaml @@ -4,8 +4,8 @@ apiVersion: rbac.authorization.k8s.io/v1 metadata: name: rook-ceph-system labels: - operator: rook - storage-backend: ceph + {{- include "rook-ceph.labels" . }} + rules: # Most resources are represented by a string representation of their name, such as “pods”, just as it appears in the URL for the relevant API endpoint. # However, some Kubernetes APIs involve a “subresource”, such as the logs for a pod. [...] @@ -24,8 +24,8 @@ kind: ClusterRole metadata: name: rook-ceph-cluster-mgmt labels: - operator: rook - storage-backend: ceph + {{- include "rook-ceph.labels" . }} + rules: - apiGroups: - "" @@ -54,8 +54,8 @@ kind: ClusterRole metadata: name: rook-ceph-global labels: - operator: rook - storage-backend: ceph + {{- include "rook-ceph.labels" . }} + rules: - apiGroups: - "" @@ -174,8 +174,8 @@ apiVersion: rbac.authorization.k8s.io/v1 metadata: name: rook-ceph-mgr-cluster labels: - operator: rook - storage-backend: ceph + {{- include "rook-ceph.labels" . }} + rules: - apiGroups: - "" @@ -226,9 +226,8 @@ kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 metadata: name: rook-ceph-object-bucket - labels: - operator: rook - storage-backend: ceph + {{- include "rook-ceph.labels" . }} + rules: - apiGroups: - "" @@ -272,8 +271,8 @@ kind: ClusterRole metadata: name: rook-ceph-agent-mount labels: - operator: rook - storage-backend: ceph + {{- include "rook-ceph.labels" . }} + rules: - apiGroups: - "" @@ -458,8 +457,8 @@ kind: ClusterRole metadata: name: 'psp:rook' labels: - operator: rook - storage-backend: ceph + {{- include "rook-ceph.labels" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" rules: - apiGroups: diff --git a/cluster/charts/rook-ceph/templates/clusterrolebinding.yaml b/cluster/charts/rook-ceph/templates/clusterrolebinding.yaml index d3c22ca74c696..16c3a49de6f13 100644 --- a/cluster/charts/rook-ceph/templates/clusterrolebinding.yaml +++ b/cluster/charts/rook-ceph/templates/clusterrolebinding.yaml @@ -4,8 +4,8 @@ apiVersion: rbac.authorization.k8s.io/v1 metadata: name: rook-ceph-system labels: - operator: rook - storage-backend: ceph + {{- include "rook-ceph.labels" . }} + roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole @@ -21,8 +21,8 @@ apiVersion: rbac.authorization.k8s.io/v1 metadata: name: rook-ceph-global labels: - operator: rook - storage-backend: ceph + {{- include "rook-ceph.labels" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" roleRef: apiGroup: rbac.authorization.k8s.io @@ -120,8 +120,8 @@ kind: ClusterRoleBinding metadata: name: rook-ceph-system-psp labels: - operator: rook - storage-backend: ceph + {{- include "rook-ceph.labels" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" roleRef: apiGroup: rbac.authorization.k8s.io @@ -138,8 +138,8 @@ metadata: name: rook-ceph-default-psp namespace: {{ .Release.Namespace }} labels: - operator: rook - storage-backend: ceph + {{- include "rook-ceph.labels" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" roleRef: apiGroup: rbac.authorization.k8s.io @@ -155,8 +155,8 @@ kind: ClusterRoleBinding metadata: name: rook-ceph-system-psp-users labels: - operator: rook - storage-backend: ceph + {{- include "rook-ceph.labels" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" roleRef: apiGroup: rbac.authorization.k8s.io diff --git a/cluster/charts/rook-ceph/templates/deployment.yaml b/cluster/charts/rook-ceph/templates/deployment.yaml index 7efb599ebe433..f7fcc642f0613 100644 --- a/cluster/charts/rook-ceph/templates/deployment.yaml +++ b/cluster/charts/rook-ceph/templates/deployment.yaml @@ -3,8 +3,8 @@ kind: Deployment metadata: name: rook-ceph-operator labels: - operator: rook - storage-backend: ceph + {{- include "rook-ceph.labels" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" spec: replicas: 1 diff --git a/cluster/charts/rook-ceph/templates/role.yaml b/cluster/charts/rook-ceph/templates/role.yaml index 70f899c5dc40d..8393791aac1a4 100644 --- a/cluster/charts/rook-ceph/templates/role.yaml +++ b/cluster/charts/rook-ceph/templates/role.yaml @@ -6,8 +6,8 @@ metadata: name: rook-ceph-system namespace: {{ .Release.Namespace }} labels: - operator: rook - storage-backend: ceph + {{- include "rook-ceph.labels" . }} + rules: - apiGroups: - "" diff --git a/cluster/charts/rook-ceph/templates/rolebinding.yaml b/cluster/charts/rook-ceph/templates/rolebinding.yaml index aeda4636ad7be..548e6e59fbfb9 100644 --- a/cluster/charts/rook-ceph/templates/rolebinding.yaml +++ b/cluster/charts/rook-ceph/templates/rolebinding.yaml @@ -6,8 +6,7 @@ metadata: name: rook-ceph-system namespace: {{ .Release.Namespace }} labels: - operator: rook - storage-backend: ceph + {{- include "rook-ceph.labels" . }} roleRef: apiGroup: rbac.authorization.k8s.io kind: Role diff --git a/cluster/charts/rook-ceph/templates/serviceaccount.yaml b/cluster/charts/rook-ceph/templates/serviceaccount.yaml index f9317cb0a8962..fbc8302ab959d 100644 --- a/cluster/charts/rook-ceph/templates/serviceaccount.yaml +++ b/cluster/charts/rook-ceph/templates/serviceaccount.yaml @@ -5,8 +5,8 @@ metadata: name: rook-ceph-system namespace: {{ .Release.Namespace }} labels: - operator: rook - storage-backend: ceph + {{- include "rook-ceph.labels" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" {{ template "imagePullSecrets" . }} --- @@ -17,8 +17,8 @@ metadata: name: rook-ceph-osd namespace: {{ .Release.Namespace }} labels: - operator: rook - storage-backend: ceph + {{- include "rook-ceph.labels" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" {{ template "imagePullSecrets" . }} --- @@ -29,8 +29,8 @@ metadata: name: rook-ceph-mgr namespace: {{ .Release.Namespace }} labels: - operator: rook - storage-backend: ceph + {{- include "rook-ceph.labels" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" {{ template "imagePullSecrets" . }} --- @@ -40,8 +40,8 @@ metadata: name: rook-ceph-cmd-reporter namespace: {{ .Release.Namespace }} labels: - operator: rook - storage-backend: ceph + {{- include "rook-ceph.labels" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" {{ template "imagePullSecrets" . }} --- diff --git a/tests/integration/ceph_base_file_test.go b/tests/integration/ceph_base_file_test.go index f2acba483cb3a..f714ffefb4dca 100644 --- a/tests/integration/ceph_base_file_test.go +++ b/tests/integration/ceph_base_file_test.go @@ -555,8 +555,8 @@ kind: ClusterRoleBinding metadata: name: rook-ceph-agent-mount labels: - operator: rook - storage-backend: ceph + app.kubernetes.io/operator: rook + app.kubernetes.io/storage-backend: ceph roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole