Skip to content

Commit

Permalink
PUT updates if needed annotations missing (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnummelin authored and jakolehm committed May 31, 2019
1 parent 84dc82f commit 4cd1811
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
33 changes: 33 additions & 0 deletions lib/k8s/foo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: v1
kind: Pod
metadata:
name: myapp
spec:
containers:
- name: myapp
image: docker.io/nginx/:1-alpine
resources:
limits:
memory: "10Mi"
cpu: "100m"

---

apiVersion: v1
kind: Pod
metadata:
name: myapp
labels: {}
spec:
containers:
- name: myapp
image: docker.io/nginx/:1-alpine
resources:
limits:
memory: "10Mi"
cpu: "100m"
ports: []




2 changes: 1 addition & 1 deletion lib/k8s/stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def apply(client, prune: true)
if !server_resource
logger.info "Create resource #{resource.apiVersion}:#{resource.kind}/#{resource.metadata.name} in namespace #{resource.metadata.namespace} with checksum=#{resource.checksum}"
keep_resource! client.create_resource(prepare_resource(resource))
elsif server_resource.metadata.annotations[@checksum_annotation] != resource.checksum
elsif server_resource.metadata.annotations&.dig(@checksum_annotation) != resource.checksum
logger.info "Update resource #{resource.apiVersion}:#{resource.kind}/#{resource.metadata.name} in namespace #{resource.metadata.namespace} with checksum=#{resource.checksum}"
r = prepare_resource(resource)
if server_resource.can_patch?(@last_config_annotation)
Expand Down
11 changes: 11 additions & 0 deletions spec/k8s/stack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@
}
subject.apply(client, prune: false)
end

it "updates the needed resource even when annotations missing" do
returned_resources = resources.dup
returned_resources = returned_resources.map { |r| subject.prepare_resource(r) unless r.nil? }
returned_resources[0].metadata.annotations = nil
allow(client).to receive(:get_resources).with([K8s::Resource, K8s::Resource, K8s::Resource]).and_return(returned_resources)

subject.resources[0] = subject.resources[0].merge(metadata: { labels: {'foo' => 'bar'}})
expect(client).to receive(:update_resource) { |r| r }
subject.apply(client, prune: false)
end
end

context "prunes namespaced objects first" do
Expand Down

0 comments on commit 4cd1811

Please sign in to comment.