Skip to content

Commit

Permalink
feat: Allows to override default values (#508)
Browse files Browse the repository at this point in the history
* Allows to override default values

Signed-off-by: Anatoliy Bazko <abazko@redhat.com>
  • Loading branch information
tolusha committed Feb 14, 2020
1 parent f66fd35 commit a15296f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ OPTIONS
-t, --templates=templates
[default: templates] Path to the templates folder
--che-operator-cr-patch-yaml=che-operator-cr-patch-yaml
Path to a yaml file that overrides the default values in CheCluster CR used by the operator. This parameter is used
only when the installer is the operator.
--che-operator-cr-yaml=che-operator-cr-yaml
Path to a yaml file that defines a CheCluster used by the operator. This parameter is used only when the installer
is the operator.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"fs-extra": "^8.1.0",
"listr": "^0.14.3",
"listr-verbose-renderer": "^0.6.0",
"lodash": "^4.17.13",
"mkdirp": "^0.5.1",
"node-notifier": "^6.0.0",
"tslib": "^1"
Expand Down
14 changes: 13 additions & 1 deletion src/api/kube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { cli } from 'cli-ux'
import * as fs from 'fs'
import https = require('https')
import * as yaml from 'js-yaml'
import { merge } from 'lodash'
import * as net from 'net'
import { Writable } from 'stream'

Expand Down Expand Up @@ -949,9 +950,11 @@ export class KubeHelper {

async createCheClusterFromFile(filePath: string, flags: any, useDefaultCR: boolean) {
let yamlCr = this.safeLoadFromYamlFile(filePath)
yamlCr = this.overrideDefaultValues(yamlCr, flags['che-operator-cr-patch-yaml'])

const cheNamespace = flags.chenamespace
if (useDefaultCR) {
// If we don't use an explicitely provided CheCluster CR,
// If we don't use an explicitly provided CheCluster CR,
// then let's modify the default example CR with values
// derived from the other parameters
const cheImage = flags.cheimage
Expand Down Expand Up @@ -1001,6 +1004,15 @@ export class KubeHelper {
}
}

overrideDefaultValues(yamlCr: any, filePath: string): any {
if (filePath) {
const patchCr = this.safeLoadFromYamlFile(filePath)
return merge(yamlCr, patchCr)
} else {
return yamlCr
}
}

async cheClusterExist(name = '', namespace = ''): Promise<boolean> {
const customObjectsApi = this.kc.makeApiClient(CustomObjectsApi)
try {
Expand Down
6 changes: 5 additions & 1 deletion src/commands/server/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ export default class Start extends Command {
description: 'Path to a yaml file that defines a CheCluster used by the operator. This parameter is used only when the installer is the operator.',
default: ''
}),
'che-operator-cr-patch-yaml': string({
description: 'Path to a yaml file that overrides the default values in CheCluster CR used by the operator. This parameter is used only when the installer is the operator.',
default: ''
}),
directory: string({
char: 'd',
description: 'Directory to store logs into',
Expand All @@ -131,7 +135,7 @@ export default class Start extends Command {
'skip-version-check': flags.boolean({
description: 'Skip minimal versions check.',
default: false
}),
})
}

static getTemplatesDir(): string {
Expand Down

0 comments on commit a15296f

Please sign in to comment.