Sergiusz Bazanski | e31d64f | 2019-10-02 20:59:26 +0200 | [diff] [blame] | 1 | // Local extensions to kube.upstream.libsonnet. |
Sergiusz Bazanski | 4d9e72c | 2019-01-13 22:06:33 +0100 | [diff] [blame] | 2 | |
Sergiusz Bazanski | e31d64f | 2019-10-02 20:59:26 +0200 | [diff] [blame] | 3 | local kube = import "kube.upstream.libsonnet"; |
Sergiusz Bazanski | 4d9e72c | 2019-01-13 22:06:33 +0100 | [diff] [blame] | 4 | |
Sergiusz Bazanski | e31d64f | 2019-10-02 20:59:26 +0200 | [diff] [blame] | 5 | kube { |
Piotr Dobrowolski | 7e84106 | 2023-04-23 11:36:15 +0200 | [diff] [blame] | 6 | ClusterIssuer(name): kube._Object("cert-manager.io/v1", "ClusterIssuer", name) { |
Sergiusz Bazanski | e31d64f | 2019-10-02 20:59:26 +0200 | [diff] [blame] | 7 | spec: error "spec must be defined", |
Sergiusz Bazanski | 4d9e72c | 2019-01-13 22:06:33 +0100 | [diff] [blame] | 8 | }, |
Piotr Dobrowolski | 7e84106 | 2023-04-23 11:36:15 +0200 | [diff] [blame] | 9 | Issuer(name): kube._Object("cert-manager.io/v1", "Issuer", name) { |
Sergiusz Bazanski | e31d64f | 2019-10-02 20:59:26 +0200 | [diff] [blame] | 10 | spec: error "spec must be defined", |
Sergiusz Bazanski | 4d9e72c | 2019-01-13 22:06:33 +0100 | [diff] [blame] | 11 | }, |
Piotr Dobrowolski | 7e84106 | 2023-04-23 11:36:15 +0200 | [diff] [blame] | 12 | Certificate(name): kube._Object("cert-manager.io/v1", "Certificate", name) { |
Sergiusz Bazanski | e31d64f | 2019-10-02 20:59:26 +0200 | [diff] [blame] | 13 | spec: error "spec must be defined", |
Sergiusz Bazanski | 4d9e72c | 2019-01-13 22:06:33 +0100 | [diff] [blame] | 14 | }, |
Serge Bazanski | 394dd83 | 2020-08-22 18:56:53 +0000 | [diff] [blame] | 15 | # For use in PodSpec.volumes_ |
| 16 | CertificateVolume(certificate): { |
| 17 | secret: { secretName: certificate.spec.secretName }, |
| 18 | }, |
Sergiusz Bazanski | 114edc2 | 2020-02-18 22:54:18 +0100 | [diff] [blame] | 19 | |
Serge Bazanski | 41bbf14 | 2021-02-06 18:12:52 +0000 | [diff] [blame] | 20 | ValidatingWebhookConfiguration(name): kube._Object("admissionregistration.k8s.io/v1", "ValidatingWebhookConfiguration", name) { |
| 21 | webhooks_:: error "webhooks_ must be defined", |
| 22 | webhooks: kube.mapToNamedList(self.webhooks_), |
| 23 | }, |
| 24 | |
Serge Bazanski | 5a89d22 | 2020-08-22 18:57:30 +0000 | [diff] [blame] | 25 | # Add .Contain method to Namespaces, allowing for easy marking of particular |
| 26 | # kube objects as contained in that namespace. |
| 27 | Namespace(name): kube.Namespace(name) { |
| 28 | Contain(o):: o { |
| 29 | metadata+: { |
| 30 | namespace: name, |
| 31 | }, |
| 32 | }, |
| 33 | }, |
| 34 | |
Radek Pietruszewski | f28cd62 | 2023-11-03 17:30:10 +0100 | [diff] [blame] | 35 | // Remove deprecated `volume.beta.kubernetes.io/storage-class` annotation |
| 36 | PersistentVolumeClaim(name): kube.PersistentVolumeClaim(name) { |
| 37 | metadata+: { annotations: {} }, |
| 38 | }, |
| 39 | |
radex | 8b8f387 | 2023-11-24 11:09:46 +0100 | [diff] [blame^] | 40 | // Add `target` field |
| 41 | Service(name): kube.Service(name) { |
| 42 | // Deployment, Pod, DaemonSet, etc. that this Service is targeting. |
| 43 | target:: error "service target must be defined", |
| 44 | target_pod:: kube.podRef(self.target), |
| 45 | }, |
| 46 | |
Sergiusz Bazanski | 114edc2 | 2020-02-18 22:54:18 +0100 | [diff] [blame] | 47 | CephObjectStoreUser(name): kube._Object("ceph.rook.io/v1", "CephObjectStoreUser", name) { |
| 48 | local user = self, |
| 49 | spec: error "spec must be defined", |
| 50 | |
| 51 | // Name of the secret that contains the login data for this user. |
| 52 | // This secret is created in the same namespace as the ceph cluster, so |
| 53 | // unfortunately you can't really refer to it directly. |
| 54 | // We should write some automation to copy these secrets over in a |
| 55 | // secure way. |
| 56 | secret_name:: "rook-ceph-object-user-%s-%s" % [user.spec.store, user.spec.displayName], |
| 57 | }, |
Sergiusz Bazanski | d436de2 | 2020-02-21 17:10:42 +0100 | [diff] [blame] | 58 | |
| 59 | // Make OpenAPI v3 schema specification less painful. |
| 60 | OpenAPI:: { |
Serge Bazanski | 9cfc2a0 | 2021-09-11 20:07:52 +0000 | [diff] [blame] | 61 | local openapi = self, |
Sergiusz Bazanski | d436de2 | 2020-02-21 17:10:42 +0100 | [diff] [blame] | 62 | Validation(obj):: { |
| 63 | openAPIV3Schema: obj.render, |
| 64 | }, |
| 65 | |
Serge Bazanski | 0b6d5d5 | 2020-08-22 18:59:17 +0000 | [diff] [blame] | 66 | Required(inner):: inner { |
| 67 | required:: true, |
| 68 | }, |
| 69 | |
Serge Bazanski | 9cfc2a0 | 2021-09-11 20:07:52 +0000 | [diff] [blame] | 70 | renderable:: { |
Sergiusz Bazanski | d436de2 | 2020-02-21 17:10:42 +0100 | [diff] [blame] | 71 | required:: false, |
Serge Bazanski | 9cfc2a0 | 2021-09-11 20:07:52 +0000 | [diff] [blame] | 72 | render:: {}, |
| 73 | }, |
| 74 | local renderable = self.renderable, |
| 75 | |
| 76 | lift(f, keys):: { |
| 77 | [if f[k] != null then k]: f[k] |
| 78 | for k in keys |
| 79 | }, |
| 80 | local lift = self.lift, |
| 81 | |
| 82 | parametrized(type, keys=[]):: ( |
| 83 | local keysp = keys + [ |
| 84 | "description", |
| 85 | "nullable", |
| 86 | "x-kubernetes-preserve-unknown-fields", |
| 87 | ]; |
| 88 | renderable { |
| 89 | render:: lift(self, keysp) { |
| 90 | type: type, |
| 91 | }, |
| 92 | } + { |
| 93 | [k]: null |
| 94 | for k in keysp |
| 95 | } |
| 96 | ), |
| 97 | local parametrized = self.parametrized, |
| 98 | |
| 99 | Any:: renderable, |
| 100 | Boolean:: parametrized("boolean"), |
| 101 | Integer:: parametrized("integer", ["minimum", "maximum", "format"]), |
| 102 | Number:: parametrized("number"), |
| 103 | String:: parametrized("string", ["pattern"]), |
| 104 | |
| 105 | Dict:: renderable { |
| 106 | local d = self, |
Sergiusz Bazanski | d436de2 | 2020-02-21 17:10:42 +0100 | [diff] [blame] | 107 | |
| 108 | local requiredList = [ |
Serge Bazanski | 9cfc2a0 | 2021-09-11 20:07:52 +0000 | [diff] [blame] | 109 | k for k in std.filter(function(k) d[k].required, std.objectFields(d)) |
Sergiusz Bazanski | d436de2 | 2020-02-21 17:10:42 +0100 | [diff] [blame] | 110 | ], |
| 111 | |
Serge Bazanski | 9cfc2a0 | 2021-09-11 20:07:52 +0000 | [diff] [blame] | 112 | render+: { |
Sergiusz Bazanski | d436de2 | 2020-02-21 17:10:42 +0100 | [diff] [blame] | 113 | properties: { |
Serge Bazanski | 9cfc2a0 | 2021-09-11 20:07:52 +0000 | [diff] [blame] | 114 | [k]: d[k].render |
| 115 | for k in std.objectFields(d) |
Sergiusz Bazanski | d436de2 | 2020-02-21 17:10:42 +0100 | [diff] [blame] | 116 | }, |
Serge Bazanski | 9cfc2a0 | 2021-09-11 20:07:52 +0000 | [diff] [blame] | 117 | [if std.length(requiredList) > 0 then 'required']: requiredList, |
| 118 | }, |
| 119 | }, |
| 120 | Object(props={}):: parametrized("object") { |
| 121 | local requiredList = [ |
| 122 | k for k in std.filter(function(k) props[k].required, std.objectFields(props)) |
| 123 | ], |
| 124 | |
| 125 | render+: { |
| 126 | [if std.length(std.objectFields(props)) > 0 then "properties"]: { |
| 127 | [k]: props[k].render |
| 128 | for k in std.objectFields(props) |
| 129 | }, |
| 130 | [if std.length(requiredList) > 0 then 'required']: requiredList, |
| 131 | }, |
Sergiusz Bazanski | d436de2 | 2020-02-21 17:10:42 +0100 | [diff] [blame] | 132 | }, |
| 133 | |
Serge Bazanski | 9cfc2a0 | 2021-09-11 20:07:52 +0000 | [diff] [blame] | 134 | Array(items):: parametrized("array") { |
| 135 | render+: { |
Sergiusz Bazanski | d436de2 | 2020-02-21 17:10:42 +0100 | [diff] [blame] | 136 | items: items.render, |
| 137 | }, |
| 138 | }, |
| 139 | |
Serge Bazanski | 9cfc2a0 | 2021-09-11 20:07:52 +0000 | [diff] [blame] | 140 | Enum(items):: parametrized("string") { |
| 141 | render+: { |
| 142 | enum: items, |
Sergiusz Bazanski | d436de2 | 2020-02-21 17:10:42 +0100 | [diff] [blame] | 143 | }, |
| 144 | }, |
| 145 | |
Serge Bazanski | 9cfc2a0 | 2021-09-11 20:07:52 +0000 | [diff] [blame] | 146 | KubeAny(nullable=false):: self.Object() { |
| 147 | [if nullable then "nullable"]: true, |
| 148 | "x-kubernetes-preserve-unknown-fields": true, |
Sergiusz Bazanski | d436de2 | 2020-02-21 17:10:42 +0100 | [diff] [blame] | 149 | }, |
| 150 | }, |
Sergiusz Bazanski | 4d9e72c | 2019-01-13 22:06:33 +0100 | [diff] [blame] | 151 | } |