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

fix: add an override for Job in cluster resource discovery #696

Merged
merged 2 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion lib/krane/cluster_resource_discovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def fetch_api_versions
def version_for_kind(versions, kind)
# Override list for kinds that don't appear in the lastest version of a group
version_override = { "CronJob" => "v1beta1", "VolumeAttachment" => "v1beta1",
"CSIDriver" => "v1beta1", "Ingress" => "v1beta1", "CSINode" => "v1beta1" }
"CSIDriver" => "v1beta1", "Ingress" => "v1beta1",
"CSINode" => "v1beta1", "Job" => "v1" }

pattern = /v(?<major>\d+)(?<pre>alpha|beta)?(?<minor>\d+)?/
latest = versions.sort_by do |version|
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/for_unit_tests/api_versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ autoscaling/v2beta1
autoscaling/v2beta2
batch/v1
batch/v1beta1
batch/v2alpha1
certificates.k8s.io/v1beta1
coordination.k8s.io/v1
coordination.k8s.io/v1beta1
Expand Down
2 changes: 1 addition & 1 deletion test/unit/cluster_resource_discovery_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_prunable_namespaced_resources
kinds = crd.prunable_resources(namespaced: true)

assert_equal(kinds.length, 25)
%w(ConfigMap CronJob Deployment).each do |expected_kind|
%w(ConfigMap CronJob Deployment batch/v1/Job).each do |expected_kind|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this just be "Job"? Otherwise of course L54 will only ever find one matching entry, before or after this PR. I guess the matcher needs to get more specific than just include? since it will also match "CronJob".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KnVerey the point of the test is to assert that the version override is working and a specific Job API is returned ("v1" not v1beta1 or v2alpha1)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sco11morgan The name of this test is vague, it was originally designed to ensure that a few obvious Kinds were present. How would you feel about adding an additional block to test for full group/version/kind matches:

%w(batch/v1/Job batch/v1beta1/cronjob).each do |expected_gvk|
  assert kinds.include?(expected_gvk)
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 moved the assertions to its own test

assert kinds.one? { |k| k.include?(expected_kind) }
end
end
Expand Down