diff --git a/lib/interface/cli/commands/agent/install.cmd.js b/lib/interface/cli/commands/agent/install.cmd.js index 96d0cb9b4..d5133141d 100644 --- a/lib/interface/cli/commands/agent/install.cmd.js +++ b/lib/interface/cli/commands/agent/install.cmd.js @@ -84,7 +84,9 @@ const installAgentCmd = new Command({ } = argv; const { 'runtime-name': reName, + 'skip-re-creation': skipRuntimeCreation, 'kube-node-selector': kubeNodeSelector, + 'build-node-selector': buildNodeSelector, 'dry-run': dryRun, 'in-cluster': inCluster, 'kubernetes-runner-type': kubernetesRunnerType, @@ -182,6 +184,7 @@ const installAgentCmd = new Command({ if (installRuntime) { return installRuntimeCmd.handler({ 'runtime-name': reName, + 'skip-re-creation': skipRuntimeCreation, 'runtime-kube-context-name': kubeContextName, 'runtime-kube-namespace': kubeNamespace, 'agent-name': name, @@ -189,6 +192,7 @@ const installAgentCmd = new Command({ 'attach-runtime': true, 'restart-agent': true, 'make-default-runtime': shouldMakeDefaultRe, + 'kube-node-selector': buildNodeSelector, 'storage-class-name': storageClassName, 'set-value': setValue, 'set-file': setFile, diff --git a/lib/interface/cli/commands/hybrid/migration.js b/lib/interface/cli/commands/hybrid/migration.js index 445416ba8..27413650b 100644 --- a/lib/interface/cli/commands/hybrid/migration.js +++ b/lib/interface/cli/commands/hybrid/migration.js @@ -2,7 +2,6 @@ const _ = require('lodash'); const { to } = require('./../../../../logic/cli-config/errors/awaitTo'); const { sdk } = require('../../../../logic'); const installAgent = require('../agent/install.cmd'); -const attachRuntime = require('../runtimeEnvironments/attach.cmd'); const installMonitoring = require('../monitor/install.cmd'); const colors = require('colors'); const inquirer = require('inquirer'); @@ -61,6 +60,10 @@ async function migrate({ agents, }) { const newAgentName = agentName || await getNewAgentName(kubeContextName, kubeNamespace, agents); + const [getRuntimeErr, runtime] = await to(sdk.runtimeEnvs.get({ name: runtimeName })); + handleError(getRuntimeErr, `Failed to get runtime with name "${runtimeName}"`); + const oldNodeSelector = _.get(runtime, 'runtimeScheduler.cluster.nodeSelector'); + const oldStorageClassName = _.get(runtime, 'dockerDaemonScheduler.pvcs.dind.storageClassName'); // prompt migration process confirmation console.log(`${colors.red('This migration process will do the following:')}`); @@ -81,7 +84,15 @@ async function migrate({ process.exit(1); } - // delete old agent + // prepare old runtime + if (oldStorageClassName && oldStorageClassName.startsWith('dind-local-volumes-venona')) { + // need to replace to start with 'dind-local-volumes-runner' + const newRe = _.set(runtime, 'dockerDaemonScheduler.pvcs.dind.storageClassName', oldStorageClassName.replace('venona', 'runner')); + const [err] = await to(sdk.runtimeEnvs.update({ name: runtimeName }, newRe)); + handleError(err, 'Failed to update runtime storage class name'); + } + + // delete old agent and runtime console.log(`Running migration script on runtime: ${colors.cyan(runtimeName)}`); const [migrateScriptErr, migrateScriptExitCode] = await to(sdk.agents.migrate({ kubeContextName, @@ -113,43 +124,31 @@ async function migrate({ oldConfig.nodeSelector = `${key}=${oldConfig.nodeSelector[key]}`; } - // install new agent - console.log(`Creating new codefresh agent with name: ${colors.cyan(newAgentName)}`); + // install new agent and runtime + console.log(`Creating new codefresh runner with name: ${colors.cyan(newAgentName)}`); const agentInstallOptions = { name: newAgentName, 'kube-context-name': kubeContextName, 'kube-node-selector': oldConfig.nodeSelector, + 'build-node-selector': oldNodeSelector, 'kube-namespace': kubeNamespace, + 'agent-kube-namespace': kubeNamespace, + 'agent-kube-context-name': kubeContextName, + 'agent-kube-config-path': kubeConfigPath, tolerations: JSON.stringify(oldConfig.tolerations), 'kube-config-path': kubeConfigPath, - 'install-runtime': false, + 'install-runtime': true, + 'runtime-name': runtimeName, + 'skip-re-creation': true, verbose, 'make-default-runtime': shouldMakeDefaultRe, - 'storage-class-name': storageClassName, + 'storage-class-name': storageClassName || oldStorageClassName, terminateProcess: false, 'set-value': setValue, 'set-file': setFile, }; const [agentInstallErr] = await to(installAgent.handler(agentInstallOptions)); - handleError(agentInstallErr, 'Failed to install new agent'); - - // attach old runtime to new agent - console.log(`Attaching runtime: ${colors.cyan(runtimeName)} to agent: ${colors.cyan(newAgentName)}`); - const [attachRuntimeErr] = await to(attachRuntime.handler({ - 'agent-name': newAgentName, - 'runtime-name': runtimeName, - 'runtime-kube-context-name': kubeContextName, - 'runtime-kube-namespace': kubeNamespace, - 'runtime-kube-serviceaccount': 'venona', - 'runtime-kube-config-path': kubeConfigPath, - 'agent-kube-context-name': kubeContextName, - 'agent-kube-namespace': kubeNamespace, - 'agent-kube-config-path': kubeConfigPath, - 'restart-agent': true, - terminateProcess: false, - verbose, - })); - handleError(attachRuntimeErr, 'Failed to attach the old runtime to the new agent'); + handleError(agentInstallErr, 'Failed to install new agent and runtime'); // Install new monitoring components console.log('Installing monitoring components'); diff --git a/lib/interface/cli/commands/runtimeEnvironments/install.cmd.js b/lib/interface/cli/commands/runtimeEnvironments/install.cmd.js index 33a751a19..dbba3961c 100644 --- a/lib/interface/cli/commands/runtimeEnvironments/install.cmd.js +++ b/lib/interface/cli/commands/runtimeEnvironments/install.cmd.js @@ -119,6 +119,7 @@ const installRuntimeCmd = new Command({ 'storage-class-name': storageClassName, 'agent-name': agentName, 'runtime-name': reName, + 'skip-re-creation': skipRuntimeCreation, 'dry-run': dryRun, 'in-cluster': inCluster, 'kube-node-selector': kubeNodeSelector, @@ -176,23 +177,25 @@ const installRuntimeCmd = new Command({ } // create RE in codefresh - await sdk.cluster.create({ - namespace: kubeNamespace, - storageClassName: storageClassName || `${defaultStorageClassPrefix}-${kubeNamespace}`, - runnerType: kubernetesRunnerType, - nodeSelector: kubeNodeSelectorObj, - annotations: buildAnnotations, - clusterName, - runtimeEnvironmentName: runtimeName, - agent: true, - }); - console.log(`Runtime environment "${colors.cyan(runtimeName)}" has been created`); - if (shouldMakeDefaultRe) { - const re = await sdk.runtimeEnvs.get({ - name: runtimeName, + if (!skipRuntimeCreation) { + await sdk.cluster.create({ + namespace: kubeNamespace, + storageClassName: storageClassName || `${defaultStorageClassPrefix}-${kubeNamespace}`, + runnerType: kubernetesRunnerType, + nodeSelector: kubeNodeSelectorObj, + annotations: buildAnnotations, + clusterName, + runtimeEnvironmentName: runtimeName, + agent: true, }); - await sdk.runtimeEnvs.setDefault({ account: re.accountId, name: re.metadata.name }); - console.log(`Runtime environment "${colors.cyan(runtimeName)}" has been set as the default runtime`); + console.log(`Runtime environment "${colors.cyan(runtimeName)}" has been created`); + if (shouldMakeDefaultRe) { + const re = await sdk.runtimeEnvs.get({ + name: runtimeName, + }); + await sdk.runtimeEnvs.setDefault({ account: re.accountId, name: re.metadata.name }); + console.log(`Runtime environment "${colors.cyan(runtimeName)}" has been set as the default runtime`); + } } // check if cluster already exists @@ -223,7 +226,6 @@ const installRuntimeCmd = new Command({ } // install RE on cluster - const runtimeEvents = new ProgressEvents(); const runtimeFormat = 'downloading runtime installer [{bar}] {percentage}% | {value}/{total}'; const runtimmrProgressBar = new cliProgress.SingleBar({ stopOnComplete: true, format: runtimeFormat }, cliProgress.Presets.shades_classic); @@ -256,7 +258,7 @@ const installRuntimeCmd = new Command({ setFile, terminateProcess: !attachRuntime, events: runtimeEvents, - storageClassName, + storageClassName: storageClassName && storageClassName.startsWith('dind-local-volumes') ? undefined : storageClassName, logFormatting: DefaultLogFormatter, }); // attach RE to agent in codefresh diff --git a/package.json b/package.json index 3e82014c2..14649d822 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codefresh", - "version": "0.68.4", + "version": "0.68.5", "description": "Codefresh command line utility", "main": "index.js", "preferGlobal": true,