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