From 452ca9348db8ca71999e30caa9aea152fb682f22 Mon Sep 17 00:00:00 2001 From: Oleksandr Andriienko Date: Tue, 20 Jul 2021 09:02:21 +0300 Subject: [PATCH] chore: Use new templates locations. (#1248) * chore: Use new templates locations after moving to a new operator-sdk v1.7.1 Signed-off-by: Oleksandr Andriienko --- .vscode/launch.json | 6 ++++ package.json | 5 +-- prepare-che-operator-templates.js | 55 +++++++++++++++++++++++++++++++ yarn.lock | 6 ++-- 4 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 prepare-che-operator-templates.js diff --git a/.vscode/launch.json b/.vscode/launch.json index 0a984d4b5..b2e6d8b50 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -59,6 +59,12 @@ "program": "${workspaceFolder}/node_modules/jest/bin/jest", } }, + { + "type": "node", + "request": "launch", + "name": "Debug prepare-che-operator.js script", + "program": "${workspaceFolder}/prepare-che-operator-templates.js" + }, ] } diff --git a/package.json b/package.json index 9f7837083..226741168 100644 --- a/package.json +++ b/package.json @@ -97,7 +97,8 @@ "/lib", "/installers", "/npm-shrinkwrap.json", - "/oclif.manifest.json" + "/oclif.manifest.json", + "/prepare-che-operator-templates.js" ], "homepage": "https://github.com/che-incubator/chectl", "keywords": [ @@ -155,7 +156,7 @@ "postinstall-helm": "rimraf templates/kubernetes && cpx 'node_modules/eclipse-che-server/deploy/kubernetes/**' 'templates/kubernetes'", "postinstall-cert-manager": "rimraf templates/cert-manager && cpx 'node_modules/eclipse-che-server/deploy/cert-manager/**' 'templates/cert-manager'", "postinstall-dev-workspace": "rimraf templates/devworkspace && cpx 'node_modules/eclipse-che-devfile-workspace-operator/deploy/**' 'templates/devworkspace'", - "postinstall-operator": "rimraf templates/che-operator && cpx 'node_modules/eclipse-che-operator/deploy/**' 'templates/che-operator'", + "postinstall-operator": "node prepare-che-operator-templates.js", "postinstall-repositories": "yarn upgrade eclipse-che-server eclipse-che-operator eclipse-che-devfile-workspace-operator", "postinstall-cleanup": "rimraf node_modules/eclipse-che-server && rimraf node_modules/eclipse-che-operator", "test": "jest --collect-coverage", diff --git a/prepare-che-operator-templates.js b/prepare-che-operator-templates.js new file mode 100644 index 000000000..2ebfbb31b --- /dev/null +++ b/prepare-che-operator-templates.js @@ -0,0 +1,55 @@ +/********************************************************************* + * Copyright (c) 2021 Red Hat, Inc. + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + **********************************************************************/ + +'use strict' + +const fs = require('fs-extra') +const path = require('path') +var deployFolder = path.join(__dirname, 'node_modules', 'eclipse-che-operator', 'deploy') +var configFolder = path.join(__dirname, 'node_modules', 'eclipse-che-operator', 'config') +var cheOperatorTemplates = path.join(__dirname, 'templates', 'che-operator') + +function prepareTemplates() { + if (fs.existsSync(deployFolder)) { + fs.copySync(deployFolder, cheOperatorTemplates) + } else if (fs.existsSync(configFolder)) { + const filterFunc = (src) => { + var isFile = fs.statSync(src).isFile() + if (isFile) { + var filePath = path.basename(src) + if (filePath === 'role.yaml' || + filePath === 'role_binding.yaml' || + filePath === 'cluster_role.yaml' || + filePath === 'cluster_rolebinding.yaml' || + filePath === 'service_account.yaml') { + return true + } + } else { + var dirName = path.basename(src) + if (dirName === 'rbac') { + return true + } + } + } + + fs.copySync(path.join(configFolder, 'rbac'), cheOperatorTemplates, filterFunc) + fs.copySync(path.join(configFolder, 'manager', 'manager.yaml'), path.join(cheOperatorTemplates, 'operator.yaml')) + fs.copySync(path.join(configFolder, 'crd', 'bases'), path.join(cheOperatorTemplates, 'crds')) + fs.copySync(path.join(configFolder, 'samples', 'org.eclipse.che_v1_checluster.yaml'), path.join(cheOperatorTemplates, 'crds', 'org_v1_che_cr.yaml')) + fs.copySync(path.join(configFolder, 'samples', 'org_v1_chebackupserverconfiguration.yaml'), path.join(cheOperatorTemplates, 'crds', 'org.eclipse.che_v1_chebackupserverconfiguration_cr.yaml')) + fs.copySync(path.join(configFolder, 'samples', 'org_v1_checlusterbackup.yaml'), path.join(cheOperatorTemplates, 'crds', 'org.eclipse.che_v1_checlusterbackup_cr.yaml')) + fs.copySync(path.join(configFolder, 'samples', 'org_v1_checlusterrestore.yaml'), path.join(cheOperatorTemplates, 'crds', 'org.eclipse.che_v1_checlusterrestore_cr.yaml')) + } else { + throw new Error("Unable to prepare che-operator templates") + } +} + +fs.removeSync(cheOperatorTemplates) +prepareTemplates() diff --git a/yarn.lock b/yarn.lock index 5374441d6..b9df40faf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2611,15 +2611,15 @@ ecc-jsbn@~0.1.1: "eclipse-che-devfile-workspace-operator@git://github.com/devfile/devworkspace-operator#main": version "0.0.0" - resolved "git://github.com/devfile/devworkspace-operator#fdc3ad4b732c88182539e708a77a639e00a8647e" + resolved "git://github.com/devfile/devworkspace-operator#ecec8b97c0ce749e1aa2ec89793cf7d862ab0f77" "eclipse-che-operator@git://github.com/eclipse-che/che-operator#main": version "0.0.0" - resolved "git://github.com/eclipse-che/che-operator#e29484fd4579bebee1acfa34b0696b73d357c85e" + resolved "git://github.com/eclipse-che/che-operator#f555494a7d5764cbed3e057b5bc092d411970610" "eclipse-che-server@git://github.com/eclipse-che/che-server#main": version "0.0.0" - resolved "git://github.com/eclipse-che/che-server#7fbc22bb6cb5a739b91328c70dc463aa5061c8ed" + resolved "git://github.com/eclipse-che/che-server#94353639e46fa2cb3139a3651706282b8a702e7e" editorconfig@^0.15.0: version "0.15.3"