Skip to content

Commit

Permalink
Merge pull request #415 from UffizziCloud/feature/412-use-current-con…
Browse files Browse the repository at this point in the history
…text-namespace-for-uffizzi-uninstall

[#412] use current context namespace for uffizzi uninstall
  • Loading branch information
moklidia authored Apr 2, 2024
2 parents 77ad3d7 + 6415c92 commit 35acaef
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/uffizzi/cli/uninstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def unset_account_installation
end

def namespace
options[:namespace] || InstallService::DEFAULT_NAMESPACE
options[:namespace] || InstallService.current_namespace
end

def server
Expand Down
8 changes: 8 additions & 0 deletions lib/uffizzi/services/install_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ def helm_values_dir_path
File.dirname(Uffizzi::ConfigFile.config_path)
end

def current_namespace
path = KubeconfigService.default_path
kubeconfig = KubeconfigService.read_kubeconfig(path)
return if kubeconfig.nil?

KubeconfigService.get_current_namespace(kubeconfig) || DEFAULT_NAMESPACE
end

private

def execute_command(command, say: true, skip_error: false)
Expand Down
6 changes: 6 additions & 0 deletions lib/uffizzi/services/kubeconfig_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ def get_current_cluster_name(kubeconfig)
.dig('context', 'cluster')
end

def get_current_namespace(kubeconfig)
get_cluster_contexts(kubeconfig)
.detect { |c| c['name'] == get_current_context(kubeconfig) }
.dig('context', 'namespace')
end

def get_cluster_contexts(kubeconfig)
kubeconfig.fetch('contexts', [])
end
Expand Down

0 comments on commit 35acaef

Please sign in to comment.