diff --git a/charts/sonarqube-dce/templates/_helpers.tpl b/charts/sonarqube-dce/templates/_helpers.tpl index c5478a14e..d73772fdf 100644 --- a/charts/sonarqube-dce/templates/_helpers.tpl +++ b/charts/sonarqube-dce/templates/_helpers.tpl @@ -146,7 +146,7 @@ Determine JDBC username {{- end -}} {{/* -Determine the k8s secretKey contrining the JDBC password +Determine the k8s secretKey containing the JDBC password */}} {{- define "jdbc.secretPasswordKey" -}} {{- if .Values.postgresql.enabled -}} diff --git a/charts/sonarqube/templates/validation.yaml b/charts/sonarqube/templates/validation.yaml index 0c9042425..a27bed1ad 100644 --- a/charts/sonarqube/templates/validation.yaml +++ b/charts/sonarqube/templates/validation.yaml @@ -1,3 +1,23 @@ +{{/* +This file is for validating the values.yaml file. +It is used to validate the values.yaml file before the installation starts. +*/}} +{{- define "sonarqube.fail" -}} +{{- printf "\n ** The values.yaml file is not valid. ** \n %s\n" . | fail -}} +{{- end -}} + +{{/* +* Validates the monitoring passcode logic. +*/}} {{- if or (and (not .Values.monitoringPasscode) (not .Values.monitoringPasscodeSecretName) (not .Values.monitoringPasscodeSecretKey)) (and (not .Values.monitoringPasscodeSecretName) .Values.monitoringPasscodeSecretKey) (and .Values.monitoringPasscodeSecretName (not .Values.monitoringPasscodeSecretKey)) -}} -{{- fail "\n ** The values.yaml file is not valid. ** \n Please provide a passcode either setting \"monitoringPasscode\" or \"monitoringPasscodeSecretName\" and \"monitoringPasscodeSecretKey\"" -}} +{{- include "sonarqube.fail" "Please provide a passcode either setting \"monitoringPasscode\" or \"monitoringPasscodeSecretName\" and \"monitoringPasscodeSecretKey\"" -}} +{{- end -}} + +{{/* +* Validates the community.enabled, edition, and tag logic. +*/}} +{{- if and (.Values.community.enabled) (not (empty .Values.edition)) -}} +{{- include "sonarqube.fail" "You can't set 'community.enabled=true' and an 'edition' at the same time." -}} +{{- else if and (not .Values.community.enabled) (empty .Values.edition) -}} +{{- include "sonarqube.fail" "You must choose an 'edition' to install: 'developer' or 'enterprise'." -}} {{- end -}} diff --git a/charts/sonarqube/values.schema.json b/charts/sonarqube/values.schema.json index c5e3a31f6..22db98b60 100644 --- a/charts/sonarqube/values.schema.json +++ b/charts/sonarqube/values.schema.json @@ -200,65 +200,5 @@ } } } - }, - "allOf": [ - { - "if": { - "properties": { - "community": { - "properties": { - "enabled": { - "const": true - } - } - } - } - }, - "then": { - "properties": { - "edition": { - "maxLength": 0 - } - } - } - }, - { - "if": { - "properties": { - "community": { - "properties": { - "enabled": { - "const": false - } - } - } - } - }, - "then": { - "required": [ - "edition" - ] - } - }, - { - "if": { - "not": { - "properties": { - "community": { - "properties": { - "enabled": { - "type": "boolean" - } - } - } - } - } - }, - "then": { - "required": [ - "edition" - ] - } - } - ] + } } diff --git a/tests/unit-test/schema_test.go b/tests/unit-test/schema_test.go index 719298d9b..52f6af76a 100644 --- a/tests/unit-test/schema_test.go +++ b/tests/unit-test/schema_test.go @@ -46,12 +46,12 @@ func TestInvalidSchema(t *testing.T) { { testCaseName: "no-default-edition", valuesFilesPaths: []string{"test-cases-values/sonarqube/invalid-no-default-edition.yaml"}, - expectedError: "edition is required", + expectedError: "You must choose an 'edition' to install: 'developer' or 'enterprise'.", }, { testCaseName: "community-disabled-no-edition", valuesFilesPaths: []string{"test-cases-values/sonarqube/invalid-community-disabled-no-edition.yaml"}, - expectedError: "edition is required", + expectedError: "You must choose an 'edition' to install: 'developer' or 'enterprise'.", }, }