-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(kubernetes): make reconcile support arrays #112
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,100 @@ | ||
# 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 `metadata.name` set. | ||
|
||
## 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 a | ||
`metadata.name`. | ||
|
||
??? Example | ||
sh0rez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
```json | ||
{ | ||
"prometheus": { | ||
"service": { // Service nested one level | ||
"apiVersion": "v1", | ||
"kind": "Service", | ||
"metadata": { | ||
"name": "promSvc" | ||
} | ||
}, | ||
"deployment": { | ||
"apiVersion": "apps/v1", | ||
"kind": "Deployment", // kind .. | ||
"metadata": { | ||
"name": "prom" // .. and metadata.name are required | ||
// to indentify a valid object. | ||
} | ||
} | ||
}, | ||
"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 | ||
sh0rez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's usually the case that Kubernetes deals in GVK (Group-Version-Kind) + Name tuples when uniquely identifying resources. It's probably better for tanka to output any leaf node that exhibits the structure:
I believe anything other than this format will fail validation anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @lawrencejones but also this remark seems inaccurate.
reconcile.go
seems to only be logging forkind
andapiVersion
right now. We should be checking for all three and document them here.