codefresh 0.84.9 → 0.85.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,160 @@
1
1
  /* eslint-disable max-len */
2
+ const cliProgress = require('cli-progress');
3
+ const colors = require('colors');
2
4
  const Command = require('../../Command');
3
5
  const installRoot = require('../root/install.cmd');
4
6
  const { sdk } = require('../../../../logic');
5
7
  const installRuntimeCmd = require('../runtimeEnvironments/install.cmd');
6
8
  const { getKubeContext } = require('../../helpers/kubernetes');
7
9
  const ProgressEvents = require('../../helpers/progressEvents');
8
- const cliProgress = require('cli-progress');
9
- const colors = require('colors');
10
10
  const { getNewAgentName } = require('./helper');
11
- const { DefaultLogFormatter } = require('./../hybrid/helper');
11
+ const { DefaultLogFormatter } = require('../hybrid/helper');
12
+ const Output = require('../../../../output/Output');
12
13
 
13
14
  const defaultNamespace = 'codefresh';
14
15
 
16
+ async function createAgent(argv) {
17
+ const {
18
+ name,
19
+ kubeConfigPath,
20
+ kubeContextName = getKubeContext(kubeConfigPath),
21
+ kubeNamespace = defaultNamespace,
22
+ } = argv;
23
+ const finalName = name || await getNewAgentName(kubeContextName, kubeNamespace);
24
+ try {
25
+ const { token } = await sdk.agents.create({ name: finalName });
26
+ console.log(`A Codefresh Runner with the name: ${colors.cyan(finalName)} has been created.`);
27
+ return token;
28
+ } catch (err) {
29
+ const msg = Output._extractErrorMessage(err);
30
+ if (msg.includes('Agent name duplication')) {
31
+ throw new Error(`A Codefresh Runner with the name "${colors.cyan(finalName)}" already exists. Please choose a different name, or delete the current agent from the platform.`);
32
+ }
33
+
34
+ throw err;
35
+ }
36
+ }
37
+
38
+ async function getAgentNameByToken(token) {
39
+ const [apiKey] = token.split('.');
40
+ const agentData = await sdk.tokens.getById({ id: apiKey });
41
+ if (!agentData) {
42
+ throw new Error('token is not valid');
43
+ }
44
+
45
+ const {
46
+ subject: {
47
+ type,
48
+ ref,
49
+ },
50
+ } = agentData;
51
+
52
+ if (type !== 'agent') {
53
+ throw new Error('token is not assosicated with a runner');
54
+ }
55
+
56
+ const { name } = await sdk.agents.get({ agentId: ref });
57
+ return name;
58
+ }
59
+
60
+ async function installAgentInCluster(argv, token, agentName) {
61
+ const {
62
+ kubeNodeSelector,
63
+ dryRun,
64
+ inCluster,
65
+ tolerations,
66
+ dockerRegistry,
67
+ skipVersionCheck,
68
+ kubeConfigPath,
69
+ kubeContextName = getKubeContext(kubeConfigPath),
70
+ kubeNamespace = defaultNamespace,
71
+ envVars,
72
+ verbose,
73
+ terminateProcess,
74
+ } = argv;
75
+
76
+ const apiHost = sdk.config.context.url;
77
+ const events = new ProgressEvents();
78
+ const format = 'downloading [{bar}] {percentage}% | {value}/{total}';
79
+ const progressBar = new cliProgress.SingleBar({ stopOnComplete: true, format }, cliProgress.Presets.shades_classic);
80
+ let totalSize;
81
+ events.onStart((size) => {
82
+ console.log('Downloading Codefresh Runner installer \n');
83
+ progressBar.start(size, 0);
84
+ totalSize = size;
85
+ });
86
+ events.onProgress((progress) => {
87
+ progressBar.update(progress);
88
+ if (progress >= totalSize) {
89
+ console.log('\n');
90
+ }
91
+ });
92
+ const agentInstallStatusCode = await sdk.agents.install({
93
+ agentId: agentName,
94
+ apiHost,
95
+ token,
96
+ kubeConfigPath,
97
+ kubeContextName,
98
+ kubeNamespace,
99
+ kubeNodeSelector,
100
+ inCluster,
101
+ dockerRegistry,
102
+ tolerations,
103
+ skipVersionCheck,
104
+ envVars,
105
+ events,
106
+ dryRun,
107
+ verbose,
108
+ terminateProcess,
109
+ logFormatting: DefaultLogFormatter,
110
+ });
111
+ if (agentInstallStatusCode !== 0) {
112
+ throw new Error(`\nRunner installation failed with code ${agentInstallStatusCode}`);
113
+ }
114
+ }
115
+
116
+ async function installRuntimeFunc(argv, agentName) {
117
+ const {
118
+ runtimeName,
119
+ skipReCreation,
120
+ buildNodeSelector,
121
+ storageClassName,
122
+ setValue,
123
+ setFile,
124
+ agentKubeContextName,
125
+ agentKubeNamespace,
126
+ kubeConfigPath,
127
+ kubeContextName,
128
+ kubeNamespace,
129
+ skipClusterCreation,
130
+ makeDefaultRuntime,
131
+ platformOnly,
132
+ verbose,
133
+ terminateProcess,
134
+ } = argv;
135
+ await installRuntimeCmd.handler({
136
+ runtimeName,
137
+ skipReCreation,
138
+ skipClusterCreation,
139
+ runtimeKubeConfigPath: kubeConfigPath,
140
+ runtimeKubeContextName: kubeContextName,
141
+ runtimeKubeNamespace: kubeNamespace,
142
+ kubeNodeSelector: buildNodeSelector,
143
+ storageClassName,
144
+ setValue,
145
+ setFile,
146
+ makeDefaultRuntime,
147
+ attachRuntime: true,
148
+ agentName,
149
+ agentKubeContextName,
150
+ agentKubeNamespace,
151
+ restartAgent: true,
152
+ platformOnly,
153
+ verbose,
154
+ terminateProcess,
155
+ });
156
+ }
157
+
15
158
  const installAgentCmd = new Command({
16
159
  root: false,
17
160
  parent: installRoot,
@@ -22,7 +165,7 @@ const installAgentCmd = new Command({
22
165
  title: 'Install',
23
166
  weight: 100,
24
167
  },
25
- builder: yargs => yargs
168
+ builder: (yargs) => yargs
26
169
  .env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
27
170
  .option('name', {
28
171
  describe: 'Agent\'s name to be created if token is not provided',
@@ -57,6 +200,24 @@ const installAgentCmd = new Command({
57
200
  .option('install-runtime', {
58
201
  describe: 'Install and attach runtime on the same namespace as the agent (default is false)',
59
202
  })
203
+ .option('runtime-name', {
204
+ describe: 'The name of the runtime to install',
205
+ })
206
+ .option('build-node-selector', {
207
+ describe: 'The kubernetes node selector "key=value" to be used by runner build resources (default is no node selector) (string)',
208
+ })
209
+ .option('skip-re-creation', {
210
+ description: 'If set to true, will skip runtime creation in the platform',
211
+ })
212
+ .option('set-value', {
213
+ describe: 'Set values for templates, example: --set-value LocalVolumesDir=/mnt/disks/ssd0/codefresh-volumes',
214
+ })
215
+ .option('set-file', {
216
+ describe: 'Set values for templates from file, example: --set-file Storage.GoogleServiceAccount=/path/to/service-account.json',
217
+ })
218
+ .option('skip-cluster-creation', {
219
+ description: 'If set to true, will skip cluster integration creation for this runtime',
220
+ })
60
221
  .option('make-default-runtime', {
61
222
  describe: 'should all pipelines run on the hybrid runtime (default is false)',
62
223
  })
@@ -73,132 +234,49 @@ const installAgentCmd = new Command({
73
234
  describe: 'The prefix for the container registry that will be used for pulling the required components images. Example: --docker-registry="docker.io"',
74
235
  type: 'string',
75
236
  })
237
+ .option('platform-only', {
238
+ describe: 'Set to true to create runtime on the platform side only',
239
+ })
76
240
  .option('verbose', {
77
241
  describe: 'Print logs',
78
242
  }),
79
243
  handler: async (argv) => {
80
- let {
81
- name, token,
82
- } = argv;
83
244
  const {
84
- 'runtime-name': reName,
85
- 'skip-re-creation': skipRuntimeCreation,
86
- 'kube-node-selector': kubeNodeSelector,
87
- 'build-node-selector': buildNodeSelector,
88
- 'dry-run': dryRun,
89
- 'in-cluster': inCluster,
90
- tolerations,
91
- 'kube-config-path': kubeConfigPath,
92
- 'skip-version-check': skipVersionCheck,
93
- 'install-runtime': installRuntime,
94
- 'make-default-runtime': shouldMakeDefaultRe,
95
- 'storage-class-name': storageClassName,
96
- verbose,
97
- terminateProcess,
98
- 'set-value': setValue,
99
- 'set-file': setFile,
100
- 'agent-kube-context-name': agentKubeContextName,
101
- 'agent-kube-namespace': agentKubeNamespace,
102
- 'docker-registry': dockerRegistry,
103
- envVars,
245
+ agentKubeNamespace,
246
+ installRuntime,
247
+ platformOnly,
104
248
  } = argv;
105
- let agent;
106
249
  let {
107
- 'kube-context-name': kubeContextName,
108
- 'kube-namespace': kubeNamespace,
250
+ name,
251
+ token,
109
252
  } = argv;
110
- if (!kubeContextName) {
111
- kubeContextName = getKubeContext(kubeConfigPath);
112
- }
113
- if (!kubeNamespace) {
114
- kubeNamespace = defaultNamespace;
115
- }
116
- if (installRuntime && !agentKubeNamespace) {
253
+
254
+ if (installRuntimeFunc && !agentKubeNamespace) {
117
255
  throw new Error('agent-kube-namespace is a mandatory parameter when installing runtime');
118
256
  }
119
257
 
120
- if (!token) { // Create an agent if not provided
121
- name = name || await getNewAgentName(kubeContextName, kubeNamespace);
122
- agent = await sdk.agents.create({ name });
123
- // eslint-disable-next-line prefer-destructuring
124
- token = agent.token;
125
- console.log(`A Codefresh Runner with the name: ${colors.cyan(name)} has been created.`);
258
+ if (!token) {
259
+ // Create an agent if not provided
260
+ token = await createAgent(argv);
126
261
  } else {
127
- // take the agent id from the token
128
- const apiKey = token.split('.')[0];
129
- const agentData = await sdk.tokens.getById({ id: apiKey });
130
- if (!agentData) {
131
- throw new Error('token is not valid');
262
+ // take the agent name from the token
263
+ const nameFromToken = await getAgentNameByToken(token);
264
+ if (!name) {
265
+ name = nameFromToken;
266
+ } else if (name !== nameFromToken) {
267
+ throw new Error(`token is assosicated with agent ${nameFromToken}, different from supplied '--name ${name}'`);
132
268
  }
133
- const { subject } = agentData;
134
-
135
- if (subject.type !== 'agent') {
136
- throw new Error('token is not assosicated with a runner');
137
- }
138
- const agentId = agentData.subject.ref;
139
- const data = await sdk.agents.get({ agentId });
140
- // eslint-disable-next-line prefer-destructuring
141
- name = data.name;
142
269
  }
143
- const apiHost = sdk.config.context.url;
144
- const events = new ProgressEvents();
145
- const format = 'downloading [{bar}] {percentage}% | {value}/{total}';
146
- const progressBar = new cliProgress.SingleBar({ stopOnComplete: true, format }, cliProgress.Presets.shades_classic);
147
- let totalSize;
148
- events.onStart((size) => {
149
- console.log('Downloading Codefresh Runner installer \n');
150
- progressBar.start(size, 0);
151
- totalSize = size;
152
- });
153
- events.onProgress((progress) => {
154
- progressBar.update(progress);
155
- if (progress >= totalSize) {
156
- console.log('\n');
157
- }
158
- });
159
- const agentInstallStatusCode = await sdk.agents.install({
160
- apiHost,
161
- kubeContextName,
162
- kubeNamespace,
163
- token,
164
- dryRun,
165
- inCluster,
166
- kubeNodeSelector,
167
- dockerRegistry,
168
- tolerations,
169
- kubeConfigPath,
170
- skipVersionCheck,
171
- verbose,
172
- agentId: name,
173
- terminateProcess,
174
- events,
175
- logFormatting: DefaultLogFormatter,
176
- envVars,
177
- });
178
- if (agentInstallStatusCode !== 0) {
179
- throw new Error(`\nRunner installation failed with code ${agentInstallStatusCode}`);
270
+
271
+ if (!platformOnly) {
272
+ await installAgentInCluster(argv, token, name);
180
273
  }
274
+
181
275
  if (installRuntime) {
182
- return installRuntimeCmd.handler({
183
- 'runtime-name': reName,
184
- 'skip-re-creation': skipRuntimeCreation,
185
- 'runtime-kube-context-name': kubeContextName,
186
- 'runtime-kube-namespace': kubeNamespace,
187
- 'agent-name': name,
188
- 'runtime-kube-config-path': kubeConfigPath,
189
- 'attach-runtime': true,
190
- 'restart-agent': true,
191
- 'make-default-runtime': shouldMakeDefaultRe,
192
- 'kube-node-selector': buildNodeSelector,
193
- 'storage-class-name': storageClassName,
194
- 'set-value': setValue,
195
- 'set-file': setFile,
196
- 'agent-kube-namespace': agentKubeNamespace,
197
- 'agent-kube-context-name': agentKubeContextName,
198
- verbose,
199
- terminateProcess,
200
- });
276
+ await installRuntimeFunc(argv, name);
201
277
  }
278
+
279
+ console.log(token);
202
280
  },
203
281
  });
204
282
 
@@ -6,7 +6,6 @@ const request = require('requestretry');
6
6
 
7
7
  jest.mock('../../../../logic/entities/Context');
8
8
 
9
-
10
9
  const DEFAULT_RESPONSE = request.__defaultResponse();
11
10
 
12
11
  describe('context commands', () => {
@@ -80,7 +79,13 @@ describe('context commands', () => {
80
79
  describe('s3', () => {
81
80
  it('should handle creation', async () => {
82
81
  const cmd = require('./create/helm-repo/types/s3.cmd');
83
- const argv = { name: 'some name', bucket: 'some bucket' };
82
+ const argv = {
83
+ name: 'some name',
84
+ bucket: 'some bucket',
85
+ 'aws-access-key-id': 'test-id',
86
+ 'aws-secret-access-key': 'test-secret',
87
+ 'aws-default-region': 'test-region',
88
+ };
84
89
  await cmd.handler(argv);
85
90
  await verifyResponsesReturned([DEFAULT_RESPONSE]); // eslint-disable-line
86
91
  });
@@ -37,19 +37,14 @@ const command = new Command({
37
37
  builder: (yargs) => {
38
38
  yargs
39
39
  .option(AWS.keyId.cliFlag, {
40
- describe: 'Amazon access key id',
41
- default: process.env[AWS.keyId.awsEnvVar],
42
- required: true,
40
+ describe: `Amazon access key id [default: ${AWS.keyId.awsEnvVar} env]`,
41
+
43
42
  })
44
43
  .option(AWS.secretKey.cliFlag, {
45
- describe: 'Amazon access secret key with permissions to the bucket',
46
- default: process.env[AWS.secretKey.awsEnvVar],
47
- required: true,
44
+ describe: `Amazon access secret key with permissions to the bucket [default: ${AWS.secretKey.awsEnvVar} env]`,
48
45
  })
49
46
  .option(AWS.region.cliFlag, {
50
- describe: 'Amazon default region',
51
- default: process.env[AWS.region.awsEnvVar],
52
- required: true,
47
+ describe: `Amazon default region [default: ${AWS.region.awsEnvVar} env]`,
53
48
  })
54
49
  .option('bucket', {
55
50
  describe: 'Name of the bucket',
@@ -58,6 +53,25 @@ const command = new Command({
58
53
  return yargs;
59
54
  },
60
55
  handler: async (argv) => {
56
+ const awsKeyId = argv[AWS.keyId.cliFlag] || process.env[AWS.keyId.awsEnvVar];
57
+ const awsSecretKey = argv[AWS.secretKey.cliFlag] || process.env[AWS.secretKey.awsEnvVar];
58
+ const awsRegion = argv[AWS.region.cliFlag] || process.env[AWS.region.awsEnvVar];
59
+ if (!awsKeyId) {
60
+ throw new CFError({
61
+ message: `Either ${AWS.keyId.awsEnvVar} env, or --${AWS.keyId.cliFlag} option is required`,
62
+ });
63
+ }
64
+ if (!awsSecretKey) {
65
+ throw new CFError({
66
+ message: `Either ${AWS.secretKey.awsEnvVar} env, or --${AWS.secretKey.cliFlag} option is required`,
67
+ });
68
+ }
69
+ if (!awsRegion) {
70
+ throw new CFError({
71
+ message: `Either ${AWS.region.awsEnvVar} env, or --${AWS.region.cliFlag} option is required`,
72
+ });
73
+ }
74
+
61
75
  let bucket = '';
62
76
  if (argv.bucket.startsWith('s3://')) {
63
77
  ({ bucket } = argv);
@@ -76,9 +90,9 @@ const command = new Command({
76
90
  data: {
77
91
  repositoryUrl: bucket,
78
92
  variables: {
79
- [AWS.keyId.awsEnvVar]: argv[AWS.keyId.cliFlag],
80
- [AWS.secretKey.awsEnvVar]: argv[AWS.secretKey.cliFlag],
81
- [AWS.region.awsEnvVar]: argv[AWS.region.cliFlag],
93
+ [AWS.keyId.awsEnvVar]: awsKeyId,
94
+ [AWS.secretKey.awsEnvVar]: awsSecretKey,
95
+ [AWS.region.awsEnvVar]: awsRegion,
82
96
  },
83
97
  },
84
98
  },
@@ -1,27 +1,107 @@
1
1
  /* eslint-disable max-len */
2
2
  const _ = require('lodash');
3
+ const cliProgress = require('cli-progress');
3
4
  const Command = require('../../Command');
4
5
  const { sdk } = require('../../../../logic');
5
6
  const ProgressEvents = require('../../helpers/progressEvents');
6
- const cliProgress = require('cli-progress');
7
7
  const { getKubeContext } = require('../../helpers/kubernetes');
8
- const { DefaultLogFormatter } = require('./../hybrid/helper');
8
+ const { DefaultLogFormatter } = require('../hybrid/helper');
9
+
10
+ async function attachInPlatform(argv) {
11
+ const {
12
+ agentName,
13
+ agentId,
14
+ runtimeName,
15
+ } = argv;
16
+ let agent;
17
+ if (_.isEmpty(runtimeName)) {
18
+ throw new Error('runtime name is mandatory');
19
+ }
20
+
21
+ if (agentName) {
22
+ agent = await sdk.agents.getByName({ name: agentName });
23
+ } else if (agentId) {
24
+ agent = await sdk.agents.get({ agentId });
25
+ } else {
26
+ throw new Error('agent name or agent id is needed');
27
+ }
28
+
29
+ if (agent === '' || !agent) {
30
+ throw new Error('agent was not found');
31
+ }
9
32
 
10
- const attachAgentToRuntime = async (agent, name) => {
11
- const rt = await sdk.runtimeEnvs.get({ name });
33
+ const rt = await sdk.runtimeEnvs.get({ name: runtimeName });
12
34
  if (!rt) {
13
- throw new Error(`runtime ${name} does not exist on the account`);
35
+ throw new Error(`runtime ${runtimeName} does not exist on the account`);
14
36
  }
37
+
15
38
  if (!rt.metadata.agent) {
16
39
  throw new Error('cannot attach non hybrid runtime');
17
40
  }
41
+
18
42
  const runtimes = _.get(agent, 'runtimes', []);
19
- const existingRT = _.find(runtimes, value => value === name);
43
+ const existingRT = _.find(runtimes, (value) => value === runtimeName);
20
44
  if (!existingRT) {
21
- runtimes.push(name);
45
+ runtimes.push(runtimeName);
22
46
  await sdk.agents.update({ agentId: agent.id, runtimes });
23
47
  }
24
- };
48
+ }
49
+
50
+ async function attachInCluster(argv) {
51
+ const {
52
+ runtimeName,
53
+ runtimeKubeConfigPath,
54
+ runtimeKubeContextName = getKubeContext(runtimeKubeConfigPath),
55
+ runtimeKubeNamespace,
56
+ agentKubeConfigPath,
57
+ agentKubeContextName = runtimeKubeContextName,
58
+ agentKubeNamespace,
59
+ runtimeKubeServiceAccount,
60
+ restartAgent,
61
+ verbose,
62
+ } = argv;
63
+ if (_.isNull(runtimeName) || _.isUndefined(runtimeName) || runtimeName === '') {
64
+ throw new Error('runtime name is mandatory');
65
+ }
66
+
67
+ if (!runtimeKubeNamespace) {
68
+ throw new Error('runtime-kube-namespace is mandatory parameter');
69
+ }
70
+
71
+ // call venonactl to attach
72
+ const events = new ProgressEvents();
73
+ const format = 'downloading [{bar}] {percentage}% | {value}/{total}';
74
+ const progressBar = new cliProgress.SingleBar({ stopOnComplete: true, format }, cliProgress.Presets.shades_classic);
75
+ let totalSize;
76
+ events.onStart((size) => {
77
+ progressBar.start(size, 0);
78
+ totalSize = size;
79
+ });
80
+ events.onProgress((progress) => {
81
+ progressBar.update(progress);
82
+ if (progress >= totalSize) {
83
+ console.log('\n');
84
+ }
85
+ });
86
+ await sdk.runtime.attach({
87
+ runtimeName,
88
+ kubeConfigPath: runtimeKubeConfigPath,
89
+ kubeContextName: runtimeKubeContextName,
90
+ kubeNamespace: runtimeKubeNamespace,
91
+ kubeServiceAccount: runtimeKubeServiceAccount,
92
+ agentKubeConfigPath,
93
+ agentKubeContextName,
94
+ agentKubeNamespace,
95
+ verbose,
96
+ restartAgent,
97
+ terminateProcess: false,
98
+ events,
99
+ logFormatting: DefaultLogFormatter,
100
+ });
101
+ if (!restartAgent) {
102
+ console.log('Please restart agent\'s pod in order that changes will take effect');
103
+ }
104
+ }
25
105
 
26
106
  const attachRuntimeCmd = new Command({
27
107
  root: true,
@@ -33,7 +113,7 @@ const attachRuntimeCmd = new Command({
33
113
  title: 'Attach Runtime-Environments',
34
114
  weight: 100,
35
115
  },
36
- builder: yargs => yargs
116
+ builder: (yargs) => yargs
37
117
  .env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
38
118
  .option('runtime-name', {
39
119
  describe: 'Runtime\'s name',
@@ -59,101 +139,42 @@ const attachRuntimeCmd = new Command({
59
139
  .option('agent-kube-namespace', {
60
140
  describe: 'Agent\'s namespace',
61
141
  })
142
+ .option('agent-kube-service-account', {
143
+ describe: 'The service account to use for the agent pod',
144
+ })
62
145
  .option('agent-kube-config-path', {
63
146
  describe: 'Path to kubeconfig file for the agent (default is $HOME/.kube/config)',
64
147
  })
65
148
  .option('restart-agent', {
66
149
  describe: 'restart agent afte install - default false',
67
150
  })
151
+ .option('platform-only', {
152
+ describe: 'Set to true to attach runtime to agent on the platform side only',
153
+ })
68
154
  .option('verbose', {
69
155
  describe: 'Print logs',
70
156
  }),
71
157
  handler: async (argv) => {
72
158
  const {
73
- 'agent-name': agentName,
74
- 'runtime-name': runtimeName,
75
- 'agent-id': agentId,
76
- 'runtime-kube-namespace': kubeNamespace,
77
- 'runtime-kube-config-path': kubeConfigPath,
78
- 'agent-kube-namespace': agentKubeNamespace,
79
- 'agent-kube-config-path': agentKubeConfigPath,
80
- 'runtime-kube-serviceaccount': kubeServiceAccount,
81
- 'restart-agent': restartAgent,
82
- verbose,
83
-
159
+ runtimeKubeNamespace,
160
+ platformOnly,
161
+ terminateProcess,
84
162
  } = argv;
85
- let {
86
- 'runtime-kube-context-name': kubeContextName,
87
- 'agent-kube-context-name': agentKubeContextName,
88
- } = argv;
89
- const { terminateProcess } = argv;
90
- let agent;
91
- if (_.isNull(runtimeName) || _.isUndefined(runtimeName) || runtimeName === '') {
92
- throw new Error('runtime name is mandatory');
93
- }
94
- if (agentName) {
95
- agent = await sdk.agents.getByName({ name: agentName });
96
- } else if (agentId) {
97
- agent = await sdk.agents.get({ agentId });
98
- } else {
99
- throw new Error('agent name or agent id is needed');
100
- }
101
- if (agent === '' || !agent) {
102
- throw new Error('agent was not found');
103
- }
104
- if (!kubeNamespace) {
163
+ if (!runtimeKubeNamespace && !platformOnly) {
105
164
  throw new Error('runtime-kube-namespace is mandatory parameter');
106
165
  }
107
- if (!kubeContextName) {
108
- kubeContextName = getKubeContext(kubeConfigPath);
109
- }
110
- if (!agentKubeContextName) {
111
- agentKubeContextName = kubeContextName;
112
- }
113
-
114
- await attachAgentToRuntime(agent, runtimeName);
115
-
116
- // call venonactl to attach
117
166
 
118
- const events = new ProgressEvents();
119
- const format = 'downloading [{bar}] {percentage}% | {value}/{total}';
120
- const progressBar = new cliProgress.SingleBar({ stopOnComplete: true, format }, cliProgress.Presets.shades_classic);
121
- let totalSize;
122
- events.onStart((size) => {
123
- progressBar.start(size, 0);
124
- totalSize = size;
125
- });
126
- events.onProgress((progress) => {
127
- progressBar.update(progress);
128
- if (progress >= totalSize) {
129
- console.log('\n');
130
- }
131
- });
132
- await sdk.runtime.attach({
133
- kubeContextName,
134
- kubeServiceAccount,
135
- kubeNamespace,
136
- kubeConfigPath,
137
- agentKubeContextName,
138
- agentKubeNamespace,
139
- agentKubeConfigPath,
140
- runtimeName,
141
- verbose,
142
- restartAgent,
143
- terminateProcess: false,
144
- events,
145
- logFormatting: DefaultLogFormatter,
146
- });
147
- if (!restartAgent) {
148
- console.log('Please restart agent\'s pod in order that changes will take effect');
167
+ await attachInPlatform(argv);
168
+ if (!platformOnly) {
169
+ await attachInCluster(argv);
149
170
  }
171
+
150
172
  if (terminateProcess || terminateProcess === undefined) {
151
173
  process.exit();
152
- } else {
153
- return 0;
154
174
  }
175
+
176
+ return 0;
155
177
  },
156
178
  });
157
179
 
158
-
159
180
  module.exports = attachRuntimeCmd;