Skip to content

Commit eaef03a

Browse files
make sure runtime exists prior attach (#418)
1 parent 6cc8d8d commit eaef03a

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ const installAgentCmd = new Command({
8383
if (!kubeContextName) {
8484
kubeContextName = getKubeContext(kubeConfigPath);
8585
}
86+
if (!kubeNamespace) {
87+
throw new Error('kube-namespace is mandatory parameter');
88+
}
8689

8790
if (!token) { // Create an agent if not provided
8891
name = name || `${kubeContextName}_${kubeNamespace}`;

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@ const ProgressEvents = require('../../helpers/progressEvents');
66
const cliProgress = require('cli-progress');
77

88

9-
const attachAgentToRuntime = async (agent, runtime) => {
9+
const attachAgentToRuntime = async (agent, name) => {
10+
const rt = await sdk.runtimeEnvs.get({ name });
11+
if (!rt) {
12+
throw new Error(`runtime ${name} does not exist on the account`);
13+
}
14+
if (!rt.metadata.agent) {
15+
throw new Error('cannot attach non hybrid runtime');
16+
}
1017
const runtimes = _.get(agent, 'runtimes', []);
11-
const existingRT = _.find(runtimes, value => value === runtime);
18+
const existingRT = _.find(runtimes, value => value === name);
1219
if (!existingRT) {
13-
runtimes.push(runtime);
20+
runtimes.push(name);
1421
await sdk.agents.update({ agentId: agent.id, runtimes });
1522
}
1623
};
@@ -90,6 +97,9 @@ const attachRuntimeCmd = new Command({
9097
if (agent === '' || !agent) {
9198
throw new Error('agent was not found');
9299
}
100+
if (!kubeNamespace) {
101+
throw new Error('runtime-kube-namespace is mandatory parameter');
102+
}
93103

94104
await attachAgentToRuntime(agent, runtimeName);
95105

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ const installRuntimeCmd = new Command({
117117
'agent-kube-config-path': agentKubeConfigPath,
118118
token,
119119
} = argv;
120+
121+
if (!kubeNamespace) {
122+
throw new Error('runtime-kube-namespace is mandatory parameter');
123+
}
124+
120125
const apiHost = sdk.config.context.url;
121126
const clusterName = kubeContextName || getKubeContext(kubeConfigPath);
122127
const runtimeName = `${clusterName}/${kubeNamespace}`;

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.43.9",
3+
"version": "0.43.10",
44

55
"description": "Codefresh command line utility",
66
"main": "index.js",

0 commit comments

Comments
 (0)