Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add helmStringValues support #1180

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,22 @@ _String_
referenced by `chartDir` exists.


| *helmValues* +
| *helmStringValues* +
_Map<String,&nbsp;String>_
|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<String,&nbsp;String>_
|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<String>_
Expand Down
22 changes: 16 additions & 6 deletions src/org/ods/component/HelmDeploymentStrategy.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}
Expand Down Expand Up @@ -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 = []
Expand All @@ -153,6 +161,7 @@ class HelmDeploymentStrategy extends AbstractDeploymentStrategy {
options.helmReleaseName,
mergedHelmValuesFiles,
mergedHelmValues,
mergedHelmStringValues,
options.helmDefaultFlags,
options.helmAdditionalFlags,
options.helmDiff
Expand Down Expand Up @@ -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,
])
Expand Down
15 changes: 13 additions & 2 deletions src/org/ods/component/RolloutOpenShiftDeploymentOptions.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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<String, String> helmValues
* referenced by `chartDir` exists.
*
* See also `helm --set-string`.
*/
Map<String, String> helmStringValues

/**
* List of paths to values files (empty by default). Only relevant if the
Expand Down
3 changes: 3 additions & 0 deletions src/org/ods/component/RolloutOpenShiftDeploymentStage.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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' ]
}
Expand Down
1 change: 1 addition & 0 deletions src/org/ods/orchestration/phases/DeployOdsComponent.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ class DeployOdsComponent {
deploymentMean.helmReleaseName,
helmValuesFiles,
helmMergedValues,
helmMergedStringValues,
deploymentMean.helmDefaultFlags,
deploymentMean.helmAdditionalFlags,
true)
Expand Down
2 changes: 2 additions & 0 deletions src/org/ods/services/OpenShiftService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,15 @@ class OpenShiftService {
String release,
List<String> valuesFiles,
Map<String, String> values,
Map<String, String> stringValues,
List<String> defaultFlags,
List<String> additionalFlags,
boolean withDiff) {
def upgradeFlags = defaultFlags.collect { it }
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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class HelmDeploymentStrategySpec extends PipelineSpockTestBase {
"helmEnvBasedValuesFiles": [],
"helmValuesFiles": ["values.yaml"],
"helmValues": [:],
"helmStringValues": [:],
"helmDefaultFlags": ["--install", "--atomic"],
"helmAdditionalFlags": []
],
Expand Down
5 changes: 3 additions & 2 deletions test/groovy/org/ods/services/OpenShiftServiceSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ class OpenShiftServiceSpec extends SpecHelper {
'foo',
'bar',
['values.yml', 'values-dev.yml'],
[:],
[imageTag: '6f8db5fb'],
['--install', '--atomic'],
['--force'],
Expand All @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down