Skip to content

Commit

Permalink
Merge pull request #304 from flanksource/helm-chart-improvements
Browse files Browse the repository at this point in the history
fix: change database name in helm chart
  • Loading branch information
moshloop authored Oct 11, 2023
2 parents d31f77a + 9106fc8 commit bcf921e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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://<username>:<password>@localhost:5432/<db_name> ./.bin/config-db serve --run-migrations
DB_URL=postgres://<username>:<password>@localhost:5432/<db_name> ./.bin/config-db serve --db-migrations
```

### Scape config
Expand Down
3 changes: 3 additions & 0 deletions chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 10 additions & 10 deletions chart/templates/postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgresql
name: {{ template "config-db.name" . }}-postgresql
spec:
serviceName: postgresql
selector:
Expand All @@ -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
Expand All @@ -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 }}
Expand Down
13 changes: 6 additions & 7 deletions chart/values.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions fixtures/expected/file-git.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{
"name": "httpbin_2xx_count",
"type": "counter",
"value": "result.code == 200 ? 1 : 0",
"value": "code == 200 ? 1 : 0",
"labels": [
{
"name": "name",
Expand All @@ -39,7 +39,7 @@
},
{
"name": "status_class",
"valueExpr": "string(result.code).charAt(0)"
"valueExpr": "string(code).charAt(0)"
}
]
}
Expand Down

0 comments on commit bcf921e

Please sign in to comment.