forked from redhat-developer/devspaces-chectl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare-devspaces-operator-templates.js
98 lines (91 loc) · 4.53 KB
/
prepare-devspaces-operator-templates.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*********************************************************************
* Copyright (c) 2019-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')
const deployFolder = path.join(__dirname, 'node_modules', 'devspaces-operator', 'devspaces-operator', 'deploy/deployment');
const configFolder = path.join(__dirname, 'node_modules', 'devspaces-operator', 'devspaces-operator', 'config');
const cheOperatorTemplates = path.join(__dirname, 'templates', 'devspaces-operator');
function prepareTemplates() {
if (fs.existsSync(deployFolder)) {
for (const platform in ['kubernetes', 'openshift']) {
fs.copySync(
path.join(deployFolder, platform, 'org_v2_checluster.yaml'),
path.join(cheOperatorTemplates, platform, 'crds', 'org_checluster_cr.yaml'))
fs.copySync(
path.join(deployFolder, platform, 'objects', 'checlusters.org.eclipse.che.CustomResourceDefinition.yaml'),
path.join(cheOperatorTemplates, platform, 'crds', 'org.eclipse.che_checlusters.yaml'))
fs.copySync(
path.join(deployFolder, platform, 'objects', 'devspaces-operator.Deployment.yaml'),
path.join(cheOperatorTemplates, 'platform,operator.yaml'))
fs.copySync(
path.join(deployFolder, platform, 'objects', 'devspaces-operator.ServiceAccount.yaml'),
path.join(cheOperatorTemplates, platform, 'service_account.yaml'))
fs.copySync(
path.join(deployFolder, platform, 'objects', 'devspaces-operator.ClusterRoleBinding.yaml'),
path.join(cheOperatorTemplates, platform, 'cluster_rolebinding.yaml'))
fs.copySync(
path.join(deployFolder, platform, 'objects', 'devspaces-operator.ClusterRole.yaml'),
path.join(cheOperatorTemplates, platform, 'cluster_role.yaml'))
fs.copySync(
path.join(deployFolder, platform, 'objects', 'devspaces-operator.RoleBinding.yaml'),
path.join(cheOperatorTemplates, platform, 'role_binding.yaml'))
fs.copySync(
path.join(deployFolder, platform, 'objects', 'devspaces-operator.Role.yaml'),
path.join(cheOperatorTemplates, platform, 'role.yaml'))
fs.copySync(
path.join(deployFolder, platform, 'objects', 'devspaces-operator-serving-cert.Certificate.yaml'),
path.join(cheOperatorTemplates, platform, 'serving-cert.yaml'))
fs.copySync(
path.join(deployFolder, platform, 'objects', 'selfsigned-issuer.Issuer.yaml'),
path.join(cheOperatorTemplates, platform, 'selfsigned-issuer.yaml'))
fs.copySync(
path.join(deployFolder, platform, 'objects', 'webhook-service.Service.yaml'),
path.join(cheOperatorTemplates, platform, 'webhook-service.yaml'))
fs.copySync(
path.join(deployFolder, platform, 'objects', 'manager-config.ConfigMap.yaml'),
path.join(cheOperatorTemplates, platform, 'manager-config.yaml'))
}
} else if (fs.existsSync(configFolder)) {
const filterFunc = (src) => {
const isFile = fs.statSync(src).isFile();
if (isFile) {
const 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 {
const 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'))
// CheCluster API v2
let cheClusterCR = path.join(configFolder, 'samples', 'org_v2_checluster.yaml')
if (!fs.existsSync(cheClusterCR)) {
// CheCluster API v1
cheClusterCR = path.join(configFolder, 'samples', 'org.eclipse.che_v1_checluster.yaml')
}
// Common file name for both versions
fs.copySync(cheClusterCR, path.join(cheOperatorTemplates, 'crds', 'org_checluster_cr.yaml'))
} else {
throw new Error("Unable to prepare devspaces-operator templates")
}
}
fs.removeSync(cheOperatorTemplates)
prepareTemplates()