lib/seira/pods.rb in seira-0.2.2 vs lib/seira/pods.rb in seira-0.3.0

- old
+ new

@@ -60,11 +60,11 @@ puts `kubectl top pod #{pod_name} --namespace=#{app} --containers` end def run_connect # If a pod name is specified, connect to that pod; otherwise pick a random web pod - target_pod_name = pod_name || fetch_pods(app: app, tier: 'web').sample&.dig('metadata', 'name') + target_pod_name = pod_name || Helpers.fetch_pods(app: app, filters: { tier: 'web' }).sample&.dig('metadata', 'name') if target_pod_name connect_to_pod(target_pod_name) else puts "Could not find web pod to connect to" @@ -102,11 +102,11 @@ # Any remaining args are the command to run command = args.join(' ') # Find a 'template' pod from the proper tier - template_pod = fetch_pods(app: app, tier: tier).first + template_pod = Helpers.fetch_pods(app: app, filters: { tier: tier }).first if template_pod.nil? puts "Unable to find #{tier} tier pod to copy config from" exit(1) end @@ -160,14 +160,9 @@ # Clean up unless system("kubectl --namespace=#{app} delete pod #{temp_name}") puts "Warning: failed to clean up pod #{temp_name}" end end - end - - def fetch_pods(filters) - filter_string = filters.map { |k, v| "#{k}=#{v}" }.join(',') - JSON.parse(`kubectl get pods --namespace=#{app} -o json --selector=#{filter_string}`)['items'] end def connect_to_pod(name, command = 'bash') puts "Connecting to #{name}..." system("kubectl exec -ti #{name} --namespace=#{app} -- #{command}")