From a15296f2b1fd274a95e3252457415aa75ae3dc8f Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Fri, 14 Feb 2020 09:40:37 +0200 Subject: [PATCH] feat: Allows to override default values (#508) * Allows to override default values Signed-off-by: Anatoliy Bazko --- README.md | 4 ++++ package.json | 1 + src/api/kube.ts | 14 +++++++++++++- src/commands/server/start.ts | 6 +++++- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 32743da39..7626a4d3a 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/package.json b/package.json index eac893f26..cc6220b61 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/api/kube.ts b/src/api/kube.ts index b175981f9..b9e41aab3 100644 --- a/src/api/kube.ts +++ b/src/api/kube.ts @@ -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' @@ -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 @@ -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 { const customObjectsApi = this.kc.makeApiClient(CustomObjectsApi) try { diff --git a/src/commands/server/start.ts b/src/commands/server/start.ts index caa10de12..67fecda86 100644 --- a/src/commands/server/start.ts +++ b/src/commands/server/start.ts @@ -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', @@ -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 {