kube_schema 1.3.0 → 1.3.2

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: a64ba0fa243fdc3e23dca962d97a3d873c1f4318ca826a1d8515fc6ec83b5a4e
4
- data.tar.gz: 96a9ce7903fa13f375888e321e3669ce7f1cbc07fc31530cf7ed7d2b6f46f188
3
+ metadata.gz: d74795f238283bb03bba7c2a82459475512cf3922704870aa2256f6235410d66
4
+ data.tar.gz: 19d329b7abbad3dbf5d37daa8202a457ec14c26f23a078bafaf1e1f10c67abe1
5
5
  SHA512:
6
- metadata.gz: 2f02c6ce6cf47818f14b48de5665a1cf11c31427c3f3feed312ea61234dff2f222ea7106ea91cc38e939261e445878acffb636f47780718cad93c3866146ceb9
7
- data.tar.gz: a0cf6d5328ae0288d9caecae9b5417550d1945b18c4ef0e090f175f2abddbf9f8e395b5ebdddcc685df398270a66a4b620d5115aa547f2172eb8cf44e14b62c6
6
+ metadata.gz: f11cfd8ce0f92d2c7b824eba56559860a95eca65e2c13ffbcd8177f296b26fabcf395fb66c16d8d4533fbb188e81698f4560d8f3a5f08d2536b2a8d36557eff7
7
+ data.tar.gz: 7af51b827644818da72e031e858f47697678dc8d97929c7d2e5bfcd964e2202ede1507f0f20e63ba64dec6a2bebdb0e2128a99a0085fa3562ce3fac1a8d241d0
data/Gemfile.lock CHANGED
@@ -1,17 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kube_schema (1.2.3)
5
- black_hole_struct (~> 0.1)
6
- json_schemer (~> 2.5)
7
- rubyshell (~> 1.5)
4
+ kube_schema (1.3.1)
5
+ json_schemer (~> 2.5.0)
6
+ rubyshell (~> 1.5.0)
8
7
 
9
8
  GEM
10
9
  remote: https://rubygems.org/
11
10
  specs:
12
11
  ast (2.4.3)
13
12
  bigdecimal (4.1.2)
14
- black_hole_struct (0.1.3)
15
13
  diff-lcs (1.6.2)
16
14
  hana (1.3.7)
17
15
  json (2.19.3)
@@ -2,6 +2,7 @@
2
2
  mkdir -p schemas
3
3
 
4
4
  git show schemas2:data/crds/05-crd-only-definitions.json > schemas/crd-definitions.json
5
+ git show schemas2:data/crds/07-loft-definitions.json > schemas/loft-definitions.json
5
6
 
6
7
  git ls-tree --name-only schemas2 data/k8s.io/ | while read -r path; do
