From 650ae3ba94ae322fc745eb07658f1663b3e7e321 Mon Sep 17 00:00:00 2001 From: Milos Backonja <35807060+milosbackonja@users.noreply.github.com> Date: Mon, 3 Jun 2024 13:09:18 +0200 Subject: [PATCH] fix: Changing .chart.name reference, adding name override (#1129) Signed-off-by: Milos Backonja --- .../charts/agent/templates/_helpers.tpl | 34 +++++++++++++- .../charts/agent/templates/apisixroute.yaml | 20 ++++----- .../charts/agent/templates/apisixtls.yaml | 4 +- .../charts/agent/templates/certificate.yaml | 4 +- .../charts/agent/templates/configmap.yaml | 4 +- .../charts/agent/templates/deployment.yaml | 44 +++++++++---------- .../charts/agent/templates/postgresql.yaml | 2 +- .../charts/agent/templates/service.yaml | 18 ++++---- infrastructure/charts/agent/values.yaml | 2 + 9 files changed, 83 insertions(+), 49 deletions(-) diff --git a/infrastructure/charts/agent/templates/_helpers.tpl b/infrastructure/charts/agent/templates/_helpers.tpl index 28264f5992..3ed226d1b3 100644 --- a/infrastructure/charts/agent/templates/_helpers.tpl +++ b/infrastructure/charts/agent/templates/_helpers.tpl @@ -1,3 +1,35 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "cloud-agent.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 "cloud-agent.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 "cloud-agent.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + {{- define "cors" }} {{- if .Values.ingress.cors.enabled }} - name: cors @@ -21,7 +53,7 @@ {{- end }} {{- end -}} {{- define "labels.common" -}} -app.kubernetes.io/part-of: {{ .Chart.Name }} +app.kubernetes.io/part-of: {{ include "cloud-agent.fullname" . }} {{- end -}} {{- define "headers.security" }} - name: response-rewrite diff --git a/infrastructure/charts/agent/templates/apisixroute.yaml b/infrastructure/charts/agent/templates/apisixroute.yaml index 7ea65196db..794f861c83 100644 --- a/infrastructure/charts/agent/templates/apisixroute.yaml +++ b/infrastructure/charts/agent/templates/apisixroute.yaml @@ -16,7 +16,7 @@ spec: {{- end }} paths: - /prism-agent/* - - /{{ .Chart.Name }}/* + - /{{ include "cloud-agent.fullname" . }}/* backends: - serviceName: agent-server-tapir-service servicePort: 8085 @@ -27,7 +27,7 @@ spec: - name: proxy-rewrite enable: true config: - regex_uri: ["^/(prism-agent|{{ .Chart.Name }})/(.*)","/$2"] + regex_uri: ["^/(prism-agent|{{ include "cloud-agent.fullname" . }})/(.*)","/$2"] - name: uri-blocker enable: true config: @@ -57,7 +57,7 @@ spec: {{- end }} paths: - /prism-agent/didcomm* - - /{{ .Chart.Name }}/didcomm* + - /{{ include "cloud-agent.fullname" . }}/didcomm* backends: - serviceName: agent-server-didcomm-service servicePort: 8090 @@ -65,7 +65,7 @@ spec: - name: proxy-rewrite enable: true config: - regex_uri: ["^/(prism-agent|{{ .Chart.Name }})/didcomm(.*)", "/$2"] + regex_uri: ["^/(prism-agent|{{ include "cloud-agent.fullname" . }})/didcomm(.*)", "/$2"] {{ template "cors" . }} {{ template "headers.requestId" . }} {{ template "headers.security" . }} @@ -89,7 +89,7 @@ spec: {{- end }} paths: - /prism-agent/schema-registry/schemas/* - - /{{ .Chart.Name }}/schema-registry/schemas/* + - /{{ include "cloud-agent.fullname" . }}/schema-registry/schemas/* methods: - GET backends: @@ -99,7 +99,7 @@ spec: - name: proxy-rewrite enable: true config: - regex_uri: ["^/(prism-agent|{{ .Chart.Name }})/schema-registry/schemas/(.*)", "/schema-registry/schemas/$2"] + regex_uri: ["^/(prism-agent|{{ include "cloud-agent.fullname" . }})/schema-registry/schemas/(.*)", "/schema-registry/schemas/$2"] {{ template "cors" . }} {{ template "headers.requestId" . }} {{ template "headers.security" . }} @@ -123,7 +123,7 @@ spec: {{- end }} paths: - /prism-agent/credential-definition-registry/definitions/* - - /{{ .Chart.Name }}/credential-definition-registry/definitions/* + - /{{ include "cloud-agent.fullname" . }}/credential-definition-registry/definitions/* methods: - GET backends: @@ -133,7 +133,7 @@ spec: - name: proxy-rewrite enable: true config: - regex_uri: ["^/(prism-agent|{{ .Chart.Name }})/credential-definition-registry/definitions/(.*)", "/credential-definition-registry/definitions/$2"] + regex_uri: ["^/(prism-agent|{{ include "cloud-agent.fullname" . }})/credential-definition-registry/definitions/(.*)", "/credential-definition-registry/definitions/$2"] {{ template "cors" . }} {{ template "headers.requestId" . }} {{ template "headers.security" . }} @@ -157,7 +157,7 @@ spec: {{- end }} paths: - /prism-agent/docs/* - - /{{ .Chart.Name }}/docs/* + - /{{ include "cloud-agent.fullname" . }}/docs/* backends: - serviceName: agent-server-tapir-service servicePort: 8085 @@ -165,7 +165,7 @@ spec: - name: proxy-rewrite enable: true config: - regex_uri: ["^/(prism-agent|{{ .Chart.Name }})/docs/(.*)","/docs/$2"] + regex_uri: ["^/(prism-agent|{{ include "cloud-agent.fullname" . }})/docs/(.*)","/docs/$2"] {{ template "cors" . }} {{ template "headers.requestId" . }} {{ template "headers.security" . }} diff --git a/infrastructure/charts/agent/templates/apisixtls.yaml b/infrastructure/charts/agent/templates/apisixtls.yaml index 13b88a8347..bdfa30fb00 100644 --- a/infrastructure/charts/agent/templates/apisixtls.yaml +++ b/infrastructure/charts/agent/templates/apisixtls.yaml @@ -2,7 +2,7 @@ apiVersion: apisix.apache.org/v2 kind: ApisixTls metadata: - name: "{{ .Chart.Name }}-base-path-tls" + name: "{{ include "cloud-agent.fullname" . }}-base-path-tls" namespace: "{{ .Release.Namespace }}" labels: {{ template "labels.common" . }} @@ -12,6 +12,6 @@ spec: - {{ . }} {{- end }} secret: - name: "{{ .Chart.Name }}-base-path-secret" + name: "{{ include "cloud-agent.fullname" . }}-base-path-secret" namespace: "{{ .Release.Namespace }}" {{- end }} diff --git a/infrastructure/charts/agent/templates/certificate.yaml b/infrastructure/charts/agent/templates/certificate.yaml index 35777cc34a..20fca71ca0 100644 --- a/infrastructure/charts/agent/templates/certificate.yaml +++ b/infrastructure/charts/agent/templates/certificate.yaml @@ -2,14 +2,14 @@ apiVersion: cert-manager.io/v1 kind: Certificate metadata: - name: "{{ .Chart.Name }}-base-path-cert" + name: "{{ include "cloud-agent.fullname" . }}-base-path-cert" namespace: "{{ .Release.Namespace }}" labels: {{ template "labels.common" . }} annotations: argocd.argoproj.io/sync-wave: "-1" spec: - secretName: "{{ .Chart.Name }}-base-path-secret" + secretName: "{{ include "cloud-agent.fullname" . }}-base-path-secret" duration: 2160h0m0s # 90d renewBefore: 360h0m0s # 15d issuerRef: diff --git a/infrastructure/charts/agent/templates/configmap.yaml b/infrastructure/charts/agent/templates/configmap.yaml index 9641f06603..a344fb7c9a 100644 --- a/infrastructure/charts/agent/templates/configmap.yaml +++ b/infrastructure/charts/agent/templates/configmap.yaml @@ -81,9 +81,9 @@ data: apiVersion: v1 kind: ConfigMap metadata: - name: {{ .Chart.Name }}-realm-import + name: {{ include "cloud-agent.fullname" . }}-realm-import data: - {{ .Chart.Name }}.json: | + {{ include "cloud-agent.fullname" . }}.json: | { "realm": {{ .Values.server.keycloak.realm | quote }}, "enabled": true diff --git a/infrastructure/charts/agent/templates/deployment.yaml b/infrastructure/charts/agent/templates/deployment.yaml index 9dc4973189..9adccc43ce 100644 --- a/infrastructure/charts/agent/templates/deployment.yaml +++ b/infrastructure/charts/agent/templates/deployment.yaml @@ -1,19 +1,19 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: {{ .Chart.Name }}-server + name: {{ include "cloud-agent.fullname" . }}-server namespace: "{{ .Release.Namespace }}" labels: {{ template "labels.common" . }} spec: selector: matchLabels: - app.kubernetes.io/name: {{ .Chart.Name }}-server + app.kubernetes.io/name: {{ include "cloud-agent.fullname" . }}-server replicas: 1 template: metadata: labels: - app.kubernetes.io/name: {{ .Chart.Name }}-server + app.kubernetes.io/name: {{ include "cloud-agent.fullname" . }}-server {{ template "labels.common" . }} spec: imagePullSecrets: @@ -21,7 +21,7 @@ spec: initContainers: - name: wait-postgress-ready image: busybox - command: ['sh', '-c', "until nc -z {{ .Values.database.postgres.managingTeam }}-{{ .Chart.Name }}-postgres-cluster.{{.Release.Namespace}} 5432; do echo waiting for postgress-operator; sleep 2; done;"] + command: ['sh', '-c', "until nc -z {{ .Values.database.postgres.managingTeam }}-{{ include "cloud-agent.fullname" . }}-postgres-cluster.{{.Release.Namespace}} 5432; do echo waiting for postgress-operator; sleep 2; done;"] {{- if .Values.server.keycloak.enabled }} - name: wait-keycloak-ready image: badouralix/curl-jq:ubuntu @@ -52,7 +52,7 @@ spec: {{- end }} {{- end }} containers: - - name: {{ .Chart.Name }}-server + - name: {{ include "cloud-agent.fullname" . }}-server image: "{{ .Values.server.image.repository }}/{{ .Values.server.image.tag }}:{{ .Values.server.image.version | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.server.image.pullPolicy }} livenessProbe: @@ -78,7 +78,7 @@ spec: key: salt optional: false - name: POLLUX_DB_HOST - value: "{{ .Values.database.postgres.managingTeam }}-{{ .Chart.Name }}-postgres-cluster.{{.Release.Namespace}}" + value: "{{ .Values.database.postgres.managingTeam }}-{{ include "cloud-agent.fullname" . }}-postgres-cluster.{{.Release.Namespace}}" - name: POLLUX_DB_PORT value: "5432" - name: POLLUX_DB_NAME @@ -86,29 +86,29 @@ spec: - name: POLLUX_DB_USER valueFrom: secretKeyRef: - name: pollux-admin.{{ .Values.database.postgres.managingTeam }}-{{ .Chart.Name }}-postgres-cluster.credentials.postgresql.acid.zalan.do + name: pollux-admin.{{ .Values.database.postgres.managingTeam }}-{{ include "cloud-agent.fullname" . }}-postgres-cluster.credentials.postgresql.acid.zalan.do key: username optional: false - name: POLLUX_DB_PASSWORD valueFrom: secretKeyRef: - name: pollux-admin.{{ .Values.database.postgres.managingTeam }}-{{ .Chart.Name }}-postgres-cluster.credentials.postgresql.acid.zalan.do + name: pollux-admin.{{ .Values.database.postgres.managingTeam }}-{{ include "cloud-agent.fullname" . }}-postgres-cluster.credentials.postgresql.acid.zalan.do key: password optional: false - name: POLLUX_DB_APP_USER valueFrom: secretKeyRef: - name: pollux-application-user.{{ .Values.database.postgres.managingTeam }}-{{ .Chart.Name }}-postgres-cluster.credentials.postgresql.acid.zalan.do + name: pollux-application-user.{{ .Values.database.postgres.managingTeam }}-{{ include "cloud-agent.fullname" . }}-postgres-cluster.credentials.postgresql.acid.zalan.do key: username optional: false - name: POLLUX_DB_APP_PASSWORD valueFrom: secretKeyRef: - name: pollux-application-user.{{ .Values.database.postgres.managingTeam }}-{{ .Chart.Name }}-postgres-cluster.credentials.postgresql.acid.zalan.do + name: pollux-application-user.{{ .Values.database.postgres.managingTeam }}-{{ include "cloud-agent.fullname" . }}-postgres-cluster.credentials.postgresql.acid.zalan.do key: password optional: false - name: CONNECT_DB_HOST - value: "{{ .Values.database.postgres.managingTeam }}-{{ .Chart.Name }}-postgres-cluster.{{.Release.Namespace}}" + value: "{{ .Values.database.postgres.managingTeam }}-{{ include "cloud-agent.fullname" . }}-postgres-cluster.{{.Release.Namespace}}" - name: CONNECT_DB_PORT value: "5432" - name: CONNECT_DB_NAME @@ -116,29 +116,29 @@ spec: - name: CONNECT_DB_USER valueFrom: secretKeyRef: - name: connect-admin.{{ .Values.database.postgres.managingTeam }}-{{ .Chart.Name }}-postgres-cluster.credentials.postgresql.acid.zalan.do + name: connect-admin.{{ .Values.database.postgres.managingTeam }}-{{ include "cloud-agent.fullname" . }}-postgres-cluster.credentials.postgresql.acid.zalan.do key: username optional: false - name: CONNECT_DB_PASSWORD valueFrom: secretKeyRef: - name: connect-admin.{{ .Values.database.postgres.managingTeam }}-{{ .Chart.Name }}-postgres-cluster.credentials.postgresql.acid.zalan.do + name: connect-admin.{{ .Values.database.postgres.managingTeam }}-{{ include "cloud-agent.fullname" . }}-postgres-cluster.credentials.postgresql.acid.zalan.do key: password optional: false - name: CONNECT_DB_APP_USER valueFrom: secretKeyRef: - name: connect-application-user.{{ .Values.database.postgres.managingTeam }}-{{ .Chart.Name }}-postgres-cluster.credentials.postgresql.acid.zalan.do + name: connect-application-user.{{ .Values.database.postgres.managingTeam }}-{{ include "cloud-agent.fullname" . }}-postgres-cluster.credentials.postgresql.acid.zalan.do key: username optional: false - name: CONNECT_DB_APP_PASSWORD valueFrom: secretKeyRef: - name: connect-application-user.{{ .Values.database.postgres.managingTeam }}-{{ .Chart.Name }}-postgres-cluster.credentials.postgresql.acid.zalan.do + name: connect-application-user.{{ .Values.database.postgres.managingTeam }}-{{ include "cloud-agent.fullname" . }}-postgres-cluster.credentials.postgresql.acid.zalan.do key: password optional: false - name: AGENT_DB_HOST - value: "{{ .Values.database.postgres.managingTeam }}-{{ .Chart.Name }}-postgres-cluster.{{.Release.Namespace}}" + value: "{{ .Values.database.postgres.managingTeam }}-{{ include "cloud-agent.fullname" . }}-postgres-cluster.{{.Release.Namespace}}" - name: AGENT_DB_PORT value: "5432" - name: AGENT_DB_NAME @@ -146,31 +146,31 @@ spec: - name: AGENT_DB_USER valueFrom: secretKeyRef: - name: agent-admin.{{ .Values.database.postgres.managingTeam }}-{{ .Chart.Name }}-postgres-cluster.credentials.postgresql.acid.zalan.do + name: agent-admin.{{ .Values.database.postgres.managingTeam }}-{{ include "cloud-agent.fullname" . }}-postgres-cluster.credentials.postgresql.acid.zalan.do key: username optional: false - name: AGENT_DB_PASSWORD valueFrom: secretKeyRef: - name: agent-admin.{{ .Values.database.postgres.managingTeam }}-{{ .Chart.Name }}-postgres-cluster.credentials.postgresql.acid.zalan.do + name: agent-admin.{{ .Values.database.postgres.managingTeam }}-{{ include "cloud-agent.fullname" . }}-postgres-cluster.credentials.postgresql.acid.zalan.do key: password optional: false - name: AGENT_DB_APP_USER valueFrom: secretKeyRef: - name: agent-application-user.{{ .Values.database.postgres.managingTeam }}-{{ .Chart.Name }}-postgres-cluster.credentials.postgresql.acid.zalan.do + name: agent-application-user.{{ .Values.database.postgres.managingTeam }}-{{ include "cloud-agent.fullname" . }}-postgres-cluster.credentials.postgresql.acid.zalan.do key: username optional: false - name: AGENT_DB_APP_PASSWORD valueFrom: secretKeyRef: - name: agent-application-user.{{ .Values.database.postgres.managingTeam }}-{{ .Chart.Name }}-postgres-cluster.credentials.postgresql.acid.zalan.do + name: agent-application-user.{{ .Values.database.postgres.managingTeam }}-{{ include "cloud-agent.fullname" . }}-postgres-cluster.credentials.postgresql.acid.zalan.do key: password optional: false - name: DIDCOMM_SERVICE_URL - value: "https://{{ index .Values.ingress.applicationUrls 0 }}/{{ .Chart.Name }}/didcomm" + value: "https://{{ index .Values.ingress.applicationUrls 0 }}/{{ include "cloud-agent.fullname" . }}/didcomm" - name: REST_SERVICE_URL - value: "https://{{ index .Values.ingress.applicationUrls 0 }}/{{ .Chart.Name }}" + value: "https://{{ index .Values.ingress.applicationUrls 0 }}/{{ include "cloud-agent.fullname" . }}" - name: PRISM_NODE_HOST value: {{ .Values.vdrManager.host | quote }} - name: PRISM_NODE_PORT diff --git a/infrastructure/charts/agent/templates/postgresql.yaml b/infrastructure/charts/agent/templates/postgresql.yaml index cce4c61ea3..153a62884e 100644 --- a/infrastructure/charts/agent/templates/postgresql.yaml +++ b/infrastructure/charts/agent/templates/postgresql.yaml @@ -1,7 +1,7 @@ apiVersion: "acid.zalan.do/v1" kind: postgresql metadata: - name: "{{ .Values.database.postgres.managingTeam }}-{{ .Chart.Name }}-postgres-cluster" + name: "{{ .Values.database.postgres.managingTeam }}-{{ include "cloud-agent.fullname" . }}-postgres-cluster" namespace: {{ .Release.Namespace }} labels: {{ template "labels.common" . }} diff --git a/infrastructure/charts/agent/templates/service.yaml b/infrastructure/charts/agent/templates/service.yaml index 105eddb6ce..20f30d1906 100644 --- a/infrastructure/charts/agent/templates/service.yaml +++ b/infrastructure/charts/agent/templates/service.yaml @@ -4,14 +4,14 @@ metadata: name: agent-server-tapir-service namespace: "{{ .Release.Namespace }}" labels: - app.kubernetes.io/name: {{ .Chart.Name }}-server - app.kubernetes.io/service: {{ .Chart.Name }}-server-main + app.kubernetes.io/name: {{ include "cloud-agent.fullname" . }}-server + app.kubernetes.io/service: {{ include "cloud-agent.fullname" . }}-server-main {{ template "labels.common" . }} spec: selector: - app.kubernetes.io/name: {{ .Chart.Name }}-server + app.kubernetes.io/name: {{ include "cloud-agent.fullname" . }}-server ports: - - name: {{ .Chart.Name }}-server-main + - name: {{ include "cloud-agent.fullname" . }}-server-main protocol: "TCP" port: 8085 targetPort: 8085 @@ -25,14 +25,14 @@ metadata: name: agent-server-didcomm-service namespace: "{{ .Release.Namespace }}" labels: - app.kubernetes.io/name: {{ .Chart.Name }}-server - app.kubernetes.io/service: {{ .Chart.Name }}-server-didcomm + app.kubernetes.io/name: {{ include "cloud-agent.fullname" . }}-server + app.kubernetes.io/service: {{ include "cloud-agent.fullname" . }}-server-didcomm {{ template "labels.common" . }} spec: selector: - app.kubernetes.io/name: {{ .Chart.Name }}-server + app.kubernetes.io/name: {{ include "cloud-agent.fullname" . }}-server ports: - - name: {{ .Chart.Name }}-server-didcomm + - name: {{ include "cloud-agent.fullname" . }}-server-didcomm protocol: "TCP" port: 8090 targetPort: 8090 @@ -49,7 +49,7 @@ metadata: annotations: external-dns.alpha.kubernetes.io/hostname: "{{ join ", " .Values.ingress.applicationUrls }}" labels: - app.kubernetes.io/name: {{ .Chart.Name }}-server + app.kubernetes.io/name: {{ include "cloud-agent.fullname" . }}-server app.kubernetes.io/service: agent-server-domain-name-fake {{ template "labels.common" . }} spec: diff --git a/infrastructure/charts/agent/values.yaml b/infrastructure/charts/agent/values.yaml index 84d552ce23..65ad01907f 100644 --- a/infrastructure/charts/agent/values.yaml +++ b/infrastructure/charts/agent/values.yaml @@ -1,3 +1,5 @@ +nameOverride: "" +fullnameOverride: "" ingress: enabled: true applicationUrls: