This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
/
kube.libsonnet
778 lines (665 loc) · 22.5 KB
/
kube.libsonnet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
// Generic library of Kubernetes objects (https://github.com/bitnami-labs/kube-libsonnet)
//
// Objects in this file follow the regular Kubernetes API object
// schema with two exceptions:
//
// ## Optional helpers
//
// A few objects have defaults or additional "helper" hidden
// (double-colon) fields that will help with common situations. For
// example, `Service.target_pod` generates suitable `selector` and
// `ports` blocks for the common case of a single-pod/single-port
// service. If for some reason you don't want the helper, just
// provide explicit values for the regular Kubernetes fields that the
// helper *would* have generated, and the helper logic will be
// ignored.
//
// ## The Underscore Convention:
//
// Various constructs in the Kubernetes API use JSON arrays to
// represent unordered sets or named key/value maps. This is
// particularly annoying with jsonnet since we want to use jsonnet's
// powerful object merge operation with these constructs.
//
// To combat this, this library attempts to provide more "jsonnet
// native" variants of these arrays in alternative hidden fields that
// end with an underscore. For example, the `env_` block in
// `Container`:
// ```
// kube.Container("foo") {
// env_: { FOO: "bar" },
// }
// ```
// ... produces the expected `container.env` JSON array:
// ```
// {
// "env": [
// { "name": "FOO", "value": "bar" }
// ]
// }
// ```
//
// If you are confused by the underscore versions, or don't want them
// in your situation then just ignore them and set the regular
// non-underscore field as usual.
//
//
// ## TODO
//
// TODO: Expand this to include all API objects.
//
// Should probably fill out all the defaults here too, so jsonnet can
// reference them. In addition, jsonnet validation is more useful
// (client-side, and gives better line information).
{
// In case you may want/need to skip assertions for speed reasons (rather big configmaps/etc),
// load the library with e.g.
// local kube = (import "lib/kube.libsonnet") { _assert:: false };
_assert:: true,
// resource contructors will use kinds/versions/fields compatible at least with version:
minKubeVersion: {
major: 1,
minor: 19,
version: "%s.%s" % [self.major, self.minor],
},
// Returns array of values from given object. Does not include hidden fields.
objectValues(o):: [o[field] for field in std.objectFields(o)],
// Returns array of [key, value] pairs from given object. Does not include hidden fields.
objectItems(o):: [[k, o[k]] for k in std.objectFields(o)],
// Replace all occurrences of `_` with `-`.
hyphenate(s):: std.join("-", std.split(s, "_")),
// Convert an octal (as a string) to number,
parseOctal(s):: (
local len = std.length(s);
local leading = std.substr(s, 0, len - 1);
local last = std.parseInt(std.substr(s, len - 1, 1));
assert (!$._assert) || last < 8 : "found '%s' digit >= 8" % [last];
last + (if len > 1 then 8 * $.parseOctal(leading) else 0)
),
// Convert {foo: {a: b}} to [{name: foo, a: b}]
mapToNamedList(o):: [{ name: $.hyphenate(n) } + o[n] for n in std.objectFields(o)],
// Return object containing only these fields elements
filterMapByFields(o, fields): { [field]: o[field] for field in std.setInter(std.objectFields(o), fields) },
// Convert from SI unit suffixes to regular number
siToNum(n):: (
local convert =
if std.endsWith(n, "m") then [1, 0.001]
else if std.endsWith(n, "K") then [1, 1e3]
else if std.endsWith(n, "M") then [1, 1e6]
else if std.endsWith(n, "G") then [1, 1e9]
else if std.endsWith(n, "T") then [1, 1e12]
else if std.endsWith(n, "P") then [1, 1e15]
else if std.endsWith(n, "E") then [1, 1e18]
else if std.endsWith(n, "Ki") then [2, std.pow(2, 10)]
else if std.endsWith(n, "Mi") then [2, std.pow(2, 20)]
else if std.endsWith(n, "Gi") then [2, std.pow(2, 30)]
else if std.endsWith(n, "Ti") then [2, std.pow(2, 40)]
else if std.endsWith(n, "Pi") then [2, std.pow(2, 50)]
else if std.endsWith(n, "Ei") then [2, std.pow(2, 60)]
else error "Unknown numerical suffix in " + n;
local n_len = std.length(n);
std.parseInt(std.substr(n, 0, n_len - convert[0])) * convert[1]
),
local remap(v, start, end, newstart) =
if v >= start && v <= end then v - start + newstart else v,
local remapChar(c, start, end, newstart) =
std.char(remap(
std.codepoint(c), std.codepoint(start), std.codepoint(end), std.codepoint(newstart)
)),
toLower(s):: (
std.join("", [remapChar(c, "A", "Z", "a") for c in std.stringChars(s)])
),
toUpper(s):: (
std.join("", [remapChar(c, "a", "z", "A") for c in std.stringChars(s)])
),
boolXor(x, y):: ((if x then 1 else 0) + (if y then 1 else 0) == 1),
_Object(apiVersion, kind, name):: {
local this = self,
apiVersion: apiVersion,
kind: kind,
metadata: {
name: name,
labels: { name: std.join("-", std.split(this.metadata.name, ":")) },
annotations: {},
},
},
List(): {
apiVersion: "v1",
kind: "List",
items_:: {},
items: $.objectValues(self.items_),
},
Namespace(name): $._Object("v1", "Namespace", name) {
},
Endpoints(name): $._Object("v1", "Endpoints", name) {
Ip(addr):: { ip: addr },
Port(p):: { port: p },
subsets: [],
},
Service(name): $._Object("v1", "Service", name) {
local service = self,
target_pod:: error "service target_pod required",
container_index:: 0,
port:: self.target_pod.spec.containers[service.container_index].ports[0].containerPort,
// Helpers that format host:port in various ways
host:: "%s.%s.svc" % [self.metadata.name, self.metadata.namespace],
host_colon_port:: "%s:%s" % [self.host, self.spec.ports[0].port],
http_url:: "http://%s/" % self.host_colon_port,
proxy_urlpath:: "/api/v1/proxy/namespaces/%s/services/%s/" % [
self.metadata.namespace,
self.metadata.name,
],
// Useful in Ingress rules
// This has been adapted for Ingress with apiVersion: networking.k8s.io/v1
name_port:: {
local this = self,
default_port:: service.spec.ports[0],
port_spec:: if std.objectHas(this.default_port, "name") then { name: this.default_port.name } else { number: this.default_port.port },
service+: {
name: service.metadata.name,
port+: this.port_spec,
},
assert (!$._assert) || $.boolXor(
std.objectHas(this.port_spec, "name"),
std.objectHas(this.port_spec, "number")
) : "Service '%s' name_port: `name` and `number` are mutually exclusive for Ingress spec" % name,
},
spec: {
selector: service.target_pod.metadata.labels,
ports: [
{
port: service.port,
name: service.target_pod.spec.containers[service.container_index].ports[0].name,
targetPort: service.target_pod.spec.containers[service.container_index].ports[0].containerPort,
},
],
type: "ClusterIP",
},
},
PersistentVolume(name): $._Object("v1", "PersistentVolume", name) {
spec: {},
},
// TODO: This is a terrible name
PersistentVolumeClaimVolume(pvc): {
persistentVolumeClaim: { claimName: pvc.metadata.name },
},
StorageClass(name): $._Object("storage.k8s.io/v1", "StorageClass", name) {
provisioner: error "provisioner required",
},
PersistentVolumeClaim(name): $._Object("v1", "PersistentVolumeClaim", name) {
local pvc = self,
storageClass:: null,
storage:: error "storage required",
spec: {
resources: {
requests: {
storage: pvc.storage,
},
},
accessModes: ["ReadWriteOnce"],
[if pvc.storageClass != null then "storageClassName"]: pvc.storageClass,
},
},
Container(name): {
name: name,
image: error "container image value required",
imagePullPolicy: if std.endsWith(self.image, ":latest") then "Always" else "IfNotPresent",
envList(map):: [
if std.type(map[x]) == "object"
then {
name: x,
valueFrom: map[x],
} else {
// Let `null` value stay as such (vs string-ified)
name: x,
value: if map[x] == null then null else std.toString(map[x]),
}
for x in std.objectFields(map)
],
env_:: {},
env: self.envList(self.env_),
args_:: {},
args: ["--%s=%s" % kv for kv in $.objectItems(self.args_)],
ports_:: {},
ports: $.mapToNamedList(self.ports_),
volumeMounts_:: {},
volumeMounts: $.mapToNamedList(self.volumeMounts_),
stdin: false,
tty: false,
assert (!$._assert) || (!self.tty || self.stdin) : "tty=true requires stdin=true",
},
PodDisruptionBudget(name): $._Object("policy/v1beta1", "PodDisruptionBudget", name) {
local this = self,
target_pod:: error "target_pod required",
spec: {
assert (!$._assert) || $.boolXor(
std.objectHas(self, "minAvailable"),
std.objectHas(self, "maxUnavailable")
) : "PDB '%s': exactly one of minAvailable/maxUnavailable required" % name,
selector: {
matchLabels: this.target_pod.metadata.labels,
},
},
},
Pod(name): $._Object("v1", "Pod", name) {
spec: $.PodSpec,
},
PodSpec: {
// The 'first' container is used in various defaults in k8s.
local container_names = std.objectFields(self.containers_),
default_container:: if std.length(container_names) > 1 then "default" else container_names[0],
containers_:: {},
local container_names_ordered = [self.default_container] + [n for n in container_names if n != self.default_container],
containers: (
assert (!$._assert) || std.length(self.containers_) > 0 : "Pod must have at least one container (via containers_ map)";
[{ name: $.hyphenate(name) } + self.containers_[name] for name in container_names_ordered if self.containers_[name] != null]
),
// Note initContainers are inherently ordered, and using this
// named object will lose that ordering. If order matters, then
// manipulate `initContainers` directly (perhaps
// appending/prepending to `super.initContainers` to mix+match
// both approaches)
initContainers_:: {},
initContainers: [{ name: $.hyphenate(name) } + self.initContainers_[name] for name in std.objectFields(self.initContainers_) if self.initContainers_[name] != null],
volumes_:: {},
volumes: $.mapToNamedList(self.volumes_),
imagePullSecrets: [],
terminationGracePeriodSeconds: 30,
assert (!$._assert) || std.length(self.containers) > 0 : "Pod must have at least one container (via containers array)",
// Return an array of pod's ports numbers
ports(proto):: [
p.containerPort
for p in std.flattenArrays([
c.ports
for c in self.containers
])
if (
(!(std.objectHas(p, "protocol")) && proto == "TCP")
||
((std.objectHas(p, "protocol")) && p.protocol == proto)
)
],
},
EmptyDirVolume(): {
emptyDir: {},
},
HostPathVolume(path, type=""): {
hostPath: { path: path, type: type },
},
GitRepoVolume(repository, revision): {
gitRepo: {
repository: repository,
// "master" is possible, but should be avoided for production
revision: revision,
},
},
SecretVolume(secret): {
secret: { secretName: secret.metadata.name },
},
ConfigMapVolume(configmap): {
configMap: { name: configmap.metadata.name },
},
ConfigMap(name): $._Object("v1", "ConfigMap", name) {
data: {},
// I keep thinking data values can be any JSON type. This check
// will remind me that they must be strings :(
local nonstrings = [
k
for k in std.objectFields(self.data)
if std.type(self.data[k]) != "string"
],
assert (!$._assert) || std.length(nonstrings) == 0 : "data contains non-string values: %s" % [nonstrings],
},
// subtype of EnvVarSource
ConfigMapRef(configmap, key): {
assert (!$._assert) || std.objectHas(configmap.data, key) : "ConfigMap '%s' doesn't have '%s' field in configmap.data" % [configmap.metadata.name, key],
configMapKeyRef: {
name: configmap.metadata.name,
key: key,
},
},
Secret(name): $._Object("v1", "Secret", name) {
local secret = self,
type: "Opaque",
data_:: {},
data: { [k]: std.base64(secret.data_[k]) for k in std.objectFields(secret.data_) },
},
// subtype of EnvVarSource
SecretKeyRef(secret, key): {
assert (!$._assert) || std.objectHas(secret.data, key) : "Secret '%s' doesn't have '%s' field in secret.data" % [secret.metadata.name, key],
secretKeyRef: {
name: secret.metadata.name,
key: key,
},
},
// subtype of EnvVarSource
FieldRef(key): {
fieldRef: {
apiVersion: "v1",
fieldPath: key,
},
},
// subtype of EnvVarSource
ResourceFieldRef(key, divisor="1"): {
resourceFieldRef: {
resource: key,
divisor: std.toString(divisor),
},
},
Deployment(name): $._Object("apps/v1", "Deployment", name) {
local deployment = self,
spec: {
template: {
spec: $.PodSpec,
metadata: {
labels: deployment.metadata.labels,
annotations: {},
},
},
selector: {
matchLabels: deployment.spec.template.metadata.labels,
},
strategy: {
type: "RollingUpdate",
local pvcs = [
v
for v in deployment.spec.template.spec.volumes
if std.objectHas(v, "persistentVolumeClaim")
],
local is_stateless = std.length(pvcs) == 0,
// Apps trying to maintain a majority quorum or similar will
// want to tune these carefully.
// NB: Upstream default is surge=1 unavail=1
rollingUpdate: if is_stateless then {
maxSurge: "25%", // rounds up
maxUnavailable: "25%", // rounds down
} else {
// Poor-man's StatelessSet. Useful mostly with replicas=1.
maxSurge: 0,
maxUnavailable: 1,
},
},
// NB: Upstream default is 0
minReadySeconds: 30,
// NB: Regular k8s default is to keep all revisions
revisionHistoryLimit: 10,
},
},
CrossVersionObjectReference(target): {
apiVersion: target.apiVersion,
kind: target.kind,
name: target.metadata.name,
},
HorizontalPodAutoscaler(name): $._Object("autoscaling/v1", "HorizontalPodAutoscaler", name) {
local hpa = self,
target:: error "target required",
spec: {
scaleTargetRef: $.CrossVersionObjectReference(hpa.target),
minReplicas: hpa.target.spec.replicas,
maxReplicas: error "maxReplicas required",
assert (!$._assert) || self.maxReplicas >= self.minReplicas,
},
},
StatefulSet(name): $._Object("apps/v1", "StatefulSet", name) {
local sset = self,
spec: {
serviceName: name,
updateStrategy: {
type: "RollingUpdate",
rollingUpdate: {
partition: 0,
},
},
template: {
spec: $.PodSpec,
metadata: {
labels: sset.metadata.labels,
annotations: {},
},
},
selector: {
matchLabels: sset.spec.template.metadata.labels,
},
volumeClaimTemplates_:: {},
volumeClaimTemplates: [
// StatefulSet is overly fussy about "changes" (even when
// they're no-ops).
// In particular annotations={} is apparently a "change",
// since the comparison is ignorant of defaults.
std.prune($.PersistentVolumeClaim($.hyphenate(kv[0])) + { apiVersion:: null, kind:: null } + kv[1])
for kv in $.objectItems(self.volumeClaimTemplates_)
],
replicas: 1,
assert (!$._assert) || self.replicas >= 1,
},
},
Job(name): $._Object("batch/v1", "Job", name) {
local job = self,
spec: $.JobSpec {
template+: {
metadata+: {
labels: job.metadata.labels,
},
},
},
},
CronJob(name): $._Object("batch/v1beta1", "CronJob", name) {
local cronjob = self,
spec: {
jobTemplate: {
spec: $.JobSpec {
template+: {
metadata+: {
labels: cronjob.metadata.labels,
},
},
},
},
schedule: error "Need to provide spec.schedule",
successfulJobsHistoryLimit: 10,
failedJobsHistoryLimit: 20,
// NB: upstream concurrencyPolicy default is "Allow"
concurrencyPolicy: "Forbid",
},
},
JobSpec: {
local this = self,
template: {
spec: $.PodSpec {
restartPolicy: "OnFailure",
},
},
completions: 1,
parallelism: 1,
},
DaemonSet(name): $._Object("apps/v1", "DaemonSet", name) {
local ds = self,
spec: {
updateStrategy: {
type: "RollingUpdate",
rollingUpdate: {
maxUnavailable: 1,
},
},
template: {
metadata: {
labels: ds.metadata.labels,
annotations: {},
},
spec: $.PodSpec,
},
selector: {
matchLabels: ds.spec.template.metadata.labels,
},
},
},
Ingress(name): $._Object("networking.k8s.io/v1", "Ingress", name) {
spec: {},
local rel_paths = [
p.path
for r in self.spec.rules
for p in r.http.paths
if std.objectHas(p, "path") && !std.startsWith(p.path, "/")
],
assert (!$._assert) || std.length(rel_paths) == 0 : "paths must be absolute: " + rel_paths,
},
ThirdPartyResource(name): $._Object("extensions/v1beta1", "ThirdPartyResource", name) {
versions_:: [],
versions: [{ name: n } for n in self.versions_],
},
CustomResourceDefinition(group, version, kind): {
local this = self,
apiVersion: "apiextensions.k8s.io/v1",
kind: "CustomResourceDefinition",
metadata+: {
name: this.spec.names.plural + "." + this.spec.group,
},
spec: {
scope: "Namespaced",
group: group,
versions_:: {
// Create an opinionated default_spec for the version, easy to override by the user,
// specially if they had several versions to derived from the same "skeleton".
default_spec:: {
served: true,
storage: true,
schema: {
openAPIV3Schema: {
type: "object",
properties: {
spec: {
type: "object",
},
},
},
},
},
[version]: self.default_spec,
},
versions: $.mapToNamedList(self.versions_),
names: {
kind: kind,
singular: $.toLower(self.kind),
plural: self.singular + "s",
listKind: self.kind + "List",
},
},
},
ServiceAccount(name): $._Object("v1", "ServiceAccount", name) {
},
Role(name): $._Object("rbac.authorization.k8s.io/v1", "Role", name) {
rules: [],
},
ClusterRole(name): $.Role(name) {
kind: "ClusterRole",
},
Group(name): {
kind: "Group",
name: name,
apiGroup: "rbac.authorization.k8s.io",
},
User(name): {
kind: "User",
name: name,
apiGroup: "rbac.authorization.k8s.io",
},
RoleBinding(name): $._Object("rbac.authorization.k8s.io/v1", "RoleBinding", name) {
local rb = self,
subjects_:: [],
subjects: [{
kind: o.kind,
namespace: o.metadata.namespace,
name: o.metadata.name,
} for o in self.subjects_],
roleRef_:: error "roleRef is required",
roleRef: {
apiGroup: "rbac.authorization.k8s.io",
kind: rb.roleRef_.kind,
name: rb.roleRef_.metadata.name,
},
},
ClusterRoleBinding(name): $.RoleBinding(name) {
kind: "ClusterRoleBinding",
},
// NB: encryptedData can be imported into a SealedSecret as follows:
// kubectl get secret ... -ojson mysec | kubeseal | jq -r .spec.encryptedData > sealedsecret.json
// encryptedData: std.parseJson(importstr "sealedsecret.json")
SealedSecret(name): $._Object("bitnami.com/v1alpha1", "SealedSecret", name) {
spec: {
encryptedData: {},
},
assert (!$._assert) || std.length(std.objectFields(self.spec.encryptedData)) != 0 : "SealedSecret '%s' has empty encryptedData field" % name,
},
// NB: helper method to access several Kubernetes objects podRef,
// used below to extract its labels
podRef(obj):: ({
Pod: obj,
Deployment: obj.spec.template,
StatefulSet: obj.spec.template,
DaemonSet: obj.spec.template,
Job: obj.spec.template,
CronJob: obj.spec.jobTemplate.spec.template,
}[obj.kind]),
// NB: return a { podSelector: ... } ready to use for e.g. NSPs (see below)
// pod labels can be optionally filtered by their label name 2nd array arg
podLabelsSelector(obj, filter=null):: {
podSelector: std.prune({
matchLabels:
if filter != null then $.filterMapByFields($.podRef(obj).metadata.labels, filter)
else $.podRef(obj).metadata.labels,
}),
},
// NB: Returns an array as [{ port: num, protocol: "PROTO" }, {...}, ... ]
// Need to split TCP, UDP logic to be able to dedup each set of protocol ports
podsPorts(obj_list):: std.flattenArrays([
[
{ port: port, protocol: protocol }
for port in std.set(
std.flattenArrays([$.podRef(obj).spec.ports(protocol) for obj in obj_list])
)
]
for protocol in ["TCP", "UDP"]
]),
// NB: most of the "helper" stuff comes from above (podLabelsSelector, podsPorts),
// NetworkPolicy returned object will have "Ingress", "Egress" policyTypes auto-set
// based on populated spec.ingress or spec.egress
// See tests/test-simple-validate.jsonnet for example(s).
NetworkPolicy(name): $._Object("networking.k8s.io/v1", "NetworkPolicy", name) {
local networkpolicy = self,
spec: {
policyTypes: std.prune([
if networkpolicy.spec.ingress != [] then "Ingress" else null,
if networkpolicy.spec.egress != [] then "Egress" else null,
]),
ingress: $.objectValues(self.ingress_),
ingress_:: {},
egress: $.objectValues(self.egress_),
egress_:: {},
podSelector: {},
},
},
VerticalPodAutoscaler(name):: $._Object("autoscaling.k8s.io/v1beta2", "VerticalPodAutoscaler", name) {
local vpa = self,
target:: error "target required",
spec+: {
targetRef: $.CrossVersionObjectReference(vpa.target),
updatePolicy: {
updateMode: "Auto",
},
},
},
// Helper function to ease VPA creation as e.g.:
// foo_vpa:: kube.createVPAFor($.foo_deploy)
createVPAFor(target, mode="Auto"):: $.VerticalPodAutoscaler(target.metadata.name) {
target:: target,
metadata+: {
namespace: target.metadata.namespace,
labels+: target.metadata.labels,
},
spec+: {
updatePolicy+: {
updateMode: mode,
},
},
},
}