mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 18:40:55 +00:00
Compare commits
269 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c464fb0a81 | ||
|
|
694cf23df8 | ||
|
|
e66656aa7f | ||
|
|
eaae7af5fe | ||
|
|
f9fe138114 | ||
|
|
2a2a889c37 | ||
|
|
34287e511f | ||
|
|
e6fffc8ba4 | ||
|
|
86f221611e | ||
|
|
b4d6e89fa2 | ||
|
|
5937bd0259 | ||
|
|
ed3c29be12 | ||
|
|
3d2e956b19 | ||
|
|
dd9d1f95e9 | ||
|
|
a279c08f7d | ||
|
|
a798109161 | ||
|
|
bafd6b5423 | ||
|
|
963913f9ef | ||
|
|
46905588ac | ||
|
|
5426888df4 | ||
|
|
35481ec6d9 | ||
|
|
6c92c30e94 | ||
|
|
02f6b3ec98 | ||
|
|
a9848f2738 | ||
|
|
b4038a6cd2 | ||
|
|
95f3303493 | ||
|
|
2faf4a491b | ||
|
|
e646bba1ff | ||
|
|
99a21b0a3c | ||
|
|
e7a22b6bc5 | ||
|
|
d783bbc0bc | ||
|
|
b7405f3872 | ||
|
|
abc419b5f9 | ||
|
|
336378b114 | ||
|
|
29959551da | ||
|
|
fc78917191 | ||
|
|
ffd95ef5a9 | ||
|
|
230090d790 | ||
|
|
8fa3861ba3 | ||
|
|
69c90e3427 | ||
|
|
5a73f345fd | ||
|
|
0e62d759f0 | ||
|
|
b2967d2f77 | ||
|
|
c23039c07a | ||
|
|
5747c417c4 | ||
|
|
8c53d77111 | ||
|
|
01667cabde | ||
|
|
f649b62629 | ||
|
|
3a4d025b5c | ||
|
|
99eb08eb1e | ||
|
|
d3f8c0d87f | ||
|
|
0bec7b996b | ||
|
|
dd5674fe6b | ||
|
|
33159c26df | ||
|
|
afc7dbebe5 | ||
|
|
f363acf839 | ||
|
|
96d5a7401d | ||
|
|
403fa20546 | ||
|
|
ba4d7ddca8 | ||
|
|
5116e2f210 | ||
|
|
9e0f198227 | ||
|
|
30b378a924 | ||
|
|
3a843f1eca | ||
|
|
9b40f8ab47 | ||
|
|
dc6dcd8150 | ||
|
|
3cb6c7f1f4 | ||
|
|
7632839bc8 | ||
|
|
c3ea109b59 | ||
|
|
579995dc8a | ||
|
|
b43bd5440d | ||
|
|
c4d899f7f3 | ||
|
|
7998ee7036 | ||
|
|
878960d7b1 | ||
|
|
ed0cfc685b | ||
|
|
b0a7345123 | ||
|
|
580963ea76 | ||
|
|
0707deae95 | ||
|
|
fb44880b8c | ||
|
|
e5ebca6604 | ||
|
|
f5fc9acb84 | ||
|
|
28d1bad3cb | ||
|
|
6f74419628 | ||
|
|
8121467c1e | ||
|
|
a85f297f31 | ||
|
|
76a7816aeb | ||
|
|
7872405379 | ||
|
|
6c17a3409f | ||
|
|
f1dbab9dee | ||
|
|
bfafbbf47f | ||
|
|
08d7c35da7 | ||
|
|
f12704f6c1 | ||
|
|
0edab60b30 | ||
|
|
3c05e2d664 | ||
|
|
aa2313c282 | ||
|
|
eeed1954fb | ||
|
|
cd00ce7ab1 | ||
|
|
145d07363f | ||
|
|
33fff655db | ||
|
|
31ab347da2 | ||
|
|
7a48b2ba8e | ||
|
|
876f2a8236 | ||
|
|
095333ffb1 | ||
|
|
0d8d9e2f2b | ||
|
|
9bff2e8883 | ||
|
|
120ba6b870 | ||
|
|
483188ba89 | ||
|
|
672bda0c9c | ||
|
|
49b32473ca | ||
|
|
08400d77a6 | ||
|
|
c912baeb3a | ||
|
|
433733eb0e | ||
|
|
f996ac82c7 | ||
|
|
efcb7cc5a5 | ||
|
|
bf7b57537b | ||
|
|
6b597f8711 | ||
|
|
088739900f | ||
|
|
3bf13f83d3 | ||
|
|
c64a72f1f9 | ||
|
|
8b60b456ac | ||
|
|
e0bac6ad19 | ||
|
|
d841d1bb36 | ||
|
|
0d87cd6ba1 | ||
|
|
28ad36b02c | ||
|
|
cad8a7bd3f | ||
|
|
60a990d660 | ||
|
|
cb3751cea6 | ||
|
|
5ad012e6d9 | ||
|
|
8a454de8f9 | ||
|
|
57b18b7caa | ||
|
|
701d2c9597 | ||
|
|
e7e844bc95 | ||
|
|
0fe95a2f74 | ||
|
|
eb93d8c389 | ||
|
|
8b373ab587 | ||
|
|
c352003f3e | ||
|
|
79d0de7000 | ||
|
|
a32d5ce7ab | ||
|
|
5de0673db1 | ||
|
|
c2b0b6f781 | ||
|
|
116b37813a | ||
|
|
27f0d29734 | ||
|
|
f62af4ebf3 | ||
|
|
faa6d0fd0a | ||
|
|
0554da9d6e | ||
|
|
fa1fd9fbd7 | ||
|
|
3dffc30e83 | ||
|
|
2126b6cf23 | ||
|
|
2b052fdd55 | ||
|
|
58faa762cb | ||
|
|
349cfff1cb | ||
|
|
558be8b923 | ||
|
|
233b3613ae | ||
|
|
615a41d6be | ||
|
|
0ceefcf39d | ||
|
|
16ae64a722 | ||
|
|
3f239fb4a5 | ||
|
|
a60d99fdc9 | ||
|
|
dd0334536b | ||
|
|
3cef37bdb2 | ||
|
|
ac27e94dff | ||
|
|
0877aa7e0b | ||
|
|
07e5a544fe | ||
|
|
60c04a5f33 | ||
|
|
b9b9fb1dd2 | ||
|
|
e1233a0fbc | ||
|
|
cc8203032c | ||
|
|
7117961234 | ||
|
|
d410252cf8 | ||
|
|
4235c57657 | ||
|
|
e34c1ce192 | ||
|
|
4d399ad89c | ||
|
|
9d6ab24388 | ||
|
|
ee9f35d451 | ||
|
|
45c11ec733 | ||
|
|
0519df4ad5 | ||
|
|
55585d8da5 | ||
|
|
b8b49c3124 | ||
|
|
a41471d895 | ||
|
|
877e9ecf64 | ||
|
|
150985bb9c | ||
|
|
039f7669df | ||
|
|
6caa042b05 | ||
|
|
cc0fffc67b | ||
|
|
50d40ef941 | ||
|
|
69d40bd740 | ||
|
|
4272611593 | ||
|
|
74f5e74b89 | ||
|
|
2bba0a6aa3 | ||
|
|
762d3143eb | ||
|
|
7f22e25dfe | ||
|
|
41c162a65f | ||
|
|
ca521946a5 | ||
|
|
b0e53d2b39 | ||
|
|
5c93722db8 | ||
|
|
d34c82c905 | ||
|
|
f11d083b0a | ||
|
|
f1a5a7703c | ||
|
|
9cc2c90a4b | ||
|
|
bc31fa9120 | ||
|
|
7a67645558 | ||
|
|
b0f59358d9 | ||
|
|
0e6c7d8af7 | ||
|
|
9c20085ca9 | ||
|
|
d48a52055a | ||
|
|
dc433e12fb | ||
|
|
1740ca6a16 | ||
|
|
2ae8ca1d63 | ||
|
|
674cd89ac9 | ||
|
|
6ed70add4a | ||
|
|
ae5ebccec7 | ||
|
|
19c8e23425 | ||
|
|
b878cd050d | ||
|
|
a7df00c07a | ||
|
|
3127f1adc6 | ||
|
|
a722cca80a | ||
|
|
0ffd78eab6 | ||
|
|
694c868048 | ||
|
|
2da2006e2a | ||
|
|
0bc83ca065 | ||
|
|
ab2643ef14 | ||
|
|
297812ec11 | ||
|
|
158f754f18 | ||
|
|
da3504105e | ||
|
|
d3f50695b4 | ||
|
|
5a9a6ab0f6 | ||
|
|
b86e78b7a9 | ||
|
|
b1cdf581d0 | ||
|
|
8bf20527be | ||
|
|
3eedc40595 | ||
|
|
93db0ef3e9 | ||
|
|
6922dbbc70 | ||
|
|
f1b9b27a15 | ||
|
|
a755558beb | ||
|
|
b8423d0f5f | ||
|
|
42ef4fbcc1 | ||
|
|
69c11780eb | ||
|
|
c925b43090 | ||
|
|
a5b97cbd9b | ||
|
|
bcb844663f | ||
|
|
0905ee293c | ||
|
|
3325852aab | ||
|
|
c437d99c5f | ||
|
|
cacafc63e8 | ||
|
|
b08f3383b8 | ||
|
|
2eccf67b1c | ||
|
|
293c8bef54 | ||
|
|
00c7ae0542 | ||
|
|
cd656faadf | ||
|
|
056b95ffa9 | ||
|
|
d211df1e73 | ||
|
|
934e036b99 | ||
|
|
9fc86f92fa | ||
|
|
49c6bd4141 | ||
|
|
24011cf2a5 | ||
|
|
83b284dfde | ||
|
|
7c9181317f | ||
|
|
01b410fe9c | ||
|
|
56ac98468d | ||
|
|
658ebeaa21 | ||
|
|
59aa898533 | ||
|
|
c88f87cee2 | ||
|
|
cc663bb08c | ||
|
|
63d647df18 | ||
|
|
e3a46cb6ce | ||
|
|
4556eb3a0c | ||
|
|
26ed9b7c58 | ||
|
|
8ff0b5423d | ||
|
|
0fbced95a8 | ||
|
|
66b816aabc |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,6 +4,7 @@
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
/kustomize
|
||||
|
||||
# Test binary, build with `go test -c`
|
||||
*.test
|
||||
|
||||
28
Makefile
Normal file
28
Makefile
Normal file
@@ -0,0 +1,28 @@
|
||||
BIN_NAME=kustomize
|
||||
|
||||
export GO111MODULE=on
|
||||
|
||||
all: test build
|
||||
|
||||
test: generate-code test-lint test-go
|
||||
|
||||
test-go:
|
||||
go test -v ./...
|
||||
|
||||
test-lint:
|
||||
golangci-lint run ./...
|
||||
|
||||
generate-code:
|
||||
./plugin/generateBuiltins.sh $(GOPATH)
|
||||
|
||||
build:
|
||||
go build -o $(BIN_NAME) cmd/kustomize/main.go
|
||||
|
||||
install:
|
||||
go install $(PWD)/cmd/kustomize
|
||||
|
||||
clean:
|
||||
go clean
|
||||
rm -f $(BIN_NAME)
|
||||
|
||||
.PHONY: test build install clean generate-code test-go test-lint
|
||||
19
README.md
19
README.md
@@ -1,5 +1,7 @@
|
||||
# kustomize
|
||||
|
||||
_[v3.0.2](https://github.com/kubernetes-sigs/kustomize/releases/tag/v3.0.2) is the latest release._
|
||||
|
||||
`kustomize` lets you customize raw, template-free YAML
|
||||
files for multiple purposes, leaving the original YAML
|
||||
untouched and usable as is.
|
||||
@@ -7,7 +9,7 @@ untouched and usable as is.
|
||||
`kustomize` targets kubernetes; it understands and can
|
||||
patch [kubernetes style] API objects. It's like
|
||||
[`make`], in that what it does is declared in a file,
|
||||
and it's like [`sed`], in that it emits editted text.
|
||||
and it's like [`sed`], in that it emits edited text.
|
||||
|
||||
This tool is sponsored by [sig-cli] ([KEP]), and
|
||||
inspired by [DAM].
|
||||
@@ -22,8 +24,16 @@ these [instructions](docs/INSTALL.md).
|
||||
Browse the [docs](docs) or jump right into the
|
||||
tested [examples](examples).
|
||||
|
||||
kustomize [v2.0.3] is available in [kubectl v1.14][kubectl].
|
||||
## kubectl integration
|
||||
|
||||
Since [v1.14][kubectl announcement] the kustomize build system has been included in kubectl.
|
||||
|
||||
| kubectl version | kustomize version |
|
||||
|---------|--------|
|
||||
| v1.15.x | [v2.0.3](https://github.com/kubernetes-sigs/kustomize/tree/v2.0.3) |
|
||||
| v1.14.x | [v2.0.3](https://github.com/kubernetes-sigs/kustomize/tree/v2.0.3) |
|
||||
|
||||
For examples and guides for using the kubectl integration please see the [kubectl book] or the [kubernetes documentation].
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -159,7 +169,9 @@ is governed by the [Kubernetes Code of Conduct].
|
||||
[imageBase]: docs/images/base.jpg
|
||||
[imageOverlay]: docs/images/overlay.jpg
|
||||
[kind/feature]: https://github.com/kubernetes-sigs/kustomize/labels/kind%2Ffeature
|
||||
[kubectl]: https://kubernetes.io/blog/2019/03/25/kubernetes-1-14-release-announcement
|
||||
[kubectl announcement]: https://kubernetes.io/blog/2019/03/25/kubernetes-1-14-release-announcement
|
||||
[kubectl book]: https://kubectl.docs.kubernetes.io/pages/app_customization/introduction.html
|
||||
[kubernetes documentation]: https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/
|
||||
[kubernetes style]: docs/glossary.md#kubernetes-style-object
|
||||
[kustomization]: docs/glossary.md#kustomization
|
||||
[overlay]: docs/glossary.md#overlay
|
||||
@@ -171,4 +183,5 @@ is governed by the [Kubernetes Code of Conduct].
|
||||
[variant]: docs/glossary.md#variant
|
||||
[variants]: docs/glossary.md#variant
|
||||
[v2.0.3]: https://github.com/kubernetes-sigs/kustomize/releases/tag/v2.0.3
|
||||
[v2.1.0]: https://github.com/kubernetes-sigs/kustomize/releases/tag/v2.1.0
|
||||
[workflows]: docs/workflows.md
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
[releases page]: https://github.com/kubernetes-sigs/kustomize/releases
|
||||
[`cloud-build-local`]: https://github.com/GoogleCloudPlatform/cloud-build-local
|
||||
[Google Cloud Build]: https://cloud.google.com/cloud-build
|
||||
|
||||
Scripts and configuration files for publishing a
|
||||
`kustomize` release on the [releases page].
|
||||
|
||||
### Build a release locally
|
||||
|
||||
Install [`cloud-build-local`], then run
|
||||
|
||||
```
|
||||
./build/localbuild.sh
|
||||
```
|
||||
|
||||
to build artifacts under `./dist`.
|
||||
|
||||
### Publish a Release
|
||||
|
||||
Get on an up-to-date master branch:
|
||||
```
|
||||
git checkout master
|
||||
git fetch upstream
|
||||
git rebase upstream/master
|
||||
```
|
||||
|
||||
Define the version (see [semver principles](https://semver.org)), e.g.:
|
||||
```
|
||||
version=v1.0.3
|
||||
```
|
||||
|
||||
Tag the repo:
|
||||
```
|
||||
git tag -a $version -m "$version release"
|
||||
```
|
||||
|
||||
Push the tag upstream:
|
||||
```
|
||||
git push upstream $version
|
||||
```
|
||||
|
||||
The new tag will trigger a job in [Google Cloud
|
||||
Build] to put a new release on the [releases page].
|
||||
@@ -6,7 +6,7 @@ package main
|
||||
import (
|
||||
"os"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/commands"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/pkg/plugins"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/plugins"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
37
docs/FAQ.md
37
docs/FAQ.md
@@ -23,17 +23,36 @@ kustomization file, and refering to this directory as a
|
||||
wants to use it. This encourages modularity and
|
||||
relocatability.
|
||||
|
||||
At the moment (in v2.0.3), however, there's no
|
||||
(released) analogous way to share patch files and other
|
||||
transformer configuration data between kustomizations.
|
||||
|
||||
As a stop-gap until we add base-like behavior for
|
||||
transformers, we've added a flag to disable the check:
|
||||
|
||||
To disable this, use v3, and the `load_restrictor` flag:
|
||||
|
||||
```
|
||||
kustomize build --load_restrictor none $target
|
||||
```
|
||||
|
||||
This flag is not in v2.0.3, but is available from head
|
||||
(`go install sigs.k8s.io/kustomize`).
|
||||
## Some field is not transformed by kustomize
|
||||
|
||||
Example: [#1319](https://github.com/kubernetes-sigs/kustomize/issues/1319), [#1322](https://github.com/kubernetes-sigs/kustomize/issues/1322), [#1347](https://github.com/kubernetes-sigs/kustomize/issues/1347) and etc.
|
||||
|
||||
The fields transformed by kustomize is configured explicitly in [defaultconfig](https://github.com/kubernetes-sigs/kustomize/tree/master/pkg/transformers/config/defaultconfig). The configuration itself can be customized by including `configurations` in `kustomization.yaml`, e.g.
|
||||
|
||||
```yaml
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
configurations:
|
||||
- kustomizeconfig.yaml
|
||||
```
|
||||
|
||||
The configuration directive allows customization of the following transformers:
|
||||
|
||||
```yaml
|
||||
commonAnnotations: []
|
||||
commonLabels: []
|
||||
nameprefix: []
|
||||
namespace: []
|
||||
varreference: []
|
||||
namereference: []
|
||||
images: []
|
||||
replicas: []
|
||||
```
|
||||
|
||||
To persist the changes to default configuration, submit a PR like [#1338](https://github.com/kubernetes-sigs/kustomize/pull/1338), [#1348](https://github.com/kubernetes-sigs/kustomize/pull/1348) and etc.
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
[release page]: https://github.com/kubernetes-sigs/kustomize/releases
|
||||
[Go]: https://golang.org
|
||||
|
||||
## Installation
|
||||
# Installation
|
||||
|
||||
For linux, macOs and Windows,
|
||||
download a binary from the
|
||||
[release page].
|
||||
Binaries at various versions for linux, macOs and Windows
|
||||
are available on the [release page].
|
||||
|
||||
Or...
|
||||
|
||||
## Quickly curl the latest
|
||||
|
||||
Or try this command:
|
||||
```
|
||||
opsys=linux # or darwin, or windows
|
||||
curl -s https://api.github.com/repos/kubernetes-sigs/kustomize/releases/latest |\
|
||||
@@ -19,17 +21,19 @@ mv kustomize_*_${opsys}_amd64 kustomize
|
||||
chmod u+x kustomize
|
||||
```
|
||||
|
||||
To install from head with [Go] v1.12 or higher:
|
||||
## Install from the HEAD of master branch
|
||||
|
||||
Requires [Go] v1.12 or higher:
|
||||
|
||||
<!-- @installkustomize @test -->
|
||||
```
|
||||
go install sigs.k8s.io/kustomize/cmd/kustomize
|
||||
go install sigs.k8s.io/kustomize/v3/cmd/kustomize
|
||||
```
|
||||
|
||||
### Other methods
|
||||
|
||||
#### macOS
|
||||
|
||||
|
||||
```
|
||||
brew install kustomize
|
||||
```
|
||||
@@ -44,4 +48,3 @@ For support on the chocolatey package
|
||||
and prior releases, see:
|
||||
- [Choco Package](https://chocolatey.org/packages/kustomize)
|
||||
- [Package Source](https://github.com/kenmaglio/choco-kustomize)
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ English | [简体中文](zh/README.md)
|
||||
* [Kustomize Fields](fields.md) - explanations of the fields
|
||||
in a [kustomization](glossary.md#kustomization) file.
|
||||
|
||||
* [Plugins](plugins.md) - extending kustomize with
|
||||
* [Plugins](plugins) - extending kustomize with
|
||||
custom generators and transformers.
|
||||
|
||||
* [Workflows](workflows.md) - steps one might take in
|
||||
@@ -23,12 +23,16 @@ English | [简体中文](zh/README.md)
|
||||
|
||||
## Release notes
|
||||
|
||||
* [2.1](v_2.1.0.md) - Date TBD, target late May 2019
|
||||
* [3.1](v3.1.0.md) - Late July 2019. Extended patches and improved resource matching.
|
||||
|
||||
* [2.0](v_2.0.0.md) - Mar 2019.
|
||||
* [3.0](v3.0.0.md) - Late June 2019. Plugin developer release.
|
||||
|
||||
* [2.1](v2.1.0.md) - 18 June 2019. Plugins, ordered resources, etc.
|
||||
|
||||
* [2.0](v2.0.0.md) - Mar 2019.
|
||||
kustomize [v2.0.3] is available in [kubectl v1.14][kubectl].
|
||||
|
||||
* [1.0](v_1.0.1.md) - May 2018. Initial release after development
|
||||
* [1.0](v1.0.1.md) - May 2018. Initial release after development
|
||||
in the [kubectl repository].
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,10 @@ following to improve response time.
|
||||
kustomize has a simple test harness in the
|
||||
[target package] for specifying a kustomization's
|
||||
input and the expected output.
|
||||
See this [example of a target test].
|
||||
|
||||
See this [example of a target test], and contribution
|
||||
[#971](https://github.com/kubernetes-sigs/kustomize/pull/971),
|
||||
which does exactly the right thing.
|
||||
|
||||
The pattern is
|
||||
* call `NewKustTestHarness`
|
||||
|
||||
1
docs/execPluginIn30sec.md
Symbolic link
1
docs/execPluginIn30sec.md
Symbolic link
@@ -0,0 +1 @@
|
||||
plugins/execPluginGuidedExample.md
|
||||
@@ -21,7 +21,7 @@ What things should be created (and optionally subsequently customized)?
|
||||
|[configMapGenerator](#configmapgenerator)| list |Each entry in this list results in the creation of one ConfigMap resource (it's a generator of n maps).|
|
||||
|[secretGenerator](#secretgenerator)| list |Each entry in this list results in the creation of one Secret resource (it's a generator of n secrets)|
|
||||
|[generatorOptions](#generatoroptions)|string|generatorOptions modify behavior of all ConfigMap and Secret generators|
|
||||
|[generators](#generators)|list|[plugin](plugins.md) configuration files|
|
||||
|[generators](#generators)|list|[plugin](plugins) configuration files|
|
||||
|
||||
|
||||
## Transformers
|
||||
@@ -38,9 +38,10 @@ What transformations (customizations) should be applied?
|
||||
| [namePrefix](#nameprefix) | string | Prepends value to the names of all resources |
|
||||
| [nameSuffix](#namesuffix) | string | The value is appended to the names of all resources. |
|
||||
| [replicas](#replicas) | list | Replicas modifies the number of replicas of a resource. |
|
||||
| [patches](#patches) | list | Each entry should resolve to a patch that can be applied to multiple targets. |
|
||||
|[patchesStrategicMerge](#patchesstrategicmerge)| list |Each entry in this list should resolve to a partial or complete resource definition file.|
|
||||
|[patchesJson6902](#patchesjson6902)| list |Each entry in this list should resolve to a kubernetes object and a JSON patch that will be applied to the object.|
|
||||
|[transformers](#transformers)|list|[plugin](plugins.md) configuration files|
|
||||
|[transformers](#transformers)|list|[plugin](plugins) configuration files|
|
||||
|
||||
|
||||
## Meta
|
||||
@@ -173,7 +174,7 @@ generatorOptions:
|
||||
|
||||
### generators
|
||||
|
||||
A list of generator [plugin](plugins.md) configuration files.
|
||||
A list of generator [plugin](plugins) configuration files.
|
||||
|
||||
```
|
||||
generators:
|
||||
@@ -263,11 +264,47 @@ resource type is ConfigMap or Secret.
|
||||
nameSuffix: -v2
|
||||
```
|
||||
|
||||
### patches
|
||||
|
||||
Each entry in this list should resolve to an Patch object,
|
||||
which includes a patch and a target selector.
|
||||
The patch can be either a strategic merge patch or a JSON patch.
|
||||
it can be either a patch file or an inline string.
|
||||
The target selects
|
||||
resources by group, version, kind, name, namespace,
|
||||
labelSelector and annotationSelector. A resource
|
||||
which matches all the specified fields is selected
|
||||
to apply the patch.
|
||||
|
||||
```
|
||||
patches:
|
||||
- path: patch.yaml
|
||||
target:
|
||||
group: apps
|
||||
version: v1
|
||||
kind: Deployment
|
||||
name: deploy.*
|
||||
labelSelector: "env=dev"
|
||||
annotationSelector: "zone=west"
|
||||
- patch: |-
|
||||
- op: replace
|
||||
path: some/existing/path
|
||||
value: new value
|
||||
target:
|
||||
kind: MyKind
|
||||
labelSelector: "env=dev"
|
||||
```
|
||||
|
||||
The `name` and `namespace` fields of the patch target selector are
|
||||
automatically anchored regular expressions. This means that the value `myapp`
|
||||
is equivalent to `^myapp$`.
|
||||
|
||||
### patchesStrategicMerge
|
||||
|
||||
Each entry in this list should be a relative path
|
||||
Each entry in this list should be either a relative
|
||||
file path or an inline content
|
||||
resolving to a partial or complete resource
|
||||
definition file.
|
||||
definition.
|
||||
|
||||
The names in these (possibly partial) resource
|
||||
files must match names already loaded via the
|
||||
@@ -286,6 +323,22 @@ patchesStrategicMerge:
|
||||
- deployment_increase_memory.yaml
|
||||
```
|
||||
|
||||
The patch content can be a inline string as well.
|
||||
```
|
||||
patchesStrategicMerge:
|
||||
- |-
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nignx:latest
|
||||
```
|
||||
|
||||
### patchesJson6902
|
||||
|
||||
Each entry in this list should resolve to
|
||||
@@ -307,12 +360,14 @@ The content in this patch file can be either in JSON format as
|
||||
|
||||
or in YAML format as
|
||||
|
||||
```
|
||||
- op: add
|
||||
path: /some/new/path
|
||||
value: value
|
||||
- op:replace
|
||||
- op: replace
|
||||
path: /some/existing/path
|
||||
value: new value
|
||||
```
|
||||
|
||||
```
|
||||
patchesJson6902:
|
||||
@@ -328,6 +383,23 @@ patchesJson6902:
|
||||
path: add_service_annotation.yaml
|
||||
```
|
||||
|
||||
The patch content can be an inline string as well:
|
||||
|
||||
```
|
||||
patchesJson6902:
|
||||
- target:
|
||||
version: v1
|
||||
kind: Deployment
|
||||
name: my-deployment
|
||||
patch: |-
|
||||
- op: add
|
||||
path: /some/new/path
|
||||
value: value
|
||||
- op: replace
|
||||
path: /some/existing/path
|
||||
value: "new value"
|
||||
```
|
||||
|
||||
### replicas
|
||||
|
||||
Replicas modified the number of replicas for a resource.
|
||||
@@ -356,6 +428,7 @@ be modified at the same time.
|
||||
|
||||
|
||||
#### Limitation
|
||||
|
||||
As this declaration does not take in a `kind:` nor a `group:`
|
||||
it will match any `group` and `kind` that has a matching name and
|
||||
that is one of:
|
||||
|
||||
@@ -405,7 +405,7 @@ A chunk of code used by kustomize, but not necessarily
|
||||
compiled into kustomize, to generate and/or transform a
|
||||
kubernetes resource as part of a kustomization.
|
||||
|
||||
Details [here](plugins.md).
|
||||
Details [here](plugins).
|
||||
|
||||
## resource
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ The _inventory_ ConfigMap contains two special annotations:
|
||||
struct that contains following information
|
||||
- all objects within this kustomization target
|
||||
- all objects that reference within this kustomization target
|
||||
|
||||
|
||||
Here is an example of an Inventory object
|
||||
```json
|
||||
{
|
||||
@@ -49,11 +49,11 @@ The _inventory_ ConfigMap contains two special annotations:
|
||||
],
|
||||
"~G_v1_Service|default|mysql":null
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- kustomize.config.k8s.io/InventoryHash
|
||||
The value of this annotation is a hash that is
|
||||
The value of this annotation is a hash that is
|
||||
computed from the list of items in the Inventory
|
||||
|
||||
Basically, this inventory object acts a record of objects that are applied as a group.
|
||||
@@ -150,7 +150,7 @@ metadata:
|
||||
annotations:
|
||||
kustomize.config.k8s.io/Inventory: '{"current":{"apps_v1_Deployment|default|mysql":null,"~G_v1_Secret|default|pass-dfg7h97cf6":[{"group":"apps","version":"v1","kind":"Deployment","name":"mysql","namespace":"default"}],"~G_v1_Service|default|mysql":null}}'
|
||||
kustomize.config.k8s.io/InventoryHash: 7mgt867b75
|
||||
name: haha
|
||||
name: root-cm
|
||||
namespace: default
|
||||
```
|
||||
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
# kustomize plugins
|
||||
|
||||
Quick guides:
|
||||
|
||||
* [linux exec plugin in 60 sec](execPluginGuidedExample.md)
|
||||
* [linux Go plugin in 60 sec](goPluginGuidedExample.md)
|
||||
|
||||
Kustomize offers a plugin framework allowing
|
||||
people to write their own resource _generators_
|
||||
and _transformers_.
|
||||
|
||||
[generator options]: ../examples/generatorOptions.md
|
||||
[transformer configs]: ../examples/transformerconfigs
|
||||
[generator options]: ../../examples/generatorOptions.md
|
||||
[transformer configs]: ../../examples/transformerconfigs
|
||||
|
||||
Write a plugin when changing [generator options]
|
||||
or [transformer configs] doesn't meet your needs.
|
||||
@@ -21,9 +26,9 @@ or [transformer configs] doesn't meet your needs.
|
||||
|
||||
* A _transformer_ plugin might perform special
|
||||
container command line edits, or any other
|
||||
transformation that exceeds the power of the
|
||||
builtin transformations (`namePrefix`,
|
||||
`commonLabels`, etc.).
|
||||
transformation beyond those provided by the
|
||||
builtin (`namePrefix`, `commonLabels`, etc.)
|
||||
transformers.
|
||||
|
||||
## Specification in `kustomization.yaml`
|
||||
|
||||
@@ -43,26 +48,21 @@ Each field accepts a string list:
|
||||
> - {as above}
|
||||
> ```
|
||||
|
||||
This is exactly like the syntax of the `resources`
|
||||
field.
|
||||
The value of each entry in a `generators` or
|
||||
`transformers` list must be a relative path to a
|
||||
YAML file, or a path or URL to a [kustomization].
|
||||
This is the same format as demanded by the
|
||||
`resources` field.
|
||||
|
||||
The value of each entry in a `resources`,
|
||||
`generators` or `transformers` list must be a
|
||||
relative path to a YAML file, or a path or URL
|
||||
to a [kustomization].
|
||||
[kustomization]: ../glossary.md#kustomization
|
||||
|
||||
[kustomization]: glossary.md#kustomization
|
||||
|
||||
In the former case the YAML is read from disk directly,
|
||||
and in the latter case a kustomization is performed,
|
||||
and its YAML output is merged with the YAML read
|
||||
directly from files. The net result in all three cases
|
||||
is a set of YAML objects.
|
||||
|
||||
Each object resulting from a `generators` or
|
||||
`transformers` field is now further interpreted by
|
||||
YAML files are read from disk directly. Paths or
|
||||
URLs leading to kustomizations trigger an
|
||||
in-process kustomization run. Each of the
|
||||
resulting objects is now further interpreted by
|
||||
kustomize as a _plugin configuration_ object.
|
||||
|
||||
|
||||
## Configuration
|
||||
|
||||
A kustomization file could have the following lines:
|
||||
@@ -72,11 +72,12 @@ generators:
|
||||
- chartInflator.yaml
|
||||
```
|
||||
|
||||
Given this, the kustomization process would expect to
|
||||
find a file called `chartInflator.yaml` in the
|
||||
kustomization [root](glossary.md#kustomization-root).
|
||||
Given this, the kustomization process would expect
|
||||
to find a file called `chartInflator.yaml` in the
|
||||
kustomization [root](../glossary.md#kustomization-root).
|
||||
|
||||
This is the _plugin's configuration file_.
|
||||
This is the plugin's configuration file;
|
||||
it contains a YAML configuration object.
|
||||
|
||||
The file `chartInflator.yaml` could contain:
|
||||
|
||||
@@ -91,19 +92,19 @@ chartName: minecraft
|
||||
__The `apiVersion` and `kind` fields are
|
||||
used to locate the plugin.__
|
||||
|
||||
[k8s object]: glossary.md#kubernetes-style-object
|
||||
[k8s object]: ../glossary.md#kubernetes-style-object
|
||||
|
||||
> Thus, these fields are required. They are also
|
||||
> required because a kustomize plugin
|
||||
> configuration object is also a [k8s object].
|
||||
Thus, these fields are required. They are also
|
||||
required because a kustomize plugin configuration
|
||||
object is also a [k8s object].
|
||||
|
||||
To get the plugin ready to generator or transform,
|
||||
To get the plugin ready to generate or transform,
|
||||
it is given the entire contents of the
|
||||
configuration file.
|
||||
|
||||
[NameTransformer]: ../plugin/builtin/prefixsuffixtransformer/PrefixSuffixTransformer_test.go
|
||||
[ChartInflator]: ../plugin/someteam.example.com/v1/chartinflator/ChartInflator_test.go
|
||||
[plugins]: ../plugin/builtin
|
||||
[NameTransformer]: ../../plugin/builtin/prefixsuffixtransformer/PrefixSuffixTransformer_test.go
|
||||
[ChartInflator]: ../../plugin/someteam.example.com/v1/chartinflator/ChartInflator_test.go
|
||||
[plugins]: ../../plugin/builtin
|
||||
|
||||
For more examples of plugin configuration YAML,
|
||||
browse the unit tests below the [plugins] root,
|
||||
@@ -115,16 +116,18 @@ e.g. the tests for [ChartInflator] or
|
||||
|
||||
Each plugin gets its own dedicated directory named
|
||||
|
||||
[`XDG_CONFIG_HOME`]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||
|
||||
```
|
||||
$XDG_CONFIG_HOME/kustomize/plugin
|
||||
/${apiVersion}/LOWERCASE(${kind})
|
||||
```
|
||||
|
||||
The default value of `XDG_CONFIG_HOME` is
|
||||
The default value of [`XDG_CONFIG_HOME`] is
|
||||
`$HOME/.config`.
|
||||
|
||||
The one-plugin-per-directory requirement eases
|
||||
creation of a plugin tarball (source, test, plugin
|
||||
creation of a plugin bundle (source, tests, plugin
|
||||
data files, etc.) for sharing.
|
||||
|
||||
In the case of a [Go plugin](#go-plugins), it also
|
||||
@@ -154,9 +157,8 @@ Plugins are only used during a run of the
|
||||
`kustomize build` command.
|
||||
|
||||
Generator plugins are run after processing the
|
||||
`resources` field (which itself is in some sense a
|
||||
generator in that it emits resources for further
|
||||
processing).
|
||||
`resources` field (which itself can be viewed as a
|
||||
generator, simply reading objects from disk).
|
||||
|
||||
The full set of resources is then passed into the
|
||||
transformation pipeline, wherein builtin
|
||||
@@ -166,28 +168,38 @@ in the kustomization file), followed by the
|
||||
user-specified transformers in the `transformers`
|
||||
field.
|
||||
|
||||
The specified order of transformers in the
|
||||
`transformers` field should be respected, as
|
||||
transformers cannot be expected to be commutative.
|
||||
The order specified in the `transformers` field is
|
||||
respected, as transformers cannot be expected to
|
||||
be commutative.
|
||||
|
||||
#### No Security
|
||||
|
||||
Kustomize plugins do not run in any kind of
|
||||
kustomize-provided sandbox. There's no notion
|
||||
of _"plugin security"_.
|
||||
|
||||
A `kustomize build` that tries to use plugins but
|
||||
omits the flag
|
||||
|
||||
> `--enable_alpha_plugins`
|
||||
|
||||
will fail with a warning about plugin use.
|
||||
will not load plugins and will fail with a
|
||||
warning about plugin use.
|
||||
|
||||
Flag use is an opt-in acknowledging the absence of
|
||||
plugin provenance. It's meant to give pause to
|
||||
someone who blindly downloads a kustomization from
|
||||
the internet and attempts to run it, without
|
||||
realizing that it might attempt to run 3rd party
|
||||
code in plugin form. The plugin would have to be
|
||||
installed already, but nevertheless the flag is a
|
||||
reminder.
|
||||
The use of this flag is an opt-in acknowledging
|
||||
the unstable (alpha) plugin API, the absence of
|
||||
plugin provenance, and the fact that a plugin
|
||||
is not part of kustomize.
|
||||
|
||||
To be clear, some kustomize plugin downloaded
|
||||
from the internet might wonderfully transform
|
||||
k8s config in a desired manner, while also
|
||||
quietly doing anything the user could do to the
|
||||
system running `kustomize build`.
|
||||
|
||||
## Writing plugins
|
||||
## Authoring
|
||||
|
||||
There are two kinds of plugins, [exec](#exec-plugins) and [Go](#go-plugins).
|
||||
|
||||
### Exec plugins
|
||||
|
||||
@@ -196,20 +208,21 @@ single argument on its command line - the name of
|
||||
a YAML file containing its configuration (the file name
|
||||
provided in the kustomization file).
|
||||
|
||||
> TODO: more restrictions on plugin to allow the same exec
|
||||
> plugin to be specified in a config under both the
|
||||
> TODO: restrictions on plugin to allow the _same exec
|
||||
> plugin_ to be targetted by both the
|
||||
> `generators` and `transformers` fields.
|
||||
>
|
||||
> - first arg could be the fixed string
|
||||
> `generate` or `transform`,
|
||||
> (the name of the configuration file moves to
|
||||
> the 2nd arg), or
|
||||
> - by default an exec plugin behaves as a tranformer
|
||||
> - or by default an exec plugin behaves as a tranformer
|
||||
> unless a flag `-g` is provided, switching the
|
||||
> exec plugin to behave as a generator.
|
||||
|
||||
[helm chart inflator]: ../plugin/someteam.example.com/v1/chartinflator
|
||||
[bashed config map]: ../plugin/someteam.example.com/v1/bashedconfigmap
|
||||
[sed transformer]: ../plugin/someteam.example.com/v1/sedtransformer
|
||||
[helm chart inflator]: ../../plugin/someteam.example.com/v1/chartinflator
|
||||
[bashed config map]: ../../plugin/someteam.example.com/v1/bashedconfigmap
|
||||
[sed transformer]: ../../plugin/someteam.example.com/v1/sedtransformer
|
||||
|
||||
#### Examples
|
||||
|
||||
@@ -232,16 +245,27 @@ marshalled resources on `stdin` and capture
|
||||
|
||||
### Go plugins
|
||||
|
||||
Be sure to read [Go plugin caveats](goPluginCaveats.md).
|
||||
|
||||
[Go plugin]: https://golang.org/pkg/plugin/
|
||||
|
||||
A [Go plugin] for kustomize looks like this:
|
||||
A `.go` file can be a [Go plugin] if it declares
|
||||
'main' as it's package, and exports a symbol to
|
||||
which useful functions are attached.
|
||||
|
||||
It can further be used as a _kustomize_ plugin if
|
||||
the symbol is named 'KustomizePlugin' and the
|
||||
attached functions implement the `Configurable`,
|
||||
`Generator` and `Transformer` interfaces.
|
||||
|
||||
A Go plugin for kustomize looks like this:
|
||||
|
||||
> ```
|
||||
> package main
|
||||
>
|
||||
> import (
|
||||
> "sigs.k8s.io/kustomize/pkg/ifc"
|
||||
> "sigs.k8s.io/kustomize/pkg/resmap"
|
||||
> "sigs.k8s.io/kustomize/v3/pkg/ifc"
|
||||
> "sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
> ...
|
||||
> )
|
||||
>
|
||||
@@ -269,27 +293,28 @@ file to be added to the `generators` or
|
||||
`transformers` field in the kustomization file.
|
||||
Do one or the other or both as desired.
|
||||
|
||||
[secret generator]: ../plugin/someteam.example.com/v1/secretsfromdatabase
|
||||
[service generator]: ../plugin/someteam.example.com/v1/someservicegenerator
|
||||
[string prefixer]: ../plugin/someteam.example.com/v1/stringprefixer
|
||||
[date prefixer]: ../plugin/someteam.example.com/v1/dateprefixer
|
||||
|
||||
[secret generator]: ../../plugin/someteam.example.com/v1/secretsfromdatabase
|
||||
[service generator]: ../../plugin/someteam.example.com/v1/someservicegenerator
|
||||
[string prefixer]: ../../plugin/someteam.example.com/v1/stringprefixer
|
||||
[date prefixer]: ../../plugin/someteam.example.com/v1/dateprefixer
|
||||
[sops encoded secrets]: https://github.com/monopole/sopsencodedsecrets
|
||||
|
||||
#### Examples
|
||||
|
||||
* [secret generator] - Generate secrets from a database.
|
||||
* [service generator] - Generate a service from a name and port argument.
|
||||
* [service generator] - generate a service from a name and port argument.
|
||||
* [string prefixer] - uses the value in `metadata/name` as the prefix.
|
||||
This particular example exists to show how a plugin can
|
||||
transform the behavior of a plugin. See the
|
||||
`TestTransformedTransformers` test in the `target` package.
|
||||
* [date prefixer] - prefix the current date to resource names, a simple
|
||||
example used to modify the string prefixer plugin just mentioned.
|
||||
* All the builtin plugins [here](../plugin/builtin).
|
||||
* [secret generator] - generate secrets from a toy database.
|
||||
* [sops encoded secrets] - a more complex secret generator.
|
||||
* [All the builtin plugins](../../plugin/builtin).
|
||||
User authored plugins are
|
||||
on the same footing as builtin operations.
|
||||
|
||||
A plugin can be both a generator and a
|
||||
A Go plugin can be both a generator and a
|
||||
transformer. The `Generate` method will run along
|
||||
with all the other generators before the
|
||||
`Transform` method runs.
|
||||
@@ -306,43 +331,3 @@ go build -buildmode plugin \
|
||||
-o $d/${kind}.so $d/${kind}.go
|
||||
```
|
||||
|
||||
#### Caveats
|
||||
|
||||
Go plugins allow kustomize extensions that run
|
||||
without the cost marshalling/unmarshalling all
|
||||
resource data to/from a subprocess for each plugin
|
||||
run.
|
||||
|
||||
[ELF]: https://en.wikipedia.org/wiki/Executable_and_Linkable_Format
|
||||
|
||||
Go plugins work as [defined][Go plugin], but fall
|
||||
short of common notions associated with the word
|
||||
_plugin_. Go plugin compilation creates an [ELF]
|
||||
formatted `.so` file, which by definition has no
|
||||
information about the provenance of the object
|
||||
code. Skew between the compilation conditions
|
||||
(versions of package dependencies, `GOOS`,
|
||||
`GOARCH`) of the main program ELF and the plugin
|
||||
ELF will cause plugin load failure.
|
||||
|
||||
Exec plugins also lack provenance, but won't
|
||||
complain about compilation skew.
|
||||
|
||||
In either case, a sensible way to share a plugin
|
||||
is as a tar file of source code, tests and
|
||||
associated data, unpackable under
|
||||
`$XDG_CONFIG_HOME/kustomize/plugin` (exactly where
|
||||
one would develop a plugin).
|
||||
|
||||
[Go modules]: https://github.com/golang/go/wiki/Modules
|
||||
|
||||
In the case of a Go plugin, an end user accepting
|
||||
a shared plugin must compile both kustomize and
|
||||
the plugin. Tooling could be built to make Go
|
||||
_plugin sharing_ easier, but this requires some
|
||||
critical mass of _plugin authoring_, which in turn
|
||||
is hampered by confusion around sharing.
|
||||
[Go modules], once they are more widely adopted,
|
||||
will solve one of the biggest plugin sharing
|
||||
difficulties - ambiguous plugin vs host
|
||||
dependencies.
|
||||
229
docs/plugins/execPluginGuidedExample.md
Normal file
229
docs/plugins/execPluginGuidedExample.md
Normal file
@@ -0,0 +1,229 @@
|
||||
# Exec plugin on linux in 60 seconds
|
||||
|
||||
This is a (no reading allowed!) 60 second copy/paste guided
|
||||
example. Full plugin docs [here](README.md).
|
||||
|
||||
This demo writes and uses a somewhat ridiculous
|
||||
_exec_ plugin (written in bash) that generates a
|
||||
`ConfigMap`.
|
||||
|
||||
This is a guide to try it without damaging your
|
||||
current setup.
|
||||
|
||||
#### requirements
|
||||
|
||||
* linux, git, curl, Go 1.12
|
||||
|
||||
|
||||
## Make a place to work
|
||||
|
||||
```
|
||||
DEMO=$(mktemp -d)
|
||||
```
|
||||
|
||||
## Create a kustomization
|
||||
|
||||
Make a kustomization directory to
|
||||
hold all your config:
|
||||
|
||||
```
|
||||
MYAPP=$DEMO/myapp
|
||||
mkdir -p $MYAPP
|
||||
```
|
||||
|
||||
Make a deployment config:
|
||||
|
||||
```
|
||||
cat <<'EOF' >$MYAPP/deployment.yaml
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: the-deployment
|
||||
spec:
|
||||
replicas: 3
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: the-container
|
||||
image: monopole/hello:1
|
||||
command: ["/hello",
|
||||
"--port=8080",
|
||||
"--date=$(THE_DATE)",
|
||||
"--enableRiskyFeature=$(ENABLE_RISKY)"]
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
env:
|
||||
- name: THE_DATE
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: the-map
|
||||
key: today
|
||||
- name: ALT_GREETING
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: the-map
|
||||
key: altGreeting
|
||||
- name: ENABLE_RISKY
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: the-map
|
||||
key: enableRisky
|
||||
EOF
|
||||
```
|
||||
|
||||
Make a service config:
|
||||
|
||||
```
|
||||
cat <<EOF >$MYAPP/service.yaml
|
||||
kind: Service
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: the-service
|
||||
spec:
|
||||
type: LoadBalancer
|
||||
ports:
|
||||
- protocol: TCP
|
||||
port: 8666
|
||||
targetPort: 8080
|
||||
EOF
|
||||
```
|
||||
|
||||
Now make a config file for the plugin
|
||||
you're about to write.
|
||||
|
||||
This config file is just another k8s resource
|
||||
object. The values of its `apiVersion` and `kind`
|
||||
fields are used to _find_ the plugin code on your
|
||||
filesystem (more on this later).
|
||||
|
||||
```
|
||||
cat <<'EOF' >$MYAPP/cmGenerator.yaml
|
||||
apiVersion: myDevOpsTeam
|
||||
kind: SillyConfigMapGenerator
|
||||
metadata:
|
||||
name: whatever
|
||||
argsOneLiner: Bienvenue true
|
||||
EOF
|
||||
```
|
||||
|
||||
Finally, make a kustomization file
|
||||
referencing all of the above:
|
||||
|
||||
```
|
||||
cat <<EOF >$MYAPP/kustomization.yaml
|
||||
commonLabels:
|
||||
app: hello
|
||||
resources:
|
||||
- deployment.yaml
|
||||
- service.yaml
|
||||
generators:
|
||||
- cmGenerator.yaml
|
||||
EOF
|
||||
```
|
||||
|
||||
Review the files
|
||||
```
|
||||
ls -C1 $MYAPP
|
||||
```
|
||||
|
||||
|
||||
## Make a home for plugins
|
||||
|
||||
Plugins must live in a particular place for
|
||||
kustomize to find them.
|
||||
|
||||
This demo will use the ephemeral directory:
|
||||
|
||||
```
|
||||
PLUGIN_ROOT=$DEMO/kustomize/plugin
|
||||
```
|
||||
|
||||
The plugin config defined above in
|
||||
`$MYAPP/cmGenerator.yaml` specifies:
|
||||
|
||||
> ```
|
||||
> apiVersion: myDevOpsTeam
|
||||
> kind: SillyConfigMapGenerator
|
||||
> ```
|
||||
|
||||
This means the plugin must live in a directory
|
||||
named:
|
||||
|
||||
```
|
||||
MY_PLUGIN_DIR=$PLUGIN_ROOT/myDevOpsTeam/sillyconfigmapgenerator
|
||||
|
||||
mkdir -p $MY_PLUGIN_DIR
|
||||
```
|
||||
|
||||
The directory name is the plugin config's
|
||||
_apiVersion_ followed by its lower-cased _kind_.
|
||||
|
||||
A plugin gets its own directory to hold itself,
|
||||
its tests and any supplemental data files it
|
||||
might need.
|
||||
|
||||
## Create the plugin
|
||||
|
||||
There are two kinds of plugins, _exec_ and _Go_.
|
||||
|
||||
Make an _exec_ plugin, installing it to the
|
||||
correct directory and file name. The file name
|
||||
must match the plugin's _kind_ (in this case,
|
||||
`SillyConfigMapGenerator`):
|
||||
|
||||
```
|
||||
cat <<'EOF' >$MY_PLUGIN_DIR/SillyConfigMapGenerator
|
||||
#!/bin/bash
|
||||
# Skip the config file name argument.
|
||||
shift
|
||||
today=`date +%F`
|
||||
echo "
|
||||
kind: ConfigMap
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: the-map
|
||||
data:
|
||||
today: $today
|
||||
altGreeting: "$1"
|
||||
enableRisky: "$2"
|
||||
"
|
||||
EOF
|
||||
```
|
||||
|
||||
By definition, an _exec_ plugin must be executable:
|
||||
|
||||
```
|
||||
chmod a+x $MY_PLUGIN_DIR/SillyConfigMapGenerator
|
||||
```
|
||||
|
||||
## Download kustomize 3.0.0
|
||||
|
||||
```
|
||||
mkdir -p $DEMO/bin
|
||||
gh=https://github.com/kubernetes-sigs/kustomize/releases/download
|
||||
url=$gh/v3.0.0-pre/kustomize_3.0.0-pre_linux_amd64
|
||||
curl -o $DEMO/bin/kustomize -L $url
|
||||
chmod u+x $DEMO/bin/kustomize
|
||||
```
|
||||
|
||||
## Review the layout
|
||||
|
||||
```
|
||||
tree $DEMO
|
||||
```
|
||||
|
||||
## Build your app, using the plugin:
|
||||
|
||||
```
|
||||
XDG_CONFIG_HOME=$DEMO $DEMO/bin/kustomize build --enable_alpha_plugins $MYAPP
|
||||
```
|
||||
|
||||
Above, if you had set
|
||||
|
||||
> ```
|
||||
> PLUGIN_ROOT=$HOME/.config/kustomize/plugin
|
||||
> ```
|
||||
|
||||
there would be no need to use `XDG_CONFIG_HOME` in the
|
||||
_kustomize_ command above.
|
||||
|
||||
117
docs/plugins/goPluginCaveats.md
Normal file
117
docs/plugins/goPluginCaveats.md
Normal file
@@ -0,0 +1,117 @@
|
||||
[plugin package]: https://golang.org/pkg/plugin
|
||||
[Go modules]: https://github.com/golang/go/wiki/Modules
|
||||
[ELF]: https://en.wikipedia.org/wiki/Executable_and_Linkable_Format
|
||||
[tensorflow plugin]: https://www.tensorflow.org/guide/extend/op
|
||||
|
||||
# Go plugin Caveats
|
||||
|
||||
A _Go plugin_ is a compilation artifact described
|
||||
by the Go [plugin package]. It is built with
|
||||
special flags and cannot run on its own.
|
||||
It must be loaded into a running Go program.
|
||||
|
||||
> A normal program written in Go might be usable
|
||||
> as _exec plugin_, but is not a _Go plugin_.
|
||||
|
||||
Go plugins allow kustomize extensions that run
|
||||
without the cost marshalling/unmarshalling all
|
||||
resource data to/from a subprocess for each plugin
|
||||
run. The Go plugin API assures a certain level of
|
||||
consistency to avoid confusing downstream
|
||||
transformers.
|
||||
|
||||
Go plugins work as described in the [plugin
|
||||
package], but fall short of common notions
|
||||
associated with the word _plugin_.
|
||||
|
||||
## The skew problem
|
||||
|
||||
Go plugin compilation creates an [ELF] formatted
|
||||
`.so` file, which by definition has no information
|
||||
about the provenance of the object code.
|
||||
|
||||
Skew between the compilation conditions (versions
|
||||
of package dependencies, `GOOS`, `GOARCH`) of the
|
||||
main program ELF and the plugin ELF will cause
|
||||
plugin load failure, with non-helpful error
|
||||
messages.
|
||||
|
||||
Exec plugins also lack provenance, but won't fail
|
||||
due to compilation skew.
|
||||
|
||||
In either case, the only sensible way to share a
|
||||
plugin is as some kind of _bundle_ (a git repo
|
||||
URL, a git archive file, a tar file, etc.)
|
||||
containing source code, tests and associated data,
|
||||
unpackable under
|
||||
`$XDG_CONFIG_HOME/kustomize/plugin`.
|
||||
|
||||
In the case of a Go plugin, an _end user_
|
||||
accepting a shared plugin _must compile both
|
||||
kustomize and the plugin_.
|
||||
|
||||
This means a one-time run of
|
||||
```
|
||||
GOPATH=${whatever} go get \
|
||||
sigs.k8s.io/kustomize/cmd/kustomize@${releaseVersion}
|
||||
```
|
||||
|
||||
and then a normal development cycle using
|
||||
|
||||
```
|
||||
go build -buildmode plugin \
|
||||
-o ${wherever}/${kind}.so ${wherever}/${kind}.go
|
||||
```
|
||||
with paths and the release version tag (e.g. `v3.0.0`)
|
||||
adjusted as needed.
|
||||
|
||||
For comparison, consider what one
|
||||
must do to write a [tensorflow plugin].
|
||||
|
||||
## Why support Go plugins?
|
||||
|
||||
### Safety
|
||||
|
||||
The Go plugin developer sees the same API offered
|
||||
to native kustomize operations, assuring certain
|
||||
semantics, invariants, checks, etc. An exec
|
||||
plugin sub-process dealing with this via
|
||||
stdin/stdout will have an easier time screwing
|
||||
things up for downstream transformers and
|
||||
consumers.
|
||||
|
||||
Minor point: if the plugin reads files via
|
||||
the kustomize-provided file `Loader` interface, it
|
||||
will be constrained by kustomize file loading
|
||||
restrictions. Of course, nothing but a code audit
|
||||
prevents a Go plugin from importing the `io` package
|
||||
and doing whatever it wants.
|
||||
|
||||
### Debugging
|
||||
|
||||
A Go plugin developer can debug the plugin _in
|
||||
situ_, setting breakpoints inside the plugin and
|
||||
elsewhere while running a plugin in feature tests.
|
||||
|
||||
To get the best of both worlds (shareability and safety),
|
||||
a developer can write an `.go` program that functions
|
||||
as an _exec plugin_, but can be processed by `go generate`
|
||||
to emit a _Go plugin_ (or vice versa).
|
||||
|
||||
### Unit of contribution
|
||||
|
||||
All the builtin generators and transformers
|
||||
are themselves Go plugins. This means that
|
||||
the kustomize maintainers can promote a contributed
|
||||
plugin to a builtin without needing code changes
|
||||
(beyond those mandated by normal code review).
|
||||
|
||||
### Ecosystems grow through use
|
||||
|
||||
Tooling could ease Go plugin _sharing_, but this
|
||||
requires some critical mass of Go plugin
|
||||
_authoring_, which in turn is hampered by
|
||||
confusion around sharing. [Go modules], once they
|
||||
are more widely adopted, will solve the
|
||||
biggest plugin sharing difficulty: ambiguous
|
||||
plugin vs host dependencies.
|
||||
367
docs/plugins/goPluginGuidedExample.md
Normal file
367
docs/plugins/goPluginGuidedExample.md
Normal file
@@ -0,0 +1,367 @@
|
||||
# Go Plugin Guided Example for Linux
|
||||
|
||||
[SopsEncodedSecrets repository]: https://github.com/monopole/sopsencodedsecrets
|
||||
[Go plugin]: https://golang.org/pkg/plugin
|
||||
[Go plugin caveats]: goPluginCaveats.md
|
||||
|
||||
This is a (no reading allowed!) 60 second copy/paste guided
|
||||
example.
|
||||
|
||||
Full plugin docs [here](README.md).
|
||||
Be sure to read the [Go plugin caveats].
|
||||
|
||||
This demo uses a Go plugin, `SopsEncodedSecrets`,
|
||||
that lives in the [sopsencodedsecrets repository].
|
||||
This is an inprocess [Go plugin], not an
|
||||
sub-process exec plugin that happens to be written
|
||||
in Go (which is another option for Go authors).
|
||||
|
||||
This is a guide to try it without damaging your
|
||||
current setup.
|
||||
|
||||
#### requirements
|
||||
|
||||
* linux, git, curl, Go 1.12
|
||||
|
||||
For encryption
|
||||
|
||||
* gpg
|
||||
|
||||
Or
|
||||
|
||||
* Google cloud (gcloud) install
|
||||
* a Google account with KMS permission
|
||||
|
||||
## Make a place to work
|
||||
|
||||
```shell
|
||||
# Keeping these separate to avoid cluttering the DEMO dir.
|
||||
DEMO=$(mktemp -d)
|
||||
tmpGoPath=$(mktemp -d)
|
||||
```
|
||||
|
||||
## Install kustomize
|
||||
|
||||
Need v3.0.0 for what follows, and you must _compile_
|
||||
it (not download the binary from the release page):
|
||||
|
||||
```shell
|
||||
GOPATH=$tmpGoPath go install sigs.k8s.io/kustomize/v3/cmd/kustomize
|
||||
```
|
||||
|
||||
## Make a home for plugins
|
||||
|
||||
A kustomize plugin is fully determined by
|
||||
its configuration file and source code.
|
||||
|
||||
[required fields]: https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/#required-fields
|
||||
|
||||
Kustomize plugin configuration files are formatted
|
||||
as kubernetes resource objects, meaning
|
||||
`apiVersion`, `kind` and `metadata` are [required
|
||||
fields] in these config files.
|
||||
|
||||
The kustomize program reads the config file
|
||||
(because the config file name appears in the
|
||||
`generators` or `transformers` field in the
|
||||
kustomization file), then locates the Go plugin's
|
||||
object code at the following location:
|
||||
|
||||
> ```shell
|
||||
> $XGD_CONFIG_HOME/kustomize/plugin/$apiVersion/$lKind/$kind.so
|
||||
> ```
|
||||
|
||||
where `lKind` holds the lowercased kind. The
|
||||
plugin is then loaded and fed its config, and the
|
||||
plugin's output becomes part of the overall
|
||||
`kustomize build` process.
|
||||
|
||||
The same plugin might be used multiple times in
|
||||
one kustomize build, but with different config
|
||||
files. Also, kustomize might customize config
|
||||
data before sending it to the plugin, for whatever
|
||||
reason. For these reasons, kustomize owns the
|
||||
mapping between plugins and config data; it's not
|
||||
left to plugins to find their own config.
|
||||
|
||||
This demo will house the plugin it uses at the
|
||||
ephemeral directory
|
||||
|
||||
```shell
|
||||
PLUGIN_ROOT=$DEMO/kustomize/plugin
|
||||
```
|
||||
|
||||
and ephemerally set `XGD_CONFIG_HOME` on a command
|
||||
line below.
|
||||
|
||||
### What apiVersion and kind?
|
||||
|
||||
At this stage in the development of kustomize
|
||||
plugins, plugin code doesn't know or care what
|
||||
`apiVersion` or `kind` appears in the config file
|
||||
sent to it.
|
||||
|
||||
The plugin could check these fields, but it's the
|
||||
remaining fields that provide actual configuration
|
||||
data, and at this point the successful parsing of
|
||||
these other fields are the only thing that matters
|
||||
to a plugin.
|
||||
|
||||
This demo uses a plugin called _SopsEncodedSecrets_,
|
||||
and it lives in the [SopsEncodedSecrets repository].
|
||||
|
||||
Somewhat arbitrarily, we'll chose to install
|
||||
this plugin with
|
||||
|
||||
```shell
|
||||
apiVersion=mygenerators
|
||||
kind=SopsEncodedSecrets
|
||||
```
|
||||
|
||||
### Define the plugin's home dir
|
||||
|
||||
By convention, the ultimate home of the plugin
|
||||
code and supplemental data, tests, documentation,
|
||||
etc. is the lowercase form of its kind.
|
||||
|
||||
```shell
|
||||
lKind=$(echo $kind | awk '{print tolower($0)}')
|
||||
```
|
||||
|
||||
### Download the SopsEncodedSecrets plugin
|
||||
|
||||
In this case, the repo name matches the lowercase
|
||||
kind already, so we just clone the repo and get
|
||||
the proper directory name automatically:
|
||||
|
||||
```shell
|
||||
mkdir -p $PLUGIN_ROOT/${apiVersion}
|
||||
cd $PLUGIN_ROOT/${apiVersion}
|
||||
git clone git@github.com:monopole/sopsencodedsecrets.git
|
||||
```
|
||||
|
||||
Remember this directory:
|
||||
|
||||
```shell
|
||||
MY_PLUGIN_DIR=$PLUGIN_ROOT/${apiVersion}/${lKind}
|
||||
```
|
||||
|
||||
### Try the plugin's own test
|
||||
|
||||
Plugins may come with their own tests.
|
||||
This one does, and it hopefully passes:
|
||||
|
||||
```shell
|
||||
cd $MY_PLUGIN_DIR
|
||||
go test SopsEncodedSecrets_test.go
|
||||
```
|
||||
|
||||
Build the object code for use by kustomize:
|
||||
|
||||
```shell
|
||||
cd $MY_PLUGIN_DIR
|
||||
GOPATH=$tmpGoPath go build -buildmode plugin -o ${kind}.so ${kind}.go
|
||||
```
|
||||
|
||||
This step may succeed, but kustomize might
|
||||
ultimately fail to load the plugin because of
|
||||
dependency [skew].
|
||||
|
||||
[skew]: https://github.com/kubernetes-sigs/kustomize/blob/master/docs/plugins/README.md#caveats
|
||||
[used in this demo]: #install-kustomize
|
||||
|
||||
On load failure
|
||||
|
||||
* be sure to build the plugin with the same
|
||||
version of Go (_go1.12_) on the same `$GOOS`
|
||||
(_linux_) and `$GOARCH` (_amd64_) used to build
|
||||
the kustomize being [used in this demo].
|
||||
|
||||
* change the plugin's dependencies in its `go.mod`
|
||||
to match the versions used by kustomize (check
|
||||
kustomize's `go.mod` used in its tagged commit).
|
||||
|
||||
Lacking tools and metadata to allow this to be
|
||||
automated, there won't be a Go plugin ecosystem.
|
||||
|
||||
Kustomize has adopted a Go plugin architecture as
|
||||
to ease accept new generators and transformers
|
||||
(just write a plugin), and to be sure that native
|
||||
operations (also constructed and tested as
|
||||
plugins) are compartmentalized, orderable and
|
||||
reusable instead of bizarrely woven throughout the
|
||||
code as a individual special cases.
|
||||
|
||||
## Create a kustomization
|
||||
|
||||
Make a kustomization directory to
|
||||
hold all your config:
|
||||
|
||||
```shell
|
||||
MYAPP=$DEMO/myapp
|
||||
mkdir -p $MYAPP
|
||||
```
|
||||
|
||||
Make a config file for the SopsEncodedSecrets plugin.
|
||||
|
||||
Its `apiVersion` and `kind` allow the plugin to be
|
||||
found:
|
||||
|
||||
```shell
|
||||
cat <<EOF >$MYAPP/secGenerator.yaml
|
||||
apiVersion: ${apiVersion}
|
||||
kind: ${kind}
|
||||
metadata:
|
||||
name: mySecretGenerator
|
||||
name: forbiddenValues
|
||||
namespace: production
|
||||
file: myEncryptedData.yaml
|
||||
keys:
|
||||
- ROCKET
|
||||
- CAR
|
||||
EOF
|
||||
```
|
||||
|
||||
This plugin expects to find more data in
|
||||
`myEncryptedData.yaml`; we'll get to that shortly.
|
||||
|
||||
Make a kustomization file referencing the plugin
|
||||
config:
|
||||
|
||||
```shell
|
||||
cat <<EOF >$MYAPP/kustomization.yaml
|
||||
commonLabels:
|
||||
app: hello
|
||||
generators:
|
||||
- secGenerator.yaml
|
||||
EOF
|
||||
```
|
||||
|
||||
Now generate the real encrypted data.
|
||||
|
||||
### Assure you have an encryption tool installed
|
||||
|
||||
We're going to use [sops](https://github.com/mozilla/sops) to encode a file. Choose either GPG or Google Cloud KMS as the secret provider to continue.
|
||||
|
||||
#### GPG
|
||||
|
||||
Try this:
|
||||
|
||||
```shell
|
||||
gpg --list-keys
|
||||
```
|
||||
|
||||
If it returns a list, presumably you've already created keys. If not, try import test keys from sops for dev.
|
||||
|
||||
```shell
|
||||
curl https://raw.githubusercontent.com/mozilla/sops/master/pgp/sops_functional_tests_key.asc | gpg --import
|
||||
SOPS_PGP_FP="1022470DE3F0BC54BC6AB62DE05550BC07FB1A0A"
|
||||
```
|
||||
|
||||
#### Google Cloude KMS
|
||||
|
||||
Try this:
|
||||
|
||||
```shell
|
||||
gcloud kms keys list --location global --keyring sops
|
||||
```
|
||||
|
||||
If it succeeds, presumably you've already created keys and placed them in a keyring called sops. If not, do this:
|
||||
|
||||
```shell
|
||||
gcloud kms keyrings create sops --location global
|
||||
gcloud kms keys create sops-key --location global \
|
||||
--keyring sops --purpose encryption
|
||||
```
|
||||
|
||||
Extract your keyLocation for use below:
|
||||
|
||||
```shell
|
||||
keyLocation=$(\
|
||||
gcloud kms keys list --location global --keyring sops |\
|
||||
grep GOOGLE | cut -d " " -f1)
|
||||
echo $keyLocation
|
||||
```
|
||||
|
||||
### Install `sops`
|
||||
|
||||
```shell
|
||||
GOPATH=$tmpGoPath go install go.mozilla.org/sops/cmd/sops
|
||||
```
|
||||
|
||||
### Create data encrypted with your private key
|
||||
|
||||
Create raw data to encrypt:
|
||||
|
||||
```shell
|
||||
cat <<EOF >$MYAPP/myClearData.yaml
|
||||
VEGETABLE: carrot
|
||||
ROCKET: saturn-v
|
||||
FRUIT: apple
|
||||
CAR: dymaxion
|
||||
EOF
|
||||
```
|
||||
|
||||
Encrypt the data into file the plugin wants to read:
|
||||
|
||||
With PGP
|
||||
|
||||
```shell
|
||||
$tmpGoPath/bin/sops --encrypt \
|
||||
--pgp $SOPS_PGP_FP \
|
||||
$MYAPP/myClearData.yaml >$MYAPP/myEncryptedData.yaml
|
||||
```
|
||||
|
||||
Or GCP KMS
|
||||
|
||||
```shell
|
||||
$tmpGoPath/bin/sops --encrypt \
|
||||
--gcp-kms $keyLocation \
|
||||
$MYAPP/myClearData.yaml >$MYAPP/myEncryptedData.yaml
|
||||
```
|
||||
|
||||
Review the files
|
||||
|
||||
```shell
|
||||
tree $DEMO
|
||||
```
|
||||
|
||||
This should look something like:
|
||||
|
||||
> ```shell
|
||||
> /tmp/tmp.0kIE9VclPt
|
||||
> ├── kustomize
|
||||
> │ └── plugin
|
||||
> │ └── mygenerators
|
||||
> │ └── sopsencodedsecrets
|
||||
> │ ├── go.mod
|
||||
> │ ├── go.sum
|
||||
> │ ├── LICENSE
|
||||
> │ ├── README.md
|
||||
> │ ├── SopsEncodedSecrets.go
|
||||
> │ ├── SopsEncodedSecrets.so
|
||||
> │ └── SopsEncodedSecrets_test.go
|
||||
> └── myapp
|
||||
> ├── kustomization.yaml
|
||||
> ├── myClearData.yaml
|
||||
> ├── myEncryptedData.yaml
|
||||
> └── secGenerator.yaml
|
||||
> ```
|
||||
|
||||
## Build your app, using the plugin:
|
||||
|
||||
```shell
|
||||
XDG_CONFIG_HOME=$DEMO $tmpGoPath/bin/kustomize build --enable_alpha_plugins $MYAPP
|
||||
```
|
||||
|
||||
This should emit a kubernetes secret, with
|
||||
encrypted data for the names `ROCKET` and `CAR`.
|
||||
|
||||
Above, if you had set
|
||||
|
||||
> ```shell
|
||||
> PLUGIN_ROOT=$HOME/.config/kustomize/plugin
|
||||
> ```
|
||||
|
||||
there would be no need to use `XDG_CONFIG_HOME` in the
|
||||
_kustomize_ command above.
|
||||
@@ -13,6 +13,6 @@ History
|
||||
* Oct 2017: s/kexpand/kinflate/
|
||||
* Sep 2017: kexpand [starts](https://github.com/kubernetes/kubectl/pull/65)
|
||||
in [github.com/kubernetes/kubectl]
|
||||
* Aug 2018: [DAM] authored by Brian Grant
|
||||
* Aug 2017: [DAM] authored by Brian Grant
|
||||
|
||||
[DAM]: https://docs.google.com/document/d/1cLPGweVEYrVqQvBLJg6sxV-TrE5Rm2MNOBA_cxZP2WU
|
||||
@@ -1,6 +1,5 @@
|
||||
# kustomize 2.1.0
|
||||
|
||||
|
||||
[Go modules]: https://github.com/golang/go/wiki/Modules
|
||||
[generator options]: ../examples/generatorOptions.md
|
||||
[imgModules]: images/goModules.png
|
||||
@@ -14,7 +13,7 @@
|
||||
[bases]: glossary.md#base
|
||||
[_base_]: glossary.md#base
|
||||
[kustomize inventory object documentation]: inventory_object.md
|
||||
[kustomize plugin documentation]: plugins.md
|
||||
[kustomize plugin documentation]: plugins
|
||||
[root]: glossary.md#kustomization-root
|
||||
[transformer configs]: ../examples/transformerconfigs
|
||||
[v1.0.9]: https://github.com/kubernetes-sigs/kustomize/releases/tag/v1.0.9
|
||||
@@ -26,6 +25,8 @@ Go modules, resource ordering respected, generator and transformer plugins, ease
|
||||
loading restrictions, the notion of inventory, eased replica count modification.
|
||||
About ~90 issues closed since [v2.0.3] in ~400 commits.
|
||||
|
||||
Download [here][v2.1.0].
|
||||
|
||||
## Go modules
|
||||
|
||||
![gopher with boxes][imgModules]
|
||||
@@ -123,7 +124,7 @@ For more information, see the
|
||||
The following usage:
|
||||
|
||||
```
|
||||
kustomize build --load_restrictions none $target
|
||||
kustomize build --load_restrictor none $target
|
||||
```
|
||||
|
||||
allows a `kustomization.yaml` file used in this
|
||||
242
docs/v2.1.0_changelog.md
Normal file
242
docs/v2.1.0_changelog.md
Normal file
@@ -0,0 +1,242 @@
|
||||
|
||||
e1b59c93 2.1 release notes
|
||||
2cf8371a Add --force flag to modify annotations and labels
|
||||
0fa2d9c3 Add --reorder flag.
|
||||
2d70526e Add ConfigMapGenerator and test.
|
||||
4df57686 Add SedTransformerTest
|
||||
68f6b0be Add Webhookconfiguration in default name references
|
||||
1545e07d Add a plugin loader test.
|
||||
449175e3 Add a sorting plugin.
|
||||
aafc23a6 Add annotation transformer.
|
||||
9bd456c6 Add bug report page.
|
||||
0df58838 Add builtin JSON patch transformer
|
||||
621bb7c6 Add builtin NameTransformer plugin.
|
||||
45901219 Add builtin label transformer.
|
||||
79906d73 Add builtin namespace transformer plugin
|
||||
d9b0c4c8 Add copy method to VarSet
|
||||
798b61c8 Add copy method to VarSet
|
||||
d9259397 Add documentation for the replicas transform
|
||||
2744e058 Add entry for inventory in fields.md
|
||||
3f2acc90 Add faq
|
||||
99391157 Add goplugin KV generator example.
|
||||
3b8c5ee9 Add load_restrictor flag.
|
||||
8f413f52 Add name reference of storageClass
|
||||
5e054c9d Add originalName field to resource.
|
||||
bb9b3163 Add script to run cloud build 'locally'.
|
||||
ffc16d51 Add secret generator.
|
||||
755dd3d0 Add some utilities.
|
||||
c9d903cc Add support for escaping characters in Doc
|
||||
2825888f Add test for builtin secretgenerator plugin.
|
||||
e6c1b141 Add test for transformers/image custom config
|
||||
644dc4b9 Add test showing shared patches disallowed.
|
||||
96707645 Add test showing shared patches disallowed.
|
||||
8d9897d5 Add the rmBuilder test helper.
|
||||
000f81b2 Added test to verify usage of multiline strip chomp in configMapGenerator
|
||||
5e7ddc86 Adds precommit for windows + documentation
|
||||
5e33ac4a Allow nil label and annotaion
|
||||
f38d0c69 Apply LimitRange resources before workloads
|
||||
b28aaae6 Break a bad dep.
|
||||
76d370a8 Chart last mile example
|
||||
f621543d Cleanup kusttarget.
|
||||
16fe7ced Cleanup plugin builds.
|
||||
d4842ebd Cleanup the replica plugin implementation.
|
||||
8991bcb3 Collect existing internal pkgs under one roof.
|
||||
d0cf0473 Convert image transformer test to a more readable format
|
||||
81c98c85 Convert inventory transformer to plugin, reduce k8sdeps.
|
||||
c9a5c03e Convert legacy file based test to in-memory
|
||||
2e71a3b8 Convert plugins to accept bytes instead of unstruct.
|
||||
52faa01e Cover #1155 with a test.
|
||||
fe67bcdb Cut more ties to k8sdeps
|
||||
e1389649 Cut more ties to k8sdeps
|
||||
175c754f Define a plugin compiler.
|
||||
9a850710 Delete kustomizationerror.
|
||||
6a106546 Delete the KV plugin code.
|
||||
9a4cb6c9 Delete unused code.
|
||||
cc531af6 Deprecate 'bases:' field.
|
||||
939de0cd Dogfood the plugin framework.
|
||||
267eec55 Fix 918
|
||||
3a44508d Fix error message
|
||||
0f571b91 Fix field names
|
||||
9a4692e6 Fix function comments based on best practices from Effective Go
|
||||
e207ae4c Fix incorrect default varrefs for CronJob volumeMounts
|
||||
3d0e2907 Fix markdownlint warnings
|
||||
31091a8d Fix missing varrefs for CronJob, Job, ReplicaSet
|
||||
cefb64b6 Fix path
|
||||
a9145702 Fix some comment nits.
|
||||
7295a9b3 Fix some nits.
|
||||
b92ee256 Fix some nits.
|
||||
57eecd74 Fix test broken by the change in ordering.
|
||||
e079c20c Fix typo
|
||||
559efd64 Fix typo in namereference path for cronjobs initContainers.
|
||||
a7a2589e Fix yaml in generator examples.
|
||||
9b6f8f0c Format generated code.
|
||||
2545ea10 Helm chart generator exec plugin
|
||||
02f37953 Idiom fixes.
|
||||
5000a2e5 Implement replica transformer as patch alternative
|
||||
9c36ac28 Improve comments in name transform code.
|
||||
58d9a510 Improve plugin doc.
|
||||
529db049 Introduce envs field.
|
||||
6d309b52 Introduce stacked transformers.
|
||||
abf538d8 Keep backward compatibility for image transformer
|
||||
7e12918f Keep var refernce in resources
|
||||
7130e3ff Leave defautconfig empty for images
|
||||
3e85c458 Load default config for image transformer
|
||||
4162dbc2 Maintain resources in order loaded.
|
||||
3a7c8a03 Make builtin the default pluginType
|
||||
bcc7412e Make kusttestharness shareable.
|
||||
cfb0c5ef Make plugin dir match Go conventions.
|
||||
8d4b6452 Make the replica transformer `kind` aware.
|
||||
3f8b1fe0 Make the replica transformer `kind` aware.
|
||||
c470982c Make transformer configs array-aware
|
||||
cd19d426 Merge remote-tracking branch 'upstream/master'
|
||||
0b555e1b Modify tests to present expected data in unsorted order.
|
||||
f17698a8 More release note tweaks.
|
||||
9a12b551 Move accumulator code to its own package.
|
||||
ee728d58 Move hashing code out of k8sdeps.
|
||||
fd2248e7 Move hashing transformer out of k8sdeps.
|
||||
d2c93065 Move kustomize main to cmd directory.
|
||||
4bc31f4b Move pluginator to cmd directory.
|
||||
5653ae69 One plugin per dir.
|
||||
a09b42b3 Order ValidatingWebhookConfig last.
|
||||
c63ebbdf Preserve order when merging.
|
||||
11bb176a Push suffix/prefix code to plugin.
|
||||
103c1b3a Put goplugins behind flag.
|
||||
2796e545 Put windows test script next to pre-commit.sh
|
||||
47c96548 Reduce k8ds deps
|
||||
4f429d6b Reduce time required for cloning remote bases
|
||||
b67d713b Remove dependency on ghodss/yaml
|
||||
78cdff6d Remove kv plugins from docs.
|
||||
3c58c9d1 Remove local load restrictions.
|
||||
8767495b Remove some duped code.
|
||||
b32e041b Remove some duped code.
|
||||
8c133ef0 Removes mdrip testing for Windows
|
||||
a2e4f6cf Rename ./bin dir to ./travis.
|
||||
0e4f9acb Rename ErrorIfNotEqual to ErrorIfNotEqualSets
|
||||
49d94f53 Rename the prefix/suffix transformer.
|
||||
c06b9507 Secret/configmap factory cleanup.
|
||||
3a01a63a Simplify code base.
|
||||
76a31798 Simplify plugin loader code.
|
||||
3a85fcd3 Simplify some of the plugin testing code.
|
||||
3011f180 Sort default varReference config by kind, path
|
||||
44ac9a9f Standalone ChartInflator plugin test.
|
||||
5614649d Standalone service generator test
|
||||
f311ba8d Support custom config for image transformer
|
||||
e191ff53 Switch to vgo
|
||||
a5660415 Tell homebrew to update.
|
||||
ed03818e This commit enhances the UnstructAdapter
|
||||
e0d2fa57 Translated kustomization.yaml into markdown in fields.md. Updated links to point to fields.md
|
||||
a352ff39 True and false are mysterious.
|
||||
7971ac1c Tweak secret docs.
|
||||
852e7ed5 Typo Fix
|
||||
1dd448e6 Update 2.1 release notes before release.
|
||||
0f50be87 Update ChartInflatorExec
|
||||
72fd31fd Update FAQ.md
|
||||
185ae510 Update README.md
|
||||
fa4dc14c Update all.go
|
||||
ae0510f6 Update chartinflatorexecplugin_test.go
|
||||
08b6f6f4 Update golinter to 1.17.1
|
||||
4502e8ff Update inventory_object.md
|
||||
ca478016 Update minecraft version in example.
|
||||
efcf8757 Update order of resources to include psps
|
||||
64bd0692 Update plugins.md
|
||||
0045d7b7 Update plugins.md
|
||||
54d1c557 Update plugins.md
|
||||
86534869 Update remoteBuild.md
|
||||
2ec8189c Update remoteBuild.md
|
||||
1afc6c77 Update strategic-merge link
|
||||
c1dea667 Update travis file.
|
||||
9edecffc Update v_2.1.0.md
|
||||
f2295acf Update v_2.1.0.md
|
||||
71f44d64 Update v_2.1.0.md
|
||||
bb69e9e7 Updates documentation for support and source
|
||||
2490e605 Updates in image transformer (#911)
|
||||
c6476d16 Upgrade version of minecraft used in tests.
|
||||
af2b101f Use go modules in cloud builder.
|
||||
5be42092 Vars should expand in ingress/spec/tls/secretName
|
||||
9203478a Write individual files to output path if it is a directory
|
||||
942e36e1 a few more changes
|
||||
5b18c4de add ItemId type
|
||||
6f4b104c add admission webhook types in the default cluster-scoped resource list
|
||||
9fc4d388 add builtin envfiles plugin
|
||||
a8465c95 add builtin files plugin
|
||||
388d5c2d add builtin plugins
|
||||
7fa02ce5 add document to explain inventory field (#997)
|
||||
142879ec add example for transformer plugin
|
||||
74937321 add generator plugins
|
||||
deaf0779 add generators/transformers fields in kusotmization.yaml
|
||||
ba43ecbc add goplugin for exec generators and transformers
|
||||
d5abe39d add inventory package and refactor inventory transformer
|
||||
f7cd44be add job initcontainer to varreference config
|
||||
53a22cbe add note for availability in kubectl
|
||||
2675bf4b add older release notes
|
||||
ca6228b5 add remove resource subcommand
|
||||
18f63282 add secret and configmap generator plugins
|
||||
f6e01cfd add support for exec plugins
|
||||
dd59eb38 add test case
|
||||
c724cb71 add test for empty patch file
|
||||
445f7392 add test for ensuirng the loader root is correctly passed
|
||||
a8c476f7 add the Chhinese translation of docs list & install (#1022)
|
||||
fb9e00bf add the unstructured to ENV of exec plugins
|
||||
4f1a2350 add transformer plugins
|
||||
237c54f4 add tutorial for custom images transformer
|
||||
b4dbac1b add validation transformer
|
||||
89243aed add zh dir
|
||||
b07bea40 added field tables
|
||||
3168b2a1 added link to examples
|
||||
7a54d998 added links to section headings
|
||||
e9a3f9f5 address comments
|
||||
86f0f9a4 address comments
|
||||
e5d730e1 address comments
|
||||
ad7ca697 address comments
|
||||
65886f12 address comments
|
||||
1d65f24b adds documentation for choco package
|
||||
e4159d94 allow to set image without a tag
|
||||
b4fc1e43 change field name: prune -> inventory
|
||||
404884e2 chinese helloworld doc
|
||||
7b82154c correct spelling, minor word ordering
|
||||
ca4aea17 doc/glossary updates for v2.1
|
||||
3ff5c793 docs add kubectl command
|
||||
c250f75d enable go module in the integration test (#1153)
|
||||
3e6ee23a fix README
|
||||
70def866 fix a link
|
||||
e6d1de0d fix commonLabels spec for volumeClaimTemplates
|
||||
4848987a fix configmap/secret name references for cronjobs with projected volumes
|
||||
fa552d77 fix help msg for set image cmd
|
||||
a64baed4 fix link
|
||||
1bd7afe6 fix linter
|
||||
822420e4 fix mergeFlags
|
||||
bcb697eb fix namespace transformer for cluster-scoped resources
|
||||
7765bdd9 fix some doc
|
||||
a889f97f fix some example ptrs
|
||||
56965a00 fix test
|
||||
927b497f fix tests
|
||||
61d46c26 fix the boilerplate copyright header (#1064)
|
||||
03751372 fix the bug for patching CRDs
|
||||
93908602 fix the bug for setting annotations when triggering transformers
|
||||
21a0cba4 fix the regression of building remote url (#935)
|
||||
7ab4d284 fix translation
|
||||
62d3200e fix typo in namereference where serviceaccount name would not resolve
|
||||
826affb8 generate configmap for pruning
|
||||
cd9572e0 hey
|
||||
5c471965 honor XDG_CONFIG_HOME
|
||||
2aa7e30a minimize test
|
||||
29cbec37 move parse helpers to util
|
||||
fc8063f7 pass loader root to exec plugins
|
||||
c1e2b27c pass resources to transformer plugin all together
|
||||
e287f615 readded kustomization.yaml
|
||||
f850ca63 remove extra comment
|
||||
e17d3033 reorganize the examples layout
|
||||
bfc3655b skip adding namespace when the object is empty
|
||||
440d0361 some transformer plugins
|
||||
61cf67fb start v2.1 release notes
|
||||
403ede78 tests: demonstrate issue with JSON patch when base adds name prefix
|
||||
b4efc833 translate example list
|
||||
16924d79 translate kustomization.yaml
|
||||
faaf6002 translate kustomization.yaml & update zh/README
|
||||
540e4023 typo in README
|
||||
748c88c2 update PruneString for resources
|
||||
b60fca05 update edit add secrets/configmaps to use plugins
|
||||
c836de5c update error msg
|
||||
e4956c55 update examples/README.md
|
||||
b2c87522 update validation transformer example text
|
||||
d2103dbf updated grouping and added brief descriptions of sections
|
||||
69
docs/v3.0.0.md
Normal file
69
docs/v3.0.0.md
Normal file
@@ -0,0 +1,69 @@
|
||||
# kustomize 3.0.0
|
||||
|
||||
This release is basically [v2.1.0](v2.1.0.md),
|
||||
with many post-v2.1.0 bugs fixed (in about 150
|
||||
commits) and a `v3` in Go package paths.
|
||||
|
||||
[plugin]: https://github.com/kubernetes-sigs/kustomize/tree/master/docs/plugins
|
||||
|
||||
The major version increment to `v3` puts a new
|
||||
floor on a stable API for [plugin] developers
|
||||
(both _Go_ plugin developers and _exec_ plugin
|
||||
developers who happen to use Go).
|
||||
|
||||
### Why so soon after v2.1.0?
|
||||
|
||||
[semantic versioning]: https://semver.org
|
||||
[Go modules doc]: https://github.com/golang/go/wiki/Modules#releasing-modules-v2-or-higher
|
||||
[versioning policy]: versioningPolicy.md
|
||||
|
||||
We made a mistake - v2.1.0 should have been
|
||||
v3.0.0. Per the [Go modules doc] (which have
|
||||
improved a great deal recently), a release that's
|
||||
already tagged v2 or higher should increment the
|
||||
major version when performing their first Go
|
||||
module-based release.
|
||||
|
||||
This advice applies to kustomize, since it was
|
||||
already at major version 2 when it began using Go
|
||||
modules to state _its own_ dependencies in v2.1.0.
|
||||
|
||||
But the more important reason for `v3` is a change
|
||||
to the kustomize [versioning policy], forced by
|
||||
the introduction of plugins.
|
||||
|
||||
Historically, kustomize's [versioning policy]
|
||||
didn't involve Go modules and addressed _only_ the
|
||||
command line tool's behavior and the fields in a
|
||||
kustomization file. The underlying packages were
|
||||
an implementation detail, not under semantic
|
||||
versioning, because they weren't intended for
|
||||
export (and should have all been under
|
||||
`internal`). Thus although the v2.1.0 CLI is
|
||||
backward compatible with v2.0.3, the underlying
|
||||
package APIs are not.
|
||||
|
||||
[minimal version selection]: https://research.swtch.com/vgo-mvs
|
||||
|
||||
With Go modules, the `go` tool must assume that Go
|
||||
packages respect [semantic versioning], so it can
|
||||
perform [minimal version selection].
|
||||
|
||||
With the introduction of alpha plugins, kustomize
|
||||
sub-packages - in particular `loader` and
|
||||
`resmap` - become part of an API formally exposed
|
||||
to plugin authors, and so must be semantically
|
||||
versioned. This allows plugins defined in other
|
||||
repositories to clarify that they depend on
|
||||
kustomize v3.0.0, and not see confusing errors
|
||||
arising from incompatibilities between v2.1.0 and
|
||||
v2.0.3. Hence, the jump to v3.
|
||||
|
||||
Aside - the set of kustomize packages outside
|
||||
`internal` is too large, and over time, informed
|
||||
by package use, this API surface must shrink.
|
||||
Such shrinkage will trigger a major version
|
||||
increment.
|
||||
|
||||
|
||||
|
||||
127
docs/v3.1.0.md
Normal file
127
docs/v3.1.0.md
Normal file
@@ -0,0 +1,127 @@
|
||||
# kustomize 3.1.0
|
||||
|
||||
|
||||
## Extended patches
|
||||
Since this version, Kustomize allows applying one patch to multiple resources. This works for both Strategic Merge Patch and JSON Patch. Take a look at [patch multiple objects](../examples/patchMultipleObjects.md).
|
||||
|
||||
## Improved Resource Matching
|
||||
|
||||
Multiple improvements have been made to allow the user to leverage "namespace"
|
||||
instead/or with "name suffix/prefix" to segregate resources.
|
||||
|
||||
### Patch resolution improvement
|
||||
|
||||
The following example demonstrates how using the namespace field in the patch definition,
|
||||
will let the user define two different patches against two different Deployment having the
|
||||
same "deploy1" name but in different namespaces in the same Kustomize context/folder.
|
||||
Unless the `namespace:` field has been specified in the kustomization.yaml, no namespace
|
||||
value will be handled as Kubernetes `default` namespace.
|
||||
|
||||
```yaml
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: deploy1
|
||||
namespace: main
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
env:
|
||||
- name: ANOTHERENV
|
||||
value: TESTVALUE
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: deploy1
|
||||
namespace: production
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: main
|
||||
env:
|
||||
- name: ANOTHERENV
|
||||
value: PRODVALUE
|
||||
```
|
||||
|
||||
|
||||
### Variable resolution improvement
|
||||
|
||||
It is possible to add namespace field to the variable declaration. In the following example,
|
||||
two `Service` objects with the same `elasticsearch` name have been declared.
|
||||
Specifying the namespace in the objRef of the corresponding varriables, allows Kustomize to
|
||||
resovlve thoses variables.
|
||||
If the namespace is not specified, Kustomize will handle it has a "wildcard" value.
|
||||
|
||||
Extract of kustomization.yaml:
|
||||
|
||||
```yaml
|
||||
vars:
|
||||
- name: elasticsearch-test-protocol
|
||||
objref:
|
||||
kind: Service
|
||||
name: elasticsearch
|
||||
namespace: test
|
||||
apiVersion: v1
|
||||
fieldref:
|
||||
fieldpath: spec.ports[0].protocol
|
||||
- name: elasticsearch-dev-protocol
|
||||
objref:
|
||||
kind: Service
|
||||
name: elasticsearch
|
||||
namespace: dev
|
||||
apiVersion: v1
|
||||
fieldref:
|
||||
fieldpath: spec.ports[0].protocol
|
||||
|
||||
```
|
||||
|
||||
### Simultaneous change of names and namespaces
|
||||
|
||||
Kustomize is now able to deal with simultaneous changes of name and namespace.
|
||||
Special attention has been paid the handling of:
|
||||
- ClusterRoleBinding/RoleBinding "subjects" field,
|
||||
- ValidatingWebhookConfiguration "webhooks" field.
|
||||
|
||||
The user should be able to use a kustomization.yaml as shown in the example bellow
|
||||
even if ClusterRoleBind,RoleBinding and ValidatingWebookConfiguration are part of the
|
||||
resources he needs to declare.
|
||||
|
||||
Extract of kustomization.yaml:
|
||||
|
||||
```yaml
|
||||
namePrefix: pfx-
|
||||
nameSuffix: -sfx
|
||||
namespace: testnamespace
|
||||
|
||||
resources:
|
||||
...
|
||||
```
|
||||
|
||||
### Resource and Kustomize Context matching.
|
||||
|
||||
Kustomize is now able to support more aggregation patterns.
|
||||
|
||||
If for instance, the top level of kustomization.yaml, is simply
|
||||
combining sub-components, (as in the following example), Kustomize has improved
|
||||
resource matching capabilities. This removes some of the constraints which were
|
||||
present on the utilization of prefix/suffix and namespace transformers in the
|
||||
individual components.
|
||||
|
||||
```yaml
|
||||
resources:
|
||||
- ../component1
|
||||
- ../component2
|
||||
- ../component3
|
||||
```
|
||||
|
||||
## Other improvements
|
||||
|
||||
- Image transformation has been improved. This allows the user to update the sha256 of
|
||||
an image with another sha256.
|
||||
- Multiple default transformer configuration entries have been added, removing the need for the
|
||||
user to add them as part of the `configurations:` section of the kustomization.yaml.
|
||||
- `kustomize` help command has been tidied up.
|
||||
@@ -1,13 +1,15 @@
|
||||
# Versioning
|
||||
|
||||
Running `kustomize` means one is running a
|
||||
particular version of a program, reading a
|
||||
particular version of a [kustomization] file.
|
||||
particular version of a program, using a
|
||||
particular version of underlying packages, and
|
||||
reading a particular version of a [kustomization]
|
||||
file.
|
||||
|
||||
## Program Versioning
|
||||
|
||||
The command `kustomize version` prints a three
|
||||
field version tag (e.g. `1.0.11`) that aspires to
|
||||
field version tag (e.g. `v3.0.0`) that aspires to
|
||||
[semantic versioning].
|
||||
|
||||
When enough changes have accumulated to
|
||||
@@ -15,6 +17,27 @@ warrant a new release, a [release process]
|
||||
is followed, and the fields in the version
|
||||
number are bumped per semver.
|
||||
|
||||
## Kustomize packages
|
||||
|
||||
At the time of writing, the kustomize program and
|
||||
the packages it uses (and exports) are in the same
|
||||
Go module (see the top level `go.mod` file in the
|
||||
repo).
|
||||
|
||||
[trailing major version indicator]: https://github.com/golang/go/wiki/Modules#releasing-modules-v2-or-higher
|
||||
|
||||
Thus, they share the module's version number, per
|
||||
its git tag (e.g. `v3.0.0`), whose major verion
|
||||
number matches the [trailing major version
|
||||
indicator] in the module name (e.g. the `/v3` in
|
||||
`sigs.k8s.io/kustomize/v3`).
|
||||
|
||||
The non-internal packages in the Go module
|
||||
`sigs.k8s.io/kustomize/v3`, introduced in
|
||||
[v3.0.0](v3.0.0.md), conform to [semantic
|
||||
versioning].
|
||||
|
||||
|
||||
## Kustomization File Versioning
|
||||
|
||||
At the time of writing (circa release of v2.0.0):
|
||||
@@ -209,11 +232,11 @@ moment forward.
|
||||
[beta-level rules]: https://github.com/kubernetes/community/blob/master/contributors/devel/api_changes.md#alpha-beta-and-stable-versions
|
||||
[changes]: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api_changes.md
|
||||
[adapt]: https://github.com/kubernetes-sigs/kustomize/blob/master/pkg/types/kustomization.go#L166
|
||||
[special]: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#resources
|
||||
[special]: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#resources
|
||||
[k8s API]: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md
|
||||
[conventions]: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md
|
||||
[release process]: ../build/README.md
|
||||
[release process]: ../releasing/README.md
|
||||
[kustomization]: glossary.md#kustomization
|
||||
[`kind`]: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#types-kinds
|
||||
[`kind`]: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#types-kinds
|
||||
[`apiVersion`]: https://kubernetes.io/docs/concepts/overview/kubernetes-api/#api-versioning
|
||||
[semantic versioning]: https://semver.org
|
||||
|
||||
@@ -35,5 +35,5 @@ chmod u+x kustomize
|
||||
|
||||
<!-- @installkustomize @test -->
|
||||
```
|
||||
go get sigs.k8s.io/kustomize
|
||||
go install sigs.k8s.io/kustomize/v3/cmd/kustomize
|
||||
```
|
||||
|
||||
@@ -8,10 +8,9 @@
|
||||
|
||||
* [术语表](../glossary.md) - 用于消除术语歧义。
|
||||
|
||||
* [kustomization.yaml](kustomization.yaml) - 包含
|
||||
[kustomization](../glossary.md#kustomization) 所有字段的示例文件。
|
||||
* [Kustomize 字段](fields.md) - 介绍 [kustomization](../glossary.md#kustomization) 文件中各字段的含义。
|
||||
|
||||
* [插件](../plugins.md) - 使用自定义的资源生成器和资源转换器来拓展 kustomize 功能。
|
||||
* [插件](../plugins) - 使用自定义的资源生成器和资源转换器来拓展 kustomize 功能。
|
||||
|
||||
* [工作流](workflows.md) - 使用定制及使用现成配置使用的一些步骤。
|
||||
|
||||
@@ -20,16 +19,21 @@
|
||||
|
||||
## 发行说明
|
||||
|
||||
* [2.1](../v_2.1.0.md) - 日期待定,预计2019年5月下旬。
|
||||
* [3.1](../v3.1.0.md) - 2019年7月下旬,扩展 patches 和改进的资源匹配。
|
||||
|
||||
* [2.0](../v_2.0.0.md) - 2019年3月
|
||||
* [3.0](../v3.0.0.md) - 2019年6月下旬,插件开发者发布。
|
||||
|
||||
* [2.1](../v2.1.0.md) - 2019年6月18日
|
||||
插件、有序资源等。
|
||||
|
||||
* [2.0](../v2.0.0.md) - 2019年3月
|
||||
可以在 [kubectl v1.14][kubectl] 中使用 kustomize [v2.0.3] 。
|
||||
|
||||
* [1.0](../v_1.0.1.md) - 2018年5月
|
||||
* [1.0](../v1.0.1.md) - 2018年5月
|
||||
于 [kubectl repository] 开发后的首发版本。
|
||||
|
||||
|
||||
## 政策
|
||||
## 行为守则
|
||||
|
||||
* [版本控制](../versioningPolicy.md) - kustomize 代码及 kustomization 文件的版本控制策略。
|
||||
|
||||
|
||||
436
docs/zh/fields.md
Normal file
436
docs/zh/fields.md
Normal file
@@ -0,0 +1,436 @@
|
||||
# Kustomization 文件字段
|
||||
|
||||
介绍 [kustomization](../glossary.md#kustomization) 文件中各字段的含义。
|
||||
|
||||
## Resources
|
||||
|
||||
现有可定制对象。
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| --- | --- | --- |
|
||||
|[resources](#resources) | list | 包含 k8s API 对象的文件,或其他包含 kustomizations 文件的目录。 |
|
||||
|[CRDs](#crds)| list | CDR 文件,以允许在资源列表中指定自定义资源。 |
|
||||
|
||||
## Generators
|
||||
|
||||
生成可定制的对象。
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| --- | --- | --- |
|
||||
|[configMapGenerator](#configmapgenerator)| list | 列表中的每个条目都将创建一个 ConfigMap (它是n个 ConfigMap 的生成器)。 |
|
||||
|[secretGenerator](#secretgenerator)| list | 此列表中的每个条目都将创建一个 Secret 资源(它是n个 secrets 的生成器)。 |
|
||||
|[generatorOptions](#generatoroptions)| string | generatorOptions 可以修改所有 ConfigMapGenerator 和 SecretGenerator 的行为。 |
|
||||
|[generators](#generators)| list | [插件](../plugins)配置文件。 |
|
||||
|
||||
## Transformers
|
||||
|
||||
可用的转换。
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| [commonLabels](#commonlabels) | string | 为所有资源和 selectors 增加 Labels 。 |
|
||||
| [commonAnnotations](#commonannotations) | string | 为所有资源增加 Annotations 。 |
|
||||
| [images](#images) | list | 修改镜像的名称、tag 或 image digest ,而无需使用 patches 。 |
|
||||
| [inventory](#inventory) | struct | 用于生成一个包含清单信息的对象。 |
|
||||
| [namespace](#namespace) | string | 为所有 resources 添加 namespace 。 |
|
||||
| [namePrefix](#nameprefix) | string | 该字段的值将添加在所有资源的名称之前。 |
|
||||
| [nameSuffix](#namesuffix) | string | 该字段的值将添加在所有资源的名称后面。 |
|
||||
| [replicas](#replicas) | list | 修改资源的副本数。 |
|
||||
| [patchesStrategicMerge](#patchesstrategicmerge) | list | 此列表中的每个条目都应可以解析为部分或完整的资源定义文件。 |
|
||||
| [patchesJson6902](#patchesjson6902) | list | 列表中的每个条目都应可以解析为 kubernetes 对象和将应用于该对象的 JSON patch 。 |
|
||||
| [transformers](#transformers) | list | [插件](../plugins)配置文件。 |
|
||||
|
||||
## Meta
|
||||
|
||||
[k8s metadata]: https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/#required-fields
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| [vars](#vars) | string | 获取一个对象中的字段并插入到另外的对象中。 |
|
||||
| [apiVersion](#apiversion) | string | [k8s metadata] 字段。 |
|
||||
| [kind](#kind) | string | [k8s metadata] 字段。 |
|
||||
|
||||
----
|
||||
|
||||
### apiVersion
|
||||
|
||||
该字段默认值为:
|
||||
```
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
```
|
||||
|
||||
### bases
|
||||
|
||||
`bases` 字段在 v2.1.0 中已被弃用。
|
||||
|
||||
该条目已被移动到 [resources](#resources) 字段中。
|
||||
|
||||
### commonLabels
|
||||
|
||||
为所有资源和 selectors 增加 Labels
|
||||
|
||||
```
|
||||
commonLabels:
|
||||
someName: someValue
|
||||
owner: alice
|
||||
app: bingo
|
||||
```
|
||||
|
||||
### commonAnnotations
|
||||
|
||||
为所有资源增加 Annotations ,和 labels 一样是 key:value 的键值对。
|
||||
|
||||
```
|
||||
commonAnnotations:
|
||||
oncallPager: 800-555-1212
|
||||
```
|
||||
|
||||
### configMapGenerator
|
||||
|
||||
列表中的每个条目都将创建一个 ConfigMap (它是n个 ConfigMap 的生成器)。
|
||||
|
||||
下面的示例创建了两个 ConfigMaps:
|
||||
|
||||
- 一个具有给定文件的名称和内容
|
||||
- 另一个包含 key/value 键值对数据
|
||||
|
||||
每个 configMapGenerator 项都可以使用 `behavior: [create|replace|merge]` 参数。
|
||||
|
||||
允许 overlay 从父级修改或替换现有的 configMap。
|
||||
|
||||
```
|
||||
configMapGenerator:
|
||||
- name: myJavaServerProps
|
||||
files:
|
||||
- application.properties
|
||||
- more.properties
|
||||
- name: myJavaServerEnvVars
|
||||
literals:
|
||||
- JAVA_HOME=/opt/java/jdk
|
||||
- JAVA_TOOL_OPTIONS=-agentlib:hprof
|
||||
```
|
||||
|
||||
### crds
|
||||
|
||||
此列表中的每个条目都应该是自定义资源定义(CRD)文件的相对路径。
|
||||
|
||||
该字段的存在是为了让 kustomize 知道用户自定义的 CRD ,并对这些类型中的对象应用适当的转换。
|
||||
|
||||
典型用例:CRD 引用 ConfigMap 对象
|
||||
|
||||
在 kustomization 中,ConfigMap 对象名称可能会通过 namePrefix 、nameSuffix 或 hashing 来更改 CRD 对象中此 ConfigMap 对象的名称,
|
||||
引用时需要以相同的方式使用 namePrefix 、 nameSuffix 或 hashing 来进行更新。
|
||||
|
||||
Annotations 可以放入 openAPI 的定义中:
|
||||
|
||||
- "x-kubernetes-annotation": ""
|
||||
- "x-kubernetes-label-selector": ""
|
||||
- "x-kubernetes-identity": ""
|
||||
- "x-kubernetes-object-ref-api-version": "v1",
|
||||
- "x-kubernetes-object-ref-kind": "Secret",
|
||||
- "x-kubernetes-object-ref-name-key": "name",
|
||||
|
||||
```
|
||||
|
||||
crds:
|
||||
- crds/typeA.yaml
|
||||
- crds/typeB.yaml
|
||||
```
|
||||
|
||||
|
||||
### generatorOptions
|
||||
|
||||
generatorOptions 修改所有 [ConfigMapGenerator](#configmapgenerator) 和 [SecretGenerator](#secretgenerator) 的行为。
|
||||
|
||||
```
|
||||
generatorOptions:
|
||||
# 为所有生成的资源添加 labels
|
||||
labels:
|
||||
kustomize.generated.resources: somevalue
|
||||
# 为所有生成的资源添加 annotations
|
||||
annotations:
|
||||
kustomize.generated.resource: somevalue
|
||||
# disableNameSuffixHash 为 true 时将禁止默认的在名称后添加哈希值后缀的行为
|
||||
disableNameSuffixHash: true
|
||||
```
|
||||
|
||||
### generators
|
||||
|
||||
[插件](../plugins)生成器配置文件列表。
|
||||
|
||||
```
|
||||
generators:
|
||||
- mySecretGeneratorPlugin.yaml
|
||||
- myAppGeneratorPlugin.yaml
|
||||
```
|
||||
|
||||
### images
|
||||
|
||||
修改镜像的名称、tag 或 image digest ,而无需使用 patches 。例如,对于这种 kubernetes Deployment 片段:
|
||||
|
||||
```
|
||||
containers:
|
||||
- name: mypostgresdb
|
||||
image: postgres:8
|
||||
- name: nginxapp
|
||||
image: nginx:1.7.9
|
||||
- name: myapp
|
||||
image: my-demo-app:latest
|
||||
- name: alpine-app
|
||||
image: alpine:3.7
|
||||
```
|
||||
|
||||
可以通过以下方式更改 `image` :
|
||||
|
||||
- `postgres:8` to `my-registry/my-postgres:v1`,
|
||||
- nginx tag `1.7.9` to `1.8.0`,
|
||||
- image name `my-demo-app` to `my-app`,
|
||||
- alpine's tag `3.7` to a digest value
|
||||
|
||||
可以在 *kustomization* 中添加以下内容:
|
||||
|
||||
```
|
||||
images:
|
||||
- name: postgres
|
||||
newName: my-registry/my-postgres
|
||||
newTag: v1
|
||||
- name: nginx
|
||||
newTag: 1.8.0
|
||||
- name: my-demo-app
|
||||
newName: my-app
|
||||
- name: alpine
|
||||
digest: sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3
|
||||
```
|
||||
|
||||
### inventory
|
||||
|
||||
详见 [inventory object](inventory_object.md)。
|
||||
|
||||
### kind
|
||||
|
||||
该字段默认值为:
|
||||
|
||||
```
|
||||
kind: Kustomization
|
||||
```
|
||||
|
||||
|
||||
### namespace
|
||||
|
||||
为所有 resources 添加 namespace 。
|
||||
|
||||
```
|
||||
namespace: my-namespace
|
||||
```
|
||||
|
||||
### namePrefix
|
||||
|
||||
该字段的值将添加在所有资源的名称之前,例如 将资源名称 `wordpress` 变为 `alices-wordpress` 。
|
||||
|
||||
```
|
||||
namePrefix: alices-
|
||||
```
|
||||
|
||||
### nameSuffix
|
||||
|
||||
该字段的值将添加在所有资源的名称后面,例如 将资源名称 `wordpress` 变为 `wordpress-v2` 。
|
||||
|
||||
如果资源类型为 ConfigMap 或 Secret ,则在哈希值之前附加后缀。
|
||||
|
||||
```
|
||||
nameSuffix: -v2
|
||||
```
|
||||
|
||||
### patchesStrategicMerge
|
||||
|
||||
此列表中的每个条目都应可以解析为部分或完整的资源定义文件。
|
||||
|
||||
这些(也可能是部分的)资源文件中的 name 必须与已经通过 `resources` 加载的 name 字段匹配,或者通过 `bases` 中的 name 字段匹配。这些条目将用于 _patch_(修改)已知资源。
|
||||
|
||||
推荐使用小的 patches,例如:修改内存的 request/limit,更改 ConfigMap 中的 env 变量等小的 patches 易于维护和查看,并且易于在 overlays 中混合使用。
|
||||
|
||||
```
|
||||
patchesStrategicMerge:
|
||||
- service_port_8888.yaml
|
||||
- deployment_increase_replicas.yaml
|
||||
- deployment_increase_memory.yaml
|
||||
```
|
||||
|
||||
### patchesJson6902
|
||||
|
||||
patchesJson6902 列表中的每个条目都应可以解析为 kubernetes 对象和将应用于该对象的 JSON patch
|
||||
|
||||
JSON patch 的文档地址:https://tools.ietf.org/html/rfc6902
|
||||
|
||||
目标字段指向的 kubernetes 对象的 group、 version、 kind、 name 和 namespace 在同一 kustomization 内 path 字段内容是 JSON patch 文件的相对路径。
|
||||
|
||||
patch 文件中的内容可以如下这种 JSON 格式:
|
||||
|
||||
```
|
||||
[
|
||||
{"op": "add", "path": "/some/new/path", "value": "value"},
|
||||
{"op": "replace", "path": "/some/existing/path", "value": "new value"}
|
||||
]
|
||||
```
|
||||
|
||||
也可以使用 YAML 格式表示:
|
||||
|
||||
```
|
||||
- op: add
|
||||
path: /some/new/path
|
||||
value: value
|
||||
- op: replace
|
||||
path: /some/existing/path
|
||||
value: new value
|
||||
```
|
||||
|
||||
```
|
||||
patchesJson6902:
|
||||
- target:
|
||||
version: v1
|
||||
kind: Deployment
|
||||
name: my-deployment
|
||||
path: add_init_container.yaml
|
||||
- target:
|
||||
version: v1
|
||||
kind: Service
|
||||
name: my-service
|
||||
path: add_service_annotation.yaml
|
||||
```
|
||||
|
||||
### replicas
|
||||
|
||||
修改资源的副本数。
|
||||
|
||||
例如:对于如下 kubernetes Deployment 片段:
|
||||
|
||||
```
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: deployment-name
|
||||
spec:
|
||||
replicas: 3
|
||||
```
|
||||
|
||||
在 kustomization 中添加以下内容,将副本数更改为5:
|
||||
|
||||
```
|
||||
replicas:
|
||||
- name: deployment-name
|
||||
count: 5
|
||||
```
|
||||
|
||||
该字段内容为列表,所以可以同时修改许多资源。
|
||||
|
||||
#### Limitation
|
||||
|
||||
由于这个声明无法设置 `kind:` 或 `group:` 它将匹配任何可以匹配名称的 `group` 和 `kind` ,并且它是以下之一:
|
||||
- `Deployment`
|
||||
- `ReplicationController`
|
||||
- `ReplicaSet`
|
||||
- `StatefulSet`
|
||||
|
||||
对于更复杂的用例,请使用 patch 。
|
||||
|
||||
### resources
|
||||
|
||||
该条目可以是指向本地目录的相对路径,也可以是指向远程仓库中的目录的 URL,例如:
|
||||
|
||||
```
|
||||
resource:
|
||||
- myNamespace.yaml
|
||||
- sub-dir/some-deployment.yaml
|
||||
- ../../commonbase
|
||||
- github.com/kubernetes-sigs/kustomize//examples/multibases?ref=v1.0.6
|
||||
- deployment.yaml
|
||||
- github.com/kubernets-sigs/kustomize//examples/helloWorld?ref=test-branch
|
||||
```
|
||||
|
||||
将以深度优先的顺序读取和处理资源。
|
||||
|
||||
|
||||
文件应包含 YAML 格式的 k8s 资源。一个资源描述文件可以含有多个由(“---”)分隔的资源。
|
||||
应该包含 `resources` 字段的 kustomization 文件的指定文件目录的相对路径。
|
||||
|
||||
[hashicorp URL]: https://github.com/hashicorp/go-getter#url-format
|
||||
|
||||
目录规范可以是相对、绝对或部分的 URL。URL 规范应遵循 [hashicorp URL] 格式。该目录必须包含 `kustomization.yaml` 文件。
|
||||
|
||||
### secretGenerator
|
||||
|
||||
此列表中的每个条目都将创建一个 Secret 资源(它是n个 secrets 的生成器)。
|
||||
|
||||
```
|
||||
secretGenerator:
|
||||
- name: app-tls
|
||||
files:
|
||||
- secret/tls.cert
|
||||
- secret/tls.key
|
||||
type: "kubernetes.io/tls"
|
||||
- name: app-tls-namespaced
|
||||
# you can define a namespace to generate secret in, defaults to: "default"
|
||||
namespace: apps
|
||||
files:
|
||||
- tls.crt=catsecret/tls.cert
|
||||
- tls.key=secret/tls.key
|
||||
type: "kubernetes.io/tls"
|
||||
- name: env_file_secret
|
||||
envs:
|
||||
- env.txt
|
||||
type: Opaque
|
||||
```
|
||||
|
||||
### vars
|
||||
|
||||
Vars 用于从一个 resource 字段中获取文本,并将该文本插入指定位置 - 反射功能。
|
||||
|
||||
例如,假设需要在容器的 command 中指定了 Service 对象的名称,并在容器的 env 中指定了 Secret 对象的名称来确保以下内容可以正常工作:
|
||||
|
||||
```
|
||||
containers:
|
||||
- image: myimage
|
||||
command: ["start", "--host", "$(MY_SERVICE_NAME)"]
|
||||
env:
|
||||
- name: SECRET_TOKEN
|
||||
value: $(SOME_SECRET_NAME)
|
||||
```
|
||||
|
||||
则可以在 `vars:` 中添加如下内容:
|
||||
|
||||
```
|
||||
vars:
|
||||
- name: SOME_SECRET_NAME
|
||||
objref:
|
||||
kind: Secret
|
||||
name: my-secret
|
||||
apiVersion: v1
|
||||
- name: MY_SERVICE_NAME
|
||||
objref:
|
||||
kind: Service
|
||||
name: my-service
|
||||
apiVersion: v1
|
||||
fieldref:
|
||||
fieldpath: metadata.name
|
||||
- name: ANOTHER_DEPLOYMENTS_POD_RESTART_POLICY
|
||||
objref:
|
||||
kind: Deployment
|
||||
name: my-deployment
|
||||
apiVersion: apps/v1
|
||||
fieldref:
|
||||
fieldpath: spec.template.spec.restartPolicy
|
||||
```
|
||||
var 是包含该对象的变量名、对象引用和字段引用的元组。
|
||||
|
||||
字段引用是可选的,默认为 `metadata.name`,这是正常的默认值,因为 kustomize 用于生成或修改 resources 的名称。
|
||||
|
||||
在撰写本文档时,仅支持字符串类型字段,不支持 ints,bools,arrays 等。例如,在某些pod模板的容器编号2中提取镜像的名称是不可能的。
|
||||
|
||||
变量引用,即字符串 '$(FOO)' ,只能放在 kustomize 配置指定的特定对象的特定字段中。
|
||||
|
||||
关于 vars 的默认配置数据可以查看:
|
||||
https://github.com/kubernetes-sigs/kustomize/blob/master/pkg/transformers/config/defaultconfig/varreference.go
|
||||
|
||||
默认目标是所有容器 command args 和 env 字段。
|
||||
|
||||
Vars _不应该_ 被用于 kustomize 已经处理过的配置中插入 names 。
|
||||
例如, Deployment 可以通过 name 引用 ConfigMap ,如果 kustomize 更改 ConfigMap 的名称,则知道更改 Deployment 中的引用的 name 。
|
||||
@@ -1,287 +0,0 @@
|
||||
# Copyright 2018 The Kubernetes Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# ----------------------------------------------------
|
||||
# Example kustomization.yaml content.
|
||||
#
|
||||
# This file declares the customization provided by
|
||||
# the kustomize program.
|
||||
#
|
||||
# Since customization is, by definition, _custom_,
|
||||
# there are no sensible default values for the fields
|
||||
# in this file.
|
||||
#
|
||||
# The field values used below are merely examples, not
|
||||
# to be copied literally. The values won't work if
|
||||
# they happen to be references to external files that
|
||||
# don't exist.
|
||||
#
|
||||
# In practice, fields with no value should simply be
|
||||
# omitted from kustomization.yaml to reduce the content
|
||||
# visible in configuration reviews.
|
||||
# ----------------------------------------------------
|
||||
# Kustomization 的 apiVersion 和 kind
|
||||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
|
||||
# 为所有 resources 添加 namespace
|
||||
namespace: my-namespace
|
||||
|
||||
# 该字段的值将添加在所有资源的名称之前
|
||||
# 例如 将资源名称 “wordpress” 变为 “alices-wordpress”
|
||||
namePrefix: alices-
|
||||
|
||||
# 该字段的值将添加在所有资源的名称后面
|
||||
# 例如 将资源名称 “wordpress” 变为 “wordpress-v2”
|
||||
# 如果资源类型为 ConfigMap 或 Secret ,则在哈希值之前附加后缀
|
||||
nameSuffix: -v2
|
||||
|
||||
# 为所有资源和 selectors 增加 Labels
|
||||
commonLabels:
|
||||
someName: someValue
|
||||
owner: alice
|
||||
app: bingo
|
||||
|
||||
# 和 Labels 一样, 增加 Annotations
|
||||
# 为 key:value 键值对
|
||||
commonAnnotations:
|
||||
oncallPager: 800-555-1212
|
||||
|
||||
# 此列表中的每条记录都必须是一个存在的 YAML 资源描述文件
|
||||
# 一个 YAML 资源描述文件可以含有多个由(“---”)分隔的资源。
|
||||
# kustomize 将读取这些YAML文件中的资源,对其进行修改并
|
||||
# 发布在 kustomize 的输出中。
|
||||
#
|
||||
# 此列表中的每个条目都应解析为包含 kustomization 文件的目录,否则定制将失败
|
||||
#
|
||||
# 该条目可以是指向本地目录的相对路径
|
||||
# 也可以是指向远程仓库中的目录的 URL
|
||||
# URL 应该遵循 hashicorp/go-getter 中的 URL 格式
|
||||
# https://github.com/hashicorp/go-getter#url-format
|
||||
#
|
||||
# 此字段的存在意味着此文件(您正在阅读的文件)是 _overlay_
|
||||
# 它将进一步定制这些来自 _bases_ 文件中的配置
|
||||
#
|
||||
# 典型用例:开发,演示和生产环境
|
||||
# 这些环境大部分相同但有些关键方式存在差异(镜像标签,一些服务器参数等,与公共 base 不同的配置)
|
||||
resources:
|
||||
- some-service.yaml
|
||||
- sub-dir/some-deployment.yaml
|
||||
- ../../base
|
||||
- github.com/kubernetes-sigs/kustomize/examples/multibases?ref=v1.0.6
|
||||
- github.com/Liujingfang1/mysql
|
||||
- github.com/Liujingfang1/kustomize/examples/helloWorld?ref=test-branch
|
||||
|
||||
# 列表中的每个条目都将创建一个 ConfigMap (它是n个 ConfigMap 的生成器)
|
||||
# 下面的示例创建了两个 ConfigMaps
|
||||
# 一个具有给定文件的名称和内容
|
||||
# 另一个包含 key/value 键值对数据
|
||||
# 每个 configMapGenerator 项都可以使用 [create | replace | merge] 参数
|
||||
# 允许 overlay 从父级修改或替换现有的 configMap
|
||||
configMapGenerator:
|
||||
- name: myJavaServerProps
|
||||
files:
|
||||
- application.properties
|
||||
- more.properties
|
||||
- name: myJavaServerEnvVars
|
||||
literals:
|
||||
- JAVA_HOME=/opt/java/jdk
|
||||
- JAVA_TOOL_OPTIONS=-agentlib:hprof
|
||||
|
||||
# 此列表中的每个条目都会导致创建一个Secret资源(n个 secrets 的生成器)
|
||||
secretGenerator:
|
||||
- name: app-tls
|
||||
files:
|
||||
- secret/tls.cert
|
||||
- secret/tls.key
|
||||
type: "kubernetes.io/tls"
|
||||
- name: app-tls-namespaced
|
||||
# 你可以给生成的 secret 定义一个 namespace ,默认为 ”default“
|
||||
namespace: apps
|
||||
files:
|
||||
- tls.crt=catsecret/tls.cert
|
||||
- tls.key=secret/tls.key
|
||||
type: "kubernetes.io/tls"
|
||||
- name: env_file_secret
|
||||
# 文件路径以 k=v 键值对的形式,每行一个键值对
|
||||
envs:
|
||||
- env.txt
|
||||
type: Opaque
|
||||
|
||||
# generatorOptions 修改所有 ConfigMapGenerator 和 SecretGenerator 的行为
|
||||
generatorOptions:
|
||||
# 为所有生成的资源添加 labels
|
||||
labels:
|
||||
kustomize.generated.resources: somevalue
|
||||
# 为所有生成的资源添加 annotations
|
||||
annotations:
|
||||
kustomize.generated.resource: somevalue
|
||||
# disableNameSuffixHash 为 true 时将禁止默认的在名称后添加哈希值后缀的行为
|
||||
disableNameSuffixHash: true
|
||||
|
||||
# 此列表中的每个条目都应可以解析为部分或完整的资源定义文件
|
||||
#
|
||||
# 这些(也可能是部分的)资源文件中的 name 必须与已经通过 `resources` 加载的 name 字段匹配
|
||||
# 或者通过 `bases` 中的 name 字段匹配
|
||||
# 这些条目将用于 _patch_(修改)已知资源
|
||||
#
|
||||
# 推荐使用小的 patches
|
||||
# 例如:修改内存的 request/limit,更改 ConfigMap 中的 env 变量等
|
||||
# 小的 patches 易于维护和查看,并且易于在 overlays 中混合使用
|
||||
patchesStrategicMerge:
|
||||
- service_port_8888.yaml
|
||||
- deployment_increase_replicas.yaml
|
||||
- deployment_increase_memory.yaml
|
||||
|
||||
# patchesJson6902 列表中的每个条目都应可以解析为 kubernetes 对象和将应用于该对象的 JSON patch
|
||||
# JSON patch 的文档地址:https://tools.ietf.org/html/rfc6902
|
||||
#
|
||||
# 目标字段指向的 kubernetes 对象的 group、 version、 kind、 name 和 namespace 在同一 kustomization 内
|
||||
# path 字段内容是 JSON patch 文件的相对路径
|
||||
# patch 文件中的内容可以如下这种 JSON 格式:
|
||||
#
|
||||
# [
|
||||
# {"op": "add", "path": "/some/new/path", "value": "value"},
|
||||
# {"op": "replace", "path": "/some/existing/path", "value": "new value"}
|
||||
# ]
|
||||
#
|
||||
# 也可以使用 YAML 格式表示:
|
||||
#
|
||||
# - op: add
|
||||
# path: /some/new/path
|
||||
# value: value
|
||||
# - op:replace
|
||||
# path: /some/existing/path
|
||||
# value: new value
|
||||
#
|
||||
patchesJson6902:
|
||||
- target:
|
||||
version: v1
|
||||
kind: Deployment
|
||||
name: my-deployment
|
||||
path: add_init_container.yaml
|
||||
- target:
|
||||
version: v1
|
||||
kind: Service
|
||||
name: my-service
|
||||
path: add_service_annotation.yaml
|
||||
|
||||
# 此列表中的每个条目都应该是 openAPI 定义中自定义资源定义(CRD)文件的相对路径
|
||||
#
|
||||
# 该字段的存在是为了让 kustomize 知道用户自定义的 CRD
|
||||
# 并对这些类型中的对象应用适当的转换
|
||||
#
|
||||
# 典型用例:CRD 引用 ConfigMap 对象
|
||||
# 在 kustomization 中,ConfigMap 对象名称可能会通过 namePrefix 、nameSuffix 或 hashing 来更改 CRD 对象中此 ConfigMap 对象的名称
|
||||
# 引用时需要以相同的方式使用 namePrefix 、 nameSuffix 或 hashing 来进行更新
|
||||
#
|
||||
# Annotations 可以放入 openAPI 的定义中:
|
||||
# "x-kubernetes-annotation": ""
|
||||
# "x-kubernetes-label-selector": ""
|
||||
# "x-kubernetes-identity": ""
|
||||
# "x-kubernetes-object-ref-api-version": "v1",
|
||||
# "x-kubernetes-object-ref-kind": "Secret",
|
||||
# "x-kubernetes-object-ref-name-key": "name",
|
||||
crds:
|
||||
- crds/typeA.json
|
||||
- crds/typeB.json
|
||||
|
||||
# Vars 用于从一个 resource 字段中获取文本
|
||||
# 并将该文本插入指定位置
|
||||
#
|
||||
# 例如,假设需要在容器的 command 中指定了 Service 对象的名称
|
||||
# 并在容器的 env 中指定了 Secret 对象的名称
|
||||
# 来确保以下内容可以正常工作:
|
||||
# ```
|
||||
# containers:
|
||||
# - image: myimage
|
||||
# command: ["start", "--host", "$(MY_SERVICE_NAME)"]
|
||||
# env:
|
||||
# - name: SECRET_TOKEN
|
||||
# value: $(SOME_SECRET_NAME)
|
||||
# ```
|
||||
#
|
||||
# 则可以在 `vars:` 中添加如下内容:
|
||||
#
|
||||
vars:
|
||||
- name: SOME_SECRET_NAME
|
||||
objref:
|
||||
kind: Secret
|
||||
name: my-secret
|
||||
apiVersion: v1
|
||||
- name: MY_SERVICE_NAME
|
||||
objref:
|
||||
kind: Service
|
||||
name: my-service
|
||||
apiVersion: v1
|
||||
fieldref:
|
||||
fieldpath: metadata.name
|
||||
- name: ANOTHER_DEPLOYMENTS_POD_RESTART_POLICY
|
||||
objref:
|
||||
kind: Deployment
|
||||
name: my-deployment
|
||||
apiVersion: apps/v1
|
||||
fieldref:
|
||||
fieldpath: spec.template.spec.restartPolicy
|
||||
#
|
||||
# var 是包含该对象的变量名、对象引用和字段引用的元组
|
||||
#
|
||||
# 字段引用是可选的,默认为 `metadata.name`
|
||||
# 这是正常的默认值,因为 kustomize 用于生成或修改 resources 的名称
|
||||
#
|
||||
# 在撰写本文档时,仅支持字符串类型字段
|
||||
# 不支持 ints,bools,arrays 等
|
||||
#
|
||||
# 变量引用,即字符串 '$(FOO)' ,只能放在 kustomize 配置指定的特定对象的特定字段中
|
||||
#
|
||||
# 关于 vars 的默认配置数据可以查看:
|
||||
# https://github.com/kubernetes-sigs/kustomize/blob/master/pkg/transformers/config/defaultconfig/varreference.go
|
||||
# 默认目标是所有容器 command args 和 env 字段
|
||||
#
|
||||
# Vars _不应该_ 被用于 kustomize 已经处理过的配置中插入 names
|
||||
# 例如, Deployment 可以通过 name 引用 ConfigMap
|
||||
# 如果 kustomize 更改 ConfigMap 的名称,则知道更改 Deployment 中的引用的 name
|
||||
|
||||
# 修改镜像的名称、tag 或 image digest ,而无需使用 patches
|
||||
# 例如,对于这种 kubernetes Deployment 片段:
|
||||
# ```
|
||||
# containers:
|
||||
# - name: mypostgresdb
|
||||
# image: postgres:8
|
||||
# - name: nginxapp
|
||||
# image: nginx:1.7.9
|
||||
# - name: myapp
|
||||
# image: my-demo-app:latest
|
||||
# - name: alpine-app
|
||||
# image: alpine:3.7
|
||||
#```
|
||||
# 想对 `image` 完成以下修改:
|
||||
#
|
||||
# - 将 `postgres:8` 修改为 `my-registry/my-postgres:v1`,
|
||||
# - 将 nginx 的 tag 从 `1.7.9` 修改为 `1.8.0`,
|
||||
# - 将 镜像名称从 `my-demo-app` 修改为 `my-app`,
|
||||
# - 将 alpine 的 tag 从 `3.7` 修改为 digest 值
|
||||
#
|
||||
# 可以在 *kustomization* 中添加以下内容:
|
||||
|
||||
images:
|
||||
- name: postgres
|
||||
newName: my-registry/my-postgres
|
||||
newTag: v1
|
||||
- name: nginx
|
||||
newTag: 1.8.0
|
||||
- name: my-demo-app
|
||||
newName: my-app
|
||||
- name: alpine
|
||||
digest: sha256:24a0c4b4a4c0eb97a1aabb8e29f18e917d05abfe1b7a7c07857230879ce7d3d3
|
||||
@@ -9,7 +9,7 @@ tests, and should work with HEAD
|
||||
|
||||
<!-- @installkustomize @test -->
|
||||
```
|
||||
go get sigs.k8s.io/kustomize/cmd/kustomize
|
||||
go get sigs.k8s.io/kustomize/v3/cmd/kustomize
|
||||
```
|
||||
|
||||
Basic Usage
|
||||
@@ -33,6 +33,8 @@ Basic Usage
|
||||
|
||||
* [json patch](jsonpatch.md) - Apply a json patch in a kustomization
|
||||
|
||||
* [patch multiple objects](patchMultipleObjects.md) - Apply a patch to multiple objects
|
||||
|
||||
Advanced Usage
|
||||
|
||||
- generator plugins:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
[stable chart]: https://github.com/helm/charts/tree/master/stable
|
||||
[Helm charts]: https://github.com/helm/charts
|
||||
[_minecraft_]: https://github.com/helm/charts/tree/master/stable/minecraft
|
||||
[plugin]: ../docs/plugins.md
|
||||
[plugin]: ../docs/plugins
|
||||
|
||||
[Helm charts] aren't natively read by kustomize, but
|
||||
kustomize has a [plugin] system that allows one to
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
# before running it.
|
||||
#
|
||||
# At time of writing, its 'call point' was in
|
||||
# https://github.com/kubernetes/test-infra/blob/master/jobs/config.json
|
||||
# https://github.com/kubernetes/test-infra/blob/master/config/jobs/kubernetes-sigs/kustomize/kustomize-config.yaml
|
||||
|
||||
function exitWith {
|
||||
local msg=$1
|
||||
@@ -53,7 +53,7 @@ function setUpEnv {
|
||||
exitWith "Script must be run from $expectedRepo"
|
||||
fi
|
||||
|
||||
GO111MODULE=on go install . || \
|
||||
GO111MODULE=on go install ./cmd/kustomize || \
|
||||
{ exitWith "Failed to install kustomize."; }
|
||||
|
||||
PATH=$GOPATH/bin:$PATH
|
||||
|
||||
188
examples/patchMultipleObjects.md
Normal file
188
examples/patchMultipleObjects.md
Normal file
@@ -0,0 +1,188 @@
|
||||
[Strategic Merge Patch]: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-api-machinery/strategic-merge-patch.md
|
||||
[JSON patches]: https://tools.ietf.org/html/rfc6902
|
||||
[label selector]: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors
|
||||
|
||||
|
||||
# Demo: applying a patch to multiple resources
|
||||
|
||||
A kustomization file supports customizing resources via both
|
||||
[Strategic Merge Patch] and [JSON patches]. Now one patch can be
|
||||
applied to multiple resources.
|
||||
|
||||
This can be done by specifying a patch and a target selector as follows:
|
||||
```
|
||||
patches:
|
||||
- path: <PatchFile>
|
||||
target:
|
||||
group: <Group>
|
||||
version: <Version>
|
||||
kind: <Kind>
|
||||
name: <Name>
|
||||
namespace: <Namespace>
|
||||
labelSelector: <LabelSelector>
|
||||
annotationSelector: <AnnotationSelector>
|
||||
```
|
||||
Both `labelSelector` and `annotationSelector` should follow the convention in [label selector].
|
||||
Kustomize selects the targets which match all the fields in `target` to apply the patch.
|
||||
|
||||
The example below shows how to inject a sidecar container for all deployment resources.
|
||||
|
||||
Make a `kustomization` containing a Deployment resource.
|
||||
|
||||
<!-- @createDeployment @test -->
|
||||
```
|
||||
DEMO_HOME=$(mktemp -d)
|
||||
|
||||
cat <<EOF >$DEMO_HOME/kustomization.yaml
|
||||
resources:
|
||||
- deployments.yaml
|
||||
EOF
|
||||
|
||||
cat <<EOF >$DEMO_HOME/deployments.yaml
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: deploy1
|
||||
spec:
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
old-label: old-value
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx
|
||||
args:
|
||||
- one
|
||||
- two
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: deploy2
|
||||
spec:
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
key: value
|
||||
spec:
|
||||
containers:
|
||||
- name: busybox
|
||||
image: busybox
|
||||
EOF
|
||||
```
|
||||
|
||||
Declare a Strategic Merge Patch file to inject a sidecar container:
|
||||
|
||||
<!-- @addPatch @test -->
|
||||
```
|
||||
cat <<EOF >$DEMO_HOME/patch.yaml
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: not-important
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
containers:
|
||||
- name: istio-proxy
|
||||
image: docker.io/istio/proxyv2
|
||||
args:
|
||||
- proxy
|
||||
- sidecar
|
||||
EOF
|
||||
```
|
||||
|
||||
Apply the patch by adding _patches_ field in kustomization.yaml
|
||||
|
||||
<!-- @applyPatch @test -->
|
||||
```
|
||||
cat <<EOF >>$DEMO_HOME/kustomization.yaml
|
||||
patches:
|
||||
- path: patch.yaml
|
||||
target:
|
||||
kind: Deployment
|
||||
EOF
|
||||
```
|
||||
|
||||
Running `kustomize build $DEMO_HOME`, in the output confirm that both Deployment resources are patched correctly.
|
||||
|
||||
<!-- @confirmPatch @test -->
|
||||
```
|
||||
test 2 == \
|
||||
$(kustomize build $DEMO_HOME | grep "image: docker.io/istio/proxyv2" | wc -l); \
|
||||
echo $?
|
||||
```
|
||||
|
||||
The output is as follows:
|
||||
|
||||
```yaml
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: deploy1
|
||||
spec:
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
old-label: old-value
|
||||
spec:
|
||||
containers:
|
||||
- args:
|
||||
- proxy
|
||||
- sidecar
|
||||
image: docker.io/istio/proxyv2
|
||||
name: istio-proxy
|
||||
- args:
|
||||
- one
|
||||
- two
|
||||
image: nginx
|
||||
name: nginx
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: deploy2
|
||||
spec:
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
key: value
|
||||
spec:
|
||||
containers:
|
||||
- args:
|
||||
- proxy
|
||||
- sidecar
|
||||
image: docker.io/istio/proxyv2
|
||||
name: istio-proxy
|
||||
- image: busybox
|
||||
name: busybox
|
||||
```
|
||||
|
||||
## Target selector
|
||||
- Select resources with name matching `name*`
|
||||
```yaml
|
||||
target:
|
||||
name: name*
|
||||
```
|
||||
- Select all Deployment resources
|
||||
```yaml
|
||||
target:
|
||||
kind: Deployment
|
||||
```
|
||||
- Select resources matching label `app=hello`
|
||||
```yaml
|
||||
target:
|
||||
labelSelector: app=hello
|
||||
```
|
||||
- Select resources matching annotation `app=hello`
|
||||
```yaml
|
||||
target:
|
||||
annotationSelector: app=hello
|
||||
```
|
||||
- Select all Deployment resources matching label `app=hello`
|
||||
```yaml
|
||||
target:
|
||||
kind: Deployment
|
||||
labelSelector: app=hello
|
||||
```
|
||||
@@ -125,10 +125,8 @@ them, etc.
|
||||
|
||||
## Secret values from anywhere
|
||||
|
||||
> New _alpha_ behavior at HEAD, for v2.1+
|
||||
|
||||
A general alternative is to enshrine secret
|
||||
value generation in a [plugin](../docs/plugins.md).
|
||||
value generation in a [plugin](../docs/plugins).
|
||||
|
||||
The values can then come in via, say, an
|
||||
authenticated and authorized RPC to a password
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
[base]: ../../docs/glossary.md#base
|
||||
[kubeval]: https://github.com/instrumenta/kubeval
|
||||
[plugin]: ../../docs/plugins.md
|
||||
[plugin]: ../../docs/plugins
|
||||
|
||||
kustomize doesn't validate either its input or
|
||||
output beyond the validation provided by the
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
这些示例通过了 [pre-commit](../../travis/pre-commit.sh) 测试,并且应该与 HEAD 一起使用。
|
||||
|
||||
```
|
||||
go get sigs.k8s.io/kustomize
|
||||
go get sigs.k8s.io/kustomize/v3/cmd/kustomize
|
||||
```
|
||||
|
||||
基本用法
|
||||
|
||||
* [configGenerations](../configGeneration.md) - 当 ConfigMapGenerator 修改时进行滚动更新。
|
||||
* [configGenerations](configGeneration.md) - 当 ConfigMapGenerator 修改时进行滚动更新。
|
||||
|
||||
* [combineConfigs](../combineConfigs.md) - 融合来自不同用户的配置数据(例如来自 devops/SRE 和 developers)。
|
||||
|
||||
@@ -24,7 +24,9 @@ go get sigs.k8s.io/kustomize
|
||||
|
||||
* [remote target](../remoteBuild.md) - 通过 github URL 来构建 kustomization 。
|
||||
|
||||
* [json patch](../jsonpatch.md) -在 kustomization 中应用 json patch 。
|
||||
* [json patch](jsonpatch.md) -在 kustomization 中应用 json patch 。
|
||||
|
||||
* [patch multiple objects](patchMultipleObjects.md) - 通过一个patch来修改多个资源。
|
||||
|
||||
高级用法
|
||||
|
||||
@@ -34,6 +36,10 @@ go get sigs.k8s.io/kustomize
|
||||
|
||||
* [secret generation](../secretGeneratorPlugin.md) - 生成 Secret。
|
||||
|
||||
- transformer 插件:
|
||||
|
||||
* [validation transformer](../validationTransformer/README.md) - 通过 transformer 验证资源。
|
||||
|
||||
- 定制内建 transformer 配置
|
||||
|
||||
* [transformer configs](../transformerconfigs/README.md) - 自定义 transformer 配置。
|
||||
|
||||
184
examples/zh/configGeneration.md
Normal file
184
examples/zh/configGeneration.md
Normal file
@@ -0,0 +1,184 @@
|
||||
[patch]: ../../docs/glossary.md#patch
|
||||
[resource]: ../../docs/glossary.md#resource
|
||||
[variant]: ../../docs/glossary.md#variant
|
||||
|
||||
## ConfigMap 的生成和滚动更新
|
||||
|
||||
kustomize 提供了两种添加 ConfigMap 的方法:
|
||||
- 将 ConfigMap 声明为 [resource]
|
||||
- 通过 ConfigMapGenerator 声明 ConfigMap
|
||||
|
||||
在 `kustomization.yaml` 中,这两种方法的格式分别如下:
|
||||
|
||||
> ```
|
||||
> # 将 ConfigMap 声明为 resource
|
||||
> resources:
|
||||
> - configmap.yaml
|
||||
>
|
||||
> # 在 ConfigMapGenerator 中声明 ConfigMap
|
||||
> configMapGenerator:
|
||||
> - name: a-configmap
|
||||
> files:
|
||||
> - configs/configfile
|
||||
> - configs/another_configfile
|
||||
> ```
|
||||
|
||||
声明为 [resource] 的 ConfigMaps 的处理方式与其他 resource 相同,Kustomize 不会在为 ConfigMap 的名称添加哈希后缀。而在 ConfigMapGenerator 中声明 ConfigMap 的处理方式则与之前不同,默认将为名称添加哈希后缀,ConfigMap 中的任何更改都将触发滚动更新。
|
||||
|
||||
在 [hello_world](helloWorld.md) 示例中,使用 ConfigmapGenerator 来替换将 ConfigMap 声明为 [resource] 的方法。由此生成的 ConfigMap 中的更改将导致哈希值更改和滚动更新。
|
||||
|
||||
### 建立 base 和 staging
|
||||
|
||||
使用 configMapGenerator 建立 base
|
||||
<!-- @establishBase @test -->
|
||||
```
|
||||
DEMO_HOME=$(mktemp -d)
|
||||
|
||||
BASE=$DEMO_HOME/base
|
||||
mkdir -p $BASE
|
||||
|
||||
curl -s -o "$BASE/#1.yaml" "https://raw.githubusercontent.com\
|
||||
/kubernetes-sigs/kustomize\
|
||||
/master/examples/helloWorld\
|
||||
/{deployment,service}.yaml"
|
||||
|
||||
cat <<'EOF' >$BASE/kustomization.yaml
|
||||
commonLabels:
|
||||
app: hello
|
||||
resources:
|
||||
- deployment.yaml
|
||||
- service.yaml
|
||||
configMapGenerator:
|
||||
- name: the-map
|
||||
literals:
|
||||
- altGreeting=Good Morning!
|
||||
- enableRisky="false"
|
||||
EOF
|
||||
```
|
||||
|
||||
通过应用 ConfigMap patch 的方式建立 staging
|
||||
<!-- @establishStaging @test -->
|
||||
```
|
||||
OVERLAYS=$DEMO_HOME/overlays
|
||||
mkdir -p $OVERLAYS/staging
|
||||
|
||||
cat <<'EOF' >$OVERLAYS/staging/kustomization.yaml
|
||||
namePrefix: staging-
|
||||
nameSuffix: -v1
|
||||
commonLabels:
|
||||
variant: staging
|
||||
org: acmeCorporation
|
||||
commonAnnotations:
|
||||
note: Hello, I am staging!
|
||||
resources:
|
||||
- ../../base
|
||||
patchesStrategicMerge:
|
||||
- map.yaml
|
||||
EOF
|
||||
|
||||
cat <<EOF >$OVERLAYS/staging/map.yaml
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: the-map
|
||||
data:
|
||||
altGreeting: "Have a pineapple!"
|
||||
enableRisky: "true"
|
||||
EOF
|
||||
```
|
||||
|
||||
### Review
|
||||
|
||||
在集群中运行的 _hello-world_ 的 deployment 配置了来自 configMap 的数据。
|
||||
|
||||
deployment 按照名称引用此 ConfigMap :
|
||||
|
||||
<!-- @showDeployment @test -->
|
||||
```
|
||||
grep -C 2 configMapKeyRef $BASE/deployment.yaml
|
||||
```
|
||||
|
||||
当 ConfigMap 中的数据需要更新时,更改群集中的实时 ConfigMap 的数据并不是一个好的做法。 由于 Deployment 无法知道其引用的 ConfigMap 已更改,这类更新是无效。
|
||||
|
||||
更改 Deployment 配置的推荐方法是:
|
||||
|
||||
1. 使用新名称创建一个新的 configMap
|
||||
2. 为_deployment_ 添加 patch,修改相应 `configMapKeyRef` 字段的名称值。
|
||||
|
||||
后一种更改会启动对 deployment 中的 pod 的滚动更新。旧的 configMap 在不再被任何其他资源引用时最终会被[垃圾回收](https://github.com/kubernetes-sigs/kustomize/issues/242)。
|
||||
|
||||
### 如何使用 kustomize
|
||||
|
||||
_staging_ 的 [variant] 包含一个 configMap 的 [patch]:
|
||||
|
||||
<!-- @showMapPatch @test -->
|
||||
```
|
||||
cat $OVERLAYS/staging/map.yaml
|
||||
```
|
||||
|
||||
根据定义,此 patch 是一个命名但不一定是完整的资源规范,旨在修改完整的资源规范。
|
||||
|
||||
在 ConfigMapGenerator 中声明 ConfigMap 的修改。
|
||||
|
||||
<!-- @showMapBase @test -->
|
||||
```
|
||||
grep -C 4 configMapGenerator $BASE/kustomization.yaml
|
||||
```
|
||||
|
||||
要使这个 patch 正常工作,`metadata/name` 字段中的名称必须匹配。
|
||||
|
||||
但是,文件中指定的名称值不是群集中使用的名称值。根据设计,kustomize 修改从 ConfigMapGenerator 声明的 ConfigMaps 的名称。要查看最终在群集中使用的名称,只需运行 kustomize:
|
||||
|
||||
<!-- @grepStagingName @test -->
|
||||
```
|
||||
kustomize build $OVERLAYS/staging |\
|
||||
grep -B 8 -A 1 staging-the-map
|
||||
```
|
||||
|
||||
根据 `$OVERLAYS/staging/kustomization.yaml` 中的 `namePrefix` 字段,configMap 名称以 _staging-_ 为前缀。
|
||||
|
||||
根据 `$OVERLAYS/staging/kustomization.yaml` 中的 `nameSuffix` 字段,configMap 名称以 _-v1_ 为后缀。
|
||||
|
||||
configMap 名称的后缀是由 map 内容的哈希生成的 - 在这种情况下,名称后缀是 _k25m8k5k5m_ :
|
||||
|
||||
<!-- @grepStagingHash @test -->
|
||||
```
|
||||
kustomize build $OVERLAYS/staging | grep k25m8k5k5m
|
||||
```
|
||||
|
||||
现在修改 map patch ,更改该服务将使用的问候消息:
|
||||
|
||||
<!-- @changeMap @test -->
|
||||
```
|
||||
sed -i.bak 's/pineapple/kiwi/' $OVERLAYS/staging/map.yaml
|
||||
```
|
||||
|
||||
查看新的问候消息:
|
||||
|
||||
```
|
||||
kustomize build $OVERLAYS/staging |\
|
||||
grep -B 2 -A 3 kiwi
|
||||
```
|
||||
|
||||
再次运行 kustomize 查看新的 configMap 名称:
|
||||
|
||||
<!-- @grepStagingName @test -->
|
||||
```
|
||||
kustomize build $OVERLAYS/staging |\
|
||||
grep -B 8 -A 1 staging-the-map
|
||||
```
|
||||
|
||||
确认 configMap 内容的更改将会生成以 _cd7kdh48fd_ 结尾的三个新名称 - 一个在 configMap 的名称中,另两个在使用 ConfigMap 的 deployment 中:
|
||||
|
||||
<!-- @countHashes @test -->
|
||||
```
|
||||
test 3 == \
|
||||
$(kustomize build $OVERLAYS/staging | grep cd7kdh48fd | wc -l); \
|
||||
echo $?
|
||||
```
|
||||
|
||||
将这些资源应用于群集将导致 deployment pod 的滚动更新,将它们从 _k25m8k5k5m_ map 重新定位到 _cd7kdh48fd_ map 。系统稍后将垃圾收集未使用的 map。
|
||||
|
||||
## 回滚
|
||||
|
||||
回滚,可以撤消对源码配置所做的任何编辑,然后在还原的配置上重新运行 kustomize 并将其应用于群集。
|
||||
124
examples/zh/jsonpatch.md
Normal file
124
examples/zh/jsonpatch.md
Normal file
@@ -0,0 +1,124 @@
|
||||
# 例子: 应用 json patch(json补丁)
|
||||
|
||||
kustomization文件支持通过[JSON patches](https://tools.ietf.org/html/rfc6902)来修改已有的资源.
|
||||
|
||||
下面的例子将会使用这个功能对`Ingress`加以修改.
|
||||
|
||||
首先,创建一个包含`ingress`的`kustomization`文件.
|
||||
|
||||
<!-- @createIngress @test -->
|
||||
```bash
|
||||
DEMO_HOME=$(mktemp -d)
|
||||
|
||||
cat <<EOF >$DEMO_HOME/kustomization.yaml
|
||||
resources:
|
||||
- ingress.yaml
|
||||
EOF
|
||||
|
||||
cat <<EOF >$DEMO_HOME/ingress.yaml
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: my-ingress
|
||||
spec:
|
||||
rules:
|
||||
- host: foo.bar.com
|
||||
http:
|
||||
paths:
|
||||
- backend:
|
||||
serviceName: my-api
|
||||
servicePort: 80
|
||||
EOF
|
||||
```
|
||||
|
||||
定义一个JSON patch文件,以更新`Ingress`对象的2个字段:
|
||||
|
||||
- 把 host 从 `foo.bar.com` 改为 `foo.bar.io`
|
||||
- 把 servicePort 从 `80` 改为 `8080`
|
||||
|
||||
<!-- @addJsonPatch @test -->
|
||||
```bash
|
||||
cat <<EOF >$DEMO_HOME/ingress_patch.json
|
||||
[
|
||||
{"op": "replace", "path": "/spec/rules/0/host", "value": "foo.bar.io"},
|
||||
{"op": "replace", "path": "/spec/rules/0/http/paths/0/backend/servicePort", "value": 8080}
|
||||
]
|
||||
EOF
|
||||
```
|
||||
|
||||
JSON patch 也可以写成 YAML 的格式.该例子顺便展示了“添加”操作:
|
||||
|
||||
<!-- @addYamlPatch @test -->
|
||||
```bash
|
||||
cat <<EOF >$DEMO_HOME/ingress_patch.yaml
|
||||
- op: replace
|
||||
path: /spec/rules/0/host
|
||||
value: foo.bar.io
|
||||
|
||||
- op: add
|
||||
path: /spec/rules/0/http/paths/-
|
||||
value:
|
||||
path: '/test'
|
||||
backend:
|
||||
serviceName: my-test
|
||||
servicePort: 8081
|
||||
EOF
|
||||
```
|
||||
|
||||
在kustomization.yaml文件中增加 _patchesJson6902_ 字段,以应用该补丁
|
||||
|
||||
<!-- @applyJsonPatch @test -->
|
||||
```bash
|
||||
cat <<EOF >>$DEMO_HOME/kustomization.yaml
|
||||
patchesJson6902:
|
||||
- target:
|
||||
group: extensions
|
||||
version: v1beta1
|
||||
kind: Ingress
|
||||
name: my-ingress
|
||||
path: ingress_patch.json
|
||||
EOF
|
||||
```
|
||||
|
||||
运行 `kustomize build $DEMO_HOME`, 在输出那里确认 host 已经被正确更新.
|
||||
|
||||
<!-- @confirmHost @test -->
|
||||
```bash
|
||||
test 1 == \
|
||||
$(kustomize build $DEMO_HOME | grep "host: foo.bar.io" | wc -l); \
|
||||
echo $?
|
||||
```
|
||||
|
||||
运行 `kustomize build $DEMO_HOME`, 在输出那里确认 servicePort 已经被正确更新.
|
||||
|
||||
<!-- @confirmServicePort @test -->
|
||||
|
||||
```bash
|
||||
test 1 == \
|
||||
$(kustomize build $DEMO_HOME | grep "servicePort: 8080" | wc -l); \
|
||||
echo $?
|
||||
```
|
||||
|
||||
如果 patch 是YAML格式的,就能正确解析:
|
||||
|
||||
<!-- @applyYamlPatch @test -->
|
||||
```bash
|
||||
cat <<EOF >>$DEMO_HOME/kustomization.yaml
|
||||
patchesJson6902:
|
||||
- target:
|
||||
group: extensions
|
||||
version: v1beta1
|
||||
kind: Ingress
|
||||
name: my-ingress
|
||||
path: ingress_patch.yaml
|
||||
EOF
|
||||
```
|
||||
|
||||
运行 `kustomize build $DEMO_HOME`, 在输出那里确认有 `/test` 这个路径.
|
||||
|
||||
<!-- @confirmYamlPatch @test -->
|
||||
```bash
|
||||
test 1 == \
|
||||
$(kustomize build $DEMO_HOME | grep "path: /test" | wc -l); \
|
||||
echo $?
|
||||
```
|
||||
46
go.mod
46
go.mod
@@ -1,38 +1,32 @@
|
||||
module sigs.k8s.io/kustomize
|
||||
module sigs.k8s.io/kustomize/v3
|
||||
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/PuerkitoBio/purell v1.1.0 // indirect
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
|
||||
github.com/emicklei/go-restful v2.9.3+incompatible // indirect
|
||||
github.com/evanphx/json-patch v3.0.0+incompatible
|
||||
github.com/ghodss/yaml v1.0.0 // indirect
|
||||
github.com/go-openapi/jsonpointer v0.0.0-20180322222829-3a0015ad55fa // indirect
|
||||
github.com/go-openapi/jsonreference v0.0.0-20180322222742-3fb327e6747d // indirect
|
||||
github.com/go-openapi/spec v0.0.0-20180415031709-bcff419492ee
|
||||
github.com/go-openapi/swag v0.0.0-20180405201759-811b1089cde9 // indirect
|
||||
github.com/gogo/protobuf v1.0.0 // indirect
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
|
||||
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect
|
||||
github.com/googleapis/gnostic v0.1.0 // indirect
|
||||
github.com/emicklei/go-restful v2.9.6+incompatible // indirect
|
||||
github.com/evanphx/json-patch v4.5.0+incompatible
|
||||
github.com/go-openapi/spec v0.19.2
|
||||
github.com/gogo/protobuf v1.2.1 // indirect
|
||||
github.com/golang/protobuf v1.3.1 // indirect
|
||||
github.com/google/gofuzz v1.0.0 // indirect
|
||||
github.com/googleapis/gnostic v0.3.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||
github.com/json-iterator/go v0.0.0-20180315132816-ca39e5af3ece // indirect
|
||||
github.com/mailru/easyjson v0.0.0-20180606163543-3fdea8d05856 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v0.0.0-20180228065516-1df9eeb2bb81 // indirect
|
||||
github.com/json-iterator/go v1.1.6 // indirect
|
||||
github.com/mailru/easyjson v0.0.0-20190620125010-da37f6c1e481 // indirect
|
||||
github.com/modern-go/reflect2 v1.0.1 // indirect
|
||||
github.com/onsi/ginkgo v1.8.0 // indirect
|
||||
github.com/onsi/gomega v1.5.0 // indirect
|
||||
github.com/pkg/errors v0.8.1
|
||||
github.com/spf13/cobra v0.0.2
|
||||
github.com/spf13/pflag v1.0.1
|
||||
github.com/stretchr/testify v1.3.0 // indirect
|
||||
golang.org/x/tools v0.0.0-20190608022120-eacb66d2a7c3 // indirect
|
||||
github.com/spf13/pflag v1.0.3
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 // indirect
|
||||
golang.org/x/sys v0.0.0-20190621203818-d432491b9138 // indirect
|
||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||
gopkg.in/yaml.v2 v2.2.1
|
||||
k8s.io/api v0.0.0-20180510062335-53d615ae3f44
|
||||
k8s.io/apimachinery v0.0.0-20180510061931-13b73596e4b6
|
||||
k8s.io/client-go v7.0.0+incompatible
|
||||
k8s.io/kube-openapi v0.0.0-20180510204742-b3f03f553288
|
||||
gopkg.in/yaml.v2 v2.2.2
|
||||
k8s.io/api v0.0.0-20190313235455-40a48860b5ab
|
||||
k8s.io/apimachinery v0.0.0-20190313205120-d7deff9243b1
|
||||
k8s.io/client-go v11.0.0+incompatible
|
||||
k8s.io/klog v0.3.3 // indirect
|
||||
k8s.io/kube-openapi v0.0.0-20190603182131-db7b694dc208
|
||||
sigs.k8s.io/yaml v1.1.0
|
||||
)
|
||||
|
||||
153
go.sum
153
go.sum
@@ -1,84 +1,132 @@
|
||||
github.com/PuerkitoBio/purell v1.1.0 h1:rmGxhojJlM0tuKtfdvliR84CFHljx9ag64t2xmVkjK4=
|
||||
github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
||||
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
|
||||
github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
||||
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
|
||||
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||
github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/emicklei/go-restful v2.9.3+incompatible h1:2OwhVdhtzYUp5P5wuGsVDPagKSRd9JK72sJCHVCXh5g=
|
||||
github.com/emicklei/go-restful v2.9.3+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
|
||||
github.com/evanphx/json-patch v3.0.0+incompatible h1:l91aby7TzBXBdmF8heZqjskeH9f3g7ZOL8/sSe+vTlU=
|
||||
github.com/evanphx/json-patch v3.0.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
|
||||
github.com/emicklei/go-restful v2.9.6+incompatible h1:tfrHha8zJ01ywiOEC1miGY8st1/igzWB8OmvPgoYX7w=
|
||||
github.com/emicklei/go-restful v2.9.6+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
|
||||
github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5IcNrDCXZ6OoTAWu7M=
|
||||
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/go-openapi/jsonpointer v0.0.0-20180322222829-3a0015ad55fa h1:hr8WVDjg4JKtQptZpzyb196TmruCs7PIsdJz8KAOZp8=
|
||||
github.com/go-openapi/jsonpointer v0.0.0-20180322222829-3a0015ad55fa/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0=
|
||||
github.com/go-openapi/jsonreference v0.0.0-20180322222742-3fb327e6747d h1:k3UQ7Z8yFYq0BNkYykKIheY0HlZBl1Hku+pO9HE9FNU=
|
||||
github.com/go-openapi/jsonreference v0.0.0-20180322222742-3fb327e6747d/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg=
|
||||
github.com/go-openapi/spec v0.0.0-20180415031709-bcff419492ee h1:eo0HQoNFtbiEc7+1gRF9pgW6azx8a1cO2fXcqq1MuD0=
|
||||
github.com/go-openapi/spec v0.0.0-20180415031709-bcff419492ee/go.mod h1:J8+jY1nAiCcj+friV/PDoE1/3eeccG9LYBs0tYvLOWc=
|
||||
github.com/go-openapi/swag v0.0.0-20180405201759-811b1089cde9 h1:+vsw187FKvA2QUGAcE+vQSfyxqLbUXixPYRRMAzwu04=
|
||||
github.com/go-openapi/swag v0.0.0-20180405201759-811b1089cde9/go.mod h1:DXUve3Dpr1UfpPtxFw+EFuQ41HhCWZfha5jSVRG7C7I=
|
||||
github.com/gogo/protobuf v1.0.0 h1:2jyBKDKU/8v3v2xVR2PtiWQviFUyiaGk2rpfyFT8rTM=
|
||||
github.com/gogo/protobuf v1.0.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0=
|
||||
github.com/go-openapi/jsonpointer v0.19.2 h1:A9+F4Dc/MCNB5jibxf6rRvOvR/iFgQdyNx9eIhnGqq0=
|
||||
github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg=
|
||||
github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg=
|
||||
github.com/go-openapi/jsonreference v0.19.2 h1:o20suLFB4Ri0tuzpWtyHlh7E7HnkqTNLq6aR6WVNS1w=
|
||||
github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc=
|
||||
github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nAiCcj+friV/PDoE1/3eeccG9LYBs0tYvLOWc=
|
||||
github.com/go-openapi/spec v0.19.2 h1:SStNd1jRcYtfKCN7R0laGNs80WYYvn5CbBjM2sOmCrE=
|
||||
github.com/go-openapi/spec v0.19.2/go.mod h1:sCxk3jxKgioEJikev4fgkNmwS+3kuYdJtcsZsD5zxMY=
|
||||
github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dpr1UfpPtxFw+EFuQ41HhCWZfha5jSVRG7C7I=
|
||||
github.com/go-openapi/swag v0.19.2 h1:jvO6bCMBEilGwMfHhrd61zIID4oIFdwb76V17SM88dE=
|
||||
github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
||||
github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE=
|
||||
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
|
||||
github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf h1:+RRA9JqSOZFfKrOeqr2z77+8R2RKyh8PG66dcu1V0ck=
|
||||
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
|
||||
github.com/googleapis/gnostic v0.1.0 h1:rVsPeBmXbYv4If/cumu1AzZPwV58q433hvONV1UEZoI=
|
||||
github.com/googleapis/gnostic v0.1.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
|
||||
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
|
||||
github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/googleapis/gnostic v0.0.0-20170426233943-68f4ded48ba9/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
|
||||
github.com/googleapis/gnostic v0.3.0 h1:CcQijm0XKekKjP/YCz28LXVSpgguuB+nCxaSjCe09y0=
|
||||
github.com/googleapis/gnostic v0.3.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
|
||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/json-iterator/go v0.0.0-20180315132816-ca39e5af3ece h1:3HJXp/18JmMk5sjBP3LDUBtWjczCvynxaeAF6b6kWp8=
|
||||
github.com/json-iterator/go v0.0.0-20180315132816-ca39e5af3ece/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/mailru/easyjson v0.0.0-20180606163543-3fdea8d05856 h1:hOnidOuIWNsFRPcxxStGeN3NNm4n4+w6KJ9cVJIh70o=
|
||||
github.com/mailru/easyjson v0.0.0-20180606163543-3fdea8d05856/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3 h1:/UewZcckqhvnnS0C6r3Sher2hSEbVmM6Ogpcjen08+Y=
|
||||
github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs=
|
||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.0.0-20190620125010-da37f6c1e481 h1:IaSjLMT6WvkoZZjspGxy3rdaTEmWLoRm49WbtVUi9sA=
|
||||
github.com/mailru/easyjson v0.0.0-20190620125010-da37f6c1e481/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180228065516-1df9eeb2bb81 h1:ImOHKpmdLPXWX5KSYquUWXKaopEPuY7TPPUo18u9aOI=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180228065516-1df9eeb2bb81/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180320133207-05fbef0ca5da h1:ZQGIPjr1iTtUPXZFk8WShqb5G+Qg65VHFLtSvmHh+Mw=
|
||||
github.com/modern-go/reflect2 v0.0.0-20180320133207-05fbef0ca5da/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
|
||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
||||
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w=
|
||||
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
|
||||
github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo=
|
||||
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/spf13/cobra v0.0.2 h1:NfkwRbgViGoyjBKsLI0QMDcuMnhM+SBg3T0cGfpvKDE=
|
||||
github.com/spf13/cobra v0.0.2/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
||||
github.com/spf13/pflag v1.0.1 h1:aCvUg6QPl3ibpQUxyLkrEkCHtPqYJL4x9AuhqVqFis4=
|
||||
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
|
||||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
||||
github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190225153610-fe579d43d832 h1:2IdId8zoI92l1bUzjAOygcAOkmCe13HY1j0rqPPPzB8=
|
||||
golang.org/x/net v0.0.0-20190225153610-fe579d43d832/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI=
|
||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e h1:o3PsSEY8E4eXWkXrIP9YJALUkVZqzHJT5DOasTyn8Vs=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190621203818-d432491b9138 h1:t8BZD9RDjkm9/h7yYN6kE8oaeov5r9aztkB7zKA5Tkg=
|
||||
golang.org/x/sys v0.0.0-20190621203818-d432491b9138/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d h1:bt+R27hbE7uVf7PY9S6wpNg9Xo2WRe/XQT0uGq9RQQw=
|
||||
golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20190608022120-eacb66d2a7c3 h1:sU3tSV6wDhWsvf9NjL0FzRjgAmYnQL5NEhdmcN16UEg=
|
||||
golang.org/x/tools v0.0.0-20190608022120-eacb66d2a7c3/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59 h1:QjA/9ArTfVTLfEhClDCG7SGrZkZixxWpwNCDiwJfh88=
|
||||
golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
|
||||
@@ -87,13 +135,20 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkep
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
k8s.io/api v0.0.0-20180510062335-53d615ae3f44 h1:zQ8YhMpuc1QJoor+Vm1moP9iEOyaQgOjSj3bo/zUEXE=
|
||||
k8s.io/api v0.0.0-20180510062335-53d615ae3f44/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA=
|
||||
k8s.io/apimachinery v0.0.0-20180510061931-13b73596e4b6 h1:pJrzRmry9HLPxkVGMk57cfeGRy/WG0oYXuji9t4zD1M=
|
||||
k8s.io/apimachinery v0.0.0-20180510061931-13b73596e4b6/go.mod h1:ccL7Eh7zubPUSh9A3USN90/OzHNSVN6zxzde07TDCL0=
|
||||
k8s.io/client-go v7.0.0+incompatible h1:kiH+Y6hn+pc78QS/mtBfMJAMIIaWevHi++JvOGEEQp4=
|
||||
k8s.io/client-go v7.0.0+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s=
|
||||
k8s.io/kube-openapi v0.0.0-20180510204742-b3f03f553288 h1:AhFqcaw5JbAAaZHxTe1fT+Jtek0pZmIwwt6FbsMA9to=
|
||||
k8s.io/kube-openapi v0.0.0-20180510204742-b3f03f553288/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
k8s.io/api v0.0.0-20190313235455-40a48860b5ab h1:DG9A67baNpoeweOy2spF1OWHhnVY5KR7/Ek/+U1lVZc=
|
||||
k8s.io/api v0.0.0-20190313235455-40a48860b5ab/go.mod h1:iuAfoD4hCxJ8Onx9kaTIt30j7jUFS00AXQi6QMi99vA=
|
||||
k8s.io/apimachinery v0.0.0-20190313205120-d7deff9243b1 h1:IS7K02iBkQXpCeieSiyJjGoLSdVOv2DbPaWHJ+ZtgKg=
|
||||
k8s.io/apimachinery v0.0.0-20190313205120-d7deff9243b1/go.mod h1:ccL7Eh7zubPUSh9A3USN90/OzHNSVN6zxzde07TDCL0=
|
||||
k8s.io/client-go v11.0.0+incompatible h1:LBbX2+lOwY9flffWlJM7f1Ct8V2SRNiMRDFeiwnJo9o=
|
||||
k8s.io/client-go v11.0.0+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s=
|
||||
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
|
||||
k8s.io/klog v0.3.3 h1:niceAagH1tzskmaie/icWd7ci1wbG7Bf2c6YGcQv+3c=
|
||||
k8s.io/klog v0.3.3/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
|
||||
k8s.io/kube-openapi v0.0.0-20190603182131-db7b694dc208 h1:5sW+fEHvlJI3Ngolx30CmubFulwH28DhKjGf70Xmtco=
|
||||
k8s.io/kube-openapi v0.0.0-20190603182131-db7b694dc208/go.mod h1:nfDlWeOsu3pUf4yWGL+ERqohP4YsZcBJXWMK+gkzOA4=
|
||||
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
|
||||
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
|
||||
@@ -6,11 +6,11 @@ package loadertest
|
||||
|
||||
import (
|
||||
"log"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/pkg/loader"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
"sigs.k8s.io/kustomize/pkg/validators"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/loader"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/validators"
|
||||
)
|
||||
|
||||
// FakeLoader encapsulates the delegate Loader and the fake file system.
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"unicode/utf8"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/types"
|
||||
)
|
||||
|
||||
func makeFreshConfigMap(
|
||||
|
||||
@@ -9,10 +9,10 @@ import (
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/loader"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
"sigs.k8s.io/kustomize/pkg/validators"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/loader"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/validators"
|
||||
)
|
||||
|
||||
func makeEnvConfigMap(name string) *corev1.ConfigMap {
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
package configmapandsecret
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/types"
|
||||
)
|
||||
|
||||
// Factory makes ConfigMaps and Secrets.
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/types"
|
||||
)
|
||||
|
||||
func makeFreshSecret(
|
||||
|
||||
@@ -9,10 +9,10 @@ import (
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/loader"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
"sigs.k8s.io/kustomize/pkg/validators"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/loader"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/validators"
|
||||
)
|
||||
|
||||
func makeEnvSecret(name string) *corev1.Secret {
|
||||
|
||||
@@ -11,9 +11,9 @@ import (
|
||||
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/util/yaml"
|
||||
"sigs.k8s.io/kustomize/k8sdeps/configmapandsecret"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
"sigs.k8s.io/kustomize/v3/k8sdeps/configmapandsecret"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/types"
|
||||
)
|
||||
|
||||
// KunstructuredFactoryImpl hides construction using apimachinery types.
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/ifc"
|
||||
)
|
||||
|
||||
func TestSliceFromBytes(t *testing.T) {
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"sigs.k8s.io/kustomize/pkg/hasher"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/hasher"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/ifc"
|
||||
)
|
||||
|
||||
// kustHash computes a hash of an unstructured object.
|
||||
|
||||
@@ -1,18 +1,5 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Package kunstruct provides unstructured from api machinery and factory for creating unstructured
|
||||
package kunstruct
|
||||
@@ -31,7 +18,11 @@ import (
|
||||
// field of the first item in the foo list
|
||||
type PathSection struct {
|
||||
fields []string
|
||||
idx *int
|
||||
idx int
|
||||
}
|
||||
|
||||
func newPathSection() PathSection {
|
||||
return PathSection{idx: -1}
|
||||
}
|
||||
|
||||
func appendNonEmpty(section *PathSection, field string) {
|
||||
@@ -40,13 +31,12 @@ func appendNonEmpty(section *PathSection, field string) {
|
||||
}
|
||||
}
|
||||
|
||||
func parseFields(path string) ([]PathSection, error) {
|
||||
section := PathSection{}
|
||||
sectionset := []PathSection{}
|
||||
func parseFields(path string) (result []PathSection, err error) {
|
||||
section := newPathSection()
|
||||
if !strings.Contains(path, "[") {
|
||||
section.fields = strings.Split(path, ".")
|
||||
sectionset = append(sectionset, section)
|
||||
return sectionset, nil
|
||||
result = append(result, section)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
start := 0
|
||||
@@ -69,15 +59,18 @@ func parseFields(path string) ([]PathSection, error) {
|
||||
case ']':
|
||||
if insideParentheses {
|
||||
// Assign this index to the current
|
||||
// PathSection, save it to the set, then begin
|
||||
// PathSection, save it to the result, then begin
|
||||
// a new PathSection
|
||||
tmpIdx, err := strconv.Atoi(path[start:i])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid index %s", path)
|
||||
if err == nil {
|
||||
// We have detected an integer so an array.
|
||||
section.idx = tmpIdx
|
||||
} else {
|
||||
// We have detected the downwardapi syntax
|
||||
appendNonEmpty(§ion, path[start:i])
|
||||
}
|
||||
section.idx = &tmpIdx
|
||||
sectionset = append(sectionset, section)
|
||||
section = PathSection{}
|
||||
result = append(result, section)
|
||||
section = newPathSection()
|
||||
|
||||
start = i + 1
|
||||
insideParentheses = false
|
||||
@@ -88,15 +81,15 @@ func parseFields(path string) ([]PathSection, error) {
|
||||
}
|
||||
if start < len(path)-1 {
|
||||
appendNonEmpty(§ion, path[start:])
|
||||
sectionset = append(sectionset, section)
|
||||
result = append(result, section)
|
||||
}
|
||||
|
||||
for _, section := range sectionset {
|
||||
for _, section := range result {
|
||||
for i, f := range section.fields {
|
||||
if strings.HasPrefix(f, "\"") || strings.HasPrefix(f, "'") {
|
||||
section.fields[i] = strings.Trim(f, "\"'")
|
||||
}
|
||||
}
|
||||
}
|
||||
return sectionset, nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -1,18 +1,5 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package kunstruct
|
||||
|
||||
@@ -23,20 +10,15 @@ import (
|
||||
|
||||
type PathSectionSlice []PathSection
|
||||
|
||||
func buildPath(idx *int, fields ...string) PathSectionSlice {
|
||||
func buildPath(idx int, fields ...string) PathSectionSlice {
|
||||
return PathSectionSlice{PathSection{fields: fields, idx: idx}}
|
||||
}
|
||||
|
||||
func (a PathSectionSlice) addSection(idx *int, fields ...string) PathSectionSlice {
|
||||
func (a PathSectionSlice) addSection(idx int, fields ...string) PathSectionSlice {
|
||||
return append(a, PathSection{fields: fields, idx: idx})
|
||||
}
|
||||
|
||||
func TestParseField(t *testing.T) {
|
||||
i := 1
|
||||
var one *int = &i
|
||||
j := 0
|
||||
var zero *int = &j
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
pathToField string
|
||||
@@ -47,62 +29,62 @@ func TestParseField(t *testing.T) {
|
||||
{
|
||||
name: "oneField",
|
||||
pathToField: "Kind",
|
||||
expectedValue: buildPath(nil, "Kind"),
|
||||
expectedValue: buildPath(-1, "Kind"),
|
||||
errorExpected: false,
|
||||
},
|
||||
{
|
||||
name: "twoFields",
|
||||
pathToField: "metadata.name",
|
||||
expectedValue: buildPath(nil, "metadata", "name"),
|
||||
expectedValue: buildPath(-1, "metadata", "name"),
|
||||
errorExpected: false,
|
||||
},
|
||||
{
|
||||
name: "threeFields",
|
||||
pathToField: "spec.ports.port",
|
||||
expectedValue: buildPath(nil, "spec", "ports", "port"),
|
||||
expectedValue: buildPath(-1, "spec", "ports", "port"),
|
||||
errorExpected: false,
|
||||
},
|
||||
{
|
||||
name: "empty",
|
||||
pathToField: "",
|
||||
expectedValue: buildPath(nil, ""),
|
||||
expectedValue: buildPath(-1, ""),
|
||||
errorExpected: false,
|
||||
},
|
||||
{
|
||||
name: "validStringIndex",
|
||||
pathToField: "that[1]",
|
||||
expectedValue: buildPath(one, "that"),
|
||||
expectedValue: buildPath(1, "that"),
|
||||
errorExpected: false,
|
||||
},
|
||||
{
|
||||
name: "sliceInSlice",
|
||||
pathToField: "that[1][0]",
|
||||
expectedValue: buildPath(one, "that").addSection(zero),
|
||||
expectedValue: buildPath(1, "that").addSection(0),
|
||||
errorExpected: false,
|
||||
},
|
||||
{
|
||||
name: "validStructSubField",
|
||||
pathToField: "those[1].field2",
|
||||
expectedValue: buildPath(one, "those").addSection(nil, "field2"),
|
||||
expectedValue: buildPath(1, "those").addSection(-1, "field2"),
|
||||
errorExpected: false,
|
||||
},
|
||||
{
|
||||
name: "validStructSubFieldIndex",
|
||||
pathToField: "these[1].field2[0]",
|
||||
expectedValue: buildPath(one, "these").addSection(zero, "field2"),
|
||||
expectedValue: buildPath(1, "these").addSection(0, "field2"),
|
||||
errorExpected: false,
|
||||
},
|
||||
{
|
||||
name: "validStructSubFieldIndexSubfield",
|
||||
pathToField: "complextree[1].field2[1].stringsubfield",
|
||||
expectedValue: buildPath(one, "complextree").addSection(one, "field2").addSection(nil, "stringsubfield"),
|
||||
expectedValue: buildPath(1, "complextree").addSection(1, "field2").addSection(-1, "stringsubfield"),
|
||||
errorExpected: false,
|
||||
},
|
||||
{
|
||||
name: "validStructSubFieldNoneIntIndex",
|
||||
pathToField: "complextree[thisisnotanint]",
|
||||
errorExpected: true,
|
||||
errorMsg: "invalid index complextree[thisisnotanint]",
|
||||
name: "validStructDownwardAPI",
|
||||
pathToField: `metadata.labels["app.kubernetes.io/component"]`,
|
||||
expectedValue: buildPath(-1, "metadata", "labels", "app.kubernetes.io/component"),
|
||||
errorExpected: false,
|
||||
},
|
||||
{
|
||||
name: "invalidIndexInIndex",
|
||||
@@ -119,7 +101,7 @@ func TestParseField(t *testing.T) {
|
||||
{
|
||||
name: "validFieldsWithQuotes",
|
||||
pathToField: "'complextree'[1].field2[1].'stringsubfield'",
|
||||
expectedValue: buildPath(one, "complextree").addSection(one, "field2").addSection(nil, "stringsubfield"),
|
||||
expectedValue: buildPath(1, "complextree").addSection(1, "field2").addSection(-1, "stringsubfield"),
|
||||
errorExpected: false,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -20,13 +20,19 @@ package kunstruct
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
jsonpatch "github.com/evanphx/json-patch"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/util/strategicpatch"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/types"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"sigs.k8s.io/kustomize/pkg/gvk"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/gvk"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/ifc"
|
||||
)
|
||||
|
||||
var _ ifc.Kunstructured = &UnstructAdapter{}
|
||||
@@ -63,6 +69,11 @@ func (fs *UnstructAdapter) GetGvk() gvk.Gvk {
|
||||
}
|
||||
}
|
||||
|
||||
// SetGvk set the Gvk of the object to the input Gvk
|
||||
func (fs *UnstructAdapter) SetGvk(g gvk.Gvk) {
|
||||
fs.SetGroupVersionKind(toSchemaGvk(g))
|
||||
}
|
||||
|
||||
// Copy provides a copy behind an interface.
|
||||
func (fs *UnstructAdapter) Copy() ifc.Kunstructured {
|
||||
return &UnstructAdapter{*fs.DeepCopy()}
|
||||
@@ -92,7 +103,7 @@ func (fs *UnstructAdapter) selectSubtree(path string) (map[string]interface{}, [
|
||||
idx := sections[sectionIdx].idx
|
||||
fields := sections[sectionIdx].fields
|
||||
|
||||
if idx == nil {
|
||||
if idx == -1 {
|
||||
// This section has no index
|
||||
return content, fields, true, nil
|
||||
}
|
||||
@@ -107,24 +118,24 @@ func (fs *UnstructAdapter) selectSubtree(path string) (map[string]interface{}, [
|
||||
if !ok {
|
||||
return content, fields, false, fmt.Errorf("%v is of the type %T, expected []interface{}", indexedField, indexedField)
|
||||
}
|
||||
if *idx >= len(s) {
|
||||
return content, fields, false, fmt.Errorf("index %d is out of bounds", *idx)
|
||||
if idx >= len(s) {
|
||||
return content, fields, false, fmt.Errorf("index %d is out of bounds", idx)
|
||||
}
|
||||
|
||||
if sectionIdx == lastSectionIdx-1 {
|
||||
// This is the last section. Let's build a fake map
|
||||
// to let the rest of the field extraction to work.
|
||||
idxstring := fmt.Sprintf("[%v]", *idx)
|
||||
newContent := map[string]interface{}{idxstring: s[*idx]}
|
||||
idxstring := fmt.Sprintf("[%v]", idx)
|
||||
newContent := map[string]interface{}{idxstring: s[idx]}
|
||||
newFields := []string{idxstring}
|
||||
return newContent, newFields, true, nil
|
||||
}
|
||||
|
||||
newContent, ok := s[*idx].(map[string]interface{})
|
||||
newContent, ok := s[idx].(map[string]interface{})
|
||||
if !ok {
|
||||
// Only map are supported here
|
||||
return content, fields, false,
|
||||
fmt.Errorf("%#v is expected to be of type map[string]interface{}", s[*idx])
|
||||
fmt.Errorf("%#v is expected to be of type map[string]interface{}", s[idx])
|
||||
}
|
||||
content = newContent
|
||||
}
|
||||
@@ -267,3 +278,79 @@ func (fs *UnstructAdapter) GetMap(path string) (map[string]interface{}, error) {
|
||||
}
|
||||
return nil, types.NoFieldError{Field: path}
|
||||
}
|
||||
|
||||
func (fs *UnstructAdapter) MatchesLabelSelector(selector string) (bool, error) {
|
||||
s, err := labels.Parse(selector)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return s.Matches(labels.Set(fs.GetLabels())), nil
|
||||
}
|
||||
|
||||
func (fs *UnstructAdapter) MatchesAnnotationSelector(selector string) (bool, error) {
|
||||
s, err := labels.Parse(selector)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return s.Matches(labels.Set(fs.GetAnnotations())), nil
|
||||
}
|
||||
|
||||
func (fs *UnstructAdapter) Patch(patch ifc.Kunstructured) error {
|
||||
versionedObj, err := scheme.Scheme.New(
|
||||
toSchemaGvk(patch.GetGvk()))
|
||||
merged := map[string]interface{}{}
|
||||
saveName := fs.GetName()
|
||||
switch {
|
||||
case runtime.IsNotRegisteredError(err):
|
||||
baseBytes, err := json.Marshal(fs.Map())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
patchBytes, err := json.Marshal(patch.Map())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mergedBytes, err := jsonpatch.MergePatch(baseBytes, patchBytes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = json.Unmarshal(mergedBytes, &merged)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case err != nil:
|
||||
return err
|
||||
default:
|
||||
// Use Strategic-Merge-Patch to handle types w/ schema
|
||||
// TODO: Change this to use the new Merge package.
|
||||
// Store the name of the target object, because this name may have been munged.
|
||||
// Apply this name to the patched object.
|
||||
lookupPatchMeta, err := strategicpatch.NewPatchMetaFromStruct(versionedObj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
merged, err = strategicpatch.StrategicMergeMapPatchUsingLookupPatchMeta(
|
||||
fs.Map(),
|
||||
patch.Map(),
|
||||
lookupPatchMeta)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
fs.SetMap(merged)
|
||||
if len(fs.Map()) != 0 {
|
||||
// if the patch deletes the object
|
||||
// don't reset the name
|
||||
fs.SetName(saveName)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// toSchemaGvk converts to a schema.GroupVersionKind.
|
||||
func toSchemaGvk(x gvk.Gvk) schema.GroupVersionKind {
|
||||
return schema.GroupVersionKind{
|
||||
Group: x.Group,
|
||||
Version: x.Version,
|
||||
Kind: x.Kind,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,14 +24,14 @@ import (
|
||||
var kunstructured = NewKunstructuredFactoryImpl().FromMap(map[string]interface{}{
|
||||
"Kind": "Service",
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": map[string]string{
|
||||
"labels": map[string]interface{}{
|
||||
"app": "application-name",
|
||||
},
|
||||
"name": "service-name",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"ports": map[string]interface{}{
|
||||
"port": "80",
|
||||
"port": int64(80),
|
||||
},
|
||||
},
|
||||
"this": map[string]interface{}{
|
||||
@@ -168,7 +168,7 @@ func TestGetFieldValue(t *testing.T) {
|
||||
{
|
||||
name: "threeFields",
|
||||
pathToField: "spec.ports.port",
|
||||
expectedValue: "80",
|
||||
expectedValue: int64(80),
|
||||
errorExpected: false,
|
||||
},
|
||||
{
|
||||
@@ -249,6 +249,12 @@ func TestGetFieldValue(t *testing.T) {
|
||||
errorMsg: "no field named 'that[99]'",
|
||||
errorExpected: true,
|
||||
},
|
||||
{
|
||||
name: "accessorError",
|
||||
pathToField: "that[downwardapi]",
|
||||
errorMsg: ".that.downwardapi accessor error: [idx0 idx1 idx2 idx3] is of the type []interface {}, expected map[string]interface{}",
|
||||
errorExpected: true,
|
||||
},
|
||||
{
|
||||
name: "unknownSlice",
|
||||
pathToField: "unknown[0]",
|
||||
@@ -298,16 +304,34 @@ func TestGetFieldValue(t *testing.T) {
|
||||
errorMsg: "no field named 'complextree[1].field2[1].invalidsubfield'",
|
||||
},
|
||||
{
|
||||
name: "validStructSubFieldNoneIntIndex",
|
||||
pathToField: "complextree[thisisnotanint]",
|
||||
errorExpected: true,
|
||||
errorMsg: "no field named 'complextree[thisisnotanint]'",
|
||||
name: "validDownwardAPILabels",
|
||||
pathToField: `metadata.labels["app"]`,
|
||||
errorExpected: false,
|
||||
expectedValue: "application-name",
|
||||
},
|
||||
{
|
||||
name: "invalidNoneIntIndex",
|
||||
pathToField: "complextree[thisisnotanint]",
|
||||
name: "validDownwardAPISpecs",
|
||||
pathToField: `spec.ports['port']`,
|
||||
errorExpected: false,
|
||||
expectedValue: int64(80),
|
||||
},
|
||||
{
|
||||
name: "validDownwardAPIThis",
|
||||
pathToField: `this.is[aFloat]`,
|
||||
errorExpected: false,
|
||||
expectedValue: float64(1.001),
|
||||
},
|
||||
{
|
||||
name: "downwardAPIInvalidLabel",
|
||||
pathToField: `metadata.labels["theisnotanint"]`,
|
||||
errorExpected: true,
|
||||
errorMsg: "no field named 'complextree[thisisnotanint]'",
|
||||
errorMsg: `no field named 'metadata.labels["theisnotanint"]'`,
|
||||
},
|
||||
{
|
||||
name: "downwardAPIInvalidLabel2",
|
||||
pathToField: `invalidfield.labels["app"]`,
|
||||
errorExpected: true,
|
||||
errorMsg: `no field named 'invalidfield.labels["app"]'`,
|
||||
},
|
||||
{
|
||||
name: "invalidIndexInIndex",
|
||||
@@ -362,12 +386,6 @@ func TestGetString(t *testing.T) {
|
||||
expectedValue: "service-name",
|
||||
errorExpected: false,
|
||||
},
|
||||
{
|
||||
name: "threeFields",
|
||||
pathToField: "spec.ports.port",
|
||||
expectedValue: "80",
|
||||
errorExpected: false,
|
||||
},
|
||||
{
|
||||
name: "emptyMap",
|
||||
pathToField: "this.is.anEmptyMap",
|
||||
@@ -440,6 +458,12 @@ func TestGetString(t *testing.T) {
|
||||
errorExpected: true,
|
||||
errorMsg: "no field named 'this.is[1].aString'",
|
||||
},
|
||||
{
|
||||
name: "validDownwardAPIField",
|
||||
pathToField: `metadata.labels["app"]`,
|
||||
errorExpected: false,
|
||||
expectedValue: "application-name",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
@@ -487,6 +511,12 @@ func TestGetInt64(t *testing.T) {
|
||||
errorExpected: true,
|
||||
errorMsg: "no field named 'these[1].field2[99]'",
|
||||
},
|
||||
{
|
||||
name: "validDownwardAPISpecs",
|
||||
pathToField: `spec.ports['port']`,
|
||||
errorExpected: false,
|
||||
expectedValue: int64(80),
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
@@ -522,6 +552,12 @@ func TestGetFloat64(t *testing.T) {
|
||||
errorExpected: false,
|
||||
expectedValue: float64(1.1121),
|
||||
},
|
||||
{
|
||||
name: "validDownwardAPIThis",
|
||||
pathToField: `this.is[aFloat]`,
|
||||
errorExpected: false,
|
||||
expectedValue: float64(1.001),
|
||||
},
|
||||
{
|
||||
name: "twoFieldsOneMissing",
|
||||
pathToField: "metadata.banana",
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
package transformer
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/k8sdeps/transformer/patch"
|
||||
"sigs.k8s.io/kustomize/pkg/resource"
|
||||
"sigs.k8s.io/kustomize/pkg/transformers"
|
||||
"sigs.k8s.io/kustomize/v3/k8sdeps/transformer/patch"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resource"
|
||||
)
|
||||
|
||||
// FactoryImpl makes patch transformer and name hash transformer
|
||||
@@ -18,9 +18,8 @@ func NewFactoryImpl() *FactoryImpl {
|
||||
return &FactoryImpl{}
|
||||
}
|
||||
|
||||
// MakePatchTransformer makes a new patch transformer
|
||||
func (p *FactoryImpl) MakePatchTransformer(
|
||||
slice []*resource.Resource,
|
||||
rf *resource.Factory) (transformers.Transformer, error) {
|
||||
return patch.NewTransformer(slice, rf)
|
||||
func (p *FactoryImpl) MergePatches(patches []*resource.Resource,
|
||||
rf *resource.Factory) (
|
||||
resmap.ResMap, error) {
|
||||
return patch.MergePatches(patches, rf)
|
||||
}
|
||||
|
||||
@@ -5,12 +5,17 @@ package patch
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/gvk"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
|
||||
"github.com/evanphx/json-patch"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/mergepatch"
|
||||
"k8s.io/apimachinery/pkg/util/strategicpatch"
|
||||
"sigs.k8s.io/kustomize/pkg/resource"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resource"
|
||||
)
|
||||
|
||||
type conflictDetector interface {
|
||||
@@ -40,7 +45,7 @@ func (jmp *jsonMergePatch) findConflict(
|
||||
if i == conflictingPatchIdx {
|
||||
continue
|
||||
}
|
||||
if !patches[conflictingPatchIdx].OrgId().GvknEquals(patch.OrgId()) {
|
||||
if !patches[conflictingPatchIdx].OrgId().Equals(patch.OrgId()) {
|
||||
continue
|
||||
}
|
||||
conflict, err := mergepatch.HasConflicts(
|
||||
@@ -100,7 +105,7 @@ func (smp *strategicMergePatch) findConflict(
|
||||
if i == conflictingPatchIdx {
|
||||
continue
|
||||
}
|
||||
if !patches[conflictingPatchIdx].OrgId().GvknEquals(patch.OrgId()) {
|
||||
if !patches[conflictingPatchIdx].OrgId().Equals(patch.OrgId()) {
|
||||
continue
|
||||
}
|
||||
conflict, err := strategicpatch.MergingMapsHaveConflicts(
|
||||
@@ -122,3 +127,64 @@ func (smp *strategicMergePatch) mergePatches(patch1, patch2 *resource.Resource)
|
||||
smp.lookupPatchMeta, patch1.Map(), patch2.Map())
|
||||
return smp.rf.FromMap(mergeJSONMap), err
|
||||
}
|
||||
|
||||
// mergePatches merge and index patches by OrgId.
|
||||
// It errors out if there is conflict between patches.
|
||||
func MergePatches(patches []*resource.Resource,
|
||||
rf *resource.Factory) (resmap.ResMap, error) {
|
||||
rc := resmap.New()
|
||||
for ix, patch := range patches {
|
||||
id := patch.OrgId()
|
||||
existing := rc.GetMatchingResourcesByOriginalId(id.Equals)
|
||||
if len(existing) == 0 {
|
||||
rc.Append(patch)
|
||||
continue
|
||||
}
|
||||
if len(existing) > 1 {
|
||||
return nil, fmt.Errorf("self conflict in patches")
|
||||
}
|
||||
|
||||
versionedObj, err := scheme.Scheme.New(toSchemaGvk(id.Gvk))
|
||||
if err != nil && !runtime.IsNotRegisteredError(err) {
|
||||
return nil, err
|
||||
}
|
||||
var cd conflictDetector
|
||||
if err != nil {
|
||||
cd = newJMPConflictDetector(rf)
|
||||
} else {
|
||||
cd, err = newSMPConflictDetector(versionedObj, rf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
conflict, err := cd.hasConflict(existing[0], patch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if conflict {
|
||||
conflictingPatch, err := cd.findConflict(ix, patches)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, fmt.Errorf(
|
||||
"conflict between %#v and %#v",
|
||||
conflictingPatch.Map(), patch.Map())
|
||||
}
|
||||
merged, err := cd.mergePatches(existing[0], patch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rc.Replace(merged)
|
||||
}
|
||||
return rc, nil
|
||||
}
|
||||
|
||||
// toSchemaGvk converts to a schema.GroupVersionKind.
|
||||
func toSchemaGvk(x gvk.Gvk) schema.GroupVersionKind {
|
||||
return schema.GroupVersionKind{
|
||||
Group: x.Group,
|
||||
Version: x.Version,
|
||||
Kind: x.Kind,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,168 +0,0 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package patch
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/evanphx/json-patch"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/util/strategicpatch"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
"sigs.k8s.io/kustomize/pkg/gvk"
|
||||
"sigs.k8s.io/kustomize/pkg/resid"
|
||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/pkg/resource"
|
||||
"sigs.k8s.io/kustomize/pkg/transformers"
|
||||
)
|
||||
|
||||
// transformer applies strategic merge patches.
|
||||
type transformer struct {
|
||||
patches []*resource.Resource
|
||||
rf *resource.Factory
|
||||
}
|
||||
|
||||
var _ transformers.Transformer = &transformer{}
|
||||
|
||||
// NewTransformer constructs a strategic merge patch transformer.
|
||||
func NewTransformer(
|
||||
slice []*resource.Resource, rf *resource.Factory) (transformers.Transformer, error) {
|
||||
if len(slice) == 0 {
|
||||
return transformers.NewNoOpTransformer(), nil
|
||||
}
|
||||
return &transformer{patches: slice, rf: rf}, nil
|
||||
}
|
||||
|
||||
// Transform apply the patches on top of the base resources.
|
||||
// nolint:ineffassign
|
||||
func (tf *transformer) Transform(m resmap.ResMap) error {
|
||||
patches, err := tf.mergePatches()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, patch := range patches.Resources() {
|
||||
target, err := tf.findPatchTarget(m, patch.OrgId())
|
||||
merged := map[string]interface{}{}
|
||||
versionedObj, err := scheme.Scheme.New(
|
||||
toSchemaGvk(patch.OrgId().Gvk))
|
||||
saveName := target.GetName()
|
||||
switch {
|
||||
case runtime.IsNotRegisteredError(err):
|
||||
// Use JSON merge patch to handle types w/o schema
|
||||
baseBytes, err := json.Marshal(target.Map())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
patchBytes, err := json.Marshal(patch.Map())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mergedBytes, err := jsonpatch.MergePatch(baseBytes, patchBytes)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = json.Unmarshal(mergedBytes, &merged)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case err != nil:
|
||||
return err
|
||||
default:
|
||||
// Use Strategic-Merge-Patch to handle types w/ schema
|
||||
// TODO: Change this to use the new Merge package.
|
||||
// Store the name of the target object, because this name may have been munged.
|
||||
// Apply this name to the patched object.
|
||||
lookupPatchMeta, err := strategicpatch.NewPatchMetaFromStruct(versionedObj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
merged, err = strategicpatch.StrategicMergeMapPatchUsingLookupPatchMeta(
|
||||
target.Map(),
|
||||
patch.Map(),
|
||||
lookupPatchMeta)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
target.SetMap(merged)
|
||||
target.SetName(saveName)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tf *transformer) findPatchTarget(
|
||||
m resmap.ResMap, id resid.ResId) (*resource.Resource, error) {
|
||||
match, err := m.GetByOriginalId(id)
|
||||
if err == nil {
|
||||
return match, nil
|
||||
}
|
||||
match, err = m.GetByCurrentId(id)
|
||||
if err == nil {
|
||||
return match, nil
|
||||
}
|
||||
return nil, fmt.Errorf(
|
||||
"failed to find target for patch %s", id.GvknString())
|
||||
}
|
||||
|
||||
// mergePatches merge and index patches by OrgId.
|
||||
// It errors out if there is conflict between patches.
|
||||
func (tf *transformer) mergePatches() (resmap.ResMap, error) {
|
||||
rc := resmap.New()
|
||||
for ix, patch := range tf.patches {
|
||||
id := patch.OrgId()
|
||||
existing := rc.GetMatchingResourcesByOriginalId(id.GvknEquals)
|
||||
if len(existing) == 0 {
|
||||
rc.Append(patch)
|
||||
continue
|
||||
}
|
||||
if len(existing) > 1 {
|
||||
return nil, fmt.Errorf("self conflict in patches")
|
||||
}
|
||||
|
||||
versionedObj, err := scheme.Scheme.New(toSchemaGvk(id.Gvk))
|
||||
if err != nil && !runtime.IsNotRegisteredError(err) {
|
||||
return nil, err
|
||||
}
|
||||
var cd conflictDetector
|
||||
if err != nil {
|
||||
cd = newJMPConflictDetector(tf.rf)
|
||||
} else {
|
||||
cd, err = newSMPConflictDetector(versionedObj, tf.rf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
conflict, err := cd.hasConflict(existing[0], patch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if conflict {
|
||||
conflictingPatch, err := cd.findConflict(ix, tf.patches)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, fmt.Errorf(
|
||||
"conflict between %#v and %#v",
|
||||
conflictingPatch.Map(), patch.Map())
|
||||
}
|
||||
merged, err := cd.mergePatches(existing[0], patch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rc.Replace(merged)
|
||||
}
|
||||
return rc, nil
|
||||
}
|
||||
|
||||
// toSchemaGvk converts to a schema.GroupVersionKind.
|
||||
func toSchemaGvk(x gvk.Gvk) schema.GroupVersionKind {
|
||||
return schema.GroupVersionKind{
|
||||
Group: x.Group,
|
||||
Version: x.Version,
|
||||
Kind: x.Kind,
|
||||
}
|
||||
}
|
||||
@@ -1,520 +0,0 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package patch
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
|
||||
"sigs.k8s.io/kustomize/pkg/resmaptest"
|
||||
"sigs.k8s.io/kustomize/pkg/resource"
|
||||
)
|
||||
|
||||
var rf = resource.NewFactory(
|
||||
kunstruct.NewKunstructuredFactoryImpl())
|
||||
|
||||
func TestOverlayRun(t *testing.T) {
|
||||
base := resmaptest_test.NewRmBuilder(t, rf).
|
||||
Add(map[string]interface{}{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "deploy1",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"template": map[string]interface{}{
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": map[string]interface{}{
|
||||
"old-label": "old-value",
|
||||
},
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"containers": []interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "nginx",
|
||||
"image": "nginx",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}).ResMap()
|
||||
patch := []*resource.Resource{
|
||||
rf.FromMap(map[string]interface{}{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "deploy1",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"template": map[string]interface{}{
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": map[string]interface{}{
|
||||
"another-label": "foo",
|
||||
},
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"containers": []interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "nginx",
|
||||
"image": "nginx:latest",
|
||||
"env": []interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "SOMEENV",
|
||||
"value": "BAR",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
}
|
||||
expected := resmaptest_test.NewRmBuilder(t, rf).
|
||||
Add(map[string]interface{}{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "deploy1",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"template": map[string]interface{}{
|
||||
"metadata": map[string]interface{}{
|
||||
"labels": map[string]interface{}{
|
||||
"old-label": "old-value",
|
||||
"another-label": "foo",
|
||||
},
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"containers": []interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "nginx",
|
||||
"image": "nginx:latest",
|
||||
"env": []interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "SOMEENV",
|
||||
"value": "BAR",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}).ResMap()
|
||||
lt, err := NewTransformer(patch, rf)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
err = lt.Transform(base)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(base, expected) {
|
||||
err = expected.ErrorIfNotEqualLists(base)
|
||||
t.Fatalf("actual doesn't match expected: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultiplePatches(t *testing.T) {
|
||||
base := resmaptest_test.NewRmBuilder(t, rf).
|
||||
Add(map[string]interface{}{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "deploy1",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"template": map[string]interface{}{
|
||||
"spec": map[string]interface{}{
|
||||
"containers": []interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "nginx",
|
||||
"image": "nginx",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}).ResMap()
|
||||
patch := []*resource.Resource{
|
||||
rf.FromMap(map[string]interface{}{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "deploy1",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"template": map[string]interface{}{
|
||||
"spec": map[string]interface{}{
|
||||
"containers": []interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "nginx",
|
||||
"image": "nginx:latest",
|
||||
"env": []interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "SOMEENV",
|
||||
"value": "BAR",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
rf.FromMap(map[string]interface{}{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "deploy1",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"template": map[string]interface{}{
|
||||
"spec": map[string]interface{}{
|
||||
"containers": []interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "nginx",
|
||||
"env": []interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "ANOTHERENV",
|
||||
"value": "HELLO",
|
||||
},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{
|
||||
"name": "busybox",
|
||||
"image": "busybox",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
}
|
||||
expected := resmaptest_test.NewRmBuilder(t, rf).
|
||||
Add(map[string]interface{}{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "deploy1",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"template": map[string]interface{}{
|
||||
"spec": map[string]interface{}{
|
||||
"containers": []interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "nginx",
|
||||
"image": "nginx:latest",
|
||||
"env": []interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "ANOTHERENV",
|
||||
"value": "HELLO",
|
||||
},
|
||||
map[string]interface{}{
|
||||
"name": "SOMEENV",
|
||||
"value": "BAR",
|
||||
},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{
|
||||
"name": "busybox",
|
||||
"image": "busybox",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}).ResMap()
|
||||
lt, err := NewTransformer(patch, rf)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
err = lt.Transform(base)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(base, expected) {
|
||||
err = expected.ErrorIfNotEqualLists(base)
|
||||
t.Fatalf("actual doesn't match expected: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultiplePatchesWithConflict(t *testing.T) {
|
||||
base := resmaptest_test.NewRmBuilder(t, rf).
|
||||
Add(map[string]interface{}{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "deploy1",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"template": map[string]interface{}{
|
||||
"spec": map[string]interface{}{
|
||||
"containers": []interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "nginx",
|
||||
"image": "nginx",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}).ResMap()
|
||||
|
||||
patch := []*resource.Resource{
|
||||
rf.FromMap(map[string]interface{}{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "deploy1",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"template": map[string]interface{}{
|
||||
"spec": map[string]interface{}{
|
||||
"containers": []interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "nginx",
|
||||
"image": "nginx:latest",
|
||||
"env": []interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "SOMEENV",
|
||||
"value": "BAR",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
rf.FromMap(map[string]interface{}{
|
||||
"apiVersion": "apps/v1",
|
||||
"kind": "Deployment",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "deploy1",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"template": map[string]interface{}{
|
||||
"spec": map[string]interface{}{
|
||||
"containers": []interface{}{
|
||||
map[string]interface{}{
|
||||
"name": "nginx",
|
||||
"image": "nginx:1.7.9",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
lt, err := NewTransformer(patch, rf)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
err = lt.Transform(base)
|
||||
if err == nil {
|
||||
t.Fatalf("did not get expected error")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "conflict") {
|
||||
t.Fatalf("expected error to contain %q but get %v", "conflict", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNoSchemaOverlayRun(t *testing.T) {
|
||||
base := resmaptest_test.NewRmBuilder(t, rf).
|
||||
Add(map[string]interface{}{
|
||||
"apiVersion": "example.com/v1",
|
||||
"kind": "Foo",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "my-foo",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"bar": map[string]interface{}{
|
||||
"A": "X",
|
||||
"B": "Y",
|
||||
},
|
||||
},
|
||||
}).ResMap()
|
||||
patch := []*resource.Resource{
|
||||
rf.FromMap(map[string]interface{}{
|
||||
"apiVersion": "example.com/v1",
|
||||
"kind": "Foo",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "my-foo",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"bar": map[string]interface{}{
|
||||
"B": nil,
|
||||
"C": "Z",
|
||||
},
|
||||
},
|
||||
}),
|
||||
}
|
||||
expected := resmaptest_test.NewRmBuilder(t, rf).
|
||||
Add(
|
||||
map[string]interface{}{
|
||||
"apiVersion": "example.com/v1",
|
||||
"kind": "Foo",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "my-foo",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"bar": map[string]interface{}{
|
||||
"A": "X",
|
||||
"C": "Z",
|
||||
},
|
||||
},
|
||||
}).ResMap()
|
||||
|
||||
lt, err := NewTransformer(patch, rf)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
err = lt.Transform(base)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if err = expected.ErrorIfNotEqualLists(base); err != nil {
|
||||
t.Fatalf("actual doesn't match expected: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNoSchemaMultiplePatches(t *testing.T) {
|
||||
base := resmaptest_test.NewRmBuilder(t, rf).
|
||||
Add(map[string]interface{}{
|
||||
"apiVersion": "example.com/v1",
|
||||
"kind": "Foo",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "my-foo",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"bar": map[string]interface{}{
|
||||
"A": "X",
|
||||
"B": "Y",
|
||||
},
|
||||
},
|
||||
}).ResMap()
|
||||
patch := []*resource.Resource{
|
||||
rf.FromMap(map[string]interface{}{
|
||||
"apiVersion": "example.com/v1",
|
||||
"kind": "Foo",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "my-foo",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"bar": map[string]interface{}{
|
||||
"B": nil,
|
||||
"C": "Z",
|
||||
},
|
||||
},
|
||||
}),
|
||||
rf.FromMap(map[string]interface{}{
|
||||
"apiVersion": "example.com/v1",
|
||||
"kind": "Foo",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "my-foo",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"bar": map[string]interface{}{
|
||||
"C": "Z",
|
||||
"D": "W",
|
||||
},
|
||||
"baz": map[string]interface{}{
|
||||
"hello": "world",
|
||||
},
|
||||
},
|
||||
}),
|
||||
}
|
||||
expected := resmaptest_test.NewRmBuilder(t, rf).
|
||||
Add(map[string]interface{}{
|
||||
"apiVersion": "example.com/v1",
|
||||
"kind": "Foo",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "my-foo",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"bar": map[string]interface{}{
|
||||
"A": "X",
|
||||
"C": "Z",
|
||||
"D": "W",
|
||||
},
|
||||
"baz": map[string]interface{}{
|
||||
"hello": "world",
|
||||
},
|
||||
},
|
||||
}).ResMap()
|
||||
|
||||
lt, err := NewTransformer(patch, rf)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
err = lt.Transform(base)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if err = expected.ErrorIfNotEqualLists(base); err != nil {
|
||||
t.Fatalf("actual doesn't match expected: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNoSchemaMultiplePatchesWithConflict(t *testing.T) {
|
||||
base := resmaptest_test.NewRmBuilder(t, rf).
|
||||
Add(map[string]interface{}{
|
||||
"apiVersion": "example.com/v1",
|
||||
"kind": "Foo",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "my-foo",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"bar": map[string]interface{}{
|
||||
"A": "X",
|
||||
"B": "Y",
|
||||
},
|
||||
},
|
||||
}).ResMap()
|
||||
patch := []*resource.Resource{
|
||||
rf.FromMap(map[string]interface{}{
|
||||
"apiVersion": "example.com/v1",
|
||||
"kind": "Foo",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "my-foo",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"bar": map[string]interface{}{
|
||||
"B": nil,
|
||||
"C": "Z",
|
||||
},
|
||||
},
|
||||
}),
|
||||
rf.FromMap(map[string]interface{}{
|
||||
"apiVersion": "example.com/v1",
|
||||
"kind": "Foo",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "my-foo",
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"bar": map[string]interface{}{
|
||||
"C": "NOT_Z",
|
||||
},
|
||||
},
|
||||
}),
|
||||
}
|
||||
|
||||
lt, err := NewTransformer(patch, rf)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
err = lt.Transform(base)
|
||||
if err == nil {
|
||||
t.Fatalf("did not get expected error")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "conflict") {
|
||||
t.Fatalf("expected error to contain %q but get %v", "conflict", err)
|
||||
}
|
||||
}
|
||||
@@ -53,6 +53,23 @@ func (v *KustValidator) MakeAnnotationValidator() func(map[string]string) error
|
||||
}
|
||||
}
|
||||
|
||||
// MakeAnnotationNameValidator returns a MapValidatorFunc using apimachinery.
|
||||
func (v *KustValidator) MakeAnnotationNameValidator() func([]string) error {
|
||||
return func(x []string) error {
|
||||
errs := field.ErrorList{}
|
||||
fldPath := field.NewPath("field")
|
||||
for _, k := range x {
|
||||
for _, msg := range validation.IsQualifiedName(strings.ToLower(k)) {
|
||||
errs = append(errs, field.Invalid(fldPath, k, msg))
|
||||
}
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
return errors.New(errs.ToAggregate().Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// MakeLabelValidator returns a MapValidatorFunc using apimachinery.
|
||||
func (v *KustValidator) MakeLabelValidator() func(map[string]string) error {
|
||||
return func(x map[string]string) error {
|
||||
@@ -64,6 +81,21 @@ func (v *KustValidator) MakeLabelValidator() func(map[string]string) error {
|
||||
}
|
||||
}
|
||||
|
||||
// MakeLabelNameValidator returns a ArrayValidatorFunc using apimachinery.
|
||||
func (v *KustValidator) MakeLabelNameValidator() func([]string) error {
|
||||
return func(x []string) error {
|
||||
errs := field.ErrorList{}
|
||||
fldPath := field.NewPath("field")
|
||||
for _, k := range x {
|
||||
errs = append(errs, v1validation.ValidateLabelName(k, fldPath)...)
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
return errors.New(errs.ToAggregate().Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ValidateNamespace validates a string is a valid namespace using apimachinery.
|
||||
func (v *KustValidator) ValidateNamespace(s string) []string {
|
||||
return validation.IsDNS1123Label(s)
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/resid"
|
||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/pkg/transformers"
|
||||
"sigs.k8s.io/kustomize/pkg/transformers/config"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resid"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/types"
|
||||
)
|
||||
|
||||
// ResAccumulator accumulates resources and the rules
|
||||
@@ -28,7 +28,7 @@ func MakeEmptyAccumulator() *ResAccumulator {
|
||||
ra := &ResAccumulator{}
|
||||
ra.resMap = resmap.New()
|
||||
ra.tConfig = &config.TransformerConfig{}
|
||||
ra.varSet = types.VarSet{}
|
||||
ra.varSet = types.NewVarSet()
|
||||
return ra
|
||||
}
|
||||
|
||||
@@ -64,8 +64,14 @@ func (ra *ResAccumulator) GetTransformerConfig() *config.TransformerConfig {
|
||||
|
||||
func (ra *ResAccumulator) MergeVars(incoming []types.Var) error {
|
||||
for _, v := range incoming {
|
||||
matched := ra.resMap.GetMatchingResourcesByOriginalId(
|
||||
resid.NewResId(v.ObjRef.GVK(), v.ObjRef.Name).GvknEquals)
|
||||
targetId := resid.NewResIdWithNamespace(v.ObjRef.GVK(), v.ObjRef.Name, v.ObjRef.Namespace)
|
||||
idMatcher := targetId.GvknEquals
|
||||
if targetId.Namespace != "" || !targetId.IsNamespaceableKind() {
|
||||
// Preserve backward compatibility. An empty namespace means
|
||||
// wildcard search on the namespace hence we still use GvknEquals
|
||||
idMatcher = targetId.Equals
|
||||
}
|
||||
matched := ra.resMap.GetMatchingResourcesByOriginalId(idMatcher)
|
||||
if len(matched) > 1 {
|
||||
return fmt.Errorf(
|
||||
"found %d resId matches for var %s "+
|
||||
|
||||
@@ -10,14 +10,14 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
|
||||
. "sigs.k8s.io/kustomize/pkg/accumulator"
|
||||
"sigs.k8s.io/kustomize/pkg/gvk"
|
||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/pkg/resmaptest"
|
||||
"sigs.k8s.io/kustomize/pkg/resource"
|
||||
"sigs.k8s.io/kustomize/pkg/transformers/config"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
"sigs.k8s.io/kustomize/v3/k8sdeps/kunstruct"
|
||||
. "sigs.k8s.io/kustomize/v3/pkg/accumulator"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/gvk"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmaptest"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resource"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/types"
|
||||
)
|
||||
|
||||
func makeResAccumulator(t *testing.T) (*ResAccumulator, *resource.Factory) {
|
||||
|
||||
@@ -4,22 +4,21 @@
|
||||
package build
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc/transformer"
|
||||
"sigs.k8s.io/kustomize/pkg/loader"
|
||||
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/pkg/plugins"
|
||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/pkg/target"
|
||||
"sigs.k8s.io/kustomize/plugin/builtin"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/loader"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/plugins"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resource"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/target"
|
||||
"sigs.k8s.io/kustomize/v3/plugin/builtin"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
@@ -61,7 +60,7 @@ https://github.com/hashicorp/go-getter#url-format
|
||||
func NewCmdBuild(
|
||||
out io.Writer, fSys fs.FileSystem,
|
||||
v ifc.Validator, rf *resmap.Factory,
|
||||
ptf transformer.Factory) *cobra.Command {
|
||||
ptf resmap.PatchFactory) *cobra.Command {
|
||||
var o Options
|
||||
|
||||
pluginConfig := plugins.DefaultPluginConfig()
|
||||
@@ -115,7 +114,7 @@ func (o *Options) Validate(args []string) (err error) {
|
||||
// RunBuild runs build command.
|
||||
func (o *Options) RunBuild(
|
||||
out io.Writer, v ifc.Validator, fSys fs.FileSystem,
|
||||
rf *resmap.Factory, ptf transformer.Factory,
|
||||
rf *resmap.Factory, ptf resmap.PatchFactory,
|
||||
pl *plugins.Loader) error {
|
||||
ldr, err := loader.NewLoader(
|
||||
o.loadRestrictor, v, o.kustomizationPath, fSys)
|
||||
@@ -136,7 +135,7 @@ func (o *Options) RunBuild(
|
||||
|
||||
func (o *Options) RunBuildPrune(
|
||||
out io.Writer, v ifc.Validator, fSys fs.FileSystem,
|
||||
rf *resmap.Factory, ptf transformer.Factory,
|
||||
rf *resmap.Factory, ptf resmap.PatchFactory,
|
||||
pl *plugins.Loader) error {
|
||||
ldr, err := loader.NewLoader(
|
||||
o.loadRestrictor, v, o.kustomizationPath, fSys)
|
||||
@@ -180,7 +179,7 @@ func (o *Options) emitResources(
|
||||
|
||||
func NewCmdBuildPrune(
|
||||
out io.Writer, v ifc.Validator, fSys fs.FileSystem,
|
||||
rf *resmap.Factory, ptf transformer.Factory,
|
||||
rf *resmap.Factory, ptf resmap.PatchFactory,
|
||||
pl *plugins.Loader) *cobra.Command {
|
||||
var o Options
|
||||
|
||||
@@ -202,23 +201,38 @@ func NewCmdBuildPrune(
|
||||
|
||||
func writeIndividualFiles(
|
||||
fSys fs.FileSystem, folderPath string, m resmap.ResMap) error {
|
||||
for _, res := range m.Resources() {
|
||||
filename := filepath.Join(
|
||||
folderPath,
|
||||
fmt.Sprintf(
|
||||
"%s_%s.yaml",
|
||||
strings.ToLower(res.GetGvk().String()),
|
||||
strings.ToLower(res.GetName()),
|
||||
),
|
||||
)
|
||||
out, err := yaml.Marshal(res.Map())
|
||||
if err != nil {
|
||||
return err
|
||||
byNamespace := m.GroupedByCurrentNamespace()
|
||||
for namespace, resList := range byNamespace {
|
||||
for _, res := range resList {
|
||||
fName := fileName(res)
|
||||
if len(byNamespace) > 1 {
|
||||
fName = strings.ToLower(namespace) + "_" + fName
|
||||
}
|
||||
err := writeFile(fSys, folderPath, fName, res)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
err = fSys.WriteFile(filename, out)
|
||||
}
|
||||
for _, res := range m.NonNamespaceable() {
|
||||
err := writeFile(fSys, folderPath, fileName(res), res)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func fileName(res *resource.Resource) string {
|
||||
return strings.ToLower(res.GetGvk().String()) +
|
||||
"_" + strings.ToLower(res.GetName()) + ".yaml"
|
||||
}
|
||||
|
||||
func writeFile(
|
||||
fSys fs.FileSystem, path, fName string, res *resource.Resource) error {
|
||||
out, err := yaml.Marshal(res.Map())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return fSys.WriteFile(filepath.Join(path, fName), out)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package build
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/pgmconfig"
|
||||
)
|
||||
|
||||
func TestNewOptionsToSilenceCodeInspectionError(t *testing.T) {
|
||||
|
||||
@@ -9,16 +9,16 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
|
||||
"sigs.k8s.io/kustomize/k8sdeps/transformer"
|
||||
"sigs.k8s.io/kustomize/k8sdeps/validator"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/build"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/edit"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/misc"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/pkg/resource"
|
||||
"sigs.k8s.io/kustomize/v3/k8sdeps/kunstruct"
|
||||
"sigs.k8s.io/kustomize/v3/k8sdeps/transformer"
|
||||
"sigs.k8s.io/kustomize/v3/k8sdeps/validator"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/build"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/edit"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/misc"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/resource"
|
||||
)
|
||||
|
||||
// NewDefaultCommand returns the default (aka root) command for kustomize command.
|
||||
@@ -36,12 +36,13 @@ See https://sigs.k8s.io/kustomize
|
||||
}
|
||||
|
||||
uf := kunstruct.NewKunstructuredFactoryImpl()
|
||||
rf := resmap.NewFactory(resource.NewFactory(uf))
|
||||
pf := transformer.NewFactoryImpl()
|
||||
rf := resmap.NewFactory(resource.NewFactory(uf), pf)
|
||||
v := validator.NewKustValidator()
|
||||
c.AddCommand(
|
||||
build.NewCmdBuild(
|
||||
stdOut, fSys, v,
|
||||
rf, transformer.NewFactoryImpl()),
|
||||
rf, pf),
|
||||
edit.NewCmdEdit(fSys, v, uf),
|
||||
misc.NewCmdConfig(fSys),
|
||||
misc.NewCmdVersion(stdOut),
|
||||
|
||||
@@ -22,8 +22,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
)
|
||||
|
||||
type addBaseOptions struct {
|
||||
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -21,10 +21,10 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/types"
|
||||
)
|
||||
|
||||
// kindOfAdd is the kind of metadata being added: label or annotation
|
||||
|
||||
@@ -20,10 +20,10 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
"sigs.k8s.io/kustomize/pkg/validators"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/validators"
|
||||
)
|
||||
|
||||
func makeKustomization(t *testing.T) *types.Kustomization {
|
||||
|
||||
@@ -21,9 +21,10 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/patch"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/edit/util"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/patch"
|
||||
)
|
||||
|
||||
type addPatchOptions struct {
|
||||
@@ -70,7 +71,7 @@ func (o *addPatchOptions) Complete(cmd *cobra.Command, args []string) error {
|
||||
|
||||
// RunAddPatch runs addPatch command (do real work).
|
||||
func (o *addPatchOptions) RunAddPatch(fSys fs.FileSystem) error {
|
||||
patches, err := globPatterns(fSys, o.patchFilePaths)
|
||||
patches, err := util.GlobPatterns(fSys, o.patchFilePaths)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -21,8 +21,9 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/edit/util"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
)
|
||||
|
||||
type addResourceOptions struct {
|
||||
@@ -69,7 +70,7 @@ func (o *addResourceOptions) Complete(cmd *cobra.Command, args []string) error {
|
||||
|
||||
// RunAddResource runs addResource command (do real work).
|
||||
func (o *addResourceOptions) RunAddResource(fSys fs.FileSystem) error {
|
||||
resources, err := globPatterns(fSys, o.resourceFilePaths)
|
||||
resources, err := util.GlobPatterns(fSys, o.resourceFilePaths)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -5,8 +5,8 @@ package add
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/ifc"
|
||||
)
|
||||
|
||||
// NewCmdAdd returns an instance of 'add' subcommand.
|
||||
|
||||
@@ -5,10 +5,10 @@ package add
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/types"
|
||||
)
|
||||
|
||||
// newCmdAddConfigMap returns a new command.
|
||||
|
||||
@@ -6,10 +6,10 @@ package add
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/loader"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
"sigs.k8s.io/kustomize/pkg/validators"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/loader"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/validators"
|
||||
)
|
||||
|
||||
func TestNewAddConfigMapIsNotNil(t *testing.T) {
|
||||
|
||||
@@ -20,7 +20,8 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/edit/util"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
)
|
||||
|
||||
// flagsAndArgs encapsulates the options for add secret/configmap commands.
|
||||
@@ -85,7 +86,7 @@ func (a *flagsAndArgs) ExpandFileSource(fSys fs.FileSystem) error {
|
||||
} else {
|
||||
patterns = append(patterns, s[0])
|
||||
}
|
||||
result, err := globPatterns(fSys, patterns)
|
||||
result, err := util.GlobPatterns(fSys, patterns)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
)
|
||||
|
||||
func TestDataValidation_NoName(t *testing.T) {
|
||||
|
||||
@@ -5,10 +5,10 @@ package add
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/types"
|
||||
)
|
||||
|
||||
// newCmdAddSecret returns a new command.
|
||||
|
||||
@@ -6,10 +6,10 @@ package add
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/loader"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
"sigs.k8s.io/kustomize/pkg/validators"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/loader"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/validators"
|
||||
)
|
||||
|
||||
func TestNewCmdAddSecretIsNotNil(t *testing.T) {
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package add
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
)
|
||||
|
||||
func globPatterns(fsys fs.FileSystem, patterns []string) ([]string, error) {
|
||||
var result []string
|
||||
for _, pattern := range patterns {
|
||||
files, err := fsys.Glob(pattern)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(files) == 0 {
|
||||
log.Printf("%s has no match", pattern)
|
||||
continue
|
||||
}
|
||||
result = append(result, files...)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
@@ -5,13 +5,13 @@ package edit
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/edit/add"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/edit/fix"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/edit/remove"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/edit/set"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/pkg/loader"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/edit/add"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/edit/fix"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/edit/remove"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/edit/set"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/loader"
|
||||
)
|
||||
|
||||
// NewCmdEdit returns an instance of 'edit' subcommand.
|
||||
@@ -38,7 +38,7 @@ func NewCmdEdit(
|
||||
add.NewCmdAdd(fSys, loader.NewFileLoaderAtCwd(v, fSys), kf),
|
||||
set.NewCmdSet(fSys, v),
|
||||
fix.NewCmdFix(fSys),
|
||||
remove.NewCmdRemove(fSys),
|
||||
remove.NewCmdRemove(fSys, loader.NewFileLoaderAtCwd(v, fSys)),
|
||||
)
|
||||
return c
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ package fix
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
)
|
||||
|
||||
// NewCmdFix returns an instance of 'fix' subcommand.
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
)
|
||||
|
||||
func TestFix(t *testing.T) {
|
||||
|
||||
@@ -18,11 +18,14 @@ package remove
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/ifc"
|
||||
)
|
||||
|
||||
// NewCmdRemove returns an instance of 'remove' subcommand.
|
||||
func NewCmdRemove(fsys fs.FileSystem) *cobra.Command {
|
||||
func NewCmdRemove(
|
||||
fsys fs.FileSystem,
|
||||
ldr ifc.Loader) *cobra.Command {
|
||||
c := &cobra.Command{
|
||||
Use: "remove",
|
||||
Short: "Removes items from the kustomization file.",
|
||||
@@ -31,11 +34,23 @@ func NewCmdRemove(fsys fs.FileSystem) *cobra.Command {
|
||||
# Removes resources from the kustomization file
|
||||
kustomize edit remove resource {filepath} {filepath}
|
||||
kustomize edit remove resource {pattern}
|
||||
|
||||
# Removes one or more patches from the kustomization file
|
||||
kustomize edit remove patch <filepath>
|
||||
|
||||
# Removes one or more commonLabels from the kustomization file
|
||||
kustomize edit remove label {labelKey1},{labelKey2}
|
||||
|
||||
# Removes one or more commonAnnotations from the kustomization file
|
||||
kustomize edit remove annotation {annotationKey1},{annotationKey2}
|
||||
`,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
}
|
||||
c.AddCommand(
|
||||
newCmdRemoveResource(fsys),
|
||||
newCmdRemoveLabel(fsys, ldr.Validator().MakeLabelNameValidator()),
|
||||
newCmdRemoveAnnotation(fsys, ldr.Validator().MakeAnnotationNameValidator()),
|
||||
newCmdRemovePatch(fsys),
|
||||
)
|
||||
return c
|
||||
}
|
||||
|
||||
174
pkg/commands/edit/remove/removemetadata.go
Normal file
174
pkg/commands/edit/remove/removemetadata.go
Normal file
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package remove
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/types"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// kindOfAdd is the kind of metadata being added: label or annotation
|
||||
type kindOfAdd int
|
||||
|
||||
const (
|
||||
annotation kindOfAdd = iota
|
||||
label
|
||||
)
|
||||
|
||||
func (k kindOfAdd) String() string {
|
||||
kinds := [...]string{
|
||||
"annotation",
|
||||
"label",
|
||||
}
|
||||
if k < 0 || k > 1 {
|
||||
return "Unknown metadatakind"
|
||||
}
|
||||
return kinds[k]
|
||||
}
|
||||
|
||||
type removeMetadataOptions struct {
|
||||
ignore bool
|
||||
metadata []string
|
||||
arrayValidator func([]string) error
|
||||
kind kindOfAdd
|
||||
}
|
||||
|
||||
// newCmdRemoveLabel removes one or more commonAnnotations from the kustomization file.
|
||||
func newCmdRemoveAnnotation(fSys fs.FileSystem, v func([]string) error) *cobra.Command {
|
||||
var o removeMetadataOptions
|
||||
o.kind = label
|
||||
o.arrayValidator = v
|
||||
cmd := &cobra.Command{
|
||||
Use: "annotation",
|
||||
Short: "Removes one or more commonAnnotations from " + pgmconfig.KustomizationFileNames[0],
|
||||
Example: `
|
||||
remove annotation {annotationKey1},{annotationKey2}`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return o.runE(args, fSys, o.removeAnnotations)
|
||||
},
|
||||
}
|
||||
cmd.Flags().BoolVarP(&o.ignore, "ignore-non-existence", "i", false,
|
||||
"ignore error if the given label doesn't exist",
|
||||
)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// newCmdRemoveLabel removes one or more commonLabels from the kustomization file.
|
||||
func newCmdRemoveLabel(fSys fs.FileSystem, v func([]string) error) *cobra.Command {
|
||||
var o removeMetadataOptions
|
||||
o.kind = label
|
||||
o.arrayValidator = v
|
||||
cmd := &cobra.Command{
|
||||
Use: "label",
|
||||
Short: "Removes one or more commonLabels from " + pgmconfig.KustomizationFileNames[0],
|
||||
Example: `
|
||||
remove label {labelKey1},{labelKey2}`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return o.runE(args, fSys, o.removeLabels)
|
||||
},
|
||||
}
|
||||
cmd.Flags().BoolVarP(&o.ignore, "ignore-non-existence", "i", false,
|
||||
"ignore error if the given label doesn't exist",
|
||||
)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (o *removeMetadataOptions) runE(
|
||||
args []string, fSys fs.FileSystem, remover func(*types.Kustomization) error) error {
|
||||
err := o.validateAndParse(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
kf, err := kustfile.NewKustomizationFile(fSys)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m, err := kf.Read()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = remover(m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return kf.Write(m)
|
||||
}
|
||||
|
||||
// validateAndParse validates `remove` commands and parses them into o.metadata
|
||||
func (o *removeMetadataOptions) validateAndParse(args []string) error {
|
||||
if len(args) < 1 {
|
||||
return fmt.Errorf("must specify %s", o.kind)
|
||||
}
|
||||
if len(args) > 1 {
|
||||
return fmt.Errorf("%ss must be comma-separated, with no spaces", o.kind)
|
||||
}
|
||||
m, err := o.convertToArray(args[0])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = o.arrayValidator(m); err != nil {
|
||||
return err
|
||||
}
|
||||
o.metadata = m
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *removeMetadataOptions) convertToArray(arg string) ([]string, error) {
|
||||
inputs := strings.Split(arg, ",")
|
||||
result := make([]string, 0, len(inputs))
|
||||
|
||||
for _, input := range inputs {
|
||||
if len(input) == 0 {
|
||||
return nil, o.makeError(input, "name is empty")
|
||||
}
|
||||
result = append(result, input)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (o *removeMetadataOptions) removeAnnotations(m *types.Kustomization) error {
|
||||
if m.CommonAnnotations == nil && !o.ignore {
|
||||
return fmt.Errorf("commonAnnotations is not defined in kustomization file")
|
||||
}
|
||||
return o.removeFromMap(m.CommonAnnotations, annotation)
|
||||
}
|
||||
|
||||
func (o *removeMetadataOptions) removeLabels(m *types.Kustomization) error {
|
||||
if m.CommonLabels == nil && !o.ignore {
|
||||
return fmt.Errorf("commonLabels is not defined in kustomization file")
|
||||
}
|
||||
return o.removeFromMap(m.CommonLabels, label)
|
||||
}
|
||||
|
||||
func (o *removeMetadataOptions) removeFromMap(m map[string]string, kind kindOfAdd) error {
|
||||
for _, k := range o.metadata {
|
||||
if _, ok := m[k]; !ok && !o.ignore {
|
||||
return fmt.Errorf("%s %s is not defined in kustomization file", kind, k)
|
||||
}
|
||||
delete(m, k)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *removeMetadataOptions) makeError(input string, message string) error {
|
||||
return fmt.Errorf("invalid %s: '%s' (%s)", o.kind, input, message)
|
||||
}
|
||||
351
pkg/commands/edit/remove/removemetadata_test.go
Normal file
351
pkg/commands/edit/remove/removemetadata_test.go
Normal file
@@ -0,0 +1,351 @@
|
||||
/*
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package remove
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/validators"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func makeKustomizationFS() fs.FileSystem {
|
||||
fakeFS := fs.MakeFakeFS()
|
||||
commonLabels := []string{"label1: val1", "label2: val2"}
|
||||
commonAnnotations := []string{"annotation1: val1", "annotation2: val2"}
|
||||
|
||||
fakeFS.WriteTestKustomizationWith([]byte(
|
||||
fmt.Sprintf("commonLabels:\n %s\ncommonAnnotations:\n %s",
|
||||
strings.Join(commonLabels, "\n "), strings.Join(commonAnnotations, "\n "))))
|
||||
return fakeFS
|
||||
}
|
||||
|
||||
func readKustomizationFS(t *testing.T, fakeFS fs.FileSystem) *types.Kustomization {
|
||||
kf, err := kustfile.NewKustomizationFile(fakeFS)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected new error %v", err)
|
||||
}
|
||||
m, err := kf.Read()
|
||||
if err != nil {
|
||||
t.Errorf("unexpected read error %v", err)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func makeKustomization(t *testing.T) *types.Kustomization {
|
||||
fakeFS := makeKustomizationFS()
|
||||
return readKustomizationFS(t, fakeFS)
|
||||
}
|
||||
|
||||
func TestRemoveAnnotation(t *testing.T) {
|
||||
var o removeMetadataOptions
|
||||
o.metadata = []string{"annotation1"}
|
||||
|
||||
m := makeKustomization(t)
|
||||
err := o.removeAnnotations(m)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: could not write to kustomization file")
|
||||
}
|
||||
|
||||
// adding the same test input should not work
|
||||
err = o.removeAnnotations(m)
|
||||
if err == nil {
|
||||
t.Errorf("expected not exist in kustomization file error")
|
||||
}
|
||||
|
||||
_, exists := m.CommonAnnotations["annotation1"]
|
||||
if exists {
|
||||
t.Errorf("annotation1 must be deleted")
|
||||
}
|
||||
|
||||
_, exists = m.CommonAnnotations["annotation2"]
|
||||
if !exists {
|
||||
t.Errorf("annotation2 must exist")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveAnnotationIgnore(t *testing.T) {
|
||||
fakeFS := makeKustomizationFS()
|
||||
|
||||
v := validators.MakeHappyMapValidator(t)
|
||||
cmd := newCmdRemoveAnnotation(fakeFS, v.ValidatorArray)
|
||||
cmd.Flag("ignore-non-existence").Value.Set("true")
|
||||
args := []string{"annotation3"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
v.VerifyCall()
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveAnnotationNoDefinition(t *testing.T) {
|
||||
fakeFS := fs.MakeFakeFS()
|
||||
fakeFS.WriteTestKustomizationWith([]byte(""))
|
||||
|
||||
v := validators.MakeHappyMapValidator(t)
|
||||
cmd := newCmdRemoveAnnotation(fakeFS, v.ValidatorArray)
|
||||
args := []string{"annotation1,annotation2"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
v.VerifyCall()
|
||||
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
if err.Error() != "commonAnnotations is not defined in kustomization file" {
|
||||
t.Errorf("incorrect error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveAnnotationNoDefinitionIgnore(t *testing.T) {
|
||||
fakeFS := fs.MakeFakeFS()
|
||||
fakeFS.WriteTestKustomizationWith([]byte(""))
|
||||
|
||||
v := validators.MakeHappyMapValidator(t)
|
||||
cmd := newCmdRemoveLabel(fakeFS, v.ValidatorArray)
|
||||
cmd.Flag("ignore-non-existence").Value.Set("true")
|
||||
args := []string{"annotation1,annotation2"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
v.VerifyCall()
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveAnnotationNoArgs(t *testing.T) {
|
||||
fakeFS := makeKustomizationFS()
|
||||
|
||||
v := validators.MakeHappyMapValidator(t)
|
||||
cmd := newCmdRemoveAnnotation(fakeFS, v.ValidatorArray)
|
||||
err := cmd.Execute()
|
||||
v.VerifyNoCall()
|
||||
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
if err.Error() != "must specify label" {
|
||||
t.Errorf("incorrect error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveAnnotationInvalidFormat(t *testing.T) {
|
||||
fakeFS := makeKustomizationFS()
|
||||
|
||||
v := validators.MakeSadMapValidator(t)
|
||||
cmd := newCmdRemoveAnnotation(fakeFS, v.ValidatorArray)
|
||||
args := []string{"nospecialchars%^=@"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
v.VerifyCall()
|
||||
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
if err.Error() != validators.SAD {
|
||||
t.Errorf("incorrect error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveAnnotationMultipleArgs(t *testing.T) {
|
||||
fakeFS := makeKustomizationFS()
|
||||
|
||||
v := validators.MakeHappyMapValidator(t)
|
||||
cmd := newCmdRemoveAnnotation(fakeFS, v.ValidatorArray)
|
||||
args := []string{"annotation1,annotation2"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
v.VerifyCall()
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
|
||||
m := readKustomizationFS(t, fakeFS)
|
||||
splitArgs := strings.Split(args[0], ",")
|
||||
for _, k := range splitArgs {
|
||||
if _, exist := m.CommonAnnotations[k]; exist {
|
||||
t.Errorf("%s must be deleted", k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveAnnotationMultipleArgsInvalidFormat(t *testing.T) {
|
||||
fakeFS := makeKustomizationFS()
|
||||
|
||||
v := validators.MakeSadMapValidator(t)
|
||||
cmd := newCmdRemoveAnnotation(fakeFS, v.ValidatorArray)
|
||||
args := []string{"annotation1", "annotation2"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
v.VerifyNoCall()
|
||||
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
if err.Error() != "labels must be comma-separated, with no spaces" {
|
||||
t.Errorf("incorrect error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveLabel(t *testing.T) {
|
||||
var o removeMetadataOptions
|
||||
o.metadata = []string{"label1"}
|
||||
|
||||
m := makeKustomization(t)
|
||||
err := o.removeLabels(m)
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: could not write to kustomization file")
|
||||
}
|
||||
|
||||
// adding the same test input should not work
|
||||
err = o.removeLabels(m)
|
||||
if err == nil {
|
||||
t.Errorf("expected not exist in kustomization file error")
|
||||
}
|
||||
|
||||
_, exists := m.CommonLabels["label1"]
|
||||
if exists {
|
||||
t.Errorf("label1 must be deleted")
|
||||
}
|
||||
|
||||
_, exists = m.CommonLabels["label2"]
|
||||
if !exists {
|
||||
t.Errorf("label2 must exist")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveLabelIgnore(t *testing.T) {
|
||||
fakeFS := makeKustomizationFS()
|
||||
|
||||
v := validators.MakeHappyMapValidator(t)
|
||||
cmd := newCmdRemoveLabel(fakeFS, v.ValidatorArray)
|
||||
cmd.Flag("ignore-non-existence").Value.Set("true")
|
||||
args := []string{"label3"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
v.VerifyCall()
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveLabelNoDefinition(t *testing.T) {
|
||||
fakeFS := fs.MakeFakeFS()
|
||||
fakeFS.WriteTestKustomizationWith([]byte(""))
|
||||
|
||||
v := validators.MakeHappyMapValidator(t)
|
||||
cmd := newCmdRemoveLabel(fakeFS, v.ValidatorArray)
|
||||
args := []string{"label1,label2"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
v.VerifyCall()
|
||||
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
if err.Error() != "commonLabels is not defined in kustomization file" {
|
||||
t.Errorf("incorrect error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveLabelNoDefinitionIgnore(t *testing.T) {
|
||||
fakeFS := fs.MakeFakeFS()
|
||||
fakeFS.WriteTestKustomizationWith([]byte(""))
|
||||
|
||||
v := validators.MakeHappyMapValidator(t)
|
||||
cmd := newCmdRemoveLabel(fakeFS, v.ValidatorArray)
|
||||
cmd.Flag("ignore-non-existence").Value.Set("true")
|
||||
args := []string{"label1,label2"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
v.VerifyCall()
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveLabelNoArgs(t *testing.T) {
|
||||
fakeFS := makeKustomizationFS()
|
||||
|
||||
v := validators.MakeHappyMapValidator(t)
|
||||
cmd := newCmdRemoveLabel(fakeFS, v.ValidatorArray)
|
||||
err := cmd.Execute()
|
||||
v.VerifyNoCall()
|
||||
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
if err.Error() != "must specify label" {
|
||||
t.Errorf("incorrect error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveLabelInvalidFormat(t *testing.T) {
|
||||
fakeFS := makeKustomizationFS()
|
||||
|
||||
v := validators.MakeSadMapValidator(t)
|
||||
cmd := newCmdRemoveLabel(fakeFS, v.ValidatorArray)
|
||||
args := []string{"exclamation!"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
v.VerifyCall()
|
||||
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
if err.Error() != validators.SAD {
|
||||
t.Errorf("incorrect error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveLabelMultipleArgs(t *testing.T) {
|
||||
fakeFS := makeKustomizationFS()
|
||||
|
||||
v := validators.MakeHappyMapValidator(t)
|
||||
cmd := newCmdRemoveLabel(fakeFS, v.ValidatorArray)
|
||||
args := []string{"label1,label2"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
v.VerifyCall()
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
|
||||
m := readKustomizationFS(t, fakeFS)
|
||||
splitArgs := strings.Split(args[0], ",")
|
||||
for _, k := range splitArgs {
|
||||
if _, exist := m.CommonLabels[k]; exist {
|
||||
t.Errorf("%s must be deleted", k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveLabelMultipleArgsInvalidFormat(t *testing.T) {
|
||||
fakeFS := makeKustomizationFS()
|
||||
|
||||
v := validators.MakeSadMapValidator(t)
|
||||
cmd := newCmdRemoveLabel(fakeFS, v.ValidatorArray)
|
||||
args := []string{"label1", "label2"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
v.VerifyNoCall()
|
||||
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
if err.Error() != "labels must be comma-separated, with no spaces" {
|
||||
t.Errorf("incorrect error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
91
pkg/commands/edit/remove/removepatch.go
Normal file
91
pkg/commands/edit/remove/removepatch.go
Normal file
@@ -0,0 +1,91 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package remove
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/edit/util"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/patch"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/pgmconfig"
|
||||
)
|
||||
|
||||
type removePatchOptions struct {
|
||||
patchFilePaths []string
|
||||
}
|
||||
|
||||
// newCmdRemovePatch removes the name of a file containing a patch from the kustomization file.
|
||||
func newCmdRemovePatch(fsys fs.FileSystem) *cobra.Command {
|
||||
var o removePatchOptions
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "patch",
|
||||
Short: "Removes one or more patches from " + pgmconfig.KustomizationFileNames[0],
|
||||
Example: `
|
||||
remove patch {filepath}`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
err := o.Validate(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = o.Complete(cmd, args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return o.RunRemovePatch(fsys)
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
// Validate validates removePatch command.
|
||||
func (o *removePatchOptions) Validate(args []string) error {
|
||||
if len(args) == 0 {
|
||||
return errors.New("must specify a patch file")
|
||||
}
|
||||
o.patchFilePaths = args
|
||||
return nil
|
||||
}
|
||||
|
||||
// Complete completes removePatch command.
|
||||
func (o *removePatchOptions) Complete(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RunRemovePatch runs removePatch command (do real work).
|
||||
func (o *removePatchOptions) RunRemovePatch(fSys fs.FileSystem) error {
|
||||
patches, err := util.GlobPatterns(fSys, o.patchFilePaths)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(patches) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
mf, err := kustfile.NewKustomizationFile(fSys)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m, err := mf.Read()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var removePatches []string
|
||||
for _, p := range patches {
|
||||
if !patch.Exist(m.PatchesStrategicMerge, p) {
|
||||
log.Printf("patch %s doesn't exist in kustomization file", p)
|
||||
continue
|
||||
}
|
||||
removePatches = append(removePatches, p)
|
||||
}
|
||||
m.PatchesStrategicMerge = patch.Delete(m.PatchesStrategicMerge, removePatches...)
|
||||
|
||||
return mf.Write(m)
|
||||
}
|
||||
136
pkg/commands/edit/remove/removepatch_test.go
Normal file
136
pkg/commands/edit/remove/removepatch_test.go
Normal file
@@ -0,0 +1,136 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package remove
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/patch"
|
||||
)
|
||||
|
||||
const (
|
||||
patchFileContent = `
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
|
||||
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
`
|
||||
)
|
||||
|
||||
func makeKustomizationPatchFS() fs.FileSystem {
|
||||
fakeFS := fs.MakeFakeFS()
|
||||
patches := []string{"patch1.yaml", "patch2.yaml"}
|
||||
|
||||
fakeFS.WriteTestKustomizationWith([]byte(
|
||||
fmt.Sprintf("patchesStrategicMerge:\n - %s",
|
||||
strings.Join(patches, "\n - "))))
|
||||
|
||||
for _, p := range patches {
|
||||
fakeFS.WriteFile(p, []byte(patchFileContent))
|
||||
}
|
||||
fakeFS.WriteFile("patch3.yaml", []byte(patchFileContent))
|
||||
return fakeFS
|
||||
}
|
||||
|
||||
func TestRemovePatch(t *testing.T) {
|
||||
fakeFS := makeKustomizationPatchFS()
|
||||
cmd := newCmdRemovePatch(fakeFS)
|
||||
args := []string{"patch1.yaml"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
|
||||
m := readKustomizationFS(t, fakeFS)
|
||||
for _, k := range args {
|
||||
if patch.Exist(m.PatchesStrategicMerge, k) {
|
||||
t.Errorf("%s must be deleted", k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemovePatchMultipleArgs(t *testing.T) {
|
||||
fakeFS := makeKustomizationPatchFS()
|
||||
cmd := newCmdRemovePatch(fakeFS)
|
||||
args := []string{"patch1.yaml", "patch2.yaml"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
|
||||
m := readKustomizationFS(t, fakeFS)
|
||||
for _, k := range args {
|
||||
if patch.Exist(m.PatchesStrategicMerge, k) {
|
||||
t.Errorf("%s must be deleted", k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemovePatchGlob(t *testing.T) {
|
||||
fakeFS := makeKustomizationPatchFS()
|
||||
cmd := newCmdRemovePatch(fakeFS)
|
||||
args := []string{"patch*.yaml"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
|
||||
m := readKustomizationFS(t, fakeFS)
|
||||
if len(m.PatchesStrategicMerge) != 0 {
|
||||
t.Errorf("all patch must be deleted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemovePatchNotDefinedInKustomization(t *testing.T) {
|
||||
fakeFS := makeKustomizationPatchFS()
|
||||
cmd := newCmdRemovePatch(fakeFS)
|
||||
args := []string{"patch3.yaml"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
|
||||
m := readKustomizationFS(t, fakeFS)
|
||||
for _, k := range []string{"patch1.yaml", "patch2.yaml"} {
|
||||
if !patch.Exist(m.PatchesStrategicMerge, k) {
|
||||
t.Errorf("%s must exist", k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemovePatchNotExist(t *testing.T) {
|
||||
fakeFS := makeKustomizationPatchFS()
|
||||
cmd := newCmdRemovePatch(fakeFS)
|
||||
args := []string{"patch4.yaml"}
|
||||
err := cmd.RunE(cmd, args)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error %v", err)
|
||||
}
|
||||
|
||||
m := readKustomizationFS(t, fakeFS)
|
||||
for _, k := range []string{"patch1.yaml", "patch2.yaml"} {
|
||||
if !patch.Exist(m.PatchesStrategicMerge, k) {
|
||||
t.Errorf("%s must exist", k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemovePatchNoArgs(t *testing.T) {
|
||||
fakeFS := makeKustomizationPatchFS()
|
||||
cmd := newCmdRemovePatch(fakeFS)
|
||||
err := cmd.RunE(cmd, nil)
|
||||
|
||||
if err == nil {
|
||||
t.Errorf("expected an error")
|
||||
}
|
||||
if err.Error() != "must specify a patch file" {
|
||||
t.Errorf("incorrect error: %v", err.Error())
|
||||
}
|
||||
}
|
||||
@@ -19,10 +19,11 @@ package remove
|
||||
import (
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/pgmconfig"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
)
|
||||
|
||||
type removeResourceOptions struct {
|
||||
@@ -35,7 +36,7 @@ func newCmdRemoveResource(fsys fs.FileSystem) *cobra.Command {
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "resource",
|
||||
Short: "Remove resource file paths to the kustomization file.",
|
||||
Short: "Removes one or more resource file paths from " + pgmconfig.KustomizationFileNames[0],
|
||||
Example: `
|
||||
remove resource my-resource.yml
|
||||
remove resource resource1.yml resource2.yml resource3.yml
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
)
|
||||
|
||||
func TestRemoveResources(t *testing.T) {
|
||||
|
||||
@@ -18,8 +18,8 @@ package set
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/ifc"
|
||||
)
|
||||
|
||||
// NewCmdSet returns an instance of 'set' subcommand.
|
||||
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
"errors"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
)
|
||||
|
||||
type setNamePrefixOptions struct {
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
"errors"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
)
|
||||
|
||||
type setNameSuffixOptions struct {
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -23,9 +23,9 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/image"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/image"
|
||||
)
|
||||
|
||||
type setImageOptions struct {
|
||||
@@ -133,7 +133,7 @@ func (o *setImageOptions) RunSetImage(fSys fs.FileSystem) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// append only new images from ksutomize file
|
||||
// append only new images from kustomize file
|
||||
for _, im := range m.Images {
|
||||
if _, ok := o.imageMap[im.Name]; ok {
|
||||
continue
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
)
|
||||
|
||||
func TestSetImage(t *testing.T) {
|
||||
|
||||
@@ -22,9 +22,9 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/commands/kustfile"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/ifc"
|
||||
)
|
||||
|
||||
type setNamespaceOptions struct {
|
||||
|
||||
@@ -21,8 +21,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/validators"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/validators"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
26
pkg/commands/edit/util/functions.go
Normal file
26
pkg/commands/edit/util/functions.go
Normal file
@@ -0,0 +1,26 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package util
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
)
|
||||
|
||||
func GlobPatterns(fsys fs.FileSystem, patterns []string) ([]string, error) {
|
||||
var result []string
|
||||
for _, pattern := range patterns {
|
||||
files, err := fsys.Glob(pattern)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(files) == 0 {
|
||||
log.Printf("%s has no match", pattern)
|
||||
continue
|
||||
}
|
||||
result = append(result, files...)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
@@ -26,9 +26,9 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/fs"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/pgmconfig"
|
||||
"sigs.k8s.io/kustomize/v3/pkg/types"
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
@@ -61,11 +61,13 @@ func determineFieldOrder() []string {
|
||||
"CommonAnnotations",
|
||||
"PatchesStrategicMerge",
|
||||
"PatchesJson6902",
|
||||
"Patches",
|
||||
"ConfigMapGenerator",
|
||||
"SecretGenerator",
|
||||
"GeneratorOptions",
|
||||
"Vars",
|
||||
"Images",
|
||||
"Replicas",
|
||||
"Configurations",
|
||||
"Generators",
|
||||
"Transformers",
|
||||
@@ -73,9 +75,7 @@ func determineFieldOrder() []string {
|
||||
}
|
||||
|
||||
// Add deprecated fields here.
|
||||
deprecated := map[string]bool{
|
||||
"Patches": true,
|
||||
}
|
||||
deprecated := map[string]bool{}
|
||||
|
||||
// Account for the inlined TypeMeta fields.
|
||||
var result []string
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user