Skip to content

Commit

Permalink
Merge pull request #1596 from zendesk/grosser/init-logs
Browse files Browse the repository at this point in the history
show init container logs too
  • Loading branch information
grosser authored Dec 30, 2016
2 parents 459a5d5 + 84923a0 commit 95f8958
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 6 additions & 1 deletion plugins/kubernetes/app/models/kubernetes/api/pod.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def role_id
end

def containers
@pod.spec.containers
@pod.spec.containers.map(&:to_h)
end

def logs(container)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions plugins/kubernetes/app/models/kubernetes/deploy_executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion plugins/kubernetes/test/models/kubernetes/api/pod_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

0 comments on commit 95f8958

Please sign in to comment.