All files / src/commands/k8s k8s.delete.command.js

54.28% Statements 19/35
100% Branches 1/1
0% Functions 0/1
54.28% Lines 19/35

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 36193x 193x 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 { k8sDelete } from '../../lib/k8s.js';
import { ask } from '../../lib/prompts.js';
import { styleText } from '../../lib/style-text.js';
import { Logger } from '../../logger.js';
import { orgaIdOrNameOption, skipConfirmationOption } from '../global.options.js';
import { k8sIdOrNameArg } from './k8s.args.js';
 
export const k8sDeleteCommand = defineCommand({
  description: 'Delete a Kubernetes cluster',
  since: '4.3.0',
  options: {
    org: orgaIdOrNameOption,
    yes: skipConfirmationOption,
  },
  args: [k8sIdOrNameArg],
  async handler(options, clusterIdOrName) {
    const { org: orgIdOrName, yes } = options;
    const display = clusterIdOrName.addon_name || clusterIdOrName.operator_id;

    if (!yes) {
      const proceed = await ask(
        `Are you sure you want to delete the Kubernetes cluster ${styleText('blue', display)}?`,
        false,
      );
      if (!proceed) {
        Logger.println('Kubernetes cluster deletion cancelled');
        return;
      }
    }

    await k8sDelete(orgIdOrName, clusterIdOrName);
    Logger.printSuccess(`Kubernetes cluster ${styleText('green', display)} successfully deleted`);
  },
});