Sha256: 8515b6dc09362dddf7e2c71116f73419260b3e35dc6840d11f52f677591f7aa2

Contents?: true

Size: 1.08 KB

Versions: 17

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require 'uffizzi/helpers/config_helper'
require 'uffizzi/services/kubeconfig_service'

class ClusterDeleteService
  class << self
    def exclude_kubeconfig(cluster_id, kubeconfig)
      cluster_config = Uffizzi::ConfigHelper.cluster_config_by_id(cluster_id)
      return if cluster_config.nil?

      kubeconfig_path = cluster_config[:kubeconfig_path]
      Uffizzi::ConfigFile.write_option(:clusters, Uffizzi::ConfigHelper.clusters_config_without(cluster_id))

      KubeconfigService.save_to_filepath(kubeconfig_path, kubeconfig) do |kubeconfig_by_path|
        if kubeconfig_by_path.nil?
          msg = "Warning: kubeconfig at path #{kubeconfig_path} does not exist"
          return Uffizzi.ui.say(msg)
        end

        new_kubeconfig = KubeconfigService.exclude(kubeconfig_by_path, kubeconfig)
        first_context = KubeconfigService.get_first_context(new_kubeconfig)
        new_current_context = first_context.present? ? first_context['name'] : nil
        KubeconfigService.update_current_context(new_kubeconfig, new_current_context)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
uffizzi-cli-2.4.11 lib/uffizzi/services/cluster/delete_service.rb
uffizzi-cli-2.4.10 lib/uffizzi/services/cluster/delete_service.rb
uffizzi-cli-2.4.9 lib/uffizzi/services/cluster/delete_service.rb
uffizzi-cli-2.4.8 lib/uffizzi/services/cluster/delete_service.rb
uffizzi-cli-2.4.7 lib/uffizzi/services/cluster/delete_service.rb
uffizzi-cli-2.4.6 lib/uffizzi/services/cluster/delete_service.rb
uffizzi-cli-2.4.5 lib/uffizzi/services/cluster/delete_service.rb
uffizzi-cli-2.4.4 lib/uffizzi/services/cluster/delete_service.rb
uffizzi-cli-2.4.3 lib/uffizzi/services/cluster/delete_service.rb
uffizzi-cli-2.4.2 lib/uffizzi/services/cluster/delete_service.rb
uffizzi-cli-2.4.1 lib/uffizzi/services/cluster/delete_service.rb
uffizzi-cli-2.4.0 lib/uffizzi/services/cluster/delete_service.rb
uffizzi-cli-2.3.4 lib/uffizzi/services/cluster/delete_service.rb
uffizzi-cli-2.3.3 lib/uffizzi/services/cluster/delete_service.rb
uffizzi-cli-2.3.2 lib/uffizzi/services/cluster/delete_service.rb
uffizzi-cli-2.3.1 lib/uffizzi/services/cluster/delete_service.rb
uffizzi-cli-2.3.0 lib/uffizzi/services/cluster/delete_service.rb