Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PUT updates if needed annotations missing #130

Merged
merged 1 commit into from
May 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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