From d4506e78cc63c5b7a2f9d41b1b276cd9a270f1e7 Mon Sep 17 00:00:00 2001 From: Yash Mehrotra Date: Mon, 9 Oct 2023 11:27:03 +0530 Subject: [PATCH 1/3] fix: change database name in helm chart --- chart/templates/postgres.yaml | 16 +++++++--------- chart/values.yaml | 13 ++++++------- cmd/root.go | 2 +- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/chart/templates/postgres.yaml b/chart/templates/postgres.yaml index 93f25204..d3e6733a 100644 --- a/chart/templates/postgres.yaml +++ b/chart/templates/postgres.yaml @@ -5,7 +5,7 @@ apiVersion: apps/v1 kind: StatefulSet metadata: - name: postgresql + name: {{ template "config-db.name" . }}-postgresql spec: serviceName: postgresql selector: @@ -31,27 +31,25 @@ spec: name: postgresql spec: accessModes: ["ReadWriteOnce"] + {{- if not (eq .Values.db.storageClass "") }} storageClassName: {{ .Values.db.storageClass }} + {{- end }} resources: requests: storage: {{ .Values.db.storage }} - --- - # PostgreSQL StatefulSet Service apiVersion: v1 kind: Service metadata: - name: postgres + name: {{ template "config-db.name" . }}-postgresql spec: selector: app: postgresql ports: - port: 5432 targetPort: 5432 - --- - {{- if .Values.db.secretKeyRef.create }} apiVersion: v1 kind: Secret @@ -61,11 +59,11 @@ metadata: "helm.sh/resource-policy": "keep" type: Opaque stringData: - {{- $secretObj := ( lookup "v1" "Secret" .Release.Namespace "postgres-connection" ) }} - {{- $secretData := ( get $secretObj "data" ) }} + {{- $secretObj := ( lookup "v1" "Secret" .Release.Namespace "postgres-connection" ) | default dict }} + {{- $secretData := ( get $secretObj "data" | default dict ) }} {{- $user := (( get $secretData "POSTGRES_USER" ) | b64dec ) | default "postgres" }} {{- $password := (( get $secretData "POSTGRES_PASSWORD" ) | b64dec ) | default (randAlphaNum 32) }} - {{- $host := print "postgres." .Release.Namespace ".svc.cluster.local:5432" }} + {{- $host := print (include "config-db.name" .) "-postgresql." .Release.Namespace ".svc.cluster.local:5432" }} {{- $url := print "postgresql://" $user ":" $password "@" $host }} {{- $configDbUrl := ( get $secretData .Values.db.secretKeyRef.key ) | default ( print $url "/config-db" ) }} diff --git a/chart/values.yaml b/chart/values.yaml index 4cb830e2..59b99ad8 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -1,5 +1,4 @@ # Default values for config-db. -# This is a YAML-formatted file. # Declare variables to be passed into your templates. replicas: 1 @@ -27,12 +26,12 @@ db: enabled: true secretKeyRef: create: true - # (Required) The name of the secret to look for. - name: - # (Required) This is the key that we look for in the secret. + # The name of the secret to look for. + name: config-db-postgresql + # This is the key that we look for in the secret. key: DB_URL - storageClass: - storage: + storageClass: "" + storage: 20Gi ingress: enabled: false @@ -62,7 +61,7 @@ serviceAccount: upstream: enabled: false secretKeyRef: - name: upstream # Must contain: UPSTREAM_USER, UPSTREAM_PASS & UPSTREAM_HOST + name: config-db-upstream # Must contain: UPSTREAM_USER, UPSTREAM_PASS & UPSTREAM_HOST agentName: default-agent pageSize: 500 diff --git a/cmd/root.go b/cmd/root.go index 41b7b8df..e8331004 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -77,7 +77,7 @@ func ServerFlags(flags *pflag.FlagSet) { // Flags for push/pull var upstreamPageSizeDefault = 500 if val, exists := os.LookupEnv("UPSTREAM_PAGE_SIZE"); exists { - if parsed, err := strconv.Atoi(val); err != nil || parsed < 0 { + if parsed, err := strconv.Atoi(val); err != nil || parsed <= 0 { logger.Fatalf("invalid value=%s for UPSTREAM_PAGE_SIZE. Must be a postive number", val) } else { upstreamPageSizeDefault = parsed From c8c4fedf0bdf9000e8f917249f1aa6e83ea6be95 Mon Sep 17 00:00:00 2001 From: Yash Mehrotra Date: Mon, 9 Oct 2023 11:39:09 +0530 Subject: [PATCH 2/3] chore: update file-git fixture --- fixtures/expected/file-git.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fixtures/expected/file-git.json b/fixtures/expected/file-git.json index dc5b11c3..15ecd439 100644 --- a/fixtures/expected/file-git.json +++ b/fixtures/expected/file-git.json @@ -39,7 +39,7 @@ }, { "name": "status_class", - "valueExpr": "string(result.code).charAt(0)" + "valueExpr": "string(code).charAt(0)" } ] } From 9106fc8c23389d288c8dedc938ac47e0f7799b4e Mon Sep 17 00:00:00 2001 From: Yash Mehrotra Date: Mon, 9 Oct 2023 17:10:27 +0530 Subject: [PATCH 3/3] fix: run db migrations in helm chart --- README.md | 2 +- chart/templates/deployment.yaml | 3 +++ chart/templates/postgres.yaml | 4 +++- fixtures/expected/file-git.json | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1e61d81b..840711c1 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ make build Starting the server will run the migrations and start scraping in background (The `default-schedule` configuration will run scraping every 60 minutes if configuration is not explicitly specified). ```bash -DB_URL=postgres://:@localhost:5432/ ./.bin/config-db serve --run-migrations +DB_URL=postgres://:@localhost:5432/ ./.bin/config-db serve --db-migrations ``` ### Scape config diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml index c98af5af..cb656ac6 100644 --- a/chart/templates/deployment.yaml +++ b/chart/templates/deployment.yaml @@ -42,6 +42,9 @@ spec: - --disable-postgrest={{ .Values.disablePostgrest }} - --change-retention-days={{ .Values.configChangeRetentionDays }} - --analysis-retention-days={{ .Values.configAnalysisRetentionDays }} + {{- if .Values.db.enabled}} + - --db-migrations + {{- end}} {{- if .Values.upstream.enabled}} envFrom: - secretRef: diff --git a/chart/templates/postgres.yaml b/chart/templates/postgres.yaml index d3e6733a..c274372e 100644 --- a/chart/templates/postgres.yaml +++ b/chart/templates/postgres.yaml @@ -63,13 +63,15 @@ stringData: {{- $secretData := ( get $secretObj "data" | default dict ) }} {{- $user := (( get $secretData "POSTGRES_USER" ) | b64dec ) | default "postgres" }} {{- $password := (( get $secretData "POSTGRES_PASSWORD" ) | b64dec ) | default (randAlphaNum 32) }} + {{- $dbname := (( get $secretData "POSTGRES_DB" ) | b64dec ) | default "config_db" }} {{- $host := print (include "config-db.name" .) "-postgresql." .Release.Namespace ".svc.cluster.local:5432" }} {{- $url := print "postgresql://" $user ":" $password "@" $host }} - {{- $configDbUrl := ( get $secretData .Values.db.secretKeyRef.key ) | default ( print $url "/config-db" ) }} + {{- $configDbUrl := ( get $secretData .Values.db.secretKeyRef.key ) | default ( print $url "/config_db?sslmode=disable" ) }} POSTGRES_USER: {{ $user | quote }} POSTGRES_PASSWORD: {{ $password | quote }} POSTGRES_HOST: {{ $host | quote }} + POSTGRES_DB: {{ $dbname | quote }} {{ .Values.db.secretKeyRef.key }}: {{ $configDbUrl | quote }} {{- end }} diff --git a/fixtures/expected/file-git.json b/fixtures/expected/file-git.json index 15ecd439..99862f31 100644 --- a/fixtures/expected/file-git.json +++ b/fixtures/expected/file-git.json @@ -27,7 +27,7 @@ { "name": "httpbin_2xx_count", "type": "counter", - "value": "result.code == 200 ? 1 : 0", + "value": "code == 200 ? 1 : 0", "labels": [ { "name": "name",