@@ -2,7 +2,6 @@ const _ = require('lodash');
22const { to } = require ( './../../../../logic/cli-config/errors/awaitTo' ) ;
33const { sdk } = require ( '../../../../logic' ) ;
44const installAgent = require ( '../agent/install.cmd' ) ;
5- const attachRuntime = require ( '../runtimeEnvironments/attach.cmd' ) ;
65const installMonitoring = require ( '../monitor/install.cmd' ) ;
76const colors = require ( 'colors' ) ;
87const inquirer = require ( 'inquirer' ) ;
@@ -61,6 +60,10 @@ async function migrate({
6160 agents,
6261} ) {
6362 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' ) ;
6467
6568 // prompt migration process confirmation
6669 console . log ( `${ colors . red ( 'This migration process will do the following:' ) } ` ) ;
@@ -81,7 +84,15 @@ async function migrate({
8184 process . exit ( 1 ) ;
8285 }
8386
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
8596 console . log ( `Running migration script on runtime: ${ colors . cyan ( runtimeName ) } ` ) ;
8697 const [ migrateScriptErr , migrateScriptExitCode ] = await to ( sdk . agents . migrate ( {
8798 kubeContextName,
@@ -113,43 +124,31 @@ async function migrate({
113124 oldConfig . nodeSelector = `${ key } =${ oldConfig . nodeSelector [ key ] } ` ;
114125 }
115126
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 ) } ` ) ;
118129 const agentInstallOptions = {
119130 name : newAgentName ,
120131 'kube-context-name' : kubeContextName ,
121132 'kube-node-selector' : oldConfig . nodeSelector ,
133+ 'build-node-selector' : oldNodeSelector ,
122134 'kube-namespace' : kubeNamespace ,
135+ 'agent-kube-namespace' : kubeNamespace ,
136+ 'agent-kube-context-name' : kubeContextName ,
137+ 'agent-kube-config-path' : kubeConfigPath ,
123138 tolerations : JSON . stringify ( oldConfig . tolerations ) ,
124139 'kube-config-path' : kubeConfigPath ,
125- 'install-runtime' : false ,
140+ 'install-runtime' : true ,
141+ 'runtime-name' : runtimeName ,
142+ 'skip-re-creation' : true ,
126143 verbose,
127144 'make-default-runtime' : shouldMakeDefaultRe ,
128- 'storage-class-name' : storageClassName ,
145+ 'storage-class-name' : storageClassName || oldStorageClassName ,
129146 terminateProcess : false ,
130147 'set-value' : setValue ,
131148 'set-file' : setFile ,
132149 } ;
133150 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' ) ;
153152
154153 // Install new monitoring components
155154 console . log ( 'Installing monitoring components' ) ;
0 commit comments