diff --git a/plugins/kubernetes/app/models/kubernetes/api/pod.rb b/plugins/kubernetes/app/models/kubernetes/api/pod.rb index be8c6da8bc..fb5d1345ec 100644 --- a/plugins/kubernetes/app/models/kubernetes/api/pod.rb +++ b/plugins/kubernetes/app/models/kubernetes/api/pod.rb @@ -46,7 +46,7 @@ def role_id end def containers - @pod.spec.containers + @pod.spec.containers.map(&:to_h) end def logs(container) @@ -74,6 +74,11 @@ def events ) end + def init_containers + return [] unless containers = @pod.dig(:metadata, :annotations, :'pod.alpha.kubernetes.io/init-containers') + JSON.parse(containers, symbolize_names: true) + end + private def probe_failed_to_often?(event) diff --git a/plugins/kubernetes/app/models/kubernetes/deploy_executor.rb b/plugins/kubernetes/app/models/kubernetes/deploy_executor.rb index e2d25ba0d5..c1715f3f4b 100644 --- a/plugins/kubernetes/app/models/kubernetes/deploy_executor.rb +++ b/plugins/kubernetes/app/models/kubernetes/deploy_executor.rb @@ -132,8 +132,9 @@ def show_failure_cause(release, release_docs, statuses) def print_pod_logs(pod) @output.puts "LOGS:" - pod.containers.map(&:name).each do |container| - @output.puts "Container #{container}" if pod.containers.size > 1 + containers = (pod.containers + pod.init_containers).map { |c| c.fetch(:name) } + containers.each do |container| + @output.puts "Container #{container}" if containers.size > 1 # Display the first and last n_lines of the log max = 50 diff --git a/plugins/kubernetes/test/models/kubernetes/api/pod_test.rb b/plugins/kubernetes/test/models/kubernetes/api/pod_test.rb index bae727b8a4..47e1060909 100644 --- a/plugins/kubernetes/test/models/kubernetes/api/pod_test.rb +++ b/plugins/kubernetes/test/models/kubernetes/api/pod_test.rb @@ -119,7 +119,7 @@ describe "#containers" do it 'reads' do - pod.containers.first.name.must_equal 'container1' + pod.containers.first[:name].must_equal 'container1' end end @@ -245,4 +245,15 @@ assert pod_with_client.events_indicate_failure? end end + + describe "#init_containers" do + it "is empty for no containers" do + pod.init_containers.must_equal [] + end + + it "finds init containers" do + pod_attributes[:metadata][:annotations] = {"pod.alpha.kubernetes.io/init-containers": [{foo: :bar}].to_json} + pod.init_containers.must_equal [{foo: "bar"}] + end + end end