@@ -2,7 +2,6 @@ const _ = require('lodash');
2
2
const { to } = require ( './../../../../logic/cli-config/errors/awaitTo' ) ;
3
3
const { sdk } = require ( '../../../../logic' ) ;
4
4
const installAgent = require ( '../agent/install.cmd' ) ;
5
- const attachRuntime = require ( '../runtimeEnvironments/attach.cmd' ) ;
6
5
const installMonitoring = require ( '../monitor/install.cmd' ) ;
7
6
const colors = require ( 'colors' ) ;
8
7
const inquirer = require ( 'inquirer' ) ;
@@ -61,6 +60,10 @@ async function migrate({
61
60
agents,
62
61
} ) {
63
62
const newAgentName = agentName || await getNewAgentName ( kubeContextName , kubeNamespace , agents ) ;
63
+ const [ getRuntimeErr , runtime ] = await to ( sdk . runtimeEnvs . get ( { name : runtimeName } ) ) ;
64
+ handleError ( getRuntimeErr , `Failed to get runtime with name "${ runtimeName } "` ) ;
65
+ const oldNodeSelector = _ . get ( runtime , 'runtimeScheduler.cluster.nodeSelector' ) ;
66
+ const oldStorageClassName = _ . get ( runtime , 'dockerDaemonScheduler.pvcs.dind.storageClassName' ) ;
64
67
65
68
// prompt migration process confirmation
66
69
console . log ( `${ colors . red ( 'This migration process will do the following:' ) } ` ) ;
@@ -81,7 +84,15 @@ async function migrate({
81
84
process . exit ( 1 ) ;
82
85
}
83
86
84
- // delete old agent
87
+ // prepare old runtime
88
+ if ( oldStorageClassName && oldStorageClassName . startsWith ( 'dind-local-volumes-venona' ) ) {
89
+ // need to replace to start with 'dind-local-volumes-runner'
90
+ const newRe = _ . set ( runtime , 'dockerDaemonScheduler.pvcs.dind.storageClassName' , oldStorageClassName . replace ( 'venona' , 'runner' ) ) ;
91
+ const [ err ] = await to ( sdk . runtimeEnvs . update ( { name : runtimeName } , newRe ) ) ;
92
+ handleError ( err , 'Failed to update runtime storage class name' ) ;
93
+ }
94
+
95
+ // delete old agent and runtime
85
96
console . log ( `Running migration script on runtime: ${ colors . cyan ( runtimeName ) } ` ) ;
86
97
const [ migrateScriptErr , migrateScriptExitCode ] = await to ( sdk . agents . migrate ( {
87
98
kubeContextName,
@@ -113,43 +124,31 @@ async function migrate({
113
124
oldConfig . nodeSelector = `${ key } =${ oldConfig . nodeSelector [ key ] } ` ;
114
125
}
115
126
116
- // install new agent
117
- console . log ( `Creating new codefresh agent with name: ${ colors . cyan ( newAgentName ) } ` ) ;
127
+ // install new agent and runtime
128
+ console . log ( `Creating new codefresh runner with name: ${ colors . cyan ( newAgentName ) } ` ) ;
118
129
const agentInstallOptions = {
119
130
name : newAgentName ,
120
131
'kube-context-name' : kubeContextName ,
121
132
'kube-node-selector' : oldConfig . nodeSelector ,
133
+ 'build-node-selector' : oldNodeSelector ,
122
134
'kube-namespace' : kubeNamespace ,
135
+ 'agent-kube-namespace' : kubeNamespace ,
136
+ 'agent-kube-context-name' : kubeContextName ,
137
+ 'agent-kube-config-path' : kubeConfigPath ,
123
138
tolerations : JSON . stringify ( oldConfig . tolerations ) ,
124
139
'kube-config-path' : kubeConfigPath ,
125
- 'install-runtime' : false ,
140
+ 'install-runtime' : true ,
141
+ 'runtime-name' : runtimeName ,
142
+ 'skip-re-creation' : true ,
126
143
verbose,
127
144
'make-default-runtime' : shouldMakeDefaultRe ,
128
- 'storage-class-name' : storageClassName ,
145
+ 'storage-class-name' : storageClassName || oldStorageClassName ,
129
146
terminateProcess : false ,
130
147
'set-value' : setValue ,
131
148
'set-file' : setFile ,
132
149
} ;
133
150
const [ agentInstallErr ] = await to ( installAgent . handler ( agentInstallOptions ) ) ;
134
- handleError ( agentInstallErr , 'Failed to install new agent' ) ;
135
-
136
- // attach old runtime to new agent
137
- console . log ( `Attaching runtime: ${ colors . cyan ( runtimeName ) } to agent: ${ colors . cyan ( newAgentName ) } ` ) ;
138
- const [ attachRuntimeErr ] = await to ( attachRuntime . handler ( {
139
- 'agent-name' : newAgentName ,
140
- 'runtime-name' : runtimeName ,
141
- 'runtime-kube-context-name' : kubeContextName ,
142
- 'runtime-kube-namespace' : kubeNamespace ,
143
- 'runtime-kube-serviceaccount' : 'venona' ,
144
- 'runtime-kube-config-path' : kubeConfigPath ,
145
- 'agent-kube-context-name' : kubeContextName ,
146
- 'agent-kube-namespace' : kubeNamespace ,
147
- 'agent-kube-config-path' : kubeConfigPath ,
148
- 'restart-agent' : true ,
149
- terminateProcess : false ,
150
- verbose,
151
- } ) ) ;
152
- handleError ( attachRuntimeErr , 'Failed to attach the old runtime to the new agent' ) ;
151
+ handleError ( agentInstallErr , 'Failed to install new agent and runtime' ) ;
153
152
154
153
// Install new monitoring components
155
154
console . log ( 'Installing monitoring components' ) ;
0 commit comments