From 7de290fd54fc25fee9615496fd8320d6391bb733 Mon Sep 17 00:00:00 2001 From: Matt Conway Date: Fri, 18 Jun 2021 08:14:35 -0400 Subject: [PATCH] remove conditional update as server-side apply takes care of it --- lib/kubetruth/etl.rb | 13 +++++++------ spec/kubetruth/etl_spec.rb | 20 -------------------- 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/lib/kubetruth/etl.rb b/lib/kubetruth/etl.rb index 0a54b0e..914e605 100644 --- a/lib/kubetruth/etl.rb +++ b/lib/kubetruth/etl.rb @@ -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}" diff --git a/spec/kubetruth/etl_spec.rb b/spec/kubetruth/etl_spec.rb index 9c548ee..666aa1d 100644 --- a/spec/kubetruth/etl_spec.rb +++ b/spec/kubetruth/etl_spec.rb @@ -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