@@ -6,6 +6,9 @@ const installRoot = require('../root/install.cmd');
6
6
const { getKubeContext } = require ( '../../helpers/kubernetes' ) ;
7
7
const ProgressEvents = require ( '../../helpers/progressEvents' ) ;
8
8
const cliProgress = require ( 'cli-progress' ) ;
9
+ const createClusterCmd = require ( '../cluster/create.cmd' ) ;
10
+
11
+ const defaultNamespace = 'codefresh' ;
9
12
10
13
11
14
const _getAgentData = async ( token ) => {
@@ -98,6 +101,9 @@ const installRuntimeCmd = new Command({
98
101
. option ( 'agent-kube-config-path' , {
99
102
describe : 'Path to kubeconfig file for the agent (default is $HOME/.kube/config) (on attach)' ,
100
103
} )
104
+ . option ( 'cluster-service-account' , {
105
+ describe : 'service account for cluster default is default' ,
106
+ } )
101
107
. option ( 'verbose' , {
102
108
describe : 'Print logs' ,
103
109
} ) ,
@@ -106,7 +112,6 @@ const installRuntimeCmd = new Command({
106
112
'storage-class-name' : storageClassName ,
107
113
'agent-name' : agentName ,
108
114
'dry-run' : dryRun ,
109
- 'runtime-kube-namespace' : kubeNamespace ,
110
115
'in-cluster' : inCluster ,
111
116
'kube-node-selector' : kubeNodeSelector ,
112
117
'kubernetes-runner-type' : kubernetesRunnerType ,
@@ -116,25 +121,27 @@ const installRuntimeCmd = new Command({
116
121
verbose,
117
122
'build-annotations' : buildAnnotations ,
118
123
'attach-runtime' : attachRuntime ,
124
+ 'cluster-service-account' : clusterServiceAccount ,
119
125
} = argv ;
120
126
121
127
let {
122
128
'runtime-kube-context-name' : kubeContextName ,
123
129
'agent-kube-context-name' : agentKubeContextName ,
124
130
'agent-kube-namespace' : agentKubeNamespace ,
125
131
'agent-kube-config-path' : agentKubeConfigPath ,
132
+ 'runtime-kube-namespace' : kubeNamespace ,
126
133
token,
127
134
} = argv ;
128
135
129
136
if ( ! kubeNamespace ) {
130
- throw new Error ( 'runtime-kube-namespace is mandatory parameter' ) ;
137
+ kubeNamespace = defaultNamespace ;
131
138
}
132
139
133
140
// parse kubeNodeSelector in form key1=value1,key2=value2 to {key1: value1, key2: value2}
134
- let kubeNodeSelectorObj = { } ;
141
+ const kubeNodeSelectorObj = { } ;
135
142
if ( kubeNodeSelector ) {
136
143
const nsSplitParts = kubeNodeSelector . split ( ',' ) ;
137
- nsSplitParts . forEach ( nsPart => {
144
+ nsSplitParts . forEach ( ( nsPart ) => {
138
145
const nsRecordSplit = nsPart . split ( '=' ) ;
139
146
if ( nsRecordSplit . length !== 2 ) {
140
147
throw new Error ( 'invalid kube-node-selector parameter' ) ;
@@ -166,19 +173,30 @@ const installRuntimeCmd = new Command({
166
173
agent : true ,
167
174
} ) ;
168
175
console . log ( `Runtime envrionment ${ runtimeName } was created` ) ;
176
+
177
+ // create the cluster in codefresh
178
+
179
+ await createClusterCmd . handler ( {
180
+ 'kube-context' : kubeContextName ,
181
+ namespace : kubeNamespace ,
182
+ 'behind-firewall' : true ,
183
+ serviceaccount : clusterServiceAccount || 'default' ,
184
+ terminateProcess : false ,
185
+ } ) ;
169
186
// install RE on cluster
170
187
171
- const events = new ProgressEvents ( ) ;
172
- const format = 'downloading [{bar}] {percentage}% | {value}/{total}' ;
173
- const progressBar = new cliProgress . SingleBar ( { stopOnComplete : true , format } , cliProgress . Presets . shades_classic ) ;
174
- let totalSize ;
175
- events . onStart ( ( size ) => {
176
- progressBar . start ( size , 0 ) ;
177
- totalSize = size ;
188
+ const runtimeEvents = new ProgressEvents ( ) ;
189
+ const runtimeFormat = 'downloading runtime installer [{bar}] {percentage}% | {value}/{total}' ;
190
+ const runtimmrProgressBar = new cliProgress . SingleBar ( { stopOnComplete : true , format : runtimeFormat } , cliProgress . Presets . shades_classic ) ;
191
+ let runtimeTotalSize ;
192
+ runtimeEvents . onStart ( ( size ) => {
193
+ console . log ( 'Downloading runtime\'s installer \n' ) ;
194
+ runtimmrProgressBar . start ( size , 0 ) ;
195
+ runtimeTotalSize = size ;
178
196
} ) ;
179
- events . onProgress ( ( progress ) => {
180
- progressBar . update ( progress ) ;
181
- if ( progress >= totalSize ) {
197
+ runtimeEvents . onProgress ( ( progress ) => {
198
+ runtimmrProgressBar . update ( progress ) ;
199
+ if ( progress >= runtimeTotalSize ) {
182
200
console . log ( '\n' ) ;
183
201
}
184
202
} ) ;
@@ -198,7 +216,7 @@ const installRuntimeCmd = new Command({
198
216
setValue,
199
217
setFile,
200
218
terminateProcess : ! attachRuntime ,
201
- events,
219
+ events : runtimeEvents ,
202
220
} ) ;
203
221
// attach RE to agent in codefresh
204
222
0 commit comments