Skip to content

Commit

Permalink
feature: added namespace helper
Browse files Browse the repository at this point in the history
- allows users to override the namespace
  • Loading branch information
Bugs5382 committed Oct 27, 2024
1 parent b1d0b09 commit 43c1a44
Show file tree
Hide file tree
Showing 49 changed files with 68 additions and 52 deletions.
13 changes: 13 additions & 0 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ If release name contains chart name it will be used as a full name.
{{- end }}
{{- end }}

{{/*
Construct the namespace for all namespaced resources
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
Preserve the default behavior of the Release namespace if no override is provided
*/}}
{{- define "harbor.namespace" -}}
{{- if .Values.namespaceOverride -}}
{{- .Values.namespaceOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- .Release.Namespace -}}
{{- end -}}
{{- end -}}

{{/* Helm required labels: legacy */}}
{{- define "harbor.legacy.labels" -}}
heritage: {{ .Release.Service }}
Expand Down
2 changes: 1 addition & 1 deletion templates/core/core-cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "harbor.core" . }}
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
data:
Expand Down
2 changes: 1 addition & 1 deletion templates/core/core-dpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "harbor.core" . }}
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
component: core
Expand Down
2 changes: 1 addition & 1 deletion templates/core/core-pre-upgrade-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: batch/v1
kind: Job
metadata:
name: migration-job
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
component: migrator
Expand Down
2 changes: 1 addition & 1 deletion templates/core/core-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v1
kind: Secret
metadata:
name: {{ template "harbor.core" . }}
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
type: Opaque
Expand Down
2 changes: 1 addition & 1 deletion templates/core/core-svc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
kind: Service
metadata:
name: {{ template "harbor.core" . }}
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
{{- with .Values.core.serviceAnnotations }}
Expand Down
2 changes: 1 addition & 1 deletion templates/core/core-tls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: v1
kind: Secret
metadata:
name: "{{ template "harbor.internalTLS.core.secretName" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
type: kubernetes.io/tls
Expand Down
2 changes: 1 addition & 1 deletion templates/database/database-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v1
kind: Secret
metadata:
name: "{{ template "harbor.database" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
type: Opaque
Expand Down
2 changes: 1 addition & 1 deletion templates/database/database-ss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apps/v1
kind: StatefulSet
metadata:
name: "{{ template "harbor.database" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
component: database
Expand Down
2 changes: 1 addition & 1 deletion templates/database/database-svc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v1
kind: Service
metadata:
name: "{{ template "harbor.database" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
spec:
Expand Down
2 changes: 1 addition & 1 deletion templates/exporter/exporter-cm-env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ template "harbor.exporter" . }}-env"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
data:
Expand Down
2 changes: 1 addition & 1 deletion templates/exporter/exporter-dpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "harbor.exporter" . }}
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
component: exporter
Expand Down
2 changes: 1 addition & 1 deletion templates/exporter/exporter-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v1
kind: Secret
metadata:
name: {{ template "harbor.exporter" . }}
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
type: Opaque
Expand Down
2 changes: 1 addition & 1 deletion templates/exporter/exporter-svc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v1
kind: Service
metadata:
name: "{{ template "harbor.exporter" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
spec:
Expand Down
2 changes: 1 addition & 1 deletion templates/ingress/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: "{{ template "harbor.ingress" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
{{- if $ingress.labels }}
Expand Down
2 changes: 1 addition & 1 deletion templates/ingress/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apiVersion: v1
kind: Secret
metadata:
name: "{{ template "harbor.ingress" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
type: kubernetes.io/tls
Expand Down
10 changes: 5 additions & 5 deletions templates/internal/auto-tls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apiVersion: v1
kind: Secret
metadata:
name: "{{ template "harbor.internalTLS.core.secretName" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
type: kubernetes.io/tls
Expand All @@ -28,7 +28,7 @@ apiVersion: v1
kind: Secret
metadata:
name: "{{ template "harbor.internalTLS.jobservice.secretName" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
type: kubernetes.io/tls
Expand All @@ -42,7 +42,7 @@ apiVersion: v1
kind: Secret
metadata:
name: "{{ template "harbor.internalTLS.registry.secretName" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
type: kubernetes.io/tls
Expand All @@ -56,7 +56,7 @@ apiVersion: v1
kind: Secret
metadata:
name: "{{ template "harbor.internalTLS.portal.secretName" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
type: kubernetes.io/tls
Expand All @@ -73,7 +73,7 @@ apiVersion: v1
kind: Secret
metadata:
name: "{{ template "harbor.internalTLS.trivy.secretName" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
type: kubernetes.io/tls
Expand Down
2 changes: 1 addition & 1 deletion templates/jobservice/jobservice-cm-env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ template "harbor.jobservice" . }}-env"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
data:
Expand Down
2 changes: 1 addition & 1 deletion templates/jobservice/jobservice-cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ template "harbor.jobservice" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
data:
Expand Down
2 changes: 1 addition & 1 deletion templates/jobservice/jobservice-dpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: "{{ template "harbor.jobservice" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
component: jobservice
Expand Down
2 changes: 1 addition & 1 deletion templates/jobservice/jobservice-pvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ template "harbor.jobservice" . }}
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
annotations:
{{- range $key, $value := $jobLog.annotations }}
{{ $key }}: {{ $value | quote }}
Expand Down
2 changes: 1 addition & 1 deletion templates/jobservice/jobservice-secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v1
kind: Secret
metadata:
name: "{{ template "harbor.jobservice" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
type: Opaque
Expand Down
2 changes: 1 addition & 1 deletion templates/jobservice/jobservice-svc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
kind: Service
metadata:
name: "{{ template "harbor.jobservice" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
spec:
Expand Down
2 changes: 1 addition & 1 deletion templates/jobservice/jobservice-tls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: v1
kind: Secret
metadata:
name: "{{ template "harbor.internalTLS.jobservice.secretName" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
type: kubernetes.io/tls
Expand Down
2 changes: 1 addition & 1 deletion templates/metrics/metrics-svcmon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ template "harbor.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels: {{ include "harbor.labels" . | nindent 4 }}
{{- if .Values.metrics.serviceMonitor.additionalLabels }}
{{ toYaml .Values.metrics.serviceMonitor.additionalLabels | indent 4 }}
Expand Down
2 changes: 1 addition & 1 deletion templates/nginx/configmap-http.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "harbor.nginx" . }}
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
data:
Expand Down
2 changes: 1 addition & 1 deletion templates/nginx/configmap-https.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "harbor.nginx" . }}
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
data:
Expand Down
2 changes: 1 addition & 1 deletion templates/nginx/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "harbor.nginx" . }}
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
component: nginx
Expand Down
2 changes: 1 addition & 1 deletion templates/nginx/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apiVersion: v1
kind: Secret
metadata:
name: {{ template "harbor.nginx" . }}
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
type: Opaque
Expand Down
2 changes: 1 addition & 1 deletion templates/nginx/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
{{- if eq .Values.expose.type "clusterIP" }}
{{- $clusterIP := .Values.expose.clusterIP }}
name: {{ $clusterIP.name }}
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
{{- if .Values.expose.clusterIP.labels }}
Expand Down
2 changes: 1 addition & 1 deletion templates/portal/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ template "harbor.portal" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
data:
Expand Down
2 changes: 1 addition & 1 deletion templates/portal/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: "{{ template "harbor.portal" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
component: portal
Expand Down
2 changes: 1 addition & 1 deletion templates/portal/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
kind: Service
metadata:
name: "{{ template "harbor.portal" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
{{- with .Values.portal.serviceAnnotations }}
Expand Down
2 changes: 1 addition & 1 deletion templates/portal/tls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: v1
kind: Secret
metadata:
name: "{{ template "harbor.internalTLS.portal.secretName" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
type: kubernetes.io/tls
Expand Down
2 changes: 1 addition & 1 deletion templates/redis/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v1
kind: Service
metadata:
name: {{ template "harbor.redis" . }}
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
spec:
Expand Down
2 changes: 1 addition & 1 deletion templates/redis/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ template "harbor.redis" . }}
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
component: redis
Expand Down
2 changes: 1 addition & 1 deletion templates/registry/registry-cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ template "harbor.registry" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
data:
Expand Down
2 changes: 1 addition & 1 deletion templates/registry/registry-dpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: "{{ template "harbor.registry" . }}"
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
labels:
{{ include "harbor.labels" . | indent 4 }}
component: registry
Expand Down
2 changes: 1 addition & 1 deletion templates/registry/registry-pvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ template "harbor.registry" . }}
namespace: {{ .Release.Namespace | quote }}
namespace: {{ template "harbor.namespace" . }}
annotations:
{{- range $key, $value := $registry.annotations }}
{{ $key }}: {{ $value | quote }}
Expand Down
Loading

0 comments on commit 43c1a44

Please sign in to comment.