Skip to content

Commit

Permalink
feat: chart or custom name based fullname, product delivery support (#2)
Browse files Browse the repository at this point in the history
* feat: chart or name based fullname

* fix: restore of excluded labels

* fix: name in annotation

* fix: code review

---------

Co-authored-by: lukasz.laszkiewicz <[email protected]>
  • Loading branch information
llaszkie and llaszkie authored Aug 16, 2023
1 parent 1a6c402 commit 0fe03a9
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 85 deletions.
9 changes: 4 additions & 5 deletions Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ version: 2.0.0
description: Quarkus helm chart
appVersion: 2.0.0
keywords:
- app
- quarkus
- app
- quarkus
maintainers:
- name: Tkit Developer
email: [email protected]

- name: Tkit Developer
email: [email protected]
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,36 @@ Default helm template for OneCX Quarkus application.
## Add to Quarkus apps

Add latest `0.x.x` version.

```yaml
dependencies:
- name: helm-quarkus-app
alias: app
version: ^0
repository: oci://ghcr.io/onecx/charts
dependencies:
- name: helm-quarkus-app
alias: app
version: ^0
repository: oci://ghcr.io/onecx/charts
```
### Config maps
* inject_maps - inject custom map environment variables
- inject_maps - inject custom map environment variables
### Secrets
* env_secrets - map of env key and value which will be put in the secrets `{{ .Release.Name }}-env`

- env_secrets - map of env key and value which will be put in the secrets `{{ .Release.Name }}-{{ .Values.name | default .Chart.Name }}-env`

### Database

Default the internal database is `disabled`
The password for the database is store in the `{{ .Release.Name }}-db-config` secrets.
The password for the database is store in the `{{ .Release.Name }}-{{ .Values.name | default .Chart.Name }}-db-config` secrets.

The database is created by the `tkit-db-operator`

#### Default configuration

External database.
* global.host, global.port will be use to setup the JDBC connection.
* Username, password and database will be set to Release.Name

- global.host, global.port will be use to setup the JDBC connection.
- Username, password and database will be set to Release.Name

```
app:
Expand All @@ -43,4 +44,3 @@ app:
db:
enabled: true
```
20 changes: 12 additions & 8 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{{- define "quarkus.fullname" -}}
{{ .Release.Name }}-{{ .Values.name | default .Chart.Name }}
{{- end -}}

{{- define "quarkus.traefik.path" -}}
{{ if .Values.routing.path }} && PathPrefix(`{{ .Values.routing.path }}`){{ end }}
{{- end -}}
Expand All @@ -12,7 +16,7 @@
{{- else if .Values.service.name -}}
{{- .Values.service.name -}}
{{- else -}}
{{- .Release.Name }}
{{- template "quarkus.fullname" $ }}
{{- end -}}
{{- end -}}

Expand All @@ -22,7 +26,7 @@
{{- else if .Values.db.host -}}
{{- .Values.db.host -}}
{{- else -}}
{{- .Release.Name }}-postgresql
{{- template "quarkus.fullname" $ }}-postgresql
{{- end -}}
{{- end -}}

Expand All @@ -39,9 +43,9 @@
{{- .Values.db.database -}}
{{- else -}}
{{- if not .Values.db.internal -}}
{{ .Release.Namespace | replace "1000kit" "tkit" | replace "-" "_" }}_{{ .Release.Name | replace "-" "_" }}
{{ .Release.Namespace | replace "1000kit" "tkit" | replace "-" "_" }}_{{ template "quarkus.fullname" $ | replace "-" "_" }}
{{- else -}}
{{ .Release.Name | replace "-" "_" }}
{{ template "quarkus.fullname" $ | replace "-" "_" }}
{{- end -}}
{{- end -}}
{{- end -}}
Expand All @@ -50,7 +54,7 @@
{{- if .Values.db.password -}}
{{- .Values.db.password -}}
{{- else -}}
{{ .Release.Name | replace "-" "_" }}
{{ template "quarkus.fullname" $ | replace "-" "_" }}
{{- end -}}
{{- end -}}

Expand All @@ -59,9 +63,9 @@
{{- .Values.db.username -}}
{{- else -}}
{{- if not .Values.db.internal -}}
{{ .Release.Namespace | replace "1000kit" "tkit" | replace "-" "_" }}_{{ .Release.Name | replace "-" "_" }}
{{ .Release.Namespace | replace "1000kit" "tkit" | replace "-" "_" }}_{{ template "quarkus.fullname" $ | replace "-" "_" }}
{{- else -}}
{{ .Release.Name | replace "-" "_" }}
{{ template "quarkus.fullname" $ | replace "-" "_" }}
{{- end -}}
{{- end -}}
{{- end -}}
Expand Down Expand Up @@ -102,6 +106,6 @@
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 }}
app.kubernetes.io/name: {{ template "quarkus.fullname" $ }}
{{- end -}}

