Skip to content

Commit

Permalink
render implicit yml multi doc file correctly (#551)
Browse files Browse the repository at this point in the history
* Only care about implicitness of first doc
* Update the changelog
  • Loading branch information
dturn committed Sep 13, 2019
1 parent 3d3f4ad commit 0ee2531
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
- Make sure that we only declare a Service of type LoadBalancer as deployed after its IP address is published. [#547](https://github.com/Shopify/kubernetes-deploy/pull/547)


*Bug Fixes*
- Fix a bug in rendering where we failed to add a yaml doc separator (`---`) to
an implicit document if there are multiple documents in the file.
([#551](https://github.com/Shopify/kubernetes-deploy/pull/551))

*Other*
- Kubernetes 1.10 is no longer officially supported as of this version ([#546](https://github.com/Shopify/kubernetes-deploy/pull/546))
- We've added a new Krane cli. This code is in alpha. We are providing
Expand Down
6 changes: 3 additions & 3 deletions lib/kubernetes-deploy/render_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ def render_filename(filename, stream)
@logger.info("Rendering #{file_basename}...")
file_content = File.read(File.join(@template_dir, filename))
rendered_content = @renderer.render_template(filename, file_content)
implicit = true
YAML.parse_stream(rendered_content, "<rendered> #{filename}") { |d| implicit = d.implicit }
implicit = []
YAML.parse_stream(rendered_content, "<rendered> #{filename}") { |d| implicit << d.implicit }
if rendered_content.present?
stream.puts "---\n" if implicit
stream.puts "---\n" if implicit.first
stream.puts rendered_content
@logger.info("Rendered #{file_basename}")
else
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/partials/no-doc-separator.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# The first doc has no yaml separator
key1: foo
---
key2: bar
2 changes: 0 additions & 2 deletions test/fixtures/partials/no-doc-seperator.yml.erb

This file was deleted.

8 changes: 4 additions & 4 deletions test/integration/render_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,12 @@ def test_render_valid_fixtures

def test_render_only_adds_initial_doc_seperator_when_missing
render = build_render_task(fixture_path('partials'))
fixture = 'no-doc-seperator.yml.erb'
expected = "---\n# This doc has no yaml seperator\nkey1: foo\n"
fixture = 'no-doc-separator.yml.erb'
expected = "---\n# The first doc has no yaml separator\nkey1: foo\n---\nkey2: bar\n"

assert_render_success(render.run(mock_output_stream, [fixture]))
assert_render_success(render.run(mock_output_stream, [fixture, fixture]))
stdout_assertion do |output|
assert_equal expected, output
assert_equal "#{expected}#{expected}", output
end

mock_output_stream.rewind
Expand Down

0 comments on commit 0ee2531

Please sign in to comment.