blob: ac96451abdc347a498c497c918d23f7a4d53783d [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 // Remove deprecated `volume.beta.kubernetes.io/storage-class` annotation
36 PersistentVolumeClaim(name): kube.PersistentVolumeClaim(name) {
37 metadata+: { annotations: {} },
38 },
39
radex8b8f3872023-11-24 11:09:46 +010040 // 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 Bazanski114edc22020-02-18 22:54:18 +010047 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 Bazanskid436de22020-02-21 17:10:42 +010058
59 // Make OpenAPI v3 schema specification less painful.
60 OpenAPI:: {
Serge Bazanski9cfc2a02021-09-11 20:07:52 +000061 local openapi = self,
Sergiusz Bazanskid436de22020-02-21 17:10:42 +010062 Validation(obj):: {
63 openAPIV3Schema: obj.render,
64 },
65
Serge Bazanski0b6d5d52020-08-22 18:59:17 +000066 Required(inner):: inner {
67 required:: true,
68 },
69
Serge Bazanski9cfc2a02021-09-11 20:07:52 +000070 renderable:: {
Sergiusz Bazanskid436de22020-02-21 17:10:42 +010071 required:: false,
Serge Bazanski9cfc2a02021-09-11 20:07:52 +000072 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 Bazanskid436de22020-02-21 17:10:42 +0100107
108 local requiredList = [
Serge Bazanski9cfc2a02021-09-11 20:07:52 +0000109 k for k in std.filter(function(k) d[k].required, std.objectFields(d))
Sergiusz Bazanskid436de22020-02-21 17:10:42 +0100110 ],
111
Serge Bazanski9cfc2a02021-09-11 20:07:52 +0000112 render+: {
Sergiusz Bazanskid436de22020-02-21 17:10:42 +0100113 properties: {
Serge Bazanski9cfc2a02021-09-11 20:07:52 +0000114 [k]: d[k].render
115 for k in std.objectFields(d)
Sergiusz Bazanskid436de22020-02-21 17:10:42 +0100116 },
Serge Bazanski9cfc2a02021-09-11 20:07:52 +0000117 [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 Bazanskid436de22020-02-21 17:10:42 +0100132 },
133
Serge Bazanski9cfc2a02021-09-11 20:07:52 +0000134 Array(items):: parametrized("array") {
135 render+: {
Sergiusz Bazanskid436de22020-02-21 17:10:42 +0100136 items: items.render,
137 },
138 },
139
Serge Bazanski9cfc2a02021-09-11 20:07:52 +0000140 Enum(items):: parametrized("string") {
141 render+: {
142 enum: items,
Sergiusz Bazanskid436de22020-02-21 17:10:42 +0100143 },
144 },
145
Serge Bazanski9cfc2a02021-09-11 20:07:52 +0000146 KubeAny(nullable=false):: self.Object() {
147 [if nullable then "nullable"]: true,
148 "x-kubernetes-preserve-unknown-fields": true,
Sergiusz Bazanskid436de22020-02-21 17:10:42 +0100149 },
150 },
Sergiusz Bazanski4d9e72c2019-01-13 22:06:33 +0100151}