Skip to content

Commit

Permalink
build: create resources with k8s recommended labels
Browse files Browse the repository at this point in the history
Use Recommended Labels in the helm chart,
for better visuals and management of k8s object

Closes: rook#8400
Signed-off-by: parth-gr <paarora@redhat.com>
  • Loading branch information
parth-gr committed Nov 16, 2021
1 parent bb7306e commit afa2878
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 11 deletions.
13 changes: 8 additions & 5 deletions build/rbac/keep-rbac-yaml.py
Expand Up @@ -26,6 +26,11 @@ def log(*values):
def kind_and_name(doc):
return doc["kind"] + "/" + doc["metadata"]["name"]

# Remove label for rendered RBAC
def remove_label(label_name):
if "labels" in doc["metadata"] and label_name in doc["metadata"]["labels"]:
log("dropping " + label_name + " label")
del doc["metadata"]["labels"][label_name]

# Set up and configure the yaml parser/dumper
yaml=ruamel.yaml.YAML()
Expand Down Expand Up @@ -56,14 +61,12 @@ def kind_and_name(doc):
log(" dropping comment:", comment.value.strip())
comments.remove(comment)

# helm-managed resources have a "chart" label, but we remove those for rendered RBAC
if "labels" in doc["metadata"] and "chart" in doc["metadata"]["labels"]:
log(" dropping 'chart' label")
del doc["metadata"]["labels"]["chart"]
remove_label("helm.sh/chart")
remove_label("app.kubernetes.io/managed-by")
remove_label("app.kubernetes.io/created-by")

kept_docs.append(doc)


kept_docs.sort(key=kind_and_name)

