lib/sct/commands/cluster.rb in sct-0.1.16 vs lib/sct/commands/cluster.rb in sct-0.1.17

- old
+ new

@@ -1,6 +1,7 @@ require 'sct/command_interface' +require 'terminal-table' module Sct class ClusterCommand @@ -25,10 +26,12 @@ update_config when "setup", "reset" reset when "delete-stalled-pods" delete_stalled_pods(feedback: true) + when "status" + status else puts "Unknown or missing argument. Please run 'sct cluster up', 'sct cluster down', 'sct cluster setup', 'sct cluster reset', 'sct cluster update-config', or 'sct cluster delete-stalled-pods'.".red end end @@ -147,9 +150,64 @@ sleep 5 end puts "Pods are now ready.".green + end + + def status + minikube_status + pods_status + system_pods + current_contexts + end + + def pods_status + rows = [] + pods.map do |pod| + status = pod[:status] == "Running" ? pod[:status].green : pod[:status].red + rows << [pod[:name], status] + end + puts Terminal::Table.new :title => "Pods Status".green, :headings => ['Name', 'Status'], :rows => rows + end + + def system_pods + rows = [] + pods("kube-system").map do |pod| + status = pod[:status] == "Running" ? pod[:status].green : pod[:status].red + rows << [pod[:name], status] + end + puts Terminal::Table.new :title => "System pods Status".green, :headings => ['Name', 'Status'], :rows => rows + end + + def current_contexts + output = `kubectl config get-contexts` + + lines = output.split "\n" + lines = lines[1..-1] + + rows = [] + lines.map do |line| + columns = line.split(" ") + + current_context = columns[0] == "*" ? "Yes".green : "No".red + rows << [columns[2], current_context] + end + puts Terminal::Table.new :title => "Contexts".green, :headings => ['Cluster', 'Using context'], :rows => rows + end + + def minikube_status + output = `#{minikube} status` + + lines = output.split "\n" + + rows = [] + lines.map do |line| + columns = line.split(" ") + + rows << [columns[0], columns[1]] + end + puts Terminal::Table.new :title => "Minikube Status".green, :headings => ['Name', 'Status'], :rows => rows end def pods(namespace = nil) if namespace output = `kubectl get pods -n #{namespace}`