Skip to content

Commit

Permalink
Add an overide list
Browse files Browse the repository at this point in the history
  • Loading branch information
dturn committed Nov 7, 2019
1 parent 635c039 commit 8bf43b6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 13 additions & 1 deletion lib/krane/cluster_resource_discovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,23 @@ def prunable_resources
api_versions = fetch_api_versions
fetch_resources.map do |resource|
next unless resource['verbs'].include?("delete")
version = api_versions.fetch(resource['apigroup'], ['v1']).last
version = latest_version(api_versions.fetch(resource['apigroup'], ['v1']), resource['kind'])
[resource['apigroup'], version, resource['kind']].compact.join("/")
end.compact
end

def latest_version(versions, kind)
version_override = { "CronJob" => "v1beta1", "VolumeAttachment" => "v1beta1",
"CSIDriver" => "v1beta1", "Ingress" => "v1beta1" }

pattern = /v(?<major>\d+)(beta)?(?<minor>\d+)?/
latest = versions.sort_by do |version|
match = version.match(pattern)
[match[:major].to_i, (match[:minor] || 999).to_i]
end.last
version_override.fetch(kind, latest)
end

def fetch_resources(only_globals: false, only_namespaced: false)
command = %w(api-resources)
command << "--namespaced=false" if only_globals
Expand Down
3 changes: 1 addition & 2 deletions lib/krane/deploy_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ def initialize(**args)
end

def prune_whitelist
black_list = %w(batch/v1beta1/Job)
cluster_resource_discoverer.prunable_resources.select do |gvk|
@task_config.namespaced_kinds.any? { |g| gvk.include?(g) } && black_list.none? { |b| gvk.include?(b) }
@task_config.namespaced_kinds.any? { |g| gvk.include?(g) }
end
end
end
Expand Down

0 comments on commit 8bf43b6

Please sign in to comment.