Skip to content

Commit

Permalink
make sure runtime exists prior attach (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
oren-codefresh authored Mar 11, 2020
1 parent 6cc8d8d commit eaef03a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/interface/cli/commands/agent/install.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ const installAgentCmd = new Command({
if (!kubeContextName) {
kubeContextName = getKubeContext(kubeConfigPath);
}
if (!kubeNamespace) {
throw new Error('kube-namespace is mandatory parameter');
}

if (!token) { // Create an agent if not provided
name = name || `${kubeContextName}_${kubeNamespace}`;
Expand Down
16 changes: 13 additions & 3 deletions lib/interface/cli/commands/runtimeEnvironments/attach.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ const ProgressEvents = require('../../helpers/progressEvents');
const cliProgress = require('cli-progress');


const attachAgentToRuntime = async (agent, runtime) => {
const attachAgentToRuntime = async (agent, name) => {
const rt = await sdk.runtimeEnvs.get({ name });
if (!rt) {
throw new Error(`runtime ${name} does not exist on the account`);
}
if (!rt.metadata.agent) {
throw new Error('cannot attach non hybrid runtime');
}
const runtimes = _.get(agent, 'runtimes', []);
const existingRT = _.find(runtimes, value => value === runtime);
const existingRT = _.find(runtimes, value => value === name);
if (!existingRT) {
runtimes.push(runtime);
runtimes.push(name);
await sdk.agents.update({ agentId: agent.id, runtimes });
}
};
Expand Down Expand Up @@ -90,6 +97,9 @@ const attachRuntimeCmd = new Command({
if (agent === '' || !agent) {
throw new Error('agent was not found');
}
if (!kubeNamespace) {
throw new Error('runtime-kube-namespace is mandatory parameter');
}

await attachAgentToRuntime(agent, runtimeName);

Expand Down
5 changes: 5 additions & 0 deletions lib/interface/cli/commands/runtimeEnvironments/install.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ const installRuntimeCmd = new Command({
'agent-kube-config-path': agentKubeConfigPath,
token,
} = argv;

if (!kubeNamespace) {
throw new Error('runtime-kube-namespace is mandatory parameter');
}

const apiHost = sdk.config.context.url;
const clusterName = kubeContextName || getKubeContext(kubeConfigPath);
const runtimeName = `${clusterName}/${kubeNamespace}`;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codefresh",
"version": "0.43.9",
"version": "0.43.10",

"description": "Codefresh command line utility",
"main": "index.js",
Expand Down

0 comments on commit eaef03a

Please sign in to comment.