Skip to content

Commit

Permalink
ignore empty stream templates
Browse files Browse the repository at this point in the history
  • Loading branch information
wr0ngway committed Jun 3, 2022
1 parent e36daa2 commit 9791457
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/kubetruth/etl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions spec/kubetruth/etl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9791457

Please sign in to comment.