From 02801375e3da21567ea6058aedb6151f8f53a5ca Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Thu, 13 Feb 2020 17:30:02 +0200 Subject: [PATCH 1/3] 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 +++++- yarn.lock | 2 +- 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 32743da39..82b282223 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=che-operator-cr-patch + Path to a yaml file that overrides the default value a CheCluster 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..19aea3775 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']) + 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 f31cfc904..14f057f78 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': string({ + description: 'Path to a yaml file that overrides the default value a CheCluster 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 { diff --git a/yarn.lock b/yarn.lock index 71816df10..6300551f3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1680,7 +1680,7 @@ ecc-jsbn@~0.1.1: "eclipse-che@git://github.com/eclipse/che#master": version "0.0.0" - resolved "git://github.com/eclipse/che#980379f3865dc339fd22c8aeaa8785c70012fd37" + resolved "git://github.com/eclipse/che#ad91e77d13bb9861cd1a3ece70f00f6f3b395ac1" editorconfig@^0.15.0: version "0.15.3" From aefd0cb9e06babba574b27e7ff6d852fbb7471f2 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Fri, 14 Feb 2020 09:06:08 +0200 Subject: [PATCH 2/3] Fix Signed-off-by: Anatoliy Bazko --- README.md | 2 +- src/api/kube.ts | 2 +- src/commands/server/start.ts | 4 ++-- yarn.lock | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 82b282223..ade3013cc 100644 --- a/README.md +++ b/README.md @@ -279,7 +279,7 @@ OPTIONS -t, --templates=templates [default: templates] Path to the templates folder - --che-operator-cr-patch=che-operator-cr-patch + --che-operator-cr-patch-yaml=che-operator-cr-patch-yaml Path to a yaml file that overrides the default value a CheCluster used by the operator. This parameter is used only when the installer is the operator. diff --git a/src/api/kube.ts b/src/api/kube.ts index 19aea3775..b9e41aab3 100644 --- a/src/api/kube.ts +++ b/src/api/kube.ts @@ -950,7 +950,7 @@ 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']) + yamlCr = this.overrideDefaultValues(yamlCr, flags['che-operator-cr-patch-yaml']) const cheNamespace = flags.chenamespace if (useDefaultCR) { diff --git a/src/commands/server/start.ts b/src/commands/server/start.ts index 14f057f78..413d4a236 100644 --- a/src/commands/server/start.ts +++ b/src/commands/server/start.ts @@ -114,8 +114,8 @@ 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': string({ - description: 'Path to a yaml file that overrides the default value a CheCluster used by the operator. This parameter is used only when the installer is the operator.', + '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({ diff --git a/yarn.lock b/yarn.lock index 6300551f3..3e802059f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1680,7 +1680,7 @@ ecc-jsbn@~0.1.1: "eclipse-che@git://github.com/eclipse/che#master": version "0.0.0" - resolved "git://github.com/eclipse/che#ad91e77d13bb9861cd1a3ece70f00f6f3b395ac1" + resolved "git://github.com/eclipse/che#06b84a6f06059d56fc90a711777d2745acd7f1c6" editorconfig@^0.15.0: version "0.15.3" From f369ae8f5ba89e1e4dcfe35aae356e8943597a12 Mon Sep 17 00:00:00 2001 From: Anatoliy Bazko Date: Fri, 14 Feb 2020 09:17:07 +0200 Subject: [PATCH 3/3] Fix Signed-off-by: Anatoliy Bazko --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ade3013cc..7626a4d3a 100644 --- a/README.md +++ b/README.md @@ -280,8 +280,8 @@ OPTIONS [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 value a CheCluster used by the operator. This parameter is used only - when the installer is the operator. + 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