7
8
  git show "schemas2:$path" > "schemas/$(basename "$path")"
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Register custom CRD schemas from datreeio/CRDs-catalog
5
+ # https://github.com/datreeio/CRDs-catalog
6
+
7
+ require_relative "../lib/kube/schema"
8
+ require "open-uri"
9
+ require "json"
10
+ require "tmpdir"
11
+
12
+ CATALOG = "https://raw.githubusercontent.com/datreeio/CRDs-catalog/main"
13
+ CACHE = "/tmp/crds-catalog"
14
+
15
+ Dir.mkdir(CACHE) unless Dir.exist?(CACHE)
16
+
17
+ # Download and register schemas
18
+ {
19
+ "Certificate" => ["cert-manager.io/certificate_v1.json", "cert-manager.io/v1"],
20
+ "Application" => ["argoproj.io/application_v1alpha1.json", "argoproj.io/v1alpha1"],
21
+ "PrometheusRule" => ["monitoring.coreos.com/prometheusrule_v1.json", "monitoring.coreos.com/v1"],
22
+ "ExternalSecret" => ["external-secrets.io/externalsecret_v1beta1.json", "external-secrets.io/v1beta1"],
23
+ "ScaledObject" => ["keda.sh/scaledobject_v1alpha1.json", "keda.sh/v1alpha1"],
24
+ }.each do |kind, (path, api_version)|
25
+ local = File.join(CACHE, File.basename(path))
26
+ URI.open("#{CATALOG}/#{path}") { |f| File.write(local, f.read) } unless File.exist?(local)
27
+ Kube::Schema.register(kind, schema: local, api_version: api_version)
28
+ end
29
+
30
+
31
+ # ── Use them alongside built-in k8s types ─────────────────────
32
+
33
+ manifest = Kube::Schema::Manifest.new
34
+
35
+ manifest << Kube::Schema["Namespace"].new {
36
+ metadata.name = "prod"
37
+ }
38
+
39
+ manifest << Kube::Schema["Deployment"].new {
40
+ metadata.name = "web"
41
+ metadata.namespace = "prod"
42
+ spec.replicas = 3
43
+ spec.selector = { matchLabels: { app: "web" } }
44
+ spec.template.metadata = { labels: { app: "web" } }
45
+ spec.template.spec.containers = [
46
+ { name: "app", image: "nginx:1.27", ports: [{ containerPort: 80 }] }
47
+ ]
48
+ }
49
+
50
+ manifest << Kube::Schema["Certificate"].new {
51
+ metadata.name = "web-tls"
52
+ metadata.namespace = "prod"
53
+ spec.secretName = "web-tls-secret"
54
+ spec.issuerRef = { name: "letsencrypt-prod", kind: "ClusterIssuer" }
55
+ spec.dnsNames = ["example.com", "www.example.com"]
56
+ }
57
+
58
+ manifest << Kube::Schema["Application"].new {
59
+ metadata.name = "web"
60
+ metadata.namespace = "argocd"
61
+ spec.project = "default"
62
+ spec.source = {
63
+ repoURL: "https://github.com/example/web.git",
64
+ targetRevision: "HEAD",
65
+ path: "k8s/production"
66
+ }
67
+ spec.destination = {
68
+ server: "https://kubernetes.default.svc",
69
+ namespace: "prod"
70
+ }
71
+ spec.syncPolicy = {
72
+ automated: { prune: true, selfHeal: true }
73
+ }
74
+ }
75
+
76
+ manifest << Kube::Schema["ExternalSecret"].new {
77
+ metadata.name = "db-creds"
78
+ metadata.namespace = "prod"
79
+ spec.refreshInterval = "1h"
80
+ spec.secretStoreRef = { name: "aws-sm", kind: "ClusterSecretStore" }
81
+ spec.target = { name: "db-creds", creationPolicy: "Owner" }
82
+ spec.data = [
83
+ { secretKey: "password", remoteRef: { key: "prod/db", property: "password" } }
84
+ ]
85
+ }
86
+
87
+ manifest << Kube::Schema["ScaledObject"].new {
88
+ metadata.name = "web-scaler"
89
+ metadata.namespace = "prod"
90
+ spec.scaleTargetRef = { name: "web" }
91
+ spec.minReplicaCount = 2
92
+ spec.maxReplicaCount = 20
93
+ spec.triggers = [
94
+ { type: "prometheus", metadata: {
95
+ serverAddress: "http://prometheus:9090",
96
+ query: 'sum(rate(http_requests_total{app="web"}[2m]))',
97
+ threshold: "100"
98
+ }}
99
+ ]
100
+ }
101
+
102
+ manifest << Kube::Schema["PrometheusRule"].new {
103
+ metadata.name = "web-alerts"
104
+ metadata.namespace = "monitoring"
105
+ spec.groups = [{
106
+ name: "web.rules",
107
+ rules: [{
108
+ alert: "HighErrorRate",
109
+ expr: 'rate(http_requests_total{status=~"5.."}[5m]) > 0.1',
110
+ "for": "5m",
111
+ labels: { severity: "critical" },
112
+ annotations: { summary: "High 5xx error rate on web" }
113
+ }]
114
+ }]
115
+ }
116
+
117
+ puts manifest.to_yaml