6 changes: 3 additions & 3 deletions templates/config-apm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ .Release.Name }}-apm-config"
name: "{{ template "quarkus.fullname" $ }}-apm-config"
annotations:
appId: {{ .Release.Name }}
appId: {{ template "quarkus.fullname" $ }}
filename: "permissions.csv"
labels:
app: {{ .Release.Name }}
app: {{ template "quarkus.fullname" $ }}
{{ include "quarkus.labels.common" $ | indent 4 }}
data:
permissions.csv: |-
Expand Down
6 changes: 3 additions & 3 deletions templates/config-data-mgmt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ .Release.Name }}-data-mgmt-config"
name: "{{ template "quarkus.fullname" $ }}-data-mgmt-config"
labels:
app: {{ .Release.Name }}
app: {{ template "quarkus.fullname" $ }}
{{ include "quarkus.labels.common" $ | indent 4 }}
data:
datasource-config: |-
{
"fileNamePrefix": "{{ .Values.operator.data.mgmt.prefix | default .Release.Name }}",
"fileNamePrefix": "{{ .Values.operator.data.mgmt.prefix | default (include "quarkus.fullname" $) }}",
"dbType": "{{ .Values.operator.data.mgmt.dbType }}",
"url": {{ include "quarkus.db.url" $ }},
"user": "{{ include "quarkus.db.username" $ }}",
Expand Down
4 changes: 2 additions & 2 deletions templates/config-db.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ .Release.Name }}-db-config
name: {{ template "quarkus.fullname" $ }}-db-config
annotations:
org.tkit.db.operator/database: {{ include "quarkus.db.host" $ }}
labels:
app: {{ .Release.Name }}
app: {{ template "quarkus.fullname" $ }}
{{ include "quarkus.labels.common" $ | indent 4 }}
type: Opaque
stringData:
Expand Down
4 changes: 2 additions & 2 deletions templates/config-keycloak.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ .Release.Name }}-kc-config"
name: "{{ template "quarkus.fullname" $ }}-kc-config"
annotations:
tkit.kc.cli/target-realm: {{ .Values.global.operator.keycloak.realm | default .Values.operator.keycloak.realm }}
labels:
app: {{ .Release.Name }}
app: {{ template "quarkus.fullname" $ }}
{{ include "quarkus.labels.common" $ | indent 4 }}
data:
{{ if .Values.operator.keycloak.client }}
Expand Down
28 changes: 14 additions & 14 deletions templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}
name: {{ template "quarkus.fullname" $ }}
labels:
app: {{ .Release.Name }}
app: {{ template "quarkus.fullname" $ }}
{{ include "quarkus.labels.common" $ | indent 4 }}
spec:
replicas: {{ .Values.replicas }}
selector:
matchLabels:
app: {{ .Release.Name }}
app: {{ template "quarkus.fullname" $ }}
template:
metadata:
labels:
app: {{ .Release.Name }}
app: {{ template "quarkus.fullname" $ }}
{{ include "quarkus.labels.common" $ | indent 8 }}
annotations:
{{- range $map_name := .Values.inject_maps }}
Expand All @@ -23,30 +23,30 @@ spec:
checksum/{{ $map_name | replace "-" "_" }}: {{ index $.Values.global ($map_name | replace "-" "_") }}
{{- end }}
{{- if .Values.operator.keycloak.enabled }}
checksum/{{ $.Release.Name }}-config-keycloak: {{ include (print $.Template.BasePath "/config-keycloak.yaml") . | sha256sum }}
checksum/{{ template "quarkus.fullname" $ }}-config-keycloak: {{ include (print $.Template.BasePath "/config-keycloak.yaml") . | sha256sum }}
{{- end }}
{{- if and (.Values.operator.apm.enabled) (.Values.operator.apm.permissions) }}
checksum/{{ $.Release.Name }}-config-apm: {{ include (print $.Template.BasePath "/config-apm.yaml") . | sha256sum }}
checksum/{{ template "quarkus.fullname" $ }}-config-apm: {{ include (print $.Template.BasePath "/config-apm.yaml") . | sha256sum }}
{{- end }}
{{- if and (.Values.db.enabled) (.Values.operator.data.mgmt.enabled) }}
checksum/{{ $.Release.Name }}-config-data-mgmt: {{ include (print $.Template.BasePath "/config-data-mgmt.yaml") . | sha256sum }}
checksum/{{ template "quarkus.fullname" $ }}-config-data-mgmt: {{ include (print $.Template.BasePath "/config-data-mgmt.yaml") . | sha256sum }}
{{- end }}
{{- if .Values.db.enabled }}
checksum/{{ $.Release.Name }}-config-db: {{ include (print $.Template.BasePath "/config-db.yaml") . | sha256sum }}
checksum/{{ template "quarkus.fullname" $ }}-config-db: {{ include (print $.Template.BasePath "/config-db.yaml") . | sha256sum }}
{{- end }}
{{- if .Values.env_secrets }}
checksum/{{ $.Release.Name }}-env: {{ include (print $.Template.BasePath "/secret-env.yaml") . | sha256sum }}
checksum/{{ template "quarkus.fullname" $ }}-env: {{ include (print $.Template.BasePath "/secret-env.yaml") . | sha256sum }}
{{- end }}
spec:
{{- if .Values.serviceAccountSuffix }}
serviceAccountName: {{ .Release.Name }}-{{ .Values.serviceAccountSuffix }}
serviceAccountName: {{ template "quarkus.fullname" $ }}-{{ .Values.serviceAccountSuffix }}
{{- end }}
{{- if .Values.imagePullSecrets }}
imagePullSecrets:
- name: {{ .Values.imagePullSecrets }}
{{- end }}
containers:
- name: {{ .Release.Name }}
- name: {{ template "quarkus.fullname" $ }}
image: {{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }}
imagePullPolicy: Always
ports:
Expand Down Expand Up @@ -80,7 +80,7 @@ spec:
- name: {{ .Values.template.db_property_password }}
valueFrom:
secretKeyRef:
name: {{ .Release.Name }}-db-config
name: {{ template "quarkus.fullname" $ }}-db-config
key: password
{{- end }}
{{- $envVals := .Values.global.env -}}
Expand All @@ -100,7 +100,7 @@ spec:
valueFrom:
secretKeyRef:
key: {{ $secret_key }}
name: {{ $.Release.Name }}-env
name: {{ template "quarkus.fullname" $ }}-env
{{- end }}
{{- end }}

