Skip to content

Commit 6c00d18

Browse files
committed
Start of fixes for non unique kinds
1 parent 42301ec commit 6c00d18

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

lib/krane/kubernetes_resource.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ def build(namespace: nil, context:, definition:, logger:, statsd_tags:, crd: nil
4848
validate_definition_essentials(definition)
4949
opts = { namespace: namespace, context: context, definition: definition, logger: logger,
5050
statsd_tags: statsd_tags }
51-
if (klass = class_for_kind(definition["kind"]))
52-
return klass.new(**opts)
53-
end
54-
if crd
51+
52+
if crd && definition['apiVersion'].start_with?("#{crd.group}/")
5553
CustomResource.new(crd: crd, **opts)
54+
elsif (klass = class_for_kind(definition["kind"]))
55+
klass.new(**opts)
5656
else
5757
type = definition["kind"]
5858
inst = new(**opts)
@@ -164,12 +164,16 @@ def file_path
164164
end
165165

166166
def sync(cache)
167-
@instance_data = cache.get_instance(kubectl_resource_type, name, raise_if_not_found: true)
167+
@instance_data = cache.get_instance(sync_group_kind, name, raise_if_not_found: true)
168168
rescue Krane::Kubectl::ResourceNotFoundError
169169
@disappeared = true if deploy_started?
170170
@instance_data = {}
171171
end
172172

173+
def sync_group_kind
174+
"#{kubectl_resource_type}.#{group}"
175+
end
176+
173177
def after_sync
174178
end
175179

lib/krane/kubernetes_resource/custom_resource_definition.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ def validate_rollout_conditions
8787
@rollout_conditions_validated = true
8888
end
8989

90+
def sync_group_kind
91+
real_group = @definition.dig("apiVersion").split("/").first
92+
"#{self.class.kind}.#{real_group}"
93+
end
94+
9095
private
9196

9297
def names_accepted_condition

lib/krane/resource_cache.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ def get_all(kind, selector = nil)
3636
[]
3737
end
3838

39+
# TODO: I've broken sync_dependencies
3940
def prewarm(resources)
4041
sync_dependencies = resources.flat_map { |r| r.class.const_get(:SYNC_DEPENDENCIES) }
41-
kinds = (resources.map(&:type) + sync_dependencies).uniq
42+
kinds = resources.map(&:sync_group_kind).uniq # sync_dependencies).uniq
4243
Krane::Concurrency.split_across_threads(kinds, max_threads: kinds.count) { |kind| get_all(kind) }
4344
end
4445

@@ -56,8 +57,9 @@ def use_or_populate_cache(kind)
5657
end
5758

5859
def fetch_by_kind(kind)
59-
resource_class = KubernetesResource.class_for_kind(kind)
60-
global_kind = @task_config.global_kinds.map(&:downcase).include?(kind.downcase)
60+
kind_only = kind.split(".").first.downcase # Busted for non unique kinds...
61+
resource_class = KubernetesResource.class_for_kind(kind_only)
62+
global_kind = @task_config.global_kinds.map(&:downcase).include?(kind_only)
6163
output_is_sensitive = resource_class.nil? ? false : resource_class::SENSITIVE_TEMPLATE_CONTENT
6264
raw_json, _, st = @kubectl.run("get", kind, "--chunk-size=0", attempts: 5, output: "json",
6365
output_is_sensitive: output_is_sensitive, use_namespace: !global_kind)

0 commit comments

Comments
 (0)