Skip to content

Commit

Permalink
Library
Browse files Browse the repository at this point in the history
  • Loading branch information
mkmik committed Mar 29, 2023
1 parent 1e55020 commit 144e62c
Show file tree
Hide file tree
Showing 3 changed files with 736 additions and 0 deletions.
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,56 @@
# k8s-libsonnet
Helpers for creating k8s resources without abuse of constructor functions

## Features

* exposes k8s "named arrays" as objects that can be more easily overriden (`env_+:{BAR: {value:'override'}}`)
* allows to apply overrides on all objects of a given type, e.g. all Objects (e.g. namespace), all PodSpecs (e.g. labels)

## Example:

```jsonnet
(import '../k8s.libsonnet').RootComponent {
configmap: $.k8s.v1.ConfigMap {
metadata+: { name: 'foo' },
data: { bar: 'baz' },
},
deployment: $.k8s.apps.v1.Deployment {
metadata+: { name: 'nginx' },
spec: {
replicas: 2,
selector: { matchLabels: { app: 'nginx' } },
template: {
metadata: { labels: { app: 'nginx' } },
spec: {
containers+: {
nginx: {
image: 'nginx:1.14.2',
env_+: {
BAR: { valueFrom: { configMapKeyRef: {
name: $.configmap.metadata.name,
key: 'bar',
} } },
},
ports_+: {
http: { containerPort: 80 },
},
},
},
},
},
},
},
service: $.k8s.v1.Service {
metadata+: { name: 'nginx' },
spec+: {
selector: $.deployment.spec.selector.matchLabels,
ports_+: {
http: { port: 80, targetPort: 'http' },
},
},
},
}
```
44 changes: 44 additions & 0 deletions examples/simple.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
(import '../k8s.libsonnet').RootComponent {
configmap: $.k8s.v1.ConfigMap {
metadata+: { name: 'foo' },
data: { bar: 'baz' },
},

deployment: $.k8s.apps.v1.Deployment {
metadata+: { name: 'nginx' },
spec: {
replicas: 2,
selector: { matchLabels: { app: 'nginx' } },
template: {
metadata: { labels: { app: 'nginx' } },
spec: {
containers+: {
nginx: {
image: 'nginx:1.14.2',
env_+: {
BAR: { valueFrom: { configMapKeyRef: {
name: $.configmap.metadata.name,
key: 'bar',
} } },
},
ports_+: {
http: { containerPort: 80 },
},
},
},
},
},
},
},

service: $.k8s.v1.Service {
metadata+: { name: 'nginx' },
spec+: {
selector: $.deployment.spec.selector.matchLabels,
ports_+: {
http: { port: 80, targetPort: 'http' },
},
},
},

}
Loading

0 comments on commit 144e62c

Please sign in to comment.