Expand Down Expand Up @@ -138,7 +138,7 @@ spec:
- name: PGPASSWORD
valueFrom:
secretKeyRef:
name: {{ .Release.Name }}-db-config
name: {{ template "quarkus.fullname" $ }}-db-config
key: password
- name: DISABLE_WELCOME_MESSAGE
value: "true"
Expand Down
23 changes: 16 additions & 7 deletions templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ .Release.Name }}-ingress
name: {{ template "quarkus.fullname" $ }}-ingress
labels:
app: {{ .Release.Name }}
{{ include "quarkus.labels.common" $ | indent 4 }}
annotations:
app: {{ template "quarkus.fullname" $ }}
{{ include "quarkus.labels.common" $ | indent 4 }}
annotations:
{{- if (.Values.prometheus | default false) }}
prometheus.io/ingress: '{{ .Values.routing.prometheus.ingress | default "true" }}'
prometheus.io/ingress_path: '{{ .Values.routing.prometheus.ingress_path | default $.Values.livenessProbe.url }}'
{{- end }}
{{- end }}
{{- if .Values.routing.stripprefix }}
traefik.ingress.kubernetes.io/router.middlewares: '{{ .Release.Namespace }}-{{ template "quarkus.fullname" $ }}-middleware@kubernetescrd'
{{- end }}
{{ toYaml .Values.routing.ingress.annotations | indent 4 }}
spec:
rules:
- host: {{ .Release.Name }}-{{ .Release.Namespace }}.{{ .Values.global.default_url | default .Values.routing.default_url }}
http:
- http:
paths:
- path: {{ .Values.routing.path | default "/" }}
pathType: Prefix
Expand All @@ -25,5 +27,12 @@ spec:
name: {{ include "quarkus.routing.service" $ }}
port:
number: {{ .Values.routing.service.port | default .Values.service.port }}
{{ if .Values.routing.ingress.host.override }}
host: {{ .Values.routing.ingress.host.override }}.{{ .Values.global.default_url | default .Values.routing.default_url }}
{{ else if .Values.routing.ingress.host.name }}
host: {{ .Values.routing.ingress.host.name }}-{{ .Release.Namespace }}.{{ .Values.global.default_url | default .Values.routing.default_url }}
{{ else }}
host: {{ template "quarkus.fullname" $ }}-{{ .Release.Namespace }}.{{ .Values.global.default_url | default .Values.routing.default_url }}
{{- end }}
{{ end }}
{{ end }}
2 changes: 1 addition & 1 deletion templates/middleware-strip.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: {{ .Release.Name }}-{{ .Release.Namespace }}-middleware
name: {{ template "quarkus.fullname" $ }}-middleware
spec:
stripPrefix:
prefixes:
Expand Down
4 changes: 2 additions & 2 deletions templates/secret-env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ .Release.Name }}-env
name: {{ template "quarkus.fullname" $ }}-env
labels:
app: {{ .Release.Name }}
app: {{ template "quarkus.fullname" $ }}
{{ include "quarkus.labels.common" $ | indent 4 }}
stringData:
{{- range $key,$val := .Values.env_secrets }}
Expand Down
15 changes: 9 additions & 6 deletions templates/service.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
apiVersion: v1
kind: Service
apiVersion: v1
metadata:
name: {{ .Release.Name }}
name: {{ template "quarkus.fullname" $ }}
labels:
app: {{ .Release.Name }}
{{ include "quarkus.labels.common" $ | indent 4 }}
app: {{ template "quarkus.fullname" $ }}
{{ include "quarkus.labels.common" $ | indent 4 }}
annotations:
description: {{ template "quarkus.fullname" $ }}
spec:
selector:
app: {{ .Release.Name }}
app: {{ template "quarkus.fullname" $ }}
ports:
- protocol: TCP
- name: http
protocol: TCP
port: {{ .Values.service.port }}
targetPort: {{ .Values.pod.port }}
Loading

0 comments on commit 0fe03a9

Please sign in to comment.