kube_schema 1.4.2 → 1.4.4

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.
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.4.2
4
+ version: 1.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan K
@@ -91,6 +91,7 @@ extra_rdoc_files: []
91
91
  files:
92
92
  - ".envrc"
93
93
  - ".github/workflows/convert-schemas.yml"
94
+ - ".github/workflows/gh-pages.yml"
94
95
  - ".github/workflows/update-crds-catalog.yml"
95
96
  - ".github/workflows/update-schema-index.yml"
96
97
  - ".github/workflows/update-schemas.yml"
@@ -98,7 +99,6 @@ files:
98
99
  - ".rubocop.yml"
99
100
  - Gemfile
100
101
  - Gemfile.lock
101
- - README.md
102
102
  - Rakefile
103
103
  - assets/validation-error.png
104
104
  - bin/console
@@ -117,6 +117,12 @@ files:
117
117
  - examples/vcluster.rb
118
118
  - flake.lock
119
119
  - flake.nix
120
+ - guides/block-dsl/readme.md
121
+ - guides/getting-started/readme.md
122
+ - guides/links.yaml
123
+ - guides/manifests/readme.md
124
+ - guides/schema-versions/readme.md
125
+ - guides/validation/readme.md
120
126
  - kube_schema.gemspec
121
127
  - lib/kube/errors.rb
122
128
  - lib/kube/monkey_patches.rb
@@ -127,6 +133,7 @@ files:
127
133
  - lib/kube/schema/sub_spec.rb
128
134
  - lib/kube/schema/version.rb
129
135
  - lib/kube/schema/version.rb.erb
136
+ - readme.md
130
137
  - schemas/crd-definitions.json
131
138
  - schemas/kubevirt-definitions.json
132
139
  - schemas/loft-definitions.json
@@ -144,7 +151,7 @@ licenses:
144
151
  metadata:
145
152
  homepage_uri: https://github.com/general-intelligence-systems/kube_schema
146
153
  source_code_uri: https://github.com/general-intelligence-systems/kube_schema
147
- documentation_uri: https://github.com/general-intelligence-systems/kube_schema
154
+ documentation_uri: https://general-intelligence-systems.github.io/kube_schema/
148
155
  rubygems_mfa_required: 'true'
149
156
  rdoc_options: []
150
157
  require_paths:
