Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(helm-chart): use templates for unique resource names #14

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions charts/policy-hub/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "chart.name" -}}
{{- define "phub.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

Expand All @@ -10,7 +10,7 @@ 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 "chart.fullname" -}}
{{- define "phub.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
Expand All @@ -26,16 +26,16 @@ If release name contains chart name it will be used as a full name.
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "chart.chart" -}}
{{- define "phub.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "chart.labels" -}}
helm.sh/chart: {{ include "chart.chart" . }}
{{ include "chart.selectorLabels" . }}
{{- define "phub.labels" -}}
helm.sh/chart: {{ include "phub.chart" . }}
{{ include "phub.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
Expand All @@ -45,17 +45,17 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
{{/*
Selector labels
*/}}
{{- define "chart.selectorLabels" -}}
app.kubernetes.io/name: {{ include "chart.name" . }}
{{- define "phub.selectorLabels" -}}
app.kubernetes.io/name: {{ include "phub.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "chart.serviceAccountName" -}}
{{- define "phub.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "chart.fullname" .) .Values.serviceAccount.name }}
{{- default (include "phub.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
Expand Down
11 changes: 7 additions & 4 deletions charts/policy-hub/templates/deployment-hub.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,24 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}-{{ .Values.policyhub.name }}
name: {{ include "phub.fullname" . }}
namespace: {{ .Values.namespace }}
labels:
{{- include "phub.labels" . | nindent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
strategy:
{{- toYaml .Values.updateStrategy | nindent 4 }}
selector:
matchLabels:
app: {{ .Values.policyhub.name }}
{{- include "phub.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
app: {{ .Values.policyhub.name }}
{{- include "phub.selectorLabels" . | nindent 8 }}
spec:
containers:
- name: {{ .Values.policyhub.name }}
- name: {{ .Chart.Name }}
securityContext:
allowPrivilegeEscalation: false
capabilities:
Expand Down
10 changes: 5 additions & 5 deletions charts/policy-hub/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/}}

{{- if .Values.ingress.enabled -}}
{{- $fullName := .Values.ingress.name -}}
{{- $fullName := include "phub.fullname" . -}}
{{- $svcPort := .Values.portService -}}
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
Expand All @@ -34,9 +34,9 @@ apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ .Release.Name }}-{{ $fullName }}
name: {{ $fullName }}
labels:
{{- include "chart.labels" . | nindent 4 }}
{{- include "phub.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
Expand Down Expand Up @@ -68,11 +68,11 @@ spec:
backend:
{{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
service:
name: {{ .backend.service }}
name: {{ $fullName }}
port:
number: {{ $svcPort }}
{{- else }}
serviceName: {{ .backend.service }}
serviceName: {{ $fullName }}
servicePort: {{ .backend.port }}
{{- end }}
{{- end }}
Expand Down
7 changes: 4 additions & 3 deletions charts/policy-hub/templates/job-policy-hub-migrations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@
apiVersion: batch/v1
kind: Job
metadata:
name: {{ .Release.Name }}-{{ .Values.policyhubmigrations.name }}
name: {{ include "phub.fullname" . }}-migrations
annotations:
"batch.kubernetes.io/job-tracking": "true"
"helm.sh/hook": post-install,post-upgrade
"helm.sh/hook-weight": "-5"
spec:
template:
metadata:
name: {{ .Values.policyhubmigrations.name }}
labels:
{{- include "phub.selectorLabels" . | nindent 8 }}
spec:
restartPolicy: Never
containers:
- name: {{ .Values.policyhubmigrations.name }}
- name: {{ include "phub.fullname" . }}-migrations
securityContext:
allowPrivilegeEscalation: false
capabilities:
Expand Down
7 changes: 5 additions & 2 deletions charts/policy-hub/templates/service-hub.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
apiVersion: v1
kind: Service
metadata:
name: "{{ .Release.Name }}-{{ .Values.policyhub.name }}"
name: {{ include "phub.fullname" . }}
namespace: {{ .Values.namespace }}
labels:
{{- include "phub.labels" . | nindent 4 }}
spec:
type: ClusterIP
ports:
- port: {{ .Values.portService }}
targetPort: {{ .Values.portContainer }}
selector:
app: {{ .Values.policyhub.name }}
{{- include "phub.selectorLabels" . | nindent 4 }}
5 changes: 0 additions & 5 deletions charts/policy-hub/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
# SPDX-License-Identifier: Apache-2.0
###############################################################

name: "policy-hub"

# -- Provide centralidp base address (CX IAM), without trailing '/auth'.
centralidpAddress: "https://centralidp.example.org"

Expand Down Expand Up @@ -47,7 +45,6 @@ ingress:
- path: "/api/policy-hub"
pathType: "Prefix"
backend:
service: "policy-hub-service"
port: 8080
dotnetEnvironment: "Production"
dbConnection:
Expand Down Expand Up @@ -76,7 +73,6 @@ healthChecks:
path: "/ready"

policyhub:
name: "policy-hub-service"
image: "tractusx/policy-hub-service:0.1.0-rc.1"
# -- We recommend not to specify default resource limits and to leave this as a conscious choice for the user.
# If you do want to specify resource limits, uncomment the following lines and adjust them as necessary.
Expand All @@ -98,7 +94,6 @@ policyhub:
swaggerEnabled: false

policyhubmigrations:
name: "policy-hub-migrations"
image: "tractusx/policy-hub-migrations:0.1.0-rc.1"
# -- We recommend not to specify default resource limits and to leave this as a conscious choice for the user.
# If you do want to specify resource limits, uncomment the following lines and adjust them as necessary.
Expand Down
1 change: 0 additions & 1 deletion consortia/environments/values-beta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ ingress:
- path: "/api/policy-hub"
pathType: "Prefix"
backend:
service: "policy-hub-service"
port: 8080

policyhub:
Expand Down
1 change: 0 additions & 1 deletion consortia/environments/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ ingress:
- path: "/api/policy-hub"
pathType: "Prefix"
backend:
service: "policy-hub-service"
port: 8080

keycloak:
Expand Down
1 change: 0 additions & 1 deletion consortia/environments/values-int.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ ingress:
- path: "/api/policy-hub"
pathType: "Prefix"
backend:
service: "policy-hub-service"
port: 8080

keycloak:
Expand Down
1 change: 0 additions & 1 deletion consortia/environments/values-pen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ ingress:
- path: "/api/policy-hub"
pathType: "Prefix"
backend:
service: "policy-hub-service"
port: 8080

policyhub:
Expand Down
1 change: 0 additions & 1 deletion consortia/environments/values-rc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ ingress:
- path: "/api/policy-hub"
pathType: "Prefix"
backend:
service: "policy-hub-service"
port: 8080

policyhub:
Expand Down
Loading