kube_schema 1.9.0 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9946ce747cc72c7fd6ca85a8427daf711844160d0fd932e2ee0adaba687f4982
4
- data.tar.gz: 3b4843e1165f6ac2a61ded6415851d80a9515b4e7f0a533be9940560e55446ca
3
+ metadata.gz: 651ce0da8cfdeb3d0811b98c5740647fbb745730696ce780b4f12886ca86c60f
4
+ data.tar.gz: 46dbc8243c5c1702ea6d8a2dada15a6716369acf80e6f77a7c7edd44e789ec44
5
5
  SHA512:
6
- metadata.gz: f369dd4d71f53dc8ce4ad7b310c992283cabda559d0f493017400418043f69d5f340b6f8642b6e34a61db9610be206defdb5deeb6ac01f5f9e1f97f2dd3665bf
7
- data.tar.gz: 52cdb3057cd53c1ae36c1be4115d03ff353ec39707bf07f11ce7d7c0732de8c56a2ff2c5f5be8bfe0f244bef4fea82d54f33b407909bb61a9e9c5da0fb3884e3
6
+ metadata.gz: b1d2bd00725e5ec1f732fb9b5251db0463ba78a91957f8d6f657b9617472b215a1f86469d69c14c8fd9a0b1bd29b274059f70d28954091e8c59e74731d7c6ad7
7
+ data.tar.gz: 3a641891343ff4ca5b11e6c9b7ab41d0e7d746f6f9e08d37cfa8844a8fc0272d0d25f3830a7b9f254d280568d957ad8ba595cda9f443c9d06891659c101bffbd
@@ -66,6 +66,12 @@ module Kube
66
66
  "\nExpected \"group/version/kind\" or \"version/kind\"."
67
67
  end
68
68
 
69
+ # Custom schemas take precedence on full-GVK lookups too.
70
+ custom = find_custom_entry_by_gvk(group, version, kind)
71
+ if custom
72
+ return build_resource_class(custom[:schema], custom[:defaults])
73
+ end
74
+
69
75
  entry = find_gvk_entry_by_full_gvk(group, version, kind)
70
76
  else
71
77
  # Kind-only lookup — custom schemas take precedence.
@@ -92,7 +98,8 @@ module Kube
92
98
  #
93
99
  # @return [Array<String>] sorted kind names
94
100
  def list_resources
95
- (gvk_index.keys + Schema.custom_schemas.keys).uniq.sort
101
+ custom_kinds = Schema.custom_schemas.values.map { |v| v[:defaults]["kind"] }
102
+ (gvk_index.keys + custom_kinds).uniq.sort
96
103
  end
97
104
 
98
105
  # Look up a sub-spec definition by short name (e.g. "Container",
@@ -243,19 +250,25 @@ module Kube
243
250
  end
244
251
  end
245
252
 
246
- # Find a custom schema entry by kind (case-insensitive).
253
+ # Find a custom schema entry by kind (case-insensitive). The registry
254
+ # is keyed by full GVK, so match on each entry's recorded kind. When
255
+ # several groups register the same kind, the first registered wins.
247
256
  # Returns the { schema:, defaults: } hash or nil.
248
257
  def find_custom_entry(kind)
249
258
  registry = Schema.custom_schemas
250
- return registry[kind] if registry.key?(kind)
251
-
252
- registry.each do |k, v|
253
- return v if k.downcase == kind.downcase
254
- end
259
+ registry.each_value { |v| return v if v[:defaults]["kind"] == kind }
260
+ registry.each_value { |v| return v if v[:defaults]["kind"].casecmp?(kind) }
255
261
 
256
262
  nil
257
263
  end
258
264
 
265
+ # Find a custom schema entry by exact group, version, and kind.
266
+ # Returns the { schema:, defaults: } hash or nil.
267
+ def find_custom_entry_by_gvk(group, version, kind)
268
+ api_version = group.empty? ? version : "#{group}/#{version}"
269
+ Schema.custom_schemas["#{api_version}/#{kind}"]
270
+ end
271
+
259
272
  # Build a Resource subclass from a JSONSchemer instance and defaults hash.
260
273
  def build_resource_class(schema_instance, defaults)
261
274
  Class.new(::Kube::Schema::Resource) do
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kube
4
4
  module Schema
5
- VERSION = "1.9.0"
5
+ VERSION = "1.9.1"
6
6
  end
7
7
  end
data/lib/kube/schema.rb CHANGED
@@ -74,7 +74,12 @@ module Kube
74
74
  "schema must be a Hash, a JSON string, or a file path — got #{schema.class}"
75
75
  end
76
76
 
77
- @custom_schemas[kind] = {
77
+ # Key by full GVK ("group/version/Kind") so a registered CRD resolves
78
+ # on fully-qualified lookups (e.g. the api_version/kind path that
79
+ # Resource#rebuild reconstructs), not just kind-only lookups. Keying by
80
+ # bare kind also collided when two CRDs shared a kind across groups.
81
+ key = api_version ? "#{api_version}/#{kind}" : kind
82
+ @custom_schemas[key] = {
78
83
  schema: JSONSchemer.schema(parsed),
79
84
  defaults: { "apiVersion" => api_version, "kind" => kind }.freeze
80
85
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kube_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan K