Skip to content

Commit

Permalink
fix: Use -f with yaml of helm patch (#1026)
Browse files Browse the repository at this point in the history
Use -f with yaml of helm patch

Signed-off-by: Mykola Morhun <mmorhun@redhat.com>
  • Loading branch information
mmorhun authored Dec 14, 2020
1 parent fa906ce commit 7c0af18
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 34 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,9 @@ OPTIONS
The URL of the external Devfile registry.
--helm-patch-yaml=helm-patch-yaml
Path to yaml file with Helm Chart values patch. The file format is identical to values.yaml from the chart.
Path to yaml file with Helm Chart values patch.
The file format is identical to values.yaml from the chart.
Note, Provided command line arguments take precedence over patch file.
--k8spoddownloadimagetimeout=k8spoddownloadimagetimeout
[default: 600000] Waiting time for Pod downloading image (in milliseconds)
Expand Down
4 changes: 3 additions & 1 deletion src/commands/server/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ export default class Deploy extends Command {
[CHE_OPERATOR_CR_YAML_KEY]: cheOperatorCRYaml,
[CHE_OPERATOR_CR_PATCH_YAML_KEY]: cheOperatorCRPatchYaml,
'helm-patch-yaml': string({
description: 'Path to yaml file with Helm Chart values patch. The file format is identical to values.yaml from the chart.',
description: `Path to yaml file with Helm Chart values patch.
The file format is identical to values.yaml from the chart.
Note, Provided command line arguments take precedence over patch file.`,
default: '',
}),
'workspace-pvc-storage-class-name': string({
Expand Down
34 changes: 2 additions & 32 deletions src/tasks/installers/helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,18 +348,9 @@ error: E_COMMAND_FAILED`)
setOptions.push(`--set cheImage=${cheImage}`)
setOptions.push(`--set che.disableProbes=${flags.debug}`)

if (flags['helm-patch-yaml']) {
// Read patch yaml. Has format the same as values.yaml
const patchTree: { [key: string]: any } = await this.kubeHelper.safeLoadFromYamlFile(flags['helm-patch-yaml'])
// Flat the yaml tree into key-value format
const patchProperties = this.prepareYamlPatch(patchTree)
// Add patch properties to the command
for (const property of patchProperties) {
setOptions.push(`--set ${property}`)
}
}
const patchFlags = flags['helm-patch-yaml'] ? '-f ' + flags['helm-patch-yaml'] : ''

let command = `helm upgrade --install che --force --namespace ${flags.chenamespace} ${setOptions.join(' ')} ${multiUserFlag} ${tlsFlag} ${destDir}`
let command = `helm upgrade --install che --force --namespace ${flags.chenamespace} ${setOptions.join(' ')} ${multiUserFlag} ${tlsFlag} ${patchFlags} ${destDir}`

let { exitCode, stderr } = await execa(command, { timeout: execTimeout, reject: false, shell: true })
// if process failed, check the following
Expand Down Expand Up @@ -389,25 +380,4 @@ error: E_COMMAND_FAILED`)
}
}

/**
* Returns flaten key=value structure of the given object.
* Nested object keys are separated by dot.
* @param patchTree object with properties and nested objects
*/
private prepareYamlPatch(patchTree: { [key: string]: any }): string[] {
const patches: string[] = []
for (const key of Object.keys(patchTree)) {
const value = patchTree[key]
if (typeof value !== 'object') {
patches.push(`${key}=${value}`)
} else {
const subProperties = this.prepareYamlPatch(value)
for (const subProperty of subProperties) {
patches.push(`${key}.${subProperty}`)
}
}
}
return patches
}

}

0 comments on commit 7c0af18

Please sign in to comment.