Skip to content

Commit

Permalink
Moves validations from schema to validations.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
davividal committed Jan 6, 2025
1 parent 4c9df46 commit 1320eae
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 65 deletions.
2 changes: 1 addition & 1 deletion charts/sonarqube-dce/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand Down
22 changes: 21 additions & 1 deletion charts/sonarqube/templates/validation.yaml
Original file line number Diff line number Diff line change
@@ -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 -}}
62 changes: 1 addition & 61 deletions charts/sonarqube/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
}
]
}
}
4 changes: 2 additions & 2 deletions tests/unit-test/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'.",
},
}

Expand Down

0 comments on commit 1320eae

Please sign in to comment.