Skip to content

Commit

Permalink
remove conditional update as server-side apply takes care of it
Browse files Browse the repository at this point in the history
  • Loading branch information
wr0ngway committed Jun 18, 2021
1 parent c9c3873 commit 7de290f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 26 deletions.
13 changes: 7 additions & 6 deletions lib/kubetruth/etl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,13 @@ def kube_apply(parsed_yml)
if ! kubeapi.under_management?(resource)
logger.warn "Skipping #{ident} as it doesn't have a label indicating it is under kubetruth management"
else
if resource.to_h.deep_stringify_keys == parsed_yml
logger.info "Skipping update for identical kubernetes resource #{ident}"
else
logger.info "Updating kubernetes resource #{ident}"
kubeapi.apply_resource(parsed_yml) unless @dry_run
end
# apply is server side, and doesn't update unless there are diffs (the
# metadata.resourceVersion/creationTimestamp/uid stay constant)
# Trying to compare the fetched resource to the generated one doesn't
# work as there a bunch of fields we don't control, so we just rely on
# the server-side apply to do the right thing.
logger.info "Updating kubernetes resource #{ident}"
kubeapi.apply_resource(parsed_yml) unless @dry_run
end
rescue Kubeclient::ResourceNotFoundError
logger.info "Creating kubernetes resource #{ident}"
Expand Down
20 changes: 0 additions & 20 deletions spec/kubetruth/etl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,26 +209,6 @@ class ForceExit < Exception; end
expect(Logging.contents).to match(/Skipping.*kubetruth management/)
end

it "doesn't update resource if data same" do
resource_yml = <<~EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: "group1"
namespace: "ns1"
data:
"param1": "value1"
EOF
parsed_yml = YAML.load(resource_yml)
resource = Kubeclient::Resource.new(parsed_yml)
expect(@kubeapi).to receive(:get_resource).with("configmaps", "group1", "ns1").and_return(resource)
expect(@kubeapi).to receive(:set_managed) # test double, so doesn't actually set the label
expect(@kubeapi).to receive(:under_management?).and_return(true)
expect(@kubeapi).to_not receive(:apply_resource)
etl.kube_apply(parsed_yml)
expect(Logging.contents).to match(/Skipping update for identical kubernetes resource/)
end

it "uses namespace for kube when supplied" do
resource_yml = <<~EOF
apiVersion: v1
Expand Down

0 comments on commit 7de290f

Please sign in to comment.