Skip to content

Commit

Permalink
fix: add an override for Job in cluster resource discovery (#696)
Browse files Browse the repository at this point in the history
* fix: add an override for Job in cluster resource discovery

* separate assertions for group/version/kind overrides
  • Loading branch information
sco11morgan authored and KnVerey committed Apr 13, 2020
1 parent 70a9849 commit ce88a08
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
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
11 changes: 11 additions & 0 deletions test/unit/cluster_resource_discovery_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,15 @@ def test_prunable_namespaced_resources
assert kinds.one? { |k| k.include?(expected_kind) }
end
end

def test_prunable_namespaced_resources_apply_group_version_kind_overrides
Krane::Kubectl.any_instance.stubs(:run).with("api-versions", attempts: 5, use_namespace: false)
.returns([api_versions_full_response, "", stub(success?: true)])
crd = mocked_cluster_resource_discovery(api_resources_namespaced_full_response, namespaced: true)
kinds = crd.prunable_resources(namespaced: true)

%w(batch/v1/Job extensions/v1beta1/Ingress).each do |expected_kind|
assert kinds.one? { |k| k.include?(expected_kind) }
end
end
end

0 comments on commit ce88a08

Please sign in to comment.