-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kubernetes): make reconcile support arrays (#112)
Allows users to output an array of objects from Jsonnet. Handy to use if you want to override sth on all objects, etc.
- Loading branch information
Showing
4 changed files
with
147 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Expected structure | ||
|
||
Tanka evaluates the `main.jsonnet` file of your [Environment](/environments) and | ||
filters the output (either Object or Array) for valid Kubernetes objects. | ||
An object is considered valid if it has both, a `kind` and a `apiVersion` set. | ||
|
||
!!! warning | ||
This behaviour is going to change in the future, `metadata.name` will | ||
also become required. | ||
|
||
## Deeply nested object (Recommended) | ||
The most commonly used structure is a single big object that includes all of | ||
your configs to be applied to the cluster nested under keys. | ||
How deeply encapsulated the actual object is does not matter, Tanka will | ||
traverse down until it finds something that has both, a `kind` and an | ||
`apiVersion`. | ||
|
||
??? Example | ||
```json | ||
{ | ||
"prometheus": { | ||
"service": { // Service nested one level | ||
"apiVersion": "v1", | ||
"kind": "Service", | ||
"metadata": { | ||
"name": "promSvc" | ||
} | ||
}, | ||
"deployment": { | ||
"apiVersion": "apps/v1", // apiVersion .. | ||
"kind": "Deployment", // .. and kind are required | ||
// to identify an object. | ||
"metadata": { | ||
"name": "prom" | ||
} | ||
} | ||
}, | ||
"web": { | ||
"nginx": { | ||
"deployment": { // Deployment nested two levels | ||
"apiVersion": "apps/v1", | ||
"kind": "Deployment", | ||
"metadata": { | ||
"name": "nginx" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Using this technique has the big benefit that it is self-documentary, as the | ||
nesting of keys can be used to logically group related manifests, for example by | ||
application. | ||
|
||
!!! info | ||
It is also valid to use an encapsulation level of zero, which means | ||
just a regular object like it could be obtained from `kubectl show -o json`: | ||
```json | ||
{ | ||
"apiVersion": "v1", | ||
"kind": "Service", | ||
"metadata": { | ||
"name": "foo" | ||
} | ||
} | ||
``` | ||
|
||
|
||
## Array | ||
Using an array of objects is also fine: | ||
```json | ||
[ | ||
{ | ||
"apiVersion": "v1", | ||
"kind": "Service", | ||
"metadata": { | ||
"name": "promSvc" | ||
} | ||
}, | ||
{ | ||
"apiVersion": "apps/v1", | ||
"kind": "Deployment", | ||
"metadata": { | ||
"name": "prom" | ||
} | ||
} | ||
] | ||
``` | ||
|
||
### `List` type | ||
Users of `kubectl` might have had contact with a type called `List`. It is not | ||
part of the official Kubernetes API but rather a pseudo-type introduced by | ||
`kubectl` for dealing with multiple objects at once. Thus, Tanka does not | ||
support it out of the box. | ||
|
||
To take full advantage of Tankas features, you can manually flatten it: | ||
|
||
```jsonnet | ||
local list = import "list.libsonnet"; | ||
# expose the `items` array on the top level: | ||
list.items | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters