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 93f25204..c274372e 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,17 +59,19 @@ 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" }} + {{- $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/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 diff --git a/fixtures/expected/file-git.json b/fixtures/expected/file-git.json index dc5b11c3..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", @@ -39,7 +39,7 @@ }, { "name": "status_class", - "valueExpr": "string(result.code).charAt(0)" + "valueExpr": "string(code).charAt(0)" } ] }