# Log to stderr the overall list of docs kept and a summary
Expand Down
16 changes: 16 additions & 0 deletions build/rbac/rbac.yaml
Expand Up @@ -74,6 +74,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
app.kubernetes.io/part-of: rook-ceph-operator
rules:
- apiGroups:
- policy
Expand Down Expand Up @@ -185,6 +186,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
app.kubernetes.io/part-of: rook-ceph-operator
rules:
- apiGroups:
- ''
Expand Down Expand Up @@ -217,6 +219,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
app.kubernetes.io/part-of: rook-ceph-operator
rules:
- apiGroups:
- ''
Expand Down Expand Up @@ -342,6 +345,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
app.kubernetes.io/part-of: rook-ceph-operator
rules:
- apiGroups:
- ''
Expand Down Expand Up @@ -398,6 +402,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
app.kubernetes.io/part-of: rook-ceph-operator
rules:
- apiGroups: ['']
resources: [secrets, configmaps]
Expand Down Expand Up @@ -463,6 +468,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
app.kubernetes.io/part-of: rook-ceph-operator
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. [...]
Expand Down Expand Up @@ -535,6 +541,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
app.kubernetes.io/part-of: rook-ceph-operator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
Expand Down Expand Up @@ -593,6 +600,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
app.kubernetes.io/part-of: rook-ceph-operator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
Expand All @@ -609,6 +617,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
app.kubernetes.io/part-of: rook-ceph-operator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
Expand Down Expand Up @@ -891,6 +900,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
app.kubernetes.io/part-of: rook-ceph-operator
rules:
- apiGroups:
- ''
Expand Down Expand Up @@ -1018,6 +1028,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
app.kubernetes.io/part-of: rook-ceph-operator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
Expand Down Expand Up @@ -1124,6 +1135,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
app.kubernetes.io/part-of: rook-ceph-operator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
Expand All @@ -1142,6 +1154,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
app.kubernetes.io/part-of: rook-ceph-operator
---
# Service account for Ceph mgrs
apiVersion: v1
Expand All @@ -1152,6 +1165,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
app.kubernetes.io/part-of: rook-ceph-operator
---
# Service account for Ceph OSDs
apiVersion: v1
Expand All @@ -1163,6 +1177,7 @@ metadata:
operator: rook
storage-backend: ceph
i-am-a-new-label: delete-me
app.kubernetes.io/part-of: rook-ceph-operator
---
# Service account for job that purges OSDs from a Rook-Ceph cluster
apiVersion: v1
Expand All @@ -1180,6 +1195,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
app.kubernetes.io/part-of: rook-ceph-operator
---
# Service account for the CephFS CSI driver
apiVersion: v1
Expand Down
1 change: 1 addition & 0 deletions cluster/charts/library/templates/_cluster-psp.tpl
Expand Up @@ -10,6 +10,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
{{- include "library.rook-ceph.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
Expand Down
3 changes: 3 additions & 0 deletions cluster/charts/library/templates/_cluster-serviceaccount.tpl
Expand Up @@ -12,6 +12,7 @@ metadata:
operator: rook
storage-backend: ceph
i-am-a-new-label: delete-me
{{- include "library.rook-ceph.labels" . | nindent 4 }}
{{ include "library.imagePullSecrets" . }}
---
# Service account for Ceph mgrs
Expand All @@ -23,6 +24,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
{{- include "library.rook-ceph.labels" . | nindent 4 }}
{{ include "library.imagePullSecrets" . }}
---
# Service account for the job that reports the Ceph version in an image
Expand All @@ -34,6 +36,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
{{- include "library.rook-ceph.labels" . | nindent 4 }}
{{ include "library.imagePullSecrets" . }}
---
# Service account for job that purges OSDs from a Rook-Ceph cluster
Expand Down
9 changes: 9 additions & 0 deletions cluster/charts/library/templates/_recommended-labels.tpl
@@ -0,0 +1,9 @@
{{/*
Common labels
*/}}
{{- define "library.rook-ceph.labels" -}}
app.kubernetes.io/part-of: rook-ceph-operator
app.kubernetes.io/managed-by: helm
app.kubernetes.io/created-by: helm
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
{{- end -}}
5 changes: 5 additions & 0 deletions cluster/charts/rook-ceph/templates/clusterrole.yaml
Expand Up @@ -6,6 +6,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
{{- include "library.rook-ceph.labels" . | nindent 4 }}
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. [...]
Expand All @@ -26,6 +27,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
{{- include "library.rook-ceph.labels" . | nindent 4 }}
rules:
- apiGroups:
- ""
Expand Down Expand Up @@ -58,6 +60,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
{{- include "library.rook-ceph.labels" . | nindent 4 }}
rules:
- apiGroups:
- ""
Expand Down Expand Up @@ -183,6 +186,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
{{- include "library.rook-ceph.labels" . | nindent 4 }}
rules:
- apiGroups:
- ""
Expand Down Expand Up @@ -239,6 +243,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
{{- include "library.rook-ceph.labels" . | nindent 4 }}
rules:
- apiGroups: [""]
resources: ["secrets", "configmaps"]
Expand Down
3 changes: 2 additions & 1 deletion cluster/charts/rook-ceph/templates/clusterrolebinding.yaml
Expand Up @@ -6,6 +6,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
{{- include "library.rook-ceph.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
Expand All @@ -23,7 +24,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
{{- include "library.rook-ceph.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
Expand Down
4 changes: 2 additions & 2 deletions cluster/charts/rook-ceph/templates/deployment.yaml
Expand Up @@ -5,7 +5,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
{{- include "library.rook-ceph.labels" . | nindent 4 }}
spec:
replicas: 1
selector:
Expand All @@ -15,7 +15,7 @@ spec:
metadata:
labels:
app: rook-ceph-operator
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
{{- if .Values.annotations }}
annotations:
{{ toYaml .Values.annotations | indent 8 }}
Expand Down
4 changes: 2 additions & 2 deletions cluster/charts/rook-ceph/templates/psp.yaml
Expand Up @@ -84,7 +84,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
{{- include "library.rook-ceph.labels" . | nindent 4 }}
rules:
- apiGroups:
- policy
Expand All @@ -102,7 +102,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
{{- include "library.rook-ceph.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
Expand Down
1 change: 1 addition & 0 deletions cluster/charts/rook-ceph/templates/role.yaml
Expand Up @@ -8,6 +8,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
{{- include "library.rook-ceph.labels" . | nindent 4 }}
rules:
- apiGroups:
- ""
Expand Down
1 change: 1 addition & 0 deletions cluster/charts/rook-ceph/templates/rolebinding.yaml
Expand Up @@ -8,6 +8,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
{{- include "library.rook-ceph.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
Expand Down
2 changes: 1 addition & 1 deletion cluster/charts/rook-ceph/templates/serviceaccount.yaml
Expand Up @@ -7,7 +7,7 @@ metadata:
labels:
operator: rook
storage-backend: ceph
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
{{- include "library.rook-ceph.labels" . | nindent 4 }}
{{ template "library.imagePullSecrets" . }}
---
# Service account for the CephFS CSI driver
Expand Down

0 comments on commit afa2878

Please sign in to comment.