cluster/lib/cluster/runner.rb in sct-0.1.21 vs cluster/lib/cluster/runner.rb in sct-0.1.22
- old
+ new
@@ -1,9 +1,9 @@
module Cluster
class Runner
-
- def launch
+
+ def launch
return UI.error("SCT has not been initialized. Run 'sct init' first.") unless SctCore::Config.exists
start_cluster
run_command "kubectl delete pod -n kube-system #{pods("kube-system").map { |pod| pod[:name] if pod[:name].start_with? "registry-creds" } .compact.join(" ")}"
run_command "kubectl rollout status -n kube-system deployment/registry-creds"
post_start
@@ -31,23 +31,33 @@
def reset
run_command "#{minikube} delete"
start_cluster
create_secrets
- run_command "#{minikube} addons enable registry-creds"
- run_command "#{minikube} addons enable ingress"
- run_command "kubectl rollout status -n kube-system deployment/registry-creds"
- run_command "kubectl rollout status -n kube-system deployment/nginx-ingress-controller"
+ enable_addons
wait_for_gcr_secret
run_command "kubectl apply -f ~/development/spend-cloud/k8s/ingress.yml"
wait_for_ingress_ip
run_command "kubectl apply -f ~/development/spend-cloud/k8s/dependencies.yml"
wait_for_pods
run_command "kubectl apply -f ~/development/spend-cloud/k8s/"
post_start
end
+ def enable_addons
+ enable_addon "registry-creds"
+ enable_addon "ingress"
+ end
+
+ def enable_addon(addon)
+ run_command "#{minikube} addons enable #{addon}"
+
+ deployment = deployments("kube-system").find { |deployment| deployment[:name].include? addon }
+
+ run_command "kubectl rollout status -n kube-system deployment/#{deployment[:name]}"
+ end
+
def wait_for_pods
UI.important("Waiting for pods to become ready...")
while ! pods.all? { |pod| pod[:status] == "Running" }
delete_stalled_pods
@@ -69,11 +79,11 @@
else
run_command "kubectl delete pods #{stalled_pods.map { |pod| pod[:name] } .join(" ")}"
end
end
- def delete_all_pods
+ def delete_all_pods
run_command "kubectl delete pods --all"
end
def delete_pods(args)
run_command "kubectl delete pods #{args.join(" ")}"
@@ -103,27 +113,40 @@
old_list = pods("kube-system").map { |pod| pod[:name] if pod[:name].start_with? "coredns" }.compact
run_command "kubectl delete pod -n kube-system #{old_list.join(" ")}" unless old_list.to_a.empty?
run_command "kubectl rollout status -n kube-system deployment/coredns"
end
- def pods(namespace = nil)
- if namespace
- output = `kubectl get pods -n #{namespace}`
- else
- output = `kubectl get pods`
- end
+ def deployments(namespace = "default")
+ output = `kubectl get deployments -n #{namespace}`
# split output lines
lines = output.split "\n"
# exclude first line (table header)
lines = lines[1..-1]
- if lines.to_a.empty?
- return
+ # get name and status of each pod
+ lines.map do |line|
+ columns = line.split(" ")
+
+ name = columns[0]
+
+ {
+ name: name
+ }
end
+ end
+ def pods(namespace = "default")
+ output = `kubectl get pods -n #{namespace}`
+
+ # split output lines
+ lines = output.split "\n"
+
+ # exclude first line (table header)
+ lines = lines[1..-1]
+
# get name and status of each pod
lines.map do |line|
columns = line.split(" ")
name = columns[0]
@@ -214,26 +237,26 @@
[columns[0][0..-2], columns[1]]
end
end
- def print_pods_status(namespace = nil)
+ def print_pods_status(namespace = "default")
pods_list = pods(namespace)
if pods_list.to_a.empty?
- return
+ return
end
rows = pods_list.map do |pod|
[
pod[:name],
pod[:status] == "Running" ? pod[:status].green : pod[:status].red
]
end
- puts Terminal::Table.new title: "Pods (namespace: #{namespace || "default"})".green, headings: ['Name', 'Status'], rows: rows
+ puts Terminal::Table.new title: "Pods (namespace: #{namespace})".green, headings: ['Name', 'Status'], rows: rows
end
def run_command command
if ! system command
raise command.red
@@ -246,6 +269,6 @@
else
return "minikube"
end
end
end
-end
\ No newline at end of file
+end