From 5ce7f2dfc52c41541d4801d6d20bffee5ee55a2d Mon Sep 17 00:00:00 2001 From: Rishabh Tayal Date: Mon, 27 Feb 2023 20:18:37 +0530 Subject: [PATCH 01/10] FEAT: extends support for externalDatabase | clair postgresHost --- charts/clair/templates/_config.yaml.tpl | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/charts/clair/templates/_config.yaml.tpl b/charts/clair/templates/_config.yaml.tpl index 59f85fd6a..97fbf0807 100644 --- a/charts/clair/templates/_config.yaml.tpl +++ b/charts/clair/templates/_config.yaml.tpl @@ -1,11 +1,16 @@ +{{- if .Values.global.externalDatabase }} +{{- $postgresHost := clair-postgresql.devtroncd }} +{{- else }} +{{- $postgresHost := postgresql-postgresql.devtroncd }} + introspection_addr: {{ .Values.config.introspection_addr }} http_listen_addr: {{ .Values.config.http_listen_addr }} log_level: {{ .Values.config.log_level }} indexer: {{- if .Values.config.postgresPassword }} - connstring: "host={{ .Values.config.postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} password={{ .Values.config.postgresPassword }} sslmode=disable" + connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} password={{ .Values.config.postgresPassword }} sslmode=disable" {{- else }} - connstring: "host={{ .Values.config.postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} sslmode=disable" + connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} sslmode=disable" {{- end }} scanlock_retry: {{ .Values.config.indexer.scanlock_retry }} layer_scan_concurrency: {{ .Values.config.indexer.layer_scan_concurrency }} @@ -16,9 +21,9 @@ indexer: matcher: indexer_addr: "{{ .Values.config.matcher.indexer_addr }}" {{- if .Values.config.postgresPassword }} - connstring: "host={{ .Values.config.postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} password={{ .Values.config.postgresPassword }} sslmode=disable" + connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} password={{ .Values.config.postgresPassword }} sslmode=disable" {{- else }} - connstring: "host={{ .Values.config.postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} sslmode=disable" + connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} sslmode=disable" {{- end }} max_conn_pool: {{ .Values.config.matcher.max_conn_pool }} run: "" @@ -32,13 +37,14 @@ matcher: {{- end }} notifier: {{- if .Values.config.postgresPassword }} - connstring: "host={{ .Values.config.postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} password={{ .Values.config.postgresPassword }} sslmode=disable" + connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} password={{ .Values.config.postgresPassword }} sslmode=disable" {{- else }} - connstring: "host={{ .Values.config.postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} sslmode=disable" + connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} sslmode=disable" {{- end }} delivery_interval: {{ .Values.config.notifier.delivery_interval }} poll_interval: {{ .Values.config.notifier.poll_interval }} migrations: {{ .Values.config.notifier.migrations }} {{- if .Values.config.notifier.extraConfig }} {{- toYaml .Values.config.notifier.extraConfig | nindent 2 }} + {{- end }} {{- end }} \ No newline at end of file From ed58c2aed24d88ac3166ac08c9b10d033efc5c5b Mon Sep 17 00:00:00 2001 From: Rishabh Tayal Date: Tue, 28 Feb 2023 15:01:35 +0530 Subject: [PATCH 02/10] FEAT: ISSUE-857 | fix _clair.yaml.tpl in clair --- charts/clair/templates/_config.yaml.tpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/clair/templates/_config.yaml.tpl b/charts/clair/templates/_config.yaml.tpl index 97fbf0807..eb8c5561f 100644 --- a/charts/clair/templates/_config.yaml.tpl +++ b/charts/clair/templates/_config.yaml.tpl @@ -1,7 +1,7 @@ {{- if .Values.global.externalDatabase }} -{{- $postgresHost := clair-postgresql.devtroncd }} +{{- $postgresHost := "clair-postgresql.devtroncd" }} {{- else }} -{{- $postgresHost := postgresql-postgresql.devtroncd }} +{{- $postgresHost := "postgresql-postgresql.devtroncd" }} introspection_addr: {{ .Values.config.introspection_addr }} http_listen_addr: {{ .Values.config.http_listen_addr }} From 0a3e91b4ece4bb347d6282a5b24c506e355553e6 Mon Sep 17 00:00:00 2001 From: Rishabh Tayal Date: Tue, 28 Feb 2023 18:15:59 +0530 Subject: [PATCH 03/10] FEAT: ISSUE-857 | made PG_USER configurable in case of externalDatabase --- charts/clair/templates/_config.yaml.tpl | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/charts/clair/templates/_config.yaml.tpl b/charts/clair/templates/_config.yaml.tpl index eb8c5561f..7fb15be03 100644 --- a/charts/clair/templates/_config.yaml.tpl +++ b/charts/clair/templates/_config.yaml.tpl @@ -3,14 +3,19 @@ {{- else }} {{- $postgresHost := "postgresql-postgresql.devtroncd" }} +{{- if .Values.global.externalDatabase }} +{{- $PG_USER := $.Values.global.externalDatabase.PG_USER | default "postgres" }} +{{- else }} +{{- $PG_USER := "postgres" }} + introspection_addr: {{ .Values.config.introspection_addr }} http_listen_addr: {{ .Values.config.http_listen_addr }} log_level: {{ .Values.config.log_level }} indexer: {{- if .Values.config.postgresPassword }} - connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} password={{ .Values.config.postgresPassword }} sslmode=disable" + connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ $PG_USER }} password={{ .Values.config.postgresPassword }} sslmode=disable" {{- else }} - connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} sslmode=disable" + connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ $PG_USER }} sslmode=disable" {{- end }} scanlock_retry: {{ .Values.config.indexer.scanlock_retry }} layer_scan_concurrency: {{ .Values.config.indexer.layer_scan_concurrency }} @@ -21,9 +26,9 @@ indexer: matcher: indexer_addr: "{{ .Values.config.matcher.indexer_addr }}" {{- if .Values.config.postgresPassword }} - connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} password={{ .Values.config.postgresPassword }} sslmode=disable" + connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ $PG_USER }} password={{ .Values.config.postgresPassword }} sslmode=disable" {{- else }} - connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} sslmode=disable" + connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ $PG_USER }} sslmode=disable" {{- end }} max_conn_pool: {{ .Values.config.matcher.max_conn_pool }} run: "" @@ -37,9 +42,9 @@ matcher: {{- end }} notifier: {{- if .Values.config.postgresPassword }} - connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} password={{ .Values.config.postgresPassword }} sslmode=disable" + connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ $PG_USER }} password={{ .Values.config.postgresPassword }} sslmode=disable" {{- else }} - connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} sslmode=disable" + connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ $PG_USER }} sslmode=disable" {{- end }} delivery_interval: {{ .Values.config.notifier.delivery_interval }} poll_interval: {{ .Values.config.notifier.poll_interval }} From b532d17f3dc6ce3550e6020136e17300e9db91dd Mon Sep 17 00:00:00 2001 From: Rishabh Tayal Date: Thu, 9 Mar 2023 08:41:44 +0530 Subject: [PATCH 04/10] adds condition for clair svc name in case of external db --- charts/clair/Chart.yaml | 2 +- charts/clair/templates/_config.yaml.tpl | 17 ++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/charts/clair/Chart.yaml b/charts/clair/Chart.yaml index 117e6444a..4cba2466e 100644 --- a/charts/clair/Chart.yaml +++ b/charts/clair/Chart.yaml @@ -12,4 +12,4 @@ maintainers: name: clair sources: - https://github.com/coreos/clair -version: 0.1.9 +version: 0.1.10 diff --git a/charts/clair/templates/_config.yaml.tpl b/charts/clair/templates/_config.yaml.tpl index 7fb15be03..eb8c5561f 100644 --- a/charts/clair/templates/_config.yaml.tpl +++ b/charts/clair/templates/_config.yaml.tpl @@ -3,19 +3,14 @@ {{- else }} {{- $postgresHost := "postgresql-postgresql.devtroncd" }} -{{- if .Values.global.externalDatabase }} -{{- $PG_USER := $.Values.global.externalDatabase.PG_USER | default "postgres" }} -{{- else }} -{{- $PG_USER := "postgres" }} - introspection_addr: {{ .Values.config.introspection_addr }} http_listen_addr: {{ .Values.config.http_listen_addr }} log_level: {{ .Values.config.log_level }} indexer: {{- if .Values.config.postgresPassword }} - connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ $PG_USER }} password={{ .Values.config.postgresPassword }} sslmode=disable" + connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} password={{ .Values.config.postgresPassword }} sslmode=disable" {{- else }} - connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ $PG_USER }} sslmode=disable" + connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} sslmode=disable" {{- end }} scanlock_retry: {{ .Values.config.indexer.scanlock_retry }} layer_scan_concurrency: {{ .Values.config.indexer.layer_scan_concurrency }} @@ -26,9 +21,9 @@ indexer: matcher: indexer_addr: "{{ .Values.config.matcher.indexer_addr }}" {{- if .Values.config.postgresPassword }} - connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ $PG_USER }} password={{ .Values.config.postgresPassword }} sslmode=disable" + connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} password={{ .Values.config.postgresPassword }} sslmode=disable" {{- else }} - connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ $PG_USER }} sslmode=disable" + connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} sslmode=disable" {{- end }} max_conn_pool: {{ .Values.config.matcher.max_conn_pool }} run: "" @@ -42,9 +37,9 @@ matcher: {{- end }} notifier: {{- if .Values.config.postgresPassword }} - connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ $PG_USER }} password={{ .Values.config.postgresPassword }} sslmode=disable" + connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} password={{ .Values.config.postgresPassword }} sslmode=disable" {{- else }} - connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ $PG_USER }} sslmode=disable" + connstring: "host={{ $postgresHost }} port={{ .Values.config.postgresPort }} dbname={{ .Values.config.postgresdbname }} user={{ .Values.config.postgresUser }} sslmode=disable" {{- end }} delivery_interval: {{ .Values.config.notifier.delivery_interval }} poll_interval: {{ .Values.config.notifier.poll_interval }} From 63cd81025bb4f8cc31b9f04d2bd449b4b5bd6c1f Mon Sep 17 00:00:00 2001 From: Rishabh Tayal Date: Fri, 10 Mar 2023 13:43:44 +0530 Subject: [PATCH 05/10] external pg changes in security chart --- charts/clair/templates/_config.yaml.tpl | 2 +- charts/clair/templates/deployment.yaml | 6 +++++- charts/clair/values.yaml | 2 +- charts/security/Chart.yaml | 2 +- charts/security/templates/_helpers.tpl | 15 +++++++++++++++ charts/security/templates/image-scanner.yaml | 9 ++++++++- charts/security/values.yaml | 2 +- 7 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 charts/security/templates/_helpers.tpl diff --git a/charts/clair/templates/_config.yaml.tpl b/charts/clair/templates/_config.yaml.tpl index eb8c5561f..d846e4fbd 100644 --- a/charts/clair/templates/_config.yaml.tpl +++ b/charts/clair/templates/_config.yaml.tpl @@ -1,4 +1,4 @@ -{{- if .Values.global.externalDatabase }} +{{- if $.Values.global.externalDatabase }} {{- $postgresHost := "clair-postgresql.devtroncd" }} {{- else }} {{- $postgresHost := "postgresql-postgresql.devtroncd" }} diff --git a/charts/clair/templates/deployment.yaml b/charts/clair/templates/deployment.yaml index 252d1b1f7..412c45e69 100644 --- a/charts/clair/templates/deployment.yaml +++ b/charts/clair/templates/deployment.yaml @@ -40,8 +40,12 @@ spec: initContainers: - name: pg-ready-wait image: postgres:11.3 +{{- if $.Values.global.externalDatabase }} +{{- $postgresHost := "clair-postgresql.devtroncd" }} +{{- else }} +{{- $postgresHost := "postgresql-postgresql.devtroncd" }} command: [ "sh", "-c", - "until pg_isready -h {{ .Values.config.postgresHost }} -p {{ .Values.config.postgresPort }}; + "until pg_isready -h {{ $postgresHost }} -p {{ .Values.config.postgresPort }}; do echo waiting for database; sleep 1; done;"] containers: - name: {{ .Chart.Name }} diff --git a/charts/clair/values.yaml b/charts/clair/values.yaml index e0b207c98..9ddfd992f 100644 --- a/charts/clair/values.yaml +++ b/charts/clair/values.yaml @@ -1,5 +1,5 @@ config: - postgresHost: postgresql-postgresql.devtroncd + # postgresHost: postgresql-postgresql.devtroncd postgresPort: 5432 postgresdbname: clairv4 postgresUser: postgres diff --git a/charts/security/Chart.yaml b/charts/security/Chart.yaml index 314253f38..8d835676d 100644 --- a/charts/security/Chart.yaml +++ b/charts/security/Chart.yaml @@ -15,7 +15,7 @@ maintaintainers: email: pawan.mehta@devtron.ai sources: - https://github.com/devtron-labs/charts -version: 0.1.4 +version: 0.1.5 appVersion: "0.1.1" dependencies: - name: clair diff --git a/charts/security/templates/_helpers.tpl b/charts/security/templates/_helpers.tpl new file mode 100644 index 000000000..b2c4c5d42 --- /dev/null +++ b/charts/security/templates/_helpers.tpl @@ -0,0 +1,15 @@ +{{/* +Returns external database hostname +*/}} +{{- define "pg.host" }} +{{- if .Values.global.externalDatabase }} +{{- $secretData := .Values.global.externalDatabase.PG_PASSWORD }} +{{- $Secret := $secretData | b64enc }} +{{- $Secret }} +{{- else }} +{{- $secretObj := (lookup "v1" "Secret" "devtroncd" "postgresql-postgresql") | default dict }} +{{- $secretData := (get $secretObj "data") | default dict }} +{{- $Secret := (get $secretData "postgresql-password") | default (randAlphaNum 32) | b64enc }} +{{- $Secret }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/security/templates/image-scanner.yaml b/charts/security/templates/image-scanner.yaml index b67112ffe..dabcf5ea9 100644 --- a/charts/security/templates/image-scanner.yaml +++ b/charts/security/templates/image-scanner.yaml @@ -8,7 +8,7 @@ metadata: release: {{ $.Release.Name }} integration: security {{- if .labels }} -{{ toYaml .labels | indent 4 }} +{{ toYaml .labels | indent 4 }} {{- end}} type: Opaque {{- if .secrets }} @@ -30,6 +30,12 @@ metadata: {{ toYaml .labels | indent 4 }} {{- end}} data: +{{- if $.Values.global.externalDatabase }} +{{- $PG_ADDR := "clair-postgresql.devtroncd" }} +{{- else }} +{{- $PG_ADDR := "postgresql-postgresql.devtroncd" }} + PG_ADDR: {{ $PG_ADDR }} +{{- end }} {{- if .configs}} {{ toYaml .configs | indent 2 }} --- @@ -134,3 +140,4 @@ spec: {{- end }} revisionHistoryLimit: 3 {{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/security/values.yaml b/charts/security/values.yaml index 6ef437758..b1212c117 100644 --- a/charts/security/values.yaml +++ b/charts/security/values.yaml @@ -3,7 +3,7 @@ imageScanner: CLAIR_ADDR: clair.devtroncd:6060 CLIENT_ID: client-2 NATS_SERVER_HOST: nats://devtron-nats.devtroncd:4222 - PG_ADDR: postgresql-postgresql.devtroncd + # PG_ADDR: postgresql-postgresql.devtroncd PG_DATABASE: orchestrator PG_LOG_QUERY: "false" PG_PORT: "5432" From f7943792e556b168e4bf92f32b81262a733342c0 Mon Sep 17 00:00:00 2001 From: Rishabh Tayal Date: Fri, 10 Mar 2023 16:28:59 +0530 Subject: [PATCH 06/10] external pg changes in deployment of clair --- charts/clair/templates/_helpers.tpl | 10 ++++++++++ charts/clair/templates/deployment.yaml | 5 +---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/charts/clair/templates/_helpers.tpl b/charts/clair/templates/_helpers.tpl index b91f6746c..7ade02b61 100644 --- a/charts/clair/templates/_helpers.tpl +++ b/charts/clair/templates/_helpers.tpl @@ -1,3 +1,13 @@ +{{/* Returns Postgres db service name */}} + +{{- define "postgres.host" }} +{{- if $.Values.global.externalDatabase }} +{{- print "clair-postgresql.devtroncd" }} +{{- else }} +{{- print "postgresql-postgresql.devtroncd" }} +{{- end }} +{{- end }} + {{/* vim: set filetype=mustache: */}} {{/* Expand the name of the chart. diff --git a/charts/clair/templates/deployment.yaml b/charts/clair/templates/deployment.yaml index 412c45e69..e9f6dedd4 100644 --- a/charts/clair/templates/deployment.yaml +++ b/charts/clair/templates/deployment.yaml @@ -1,3 +1,4 @@ +{{- $postgresHost := (include "postgres.host" $) }} apiVersion: apps/v1 kind: Deployment metadata: @@ -40,10 +41,6 @@ spec: initContainers: - name: pg-ready-wait image: postgres:11.3 -{{- if $.Values.global.externalDatabase }} -{{- $postgresHost := "clair-postgresql.devtroncd" }} -{{- else }} -{{- $postgresHost := "postgresql-postgresql.devtroncd" }} command: [ "sh", "-c", "until pg_isready -h {{ $postgresHost }} -p {{ .Values.config.postgresPort }}; do echo waiting for database; sleep 1; done;"] From 8bf727d49683f519cfd18c0f48a6a74edcaad64d Mon Sep 17 00:00:00 2001 From: Rishabh Tayal Date: Fri, 10 Mar 2023 16:56:17 +0530 Subject: [PATCH 07/10] adds condition in function | ext pg --- charts/security/Chart.yaml | 2 +- charts/security/templates/_helpers.tpl | 18 ++++++------------ charts/security/templates/image-scanner.yaml | 9 ++------- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/charts/security/Chart.yaml b/charts/security/Chart.yaml index 8d835676d..1b657664d 100644 --- a/charts/security/Chart.yaml +++ b/charts/security/Chart.yaml @@ -19,6 +19,6 @@ version: 0.1.5 appVersion: "0.1.1" dependencies: - name: clair - version: "0.x.x" + version: "0.1.10" repository: https://helm.devtron.ai condition: clair.enabled diff --git a/charts/security/templates/_helpers.tpl b/charts/security/templates/_helpers.tpl index b2c4c5d42..562c46853 100644 --- a/charts/security/templates/_helpers.tpl +++ b/charts/security/templates/_helpers.tpl @@ -1,15 +1,9 @@ -{{/* -Returns external database hostname -*/}} -{{- define "pg.host" }} -{{- if .Values.global.externalDatabase }} -{{- $secretData := .Values.global.externalDatabase.PG_PASSWORD }} -{{- $Secret := $secretData | b64enc }} -{{- $Secret }} +{{/* Returns Postgres db service name */}} + +{{- define "postgres.host" }} +{{- if $.Values.global.externalDatabase }} +{{- print "clair-postgresql.devtroncd" }} {{- else }} -{{- $secretObj := (lookup "v1" "Secret" "devtroncd" "postgresql-postgresql") | default dict }} -{{- $secretData := (get $secretObj "data") | default dict }} -{{- $Secret := (get $secretData "postgresql-password") | default (randAlphaNum 32) | b64enc }} -{{- $Secret }} +{{- print "postgresql-postgresql.devtroncd" }} {{- end }} {{- end }} \ No newline at end of file diff --git a/charts/security/templates/image-scanner.yaml b/charts/security/templates/image-scanner.yaml index dabcf5ea9..5534e6199 100644 --- a/charts/security/templates/image-scanner.yaml +++ b/charts/security/templates/image-scanner.yaml @@ -1,3 +1,4 @@ +{{- $postgresHost := (include "postgres.host" $) }} {{- with .Values.imageScanner }} apiVersion: v1 kind: Secret @@ -30,12 +31,7 @@ metadata: {{ toYaml .labels | indent 4 }} {{- end}} data: -{{- if $.Values.global.externalDatabase }} -{{- $PG_ADDR := "clair-postgresql.devtroncd" }} -{{- else }} -{{- $PG_ADDR := "postgresql-postgresql.devtroncd" }} - PG_ADDR: {{ $PG_ADDR }} -{{- end }} + PG_ADDR: {{ $postgresHost }} {{- if .configs}} {{ toYaml .configs | indent 2 }} --- @@ -139,5 +135,4 @@ spec: {{ toYaml .tolerations | indent 8 }} {{- end }} revisionHistoryLimit: 3 -{{- end }} {{- end }} \ No newline at end of file From dda228ea231bb685b6963ae19fda8d868e9f8467 Mon Sep 17 00:00:00 2001 From: Rishabh Tayal Date: Mon, 13 Mar 2023 11:19:54 +0530 Subject: [PATCH 08/10] minor using function instead of condition in config.yaml.tpl #ISSUE-857 --- charts/clair/templates/_config.yaml.tpl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/charts/clair/templates/_config.yaml.tpl b/charts/clair/templates/_config.yaml.tpl index d846e4fbd..855f959d4 100644 --- a/charts/clair/templates/_config.yaml.tpl +++ b/charts/clair/templates/_config.yaml.tpl @@ -1,7 +1,4 @@ -{{- if $.Values.global.externalDatabase }} -{{- $postgresHost := "clair-postgresql.devtroncd" }} -{{- else }} -{{- $postgresHost := "postgresql-postgresql.devtroncd" }} +{{- $postgresHost := (include "postgres.host" $) }} introspection_addr: {{ .Values.config.introspection_addr }} http_listen_addr: {{ .Values.config.http_listen_addr }} From 3b232ee78260c23b4474d04e69ed4628bba07511 Mon Sep 17 00:00:00 2001 From: Rishabh Tayal Date: Mon, 13 Mar 2023 11:27:20 +0530 Subject: [PATCH 09/10] minor tweak | ISSUE-857 --- charts/clair/templates/_config.yaml.tpl | 1 - 1 file changed, 1 deletion(-) diff --git a/charts/clair/templates/_config.yaml.tpl b/charts/clair/templates/_config.yaml.tpl index 855f959d4..b95e5a9a6 100644 --- a/charts/clair/templates/_config.yaml.tpl +++ b/charts/clair/templates/_config.yaml.tpl @@ -43,5 +43,4 @@ notifier: migrations: {{ .Values.config.notifier.migrations }} {{- if .Values.config.notifier.extraConfig }} {{- toYaml .Values.config.notifier.extraConfig | nindent 2 }} - {{- end }} {{- end }} \ No newline at end of file From 745c75fb18f68ee018a52899e419c2230168d836 Mon Sep 17 00:00:00 2001 From: Rishabh Tayal Date: Mon, 13 Mar 2023 13:36:48 +0530 Subject: [PATCH 10/10] adds condition for PG_DATABASE in img_scanner | ISSUE-857 --- charts/security/templates/_helpers.tpl | 10 ++++++++++ charts/security/templates/image-scanner.yaml | 2 ++ charts/security/values.yaml | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/charts/security/templates/_helpers.tpl b/charts/security/templates/_helpers.tpl index 562c46853..fcd520147 100644 --- a/charts/security/templates/_helpers.tpl +++ b/charts/security/templates/_helpers.tpl @@ -6,4 +6,14 @@ {{- else }} {{- print "postgresql-postgresql.devtroncd" }} {{- end }} +{{- end }} + +{{/* Returns Postgres db name */}} + +{{- define "postgres.db" }} +{{- if $.Values.global.externalDatabase }} +{{- print "clairv4" }} +{{- else }} +{{- print "orchestrator" }} +{{- end }} {{- end }} \ No newline at end of file diff --git a/charts/security/templates/image-scanner.yaml b/charts/security/templates/image-scanner.yaml index 5534e6199..a8d53fbcc 100644 --- a/charts/security/templates/image-scanner.yaml +++ b/charts/security/templates/image-scanner.yaml @@ -1,4 +1,5 @@ {{- $postgresHost := (include "postgres.host" $) }} +{{- $postgresDB := (include "postgres.db" $) }} {{- with .Values.imageScanner }} apiVersion: v1 kind: Secret @@ -32,6 +33,7 @@ metadata: {{- end}} data: PG_ADDR: {{ $postgresHost }} + PG_DATABASE: {{ $postgresDB }} {{- if .configs}} {{ toYaml .configs | indent 2 }} --- diff --git a/charts/security/values.yaml b/charts/security/values.yaml index b1212c117..93638a6a2 100644 --- a/charts/security/values.yaml +++ b/charts/security/values.yaml @@ -4,7 +4,7 @@ imageScanner: CLIENT_ID: client-2 NATS_SERVER_HOST: nats://devtron-nats.devtroncd:4222 # PG_ADDR: postgresql-postgresql.devtroncd - PG_DATABASE: orchestrator + # PG_DATABASE: orchestrator PG_LOG_QUERY: "false" PG_PORT: "5432" PG_USER: postgres