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

don't use uniq by kind for prunable resources due to duplicate kinds … #825

Merged
merged 10 commits into from
May 13, 2021
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## next

*Bug Fixes*
- Don't gather prunable resources by calling uniq only on `kind`, use `group` and `version` as well. Otherwise certain resources may not be added to the prune whitelist [#825](https://github.com/Shopify/krane/pull/825)

## 2.1.9

*Other*
Expand Down
2 changes: 1 addition & 1 deletion lib/krane/cluster_resource_discovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def fetch_resources(namespaced: false)
end
responses.flat_map do |path, resources|
resources.map { |r| resource_hash(path, namespaced, r) }
end.compact.uniq { |r| r["kind"] }
end.compact.uniq { |r| "#{r['group']}/#{r['version']}#{r['kind']} }" }
end

def fetch_mutating_webhook_configurations
Expand Down
8 changes: 4 additions & 4 deletions test/unit/cluster_resource_discovery_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_fetch_resources_failure

def test_fetch_resources_not_namespaced
crd = mocked_cluster_resource_discovery
kinds = crd.fetch_resources(namespaced: false).map { |r| r['kind'] }
kinds = crd.fetch_resources(namespaced: false).map { |r| r['kind'] }.uniq
assert_equal(kinds.length, 22)
%w(MutatingWebhookConfiguration ComponentStatus CustomResourceDefinition).each do |kind|
assert_includes(kinds, kind)
Expand All @@ -22,7 +22,7 @@ def test_fetch_resources_not_namespaced

def test_fetch_resources_namespaced
crd = mocked_cluster_resource_discovery
kinds = crd.fetch_resources(namespaced: true).map { |r| r['kind'] }
kinds = crd.fetch_resources(namespaced: true).map { |r| r['kind'] }.uniq
assert_equal(kinds.length, 29)
%w(ConfigMap CronJob Deployment).each do |kind|
assert_includes(kinds, kind)
Expand All @@ -31,7 +31,7 @@ def test_fetch_resources_namespaced

def test_prunable_global_resources
crd = mocked_cluster_resource_discovery
kinds = crd.prunable_resources(namespaced: false)
kinds = crd.prunable_resources(namespaced: false).uniq { r['kind'] }
assert_equal(kinds.length, 15)
%w(PriorityClass StorageClass).each do |expected_kind|
assert(kinds.one? { |k| k.include?(expected_kind) })
Expand All @@ -43,7 +43,7 @@ def test_prunable_global_resources

def test_prunable_namespaced_resources
crd = mocked_cluster_resource_discovery
kinds = crd.prunable_resources(namespaced: true)
kinds = crd.prunable_resources(namespaced: true).uniq { r['kind'] }

assert_equal(kinds.length, 25)
%w(ConfigMap CronJob Deployment).each do |expected_kind|
Expand Down