Skip to content
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
5 changes: 4 additions & 1 deletion lib/krane/cluster_resource_discovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ def crds
end

def prunable_resources(namespaced:)
black_list = %w(Namespace Node ControllerRevision Event)
black_list = %w(Namespace Node ControllerRevision Event Elasticsearch)
fetch_resources(namespaced: namespaced).map do |resource|
next unless resource["verbs"].one? { |v| v == "delete" }
if resource["kind"] == "Elasticsearch"
StatsD.client.increment('elasticsearch_resource_deletion_attempt.increment', tags: %W(context:#{context} namespace:#{namespace}))
end
next if black_list.include?(resource["kind"])
[resource["apigroup"], resource["version"], resource["kind"]].compact.join("/")
end.compact
Expand Down
13 changes: 12 additions & 1 deletion test/unit/cluster_resource_discovery_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class ClusterResourceDiscoveryTest < Krane::TestCase
include ClusterResourceDiscoveryHelper
include StatsD::Instrument::Assertions

def test_fetch_resources_failure
crd = mocked_cluster_resource_discovery(success: false)
Expand Down Expand Up @@ -49,7 +50,7 @@ def test_prunable_namespaced_resources
%w(ConfigMap CronJob Deployment).each do |expected_kind|
assert(kinds.one? { |k| k.include?(expected_kind) })
end
%w(controllerrevision event).each do |black_listed_kind|
%w(controllerrevision event elasticsearch).each do |black_listed_kind|
assert_empty(kinds.select { |k| k.downcase.include?(black_listed_kind) })
end
end
Expand All @@ -61,4 +62,14 @@ def test_prunable_namespaced_resources_apply_group_version_kind_overrides
assert(kinds.one? { |k| k.include?(expected_kind) })
end
end

def test_elasticsearch_statsd_increment_not_emitted_when_no_elasticsearch
crd = mocked_cluster_resource_discovery
metrics = capture_statsd_calls(client: Krane::StatsD.client) do
crd.prunable_resources(namespaced: true)
end

increment_metric = metrics.find { |m| m.name == 'Krane.elasticsearch_resource_deletion_attempt.increment' && m.type == :c }
assert_nil(increment_metric, "Expected elasticsearch_resource_deletion_attempt.increment NOT to be emitted when no Elasticsearch exists")
end
end