From 0ee2531aa5af525a88e10ac05678c139b34de1e6 Mon Sep 17 00:00:00 2001 From: Danny Turner Date: Fri, 13 Sep 2019 10:03:09 -0700 Subject: [PATCH] render implicit yml multi doc file correctly (#551) * Only care about implicitness of first doc * Update the changelog --- CHANGELOG.md | 5 +++++ lib/kubernetes-deploy/render_task.rb | 6 +++--- test/fixtures/partials/no-doc-separator.yml.erb | 4 ++++ test/fixtures/partials/no-doc-seperator.yml.erb | 2 -- test/integration/render_task_test.rb | 8 ++++---- 5 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 test/fixtures/partials/no-doc-separator.yml.erb delete mode 100644 test/fixtures/partials/no-doc-seperator.yml.erb diff --git a/CHANGELOG.md b/CHANGELOG.md index 975316eff..8b30cdb7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/kubernetes-deploy/render_task.rb b/lib/kubernetes-deploy/render_task.rb index 6917453f9..c788e47a4 100644 --- a/lib/kubernetes-deploy/render_task.rb +++ b/lib/kubernetes-deploy/render_task.rb @@ -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, " #{filename}") { |d| implicit = d.implicit } + implicit = [] + YAML.parse_stream(rendered_content, " #{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 diff --git a/test/fixtures/partials/no-doc-separator.yml.erb b/test/fixtures/partials/no-doc-separator.yml.erb new file mode 100644 index 000000000..d70ff4bb7 --- /dev/null +++ b/test/fixtures/partials/no-doc-separator.yml.erb @@ -0,0 +1,4 @@ +# The first doc has no yaml separator +key1: foo +--- +key2: bar diff --git a/test/fixtures/partials/no-doc-seperator.yml.erb b/test/fixtures/partials/no-doc-seperator.yml.erb deleted file mode 100644 index 984e3e5de..000000000 --- a/test/fixtures/partials/no-doc-seperator.yml.erb +++ /dev/null @@ -1,2 +0,0 @@ -# This doc has no yaml seperator -key1: foo diff --git a/test/integration/render_task_test.rb b/test/integration/render_task_test.rb index 04f3c5519..bd5047c6c 100644 --- a/test/integration/render_task_test.rb +++ b/test/integration/render_task_test.rb @@ -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