From f3c5f18c2c06317c80bb0d349eb0889b3029df3b Mon Sep 17 00:00:00 2001 From: Mateusz Urbanek Date: Sat, 27 Jul 2024 22:29:16 +0200 Subject: [PATCH] feat(lubelogger): add secrets name overrides (#8) ## Description This pull request allows overriding secrets name when configuring the application. --------- Signed-off-by: Mateusz Urbanek --- anza-labs/lubelog/Chart.yaml | 2 +- anza-labs/lubelog/README.md | 18 +++++++++++---- anza-labs/lubelog/templates/_helpers.tpl | 21 ++++++++++++++++++ anza-labs/lubelog/templates/deployment.yaml | 14 ++++++------ .../templates/postgres-connection.yaml | 2 +- anza-labs/lubelog/templates/secret.yaml | 2 +- anza-labs/lubelog/values.yaml | 22 +++++++++++++++++-- 7 files changed, 65 insertions(+), 16 deletions(-) diff --git a/anza-labs/lubelog/Chart.yaml b/anza-labs/lubelog/Chart.yaml index e760fe5..8f67ec9 100644 --- a/anza-labs/lubelog/Chart.yaml +++ b/anza-labs/lubelog/Chart.yaml @@ -2,4 +2,4 @@ apiVersion: v2 name: lubelog description: LubeLogger is a web-based vehicle maintenance and fuel mileage tracker type: application -version: 0.1.1 +version: 0.1.2 diff --git a/anza-labs/lubelog/README.md b/anza-labs/lubelog/README.md index b4f8528..013bafd 100644 --- a/anza-labs/lubelog/README.md +++ b/anza-labs/lubelog/README.md @@ -1,6 +1,6 @@ # lubelog -![Version: 0.1.1](https://img.shields.io/badge/Version-0.1.1-informational?style=flat) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat) +![Version: 0.1.2](https://img.shields.io/badge/Version-0.1.2-informational?style=flat) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat) LubeLogger is a web-based vehicle maintenance and fuel mileage tracker @@ -13,8 +13,8 @@ LubeLogger is a web-based vehicle maintenance and fuel mileage tracker | autoscaling.maxReplicas | int | `3` | Maximum number of replicas for autoscaling. | | autoscaling.minReplicas | int | `1` | Minimum number of replicas for autoscaling. | | autoscaling.targetCPUUtilizationPercentage | int | `80` | Target CPU utilization percentage for autoscaling. | -| config.LANG | string | `"en_US.UTF-8"` | Same as above. Note that some languages don't have UTF-8 encodings. | -| config.LC_ALL | string | `"en_US.UTF-8"` | Locale and Language Settings, this will affect how numbers, currencies, and dates are formatted. | +| config.LANG | string | `"en_US.UTF-8"` | Locale and Language Settings, this will affect how numbers, currencies, and dates are formatted. | +| config.LC_ALL | string | `"en_US.UTF-8"` | Same as above. Note that some languages don't have UTF-8 encodings. | | config.LOGLEVEL | string | `"Information"` | Specifies the level of logs. Valid levels are `Trace`, `Debug`, `Information`, `Warning`, `Error`, `Critical` and `None`. Learn more at: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/ | | fullnameOverride | string | `""` | Override for the full name. | | image.pullPolicy | string | `"IfNotPresent"` | Image pull policy. | @@ -32,13 +32,23 @@ LubeLogger is a web-based vehicle maintenance and fuel mileage tracker | podAnnotations | object | `{}` | Annotations to be added to the pods. | | podLabels | object | `{}` | Labels to be added to the pods. | | podSecurityContext | object | `{}` | | -| postgres | object | `{"connect":false,"database":"postgres","host":"postgres","password":"postgres","port":5432,"user":"postgres"}` | PostgreSQL connection details. | +| postgres | object | `{"connect":false,"create":false,"database":"postgres","host":"postgres","keyRef":"POSTGRES_CONNECTION","name":"","password":"postgres","port":5432,"user":"postgres"}` | PostgreSQL connection details. | +| postgres.connect | bool | `false` | Defines if the LubeLogger should connect to the Postgres backend. It has no effect when `postgres.create=true`. | +| postgres.create | bool | `false` | Defines if the secret with Postgres connection details should be created. | +| postgres.database | string | `"postgres"` | Database name. | +| postgres.host | string | `"postgres"` | Host of the Postgres database. | +| postgres.keyRef | string | `"POSTGRES_CONNECTION"` | Defines the key under which postgres connection string can be found. It uses Npgsql connection format. | +| postgres.name | string | `""` | Specifies name of a secret used to configure the LubeLogger's Postgres backend. If not filled, uses full name. | +| postgres.password | string | `"postgres"` | Password for the user used to connect to the Postgres database. | +| postgres.port | int | `5432` | Port of the Postgres database. | +| postgres.user | string | `"postgres"` | User used to connect to the Postgres database. | | readinessProbe.httpGet | object | `{"path":"/","port":"http"}` | Readiness probe configuration. | | replicaCount | int | `1` | Number of replicas for the deployment. | | resources | object | `{}` | | | secret.create | bool | `true` | Specifies whether a secret should be created. | | secret.emailFrom | string | `""` | Email from address for the secret. | | secret.emailServer | string | `""` | Email server for the secret. | +| secret.name | string | `""` | Specifies name of a secret used to configure the LubeLogger's mail connection. If not filled, uses full name. | | secret.password | string | `""` | Password for the email server. | | secret.port | int | `587` | Port for the email server. | | secret.username | string | `""` | Username for the email server. | diff --git a/anza-labs/lubelog/templates/_helpers.tpl b/anza-labs/lubelog/templates/_helpers.tpl index 51870ea..89d4f40 100644 --- a/anza-labs/lubelog/templates/_helpers.tpl +++ b/anza-labs/lubelog/templates/_helpers.tpl @@ -57,3 +57,24 @@ Create the name of the service account to use {{- default "default" .Values.serviceAccount.name }} {{- end }} {{- end }} + +{{/* +Create secret name used for configuring mail. +*/}} +{{- define "lubelog.mailSecret" -}} + {{- default (include "lubelog.fullname" .) .Values.secret.name }} +{{- end }} + +{{/* +Create secret name used for configuring PostgreSQL connection. +*/}} +{{- define "lubelog.postgresSecret" -}} + {{- default ( printf "%s-postgres-connection" (include "lubelog.fullname" .)) .Values.postgres.name }} +{{- end }} + +{{/* +Create key under which PostgreSQL connection string can be found. +*/}} +{{- define "lubelog.postgresSecretKey" -}} + {{- default "POSTGRES_CONNECTION" .Values.postgres.keyRef }} +{{- end }} diff --git a/anza-labs/lubelog/templates/deployment.yaml b/anza-labs/lubelog/templates/deployment.yaml index cb6bffe..cac997c 100644 --- a/anza-labs/lubelog/templates/deployment.yaml +++ b/anza-labs/lubelog/templates/deployment.yaml @@ -59,33 +59,33 @@ spec: - name: MailConfig__EmailServer valueFrom: secretKeyRef: - name: {{ include "lubelog.fullname" . }} + name: {{ include "lubelog.mailSecret" . }} key: MailConfig__EmailServer - name: MailConfig__EmailFrom valueFrom: secretKeyRef: - name: {{ include "lubelog.fullname" . }} + name: {{ include "lubelog.mailSecret" . }} key: MailConfig__EmailFrom - name: MailConfig__Port valueFrom: secretKeyRef: - name: {{ include "lubelog.fullname" . }} + name: {{ include "lubelog.mailSecret" . }} key: MailConfig__Port - name: MailConfig__Username valueFrom: secretKeyRef: - name: {{ include "lubelog.fullname" . }} + name: {{ include "lubelog.mailSecret" . }} key: MailConfig__Username - name: MailConfig__Password valueFrom: secretKeyRef: - name: {{ include "lubelog.fullname" . }} + name: {{ include "lubelog.mailSecret" . }} key: MailConfig__Password - {{- if .Values.postgres.connect }} + {{- if or .Values.postgres.connect .Values.postgres.create }} - name: POSTGRES_CONNECTION valueFrom: secretKeyRef: - name: {{ include "lubelog.fullname" . }}-postgres-connection + name: {{ include "lubelog.postgresSecret" . }} key: POSTGRES_CONNECTION {{- end }} {{- with .Values.nodeSelector }} diff --git a/anza-labs/lubelog/templates/postgres-connection.yaml b/anza-labs/lubelog/templates/postgres-connection.yaml index df4e704..2afc943 100644 --- a/anza-labs/lubelog/templates/postgres-connection.yaml +++ b/anza-labs/lubelog/templates/postgres-connection.yaml @@ -16,5 +16,5 @@ metadata: {{- end }} type: Opaque stringData: - POSTGRES_CONNECTION: "Host={{ $pgHost }}:{{ $pgPort }};Username={{ $pgUser }};Password={{ $pgPass }};Database={{ $pgDatabase }};" + {{- include "lubelog.postgresSecretKey" . | nindent 2}}: "Host={{ $pgHost }}:{{ $pgPort }};Username={{ $pgUser }};Password={{ $pgPass }};Database={{ $pgDatabase }};" {{- end }} \ No newline at end of file diff --git a/anza-labs/lubelog/templates/secret.yaml b/anza-labs/lubelog/templates/secret.yaml index 208bc98..e34a21e 100644 --- a/anza-labs/lubelog/templates/secret.yaml +++ b/anza-labs/lubelog/templates/secret.yaml @@ -7,7 +7,7 @@ apiVersion: v1 kind: Secret metadata: - name: {{ include "lubelog.fullname" . }} + name: {{ include "lubelog.mailSecret" . }} namespace: {{ .Release.Namespace }} labels: {{- include "lubelog.labels" . | nindent 4 }} diff --git a/anza-labs/lubelog/values.yaml b/anza-labs/lubelog/values.yaml index f71eb2c..59423ff 100644 --- a/anza-labs/lubelog/values.yaml +++ b/anza-labs/lubelog/values.yaml @@ -12,10 +12,10 @@ image: pullPolicy: IfNotPresent config: - # -- Same as above. Note that some languages don't have UTF-8 encodings. - LANG: en_US.UTF-8 # -- Locale and Language Settings, this will affect how numbers, currencies, and dates are # formatted. + LANG: en_US.UTF-8 + # -- Same as above. Note that some languages don't have UTF-8 encodings. LC_ALL: en_US.UTF-8 # -- Specifies the level of logs. Valid levels are `Trace`, `Debug`, `Information`, # `Warning`, `Error`, `Critical` and `None`. Learn more at: @@ -43,6 +43,9 @@ serviceAccount: secret: # -- Specifies whether a secret should be created. create: true + # -- Specifies name of a secret used to configure the LubeLogger's mail connection. + # If not filled, uses full name. + name: "" # -- Email server for the secret. emailServer: "" # -- Email from address for the secret. @@ -56,11 +59,26 @@ secret: # -- PostgreSQL connection details. postgres: + # -- Defines if the secret with Postgres connection details should be created. + create: false + # -- Defines if the LubeLogger should connect to the Postgres backend. + # It has no effect when `postgres.create=true`. connect: false + # -- Specifies name of a secret used to configure the LubeLogger's Postgres backend. + # If not filled, uses full name. + name: "" + # -- Defines the key under which postgres connection string can be found. + # It uses Npgsql connection format. + keyRef: "POSTGRES_CONNECTION" + # -- Host of the Postgres database. host: "postgres" + # -- Port of the Postgres database. port: 5432 + # -- User used to connect to the Postgres database. user: "postgres" + # -- Password for the user used to connect to the Postgres database. password: "postgres" + # -- Database name. database: "postgres" # -- Annotations to be added to the pods.