Sha256: bab056d53d081ced015f0e10170874e6e1a4de434ce90f206c76a6c29408afe3

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

require_relative 'ionoscloud_base'

class Chef
  class Knife
    class IonoscloudNodepoolDelete < Knife
      include Knife::IonoscloudBase

      banner 'knife ionoscloud nodepool delete NODEPOOL_ID [NODEPOOL_ID] (options)'

      option :cluster_id,
              short: '-C CLUSTER_ID',
              long: '--cluster-id CLUSTER_ID',
              description: 'The ID of the K8s Cluster'

      def initialize(args = [])
        super(args)
        @description =
        'Deletes a node pool within an existing Kubernetes cluster.'
        @directory = 'kubernetes'
        @required_options = [:cluster_id, :ionoscloud_username, :ionoscloud_password]
      end

      def run
        $stdout.sync = true
        handle_extra_config
        validate_required_params(@required_options, config)

        kubernetes_api = Ionoscloud::KubernetesApi.new(api_client)

        @name_args.each do |nodepool_id|
          begin
            nodepool = kubernetes_api.k8s_nodepools_find_by_id(config[:cluster_id], nodepool_id)
          rescue Ionoscloud::ApiError => err
            raise err unless err.code == 404
            ui.error("K8s Nodepool ID #{nodepool_id} not found. Skipping.")
            next
          end

          print_k8s_nodepool(nodepool)
          puts "\n"

          begin
            confirm('Do you really want to delete this K8s Nodepool')
          rescue SystemExit
            next
          end

          kubernetes_api.k8s_nodepools_delete(config[:cluster_id], nodepool.id)
          ui.warn("Deleted K8s Nodepool #{nodepool.id}.")
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
knife-ionoscloud-6.1.1 lib/chef/knife/ionoscloud_nodepool_delete.rb