Skip to content

Commit a06db1d

Browse files
Merge pull request #321 from devtron-labs/clair-pg
feat: shifted the database configurations to global level
2 parents b8fd224 + b6d7c92 commit a06db1d

File tree

5 files changed

+52
-22
lines changed

5 files changed

+52
-22
lines changed

charts/clair/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ maintainers:
1212
name: clair
1313
sources:
1414
- https://github.com/coreos/clair
15-
version: 0.1.14
15+
version: 0.1.15

charts/clair/templates/_config.yaml.tpl

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,16 @@ introspection_addr: {{ .Values.config.introspection_addr }}
22
http_listen_addr: {{ .Values.config.http_listen_addr }}
33
log_level: {{ .Values.config.log_level }}
44
indexer:
5-
{{- if .Values.config.postgresPassword }}
6-
connstring: "host={{ .Values.config.postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} password={{ .Values.config.postgresPassword }} sslmode=disable"
7-
{{- else }}
8-
connstring: "host={{ .Values.config.postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} sslmode=disable"
9-
{{- end }}
5+
{{- include "clair.dbconnstring" . }}
106
scanlock_retry: {{ .Values.config.indexer.scanlock_retry }}
117
layer_scan_concurrency: {{ .Values.config.indexer.layer_scan_concurrency }}
128
migrations: {{ .Values.config.indexer.migrations }}
139
{{- if .Values.config.indexer.extraConfig }}
1410
{{- toYaml .Values.config.indexer.extraConfig | nindent 2 }}
1511
{{- end }}
1612
matcher:
13+
{{- include "clair.dbconnstring" . }}
1714
indexer_addr: "{{ .Values.config.matcher.indexer_addr }}"
18-
{{- if .Values.config.postgresPassword }}
19-
connstring: "host={{ .Values.config.postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} password={{ .Values.config.postgresPassword }} sslmode=disable"
20-
{{- else }}
21-
connstring: "host={{ .Values.config.postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} sslmode=disable"
22-
{{- end }}
2315
max_conn_pool: {{ .Values.config.matcher.max_conn_pool }}
2416
run: ""
2517
migrations: {{ .Values.config.matcher.migrations }}
@@ -31,11 +23,7 @@ matcher:
3123
{{- toYaml .Values.config.matcher.extraConfig | nindent 2 }}
3224
{{- end }}
3325
notifier:
34-
{{- if .Values.config.postgresPassword }}
35-
connstring: "host={{ .Values.config.postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} password={{ .Values.config.postgresPassword }} sslmode=disable"
36-
{{- else }}
37-
connstring: "host={{ .Values.config.postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} sslmode=disable"
38-
{{- end }}
26+
{{- include "clair.dbconnstring" . }}
3927
delivery_interval: {{ .Values.config.notifier.delivery_interval }}
4028
poll_interval: {{ .Values.config.notifier.poll_interval }}
4129
migrations: {{ .Values.config.notifier.migrations }}

charts/clair/templates/_helpers.tpl

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,45 @@ imagePullSecrets:
8181
imagePullSecrets:
8282
{{ toYaml .global.imagePullSecrets | indent 2 }}
8383
{{- end }}
84-
{{- end }}
84+
{{- end }}
85+
86+
{{/*
87+
Generate dbconnection String
88+
*/}}
89+
{{- define "clair.dbconnstring" -}}
90+
{{- $globalDbConfig := dict -}}
91+
{{- if .Values.global -}}
92+
{{- $globalDbConfig = .Values.global.dbConfig | default dict -}}
93+
{{- end -}}
94+
{{- $pgAddr := .Values.config.PG_ADDR | default $globalDbConfig.PG_ADDR | default "postgresql-postgresql.devtroncd" -}}
95+
{{- $pgPort := .Values.config.PG_PORT | default $globalDbConfig.PG_PORT | default "5432" -}}
96+
{{- $pgDatabase := .Values.config.PG_DATABASE | default $globalDbConfig.PG_DATABASE | default "clairv4" -}}
97+
{{- $pgUser := .Values.config.PG_USER | default $globalDbConfig.PG_USER | default "postgres" -}}
98+
{{- if .Values.config.postgresPassword }}
99+
connstring: "host={{ $pgAddr }} port={{ $pgPort }} dbname={{ $pgDatabase }} user={{ $pgUser }} password={{ .Values.config.postgresPassword }} sslmode=disable"
100+
{{- else }}
101+
connstring: "host={{ $pgAddr }} port={{ $pgPort }} dbname={{ $pgDatabase }} user={{ $pgUser }} sslmode=disable"
102+
{{- end }}
103+
{{- end -}}
104+
105+
{{/*
106+
Generate postgres host
107+
*/}}
108+
{{- define "clair.postgresHost" -}}
109+
{{- $globalDbConfig := dict -}}
110+
{{- if .Values.global -}}
111+
{{- $globalDbConfig = .Values.global.dbConfig | default dict -}}
112+
{{- end -}}
113+
{{- .Values.config.PG_ADDR | default $globalDbConfig.PG_ADDR | default "postgresql-postgresql.devtroncd" -}}
114+
{{- end -}}
115+
116+
{{/*
117+
Generate postgres port
118+
*/}}
119+
{{- define "clair.postgresPort" -}}
120+
{{- $globalDbConfig := dict -}}
121+
{{- if .Values.global -}}
122+
{{- $globalDbConfig = .Values.global.dbConfig | default dict -}}
123+
{{- end -}}
124+
{{- .Values.config.PG_PORT | default $globalDbConfig.PG_PORT | default "5432" -}}
125+
{{- end -}}

charts/clair/templates/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ spec:
3434
- name: pg-ready-wait
3535
image: {{ include "common.clair.image" (dict "component" $.Values.image "global" $.Values.global "extraImage" $.Values.image.initContainer.image "extraImageTag" $.Values.image.initContainer.tag ) }}
3636
command: [ "sh", "-c",
37-
"until pg_isready -h {{ .Values.config.postgresHost }} -p {{ .Values.config.postgresPort }};
37+
"until pg_isready -h {{ include "clair.postgresHost" . }} -p {{ include "clair.postgresPort" . }};
3838
do echo waiting for database; sleep 1; done;"]
3939
envFrom:
4040
- configMapRef:

charts/clair/values.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ global:
1111
# imagePullSecrets:
1212
# - name: yoursecret
1313

14+
dbConfig:
15+
PG_ADDR: postgresql-postgresql.devtroncd
16+
PG_PORT: "5432"
17+
PG_USER: postgres
18+
1419
config:
15-
postgresHost: postgresql-postgresql.devtroncd
16-
postgresPort: 5432
17-
postgresdbname: clairv4
18-
postgresUser: postgres
1920
postgresPassword: ""
2021
introspection_addr: :6061
2122
http_listen_addr: :6060

0 commit comments

Comments
 (0)