diff --git a/CHANGELOG.md b/CHANGELOG.md index 95f0dea13..0c038f77c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ ### Fixed * Fix Tailor deployment drifts for D, Q envs ([#1055](https://github.com/opendevstack/ods-jenkins-shared-library/pull/1055)) +* Helm chart validation error if a commit hash starts with 8 or more numbers ([#1179](https://github.com/opendevstack/ods-jenkins-shared-library/issues/1179)) ## [4.6.0] - 2024-10-23 diff --git a/docs/modules/jenkins-shared-library/partials/odsComponentStageRolloutOpenShiftDeployment.adoc b/docs/modules/jenkins-shared-library/partials/odsComponentStageRolloutOpenShiftDeployment.adoc index e27ba5a19..85bf2600a 100644 --- a/docs/modules/jenkins-shared-library/partials/odsComponentStageRolloutOpenShiftDeployment.adoc +++ b/docs/modules/jenkins-shared-library/partials/odsComponentStageRolloutOpenShiftDeployment.adoc @@ -144,12 +144,22 @@ _String_ referenced by `chartDir` exists. -| *helmValues* + +| *helmStringValues* + _Map_ |Key/value pairs to pass as values (by default, the key `imageTag` is set to the config option `imageTag`). Only relevant if the directory referenced by `chartDir` exists. + See also `helm --set-string`. + + +| *helmValues* + +_Map_ +|Key/value pairs to pass as values. Only relevant if the directory + referenced by `chartDir` exists. + + See also `helm --set`. Be aware that the resulting data type may vary depending on the input. + | *helmValuesFiles* + _List_ diff --git a/src/org/ods/component/HelmDeploymentStrategy.groovy b/src/org/ods/component/HelmDeploymentStrategy.groovy index 908cc14fb..df0bb8978 100644 --- a/src/org/ods/component/HelmDeploymentStrategy.groovy +++ b/src/org/ods/component/HelmDeploymentStrategy.groovy @@ -54,6 +54,9 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy { if (!config.containsKey('helmValues')) { config.helmValues = [:] } + if (!config.containsKey('helmStringValues')) { + config.helmStringValues = [:] + } if (!config.containsKey('helmValuesFiles')) { config.helmValuesFiles = ['values.yaml'] } @@ -120,24 +123,29 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy { } // we add two things persistent - as these NEVER change (and are env independent) - options.helmValues['registry'] = context.clusterRegistryAddress - options.helmValues['componentId'] = context.componentId + options.helmStringValues['registry'] = context.clusterRegistryAddress + options.helmStringValues['componentId'] = context.componentId // we persist the original ones set from outside - here we just add ours Map mergedHelmValues = [:] mergedHelmValues << options.helmValues + Map mergedHelmStringValues = [:] + mergedHelmStringValues << options.helmStringValues // we add the global ones - this allows usage in subcharts options.helmValues.each { key, value -> mergedHelmValues["global.${key}"] = value } + options.helmStringValues.each { key, value -> + mergedHelmStringValues["global.${key}"] = value + } - mergedHelmValues['imageNamespace'] = targetProject - mergedHelmValues['imageTag'] = options.imageTag + mergedHelmStringValues['imageNamespace'] = targetProject + mergedHelmStringValues['imageTag'] = options.imageTag // we also add the predefined ones as these are in use by the library - mergedHelmValues['global.imageNamespace'] = targetProject - mergedHelmValues['global.imageTag'] = options.imageTag + mergedHelmStringValues['global.imageNamespace'] = targetProject + mergedHelmStringValues['global.imageTag'] = options.imageTag // deal with dynamic value files - which are env dependent def mergedHelmValuesFiles = [] @@ -153,6 +161,7 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy { options.helmReleaseName, mergedHelmValuesFiles, mergedHelmValues, + mergedHelmStringValues, options.helmDefaultFlags, options.helmAdditionalFlags, options.helmDiff @@ -191,6 +200,7 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy { 'helmEnvBasedValuesFiles': options.helmEnvBasedValuesFiles, 'helmValuesFiles': options.helmValuesFiles, 'helmValues': options.helmValues, + 'helmStringValues': options.helmStringValues, 'helmDefaultFlags': options.helmDefaultFlags, 'helmAdditionalFlags': options.helmAdditionalFlags, ]) diff --git a/src/org/ods/component/RolloutOpenShiftDeploymentOptions.groovy b/src/org/ods/component/RolloutOpenShiftDeploymentOptions.groovy index 3fe467406..b7fe533e5 100644 --- a/src/org/ods/component/RolloutOpenShiftDeploymentOptions.groovy +++ b/src/org/ods/component/RolloutOpenShiftDeploymentOptions.groovy @@ -36,11 +36,22 @@ class RolloutOpenShiftDeploymentOptions extends Options { * referenced by `chartDir` exists. */ String helmReleaseName + /** + * Key/value pairs to pass as values. Only relevant if the directory + * referenced by `chartDir` exists. + * + * See also `helm --set`. Be aware that the resulting data type may vary depending on the input. + */ + Map helmValues + /** * Key/value pairs to pass as values (by default, the key `imageTag` is set * to the config option `imageTag`). Only relevant if the directory - * referenced by `chartDir` exists. */ - Map helmValues + * referenced by `chartDir` exists. + * + * See also `helm --set-string`. + */ + Map helmStringValues /** * List of paths to values files (empty by default). Only relevant if the diff --git a/src/org/ods/component/RolloutOpenShiftDeploymentStage.groovy b/src/org/ods/component/RolloutOpenShiftDeploymentStage.groovy index 06e373281..2655e5f6f 100644 --- a/src/org/ods/component/RolloutOpenShiftDeploymentStage.groovy +++ b/src/org/ods/component/RolloutOpenShiftDeploymentStage.groovy @@ -50,6 +50,9 @@ class RolloutOpenShiftDeploymentStage extends Stage { if (!config.containsKey('helmValues')) { config.helmValues = [:] } + if (!config.containsKey('helmStringValues')) { + config.helmStringValues = [:] + } if (!config.containsKey('helmValuesFiles')) { config.helmValuesFiles = [ 'values.yaml' ] } diff --git a/src/org/ods/orchestration/phases/DeployOdsComponent.groovy b/src/org/ods/orchestration/phases/DeployOdsComponent.groovy index 260128866..1c0aaca68 100644 --- a/src/org/ods/orchestration/phases/DeployOdsComponent.groovy +++ b/src/org/ods/orchestration/phases/DeployOdsComponent.groovy @@ -224,6 +224,7 @@ class DeployOdsComponent { deploymentMean.helmReleaseName, helmValuesFiles, helmMergedValues, + helmMergedStringValues, deploymentMean.helmDefaultFlags, deploymentMean.helmAdditionalFlags, true) diff --git a/src/org/ods/services/OpenShiftService.groovy b/src/org/ods/services/OpenShiftService.groovy index f88881572..d2207fed6 100644 --- a/src/org/ods/services/OpenShiftService.groovy +++ b/src/org/ods/services/OpenShiftService.groovy @@ -124,6 +124,7 @@ class OpenShiftService { String release, List valuesFiles, Map values, + Map stringValues, List defaultFlags, List additionalFlags, boolean withDiff) { @@ -131,6 +132,7 @@ class OpenShiftService { additionalFlags.collect { upgradeFlags << it } valuesFiles.collect { upgradeFlags << "-f ${it}".toString() } values.collect { k, v -> upgradeFlags << "--set ${k}=${v}".toString() } + stringValues.collect { k, v -> upgradeFlags << "--set-string ${k}=${v}".toString() } if (withDiff) { def diffFlags = upgradeFlags.findAll { it } diffFlags << '--no-color' diff --git a/test/groovy/org/ods/component/HelmDeploymentStrategySpec.groovy b/test/groovy/org/ods/component/HelmDeploymentStrategySpec.groovy index 81edfd3b5..bb7cacf1e 100644 --- a/test/groovy/org/ods/component/HelmDeploymentStrategySpec.groovy +++ b/test/groovy/org/ods/component/HelmDeploymentStrategySpec.groovy @@ -41,6 +41,7 @@ class HelmDeploymentStrategySpec extends PipelineSpockTestBase { "helmEnvBasedValuesFiles": [], "helmValuesFiles": ["values.yaml"], "helmValues": [:], + "helmStringValues": [:], "helmDefaultFlags": ["--install", "--atomic"], "helmAdditionalFlags": [] ], diff --git a/test/groovy/org/ods/services/OpenShiftServiceSpec.groovy b/test/groovy/org/ods/services/OpenShiftServiceSpec.groovy index efbabf285..2c5ef38b2 100644 --- a/test/groovy/org/ods/services/OpenShiftServiceSpec.groovy +++ b/test/groovy/org/ods/services/OpenShiftServiceSpec.groovy @@ -270,6 +270,7 @@ class OpenShiftServiceSpec extends SpecHelper { 'foo', 'bar', ['values.yml', 'values-dev.yml'], + [:], [imageTag: '6f8db5fb'], ['--install', '--atomic'], ['--force'], @@ -278,11 +279,11 @@ class OpenShiftServiceSpec extends SpecHelper { then: 1 * steps.sh( - script: 'HELM_DIFF_IGNORE_UNKNOWN_FLAGS=true helm -n foo secrets diff upgrade --install --atomic --force -f values.yml -f values-dev.yml --set imageTag=6f8db5fb --no-color --three-way-merge --normalize-manifests bar ./', + script: 'HELM_DIFF_IGNORE_UNKNOWN_FLAGS=true helm -n foo secrets diff upgrade --install --atomic --force -f values.yml -f values-dev.yml --set-string imageTag=6f8db5fb --no-color --three-way-merge --normalize-manifests bar ./', label: 'Show diff explaining what helm upgrade would change for release bar in foo' ) 1 * steps.sh( - script: 'helm -n foo secrets upgrade --install --atomic --force -f values.yml -f values-dev.yml --set imageTag=6f8db5fb bar ./', + script: 'helm -n foo secrets upgrade --install --atomic --force -f values.yml -f values-dev.yml --set-string imageTag=6f8db5fb bar ./', label: 'Upgrade Helm release bar in foo', returnStatus: true ) diff --git a/test/groovy/vars/OdsComponentStageRolloutOpenShiftDeploymentSpec.groovy b/test/groovy/vars/OdsComponentStageRolloutOpenShiftDeploymentSpec.groovy index 9bffdc955..5dae5f527 100644 --- a/test/groovy/vars/OdsComponentStageRolloutOpenShiftDeploymentSpec.groovy +++ b/test/groovy/vars/OdsComponentStageRolloutOpenShiftDeploymentSpec.groovy @@ -204,7 +204,7 @@ class OdsComponentStageRolloutOpenShiftDeploymentSpec extends PipelineSpockTestB buildArtifacts.size() > 0 buildArtifacts.deployments['bar-deploymentMean']['type'] == 'helm' - 1 * openShiftService.helmUpgrade('foo-dev', 'bar', ['values.yaml'], ['registry':null, 'componentId':'bar', 'global.registry':null, 'global.componentId':'bar', 'imageNamespace':'foo-dev', 'imageTag':'cd3e9082', 'global.imageNamespace':'foo-dev', 'global.imageTag':'cd3e9082'], ['--install', '--atomic'], [], true) + 1 * openShiftService.helmUpgrade('foo-dev', 'bar', ['values.yaml'], [:], ['registry':null, 'componentId':'bar', 'global.registry':null, 'global.componentId':'bar', 'imageNamespace':'foo-dev', 'imageTag':'cd3e9082', 'global.imageNamespace':'foo-dev', 'global.imageTag':'cd3e9082'], ['--install', '--atomic'], [], true) } @Unroll