diff --git a/lib/kubetruth/etl.rb b/lib/kubetruth/etl.rb index addd2e2..b698828 100644 --- a/lib/kubetruth/etl.rb +++ b/lib/kubetruth/etl.rb @@ -221,8 +221,14 @@ def apply parsed_ymls = YAML.safe_load_stream(resource_yml, template_id) logger.debug {"Skipping empty template"} if parsed_ymls.empty? parsed_ymls.each do |parsed_yml| - async(annotation: "Apply Template: #{template_id}") do + if parsed_yml.present? + async(annotation: "Apply Template: #{template_id}") do + kube_apply(parsed_yml) kube_apply(parsed_yml) + kube_apply(parsed_yml) + end + else + logger.debug {"Skipping empty stream template"} end end diff --git a/spec/kubetruth/etl_spec.rb b/spec/kubetruth/etl_spec.rb index 228fc8e..a0d1cf4 100644 --- a/spec/kubetruth/etl_spec.rb +++ b/spec/kubetruth/etl_spec.rb @@ -491,6 +491,19 @@ class ForceExit < Exception; end expect(Logging.contents).to match(/Skipping empty template/) end + it "skips empty streams in template" do + config.root_spec.resource_templates = {"name1" => Template.new("---\n\n---\n\n")} + allow(etl).to receive(:load_config).and_yield(@ns, config) + + expect(collection).to receive(:names).and_return(["proj1"]) + + expect(etl).to_not receive(:kube_apply) + + etl.apply() + expect(Logging.contents).to_not match(/Skipping empty template/) + expect(Logging.contents).to match(/Skipping empty stream template/) + end + it "allows dryrun" do etl = described_class.new(dry_run: true) allow(etl).to receive(:load_config).and_yield(@ns, config)