data/README.md DELETED
@@ -1,259 +0,0 @@
1
- # kube_schema
2
-
3
- Ruby objects for every Kubernetes resource. Validated against the real OpenAPI spec.
4
-
5
- ```ruby
6
- Kube::Schema["Deployment"].new {
7
- metadata.name = "web"
8
- metadata.namespace = "prod"
9
- spec.replicas = 3
10
- spec.template.spec.containers = [
11
- { name: "app", image: "nginx:1.27", ports: [{ containerPort: 80 }] }
12
- ]
13
- }
14
- ```
15
-
16
- No YAML. No hash literals. Just Ruby blocks that know their schema.
17
-
18
- ## Contents
19
-
20
- - [Install](#install)
21
- - [Resources](#resources)
22
- - [The block DSL](#the-block-dsl)
23
- - [Subclassing](#subclassing)
24
- - [Validation](#validation)
25
- - [Error messages](#error-messages)
26
- - [Manifests](#manifests)
27
- - [File I/O](#file-io)
28
- - [Composition](#composition)
29
- - [Enumerable](#enumerable)
30
- - [Schema versions](#schema-versions)
31
- - [Related projects](#related-projects)
32
- - [Built with](#built-with)
33
-
34
- ## Install
35
-
36
- ```
37
- gem install kube_schema
38
- ```
39
-
40
- ## Resources
41
-
42
- Every Kubernetes kind is a class. Fetch it by name.
43
-
44
- ```ruby
45
- Kube::Schema["Deployment"] # => Class < Kube::Schema::Resource
46
- Kube::Schema["Service"]
47
- Kube::Schema["ConfigMap"]
48
- Kube::Schema["NetworkPolicy"]
49
- ```
50
-
51
- Specific versions:
52
-
53
- ```ruby
54
- Kube::Schema["1.34"]["Deployment"]
55
- Kube::Schema["1.31"]["Pod"]
56
- ```
57
-
58
- Discovery:
59
-
60
- ```ruby
61
- Kube::Schema.schema_versions # => ["1.19", "1.20", ..., "1.35"]
62
- Kube::Schema.latest_version # => "1.35"
63
-
64
- Kube::Schema["1.34"].list_resources
65
- # => ["Binding", "CSIDriver", "ConfigMap", "Deployment", ...]
66
- ```
67
-
68
- ## The block DSL
69
-
70
- Nested attributes just work. No intermediate hashes, no string keys.
71
-
72
- ```ruby
73
- deploy = Kube::Schema["Deployment"].new {
74
- metadata.name = "web"
75
- metadata.namespace = "prod"
76
- metadata.labels = { app: "web" }
77
-
78
- spec.replicas = 3
79
- spec.selector.matchLabels = { app: "web" }
80
-
81
- spec.template.metadata.labels = { app: "web" }
82
- spec.template.spec.containers = [
83
- { name: "app", image: "nginx:1.27", ports: [{ containerPort: 80 }] }
84
- ]
85
- }
86
- ```
87
-
88
- `apiVersion` and `kind` are derived from the schema automatically:
89
-
90
- ```ruby
91
- deploy.to_h[:apiVersion] # => "apps/v1"
92
- deploy.to_h[:kind] # => "Deployment"
93
- ```
94
-
95
- ## Subclassing
96
-
97
- ```ruby
98
- class RailsApp < Kube::Schema["Deployment"]
99
- def default_image
100
- "ruby:3.4"
101
- end
102
- end
103
-
104
- app = RailsApp.new {
105
- metadata.name = "rails"
106
- spec.template.spec.containers = [
107
- { name: "web", image: "myapp:latest" }
108
- ]
109
- }
110
-
111
- app.default_image # => "ruby:3.4"
112
- app.valid? # => true
113
- ```
114
-
115
- ## Validation
116
-
117
- Every resource validates against the full Kubernetes OpenAPI spec.
118
-
119
- ```ruby
120
- deploy.valid? # => true
121
-
122
- bad = Kube::Schema["Deployment"].new {
123
- self.apiVersion = 12345
124
- }
125
-
126
- bad.valid? # => false
127
-
128
- bad.valid!
129
- # Kube::ValidationError: Schema validation failed for Deployment:
130
- # - apiVersion = 12345 — expected string, got Integer
131
- ```
132
-
133
- `to_yaml` refuses to serialize invalid resources:
134
-
135
- ```ruby
136
- bad.to_yaml # raises Kube::ValidationError
137
- ```
138
-
139
- ## Error messages
140
-
141
- Validation errors render annotated YAML with color-coded diagnostics. Error lines are highlighted in red, missing required keys are injected inline, and each problem gets a clear explanation:
142
-
143
- ![Validation error output](assets/validation-error.png)
144
-
145
- ## Manifests
146
-
147
- Group resources into multi-document YAML.
148
-
149
- ```ruby
150
- manifest = Kube::Schema::Manifest.new
151
-
152
- manifest << Kube::Schema["Namespace"].new {
153
- metadata.name = "prod"
154
- }
155
-
156
- manifest << Kube::Schema["Deployment"].new {
157
- metadata.name = "web"
158
- metadata.namespace = "prod"
159
- spec.replicas = 3
160
- spec.template.spec.containers = [
161
- { name: "app", image: "nginx:1.27" }
162
- ]
163
- }
164
-
165
- manifest << Kube::Schema["Service"].new {
166
- metadata.name = "web"
167
- metadata.namespace = "prod"
168
- spec.selector = { app: "web" }
169
- spec.ports = [{ port: 80, targetPort: 8080 }]
170
- }
171
-
172
- puts manifest.to_yaml
173
- ```
174
-
175
- ```yaml
176
- ---
177
- apiVersion: v1
178
- kind: Namespace
179
- metadata:
180
- name: prod
181
- ---
182
- apiVersion: apps/v1
183
- kind: Deployment
184
- metadata:
185
- name: web
186
- namespace: prod
187
- spec:
188
- replicas: 3
189
- ...
190
- ---
191
- apiVersion: v1
192
- kind: Service
193
- metadata:
194
- name: web
195
- namespace: prod
196
- spec:
197
- selector:
198
- app: web
199
- ports:
200
- - port: 80
201
- targetPort: 8080
202
- ```
203
-
204
- ### File I/O
205
-
206
- ```ruby
207
- # Write
208
- manifest.write("cluster.yaml")
209
-
210
- # Read
211
- loaded = Kube::Schema::Manifest.open("cluster.yaml")
212
-
213
- # Modify and write back
214
- loaded << new_resource
215
- loaded.write
216
- ```
217
-
218
- ### Composition
219
-
220
- Manifests flatten into each other. No nesting.
221
-
222
- ```ruby
223
- infra = Kube::Schema::Manifest.new(namespace, configmap, secret)
224
- app = Kube::Schema::Manifest.new(deployment, service)
225
-
226
- combined = Kube::Schema::Manifest.new
227
- combined << infra
228
- combined << app
229
- combined.size # => 5
230
- ```
231
-
232
- ### Enumerable
233
-
234
- ```ruby
235
- manifest.map { |r| r.to_h[:kind] }
236
- manifest.select { |r| r.to_h[:kind] == "Service" }
237
- manifest.any? { |r| r.to_h[:kind] == "Pod" }
238
- manifest.count
239
- ```
240
-
241
- ## Schema versions
242
-
243
- Bundled schemas ship with the gem for Kubernetes 1.19 through 1.35. Updated automatically via CI.
244
-
245
- ```ruby
246
- Kube::Schema.schema_version = "1.31"
247
- Kube::Schema["Deployment"] # uses 1.31
248
- ```
249
-
250
- ## Related projects
251
-
252
- - [kube_cluster](https://github.com/general-intelligence-systems/kube_cluster) -- OOP resource management with dirty tracking and persistence
253
- - [kube_kubectl](https://github.com/general-intelligence-systems/kube_ctl) -- Ruby DSL that compiles to kubectl and helm commands
254
- - [kube_kit](https://github.com/general-intelligence-systems/kube_kit) -- Generators for kube_cluster projects
255
- - [kube_engine](https://github.com/general-intelligence-systems/kube_engine) -- Kubernetes engine
256
-
257
- ## Built with
258
-
259
- [black_hole_struct](https://github.com/aanand/black_hole_struct) -- the dynamic nested struct that powers the block DSL. [json_schemer](https://github.com/davishmcclurg/json_schemer) -- JSON Schema validation against the real Kubernetes OpenAPI specs.