blob: 001cfdbd43cceb0e2212884ed2a7f54896c17cb6 [file] [log] [blame]
Sergiusz Bazanskie31d64f2019-10-02 20:59:26 +02001// Local extensions to kube.upstream.libsonnet.
Sergiusz Bazanski4d9e72c2019-01-13 22:06:33 +01002
Sergiusz Bazanskie31d64f2019-10-02 20:59:26 +02003local kube = import "kube.upstream.libsonnet";
Sergiusz Bazanski4d9e72c2019-01-13 22:06:33 +01004
Sergiusz Bazanskie31d64f2019-10-02 20:59:26 +02005kube {
Piotr Dobrowolski7e841062023-04-23 11:36:15 +02006 ClusterIssuer(name): kube._Object("cert-manager.io/v1", "ClusterIssuer", name) {
Sergiusz Bazanskie31d64f2019-10-02 20:59:26 +02007 spec: error "spec must be defined",
Sergiusz Bazanski4d9e72c2019-01-13 22:06:33 +01008 },
Piotr Dobrowolski7e841062023-04-23 11:36:15 +02009 Issuer(name): kube._Object("cert-manager.io/v1", "Issuer", name) {
Sergiusz Bazanskie31d64f2019-10-02 20:59:26 +020010 spec: error "spec must be defined",
Sergiusz Bazanski4d9e72c2019-01-13 22:06:33 +010011 },
Piotr Dobrowolski7e841062023-04-23 11:36:15 +020012 Certificate(name): kube._Object("cert-manager.io/v1", "Certificate", name) {
Sergiusz Bazanskie31d64f2019-10-02 20:59:26 +020013 spec: error "spec must be defined",
Sergiusz Bazanski4d9e72c2019-01-13 22:06:33 +010014 },
Serge Bazanski394dd832020-08-22 18:56:53 +000015 # For use in PodSpec.volumes_
16 CertificateVolume(certificate): {
17 secret: { secretName: certificate.spec.secretName },
18 },
Sergiusz Bazanski114edc22020-02-18 22:54:18 +010019
Serge Bazanski41bbf142021-02-06 18:12:52 +000020 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 Bazanski5a89d222020-08-22 18:57:30 +000025 # 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 Pietruszewskif28cd622023-11-03 17:30:10 +010035 PersistentVolumeClaim(name): kube.PersistentVolumeClaim(name) {
radex4ffc64d2023-11-24 13:28:57 +010036 // Convenience for creating a volume from a PVC
37 volume:: kube.PersistentVolumeClaimVolume(self),
38
39 // Remove deprecated `volume.beta.kubernetes.io/storage-class` annotation
Radek Pietruszewskif28cd622023-11-03 17:30:10 +010040 metadata+: { annotations: {} },
41 },
42
radex4ffc64d2023-11-24 13:28:57 +010043 ConfigMap(name): kube.ConfigMap(name) {
44 // Convenience for creating a volume from a ConfigMap
45 volume:: kube.ConfigMapVolume(self),
46 },
47
radex8b8f3872023-11-24 11:09:46 +010048 // Add `target` field
49 Service(name): kube.Service(name) {
50 // Deployment, Pod, DaemonSet, etc. that this Service is targeting.
51 target:: error "service target must be defined",
52 target_pod:: kube.podRef(self.target),
53 },
54
Sergiusz Bazanski114edc22020-02-18 22:54:18 +010055 CephObjectStoreUser(name): kube._Object("ceph.rook.io/v1", "CephObjectStoreUser", name) {
56 local user = self,
57 spec: error "spec must be defined",
58
59 // Name of the secret that contains the login data for this user.
60 // This secret is created in the same namespace as the ceph cluster, so
61 // unfortunately you can't really refer to it directly.
62 // We should write some automation to copy these secrets over in a
63 // secure way.
64 secret_name:: "rook-ceph-object-user-%s-%s" % [user.spec.store, user.spec.displayName],
65 },
Sergiusz Bazanskid436de22020-02-21 17:10:42 +010066
67 // Make OpenAPI v3 schema specification less painful.
68 OpenAPI:: {
Serge Bazanski9cfc2a02021-09-11 20:07:52 +000069 local openapi = self,
Sergiusz Bazanskid436de22020-02-21 17:10:42 +010070 Validation(obj):: {
71 openAPIV3Schema: obj.render,
72 },
73
Serge Bazanski0b6d5d52020-08-22 18:59:17 +000074 Required(inner):: inner {
75 required:: true,
76 },
77
Serge Bazanski9cfc2a02021-09-11 20:07:52 +000078 renderable:: {
Sergiusz Bazanskid436de22020-02-21 17:10:42 +010079 required:: false,
Serge Bazanski9cfc2a02021-09-11 20:07:52 +000080 render:: {},
81 },
82 local renderable = self.renderable,
83
84 lift(f, keys):: {
85 [if f[k] != null then k]: f[k]
86 for k in keys
87 },
88 local lift = self.lift,
89
90 parametrized(type, keys=[]):: (
91 local keysp = keys + [
92 "description",
93 "nullable",
94 "x-kubernetes-preserve-unknown-fields",
95 ];
96 renderable {
97 render:: lift(self, keysp) {
98 type: type,
99 },
100 } + {
101 [k]: null
102 for k in keysp
103 }
104 ),
105 local parametrized = self.parametrized,
106
107 Any:: renderable,
108 Boolean:: parametrized("boolean"),
109 Integer:: parametrized("integer", ["minimum", "maximum", "format"]),
110 Number:: parametrized("number"),
111 String:: parametrized("string", ["pattern"]),
112
113 Dict:: renderable {
114 local d = self,
Sergiusz Bazanskid436de22020-02-21 17:10:42 +0100115
116 local requiredList = [
Serge Bazanski9cfc2a02021-09-11 20:07:52 +0000117 k for k in std.filter(function(k) d[k].required, std.objectFields(d))
Sergiusz Bazanskid436de22020-02-21 17:10:42 +0100118 ],
119
Serge Bazanski9cfc2a02021-09-11 20:07:52 +0000120 render+: {
Sergiusz Bazanskid436de22020-02-21 17:10:42 +0100121 properties: {
Serge Bazanski9cfc2a02021-09-11 20:07:52 +0000122 [k]: d[k].render
123 for k in std.objectFields(d)
Sergiusz Bazanskid436de22020-02-21 17:10:42 +0100124 },
Serge Bazanski9cfc2a02021-09-11 20:07:52 +0000125 [if std.length(requiredList) > 0 then 'required']: requiredList,
126 },
127 },
128 Object(props={}):: parametrized("object") {
129 local requiredList = [
130 k for k in std.filter(function(k) props[k].required, std.objectFields(props))
131 ],
132
133 render+: {
134 [if std.length(std.objectFields(props)) > 0 then "properties"]: {
135 [k]: props[k].render
136 for k in std.objectFields(props)
137 },
138 [if std.length(requiredList) > 0 then 'required']: requiredList,
139 },
Sergiusz Bazanskid436de22020-02-21 17:10:42 +0100140 },
141
Serge Bazanski9cfc2a02021-09-11 20:07:52 +0000142 Array(items):: parametrized("array") {
143 render+: {
Sergiusz Bazanskid436de22020-02-21 17:10:42 +0100144 items: items.render,
145 },
146 },
147
Serge Bazanski9cfc2a02021-09-11 20:07:52 +0000148 Enum(items):: parametrized("string") {
149 render+: {
150 enum: items,
Sergiusz Bazanskid436de22020-02-21 17:10:42 +0100151 },
152 },
153
Serge Bazanski9cfc2a02021-09-11 20:07:52 +0000154 KubeAny(nullable=false):: self.Object() {
155 [if nullable then "nullable"]: true,
156 "x-kubernetes-preserve-unknown-fields": true,
Sergiusz Bazanskid436de22020-02-21 17:10:42 +0100157 },
158 },
Sergiusz Bazanski4d9e72c2019-01-13 22:06:33 +0100159}