From c955a62b8cc521d25d528f97847ff9559aae4486 Mon Sep 17 00:00:00 2001 From: Aaron Andrino <1107822+a3n7@users.noreply.github.com> Date: Fri, 4 Mar 2022 19:22:01 +0100 Subject: [PATCH 1/4] Raise errors if both externalService and service are set --- ...th-externalService-and-service-enabled.tpl | 27 +++++++++++++++++++ ...h-externalService-and-service-enabled.yaml | 5 ++++ 2 files changed, 32 insertions(+) create mode 100644 charts/posthog/templates/_snippet-error-on-both-externalService-and-service-enabled.tpl create mode 100644 charts/posthog/templates/error-on-both-externalService-and-service-enabled.yaml diff --git a/charts/posthog/templates/_snippet-error-on-both-externalService-and-service-enabled.tpl b/charts/posthog/templates/_snippet-error-on-both-externalService-and-service-enabled.tpl new file mode 100644 index 000000000..fbebe1ce8 --- /dev/null +++ b/charts/posthog/templates/_snippet-error-on-both-externalService-and-service-enabled.tpl @@ -0,0 +1,27 @@ +{{/* Raise an error if externalService is configured without service.enabled being false. */}} +{{- define "snippet.error-on-both-externalService-and-service-enabled" }} +{{- if and .Values.postgresql.enabled .Values.externalPostgresql.postgresqlHost }} + {{- required (printf (include "snippet.error-on-both-externalService-and-service-enabled-template" .) "externalPostgresql.postgresqlHost cannot be set if postgresql.enabled is true") nil -}} +{{- else if and .Values.redis.enabled .Values.externalRedis.host }} + {{- required (printf (include "snippet.error-on-both-externalService-and-service-enabled-template" .) "externalRedis.host cannot be set if redis.enabled is true") nil -}} +{{- else if and .Values.kafka.enabled .Values.externalKafka.brokers }} + {{- required (printf (include "snippet.error-on-both-externalService-and-service-enabled-template" .) "externalKafka.brokers cannot be set if kafka.enabled is true") nil -}} +{{- else if and .Values.clickhouse.enabled .Values.externalClickhouse.host }} + {{- required (printf (include "snippet.error-on-both-externalService-and-service-enabled-template" .) "externalClickhouse.host cannot be set if clickhouse.enabled is true") nil -}} +{{- else if and .Values.clickhouse.enabled .Values.externalClickhouse.cluster }} + {{- required (printf (include "snippet.error-on-both-externalService-and-service-enabled-template" .) "externalClickhouse.cluster cannot be set if clickhouse.enabled is true") nil -}} +{{- end -}} +{{- end -}} + +{{- define "snippet.error-on-both-externalService-and-service-enabled-template" }} + + +==== MISCONFIGURATION ERROR ==== + +Read more on how to update your values.yaml: + +- %s + +========================= + +{{ end -}} diff --git a/charts/posthog/templates/error-on-both-externalService-and-service-enabled.yaml b/charts/posthog/templates/error-on-both-externalService-and-service-enabled.yaml new file mode 100644 index 000000000..57c3f0546 --- /dev/null +++ b/charts/posthog/templates/error-on-both-externalService-and-service-enabled.yaml @@ -0,0 +1,5 @@ +{{- if false -}} +# :TRICKY: This template raises an error if any externalService is configured without service.enabled being false in values.yaml. +# It doesn't actually define any real kubernetes resources +{{- end -}} +{{- include "snippet.error-on-both-externalService-and-service-enabled" . -}} From ad2bb27a3814bb7049e62abb1b7840912d3ed881 Mon Sep 17 00:00:00 2001 From: Aaron Andrino <1107822+a3n7@users.noreply.github.com> Date: Mon, 7 Mar 2022 15:04:34 +0100 Subject: [PATCH 2/4] Merged tpl files for invalid values --- ...and-service-enabled.yaml => error-on-invalid-values.yaml} | 3 ++- charts/posthog/templates/error-on-removed-values.yaml | 5 ----- 2 files changed, 2 insertions(+), 6 deletions(-) rename charts/posthog/templates/{error-on-both-externalService-and-service-enabled.yaml => error-on-invalid-values.yaml} (54%) delete mode 100644 charts/posthog/templates/error-on-removed-values.yaml diff --git a/charts/posthog/templates/error-on-both-externalService-and-service-enabled.yaml b/charts/posthog/templates/error-on-invalid-values.yaml similarity index 54% rename from charts/posthog/templates/error-on-both-externalService-and-service-enabled.yaml rename to charts/posthog/templates/error-on-invalid-values.yaml index 57c3f0546..0dad4c9af 100644 --- a/charts/posthog/templates/error-on-both-externalService-and-service-enabled.yaml +++ b/charts/posthog/templates/error-on-invalid-values.yaml @@ -1,5 +1,6 @@ {{- if false -}} -# :TRICKY: This template raises an error if any externalService is configured without service.enabled being false in values.yaml. +# :TRICKY: These templates raise an error if any invalid values are used in values.yaml. # It doesn't actually define any real kubernetes resources {{- end -}} +{{- include "snippet.error-on-removed-values" . -}} {{- include "snippet.error-on-both-externalService-and-service-enabled" . -}} diff --git a/charts/posthog/templates/error-on-removed-values.yaml b/charts/posthog/templates/error-on-removed-values.yaml deleted file mode 100644 index d00841b7b..000000000 --- a/charts/posthog/templates/error-on-removed-values.yaml +++ /dev/null @@ -1,5 +0,0 @@ -{{- if false -}} -# :TRICKY: This template raises an error if any removed values are used in values.yaml. -# It doesn't actually define any real kubernetes resources -{{- end -}} -{{- include "snippet.error-on-removed-values" . -}} From e245d2465835a75f7f43e077cd75d645d17217b4 Mon Sep 17 00:00:00 2001 From: Aaron Andrino <1107822+a3n7@users.noreply.github.com> Date: Mon, 7 Mar 2022 16:36:29 +0100 Subject: [PATCH 3/4] Add test coverage for error-on-invalid-values.yaml --- .../tests/error-on-invalid-values.yaml | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 charts/posthog/tests/error-on-invalid-values.yaml diff --git a/charts/posthog/tests/error-on-invalid-values.yaml b/charts/posthog/tests/error-on-invalid-values.yaml new file mode 100644 index 000000000..d1d947101 --- /dev/null +++ b/charts/posthog/tests/error-on-invalid-values.yaml @@ -0,0 +1,103 @@ +suite: Error on invalid values +templates: + - error-on-invalid-values.yaml + +tests: + - it: shouldn't error if externalPostgresql.postgresqlHost is set and postgresql.enabled is false + set: + cloud: local + postgresql.enabled: false + externalPostgresql.postgresqlHost: test123.local + asserts: [] + + - it: shouldn't error if externalPostgresql.postgresqlHost is empty and postgresql.enabled is true + set: + cloud: local + postgresql.enabled: true + externalPostgresql.postgresqlHost: "" + asserts: [] + + - it: shouldn't error if externalPostgresql.postgresqlHost is null and postgresql.enabled is true + set: + cloud: local + postgresql.enabled: true + externalPostgresql.postgresqlHost: ~ + asserts: [] + + - it: shouldn't error if externalRedis.host is set and redis.enabled is false + set: + cloud: local + redis.enabled: false + externalRedis.host: test123.local + asserts: [] + + - it: shouldn't error if externalRedis.host is empty and redis.enabled is true + set: + cloud: local + redis.enabled: true + externalRedis.host: "" + asserts: [] + + - it: shouldn't error if externalRedis.host is null and redis.enabled is true + set: + cloud: local + redis.enabled: true + externalRedis.host: ~ + asserts: [] + + - it: shouldn't error if externalKafka.brokers is set and kafka.enabled is false + set: + cloud: local + kafka.enabled: false + externalKafka.brokers: + - test123.local + asserts: [] + + - it: shouldn't error if externalKafka.brokers is empty and kafka.enabled is true + set: + cloud: local + kafka.enabled: true + externalKafka.brokers: [] + asserts: [] + + - it: shouldn't error if externalClickhouse.host is set and clickhouse.enabled is false + set: + cloud: local + clickhouse.enabled: false + externalClickhouse.host: test123.local + asserts: [] + + - it: shouldn't error if externalClickhouse.host is empty and clickhouse.enabled is true + set: + cloud: local + clickhouse.enabled: true + externalClickhouse.host: "" + asserts: [] + + - it: shouldn't error if externalClickhouse.host is null and clickhouse.enabled is true + set: + cloud: local + clickhouse.enabled: true + externalClickhouse.host: ~ + asserts: [] + + - it: shouldn't error if externalClickhouse.cluster is set and clickhouse.enabled is false + set: + cloud: local + clickhouse.enabled: false + externalClickhouse.cluster: clickhouse + asserts: [] + + - it: shouldn't error if externalClickhouse.cluster is empty and clickhouse.enabled is true + set: + cloud: local + clickhouse.enabled: true + externalClickhouse.cluster: "" + asserts: [] + + - it: shouldn't error if externalClickhouse.cluster is null and clickhouse.enabled is true + set: + cloud: local + clickhouse.enabled: true + externalClickhouse.cluster: ~ + asserts: [] From 73923d8b79829175910f6ea6712d9ad22076fb22 Mon Sep 17 00:00:00 2001 From: Aaron Andrino <1107822+a3n7@users.noreply.github.com> Date: Mon, 7 Mar 2022 17:47:10 +0100 Subject: [PATCH 4/4] Merged error-on-invalid-values snippets --- ...th-externalService-and-service-enabled.tpl | 27 ----- .../_snippet-error-on-invalid-values.tpl | 103 ++++++++++++++++++ .../_snippet-error-on-removed-values.tpl | 41 ------- .../templates/error-on-invalid-values.yaml | 5 +- 4 files changed, 105 insertions(+), 71 deletions(-) delete mode 100644 charts/posthog/templates/_snippet-error-on-both-externalService-and-service-enabled.tpl create mode 100644 charts/posthog/templates/_snippet-error-on-invalid-values.tpl delete mode 100644 charts/posthog/templates/_snippet-error-on-removed-values.tpl diff --git a/charts/posthog/templates/_snippet-error-on-both-externalService-and-service-enabled.tpl b/charts/posthog/templates/_snippet-error-on-both-externalService-and-service-enabled.tpl deleted file mode 100644 index fbebe1ce8..000000000 --- a/charts/posthog/templates/_snippet-error-on-both-externalService-and-service-enabled.tpl +++ /dev/null @@ -1,27 +0,0 @@ -{{/* Raise an error if externalService is configured without service.enabled being false. */}} -{{- define "snippet.error-on-both-externalService-and-service-enabled" }} -{{- if and .Values.postgresql.enabled .Values.externalPostgresql.postgresqlHost }} - {{- required (printf (include "snippet.error-on-both-externalService-and-service-enabled-template" .) "externalPostgresql.postgresqlHost cannot be set if postgresql.enabled is true") nil -}} -{{- else if and .Values.redis.enabled .Values.externalRedis.host }} - {{- required (printf (include "snippet.error-on-both-externalService-and-service-enabled-template" .) "externalRedis.host cannot be set if redis.enabled is true") nil -}} -{{- else if and .Values.kafka.enabled .Values.externalKafka.brokers }} - {{- required (printf (include "snippet.error-on-both-externalService-and-service-enabled-template" .) "externalKafka.brokers cannot be set if kafka.enabled is true") nil -}} -{{- else if and .Values.clickhouse.enabled .Values.externalClickhouse.host }} - {{- required (printf (include "snippet.error-on-both-externalService-and-service-enabled-template" .) "externalClickhouse.host cannot be set if clickhouse.enabled is true") nil -}} -{{- else if and .Values.clickhouse.enabled .Values.externalClickhouse.cluster }} - {{- required (printf (include "snippet.error-on-both-externalService-and-service-enabled-template" .) "externalClickhouse.cluster cannot be set if clickhouse.enabled is true") nil -}} -{{- end -}} -{{- end -}} - -{{- define "snippet.error-on-both-externalService-and-service-enabled-template" }} - - -==== MISCONFIGURATION ERROR ==== - -Read more on how to update your values.yaml: - -- %s - -========================= - -{{ end -}} diff --git a/charts/posthog/templates/_snippet-error-on-invalid-values.tpl b/charts/posthog/templates/_snippet-error-on-invalid-values.tpl new file mode 100644 index 000000000..6574b598a --- /dev/null +++ b/charts/posthog/templates/_snippet-error-on-invalid-values.tpl @@ -0,0 +1,103 @@ +{{/* Checks whether invalid values are set */}} +{{- define "snippet.error-on-invalid-values" }} + {{- if and .Values.postgresql.enabled .Values.externalPostgresql.postgresqlHost }} + {{- required (printf (include "snippet.error-on-invalid-values-template" .) + "externalPostgresql.postgresqlHost cannot be set if postgresql.enabled is true" "" + ) nil -}} + + {{- else if and .Values.redis.enabled .Values.externalRedis.host }} + {{- required (printf (include "snippet.error-on-invalid-values-template" .) + "externalRedis.host cannot be set if redis.enabled is true" "" + ) nil -}} + + {{- else if and .Values.kafka.enabled .Values.externalKafka.brokers }} + {{- required (printf (include "snippet.error-on-invalid-values-template" .) + "externalKafka.brokers cannot be set if kafka.enabled is true" "" + ) nil -}} + + {{- else if and .Values.clickhouse.enabled .Values.externalClickhouse.host }} + {{- required (printf (include "snippet.error-on-invalid-values-template" .) + "externalClickhouse.host cannot be set if clickhouse.enabled is true" "" + ) nil -}} + + {{- else if and .Values.clickhouse.enabled .Values.externalClickhouse.cluster }} + {{- required (printf (include "snippet.error-on-invalid-values-template" .) + "externalClickhouse.cluster cannot be set if clickhouse.enabled is true" "" + ) nil -}} + + {{- else if .Values.certManager }} + {{- required (printf (include "snippet.error-on-invalid-values-template" .) + "certManager value has been renamed to cert-manager" + "https://posthog.com/docs/self-host/deploy/upgrade-notes#upgrading-from-3xx" + ) nil -}} + + {{- else if .Values.beat }} + {{- required (printf (include "snippet.error-on-invalid-values-template" .) + "beat deployment has been removed" + "https://posthog.com/docs/self-host/deploy/upgrade-notes#upgrading-from-7xx" + ) nil -}} + + {{- else if .Values.clickhouseOperator }} + {{- required (printf (include "snippet.error-on-invalid-values-template" .) + "clickhouseOperator values are no longer valid" + "https://posthog.com/docs/self-host/deploy/upgrade-notes#upgrading-from-9xx" + ) nil -}} + + {{- else if or .Values.redis.port .Values.redis.host .Values.redis.password }} + {{- required (printf (include "snippet.error-on-invalid-values-template" .) + "redis.port, redis.host and redis.password are no longer valid" + "https://posthog.com/docs/self-host/deploy/upgrade-notes#upgrading-from-11xx" + ) nil -}} + + {{- else if .Values.clickhouse.host }} + {{- required (printf (include "snippet.error-on-invalid-values-template" .) + "clickhouse.host has been moved to externalClickhouse.host" + "https://posthog.com/docs/self-host/deploy/upgrade-notes#upgrading-from-13xx" + ) nil -}} + + {{- else if .Values.clickhouse.replication }} + {{- required (printf (include "snippet.error-on-invalid-values-template" .) + "clickhouse.replication has been removed" + "https://posthog.com/docs/self-host/deploy/upgrade-notes#upgrading-from-12xx" + ) nil -}} + + {{- else if .Values.postgresql.postgresqlHost }} + {{- required (printf (include "snippet.error-on-invalid-values-template" .) + "postgresql.postgresqlHost has been moved to externalPostgresql.postgresqlHost" + "https://posthog.com/docs/self-host/deploy/upgrade-notes#upgrading-from-13xx" + ) nil -}} + + {{- else if .Values.postgresql.postgresqlPort }} + {{- required (printf (include "snippet.error-on-invalid-values-template" .) + "postgresql.postgresqlPort has been moved to externalPostgresql.postgresqlPort" + "https://posthog.com/docs/self-host/deploy/upgrade-notes#upgrading-from-13xx" + ) nil -}} + + {{- else if .Values.postgresql.postgresqlUsername }} + {{- if ne .Values.postgresql.postgresqlUsername "postgres" }} + {{- required (printf (include "snippet.error-on-invalid-values-template" .) + "postgresql.postgresqlUsername has been removed" + "https://posthog.com/docs/self-host/deploy/upgrade-notes#upgrading-from-13xx" + ) nil -}} + {{- end -}} + + {{- if .Values.clickhouse.useNodeSelector }} + {{- required (printf (include "snippet.error-on-invalid-values-template" .) + "clickhouse.useNodeSelector has been removed" + "please use the clickhouse.nodeSelector variable instead" + ) nil -}} + {{- end -}} + {{- end -}} +{{- end -}} + +{{- define "snippet.error-on-invalid-values-template" }} + +==== INVALID VALUES ==== + +Read more on how to update your values.yaml: + +- %s + %s + +========================= +{{ end -}} diff --git a/charts/posthog/templates/_snippet-error-on-removed-values.tpl b/charts/posthog/templates/_snippet-error-on-removed-values.tpl deleted file mode 100644 index f9bbf815f..000000000 --- a/charts/posthog/templates/_snippet-error-on-removed-values.tpl +++ /dev/null @@ -1,41 +0,0 @@ -{{/* Checks whether removed variables are in use. */}} -{{- define "snippet.error-on-removed-values" }} -{{- if .Values.certManager }} - {{- required (printf (include "snippet.error-on-removed-values-template" .) "certManager value has been renamed to cert-manager." "https://posthog.com/docs/self-host/deploy/upgrade-notes#upgrading-from-3xx") nil -}} -{{- else if .Values.beat }} - {{- required (printf (include "snippet.error-on-removed-values-template" .) "beat deployment has been removed." "https://posthog.com/docs/self-host/deploy/upgrade-notes#upgrading-from-7xx") nil -}} -{{- else if .Values.clickhouseOperator }} - {{- required (printf (include "snippet.error-on-removed-values-template" .) "clickhouseOperator values are no longer valid." "https://posthog.com/docs/self-host/deploy/upgrade-notes#upgrading-from-9xx") nil -}} -{{- else if or .Values.redis.port .Values.redis.host .Values.redis.password }} - {{- required (printf (include "snippet.error-on-removed-values-template" .) "redis.port, redis.host and redis.password are no longer valid." "https://posthog.com/docs/self-host/deploy/upgrade-notes#upgrading-from-11xx") nil -}} -{{- else if .Values.clickhouse.host }} - {{- required (printf (include "snippet.error-on-removed-values-template" .) "clickhouse.host has been moved to externalClickhouse.host" "https://posthog.com/docs/self-host/deploy/upgrade-notes#upgrading-from-13xx") nil -}} -{{- else if .Values.clickhouse.replication }} - {{- required (printf (include "snippet.error-on-removed-values-template" .) "clickhouse.replication has been removed" "https://posthog.com/docs/self-host/deploy/upgrade-notes#upgrading-from-12xx") nil -}} -{{- else if .Values.postgresql.postgresqlHost }} - {{- required (printf (include "snippet.error-on-removed-values-template" .) "postgresql.postgresqlHost has been moved to externalPostgresql.postgresqlHost" "https://posthog.com/docs/self-host/deploy/upgrade-notes#upgrading-from-13xx") nil -}} -{{- else if .Values.postgresql.postgresqlPort }} - {{- required (printf (include "snippet.error-on-removed-values-template" .) "postgresql.postgresqlPort has been moved to externalPostgresql.postgresqlPort" "https://posthog.com/docs/self-host/deploy/upgrade-notes#upgrading-from-13xx") nil -}} -{{- else if .Values.postgresql.postgresqlUsername }} -{{- if ne .Values.postgresql.postgresqlUsername "postgres" }} - {{- required (printf (include "snippet.error-on-removed-values-template" .) "postgresql.postgresqlUsername has been removed" "https://posthog.com/docs/self-host/deploy/upgrade-notes#upgrading-from-13xx") nil -}} -{{- end -}} -{{- if .Values.clickhouse.useNodeSelector }} - {{- required (printf (include "snippet.error-on-removed-values-template" .) "clickhouse.useNodeSelector has been removed." "please use the clickhouse.nodeSelector variable instead") nil -}} -{{- end -}} -{{- end -}} -{{- end -}} - -{{- define "snippet.error-on-removed-values-template" }} - - -==== BREAKING CHANGE ==== - -%s - -Read more on how to update your values.yaml: -%s - -========================= - -{{ end -}} diff --git a/charts/posthog/templates/error-on-invalid-values.yaml b/charts/posthog/templates/error-on-invalid-values.yaml index 0dad4c9af..a39abf2e0 100644 --- a/charts/posthog/templates/error-on-invalid-values.yaml +++ b/charts/posthog/templates/error-on-invalid-values.yaml @@ -1,6 +1,5 @@ {{- if false -}} -# :TRICKY: These templates raise an error if any invalid values are used in values.yaml. +# :TRICKY: This template raises an error if any invalid values are used in values.yaml. # It doesn't actually define any real kubernetes resources {{- end -}} -{{- include "snippet.error-on-removed-values" . -}} -{{- include "snippet.error-on-both-externalService-and-service-enabled" . -}} +{{- include "snippet.error-on-invalid-values" . -}}