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..304ee21bf 100644 --- a/package.json +++ b/package.json @@ -155,7 +155,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()