Skip to content

Commit

Permalink
Merge pull request #1881 from macaktom/ensure-kubeconfig
Browse files Browse the repository at this point in the history
Add default kubeconfig path if KUBECONFIG is unset
  • Loading branch information
agentpoyo authored Mar 6, 2024
2 parents a1797d3 + 55ca838 commit aa79990
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/tasks/utils/utils.cr
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,19 @@ module ShellCmd
end

def ensure_kubeconfig!
puts "KUBECONFIG is not set. Please set a KUBECONFIG, i.p 'export KUBECONFIG=path-to-your-kubeconfig'".colorize(:red) unless ENV.has_key?("KUBECONFIG")
raise "KUBECONFIG is not set. Please set a KUBECONFIG, i.p 'export KUBECONFIG=path-to-your-kubeconfig'" unless ENV.has_key?("KUBECONFIG")

kubeconfig_path = File.join(ENV["HOME"], ".kube", "config")

if ENV.has_key?("KUBECONFIG") && File.exists?(ENV["KUBECONFIG"])
puts "KUBECONFIG is already set.".colorize(:green)
elsif File.exists?(kubeconfig_path)
ENV["KUBECONFIG"] = kubeconfig_path
puts "KUBECONFIG is set as #{ENV["KUBECONFIG"]}.".colorize(:green)
else
puts "KUBECONFIG is not set. Please set a KUBECONFIG, i.p 'export KUBECONFIG=path-to-your-kubeconfig'".colorize(:red)
raise "KUBECONFIG is not set. Please set a KUBECONFIG, i.p 'export KUBECONFIG=path-to-your-kubeconfig'"
end

end

def log_formatter
Expand Down

0 comments on commit aa79990

Please sign in to comment.