kube_schema 1.3.1 → 1.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2fbfd3f44c5ebc57a3d43c6baac8be1b64c7feed0e8c9657c951cfd530013fa
4
- data.tar.gz: b0057e0e43fe1160f6ad166dc28f204e4e9870c76457db5a980556ac883200c5
3
+ metadata.gz: 193f973be41e7f42709ecf8d2407d47d7200ab399a441563b34342149f759956
4
+ data.tar.gz: 3a931d60cf56e1d03ed9a25eee098978a1e6f647113dc22f05f1858d0d03e045
5
5
  SHA512:
6
- metadata.gz: 8314abd9a04c46ea3b1a2de5e5d27bbf05fb891b518881585b66d252f3a00a2cf38f33ad795a330d6477e5318edfa2ed5cdc0e6df63f06ec1f54a6a6e0629f69
7
- data.tar.gz: facee27eab8f920216f537d14a1b403843cda17cb0ddf87980542e9693be2a219ea4ccb58d48665bda977554c7bc51b6d17fd7c1c82ad9283d3bfdc9c1def3ac
6
+ metadata.gz: d789cd2fe143a465f645f73fb7d6ecc0882ace1bbaadca2513b26053efff52bd1c162aff2fe43ee25e0bd600024366db92a221b855562d3eef4b44025f691daf
7
+ data.tar.gz: 94642b199d333cb7da54cc324c0ee29641431bcc4884e38b7e24e6d47eb97f886ece7f680f3923c336c62a55ff171d247d8578abde94e10cee0c5eda8a8759a6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kube_schema (1.3.1)
4
+ kube_schema (1.3.3)
5
5
  json_schemer (~> 2.5.0)
6
6
  rubyshell (~> 1.5.0)
7
7
 
@@ -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