All files / src/commands/k8s k8s.nodegroups.list.command.js

36.73% Statements 18/49
100% Branches 1/1
0% Functions 0/1
36.73% Lines 18/49

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x                                                               193x 193x  
import { defineCommand } from '../../lib/define-command.js';
import { k8sListNodeGroups } from '../../lib/k8s.js';
import { styleText } from '../../lib/style-text.js';
import { Logger } from '../../logger.js';
import { humanJsonOutputFormatOption, orgaIdOrNameOption } from '../global.options.js';
import { k8sIdOrNameArg } from './k8s.args.js';
 
export const k8sNodeGroupListCommand = defineCommand({
  description: 'List the node groups of a Kubernetes cluster',
  since: '4.9.0',
  options: {
    org: orgaIdOrNameOption,
    format: humanJsonOutputFormatOption,
  },
  args: [k8sIdOrNameArg],
  async handler(options, clusterIdOrName) {
    const { format, org: orgIdOrName } = options;
    const nodeGroups = await k8sListNodeGroups(orgIdOrName, clusterIdOrName);

    switch (format) {
      case 'json':
        Logger.printJson(nodeGroups);
        break;
      case 'human':
      default:
        if (nodeGroups.length === 0) {
          Logger.println(
            `🔎 No node group found, create one with ${styleText('blue', 'clever k8s nodegroups create')}`,
          );
          return;
        }
        console.table(
          Object.fromEntries(
            nodeGroups.map((ng) => [
              ng.id,
              {
                Name: ng.name,
                Status: ng.status,
                Flavor: ng.flavor,
                Nodes: `${ng.currentNodeCount}/${ng.targetNodeCount}`,
                Autoscaling: ng.autoscalingEnabled ? `${ng.minNodeCount}-${ng.maxNodeCount}` : 'disabled',
              },
            ]),
          ),
        );
        break;
    }
  },
});