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

fix: Use -f with yaml of helm patch #1026

Merged
merged 2 commits into from
Dec 14, 2020
Merged
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
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}`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should patchFlags be at the very end ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usage:
  helm upgrade [RELEASE] [CHART] [flags]

flags can be set at the end, or before (like chectl is doing). Both will work. In this case ${destDir} is the CHART parameter. If you want to follow helm's documented usage, you will need to shuffle more than that parameter.


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
}

}