Skip to content

Commit

Permalink
Merge pull request karmada-io#4337 from a7i/helm-common-labels
Browse files Browse the repository at this point in the history
feat: helm common labels for all resources
  • Loading branch information
karmada-bot authored Dec 1, 2023
2 parents 27a3e54 + ee24338 commit 6128367
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 1 deletion.
33 changes: 32 additions & 1 deletion charts/karmada/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@
{{- default .Release.Namespace -}}
{{- end -}}

{{- define "karmada.commonLabels" -}}
{{- if .Values.global.commonLabels -}}
{{- range $key, $value := .Values.global.commonLabels }}
{{ $key }}: {{ $value | quote }}
{{- end -}}
{{- end -}}
{{- end -}}

{{- define "karmada.apiserver.labels" -}}
{{- if .Values.apiServer.labels }}
{{- range $key, $value := .Values.apiServer.labels }}
{{ $key }}: {{ $value }}
{{- end }}
{{- else}}
{{- include "karmada.commonLabels" . -}}
app: {{- include "karmada.name" .}}-apiserver
{{- end }}
{{- end -}}
Expand All @@ -29,9 +38,10 @@ app: {{- include "karmada.name" .}}-apiserver
{{- define "karmada.etcd.labels" -}}
{{- if .Values.etcd.labels }}
{{- range $key, $value := .Values.etcd.labels }}
{{ $key }}: {{ $value }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- else}}
{{- include "karmada.commonLabels" . -}}
app: etcd
{{- end }}
{{- end -}}
Expand All @@ -52,6 +62,7 @@ app: etcd
{{- else}}
app: {{- include "karmada.name" .}}-aggregated-apiserver
{{- end }}
{{- include "karmada.commonLabels" . -}}
{{- end -}}

{{- define "karmada.aggregatedApiServer.podLabels" -}}
Expand Down Expand Up @@ -88,6 +99,7 @@ app: {{- include "karmada.name" .}}-metrics-adapter
{{- else}}
app: {{- include "karmada.name" .}}-kube-controller-manager
{{- end }}
{{- include "karmada.commonLabels" . -}}
{{- end -}}

{{- define "karmada.kube-cm.podLabels" -}}
Expand Down Expand Up @@ -129,6 +141,7 @@ certificate-authority-data: {{ b64enc .Values.certs.custom.caCrt }}
{{- else -}}
app: {{$name}}-controller-manager
{{- end -}}
{{- include "karmada.commonLabels" . -}}
{{- end -}}

{{- define "karmada.cm.podLabels" -}}
Expand All @@ -149,6 +162,7 @@ app: {{$name}}-controller-manager
{{- else -}}
app: {{$name}}-scheduler
{{- end -}}
{{- include "karmada.commonLabels" . -}}
{{- end -}}

{{- define "karmada.scheduler.podLabels" -}}
Expand All @@ -169,6 +183,7 @@ app: {{$name}}-scheduler
{{- else -}}
app: {{$name}}
{{- end -}}
{{- include "karmada.commonLabels" . -}}
{{- end -}}

{{- define "karmada.descheduler.podLabels" -}}
Expand Down Expand Up @@ -202,6 +217,7 @@ app: {{$name}}
{{- else}}
app: {{$name}}-webhook
{{- end }}
{{- include "karmada.commonLabels" . -}}
{{- end -}}

{{- define "karmada.webhook.podLabels" -}}
Expand All @@ -221,6 +237,7 @@ app: {{$name}}-webhook
{{- else}}
app: {{$name}}
{{- end }}
{{- include "karmada.commonLabels" . -}}
{{- end -}}

{{- define "karmada.agent.podLabels" -}}
Expand Down Expand Up @@ -263,6 +280,7 @@ caBundle: {{ b64enc .Values.certs.custom.caCrt }}
{{ $key }}: {{ $value }}
{{- end }}
{{- end }}
{{- include "karmada.commonLabels" . -}}
{{- end -}}

{{- define "karmada.search.labels" -}}
Expand All @@ -273,6 +291,7 @@ caBundle: {{ b64enc .Values.certs.custom.caCrt }}
{{- else}}
app: {{- include "karmada.name" .}}-search
{{- end }}
{{- include "karmada.commonLabels" . -}}
{{- end -}}

