Skip to content

Commit f8a9a61

Browse files
Saas 7447 - fix migration (#496)
1 parent e4939d3 commit f8a9a61

File tree

4 files changed

+49
-44
lines changed

4 files changed

+49
-44
lines changed

lib/interface/cli/commands/agent/install.cmd.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ const installAgentCmd = new Command({
8484
} = argv;
8585
const {
8686
'runtime-name': reName,
87+
'skip-re-creation': skipRuntimeCreation,
8788
'kube-node-selector': kubeNodeSelector,
89+
'build-node-selector': buildNodeSelector,
8890
'dry-run': dryRun,
8991
'in-cluster': inCluster,
9092
'kubernetes-runner-type': kubernetesRunnerType,
@@ -182,13 +184,15 @@ const installAgentCmd = new Command({
182184
if (installRuntime) {
183185
return installRuntimeCmd.handler({
184186
'runtime-name': reName,
187+
'skip-re-creation': skipRuntimeCreation,
185188
'runtime-kube-context-name': kubeContextName,
186189
'runtime-kube-namespace': kubeNamespace,
187190
'agent-name': name,
188191
'runtime-kube-config-path': kubeConfigPath,
189192
'attach-runtime': true,
190193
'restart-agent': true,
191194
'make-default-runtime': shouldMakeDefaultRe,
195+
'kube-node-selector': buildNodeSelector,
192196
'storage-class-name': storageClassName,
193197
'set-value': setValue,
194198
'set-file': setFile,

lib/interface/cli/commands/hybrid/migration.js

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const _ = require('lodash');
22
const { to } = require('./../../../../logic/cli-config/errors/awaitTo');
33
const { sdk } = require('../../../../logic');
44
const installAgent = require('../agent/install.cmd');
5-
const attachRuntime = require('../runtimeEnvironments/attach.cmd');
65
const installMonitoring = require('../monitor/install.cmd');
76
const colors = require('colors');
87
const 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');

lib/interface/cli/commands/runtimeEnvironments/install.cmd.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ const installRuntimeCmd = new Command({
119119
'storage-class-name': storageClassName,
120120
'agent-name': agentName,
121121
'runtime-name': reName,
122+
'skip-re-creation': skipRuntimeCreation,
122123
'dry-run': dryRun,
123124
'in-cluster': inCluster,
124125
'kube-node-selector': kubeNodeSelector,
@@ -176,23 +177,25 @@ const installRuntimeCmd = new Command({
176177
}
177178

178179
// create RE in codefresh
179-
await sdk.cluster.create({
180-
namespace: kubeNamespace,
181-
storageClassName: storageClassName || `${defaultStorageClassPrefix}-${kubeNamespace}`,
182-
runnerType: kubernetesRunnerType,
183-
nodeSelector: kubeNodeSelectorObj,
184-
annotations: buildAnnotations,
185-
clusterName,
186-
runtimeEnvironmentName: runtimeName,
187-
agent: true,
188-
});
189-
console.log(`Runtime environment "${colors.cyan(runtimeName)}" has been created`);
190-
if (shouldMakeDefaultRe) {
191-
const re = await sdk.runtimeEnvs.get({
192-
name: runtimeName,
180+
if (!skipRuntimeCreation) {
181+
await sdk.cluster.create({
182+
namespace: kubeNamespace,
183+
storageClassName: storageClassName || `${defaultStorageClassPrefix}-${kubeNamespace}`,
184+
runnerType: kubernetesRunnerType,
185+
nodeSelector: kubeNodeSelectorObj,
186+
annotations: buildAnnotations,
187+
clusterName,
188+
runtimeEnvironmentName: runtimeName,
189+
agent: true,
193190
});
194-
await sdk.runtimeEnvs.setDefault({ account: re.accountId, name: re.metadata.name });
195-
console.log(`Runtime environment "${colors.cyan(runtimeName)}" has been set as the default runtime`);
191+
console.log(`Runtime environment "${colors.cyan(runtimeName)}" has been created`);
192+
if (shouldMakeDefaultRe) {
193+
const re = await sdk.runtimeEnvs.get({
194+
name: runtimeName,
195+
});
196+
await sdk.runtimeEnvs.setDefault({ account: re.accountId, name: re.metadata.name });
197+
console.log(`Runtime environment "${colors.cyan(runtimeName)}" has been set as the default runtime`);
198+
}
196199
}
197200

198201
// check if cluster already exists
@@ -223,7 +226,6 @@ const installRuntimeCmd = new Command({
223226
}
224227

225228
// install RE on cluster
226-
227229
const runtimeEvents = new ProgressEvents();
228230
const runtimeFormat = 'downloading runtime installer [{bar}] {percentage}% | {value}/{total}';
229231
const runtimmrProgressBar = new cliProgress.SingleBar({ stopOnComplete: true, format: runtimeFormat }, cliProgress.Presets.shades_classic);
@@ -256,7 +258,7 @@ const installRuntimeCmd = new Command({
256258
setFile,
257259
terminateProcess: !attachRuntime,
258260
events: runtimeEvents,
259-
storageClassName,
261+
storageClassName: storageClassName && storageClassName.startsWith('dind-local-volumes') ? undefined : storageClassName,
260262
logFormatting: DefaultLogFormatter,
261263
});
262264
// attach RE to agent in codefresh

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.68.4",
3+
"version": "0.68.5",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)