All files / src/commands/k8s k8s.get-kubeconfig.command.js

53.12% Statements 17/32
100% Branches 1/1
0% Functions 0/1
53.12% Lines 17/32

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 33193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x 193x                               193x 193x  
import { defineCommand } from '../../lib/define-command.js';
import { isK8sClusterActive, k8sGetConfig } from '../../lib/k8s.js';
import { styleText } from '../../lib/style-text.js';
import { Logger } from '../../logger.js';
import { orgaIdOrNameOption } from '../global.options.js';
import { k8sIdOrNameArg } from './k8s.args.js';
 
export const k8sGetKubeconfigCommand = defineCommand({
  description: 'Get configuration of a Kubernetes cluster',
  since: '4.3.0',
  options: {
    org: orgaIdOrNameOption,
  },
  args: [k8sIdOrNameArg],
  async handler(options, clusterIdOrName) {
    const orgIdOrName = options.org;

    if ((await isK8sClusterActive(orgIdOrName, clusterIdOrName)) !== true) {
      Logger.printInfo(
        'Kubeconfig can only be retrieved from deployed clusters, wait for the deployment to finish and try again',
      );

      const orgMessageComplement = orgIdOrName ? `--org "${orgIdOrName.orga_id || orgIdOrName.orga_name}"` : '';
      Logger.println(
        `Check with ${styleText('blue', `clever k8s get ${clusterIdOrName.addon_name || clusterIdOrName.operator_id} ${orgMessageComplement}`)}`,
      );
      return;
    }

    console.log(await k8sGetConfig(orgIdOrName, clusterIdOrName));
  },
});