{{- define "karmada.search.podLabels" -}}
Expand All @@ -283,6 +302,18 @@ app: {{- include "karmada.name" .}}-search
{{- end }}
{{- end -}}

{{- define "karmada.preInstallJob.labels" -}}
{{- include "karmada.commonLabels" . -}}
{{- end -}}

{{- define "karmada.postInstallJob.labels" -}}
{{- include "karmada.commonLabels" . -}}
{{- end -}}

{{- define "karmada.postDeleteJob.labels" -}}
{{- include "karmada.commonLabels" . -}}
{{- end -}}

{{- define "karmada.search.kubeconfig.volume" -}}
{{ $name := include "karmada.name" . }}
{{- if eq .Values.installMode "host" -}}
Expand Down
2 changes: 2 additions & 0 deletions charts/karmada/templates/_karmada-clusterrole.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ metadata:
kubernetes.io/bootstrapping: rbac-defaults
# used to aggregate rules to view clusterrole
rbac.authorization.k8s.io/aggregate-to-view: "true"
{{- include "karmada.commonLabels" . | nindent 4 }}
name: karmada-view
rules:
- apiGroups:
Expand Down Expand Up @@ -83,6 +84,7 @@ metadata:
kubernetes.io/bootstrapping: rbac-defaults
# used to aggregate rules to view clusterrole
rbac.authorization.k8s.io/aggregate-to-edit: "true"
{{- include "karmada.commonLabels" . | nindent 4 }}
name: karmada-edit
rules:
- apiGroups:
Expand Down
8 changes: 8 additions & 0 deletions charts/karmada/templates/_karmada_apiservice.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ metadata:
labels:
app: {{ $name }}-aggregated-apiserver
apiserver: "true"
{{- include "karmada.commonLabels" . | nindent 4 }}
spec:
{{- include "karmada.apiserver.caBundle" . | nindent 2 }}
group: cluster.karmada.io
Expand All @@ -25,6 +26,9 @@ kind: Service
metadata:
name: {{ $name }}-aggregated-apiserver
namespace: {{ $systemNamespace }}
labels:
app: {{ $name }}-aggregated-apiserver
{{- include "karmada.commonLabels" . | nindent 4 }}
spec:
type: ExternalName
externalName: {{ $name }}-aggregated-apiserver.{{ include "karmada.namespace" . }}.svc.{{ .Values.clusterDomain }}
Expand Down Expand Up @@ -98,6 +102,7 @@ metadata:
labels:
app: {{ $name }}-search
apiserver: "true"
{{- include "karmada.commonLabels" . | nindent 4 }}
spec:
{{- include "karmada.apiserver.caBundle" . | nindent 2 }}
group: search.karmada.io
Expand All @@ -113,6 +118,9 @@ kind: Service
metadata:
name: {{ $name }}-search
namespace: {{ $systemNamespace }}
labels:
app: {{ $name }}-search
{{- include "karmada.commonLabels" . | nindent 4 }}
spec:
type: ExternalName
externalName: {{ $name }}-search.{{ include "karmada.namespace" . }}.svc.{{ .Values.clusterDomain }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ kind: ConfigMap
metadata:
name: cluster-info
namespace: kube-public
{{- if "karmada.commonLabels" }}
labels:
{{- include "karmada.commonLabels" . | nindent 4 }}
{{- end }}
data:
kubeconfig: |
apiVersion: v1
Expand All @@ -21,6 +25,10 @@ kind: Role
metadata:
name: karmada:bootstrap-signer-clusterinfo
namespace: kube-public
{{- if "karmada.commonLabels" }}
labels:
{{- include "karmada.commonLabels" . | nindent 4 }}
{{- end }}
rules:
- apiGroups:
- ""
Expand All @@ -36,6 +44,10 @@ kind: RoleBinding
metadata:
name: karmada:bootstrap-signer-clusterinfo
namespace: kube-public
{{- if "karmada.commonLabels" }}
labels:
{{- include "karmada.commonLabels" . | nindent 4 }}
{{- end }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
Expand All @@ -49,6 +61,10 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: karmada:agent-bootstrap
{{- if "karmada.commonLabels" }}
labels:
{{- include "karmada.commonLabels" . | nindent 4 }}
{{- end }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
Expand All @@ -62,6 +78,10 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: karmada:agent-autoapprove-bootstrap
{{- if "karmada.commonLabels" }}
labels:
{{- include "karmada.commonLabels" . | nindent 4 }}
{{- end }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
Expand All @@ -75,6 +95,10 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: karmada:agent-autoapprove-certificate-rotation
{{- if "karmada.commonLabels" }}
labels:
{{- include "karmada.commonLabels" . | nindent 4 }}
{{- end }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
Expand All @@ -88,6 +112,10 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: system:karmada:agent
{{- if "karmada.commonLabels" }}
labels:
{{- include "karmada.commonLabels" . | nindent 4 }}
{{- end }}
rules:
- apiGroups:
- authentication.k8s.io
Expand Down Expand Up @@ -191,6 +219,10 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: system:karmada:agent
{{- if "karmada.commonLabels" }}
labels:
{{- include "karmada.commonLabels" . | nindent 4 }}
{{- end }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ $name }}-cluster-proxy-admin
{{- if "karmada.commonLabels" }}
labels:
{{- include "karmada.commonLabels" . | nindent 4 }}
{{- end }}
rules:
- apiGroups:
- 'cluster.karmada.io'
Expand All @@ -17,6 +21,10 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ $name }}-cluster-proxy-admin
{{- if "karmada.commonLabels" }}
labels:
{{- include "karmada.commonLabels" . | nindent 4 }}
{{- end }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
Expand Down
8 changes: 8 additions & 0 deletions charts/karmada/templates/_karmada_system_namespace.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ apiVersion: v1
kind: Namespace
metadata:
name: {{ .Values.systemNamespace }}
{{- if "karmada.commonLabels" }}
labels:
{{- include "karmada.commonLabels" . | nindent 4 }}
{{- end }}
---
apiVersion: v1
kind: Namespace
metadata:
name: karmada-cluster
{{- if "karmada.commonLabels" }}
labels:
{{- include "karmada.commonLabels" . | nindent 4 }}
{{- end }}
{{- end -}}
2 changes: 2 additions & 0 deletions charts/karmada/templates/_karmada_webhook_configuration.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ metadata:
name: mutating-config
labels:
app: mutating-config
{{- include "karmada.commonLabels" . | nindent 4 }}
webhooks:
- name: propagationpolicy.karmada.io
rules:
Expand Down Expand Up @@ -100,6 +101,7 @@ metadata:
name: validating-config
labels:
app: validating-config
{{- include "karmada.commonLabels" . | nindent 4 }}
webhooks:
- name: propagationpolicy.karmada.io
rules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: clusterresourcebindings.work.karmada.io
{{- if "karmada.commonLabels" }}
labels:
{{- include "karmada.commonLabels" . | nindent 4 }}
{{- end }}
spec:
conversion:
strategy: Webhook
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: resourcebindings.work.karmada.io
{{- if "karmada.commonLabels" }}
labels:
{{- include "karmada.commonLabels" . | nindent 4 }}
{{- end }}
spec:
conversion:
strategy: Webhook
Expand Down
1 change: 1 addition & 0 deletions charts/karmada/templates/post-delete-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ metadata:
namespace: {{ $namespace }}
labels:
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
{{- include "karmada.postDeleteJob.labels" . | nindent 4 }}
annotations:
# This is what defines this resource as a hook. Without this line, the
# job is considered part of the release.
Expand Down
1 change: 1 addition & 0 deletions charts/karmada/templates/post-install-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ metadata:
app.kubernetes.io/instance: {{ $name | quote }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
{{- include "karmada.postInstallJob.labels" . | nindent 4 }}
annotations:
# This is what defines this resource as a hook. Without this line, the
# job is considered part of the release.
Expand Down
Loading

0 comments on commit 6128367

Please sign in to comment.