From c88c9f28d303a764a8a0ccdf421805773ded3f90 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Thu, 14 Oct 2021 17:36:20 -0700 Subject: [PATCH] update registry chart --- helm/charts/registry/templates/_helpers.tpl | 62 +++++++++++++++++++ helm/charts/registry/templates/configmap.yaml | 5 +- .../charts/registry/templates/deployment.yaml | 18 +++--- helm/charts/registry/templates/ingress.yaml | 5 +- helm/charts/registry/templates/pvc.yaml | 5 +- helm/charts/registry/templates/role.yaml | 5 +- .../registry/templates/rolebinding.yaml | 13 ++-- helm/charts/registry/templates/secret.yaml | 4 +- helm/charts/registry/templates/service.yaml | 9 ++- .../registry/templates/serviceaccount.yaml | 5 +- helm/charts/registry/values.yaml | 7 +++ 11 files changed, 107 insertions(+), 31 deletions(-) create mode 100644 helm/charts/registry/templates/_helpers.tpl diff --git a/helm/charts/registry/templates/_helpers.tpl b/helm/charts/registry/templates/_helpers.tpl new file mode 100644 index 0000000000..0ed5df43ad --- /dev/null +++ b/helm/charts/registry/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "registry.name" -}} +{{- default .Chart.Name .Values.nameOverride | 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 "registry.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "registry.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "registry.labels" -}} +helm.sh/chart: {{ include "registry.chart" . }} +{{ include "registry.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "registry.selectorLabels" -}} +app.kubernetes.io/name: {{ include "registry.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "registry.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "registry.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/helm/charts/registry/templates/configmap.yaml b/helm/charts/registry/templates/configmap.yaml index 72d405544c..d90b129128 100644 --- a/helm/charts/registry/templates/configmap.yaml +++ b/helm/charts/registry/templates/configmap.yaml @@ -2,8 +2,9 @@ apiVersion: v1 kind: ConfigMap metadata: - name: infra-registry - namespace: {{ .Release.Namespace }} + name: {{ include "registry.fullname" . }} + labels: +{{- include "registry.labels" . | nindent 4 }} data: {{- if kindIs "map" .Values.config }} infra.yaml: | diff --git a/helm/charts/registry/templates/deployment.yaml b/helm/charts/registry/templates/deployment.yaml index 2f671217b6..e768f91a87 100644 --- a/helm/charts/registry/templates/deployment.yaml +++ b/helm/charts/registry/templates/deployment.yaml @@ -1,28 +1,32 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: infra-registry - namespace: {{ .Release.Namespace }} + name: {{ include "registry.fullname" . }} + labels: +{{- include "registry.labels" . | nindent 4 }} spec: selector: matchLabels: - app: infra-registry +{{- include "registry.selectorLabels" . | nindent 6 }} replicas: 1 template: metadata: labels: - app: infra-registry +{{- include "registry.selectorLabels" . | nindent 8 }} +{{- with .Values.pod.annotations }} annotations: rollme: {{ randAlphaNum 5 | quote }} + {{- toYaml . | nindent 8 }} +{{- end }} spec: automountServiceAccountToken: true - serviceAccountName: infra-registry + serviceAccountName: {{ include "registry.serviceAccountName" . }} dnsPolicy: ClusterFirst {{- with .Values.image.pullSecrets }} imagePullSecrets: -{{- range . }} + {{- range . }} - name: {{ . }} -{{- end }} + {{- end }} {{- end }} containers: - name: registry diff --git a/helm/charts/registry/templates/ingress.yaml b/helm/charts/registry/templates/ingress.yaml index e4dd177aed..95426b5897 100644 --- a/helm/charts/registry/templates/ingress.yaml +++ b/helm/charts/registry/templates/ingress.yaml @@ -11,10 +11,9 @@ apiVersion: {{ $apiVersion }} kind: Ingress metadata: - name: infra-registry - namespace: {{ .Release.Namespace }} + name: {{ include "registry.fullname" . }} labels: - app: infra-registry +{{- include "registry.labels" . | nindent 4 }} {{- with .Values.ingress.labels }} {{- toYaml . | nindent 4 }} {{- end }} diff --git a/helm/charts/registry/templates/pvc.yaml b/helm/charts/registry/templates/pvc.yaml index 6a95292b11..f3dbe33f01 100644 --- a/helm/charts/registry/templates/pvc.yaml +++ b/helm/charts/registry/templates/pvc.yaml @@ -1,8 +1,9 @@ apiVersion: v1 kind: PersistentVolumeClaim metadata: - name: infra-registry - namespace: {{ .Release.Namespace }} + name: {{ include "registry.fullname" . }} + labels: +{{- include "registry.labels" . | nindent 4 }} spec: accessModes: - ReadWriteOnce diff --git a/helm/charts/registry/templates/role.yaml b/helm/charts/registry/templates/role.yaml index 50402e783f..352ad82241 100644 --- a/helm/charts/registry/templates/role.yaml +++ b/helm/charts/registry/templates/role.yaml @@ -1,8 +1,9 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: - name: infra-registry-secret-reader - namespace: {{ .Release.Namespace }} + name: {{ include "registry.fullname" . }} + labels: +{{- include "registry.labels" . | nindent 4 }} rules: - apiGroups: [""] resources: ["secrets"] diff --git a/helm/charts/registry/templates/rolebinding.yaml b/helm/charts/registry/templates/rolebinding.yaml index 81fde98b36..7cb4a95c25 100644 --- a/helm/charts/registry/templates/rolebinding.yaml +++ b/helm/charts/registry/templates/rolebinding.yaml @@ -1,13 +1,14 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: - name: infra-registry-secret-reader - namespace: {{ .Release.Namespace }} + name: {{ include "registry.fullname" . }} + labels: +{{- include "registry.labels" . | nindent 4 }} subjects: -- kind: ServiceAccount - name: infra-registry - namespace: {{ .Release.Namespace }} + - kind: ServiceAccount + name: {{ include "registry.fullname" . }} + namespace: {{ .Release.Namespace }} roleRef: apiGroup: rbac.authorization.k8s.io kind: Role - name: infra-registry-secret-reader \ No newline at end of file + name: {{ include "registry.fullname" . }} diff --git a/helm/charts/registry/templates/secret.yaml b/helm/charts/registry/templates/secret.yaml index 11996ec051..70a6da6c6a 100644 --- a/helm/charts/registry/templates/secret.yaml +++ b/helm/charts/registry/templates/secret.yaml @@ -18,9 +18,9 @@ apiVersion: v1 kind: Secret metadata: - name: infra-registry - namespace: {{ .Release.Namespace }} + name: {{ include "registry.fullname" . }} labels: +{{- include "registry.labels" . | nindent 4 }} type: Opaque data: rootApiKey: {{ include "rootApiKey" . | b64enc | quote }} diff --git a/helm/charts/registry/templates/service.yaml b/helm/charts/registry/templates/service.yaml index d2d3a5f2e0..ebfb07998f 100644 --- a/helm/charts/registry/templates/service.yaml +++ b/helm/charts/registry/templates/service.yaml @@ -1,10 +1,9 @@ apiVersion: v1 kind: Service metadata: - name: infra-registry - namespace: {{ .Release.Namespace }} + name: {{ include "registry.fullname" . }} labels: - app: infra-registry +{{- include "registry.labels" . | nindent 4 }} {{- with .Values.service.labels }} {{- toYaml . | nindent 4 }} {{- end }} @@ -34,7 +33,7 @@ spec: {{- end }} {{- with .Values.service.externalIPs }} externalIPs: - {{ toYaml . | indent 4 }} + {{- toYaml . | nindent 4 }} {{- end }} ports: {{- range .Values.service.ports }} @@ -47,4 +46,4 @@ spec: {{- end }} {{- end }} selector: - app: infra-registry +{{- include "registry.selectorLabels" . | nindent 6 }} diff --git a/helm/charts/registry/templates/serviceaccount.yaml b/helm/charts/registry/templates/serviceaccount.yaml index 39e53c707f..f2ca42f86d 100644 --- a/helm/charts/registry/templates/serviceaccount.yaml +++ b/helm/charts/registry/templates/serviceaccount.yaml @@ -1,5 +1,6 @@ apiVersion: v1 kind: ServiceAccount metadata: - name: infra-registry - namespace: {{ .Release.Namespace }} \ No newline at end of file + name: {{ include "registry.fullname" . }} + labels: +{{- include "registry.labels" . | nindent 4 }} diff --git a/helm/charts/registry/values.yaml b/helm/charts/registry/values.yaml index 90cb6f128c..9e6d32aad4 100644 --- a/helm/charts/registry/values.yaml +++ b/helm/charts/registry/values.yaml @@ -2,6 +2,13 @@ storage: 1Gi engineApiKey: "" config: null +pod: + annotations: {} + +serviceAccount: + create: true + annotations: {} + image: repository: infrahq/infra tag: ""