kube_schema 1.10.0 → 1.11.0

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: 95c2a3f8aa906bd8a40d43eedf4b209a4cdc83754c0ffe6a1b74a5c4aeab14c0
4
- data.tar.gz: 0f14d9a60d65d003dd11b0f0f0f344f5f1ac9e3b8c5bf44fde3b489b8828bebc
3
+ metadata.gz: a6007594b371eeb36c26edde49a50c9ad8f4a2024784f4ef1add3eee59afaa8d
4
+ data.tar.gz: abb0766ced76224828aa5356bc52bcaffe738ce99a4bd6369458a1555b2f3579
5
5
  SHA512:
6
- metadata.gz: 1ae77de844bff9919b8a429202648f85c97ac6ad2c2f522be9602008cf2cec518bd1544bd6ab4de98f29dc7a76262293138286a33ec89e4a4d2063fbdcb769cf
7
- data.tar.gz: 1ba74962b756416d428b793c3afb51847b1e3ce1b5366e4a089f0eac4614949fd1a1c8976c219b1e0adccda5ed3ae9da364b5d3848a7ca51bf27a68645fc6332
6
+ metadata.gz: 61eb43c26cf34db4c66b078169f8b23d36db383b80eb337cd39f4b61c69c36604f6bcec08606d90496ca825b70c50875deb99105db198f81532d055501baf310
7
+ data.tar.gz: 05316b1722bb83a2e182ba39afe1c109b50e92fe0fcc5839d12aaa80649241e533c98d731a956181475799e57b9a30714f1e146eb01ce3207b785f889c1fcb10
data/CHANGELOG.md CHANGED
@@ -4,6 +4,17 @@ All notable changes to this project are documented here.
4
4
 
5
5
  This file starts at 1.10.0; for earlier releases see the git history.
6
6
 
7
+ ## [1.11.0]
8
+
9
+ ### Added
10
+
11
+ - `Kube::Schema.api_groups` and `Instance#api_groups` — every API group known
12
+ to the schema (built-in types, the merged CRD bundles, and schemas
13
+ registered via `.register`), sorted and deduplicated, with the core group
14
+ as `""`. Intended for consumers that need to distinguish group/resource
15
+ from core resource/subresource strings — e.g. building RBAC rules — without
16
+ hardcoding a group list.
17
+
7
18
  ## [1.10.0]
8
19
 
9
20
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kube_schema (1.10.0)
4
+ kube_schema (1.11.0)
5
5
  json_schemer (~> 2.5.0)
6
6
  rubyshell (~> 1.5.0)
7
7
 
@@ -102,6 +102,21 @@ module Kube
102
102
  (gvk_index.keys + custom_kinds).uniq.sort
103
103
  end
104
104
 
105
+ # All API groups known to this version, including any custom schemas
106
+ # registered via Kube::Schema.register. The core API group is the
107
+ # empty string.
108
+ #
109
+ # instance.api_groups # => ["", "apps", "argoproj.io", "batch", ...]
110
+ #
111
+ # @return [Array<String>] sorted, deduplicated group names
112
+ def api_groups
113
+ custom_groups = Schema.custom_schemas.keys.filter_map do |key|
114
+ parts = key.split("/")
115
+ parts.first if parts.size == 3
116
+ end
117
+ (gvk_index.values.flatten.map { |entry| entry[:group] } + custom_groups).uniq.sort
118
+ end
119
+
105
120
  # Look up a sub-spec definition by short name (e.g. "Container",
106
121
  # "ContainerPort", "Volume", "Probe"). Returns a class that
107
122
  # inherits from Kube::Schema::SubSpec.
@@ -489,6 +504,32 @@ if __FILE__ == $0
489
504
  end
490
505
  end
491
506
 
507
+ describe "#api_groups" do
508
+ it "returns a sorted array of group names including the core group" do
509
+ groups = instance.api_groups
510
+ expect(groups).to be_an(Array)
511
+ expect(groups).to eq(groups.sort)
512
+ expect(groups).to include("")
513
+ end
514
+
515
+ it "includes built-in groups, including ones without dots" do
516
+ expect(instance.api_groups).to include("apps", "batch", "rbac.authorization.k8s.io")
517
+ end
518
+
519
+ it "includes groups from the merged CRD definition bundles" do
520
+ expect(instance.api_groups).to include("kubevirt.io", "argoproj.io")
521
+ end
522
+
523
+ it "includes groups from registered custom schemas" do
524
+ Kube::Schema.register("TenantVmClaim",
525
+ schema: { "type" => "object" },
526
+ api_version: "tradeportal.ai/v1")
527
+ expect(instance.api_groups).to include("tradeportal.ai")
528
+ ensure
529
+ Kube::Schema.reset_custom_schemas!
530
+ end
531
+ end
532
+
492
533
  describe "KubeVirt schemas" do
493
534
  it "resolves VirtualMachine" do
494
535
  klass = instance["VirtualMachine"]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kube
4
4
  module Schema
5
- VERSION = "1.10.0"
5
+ VERSION = "1.11.0"
6
6
  end
7
7
  end
data/lib/kube/schema.rb CHANGED
@@ -160,6 +160,16 @@ module Kube
160
160
  schema_versions.last
161
161
  end
162
162
 
163
+ # All API groups known to the default schema version, including any
164
+ # custom schemas registered via .register. The core group is "".
165
+ #
166
+ # Kube::Schema.api_groups # => ["", "apps", "argoproj.io", "batch", ...]
167
+ #
168
+ # @return [Array<String>] sorted, deduplicated group names
169
+ def api_groups
170
+ self[schema_version || DEFAULT_VERSION].api_groups
171
+ end
172
+
163
173
  def has_version?(version)
164
174
  schema_versions.include?(version)
165
175
  end
@@ -314,5 +324,15 @@ if __FILE__ == $0
314
324
  expect(Kube::Schema.has_version?("0.0.1")).to be false
315
325
  end
316
326
  end
327
+
328
+ describe ".api_groups" do
329
+ it "delegates to the default version's instance" do
330
+ expect(Kube::Schema.api_groups).to eq(Kube::Schema[Kube::Schema::DEFAULT_VERSION].api_groups)
331
+ end
332
+
333
+ it "includes core and built-in groups" do
334
+ expect(Kube::Schema.api_groups).to include("", "apps", "batch")
335
+ end
336
+ end
317
337
  end
318
338
  end
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.10.0
4
+ version: 1.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan K