Skip to content

Commit

Permalink
feat: refactoring for product deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras committed Jan 23, 2024
1 parent 59a9f77 commit 4f79169
Show file tree
Hide file tree
Showing 13 changed files with 294 additions and 167 deletions.
2 changes: 1 addition & 1 deletion Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v2
name: angular
name: helm-angular-app
version: 0.0.0
description: Angular helm chart
appVersion: 0.0.0
Expand Down
53 changes: 29 additions & 24 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
{{- define "angular.traefik.path" -}}
{{ if .Values.routing.path }} && PathPrefix(`{{ .Values.routing.path }}`){{ end }}
{{- define "app.fullname" -}}
{{ .Release.Name }}-{{ .Values.name | default .Chart.Name }}
{{- end -}}

{{- define "angular.routing.type" -}}
{{ if .Values.global.routing.type }}{{ .Values.global.routing.type }}{{ else }}{{ .Values.routing.type }}{{ end }}
{{- define "app.version" -}}
{{ .Values.image.tag }}
{{- end -}}

{{- define "angular.labels.common" -}}
version: {{ .Values.version | default .Values.image.tag | quote }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/name: {{ .Release.Name | quote }}
{{- define "app.id" -}}
{{ if .Values.routing.backend }}{{ .Values.appId }}{{ else }}{{ template "app.fullname" $ }}{{ end }}
{{- end -}}


{{- define "app.traefik.path" -}}
{{ if .Values.routing.path }} && PathPrefix(`{{ .Values.routing.path }}`){{ end }}
{{- end -}}

{{- define "app.routing.type" -}}
{{ if .Values.global.routing.type }}{{ .Values.global.routing.type }}{{ else }}{{ .Values.routing.type }}{{ end }}
{{- 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 "common.names.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 "-" -}}
{{- define "app.ingress.host" -}}
{{ if .Values.routing.backend }}
{{ template "app.fullname" $ }}-{{ .Release.Namespace }}.{{ .Values.global.default_url | default .Values.routing.default_url }}
{{ else if .Values.routing.hostName }}
{{ .Values.routing.hostName }}
{{ else if .Values.global.hostName }}
{{ .Values.global.hostName }}
{{ else }}
{{ template "app.fullname" $ }}-{{ .Release.Namespace }}.{{ .Values.global.default_url | default .Values.routing.default_url }}
{{ end }}
{{- end -}}

{{- define "app.labels.common" -}}
version: {{ .Values.version | default .Values.image.tag | quote }}
helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
app.kubernetes.io/name: {{ template "app.fullname" $ }}
{{- end -}}
{{- end -}}
17 changes: 0 additions & 17 deletions templates/config-apm.yaml

This file was deleted.

11 changes: 11 additions & 0 deletions templates/config-env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ template "app.fullname" $ }}-env"
labels:
app: {{ template "app.fullname" $ }}
{{ include "app.labels.common" $ | indent 4 }}
data:
APP_VERSION: {{ .Values.image.tag }}
APP_ID: {{ template "app.id" $ }}
{{ if and .Values.routing.enabled .Values.routing.path }}APP_BASE_HREF: {{ .Values.routing.path }}{{ end }}
6 changes: 3 additions & 3 deletions templates/config-keycloak.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ include "common.names.fullname" . }}-kc-config"
name: "{{ template "app.fullname" $ }}-kc-config"
annotations:
tkit.kc.cli/target-realm: {{ .Values.global.operator.keycloak.realm | default .Values.operator.keycloak.realm }}
labels:
app: {{ include "common.names.fullname" . }}
{{ include "angular.labels.common" $ | indent 4 }}
app: {{ template "app.fullname" $ }}
{{ include "app.labels.common" $ | indent 4 }}
data:
{{ if .Values.operator.keycloak.client }}
client: |-
Expand Down
108 changes: 67 additions & 41 deletions templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "common.names.fullname" . }}
name: {{ template "app.fullname" $ }}
labels:
app: {{ include "common.names.fullname" . }}
{{ include "angular.labels.common" $ | indent 4 }}
app: {{ template "app.fullname" $ }}
{{ include "app.labels.common" $ | indent 4 }}
spec:
replicas: {{ .Values.replicas }}
selector:
matchLabels:
app: {{ include "common.names.fullname" . }}
app: {{ template "app.fullname" $ }}
template:
metadata:
labels:
app: {{ include "common.names.fullname" . }}
{{ include "angular.labels.common" $ | indent 8 }}
app: {{ template "app.fullname" $ }}
{{ include "app.labels.common" $ | indent 8 }}
annotations:
{{- range $map_name := .Values.inject_maps }}
checksum/{{ $map_name | replace "-" "_" }}: {{ index $.Values.global ($map_name | replace "-" "_") }}
Expand All @@ -23,22 +23,28 @@ spec:
checksum/{{ $map_name | replace "-" "_" }}: {{ index $.Values.global ($map_name | replace "-" "_") }}
{{- end }}
spec:
{{- if .Values.serviceAccountSuffix }}
serviceAccountName: {{ include "common.names.fullname" . }}-{{ .Values.serviceAccountSuffix }}
{{- end }}
{{- if .Values.serviceAccount.enabled }}
{{- if .Values.serviceAccount.name }}
serviceAccountName: {{ .Values.serviceAccount.name }}
{{- else if .Values.serviceAccountSuffix }}
serviceAccountName: {{ template "quarkus.fullname" $ }}-{{ .Values.serviceAccount.suffix }}
{{ else }}
serviceAccountName: {{ template "quarkus.fullname" $ }}
{{- end }}
{{- end }}
{{- if .Values.imagePullSecrets }}
imagePullSecrets:
- name: {{ .Values.imagePullSecrets }}
{{- end }}
containers:
- name: nginx
- name: {{ template "app.fullname" $ }}
image: {{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: Always
imagePullPolicy: {{ .Values.image.pull }}
ports:
- containerPort: {{ .Values.pod.port }}
readinessProbe:
httpGet:
path: {{ .Values.health.url }}
path: {{ .Values.livenessProbe.url }}
port: {{ .Values.pod.port }}
scheme: HTTP
initialDelaySeconds: 3
Expand All @@ -48,42 +54,62 @@ spec:
failureThreshold: 5
livenessProbe:
httpGet:
path: {{ .Values.health.url }}
path: {{ .Values.readinessProbe.url }}
port: {{ .Values.pod.port }}
scheme: HTTP
initialDelaySeconds: 3
periodSeconds: 30
timeoutSeconds: 3
successThreshold: 1
failureThreshold: 5
{{- $envVals := .Values.global.env -}}
{{ if .Values.routing.enabled }}
{{ if .Values.routing.path }}
{{- $appBaseHref := dict "APP_BASE_HREF" .Values.routing.path -}}
{{- $envVals = merge $appBaseHref $envVals -}}
{{ end }}
{{ end }}
{{- if (.Values.env) }}
{{- $envVals = merge .Values.env $envVals -}}
{{- end }}

failureThreshold: 5
startupProbe:
failureThreshold: 3
httpGet:
path: /q/health/started
port: {{ .Values.pod.port }}
scheme: HTTP
initialDelaySeconds: 3
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 10
env:
- name: APP_VERSION
value: {{ .Values.version | default .Values.image.tag }}
{{- if $envVals }}
{{- range $key,$val := $envVals }}
- name: {{ $key }}
value: {{ tpl ($val|toString) $ | quote }}
{{- end }}
{{- end }}
{{- $im := .Values.global.inject_maps -}}
{{- if (.Values.inject_maps) }}
{{- $im = concat .Values.inject_maps .Values.global.inject_maps | uniq -}}
{{- end }}
{{- if $im }}
{{- $envVals := .Values.global.env -}}
{{- if (.Values.env) }}
{{- $envVals = merge .Values.env $envVals -}}
{{- end }}
{{- if $envVals }}
{{- range $key,$val := $envVals }}
- name: {{ $key }}
value: {{ tpl ($val|toString) $ | quote }}
{{- end }}
{{- end }}

{{- if .Values.env_secrets }}
{{- range $secret_key,$secret_value := .Values.env_secrets }}
- name: {{ $secret_key }}
valueFrom:
secretKeyRef:
key: {{ $secret_key }}
name: {{ template "quarkus.fullname" $ }}-env
{{- end }}
{{- end }}

{{- if .Values.envCustom }}
{{- .Values.envCustom | toYaml | trim | nindent 10 }}
{{- end }}

{{- if or (.Values.global.inject_maps) (.Values.inject_maps) }}
envFrom:
{{- range $map_name := $im }}
- configMapRef:
name: {{ template "app.fullname" $ }}-env
{{- $im := .Values.global.inject_maps -}}
{{- if (.Values.inject_maps) }}
{{- $im = concat .Values.inject_maps .Values.global.inject_maps | uniq -}}
{{- end }}
{{- if $im }}
{{- range $map_name := $im }}
- configMapRef:
name: {{ $map_name }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
30 changes: 30 additions & 0 deletions templates/ingress-traefik.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{- if .Values.routing.enabled }}
{{- if eq (include "app.routing.type" $) "traefik" }}
kind: IngressRoute
apiVersion: traefik.io/v1alpha1
metadata:
name: {{ template "app.fullname" $ }}
labels:
app: {{ template "app.fullname" $ }}
{{ include "app.labels.common" $ | indent 4 }}
spec:
entryPoints:
{{- range $ep := .Values.routing.entryPoints }}
- {{ $ep }}
{{ end }}
{{- range $ep := .Values.global.routing.entryPoints }}
- {{ $ep }}
{{ end }}
routes:
- kind: Rule
match: Host(`{{ template "app.ingress.host" $ }}`){{ include "app.traefik.path" $ }}
{{ if .Values.routing.traefik.middleware.enabled }}
middlewares:
- name: {{ .Values.routing.traefik.middleware.name }}
{{ end }}
services:
- kind: Service
name: {{ template "app.fullname" $ }}
port: {{ .Values.service.port }}
{{ end }}
{{ end }}
14 changes: 0 additions & 14 deletions templates/middleware-strip.yaml

This file was deleted.

30 changes: 30 additions & 0 deletions templates/operator-microfrontend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{ if .Values.operator.microfrontend.enabled }}
apiVersion: onecx.github.io/v1
kind: Microfrontend
metadata:
name: {{ template "app.fullname" $ }}
labels:
app: {{ template "app.fullname" $ }}
{{ include "app.labels.common" $ | indent 4 }}
spec:
appId: {{ .Values.operator.microfrontend.spec.appId | default (include "app.id" .) }}
appName: {{ .Values.operator.microfrontend.spec.appName | default (include "app.fullname" .) }}
appVersion: {{ template "app.version" $ }}
classifications: {{ .Values.operator.microfrontend.spec.classifications }}
contact: {{ .Values.operator.microfrontend.spec.contact }}
description: {{ .Values.operator.microfrontend.spec.description }}
exposedModule: {{ .Values.operator.microfrontend.spec.exposedModule }}
iconName: {{ .Values.operator.microfrontend.spec.iconName }}
note: {{ .Values.operator.microfrontend.spec.note }}
productName: {{ .Values.operator.microfrontend.spec.productName | default .Release.Name }}
remoteBaseUrl: {{ .Values.operator.microfrontend.spec.remoteBaseUrl | default .Values.routing.path }}
remoteEntry: {{ .Values.operator.microfrontend.spec.remoteBaseUrl | default .Values.routing.path }}{{ .Values.operator.microfrontend.entrySuffix }}
technology: {{ .Values.operator.microfrontend.spec.technology }}
{{ if (.Values.operator.microfrontend.spec.endpoints) }}
endpoints:
{{- range $item := .Values.operator.microfrontend.spec.endpoints }}
- name: {{ $item.name }}
path: {{ $item.path }}
{{- end }}
{{- end }}
{{- end }}
12 changes: 12 additions & 0 deletions templates/operator-permission.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{ if .Values.operator.permission.enabled }}
apiVersion: onecx.github.io/v1
kind: Permission
metadata:
name: {{ template "app.fullname" $ }}
labels:
app: {{ template "app.fullname" $ }}
{{ include "app.labels.common" $ | indent 4 }}
spec:
appId: {{ .Values.operator.permission.spec.appId | default (include "app.fullname" .) }}
permissions: {{ if .Values.operator.permission.spec.permissions }}{{ .Values.operator.permission.spec.permissions | toYaml | nindent 4 }}{{- end }}
{{- end }}
16 changes: 9 additions & 7 deletions templates/service.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
apiVersion: v1
kind: Service
apiVersion: v1
metadata:
name: {{ include "common.names.fullname" . }}
name: {{ template "app.fullname" $ }}
labels:
app: {{ include "common.names.fullname" . }}
{{ include "angular.labels.common" $ | indent 4 }}
app: {{ template "app.fullname" $ }}
{{ include "app.labels.common" $ | indent 4 }}
annotations:
description: {{ template "app.fullname" $ }}
spec:
selector:
app: {{ include "common.names.fullname" . }}
{{ include "angular.labels.common" $ | indent 4 }}
app: {{ template "app.fullname" $ }}
ports:
- protocol: TCP
- name: http
protocol: TCP
port: {{ .Values.service.port }}
targetPort: {{ .Values.pod.port }}
Loading

0 comments on commit 4f79169

Please sign in to comment.