From 49187b91278bc1c49d1fbbb36b9c1e7e8404b777 Mon Sep 17 00:00:00 2001 From: angryPopcorn Date: Mon, 4 Jul 2022 19:54:35 +0800 Subject: [PATCH] Use external db replace init db (#13) * feat: use external db * fix: fix connectionPool * fix: fix port int error * fix: remove chart.lock --- helm-chart/Chart.lock | 6 --- helm-chart/Chart.yaml | 7 +--- helm-chart/README.md | 2 +- helm-chart/templates/deployment.yaml | 59 ++++++---------------------- helm-chart/templates/secret.yaml | 10 ----- helm-chart/values.yaml | 54 ++++--------------------- 6 files changed, 23 insertions(+), 115 deletions(-) delete mode 100644 helm-chart/Chart.lock delete mode 100644 helm-chart/templates/secret.yaml diff --git a/helm-chart/Chart.lock b/helm-chart/Chart.lock deleted file mode 100644 index 6deb75c..0000000 --- a/helm-chart/Chart.lock +++ /dev/null @@ -1,6 +0,0 @@ -dependencies: -- name: postgresql - repository: https://charts.bitnami.com/bitnami - version: 9.2.1 -digest: sha256:9b7cb89bbb9abf56b7006cba5f9a189e90b4d3dfbfa1e14e02d420ada5f04b0b -generated: "2022-05-14T06:52:40.853881713+03:00" diff --git a/helm-chart/Chart.yaml b/helm-chart/Chart.yaml index c5583dc..2fd8d45 100644 --- a/helm-chart/Chart.yaml +++ b/helm-chart/Chart.yaml @@ -1,11 +1,6 @@ apiVersion: v2 name: supertokens description: SuperTokens Core Deployment -dependencies: - - name: postgresql - version: 9.2.1 - repository: https://charts.bitnami.com/bitnami - condition: database.postgresql.enabled # A chart can be either an 'application' or a 'library' chart. # # Application charts are a collection of templates that can be packaged into versioned archives @@ -25,4 +20,4 @@ version: 0.1.1 # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "3.13.0" +appVersion: "3.14.0" diff --git a/helm-chart/README.md b/helm-chart/README.md index ea5128b..790c802 100644 --- a/helm-chart/README.md +++ b/helm-chart/README.md @@ -6,7 +6,7 @@ SuperTokens Core Deployment ## Deployment -To install with in cluster postgres deployment, the chart currently does not support external postgres servers. +The chart currently use external postgres servers. ```bash diff --git a/helm-chart/templates/deployment.yaml b/helm-chart/templates/deployment.yaml index b6a29f3..9560f07 100644 --- a/helm-chart/templates/deployment.yaml +++ b/helm-chart/templates/deployment.yaml @@ -28,36 +28,7 @@ spec: {{- if .Values.podSecurityContext }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} - {{- end }} - initContainers: - - name: postgres-init - image: "{{ .Values.database.postgresql.initContainer.image.repository }}:{{ .Values.database.postgresql.initContainer.image.tag | default "latest" }}" - command: - - 'sh' - - '-c' - - "until psql postgresql://postgres:${POSTGRES_PASSWORD}@{{ .Release.Namespace }}-{{ .Values.postgresql.host }}.{{ .Release.Namespace }}.svc.cluster.local:5432; - do echo trying to connect to postgres - waiting 5 sec for it to load up; sleep 5;done;echo succes connecting to postgres; - psql postgresql://postgres:${POSTGRES_PASSWORD}@{{ .Release.Namespace }}-{{ .Values.postgresql.host }}.{{ .Release.Namespace }}.svc.cluster.local:5432 -c \"CREATE ROLE ${SUPERTOKENS_USER} WITH LOGIN ENCRYPTED PASSWORD '${SUPERTOKENS_PASSWORD}'\"; - psql postgresql://postgres:${POSTGRES_PASSWORD}@{{ .Release.Namespace }}-{{ .Values.postgresql.host }}.{{ .Release.Namespace }}.svc.cluster.local:5432 -c \"CREATE DATABASE {{ .Values.database.dbName }} WITH OWNER = ${SUPERTOKENS_USER} ENCODING = 'UTF8' CONNECTION LIMIT = -1 \";" - env: - - name: POSTGRES_PASSWORD - valueFrom: - secretKeyRef: - name: {{ .Release.Name }}-postgresql - key: postgresql-password - optional: false - - name: SUPERTOKENS_USER - valueFrom: - secretKeyRef: - name: {{ include "supertokens.fullname" . }}-db-creds - key: dbUsername - optional: false - - name: SUPERTOKENS_PASSWORD - valueFrom: - secretKeyRef: - name: {{ include "supertokens.fullname" . }}-db-creds - key: dbPassword - optional: false + {{- end }} containers: - name: {{ .Chart.Name }} {{- if .Values.securityContext }} @@ -70,12 +41,20 @@ spec: image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default "latest" }}" imagePullPolicy: {{ .Values.image.pullPolicy }} env: - - name: "POSTGRESQL_CONNECTION_URI" - value: "postgresql://${SUPERTOKENS_USER}:${SUPERTOKENS_PASSWORD}@{{ .Release.Namespace }}-{{ .Values.postgresql.host }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.postgresql.port }}/{{ .Values.database.dbName }}" + - name: "POSTGRESQL_DATABASE_NAME" + value: {{ quote .Values.database.name }} + - name: "POSTGRESQL_PORT" + value: {{ quote .Values.database.port }} + - name: "POSTGRESQL_HOST" + value: {{ quote .Values.database.host }} + - name: "POSTGRESQL_USER" + value: {{ quote .Values.database.user }} + - name: "POSTGRESQL_PASSWORD" + value: {{ quote .Values.database.password }} + - name: "POSTGRESQL_CONNECTION_POOL_SIZE" + value: {{ quote .Values.database.connectionPoolSize }} - name: "SUPERTOKENS_PORT" value: {{ quote .Values.service.port }} - - name: "POSTGRESQL_CONNECTION_POOL_SIZE" - value: {{ quote .Values.postgresql.connectionPoolSize }} - name: "ACCESS_TOKEN_VALIDITY" value: {{ quote .Values.accessTokenValidity }} - name: "ACCESS_TOKEN_BLACKLISTING" @@ -104,18 +83,6 @@ spec: - name: "API_KEYS" value: "{{ join "," .Values.apiKeys.keys }}" {{- end }} - - name: SUPERTOKENS_USER - valueFrom: - secretKeyRef: - name: {{ include "supertokens.fullname" . }}-db-creds - key: dbUsername - optional: false - - name: SUPERTOKENS_PASSWORD - valueFrom: - secretKeyRef: - name: {{ include "supertokens.fullname" . }}-db-creds - key: dbPassword - optional: false ports: - name: http containerPort: 3567 diff --git a/helm-chart/templates/secret.yaml b/helm-chart/templates/secret.yaml deleted file mode 100644 index 27c5454..0000000 --- a/helm-chart/templates/secret.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: {{ include "supertokens.fullname" . }}-db-creds - labels: - {{- include "supertokens.labels" . | nindent 4 }} -type: Opaque -data: - dbPassword: {{ .Values.auth.dbPassword | b64enc }} - dbUsername: {{ .Values.auth.dbUsername | b64enc }} \ No newline at end of file diff --git a/helm-chart/values.yaml b/helm-chart/values.yaml index fe95926..670a03b 100644 --- a/helm-chart/values.yaml +++ b/helm-chart/values.yaml @@ -2,11 +2,7 @@ image: repository: supertokens/supertokens-postgresql pullPolicy: IfNotPresent # -- Overrides the image tag whose default is the chart appVersion. - tag: "3.13" - -auth: # -- database user and password - dbUsername: supertokens - dbPassword: supersecretpassword + tag: "3.14" replicaCount: 1 imagePullSecrets: [] @@ -15,49 +11,15 @@ fullnameOverride: "" database: # -- database name - dbName: supertokens - postgresql: - enabled: true - initContainer: - image: - repository: postgres - pullPolicy: IfNotPresent - # -- Overrides the image tag whose default is the chart appVersion. - tag: "14.2" -# Specifies the database settings -postgresql: + name: supertokens # -- database port port: 5432 - # -- database host address - host: postgresql - # -- database username - service: - type: ClusterIP - #nodePort: 30017 - connectionPoolSize: 5 - persistence: - enabled: true - ## A manually managed Persistent Volume and Claim - ## If defined, PVC must be created manually before volume will be bound - ## The value is evaluated as a template, so, for example, the name can depend on .Release or .Chart - ## - # existingClaim: - ## The path the volume will be mounted at, useful when using different - ## PostgreSQL images. - #mountPath: /bitnami/postgresql - ## The subdirectory of the volume to mount to, useful in dev environments - ## and one PV for multiple services. - subPath: "" - # storageClass: "-" - accessModes: - - ReadWriteOnce - size: 8Gi - annotations: {} - -## updateStrategy for PostgreSQL StatefulSet and its slaves StatefulSets -## ref: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#update-strategies -updateStrategy: - type: RollingUpdate + # -- database host + host: postgres.postgres + # -- database user + user: postgres + # -- database password + password: password service: port: 3567