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 { |
| 6 | ClusterIssuer(name): kube._Object("certmanager.k8s.io/v1alpha1", "ClusterIssuer", name) { |
| 7 | spec: error "spec must be defined", |
Sergiusz Bazanski | 4d9e72c | 2019-01-13 22:06:33 +0100 | [diff] [blame] | 8 | }, |
Sergiusz Bazanski | e31d64f | 2019-10-02 20:59:26 +0200 | [diff] [blame] | 9 | Issuer(name): kube._Object("certmanager.k8s.io/v1alpha1", "Issuer", name) { |
| 10 | spec: error "spec must be defined", |
Sergiusz Bazanski | 4d9e72c | 2019-01-13 22:06:33 +0100 | [diff] [blame] | 11 | }, |
Sergiusz Bazanski | e31d64f | 2019-10-02 20:59:26 +0200 | [diff] [blame] | 12 | Certificate(name): kube._Object("certmanager.k8s.io/v1alpha1", "Certificate", name) { |
| 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 | |
Sergiusz Bazanski | 114edc2 | 2020-02-18 22:54:18 +0100 | [diff] [blame] | 35 | CephObjectStoreUser(name): kube._Object("ceph.rook.io/v1", "CephObjectStoreUser", name) { |
| 36 | local user = self, |
| 37 | spec: error "spec must be defined", |
| 38 | |
| 39 | // Name of the secret that contains the login data for this user. |
| 40 | // This secret is created in the same namespace as the ceph cluster, so |
| 41 | // unfortunately you can't really refer to it directly. |
| 42 | // We should write some automation to copy these secrets over in a |
| 43 | // secure way. |
| 44 | secret_name:: "rook-ceph-object-user-%s-%s" % [user.spec.store, user.spec.displayName], |
| 45 | }, |
Sergiusz Bazanski | d436de2 | 2020-02-21 17:10:42 +0100 | [diff] [blame] | 46 | |
| 47 | // Make OpenAPI v3 schema specification less painful. |
| 48 | OpenAPI:: { |
| 49 | Validation(obj):: { |
| 50 | openAPIV3Schema: obj.render, |
| 51 | }, |
| 52 | |
Serge Bazanski | 0b6d5d5 | 2020-08-22 18:59:17 +0000 | [diff] [blame] | 53 | Required(inner):: inner { |
| 54 | required:: true, |
| 55 | }, |
| 56 | |
Sergiusz Bazanski | d436de2 | 2020-02-21 17:10:42 +0100 | [diff] [blame] | 57 | Dict:: { |
| 58 | local dict = self, |
| 59 | required:: false, |
| 60 | |
| 61 | local requiredList = [ |
| 62 | k for k in std.filter(function(k) dict[k].required, std.objectFields(dict)) |
| 63 | ], |
| 64 | |
| 65 | render:: { |
| 66 | properties: { |
| 67 | [k]: dict[k].render |
| 68 | for k in std.objectFields(dict) |
| 69 | }, |
| 70 | } + (if std.length(requiredList) > 0 then { |
| 71 | required: requiredList, |
| 72 | } else {}), |
| 73 | }, |
| 74 | |
| 75 | Array(items):: { |
| 76 | required:: false, |
| 77 | render:: { |
| 78 | type: "array", |
| 79 | items: items.render, |
| 80 | }, |
| 81 | }, |
| 82 | |
| 83 | Integer:: { |
| 84 | local integer = self, |
| 85 | required:: false, |
| 86 | render:: { |
| 87 | type: "integer", |
| 88 | } + (if integer.minimum != null then { |
| 89 | minimum: integer.minimum, |
| 90 | } else {}) + (if integer.maximum != null then { |
| 91 | maximum: integer.maximum, |
| 92 | } else {}), |
| 93 | |
| 94 | minimum:: null, |
| 95 | maximum:: null, |
| 96 | }, |
| 97 | |
| 98 | String:: { |
| 99 | local string = self, |
| 100 | required:: false, |
| 101 | render:: { |
| 102 | type: "string", |
| 103 | } + (if string.pattern != null then { |
| 104 | pattern: string.pattern, |
| 105 | } else {}), |
| 106 | |
| 107 | pattern:: null, |
| 108 | }, |
| 109 | |
| 110 | Boolean:: { |
| 111 | required:: false, |
| 112 | render:: { |
| 113 | type: "boolean", |
| 114 | }, |
| 115 | }, |
| 116 | |
| 117 | Any:: { |
| 118 | required:: false, |
| 119 | render:: {}, |
| 120 | }, |
| 121 | }, |
Sergiusz Bazanski | 4d9e72c | 2019-01-13 22:06:33 +0100 | [diff] [blame] | 122 | } |