Compare commits

...

409 Commits

Author SHA1 Message Date
Kubernetes Prow Robot
9cc25a511c Merge pull request #5703 from koba1t/pinToCmdConfig
Update cmd/config to v0.14.1
2024-05-22 07:53:44 -07:00
koba1t
f6ad718ee6 Update cmd/config to v0.14.1 2024-05-22 23:41:07 +09:00
Kubernetes Prow Robot
da14e76359 Merge pull request #5702 from koba1t/pinToKyaml
Update kyaml to v0.17.1
2024-05-22 07:37:54 -07:00
koba1t
7424956ccf Update kyaml to v0.17.1 2024-05-22 23:24:23 +09:00
Kubernetes Prow Robot
e244b83844 Merge pull request #5688 from emirot/refactor/indexOf
refactor: function in stdlib now
2024-05-05 19:38:34 -07:00
emirot
f9838461af refactor: function in stdlib now
Signed-off-by: emirot <emirot.nolan@gmail.com>
2024-05-03 22:45:56 +02:00
Kubernetes Prow Robot
49a645f05d Merge pull request #5294 from typeid/localize_absolute_paths
feat: localize absolute paths
2024-04-29 22:11:47 -07:00
Tiago Silva
e7a15496dd fix: use fmt.Errorf instead of non-existing errors.New (#5651)
* fix: use fmt.Errorf ubstead if non-exising `errors.New`

When https://github.com/kubernetes-sigs/kustomize/pull/5525 merged, it
referenced `errors.New` function but that function doesn't exist.
This PR replaces the call with simple `fmt.Errorf`.

* Add lint check with kustomize_disable_go_plugin_support

* move lint-api-static to /api/Makefile

* clean golangci cache
2024-04-29 18:22:26 -07:00
Kubernetes Prow Robot
0d7d830236 Merge pull request #5681 from emirot/remove-string-in-slice
chore: remove unused function
2024-04-28 23:59:56 -07:00
Kubernetes Prow Robot
e676d056b2 Merge pull request #5500 from charles-chenzz/kust-target-tc
add testcase that check yield malformed yaml errors
2024-04-28 23:45:18 -07:00
emirot
0e649599d0 chore: remove unused function
Signed-off-by: emirot <emirot.nolan@gmail.com>
2024-04-26 16:32:00 +01:00
Kubernetes Prow Robot
a68f40738a Merge pull request #5680 from koba1t/chore/restore_version_for_govalidator
chore: restore version for github.com/asaskevich/govalidator
2024-04-25 08:20:51 -07:00
koba1t
72d95b5f41 chore: restore version for github.com/asaskevich/govalidator 2024-04-25 17:21:05 +09:00
Mauren
671de1662d feat: support labels key in transformer configuration (#5556)
* feat: support labels key in transformer configuration

Allow the usage of a separate transformer configuration for the labels key,
similar to what is currently available for commonLabels and commonAnnotations.
This aims to provide the same functionality that commonLabels currently provide
for labels, since commonLabels is deprecated and slated for removal in a future
release.

* chore(transformerconfig): add nolint hint

Add a nolint hint to the new method so the returns can stay consistent with
one another.

* fix: changes from code review

* Rename methods `AddCommonLabelFieldSpec` and `AddLabelFieldSpec` to
  `AddCommonLabelsFieldSpec` and `AddLabelsFieldSpec`.
* Add extra test to verify scenarios applying labels to Custom Resource Definitions.
2024-04-25 00:40:44 -07:00
Kubernetes Prow Robot
2e6171a9ea Merge pull request #5671 from emirot/refactor/string_inSlice
refactor: string in slice is now part of stdlib
2024-04-23 04:36:33 -07:00
Kubernetes Prow Robot
7f99cebdc6 Merge pull request #5672 from stormqueen1990/chore/bump-deps
chore(deps): bump dependencies of kustomize + sync go workspace
2024-04-22 20:01:27 -07:00
Mauren Berti
5d127e4138 chore(deps): bump dependencies of kustomize + sync go workspace
* Bump the golang.org/x dependencies.
* Run `go work sync` to synchronize dependencies across Go workspaces.
2024-04-21 20:03:38 -04:00
nolan emirot
bcb1a367aa refactor: string in slice part of stdlib now
Signed-off-by: emirot <nolan.emirot@workday.com>
2024-04-20 18:48:40 -04:00
Yusuke Abe
ed09399cd1 fix: return error instead of log.Fatalf() (#5625)
* fix: return error instead of log.Fatalf()

* chore: add meaningful message to error output

* chore: add meaningful message to fatal function
2024-04-18 03:56:51 -07:00
Kubernetes Prow Robot
82ee768212 Merge pull request #5079 from chlunde/perf-1
perf: improve applyOrdering by avoid call to GetByCurrentId
2024-04-06 10:14:25 -07:00
Kubernetes Prow Robot
116b307b88 Merge pull request #5646 from koba1t/unpinEverything
Back to development mode; unpin the modules
2024-04-04 10:38:23 -07:00
koba1t
fb9f45ebe0 Back to development mode; unpin the modules 2024-04-05 02:24:31 +09:00
Kubernetes Prow Robot
536c1c0a8b Merge pull request #5645 from koba1t/pinToApi
Update api to v0.17.1
2024-04-04 10:11:54 -07:00
koba1t
e20e438d05 Update api to v0.17.1 2024-04-05 02:01:10 +09:00
Kubernetes Prow Robot
42873c8d2a Merge pull request #5644 from koba1t/fix/version_subcommand_is_broken
fix version subcommand is not working after release build
2024-04-04 09:53:40 -07:00
koba1t
277da9ed21 fix version subcommand is not working after release build 2024-04-05 01:37:31 +09:00
Kubernetes Prow Robot
2b00d887fd Merge pull request #5643 from koba1t/unpinEverything
unpin api
2024-04-04 08:57:57 -07:00
koba1t
08d0593c3e unpin api 2024-04-05 00:45:41 +09:00
Kubernetes Prow Robot
31706fd7fd Merge pull request #5641 from koba1t/pinToApi
Update api to v0.17.0
2024-04-04 07:06:03 -07:00
koba1t
e862612703 Update api to v0.17.0 2024-04-04 22:45:14 +09:00
Kubernetes Prow Robot
1b449768b5 Merge pull request #5640 from koba1t/pinToCmdConfig
Update cmd/config to v0.14.0
2024-04-04 06:38:36 -07:00
koba1t
a9f7a0427a Update cmd/config to v0.14.0 2024-04-04 22:25:14 +09:00
Kubernetes Prow Robot
cd954ce6fe Merge pull request #5639 from koba1t/pinToKyaml
Update kyaml to v0.17.0
2024-04-04 06:20:23 -07:00
koba1t
10c292f501 Update kyaml to v0.17.0 2024-04-04 21:59:50 +09:00
Kubernetes Prow Robot
a9bfabc771 Merge pull request #5637 from karlkfi/karl-fix-generate
Fix gorepomod make test
2024-04-04 03:13:42 -07:00
Kubernetes Prow Robot
398aa3666f Merge pull request #5638 from kubernetes-sigs/dependabot/go_modules/hack/github.com/cloudflare/circl-1.3.7
build(deps): bump github.com/cloudflare/circl from 1.3.3 to 1.3.7 in /hack
2024-04-04 02:51:07 -07:00
Kubernetes Prow Robot
8f2d2436ec Merge pull request #5634 from kubernetes-sigs/dependabot/go_modules/hack/github.com/cli/cli-1.2.1
build(deps): bump github.com/cli/cli from 0.6.0 to 1.2.1 in /hack
2024-04-04 02:34:01 -07:00
dependabot[bot]
fd06780f3e build(deps): bump github.com/cloudflare/circl in /hack
Bumps [github.com/cloudflare/circl](https://github.com/cloudflare/circl) from 1.3.3 to 1.3.7.
- [Release notes](https://github.com/cloudflare/circl/releases)
- [Commits](https://github.com/cloudflare/circl/compare/v1.3.3...v1.3.7)

---
updated-dependencies:
- dependency-name: github.com/cloudflare/circl
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-04-04 09:12:28 +00:00
dependabot[bot]
562cbc132d build(deps): bump github.com/cli/cli from 0.6.0 to 1.2.1 in /hack
Bumps [github.com/cli/cli](https://github.com/cli/cli) from 0.6.0 to 1.2.1.
- [Release notes](https://github.com/cli/cli/releases)
- [Changelog](https://github.com/cli/cli/blob/trunk/.goreleaser.yml)
- [Commits](https://github.com/cli/cli/compare/v0.6.0...v1.2.1)

---
updated-dependencies:
- dependency-name: github.com/cli/cli
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-04-04 09:10:54 +00:00
Kubernetes Prow Robot
d5f3c4fad9 Merge pull request #5635 from kubernetes-sigs/dependabot/go_modules/hack/github.com/go-git/go-git/v5-5.11.0
build(deps): bump github.com/go-git/go-git/v5 from 5.4.2 to 5.11.0 in /hack
2024-04-04 02:09:43 -07:00
Kubernetes Prow Robot
f1599f6498 Merge pull request #5633 from kubernetes-sigs/dependabot/go_modules/hack/github.com/microcosm-cc/bluemonday-1.0.26
build(deps): bump github.com/microcosm-cc/bluemonday from 1.0.2 to 1.0.26 in /hack
2024-04-04 02:09:36 -07:00
Kubernetes Prow Robot
c0b3801c7a Merge pull request #5636 from karlkfi/karl-site-pin-version
Update site/Dockerfile to use pinned hugo version
2024-04-04 01:21:35 -07:00
Kubernetes Prow Robot
f0681429ea Merge pull request #5629 from jakezhu9/favicons
add favicons for kustomize site
2024-04-03 08:38:07 -07:00
Karl Isenberg
a6bbbe843c Fix gorepomod make test 2024-04-02 17:59:22 -07:00
Karl Isenberg
2c68a4d2d4 Update site/Dockerfile to use pinned hugo version
Version pinned in hack/go.mod.
Use `make tools` to update the pinned version to match netlify.toml
2024-04-02 14:26:31 -07:00
Jonathan King
b3d1df2644 Fix name in a configMapRef missing hash #5047 (#5236)
* Add regression tests

* Update PrefixesSuffixesEquals function

* Try empty prefix/suffix but fall back on duplicates

* Run gofmt

* Remove newline

* Revert unnecessary gofmt change

* Add comment
2024-04-02 12:44:11 -07:00
dependabot[bot]
8d21d43cf7 build(deps): bump github.com/go-git/go-git/v5 in /hack
Bumps [github.com/go-git/go-git/v5](https://github.com/go-git/go-git) from 5.4.2 to 5.11.0.
- [Release notes](https://github.com/go-git/go-git/releases)
- [Commits](https://github.com/go-git/go-git/compare/v5.4.2...v5.11.0)

---
updated-dependencies:
- dependency-name: github.com/go-git/go-git/v5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-04-02 19:35:31 +00:00
dependabot[bot]
eabf2d41d3 build(deps): bump github.com/microcosm-cc/bluemonday in /hack
Bumps [github.com/microcosm-cc/bluemonday](https://github.com/microcosm-cc/bluemonday) from 1.0.2 to 1.0.26.
- [Release notes](https://github.com/microcosm-cc/bluemonday/releases)
- [Commits](https://github.com/microcosm-cc/bluemonday/compare/v1.0.2...v1.0.26)

---
updated-dependencies:
- dependency-name: github.com/microcosm-cc/bluemonday
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-04-02 19:35:20 +00:00
Karl Isenberg
ed2ca23400 Pin tool versions with hack/go.mod (#5622)
* Pin tool versions with hack/go.mod

This change centralizes the tracking of versions for tools used for
development and testing. This way, the tools and all their
dependencies have their checksums stored in hack/go.sum, which
improves supply chain security.

* Workspace Sync & Tidy
2024-04-02 12:34:13 -07:00
jakezhu9
6145a4be44 add favicons for kustomize site 2024-03-28 03:23:09 +00:00
Kubernetes Prow Robot
8fef99fa35 Merge pull request #5542 from ephesused/issue5540
fix: improve accumulation failure message
2024-03-27 10:32:54 -07:00
Kubernetes Prow Robot
a6149b1c88 Merge pull request #5627 from koba1t/remove_klog/v1_dependencies
Remove klog/v1 dependencies
2024-03-27 08:46:54 -07:00
koba1t
91b92b52c1 remove klog/v1 dependencies due to that is in the unwanted dependencies in k/k 2024-03-28 00:30:27 +09:00
Kubernetes Prow Robot
d7e60b8451 Merge pull request #5624 from karlkfi/karl-example-500
Use a local test server instead of example.com
2024-03-27 08:28:55 -07:00
Karl Isenberg
9db92fd28d Use a local test server instead of example.com 2024-03-21 13:14:12 -07:00
Kubernetes Prow Robot
d514df3db0 Merge pull request #5621 from karlkfi/karl-require-assert
Use require for Error and NoError
2024-03-21 02:42:00 -07:00
Kubernetes Prow Robot
22ce9c02bf Merge pull request #5620 from karlkfi/karl-fix-lint
Disable abandoned/archived linters
2024-03-21 01:39:22 -07:00
Karl Isenberg
43868688d5 Use require for Error and NoError
Assert keeps going after failure, but require immediately fails
the tests, making it easier to find the output related to the test
failure, rather than having to comb through a bunch of subsequent
assertion failures. For equality tests, we may or may not want to
continue, but for error checks we almost always want to immediately
fail the test. Exceptions can be changed as-needed.
2024-03-20 13:19:18 -07:00
Karl Isenberg
434a55a244 Disable abandoned/archived linters
This reduces the warnings printed when running `make lint`
2024-03-20 13:04:35 -07:00
Kubernetes Prow Robot
a6ea3e2bb6 Merge pull request #5567 from koba1t/remove_exp_slices_dependencies
fix 'golang.org/x/exp/slices' dependencies
2024-03-20 10:35:33 -07:00
koba1t
72f0a3cfb1 remove deprecated 'golang.org/x/exp/slices' dependencies 2024-03-21 02:12:15 +09:00
Kubernetes Prow Robot
1eccd8f4b7 Merge pull request #5555 from karlkfi/karl-go-121
chore: Update to Go v1.21
2024-03-20 10:05:07 -07:00
Karl Isenberg
4dbc0d22e1 chore: Update to Go v1.21
- go mod tidy (all modules)
- go work sync
- Fixed plugin generation for Go 1.21
- Updated linting for Go 1.21
- Fixed minecraft example for Helm v3 pull download path
- Update dev docs to mention Go 1.21
- Regenerate plugins with Go 1.21
2024-03-15 11:47:44 -07:00
Kubernetes Prow Robot
e9fc57abd6 Merge pull request #5615 from koba1t/update_dependencies_google.golang.org/protobuf_to_v1.33.0
update dependencies google.golang.org/protobuf@v1.33.0
2024-03-14 06:23:08 -07:00
koba1t
d35edbf80d update dependencies google.golang.org/protobuf@v1.33.0 2024-03-14 17:27:48 +09:00
Kubernetes Prow Robot
da3985c284 Merge pull request #5519 from matthewhughes934/fix-null-strings-after-multiple-patches
Fix null YAML values being replaced by `"null"`
2024-03-12 08:40:24 -07:00
Ed Overton
14a9a9849f test: correct lint issues 2024-03-11 15:16:11 -04:00
Matthew Hughes
8aafbacd17 Fix null YAML values being replaced by "null"
Related issues:

* https://github.com/kubernetes-sigs/kustomize/issues/5031
* https://github.com/kubernetes-sigs/kustomize/issues/5171

After noting this behaviour was not present in
d89b448c74 a `git bisect` pointed to the
change 1b7db20504. The issue with that
change is that upon seeing a `null` node it would replace it with a node
whose value was equivalent but without a `!!null` tag. This meant that
one application of a patch would have the desired approach: the result
would be `null` in the output, but on a second application of a similar
patch the field would be rendered as `"null"`.

To avoid this, define a new attribute on `RNode`s that is checked before
clearing any node we should keep. The added
`TestApplySmPatch_Idempotency` test verifies this behaviour.

See also https://github.com/kubernetes-sigs/kustomize/pull/5365 for an
alternative approach
2024-03-09 17:31:35 +00:00
Ed Overton
4da880d6cb Merge remote-tracking branch 'origin/master' into issue5540 2024-03-08 14:48:51 -05:00
Ed Overton
62eca858f3 test: add test for issue 5440 2024-03-08 14:33:09 -05:00
Kubernetes Prow Robot
11704312be Merge pull request #5551 from colinodell/patch-1
Improve framework documentation
2024-03-06 14:14:54 -08:00
Kubernetes Prow Robot
74ba2fb141 Merge pull request #5387 from Crystalix007/master
fix: show CronJob properties
2024-03-06 13:51:17 -08:00
Colin O'Dell
cc410bc23a Update the example to match what kustomize fn expects 2024-03-05 17:31:38 -05:00
Colin O'Dell
2252fd951a Fix lint violations 2024-03-05 17:26:35 -05:00
Tiago Silva
33caee50cb Allow importing kustomize API's without relying on plugins (#5525)
* Allow importing kustomize API's without relying on `plugins`

Introduce `kustomize_disable_go_plugin_support` go build tag to decouple the kustomize
API from the `plugins` package dependency. This is advantageous for applications
embedding the kusstomize API without the need for dynamic Go plugins, mitigating an
increase in binary size associated with the inclusion of the plugins dependency
and the population of ELF sections like `.dynsym` and `.dynstr`.

The flag provides applications with the flexibility to exclude the import, catering to
scenarios where dynamic Go plugin support is unnecessary.

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>

* fix golint by disabling some lint checks

* handle code review suggestions

---------

Signed-off-by: Tiago Silva <tiago.silva@goteleport.com>
2024-02-27 08:22:51 -08:00
Kubernetes Prow Robot
28ef9da0d9 Merge pull request #5545 from kubernetes-sigs/dependabot/github_actions/dorny/paths-filter-3
build(deps): bump dorny/paths-filter from 2 to 3
2024-02-27 08:10:19 -08:00
Kubernetes Prow Robot
db2240c9c1 Merge pull request #5541 from skitt/canonical-json-patch
Use canonical json-patch v4 import
2024-02-27 08:10:10 -08:00
Nick
d3329453a2 Add kustomization and transformer references (#5523)
* Add fields to kustomization file ref

* Address grammar feedback.

* labels.fields
2024-02-26 10:25:24 -08:00
Kubernetes Prow Robot
6ffcc08591 Merge pull request #5201 from danistrebel/fix/examples-patches
fix(examples): move examples from patchesStrategicMerge to patches
2024-02-25 12:36:03 -08:00
Colin O'Dell
facabded61 Fix other command reference 2024-02-23 11:16:15 -05:00
Colin O'Dell
9d66eb16c8 Add import statements to help users get up-and-running faster 2024-02-23 11:14:16 -05:00
Colin O'Dell
6088692165 Fix incorrect command name 2024-02-23 11:12:00 -05:00
Kubernetes Prow Robot
9e68399e04 Merge pull request #5550 from koba1t/use_StrictUnmarshal_for_read_TransformerConfig
use Strict unmarshal when read TransformerConfig
2024-02-21 17:21:49 -08:00
Colin O'Dell
e25f99ee02 Fix broken example 2024-02-21 16:56:03 -05:00
koba1t
37715863f0 use Strict unmarshal when read TransformerConfig 2024-02-22 05:39:55 +09:00
Kubernetes Prow Robot
3e69c2e36a Merge pull request #5510 from andreaskaris/kustomize-env-var-max-length
Skip KUSTOMIZE_PLUGIN_CONFIG_* env variables when too large
2024-02-21 09:35:01 -08:00
Andreas Karis
17eab513e9 Skip KUSTOMIZE_PLUGIN_CONFIG_* env variables when too large
Kustomize sets the legacy KUSTOMIZE_PLUGIN_CONFIG_STRING and
KUSTOMIZE_PLUGIN_CONFIG_ROOT environment variables. When these
environment variables exceed a hardcoded length (PAGE_SIZE * 32 on most
Linux systems), the kernel will return `argument list too long`. Given
that the environment variables are legacy, log a warning and do not set
them if they exceed 131071 bytes.

Reported-at: https://github.com/kubernetes-sigs/kustomize/issues/5480
Signed-off-by: Andreas Karis <ak.karis@gmail.com>
2024-02-21 17:36:09 +01:00
Kubernetes Prow Robot
800e12b5ae Merge pull request #5539 from dhaiducek/plugin-errmsg
Include exec plugin `stderr` with wrapped error
2024-02-19 17:45:08 -08:00
dependabot[bot]
96c6bbad2c build(deps): bump dorny/paths-filter from 2 to 3
Bumps [dorny/paths-filter](https://github.com/dorny/paths-filter) from 2 to 3.
- [Release notes](https://github.com/dorny/paths-filter/releases)
- [Changelog](https://github.com/dorny/paths-filter/blob/master/CHANGELOG.md)
- [Commits](https://github.com/dorny/paths-filter/compare/v2...v3)

---
updated-dependencies:
- dependency-name: dorny/paths-filter
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-19 19:59:25 +00:00
Kubernetes Prow Robot
1fa02e729d Merge pull request #5546 from kubernetes-sigs/dependabot/github_actions/actions/checkout-4
build(deps): bump actions/checkout from 3 to 4
2024-02-19 11:58:51 -08:00
dependabot[bot]
f93b0ead3c build(deps): bump actions/checkout from 3 to 4
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-02-19 01:09:56 +00:00
Ed Overton
f80650e8ce fix: improve accumulation failure message
For accumulation errors when the file load fails due to malformed
YAML and the base load fails due to a timeout, report both errors.
Previously only the malformed YAML error was returned, masking the
git repo timeout.
2024-02-16 12:47:02 -05:00
Stephen Kitt
bcf100f592 Use canonical json-patch v4 import
The canonical import for json-patch v4 is
gopkg.in/evanphx/json-patch.v4 (see
https://github.com/evanphx/json-patch/blob/master/README.md#get-it for
reference).

Using the v4-specific path should also reduce the risk of unwanted v5
upgrade attempts (see
https://github.com/kubernetes/kubernetes/pull/120327 for context).

Signed-off-by: Stephen Kitt <skitt@redhat.com>
2024-02-16 12:23:04 +01:00
Dale Haiducek
9546529f1d Include plugin stderr with wrapped error
This allows plugins to provide more details aside
from just `exit status 1` inside the error

Signed-off-by: Dale Haiducek <19750917+dhaiducek@users.noreply.github.com>
2024-02-15 09:48:21 -05:00
Kubernetes Prow Robot
91ccf00ac8 Merge pull request #5533 from karlkfi/karl-version
chore: add hack/latest_version.sh
2024-02-14 12:08:33 -08:00
Kubernetes Prow Robot
f8f4203fb7 Merge pull request #5528 from Phillipdk/patch-1
Remove typo in documentation
2024-02-14 08:18:23 -08:00
Kubernetes Prow Robot
537c4fa5c2 Merge pull request #5438 from sarab97/act-skip-cond
Add condtional checks on jobs to skip on document changes.
2024-02-13 09:52:02 -08:00
Karl Isenberg
dc7ebef925 chore: add hack/latest_version.sh
Add script to lookup component version from github releases.

To sort, we're using sort -V or --version-sort, depending which
option is available. This which has some limitations:
- pre-releases (-) are sorted as post-releases
- post-releases and build metadata (+) are ignored

This is the best option available for SemVer sorting without
requiring the user to install additional depedencies, like nodejs.
2024-02-12 12:32:48 -08:00
Kubernetes Prow Robot
b154361c00 Merge pull request #5467 from stormqueen1990/feat/edit-set-secret
feat: edit set secret
2024-02-07 23:36:25 -08:00
Mauren Berti
3bb9a6d414 fix: update long description as per code review request 2024-02-06 21:12:39 -05:00
Mauren Berti
14c091aec7 fix: remove excessive quoting from error messages 2024-02-06 21:12:38 -05:00
Mauren Berti
6c1fea79ed chore: add failure test case for empty generator 2024-02-06 21:12:37 -05:00
Mauren Berti
ca8d629230 chore: update help to include bit about default namespace
Add a blurb to the help output for both 'edit set configmap' and 'edit set secret'
to clarify that whenever a namespace is not specified, the default namespace is
implicitly defined as part of the commands.
2024-02-06 21:12:36 -05:00
Mauren Berti
fd09a6ed50 chore: changes from code review
Remove error checks from the utility function and bubble them up instead.
2024-02-06 21:12:35 -05:00
Mauren Berti
23fbdd2ab5 chore: fix spacing in added description 2024-02-06 21:12:34 -05:00
Mauren Berti
27a8ff9d23 feat: edit set secret
* Add new functionality to allow editing a secret in a kustomization file. Initial
  implementation supports only --from-literal option.
* Refactor edit set configmap to reuse some testing bits.
2024-02-06 21:12:33 -05:00
Kubernetes Prow Robot
cf01ceb2f6 Merge pull request #5529 from karlkfi/karl-pin-site-deps
chore: pin dev deps in the dev container
2024-02-06 17:28:10 -08:00
Karl Isenberg
3bd9ea8ee7 chore: pin dev deps in the dev container
Copy package.json and package-lock.json into the site dev container
and use them to pin the versions and checksums for autoprefixer,
postcss-cli, and their dependencies.

This should help reduce risk of importing newer dependency versions
that haven't passed vulnerability checks.
2024-02-05 11:02:43 -08:00
Phillipdk
d223b9d55e Removed a typo in documentation 2024-02-05 08:37:23 +01:00
Kubernetes Prow Robot
31b852c7bc Merge pull request #5411 from sylr/complete-load-restrictor
Add --load-restrictor completion
2024-02-01 11:45:03 -08:00
Nick
add367bf2e Fix running docs site with docker (#5512)
* Update docs site local build

Clean up makefile

Ignore container-image.sentinel

Fix hugo server errors

Ignore files

Add makefile credit

* Indentation per feedback

* Address PR feedback. Remove sentinel file

* Remove change to .gitignore
2024-01-31 14:54:03 -08:00
Kubernetes Prow Robot
b1b61ad4cf Merge pull request #5044 from krzysiekg/fix-empty-map-merge
Remove non-essential dependency `imdario/mergo`
2024-01-31 10:03:00 -08:00
Krzysztof Gibuła
d73f0fd097 add test for values merge replace 2024-01-29 22:06:36 +01:00
Krzysztof Gibuła
bf286dce76 wrap errors and add comments 2024-01-29 22:06:36 +01:00
Krzysztof Gibuła
d768fc371c replace mergo with kyaml/yaml/merge2 2024-01-29 22:06:36 +01:00
Kubernetes Prow Robot
7e392f9117 Merge pull request #5521 from koba1t/add_license_for_api/pkg/util/image.go
add license for api/pkg/util/image.go
2024-01-29 06:35:11 -08:00
koba1t
4675bec08a add license for api/pkg/util/image/go 2024-01-29 23:18:51 +09:00
Nick
26165a86b7 Add buildMetadata task and ref (#5511)
* Add buildMetadata task and ref

Move build metadata tasks, draft buildMetadata reference

Clean up buildMetadata ref

Add managed by label task

Add local non-generated task

Add local generated resource

Add remote generator task

Clean up tasks and ref

Add local transformer annotation example

Add local and remote transformer example

* Address PR feedback and general cleanup
2024-01-27 00:12:39 +01:00
Kubernetes Prow Robot
69826668a7 Merge pull request #5234 from blackjid/bug_fix_set_image_digest_and_tag
fix edit set image to parse both tag and digest
2024-01-26 21:03:52 +01:00
Juan Ignacio Donoso
a85dfd4141 fix edit set image to parse both tag and digest 2024-01-26 16:30:41 -03:00
Kubernetes Prow Robot
abdcae870c Merge pull request #5463 from chansuke/feat/show-version
Fix version tag management
2024-01-26 20:21:29 +01:00
Kubernetes Prow Robot
dd49bd4c6d Merge pull request #5518 from natasha41575/updateowners
Update owners file
2024-01-25 22:57:08 +01:00
natasha41575
4adb7f9604 update owners file 2024-01-25 11:46:06 -06:00
Kubernetes Prow Robot
40ce15cca3 Merge pull request #5514 from kubernetes-sigs/dependabot/github_actions/joelanford/go-apidiff-0.8.2
build(deps): bump joelanford/go-apidiff from 0.7.0 to 0.8.2
2024-01-23 10:52:18 +01:00
dependabot[bot]
4e93959754 build(deps): bump joelanford/go-apidiff from 0.7.0 to 0.8.2
Bumps [joelanford/go-apidiff](https://github.com/joelanford/go-apidiff) from 0.7.0 to 0.8.2.
- [Release notes](https://github.com/joelanford/go-apidiff/releases)
- [Commits](https://github.com/joelanford/go-apidiff/compare/v0.7.0...v0.8.2)

---
updated-dependencies:
- dependency-name: joelanford/go-apidiff
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-01-22 01:11:48 +00:00
Kurnianto Trilaksono
ab519fdc13 Feature/dependency pinning and update automation (#5451)
* * handle local flag
* add managerfactory handling for local flag
* add shortName handling for local flag
* add dot git file handling for local flag
* add tests

* fix normal listing

* add ParseGitRepository function, add viper, add testing for utils

* add latest tag logic, add auto pinning and auto fetching

* makke gorepomod list works with --local

* make pinning works with local flag, enable auto update on fork and non-fork repo

* fix: refactor to pass linter

* refactor code and fix comments

* edit README

* refactor code to pass linting

* refactor code

* refactor code and enable patch branch label

* ru add license

* fbackward compatibility for unpin
2024-01-16 22:34:56 +01:00
Nick
f3fedac429 Add generator kustomization references (#5447)
* Initial configMapGenerator ref

* Draft configMapGenerator options

* ConfigMapArgs

* Add sources

* Begin to restructure generator spec

* Add ObjectMeta

* Draft kustomization.md

* Draft kustomization file links

* Move bases weight

* Update generatorArgs link to commmon generatorOptions

* Remove api/generators for now

* Update generatorOptions

* Add generatorArgs header

* Add secretGenerator

* Remove ObjectMeta for now

* Draft generators

* Fix secretGenerator

* Cleanup

* Add include shortcode, cleanup generators

* Use common includes

* Update object metadata description

* spelling

* Improve args description
2024-01-10 20:27:05 +01:00
charles-chenzz
3f921e159b add testcase that yield malformed yaml errors 2024-01-08 19:25:04 +08:00
Michael Kuc
872968c420 fix: show CronJob properties
Show the properties of CronJobs when running
`kustomize cfg tree` with the `--image` flag (or other resource flag).
2024-01-04 14:45:07 +00:00
Kubernetes Prow Robot
f72db33d5e Merge pull request #4558 from koba1t/proposals/replacements_and_patch_to_value_in_the_structured_data
Proposal: Replacements and Patch value in the structured data
2024-01-04 00:05:48 +01:00
Kubernetes Prow Robot
cfa2c41b44 Merge pull request #5361 from kubernetes-sigs/dependabot/npm_and_yarn/site/postcss-8.4.31
build(deps-dev): bump postcss from 8.4.8 to 8.4.31 in /site
2023-12-28 12:41:51 +01:00
Kubernetes Prow Robot
0c461d61df Merge pull request #5495 from stormqueen1990/chore/removetest-internal-package
chore: move removetest.go to the internal package
2023-12-22 11:06:54 +01:00
Mauren Berti
27ae0693b4 fix: rename helper structs to use more specific names 2023-12-21 22:51:18 -05:00
Mauren Berti
42d5870546 chore: move removetest_testutils.go to internal/testutils 2023-12-21 22:51:17 -05:00
Mauren Berti
f814039f99 chore: move removetest.go to the internal package
* Move the edit/remove_test/removetest.go file to the internal package, as it is
  intended to aid testing.
* Rename the method ExecuteTestCases to ExecuteRemoveTestCases.
2023-12-21 22:51:16 -05:00
Kubernetes Prow Robot
b28e0445a2 Merge pull request #5489 from ltearno/fixtypo-in-merge2
Fix typo in merge2
2023-12-21 12:11:55 +01:00
Kubernetes Prow Robot
7db7de65c1 Merge pull request #5479 from skitt/revert-5197
Revert "Switch to json-patch v5"
2023-12-20 20:56:28 +01:00
koba1t
a34dd1fc3f fix replacements syntax 2023-12-17 05:48:56 +09:00
chansuke
cd886102a9 Fix version tag management 2023-12-15 00:32:36 +09:00
koba1t
2831689a1b update configMapGenerator section 2023-12-14 21:55:58 +09:00
koba1t
069c5fd5d7 add story4 details 2023-12-14 21:55:58 +09:00
koba1t
504e805da0 add non-goal 2023-12-14 21:55:58 +09:00
koba1t
3cf12635d4 scope change to support only JSON/YAML and add support secretGenerator 2023-12-14 21:55:58 +09:00
koba1t
9adb7535fa move behavior: merge in base 2023-12-14 21:55:58 +09:00
koba1t
c87c7a139c fix with suggestion from natasha41575 2023-12-14 21:55:58 +09:00
koba1t
50583c4b0e add Story of yaml in configmap and json in Annotations 2023-12-14 21:55:58 +09:00
koba1t
9a7014cc14 add proposal 'Disciplined merge the value in structured data with configMapGenerator' 2023-12-14 21:55:58 +09:00
koba1t
32a78f3915 fix motivation, this function is scoped edit 2023-12-14 21:55:58 +09:00
koba1t
f866701088 improve 'Replacement the value in structured data' 2023-12-14 21:55:58 +09:00
koba1t
49e911fcef add mini-Kep 'Replacements and Patch value in the structured data' 2023-12-14 21:55:58 +09:00
Arnaud Tournier
665bfbc32d fix typo 2023-12-13 17:50:41 +01:00
Kubernetes Prow Robot
a0a9bdfe05 Merge pull request #5483 from kubernetes-sigs/dependabot/github_actions/actions/setup-go-5
build(deps): bump actions/setup-go from 3 to 5
2023-12-12 06:00:11 +01:00
dependabot[bot]
16f7e42392 build(deps): bump actions/setup-go from 3 to 5
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 3 to 5.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/v3...v5)

---
updated-dependencies:
- dependency-name: actions/setup-go
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-11 00:46:34 +00:00
Stephen Kitt
bf485f66d3 Revert "Switch to json-patch v5"
This reverts commit b692e49b1e.

The json-patch bump in k/k was reverted, so the corresponding bump in
kustomize should be reverted too.

Signed-off-by: Stephen Kitt <skitt@redhat.com>
2023-12-07 18:40:29 +01:00
yugo kobayashi
557d6cba2d Merge pull request #5478 from koba1t/unpinEverything
Back to development mode; unpin the modules
2023-12-07 20:11:28 +09:00
koba1t
8eee90d2c6 Back to development mode; unpin the modules 2023-12-07 19:56:35 +09:00
yugo kobayashi
9da0cf8b4c Merge pull request #5477 from koba1t/pinToApi
Update api to v0.16.0
2023-12-07 19:40:41 +09:00
koba1t
c259c478e5 Update api to v0.16.0 2023-12-07 19:30:36 +09:00
yugo kobayashi
c2ec4bb482 Merge pull request #5476 from koba1t/pinToCmdConfig
Update cmd/config to v0.13.0
2023-12-07 19:25:28 +09:00
koba1t
29d0214cbd Update cmd/config to v0.13.0 2023-12-07 19:16:32 +09:00
yugo kobayashi
faf93bb71d Merge pull request #5475 from koba1t/pinToKyaml
Update kyaml to v0.16.0
2023-12-07 19:11:21 +09:00
koba1t
71f6f4c7d7 Update kyaml to v0.16.0 2023-12-07 19:00:00 +09:00
Kubernetes Prow Robot
b22dbc7db9 Merge pull request #5326 from kubernetes-sigs/dependabot/github_actions/actions/checkout-4
Bump actions/checkout from 3 to 4
2023-12-07 05:13:11 +01:00
Kubernetes Prow Robot
bfe18b8198 Merge pull request #5309 from kubernetes-sigs/dependabot/github_actions/joelanford/go-apidiff-0.7.0
Bump joelanford/go-apidiff from 0.6.0 to 0.7.0
2023-12-07 05:13:04 +01:00
Sylvain Rabot
82bd395289 Add missing error handling for --load-restrictor completion
Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
2023-12-06 10:34:08 +01:00
Sylvain Rabot
e3031f3a7b Add build --load-restrictor completion
Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
2023-12-06 10:34:08 +01:00
Kubernetes Prow Robot
6f47203e3f Merge pull request #5469 from ncapps/add/reviewer
Add ncapps to reviewers
2023-12-01 17:19:11 +01:00
Nick Capps
afc2357d5f Add ncapps to reviewers 2023-11-30 19:55:39 -08:00
Kubernetes Prow Robot
c1ae80d25d Merge pull request #5454 from stormqueen1990/fix/support-namespace-remove
fix: support namespace flag on edit remove secret/configmap
2023-11-30 21:05:05 +01:00
Nick
f23d45fcb4 Add deprecation warning message to commonLabels (#5464)
* Add commonLabels deprecation warning message

* Add test

* Add warningToRunEditFix message
2023-11-30 17:41:43 +01:00
Kubernetes Prow Robot
0b4974eb1c Merge pull request #5461 from kundan2707/type_kustomization
fix typo in kustomization.yaml
2023-11-29 19:33:55 +01:00
Mauren Berti
228d22cff0 fix: support namespace flag on edit remove secret/configmap
Fix the 'edit remove secret'/'edit remove configmap' commands that were previously
missing support to specifying a namespace.
2023-11-28 21:22:31 -05:00
Claudio Busse
7b1eaf1e4f feat: localize absolute paths 2023-11-26 12:22:15 +01:00
Nick
bfb00ecb27 Add common Tasks to documentation (#5383)
* Add labels, annotations, namespaces, and names tasks

* Remove redundant information from ref/labels ref/annotations

* Update labels and annotations example names for consistency

* Remove name, prefix and suffix api examples

* Add link to tasks in reference

* Add link to tasks section for ref/configMapGenerator and ref/secretGenerator

* Add Labels/Annotatations headers

* Add Labels

* Add Template Labels

* Cleanup Add Template Labels

* Consolidate commonLabels and labels.includeSelectors

* Improve commonAnnotations example

* Add labels and annotations ref links

* Add generated ConfigMap to namespace example

* Add name headers

* Change header weights so they appear in sidebar

* Add namespace/name links

* Add generated ConfigMap to namePrefix example

* Add name propagation example

* Add more description of name propagation

* template labels

* Address feedback for labels

* Address names feedback

* Update for consistency

* Address feedback

* Remove API
2023-11-25 21:34:10 +01:00
sarab
fefa21fa01 Add conditional doc check in go workflow
Add checkout
2023-11-24 14:41:40 +05:30
Kundan Kumar
bb7003e557 fix type in kustomization.yaml 2023-11-23 19:18:15 +05:30
Kubernetes Prow Robot
0122aa82ef Merge pull request #5456 from stormqueen1990/chore/rename-add-set-files
chore: rename files to match package pattern
2023-11-20 23:40:36 +01:00
Natasha Sarkar
7db6c203d5 Merge pull request #5453 from varshaprasad96/add-self-to-reviewers
Add varshaprasad96 to Reviewers
2023-11-20 15:08:25 -06:00
Kubernetes Prow Robot
42394090df Merge pull request #5455 from stormqueen1990/fix/cmsecretargs-flaky-test
fix: flaky ConfigMap/Secret args tests
2023-11-20 17:25:23 +01:00
Mauren Berti
447d433457 chore: rename files to match package pattern
Rename files that deal with configmaps and secrets to include the name of the
package as a prefix, as those were not following the pattern from the remaining
files in the package before.
2023-11-18 18:44:48 -05:00
Mauren Berti
9b54286933 fix: flaky ConfigMap/Secret args tests
* Fix a mistake in the comparison between elements in the ConfigMap and Secret args
  test that causes it to become flaky.
* Rename the package in configmapSecretFlagsAndArgs_test.go back to util since the
  testpackage linter has been disabled.
2023-11-18 18:26:52 -05:00
Varsha Prasad Narsing
d2549312d6 Add varshaprasad96 to Reviewers
Signed-off-by: Varsha Prasad Narsing <varshaprasad96@gmail.com>
2023-11-17 17:07:10 -05:00
Joseph Gu
fdf8f44c90 Fix nil pointer dereferencing when converting vars to replacements (#5211)
* fix patch.Target is nil in writePatchTargets

* add test case

* lint

* lint err not check

* remove new lin in imports

* rollback changes to `cmd :=`

* remove extra lines
2023-11-17 19:28:00 +01:00
Mauren Berti
30893b0184 feat: edit set configmap (#5391)
* feat: add new command 'edit set configmap'

* Add a new command 'edit set configmap' to allow editing the values of an
  already-existing configmap in a kustomization file.
* Add tests to validate the new feature.

* fix: add tests, minor refactoring to use constants

* Include tests to validade the new function ValidateSet, included to do
  necessary validations when running the 'kustomize edit set configmap' command.
* Minor refactorings to use the existing constants in the 'edit set configmap'
  command.
* Add dashes before each item in the comment explaining how ExpandFileSource()
  works so IDEs don't try to reformat the list and remove the indentation in it.
* Because this change mutates the list of literal sources, ensure that both add
  and set save the resulting list in a predictable order to make it easier to
  check when new items are added/removed and aid in testing.
* Since literal sources are the only bit that's important in this test, verify
  that the literal sources in the actual result is equal to what we expected it
  to be.

* fix: change format to print resource name

Use '%q' formatter instead of '%s' to print resource name

Co-authored-by: Varsha <varshaprasad96@gmail.com>

* fix: add changes from code review

* Unexport constant that is used only in the scope of a single function.
* Add extra validation to ensure format is correct with one single '=' per key-value
  pair.
* Add extra set of tests to validate format.
* Update test case to match new printed format in the error message.

* fix: rollback sort for edit add/set configmap

* chore: rename test package and unexport functions

Rename the test package from set_test back to set and unexport functions that do
not need to be exported anymore for testing purposes.

* feat: handle empty and default namespace as equal

Handle the empty and the default namespaces as equal. Add tests to validate this
scenario.

---------

Co-authored-by: Varsha <varshaprasad96@gmail.com>
2023-11-17 19:14:53 +01:00
Kubernetes Prow Robot
eb7f91ffcd Merge pull request #5270 from MrFreezeex/helm-kube-api
helm: add support for kube-version and add cli args for both kube-version and api-versions
2023-11-15 21:13:59 +01:00
Kubernetes Prow Robot
413e01e52c Merge pull request #5450 from stormqueen1990/patch-1
Add myself as a reviewer to Kustomize
2023-11-15 20:02:48 +01:00
Mauren Berti
b57b3abc49 Add myself as a reviewer to Kustomize
Based on my contributions in the past 3 months I would like to propose becoming a reviewer for Kustomize.
2023-11-15 13:49:53 -05:00
Kubernetes Prow Robot
4ae9f53593 Merge pull request #5439 from charles-chenzz/windows_release_binary_name
add back the missing suffix in kustomize v5.x.x in windows version
2023-11-15 18:39:51 +01:00
Kubernetes Prow Robot
265195ca80 Merge pull request #5430 from stormqueen1990/fix/treat-empty-ns-as-default-ns
fix: handle empty namespace as default
2023-11-15 18:39:33 +01:00
Kubernetes Prow Robot
8b52e04c3a Merge pull request #5448 from stormqueen1990/chore/remove-testpackage-linter
chore: disable testpackage linter
2023-11-15 15:39:49 +01:00
Mauren Berti
572a096e60 chore: disable testpackage linter 2023-11-14 21:12:05 -05:00
Mauren Berti
4d7b8efc3e fix: revert package name change 2023-11-13 21:56:07 -05:00
Mauren Berti
fa32631993 chore: revert changes to go.work.sum
Revert changes made to go.work.sum, since they don't pertain to code changed in
this PR.
2023-11-13 21:50:19 -05:00
charles-chenzz
ec3be81217 add back the missing suffix in kustomize v5.x.x in windows version
Co-authored-by: Ricardo <ricardo.bartels@telekom.de>
2023-11-13 20:08:58 +08:00
Mauren Berti
53c86258a6 fix: run go mod tidy to remove unused package ref
Run go mod tidy to remove references of golang.org/x/exp, that was used during
development but later removed.
2023-11-11 10:46:27 -05:00
Mauren Berti
7226ba5086 fix: handle empty namespace as default
Update the namespace handling in the edit add configmap and secret commands to
handle the empty namespace and the default namespace in the same way. Before
this change, if a configmap/secret was created using kustomize edit add where
one command was issued with default as the namespace and the other without a
namespace specified it would create two separate configmap generators, and then
kustomize build would fail if merge was not the strategy for either.
2023-11-11 10:46:24 -05:00
Kubernetes Prow Robot
e219b8864e Merge pull request #5421 from prashantrewar/swap-yaml-library
Replace gopkg.in/yaml.v2 with sigs.k8s.io/yaml/goyaml.v2
2023-11-10 17:14:41 +01:00
Kubernetes Prow Robot
863ca93f0b Merge pull request #5364 from 0xff-dev/master
fix: goroutine leak
2023-11-10 17:14:34 +01:00
Kubernetes Prow Robot
68e0997dc9 Merge pull request #5356 from charles-chenzz/deps
update dependabot to enable CVE detect
2023-11-09 20:39:19 +01:00
Arthur Outhenin-Chalandre
dc29923a08 helm: add tests with different kubeVersion
Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@ledger.fr>
2023-11-09 11:37:14 +01:00
0xff-dev
f7bc0aced8 fix: goroutine leak 2023-11-06 13:12:22 +08:00
Nick
e7c8ed1899 Add contributor guide (#5426)
* Add contributor guide

* git merge upstream/master

* git rebase upstream/master

* make test-unit-all

* make lint
2023-11-03 22:36:14 +01:00
Kubernetes Prow Robot
b8443683f9 Merge pull request #5390 from chansuke/add-negative-test-for-kv
Add negative case for testing `keyValuesFromLine`
2023-11-03 17:29:43 +01:00
Carl Henrik Lunde
2fda12d220 perf: MakeDefaultConfig once (#5082)
* perf: MakeDefaultConfig once

This shaves of another 2 seconds (62%) of the remaining execution
time for a kustomization tree with 4000 documents, reducing the execution
time from 4.79s to 1.82s

    0     0%  1.38%      2.98s 37.25%  sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig.MakeDefaultConfig

before:

    (pprof) top30 -cum
    Showing nodes accounting for 1.82s, 22.75% of 8s total
    Dropped 408 nodes (cum <= 0.04s)
    Showing top 30 nodes out of 308
        flat  flat%   sum%        cum   cum%
            0     0%     0%      4.79s 59.88%  github.com/spf13/cobra.(*Command).Execute
            0     0%     0%      4.79s 59.88%  github.com/spf13/cobra.(*Command).ExecuteC
            0     0%     0%      4.79s 59.88%  github.com/spf13/cobra.(*Command).execute
            0     0%     0%      4.79s 59.88%  main.main
            0     0%     0%      4.79s 59.88%  runtime.main
            0     0%     0%      4.79s 59.88%  sigs.k8s.io/kustomize/kustomize/v5/commands/build.NewCmdBuild.func1
            0     0%     0%      4.22s 52.75%  sigs.k8s.io/kustomize/api/krusty.(*Kustomizer).Run
            0     0%     0%      4.18s 52.25%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).MakeCustomizedResMap (inline)
            0     0%     0%      4.18s 52.25%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).makeCustomizedResMap
            0     0%     0%      4.06s 50.75%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).AccumulateTarget
            0     0%     0%      4.06s 50.75%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).accumulateResources
            0     0%     0%      4.06s 50.75%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).accumulateTarget
            0     0%     0%      4.05s 50.62%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).accumulateDirectory
            0     0%     0%      3.22s 40.25%  runtime.systemstack
            0     0%     0%      3.03s 37.88%  runtime.gcBgMarkWorker
            0     0%     0%      3.03s 37.88%  runtime.gcBgMarkWorker.func2
        0.11s  1.38%  1.38%      3.03s 37.88%  runtime.gcDrain
            0     0%  1.38%      2.98s 37.25%  sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig.MakeDefaultConfig
            0     0%  1.38%      2.98s 37.25%  sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig.MakeTransformerConfig
            0     0%  1.38%      2.98s 37.25%  sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig.makeTransformerConfigFromBytes
            0     0%  1.38%      2.97s 37.12%  sigs.k8s.io/yaml.yamlUnmarshal
            0     0%  1.38%      2.91s 36.38%  sigs.k8s.io/yaml.Unmarshal (inline)
        1.34s 16.75% 18.12%      2.87s 35.88%  runtime.scanobject
            0     0% 18.12%      2.53s 31.62%  sigs.k8s.io/yaml.yamlToJSON
            0     0% 18.12%      1.91s 23.88%  gopkg.in/yaml%2ev2.unmarshal
            0     0% 18.12%      1.86s 23.25%  gopkg.in/yaml%2ev2.Unmarshal (partial-inline)
            0     0% 18.12%      1.43s 17.88%  gopkg.in/yaml%2ev2.(*parser).parse
        0.01s  0.12% 18.25%      1.27s 15.88%  gopkg.in/yaml%2ev2.(*parser).document
        0.01s  0.12% 18.38%      1.25s 15.62%  gopkg.in/yaml%2ev2.(*parser).mapping
        0.35s  4.38% 22.75%      1.21s 15.12%  runtime.mallocgc

after:

    (pprof) top30 -cum
    Showing nodes accounting for 0.84s, 24.42% of 3.44s total
    Dropped 225 nodes (cum <= 0.02s)
    Showing top 30 nodes out of 345
        flat  flat%   sum%        cum   cum%
            0     0%     0%      1.82s 52.91%  github.com/spf13/cobra.(*Command).Execute
            0     0%     0%      1.82s 52.91%  github.com/spf13/cobra.(*Command).ExecuteC
            0     0%     0%      1.82s 52.91%  github.com/spf13/cobra.(*Command).execute
            0     0%     0%      1.82s 52.91%  main.main
            0     0%     0%      1.82s 52.91%  runtime.main
            0     0%     0%      1.82s 52.91%  sigs.k8s.io/kustomize/kustomize/v5/commands/build.NewCmdBuild.func1
            0     0%     0%      1.57s 45.64%  runtime.systemstack
            0     0%     0%      1.49s 43.31%  runtime.gcBgMarkWorker
            0     0%     0%      1.49s 43.31%  runtime.gcBgMarkWorker.func2
        0.03s  0.87%  0.87%      1.49s 43.31%  runtime.gcDrain
        0.62s 18.02% 18.90%      1.45s 42.15%  runtime.scanobject
            0     0% 18.90%      1.25s 36.34%  sigs.k8s.io/kustomize/api/krusty.(*Kustomizer).Run
            0     0% 18.90%      1.21s 35.17%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).MakeCustomizedResMap (inline)
            0     0% 18.90%      1.21s 35.17%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).makeCustomizedResMap
            0     0% 18.90%      1.08s 31.40%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).AccumulateTarget
            0     0% 18.90%      1.08s 31.40%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).accumulateResources
            0     0% 18.90%      1.08s 31.40%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).accumulateTarget
            0     0% 18.90%      1.07s 31.10%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).accumulateDirectory
            0     0% 18.90%      0.57s 16.57%  sigs.k8s.io/kustomize/api/resmap.(*resWrangler).AsYaml
            0     0% 18.90%      0.57s 16.57%  sigs.k8s.io/kustomize/api/resource.(*Resource).AsYAML
        0.11s  3.20% 22.09%      0.48s 13.95%  runtime.mallocgc
            0     0% 22.09%      0.45s 13.08%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).accumulateFile
            0     0% 22.09%      0.45s 13.08%  sigs.k8s.io/kustomize/api/resmap.(*Factory).FromFile
            0     0% 22.09%      0.33s  9.59%  sigs.k8s.io/kustomize/kyaml/yaml.(*RNode).MarshalJSON
        0.08s  2.33% 24.42%      0.32s  9.30%  runtime.greyobject
            0     0% 24.42%      0.30s  8.72%  sigs.k8s.io/kustomize/api/resmap.(*Factory).NewResMapFromBytes
            0     0% 24.42%      0.27s  7.85%  sigs.k8s.io/yaml.JSONToYAML
            0     0% 24.42%      0.25s  7.27%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).runTransformers
            0     0% 24.42%      0.25s  7.27%  sigs.k8s.io/kustomize/api/resource.(*Factory).RNodesFromBytes
            0     0% 24.42%      0.25s  7.27%  sigs.k8s.io/kustomize/api/resource.(*Factory).SliceFromBytes

* Tests and comments for MakeDefaultConfig perf work

Document updated code in MakeDefaultConfig.
Add unit tests to ensure DeepCopy works.
Add hints to other code to ensure DeepCopy is kept up to date.
2023-11-02 22:54:42 +01:00
Arthur Outhenin-Chalandre
790ca0e7b6 helm: add kube-version and api-versions on CLI args
It makes sense to add that as a CLI args since you could use one single
kustomization file/helm chart for multiple clusters. Also it's easier to
have those on the CLI if the user has some kind of tooling that will end
up calling kustomize and that could pass those (i.e.: ArgoCD is doing
that for Helm so it could do that for Kustomize as well that will end up
calling Helm as well).

Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@ledger.fr>
2023-11-02 16:46:41 +01:00
Arthur Outhenin-Chalandre
d5dd5f4567 helm: add kube-version
Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@ledger.fr>
2023-11-02 16:46:41 +01:00
Kubernetes Prow Robot
5b51722720 Merge pull request #5293 from ardikabs/fix/5164
fix: local helm chart with version but no repo
2023-11-02 14:58:17 +01:00
Ardika Bagus
6640f8799e test: add Kustomize test case for multiple helm charts with different version
Signed-off-by: Ardika Bagus <me@ardikabs.com>
2023-11-02 06:27:39 +07:00
Ardika Bagus
790dbf0fdf chore: rename chart and test case with clear intention 2023-11-02 06:23:50 +07:00
Ardika Bagus
b7b85b10fc chore: remove unnecessary code, and using testdata instead of inline
Signed-off-by: Ardika Bagus <me@ardikabs.com>
2023-11-02 06:23:50 +07:00
Ardika Bagus
5505af439a chore: fix lint, assert with required 2023-11-02 06:22:11 +07:00
Ardika Bagus
cc35d3c4e5 fix: fix while using local charts with version
fix https://github.com/kubernetes-sigs/kustomize/issues/5163

Signed-off-by: Ardika Bagus <me@ardikabs.com>
2023-11-02 06:22:11 +07:00
Dustin Lish
a0f131cf86 Fix using same helm chart with different versions (#4999)
* Fix using same helm chart with different versions

* Fix p.ValuesFile when version is set

* Updated: Fix using same helm chart with different versions

* Add test for issue #4813

* Use if/else for readability, add version check to absChartHome
2023-11-02 06:22:11 +07:00
Kubernetes Prow Robot
f87942ec76 Merge pull request #5328 from koba1t/fix/failed_tests_are_depends_on_external_container_images
fix failed tests are depends on external container images
2023-11-01 20:01:53 +01:00
koba1t
af7c088053 fix failed tests for fn framework mount generator 2023-11-02 02:37:00 +09:00
koba1t
7af4e772bd fix failed tests for fn framework generator 2023-11-02 02:37:00 +09:00
koba1t
67a0b43c81 fix failed tests for testing fn framework about get value from env 2023-11-02 02:37:00 +09:00
koba1t
2bff0d6882 fix failure tests that are running for external container image 2023-11-02 02:37:00 +09:00
Prashant Rewar
2ab117166f replace gopkg.in/yaml.v2 with sigs.k8s.io/yaml/goyaml.v2
Signed-off-by: Prashant Rewar <108176843+prashantrewar@users.noreply.github.com>
2023-11-01 14:40:41 +05:30
Kubernetes Prow Robot
8effd35d3f Merge pull request #5424 from sylr/go-work-sync
Run go work sync
2023-10-31 21:33:44 +01:00
Carl Henrik Lunde
5c7f8b8d73 perf: improve applyOrdering by avoid call to GetByCurrentId
This shaves of 14 seconds (one third) of the execution time for a
kustomization tree with 4000 documents, from 40.68s to 27.41s

            0     0%  5.44%     18.42s 40.56%  sigs.k8s.io/kustomize/api/krusty.(*Kustomizer).applySortOrder
            0     0%  5.44%     18.40s 40.52%  sigs.k8s.io/kustomize/api/internal/builtins.applyOrdering
before

    (pprof) top20 -cum
    Showing nodes accounting for 5.85s, 12.88% of 45.41s total
    Dropped 622 nodes (cum <= 0.23s)
    Showing top 20 nodes out of 157
        flat  flat%   sum%        cum   cum%
            0     0%     0%     40.68s 89.58%  github.com/spf13/cobra.(*Command).Execute
            0     0%     0%     40.68s 89.58%  github.com/spf13/cobra.(*Command).ExecuteC
            0     0%     0%     40.68s 89.58%  github.com/spf13/cobra.(*Command).execute
            0     0%     0%     40.68s 89.58%  main.main
            0     0%     0%     40.68s 89.58%  runtime.main
            0     0%     0%     40.68s 89.58%  sigs.k8s.io/kustomize/kustomize/v5/commands/build.NewCmdBuild.func1
            0     0%     0%     40.12s 88.35%  sigs.k8s.io/kustomize/api/krusty.(*Kustomizer).Run
        0.51s  1.12%  1.12%     33.20s 73.11%  sigs.k8s.io/kustomize/api/resource.(*Resource).CurId
            0     0%  1.12%     26.95s 59.35%  sigs.k8s.io/kustomize/api/resmap.(*resWrangler).GetMatchingResourcesByCurrentId
        0.35s  0.77%  1.89%     26.95s 59.35%  sigs.k8s.io/kustomize/api/resmap.(*resWrangler).filteredById
        0.07s  0.15%  2.05%     25.53s 56.22%  sigs.k8s.io/kustomize/api/resmap.GetCurrentId
            0     0%  2.05%     21.68s 47.74%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).MakeCustomizedResMap (inline)
            0     0%  2.05%     21.68s 47.74%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).makeCustomizedResMap
        0.54s  1.19%  3.24%     19.75s 43.49%  sigs.k8s.io/kustomize/api/resource.(*Resource).GetGvk (inline)
            1s  2.20%  5.44%     19.21s 42.30%  sigs.k8s.io/kustomize/kyaml/resid.GvkFromNode
            0     0%  5.44%     18.42s 40.56%  sigs.k8s.io/kustomize/api/internal/builtins.(*SortOrderTransformerPlugin).Transform
            0     0%  5.44%     18.42s 40.56%  sigs.k8s.io/kustomize/api/krusty.(*Kustomizer).applySortOrder
            0     0%  5.44%     18.40s 40.52%  sigs.k8s.io/kustomize/api/internal/builtins.applyOrdering
        0.87s  1.92%  7.36%     16.55s 36.45%  sigs.k8s.io/kustomize/kyaml/yaml.visitMappingNodeFields
        2.51s  5.53% 12.88%     15.68s 34.53%  sigs.k8s.io/kustomize/kyaml/yaml.visitFieldsWhileTrue

after

    (pprof) top20 -cum
    Showing nodes accounting for 1.23s, 3.85% of 31.98s total
    Dropped 584 nodes (cum <= 0.16s)
    Showing top 20 nodes out of 184
        flat  flat%   sum%        cum   cum%
            0     0%     0%     27.41s 85.71%  github.com/spf13/cobra.(*Command).Execute
            0     0%     0%     27.41s 85.71%  github.com/spf13/cobra.(*Command).ExecuteC
            0     0%     0%     27.41s 85.71%  github.com/spf13/cobra.(*Command).execute
            0     0%     0%     27.41s 85.71%  main.main
            0     0%     0%     27.41s 85.71%  runtime.main
            0     0%     0%     27.41s 85.71%  sigs.k8s.io/kustomize/kustomize/v5/commands/build.NewCmdBuild.func1
            0     0%     0%     26.85s 83.96%  sigs.k8s.io/kustomize/api/krusty.(*Kustomizer).Run
            0     0%     0%     22.07s 69.01%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).MakeCustomizedResMap (inline)
            0     0%     0%     22.07s 69.01%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).makeCustomizedResMap
        0.38s  1.19%  1.19%     20.69s 64.70%  sigs.k8s.io/kustomize/api/resource.(*Resource).CurId
            0     0%  1.19%     13.64s 42.65%  sigs.k8s.io/kustomize/api/resmap.(*resWrangler).Append
            0     0%  1.19%     13.55s 42.37%  sigs.k8s.io/kustomize/api/resmap.(*resWrangler).GetMatchingResourcesByCurrentId (inline)
        0.12s  0.38%  1.56%     13.55s 42.37%  sigs.k8s.io/kustomize/api/resmap.(*resWrangler).filteredById
        0.01s 0.031%  1.59%     12.67s 39.62%  sigs.k8s.io/kustomize/api/resmap.GetCurrentId
        0.21s  0.66%  2.25%     12.49s 39.06%  sigs.k8s.io/kustomize/api/resource.(*Resource).GetGvk (inline)
        0.51s  1.59%  3.85%     12.28s 38.40%  sigs.k8s.io/kustomize/kyaml/resid.GvkFromNode
            0     0%  3.85%     11.52s 36.02%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).IgnoreLocal
            0     0%  3.85%     10.53s 32.93%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).AccumulateTarget
            0     0%  3.85%     10.53s 32.93%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).accumulateResources
            0     0%  3.85%     10.53s 32.93%  sigs.k8s.io/kustomize/api/internal/target.(*KustTarget).accumulateTarget
2023-10-30 22:31:52 +01:00
Sylvain Rabot
b1f100e3da Run go work sync and go mod tidy
```shell
go work sync
for i in $(find . -name go.mod); do (cd $(dirname $i); go mod tidy); done
```

Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
2023-10-28 13:05:11 +02:00
chansuke
e002b49244 hotfix: return error instead of log at FromMapAndOption (#5381)
* hotfix: return error instead of log at `FromMapAndOption`

* chore: show error message

* hotfix: use correct function

* hotix: use `t.Helper()` and fix `t *testing.T order

* hotfix: wrapt the error of `FromMapAndOption`

* hotfix: meaningful message for an error

* hotfix: summarize in one line

* hotfix: fix the abandoned error and show meaningful message

* hotfix: start with helper function

* Keep TODO comment
2023-10-27 23:01:47 +02:00
Nick
bd435d4154 Add Generator Tasks to Documentation (#5368)
* Update tasks index description

* Create generators folder

* Update tasks/generators titles

* Add rollouts placeholder

* Add generate configmap from file example

* Add literals and env file example

* Add propogation example

* Consistent punctuation

* Update grammar

* Clean up configmaps page

* Remove examples from configMapGenerator ref page

* Move secret examples to Tasks

* Clean up spacing

* Consolidate cm and secret

* Consistent grammar

* Cleanup

* Address feedback

* Bump date

* Fix propagate spelling

* Remove roll out updates section

* Separate configmap and secret generator tasks

* Add secret from file example

* Add secret from literals example

* Update tls secret example

* Update task page weights

* Link cm generator reference

* Add link to secret reference

* Remove secretGenerator example from reference section

* Add configmap options task, clean up reference

* Add file with key example

* Secrets are base64 encoded
2023-10-27 22:26:37 +02:00
Kubernetes Prow Robot
a869386996 Merge pull request #5423 from natasha41575/roadmap-update
update roadmap based on review comments
2023-10-27 18:54:58 +02:00
Kubernetes Prow Robot
a40379782e Merge pull request #5420 from soltysh/security_contants
Update security contacts for sig-cli
2023-10-27 18:37:56 +02:00
Natasha Sarkar
761893d1fc Merge pull request #5351 from natasha41575/roadmap
update kustomize roadmap 23-24
2023-10-27 11:20:58 -05:00
natasha41575
9f4f9b323c review comments 2023-10-27 10:59:30 -05:00
Kubernetes Prow Robot
48fd585620 Merge pull request #5408 from koba1t/fix_add_checksum_create_step_in_release_scripts
fix add checksum create step in release scripts
2023-10-27 02:29:19 +02:00
Natasha Sarkar
96ad106ee1 Use upstream go-yaml fork and remove our internal one (#5412)
* test new yaml fork

* delete old kyaml fork

* update to sigs yaml 1.4.0

* remove comments
2023-10-25 19:48:22 +02:00
Maciej Szulik
e2b0297d18 Update security contacts for sig-cli 2023-10-25 19:02:36 +02:00
koba1t
d6fa69d26e use pushd when generate checksum 2023-10-25 05:19:25 +09:00
Kubernetes Prow Robot
cba3f1115f Merge pull request #5409 from stormqueen1990/refactor/move-reusable-set-bits
refactor: move reusable bits in preparation for new 'edit set' commands
2023-10-23 17:45:58 +02:00
Mauren Berti
5568521cd1 fix: lint issues
Change package for test to 'util_test' and add dot-import for the main package.
2023-10-21 17:47:49 -04:00
Mauren Berti
a5a2db577f refactor: move reusable bits in preparation for edit set commands
* Move configmapSecretFlagsAndArgs.go to the internal/util folder so it can be
  reused by the edit set commands.
2023-10-21 16:55:37 -04:00
koba1t
b6387b9eaf fix add checksum create step in release scripts 2023-10-21 15:41:00 +09:00
Kubernetes Prow Robot
0f2618b21d Merge pull request #5402 from koba1t/unpinEverything
release cleanup, unpin the modules
2023-10-19 22:58:25 +02:00
koba1t
0465637335 Back to development mode; unpin the modules 2023-10-20 05:30:43 +09:00
Natasha Sarkar
e71072b90b Merge pull request #5397 from koba1t/fix_release_binary_archive_contains_unnecessary_dir
fix release binary archive contains unnecessary dir
2023-10-19 15:11:23 -05:00
koba1t
289e78c136 fix release binary archive contains unnecessary dir 2023-10-20 04:00:13 +09:00
Kubernetes Prow Robot
001ab61b37 Merge pull request #5395 from koba1t/pinToApi
Update api to v0.15.0
2023-10-19 19:57:18 +02:00
koba1t
16395012d1 Update api to v0.15.0 2023-10-20 02:36:50 +09:00
Kubernetes Prow Robot
5497967665 Merge pull request #5394 from koba1t/pinToCmdConfig
Update cmd/config to v0.12.0
2023-10-19 19:27:53 +02:00
koba1t
0115ae6da4 Update cmd/config to v0.12.0 2023-10-20 02:11:11 +09:00
Kubernetes Prow Robot
bb5022441a Merge pull request #5393 from koba1t/pinToKyaml
Update kyaml to v0.15.0
2023-10-19 18:59:14 +02:00
koba1t
8668b74622 Update kyaml to v0.15.0 2023-10-20 01:07:49 +09:00
Kubernetes Prow Robot
752bb2ef41 Merge pull request #5303 from antoooks/refactor/ci-tasks-improvement-new
refactor/ci tasks improvement new
2023-10-19 09:41:50 +02:00
Kubernetes Prow Robot
bde28b1320 Merge pull request #5324 from charles-chenzz/fix_doc_refs
update deprecated doc refs
2023-10-18 17:41:01 +02:00
Kubernetes Prow Robot
689dcefa3a Merge pull request #5378 from kubernetes-sigs/dependabot/go_modules/cmd/depprobcheck/golang.org/x/net-0.17.0
build(deps): bump golang.org/x/net from 0.8.0 to 0.17.0 in /cmd/depprobcheck
2023-10-18 16:05:15 +02:00
dependabot[bot]
f3e263a051 build(deps): bump golang.org/x/net in /cmd/depprobcheck
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.8.0 to 0.17.0.
- [Commits](https://github.com/golang/net/compare/v0.8.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-18 13:27:09 +00:00
Kubernetes Prow Robot
fa48ab16bf Merge pull request #5377 from kubernetes-sigs/dependabot/go_modules/functions/examples/application-cr/image/golang.org/x/net-0.17.0
build(deps): bump golang.org/x/net from 0.8.0 to 0.17.0 in /functions/examples/application-cr/image
2023-10-18 15:25:21 +02:00
dependabot[bot]
0eca5c4b06 build(deps): bump golang.org/x/net
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.8.0 to 0.17.0.
- [Commits](https://github.com/golang/net/compare/v0.8.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-17 19:51:16 +00:00
Kubernetes Prow Robot
6b76c807f5 Merge pull request #5376 from kubernetes-sigs/dependabot/go_modules/functions/examples/fn-framework-application/golang.org/x/net-0.17.0
build(deps): bump golang.org/x/net from 0.8.0 to 0.17.0 in /functions/examples/fn-framework-application
2023-10-17 21:48:54 +02:00
dependabot[bot]
76695414c7 build(deps): bump golang.org/x/net
Bumps [golang.org/x/net](https://github.com/golang/net) from 0.8.0 to 0.17.0.
- [Commits](https://github.com/golang/net/compare/v0.8.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/net
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-17 19:24:53 +00:00
Jan-Otto Kröpke
d64ac13447 kustomize: Add support for OCI based helm repos (#5167)
* kustomize: Add support for OCI based helm repos

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* Update api/internal/builtins/HelmChartInflationGenerator.go

* Update plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go

* go fmt

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* s/expectedHelmExternalDns/expectedHelmExternalDNS

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* commit

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* commit with content

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>

* Apply suggestions from maintainer

* go work sync

* added test

---------

Signed-off-by: Jan-Otto Kröpke <joe@cloudeteer.de>
2023-10-17 21:24:00 +02:00
chansuke
50159d47c2 Add negative case for testing keyValuesFromLine 2023-10-17 23:55:04 +09:00
Kubernetes Prow Robot
f80d9c41e5 Merge pull request #5370 from phooijenga/patch-1
merge2: fix duplicate test case
2023-10-14 18:41:37 +02:00
Kubernetes Prow Robot
2f99707792 Merge pull request #5367 from stormqueen1990/fix/edit-add-configmap-namespace
fix: add namespace option to 'edit add configmap' command
2023-10-14 09:39:40 +02:00
Mauren Berti
7a08dde7ac fix: change spaces for tabs 2023-10-13 18:35:27 -04:00
Kubernetes Prow Robot
81297df4ff Merge pull request #5374 from kundan2707/broken_link
Path for glossary.md corrected
2023-10-13 22:14:55 +02:00
Kundan Kumar
c4137c0c2a Path for glossary corrected 2023-10-12 10:29:05 +05:30
charles-chenzz
944c72a275 update deprecated doc refs 2023-10-11 22:30:43 +08:00
Paul
46e2d72213 merge2: fix duplicate test case 2023-10-10 14:12:07 +02:00
Mauren Berti
6cb85e8544 fix: remove unnecessary empty space as per lint 2023-10-09 19:28:37 -04:00
Mauren Berti
6ef9773c02 docs: update comment to reflect usage of namespace
Update the comment for the namespace option to reflect its real usage for both
secret and configmap.
2023-10-09 17:17:49 -04:00
Mauren Berti
11aa57e67f fix: add --namespace flag to edit add configmap
* Add the option to specify a namespace when using 'kustomize edit add configmap'
  for code parity with 'edit add secret'.
* Rename constants for 'add configmap'/'add secret' so they are standardized.
* Create new constant for the 'namespace' flag.
* Update test cases to cover new scenarios.
2023-10-09 17:17:40 -04:00
Kubernetes Prow Robot
779f153071 Merge pull request #5353 from charles-chenzz/git_submodule
git submodule need origin
2023-10-07 03:27:32 +02:00
charles-chenzz
60d7ee6710 add orgin back when clone repo (due to git submodule). 2023-10-07 07:50:13 +08:00
Kubernetes Prow Robot
852739c477 Merge pull request #5265 from rodrigc/update-remote-example
doc: update example to use tag v3.3.1
2023-10-06 21:21:37 +02:00
Craig Rodrigues
bee2e5f50c doc: update example to use tag v3.3.1
Signed-off-by: Craig Rodrigues <rodrigc@crodrigues.org>
2023-10-06 11:38:17 -07:00
Natasha Sarkar
ace2d53b18 Merge pull request #5333 from hailkomputer/add-skip-validation-flag-to-edit-add-resource
Add --no-verify flag to edit add resource command
2023-10-06 13:00:27 -05:00
dependabot[bot]
f910219c7a build(deps-dev): bump postcss from 8.4.8 to 8.4.31 in /site
Bumps [postcss](https://github.com/postcss/postcss) from 8.4.8 to 8.4.31.
- [Release notes](https://github.com/postcss/postcss/releases)
- [Changelog](https://github.com/postcss/postcss/blob/main/CHANGELOG.md)
- [Commits](https://github.com/postcss/postcss/compare/8.4.8...8.4.31)

---
updated-dependencies:
- dependency-name: postcss
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-04 20:07:19 +00:00
Kubernetes Prow Robot
aeb7cb2a40 Merge pull request #5342 from superbrothers/fix-issue4905
Update imdario/mergo to v0.3.13
2023-10-04 22:06:34 +02:00
charles-chenzz
a7e065ddb4 update dependabot to auto bump deps and enable CVE detect 2023-10-03 20:16:56 +08:00
Yigit Demirbas
713842330e rename flag to --no-verify 2023-10-03 09:02:34 +02:00
Yigit Demirbas
5936a892a7 fix imports after rebase 2023-10-02 09:06:07 +02:00
Yigit Demirbas
c3a4f3eab6 Merge branch 'master' into add-skip-validation-flag-to-edit-add-resource 2023-10-02 09:03:14 +02:00
Mauren Berti
fb7ee2f487 refactor: change "add configmap/secret" commands to reuse code and improve tests (#5315)
* feat: minor refactoring + test improvements

* Refactor some bits of the edit add secret/configmap commands to reuse code.
* Improve test coverage for both these commands by invoking the cobra command
  directly.
* Add some reusable constants for both these commands and their tests.

* fix: changes from code review

* Update formatting as requested in code review.
* Rename flagsAndArgs to configmapSecretFlagsAndArgs: change the file and struct
  names to reflect the real usage of this code.
* Remove excessive newlines from the imports block.
* Replace all usages of assert with require and fix newlines in imports.
2023-10-01 19:32:45 -07:00
Kubernetes Prow Robot
45e57f0228 Merge pull request #5350 from kubernetes-sigs/revert-5332-master
Revert "Disable CI Code Checks if all PR changes fall under `site/`"
2023-09-29 15:01:56 -07:00
natasha41575
d20a7c4996 update kustomize roadmap 23-24 2023-09-29 13:57:02 -05:00
Kubernetes Prow Robot
9920586b22 Merge pull request #5345 from stormqueen1990/docs/update-remove-configmap-comment
docs: update remove configmap comment
2023-09-29 11:12:42 -07:00
Kubernetes Prow Robot
61dad14345 Merge pull request #5344 from stormqueen1990/feat/add-remove-secret-command
feat: add remove secret command
2023-09-29 11:02:43 -07:00
Kubernetes Prow Robot
f65506d285 Merge pull request #5268 from kubernetes-sigs/dependabot/github_actions/nashmaniac/create-issue-action-1.2
Bump nashmaniac/create-issue-action from 1.1 to 1.2
2023-09-29 10:52:43 -07:00
Natasha Sarkar
cbbd1599f2 Revert "Disable CI Code Checks if all PR changes fall under site/" 2023-09-29 09:50:39 -05:00
Kubernetes Prow Robot
4b34ff3075 Merge pull request #5132 from samstride/issue/5127
Update README.md
2023-09-28 12:10:34 -07:00
Kubernetes Prow Robot
654d7953d9 Merge pull request #5193 from varshaprasad96/refactor/api
[refactor]: Internalize loader api
2023-09-28 08:36:32 -07:00
Kurnianto Trilaksono
d91ea65f5a separate generate plugins and check diff step 2023-09-28 21:49:57 +07:00
Varsha Prasad Narsing
7911b2c001 [refactor]: Internalize loader api
This PR intends to move the loader api to
internal. Only the necessary methods which
are needed for the api have been put into
`pkg/loader.go`.

Signed-off-by: Varsha Prasad Narsing <varshaprasad96@gmail.com>
2023-09-28 10:49:45 -04:00
Yigit Demirbas
0d854a5144 modify error message to original 2023-09-27 12:52:09 +02:00
Yigit Demirbas
cb5b241715 modify add resource test to accomodate changes 2023-09-27 12:49:19 +02:00
Yigit Demirbas
039b05fb16 refactor tests to use require instead 2023-09-27 12:40:05 +02:00
Mauren Berti
9c1d412dac docs: update remove configmap comment
Update the comment for the newCmdRemoveConfigMap function to explain what this
function really does. The previous comment was referring to a different function.
2023-09-24 19:26:48 -04:00
Mauren Berti
a318d4db26 feat: incorporate feedback from review
* Incorporate feedback from reviews.
* Add extra test cases to increase coverage.
* Tiny refactors for code parity with remove configmap.
* Update copyright notice.
2023-09-24 19:16:37 -04:00
yufei.li
0cfafddacc feat: add remove secret command
(cherry picked from commit 63d44f5e88)

chore: fix for lint

(cherry picked from commit 21edcd0582)

fix: correct lint issues

(cherry picked from commit 0c87856b2c)

fix: Resolve conversations

(cherry picked from commit 9ee5ab3a70)
2023-09-24 18:07:55 -04:00
Kazuki Suda
f5ca753377 Update imdario/mergo to v0.3.13
Co-authored-by: Krzysztof Gibuła <krzysztof.gibula@gmail.com>
Signed-off-by: Kazuki Suda <kazuki.suda@gmail.com>
2023-09-24 16:34:45 +09:00
Kazuki Suda
0d4849ff98 Add a test case for issue 4905
```
===== ACTUAL BEGIN ========================================
apiVersion: v1
data:
  config.yaml: "null"
kind: ConfigMap
metadata:
  name: issue4905
===== ACTUAL END ==========================================
   EXPECTED              ACTUAL
   --------              ------
   apiVersion: v1        apiVersion: v1
   data:                 data:
X    config.yaml: |-       config.yaml: "null"
X      item1: 1          kind: ConfigMap
X      item2: 2          metadata:
X  kind: ConfigMap         name: issue4905
X  metadata:
X    name: issue4905
    hasgett.go:22: Expected not equal to actual
--- FAIL: TestHelmChartInflationGeneratorIssue4905 (0.24s)
```

Signed-off-by: Kazuki Suda <kazuki.suda@gmail.com>
2023-09-24 16:33:43 +09:00
Nick
e3b9afcfaa Add CLI page to Reference Section (#5304)
* Add CLI page

Start operations section

Refine operations section

Add common operations

Address comments

* Move the cli content to the CLI section

Update the CLI description
2023-09-22 23:30:56 -07:00
Kubernetes Prow Robot
af781bfa5e Merge pull request #5313 from bugoverdose/docs/api
Add API section to Reference Section
2023-09-22 22:56:55 -07:00
Kubernetes Prow Robot
7dd9637b1a Merge pull request #5340 from koba1t/add_koba1t_to_approvers
add koba1t to approvers
2023-09-22 13:48:49 -07:00
koba1t
ddce57b585 add koba1t to approvers 2023-09-23 03:37:24 +09:00
Natasha Sarkar
11fc419cee be more specific about reqs in contributing guide (#5330)
* be more specific about reqs in contributing guide

* fix wording
2023-09-22 11:14:48 -07:00
Kubernetes Prow Robot
a8dec66a84 Merge pull request #4486 from koba1t/feature/add_edit_set_labels_subcommand_add_option_for_labels_on_without_selector
add: "edit add labels" command adds an option for labels without selector
2023-09-22 09:36:50 -07:00
Kubernetes Prow Robot
7e541ca380 Merge pull request #5332 from roopeshvs/master
Disable CI Code Checks if all PR changes fall under `site/`
2023-09-20 14:46:02 -07:00
Kubernetes Prow Robot
1bd58bdc15 Merge pull request #5327 from stormqueen1990/feat/add-remove-configmap-command
feat: add remove configmap command
2023-09-20 14:32:01 -07:00
Mauren Berti
9107fa3c81 fix: changes from code review
* Replace last assert directive with require in the test.
* Change copyright notice.
2023-09-19 22:29:33 -04:00
Yigit Demirbas
df0cd3c4a3 modified to fix linter issues 2023-09-18 20:54:56 +02:00
Yigit Demirbas
f3b34c44b5 Add skip-validation flag to edit add resource cmd 2023-09-18 20:22:59 +02:00
Kurnianto Trilaksono
9e101ee97f use doGoMod.sh forr go mod tidy 2023-09-18 23:17:11 +07:00
Roopesh V S
433be59ea7 ignore pr code checks for docs only changes 2023-09-18 19:49:11 +05:30
Jeong Jinwoo
2c444d6bf4 docs(api/kustomizaion-file): migrate field sections 2023-09-17 16:05:32 +09:00
Kurnianto Trilaksono
a90c19d577 Edit commentaries and ensure pluginator logic does not create diff 2023-09-17 00:23:32 +07:00
Kurnianto Trilaksono
8f283499e9 add go mod tidy before workspace sync 2023-09-16 21:47:23 +07:00
Kurnianto Trilaksono
d78fe665a7 add commentaries, change command order on presubmit-check 2023-09-16 21:47:23 +07:00
Kurnianto Trilaksono
532abf77e7 refactor: fix generate-kustimize-builtin-plugins, add diff checker on generate-kustomize-builtin-plugins, add go work sync on presubmit check, add generate-kustomize-builtin-plugins on presubmit check 2023-09-16 21:47:23 +07:00
yugo kobayashi
59696d1ace fix a patch files accept multiple patches (#5194)
* fix a patch files accept multiple patches

* fix comments and variable name

* add error handling when using not allowed multiple strategic-merge patches

* fix error message of Multiple Strategic-Merge Patch file

* refactor transformStrategicMerge()

* add TODO comment and test for Multiple JSON patch Yaml documents are not allowed

* refactoring PatchTransformer

* add multiple patch test for PatchTransformer package

* improve error message to PatchTransformer

* refactor const and error message check

* fix some error messages
2023-09-15 16:20:13 -07:00
Jeong Jinwoo
d30e457031 docs(api/patches): fix broken links 2023-09-14 21:01:25 +09:00
Jeong Jinwoo
ae041b5c54 docs(api/generatorOptions): fill up empty links 2023-09-14 20:54:06 +09:00
Jeong Jinwoo
a2b60e4bcb docs(api): fix broken links 2023-09-14 20:52:11 +09:00
Jeong Jinwoo
9d126f6dd8 docs(api/components): add Components guide from cli-experimental
- add reference to Concept page
2023-09-14 12:55:50 +09:00
Jeong Jinwoo
bd8045b648 docs(api/replacements): fix heavy check mark issue 2023-09-14 12:40:57 +09:00
Jeong Jinwoo
5c1a022a3c docs(api): fix broken hyperlinks 2023-09-14 12:40:57 +09:00
Jeong Jinwoo
e19ca5405a docs: setup API section with cli-experimental site 2023-09-14 12:40:54 +09:00
Kubernetes Prow Robot
56d37acc7d Merge pull request #5261 from varshaprasad96/refactor/image
[Refactor] Move image to internal
2023-09-13 10:22:12 -07:00
Mauren Berti
0571a2f15d Incorporate feedback from original PR
* Incorporate feedback left on original PR.
* Add more test cases.
* Minor refactoring and update to copyright notice.
2023-09-12 20:18:45 -04:00
yufei.li
0cdfa5b3dc feat: add remove configmap command
(cherry picked from commit 0d7c56dcf8)

fix: add logging when configmap not exists

(cherry picked from commit 0235f10b09)

fix: correct lint issues

(cherry picked from commit 8ca1f3813b)

fix: Resolve conversation

(cherry picked from commit 927804dfe5)
2023-09-12 19:21:55 -04:00
dependabot[bot]
7b9880aaab Bump actions/checkout from 3 to 4
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-11 01:11:25 +00:00
Anna Song
7c36ed21b3 Document AnnotationsTransformer (#5247)
* Restructure existing Reference docs

Restructure Reference section for site to better match k8s.io. Change
descriptions to complete sentences. Improve instructions to locally load
site.

* Document AnnotationsTransformer on site

Dcoument AnnotationsTransformer API under Reference on site.

* Document required fields

Document required fields and explain effects of optional ones.

* Make site setup instructions more explicit

* Link required K8s fields
2023-09-08 20:54:10 -07:00
Ed Overton
985835f96f perf: limit initSchema calls from openapi.IsNamespaceScoped (#5076)
* test: add openapi.IsNamespaceScoped benchmark

Add a benchmark test for IsNamespaceScoped performance when the default
schema is in use.

* perf: limit initSchema calls from openapi.IsNamespaceScoped

Avoid calling initSchema from openapi.IsNamespaceScoped when possible.
Work done in #4152 introduced a precomputed namespace scope map based on
the default built-in schema. This commit extends that work by avoiding
calls to initSchema when a resource is not found in the precomputed map
and the default built-in schema is in use. In those cases, there is no
benefit to calling initSchema since the precomputed map is exactly what
will be calculated by parsing the default built-in schema.

* fix: delay parsing of default built-in schema

When namespace scope can be determined by the precomputed map but the
type is not present in the precomputed map, delay the parsing of the
default built-in schema.

If the schema to be initialized is the default built-in schema and the
type is not in the precomputed map, then the type will not be found in
the default built-in schema. There is no need to parse the default
built-in schema for that answer; its parsing may be delayed until it
is needed for some other purpose.

In cases where the schema is used solely for namespace scope checks, the
schema might not ever be parsed. Skipping the parsing reduces both
execution time and memory use.

* fix: correct openapi.go's schemaNotParsed value

openapiData initializes with defaultBuiltInSchemaParseStatus set to 0,
so schemaNotParsed should have 0 as its value.
2023-09-08 12:34:30 -07:00
Kubernetes Prow Robot
f81765b96e Merge pull request #5320 from natasha41575/updatedeps
small fixes
2023-09-08 10:06:14 -07:00
natasha41575
a2ceaff053 small fixes 2023-09-08 11:38:23 -05:00
Kubernetes Prow Robot
94181b1be7 Merge pull request #5291 from irvifa/refactor/remove-setters-config-from-kyaml
refactor: Remove setters from kyaml
2023-09-08 07:54:14 -07:00
dependabot[bot]
9966387002 Bump joelanford/go-apidiff from 0.6.0 to 0.7.0
Bumps [joelanford/go-apidiff](https://github.com/joelanford/go-apidiff) from 0.6.0 to 0.7.0.
- [Release notes](https://github.com/joelanford/go-apidiff/releases)
- [Commits](https://github.com/joelanford/go-apidiff/compare/v0.6.0...v0.7.0)

---
updated-dependencies:
- dependency-name: joelanford/go-apidiff
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-04 01:10:56 +00:00
Kubernetes Prow Robot
169fdd7330 Merge pull request #5196 from ephesused/issue4928-append-honors-key-style
fix: patch additions honor source key style
2023-09-01 09:06:33 -07:00
Ed Overton
78b8139d46 Merge branch 'master' into issue4928-append-honors-key-style 2023-08-30 12:30:49 -04:00
Kubernetes Prow Robot
76f8d2828b Merge pull request #5197 from skitt/json-patch.v5
Switch to json-patch v5
2023-08-28 09:35:45 -07:00
Stephen Kitt
b692e49b1e Switch to json-patch v5
json-patch was bumped to v5 in k/k as a result of
https://github.com/kubernetes/kubernetes/pull/118384; this aligns with
that, but switches to the v5 module, which is documented as
gopkg.in/evanphx/json-patch.v5.

Signed-off-by: Stephen Kitt <skitt@redhat.com>
2023-08-26 08:42:07 +02:00
Kubernetes Prow Robot
bd7f001c26 Merge pull request #5239 from koba1t/chore/change_release_flow
change release flow from using goreleaser to build scripts
2023-08-25 11:54:52 -07:00
Kubernetes Prow Robot
d6ff768298 Merge pull request #5262 from varshaprasad96/refactor/konfig
[Refactor] Internalize konfig constants
2023-08-25 10:18:52 -07:00
Irvi Aini
4947a905fa refactor: Remove setters from kyaml
Kind:

Refactor

Summary:

Setters functionality is provided as a KRM function. We should remove code related to setters in cmd/config and kyaml.
As of now most setters2 and setters usage are related to fork of kpt, however, these:
[fluxcd/image-automation-controller](6827808a1a/pkg/update/filter.go (L24)) with [kyml](6827808a1a/go.mod (L42))
[rancher/fleet](0a6cf6cb92/internal/cmd/controller/controllers/image/update/setters.go (L16)) with [kyaml](0a6cf6cb92/go.mod (L75))

Repositories still using them, They pinned these two into a specific kyaml version. If we decide to go for this removal then we can make a release note that this is actually removed on the next version since we already marked this as deprecated before.
2023-08-24 00:39:47 +08:00
Kubernetes Prow Robot
cd9a16cfab Merge pull request #5273 from natasha41575/pm
add description of PM role to contributing doc
2023-08-22 14:11:55 -07:00
natasha41575
02a53f193d add description of PM role to contributing doc 2023-08-22 15:11:53 -05:00
koba1t
b1717c8a97 change_release_flow_to_build_scripts 2023-08-17 22:57:44 +09:00
Kubernetes Prow Robot
911ddcda40 Merge pull request #5263 from bugoverdose/fix/reject-on-id-change
Fix `reject` needing both current and previous ids
2023-08-14 09:19:22 -07:00
dependabot[bot]
daf06622a2 Bump nashmaniac/create-issue-action from 1.1 to 1.2
Bumps [nashmaniac/create-issue-action](https://github.com/nashmaniac/create-issue-action) from 1.1 to 1.2.
- [Release notes](https://github.com/nashmaniac/create-issue-action/releases)
- [Commits](https://github.com/nashmaniac/create-issue-action/compare/v1.1...v1.2)

---
updated-dependencies:
- dependency-name: nashmaniac/create-issue-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-08-14 00:53:35 +00:00
Jeong Jinwoo
9f1d5acdc8 fix: check both prev and current ids for filtering reject targets 2023-08-11 21:37:55 +09:00
Jeong Jinwoo
9756d92a91 test: demonstrate reject not working on targets with changed id 2023-08-11 21:37:07 +09:00
Natasha Sarkar
d32d1937e6 Merge pull request #5254 from natasha41575/unpineverything
release cleanup
2023-08-10 12:03:25 -05:00
Varsha Prasad Narsing
ddcbae54ab [Refactor] Internalize konfig constants
This PR is an effort towards internalizing public APIs.
It moves some of the builtinconstants to internal/

Signed-off-by: Varsha Prasad Narsing <varshaprasad96@gmail.com>
2023-08-09 14:14:48 -04:00
Varsha Prasad Narsing
ca748faa3f [Refactor] Move image/ to internal
This PR is an effort towards reducing the public surface
of APIs. It move image/ to internal/image

Signed-off-by: Varsha Prasad Narsing <varshaprasad96@gmail.com>
(cherry picked from commit 1f5890709fdc17de6f44f42b5138dd0f7e64bc74)
2023-08-09 13:40:07 -04:00
Kubernetes Prow Robot
5e6cbac589 Merge pull request #5203 from varshaprasad96/add/goapi-diff
[Chore] Enable go-api-diff checker
2023-08-07 08:42:32 -07:00
natasha41575
ff75dd6cd5 release cleanup 2023-07-31 12:27:44 -05:00
Natasha Sarkar
f8391994b4 Merge pull request #5253 from natasha41575/pincmdconfigandapi
pin to cmd/config and api
2023-07-31 11:49:43 -05:00
natasha41575
5ce14e5024 pin to cmd/config and api 2023-07-31 11:28:25 -05:00
Natasha Sarkar
ee22c9cab7 Merge pull request #5252 from natasha41575/pinkyaml
pin to kyaml 0.14.3
2023-07-31 11:24:02 -05:00
natasha41575
4a893ce8c6 pin to kyaml 2023-07-31 11:08:00 -05:00
Kubernetes Prow Robot
9ce923ebeb Merge pull request #5245 from yedayak/customization-typo
Fix typo in help for the create subcommand
2023-07-25 12:47:57 -07:00
Yedaya
494a807f28 Fix typo in help for the create subcommand 2023-07-18 09:58:14 +03:00
Varsha Prasad Narsing
820f17c73b [Chore] Enable go-api-diff checker
This PR introduces go-api-diff checker in Makefile
and in CI to make sure we don't end up breaking APIs
unintentionally.

Signed-off-by: Varsha Prasad Narsing <varshaprasad96@gmail.com>
2023-07-12 13:55:07 -04:00
Kubernetes Prow Robot
cd7ba1744e Merge pull request #5189 from annasong20/test-relative-submodules
Add test for issue #5131
2023-07-12 10:03:13 -07:00
Anna Song
da4e881007 Add accumulateResources error tests for local files (#5225)
* Add accumulateResources error tests for local files.

Add tests demonstrating accumulateResources errors when the resource is
a local file. Works to address #4807.

* Improve readability
2023-07-01 11:46:49 -07:00
Natasha Sarkar
878cda7c55 Merge pull request #5215 from natasha41575/unpin
release cleanup
2023-06-19 12:23:20 -05:00
natasha41575
47327616df update latest release version 2023-06-19 12:06:16 -05:00
natasha41575
eeff67d88d unpin everything 2023-06-19 12:05:59 -05:00
Natasha Sarkar
6adf4f294a Merge pull request #5214 from natasha41575/pintoapi
pin to api
2023-06-19 11:53:36 -05:00
natasha41575
5e7cc3437d pintoapi 2023-06-19 11:35:33 -05:00
Natasha Sarkar
ded76df3af Merge pull request #5213 from natasha41575/pintocmdconfig
pin to cmd/config
2023-06-19 11:24:40 -05:00
natasha41575
d7362ed22d pin to cmd/config 2023-06-19 11:07:36 -05:00
Natasha Sarkar
4711bfe40c Merge pull request #5212 from natasha41575/pintokyaml
pin to kyaml
2023-06-19 11:02:27 -05:00
natasha41575
8c0e0b3b47 pin to kyaml 2023-06-19 10:45:18 -05:00
Ed Overton
096b2c4435 test: add psm test for different key types 2023-06-15 16:12:29 -04:00
Anna Song
129d0f90af Add test for issue #5131 2023-06-14 18:32:12 +00:00
Ed Overton
c76fd5eb85 test: update psm key style test 2023-06-13 14:50:22 -04:00
Kubernetes Prow Robot
9e42f8d57e Merge pull request #5177 from annasong20/test-accumulate-remote-file
Test accumulateResources errors for remote files
2023-06-13 07:33:59 -07:00
Anna Song
168e31bfb6 Add accumulateResources remote file error tests
Test accumulateResources errors when a remote file fails to load. This
is part of the effort to fix issue #4807.
2023-06-09 21:31:27 +00:00
Daniel Strebel
d37c0eb477 fix(examples): move examples from patchesStrategicMerge to patches 2023-06-09 22:32:19 +02:00
Ed Overton
691b7d1df3 fix: patch additions honor source key style
When a patch appends a new node, it should honor the key style from the
patch. Prior to this commit, no style was applied, leading to problems
when the key value could be interpreted as a different type based on its
content. For example, "9110" needs quoting to ensure it is seen as a
string in yaml.
2023-06-08 17:21:46 -04:00
Kubernetes Prow Robot
336bc14e1a Merge pull request #5195 from natasha41575/updatemaintainers
add Anna to maintainers
2023-06-08 10:00:13 -07:00
natasha41575
b2c39b61bb add Anna to maintainers 2023-06-08 10:04:18 -05:00
Kubernetes Prow Robot
da31b966fb Merge pull request #5187 from koba1t/update_go_1.20
Bump to go 1.20
2023-06-07 08:28:15 -07:00
Kubernetes Prow Robot
dce94267fb Merge pull request #5030 from koba1t/fix/error_when_no_path_match
be error when no path matching
2023-06-07 07:42:13 -07:00
koba1t
d1647a51af fix e2econtainer test 2023-06-07 02:19:55 +09:00
koba1t
5b76aa9d2f update go 1.20 2023-06-06 22:39:06 +09:00
yugo kobayashi
0add0f95e2 change: components apply after all generators and transformers applied (#5170)
* change: components apply after all generator and transformer applied

* fix name for a test case

* add comment about when the components will be executed

* components are applied before transformer
2023-06-02 10:26:54 -07:00
Kubernetes Prow Robot
6ce0bf390c Merge pull request #5186 from Jefftree/gnostic-dependency
Update gnostic dependency with gnostic-models
2023-06-01 09:59:47 -07:00
Jefftree
7c98e531f2 make test-go-mod 2023-05-31 19:54:13 +00:00
Jefftree
e1ab8c79c1 Replace gnostic with gnostic-models 2023-05-31 18:14:33 +00:00
Kubernetes Prow Robot
cf3e81b590 Merge pull request #4949 from koba1t/fix/add_check_kustomization_is_empty
add check that kustomization is empty
2023-05-26 10:36:53 -07:00
koba1t
565cff2d07 update test add KustomizationFile 2023-05-25 05:13:33 +09:00
koba1t
8383b28322 fix test case handling and update a function comment 2023-05-25 04:25:10 +09:00
yugo kobayashi
e1c530e420 fix breaking examples (#5024)
* fix examples?springboot with no kustomization.yaml

* fix examples/loadHttp with legacy patch syntax
2023-05-24 10:02:50 -07:00
Natasha Sarkar
035924bc1e Merge pull request #5175 from natasha41575/release-cleanup
release cleanup
2023-05-17 10:59:48 -05:00
natasha41575
fd508f0e3a release cleanup 2023-05-17 10:41:37 -05:00
Kubernetes Prow Robot
9407e26433 Merge pull request #5155 from ephesused/eliminate-unnecessary-rnode
perf: eliminate unnecessary RNode creation
2023-05-09 15:27:55 -07:00
Natasha Sarkar
3cac8448d3 Merge pull request #5166 from natasha41575/pintoapinew
pin to api v0.13.4
2023-05-09 15:05:13 -05:00
natasha41575
84642b1fed pin to api v0.13.4 2023-05-09 14:48:02 -05:00
Vijay
91078545e6 Update README.md 2023-05-05 09:57:10 +12:00
Vijay
467633c2de Update README.md 2023-05-04 12:30:46 +12:00
Vijay
e44df7b386 Delete images directory 2023-05-03 13:49:41 +12:00
Vijay
bbff6768da Update README.md 2023-05-03 13:49:15 +12:00
Vijay
0020a496f7 Merge branch 'kubernetes-sigs:master' into issue/5127 2023-05-03 13:34:39 +12:00
Ed Overton
97c8cd7d1a perf: eliminate unnecessary RNode creation 2023-05-02 13:15:01 -04:00
Vijay
9eddc3c5a7 Update README.md
- Changes to address https://github.com/kubernetes-sigs/kustomize/issues/5127
2023-04-14 18:09:34 +12:00
koba1t
928b823d8f fix using reflect.DeepEqual for check kustomization is empty 2023-04-06 05:52:13 +09:00
koba1t
2c2b2ab825 add check that kustomization is empty 2023-04-06 05:32:08 +09:00
koba1t
694b3c9318 Add the test cases for check the file when edit add command 2023-03-01 04:20:59 +09:00
koba1t
cd49194383 fix tests 2023-02-09 05:35:45 +09:00
koba1t
53a4134379 fix error handling and test 2023-02-09 04:01:30 +09:00
koba1t
dfd2d7600d be error when no path match 2023-02-04 00:57:56 +09:00
koba1t
7aa33ff471 add edit add labels command add option for labels without selector 2022-02-24 09:49:31 +09:00
562 changed files with 22901 additions and 32523 deletions

View File

@@ -1,7 +1,5 @@
.github
docs
examples
hack
site
travis
*.md

View File

@@ -4,3 +4,11 @@ updates:
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: gomod
directory: "/"
schedule:
interval: "weekly"
open-pull-requests-limit: 10
vulnerability-alerts:
enabled: true

36
.github/workflows/apidiff.yml vendored Normal file
View File

@@ -0,0 +1,36 @@
name: APIDiff
# Trigger the workflow on pull requests and direct pushes to any branch
on:
push:
pull_request:
jobs:
go-apidiff:
name: Verify API differences
runs-on: ubuntu-latest
# Pull requests from different repository only trigger this checks
if: (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository)
steps:
- name: Clone the code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.work
- name: Execute go-apidiff
uses: joelanford/go-apidiff@v0.8.2
with:
compare-imports: true
print-compatible: true
- name: Report failure
uses: nashmaniac/create-issue-action@v1.2
# Only report failures of pushes (PRs have are visible through the Checks section) to the default branch
if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/master'
with:
title: 🐛 go-apidiff failed for ${{ github.sha }}
token: ${{ secrets.GITHUB_TOKEN }}
labels: kind/bug
body: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}

View File

@@ -10,16 +10,33 @@ permissions:
contents: read
jobs:
conditional-changes:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
doc: ${{ steps.filter.outputs.doc }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
doc:
- 'site/**'
lint:
name: Lint
needs: conditional-changes
if: needs.conditional-changes.outputs.doc == 'false'
runs-on: [ubuntu-latest]
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go 1.x
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version-file: go.work
id: go
@@ -30,12 +47,14 @@ jobs:
test-linux:
name: Test Linux
needs: conditional-changes
if: needs.conditional-changes.outputs.doc == 'false'
runs-on: [ubuntu-latest]
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Go 1.x
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version-file: go.work
id: go
@@ -46,12 +65,14 @@ jobs:
test-macos:
name: Test MacOS
needs: conditional-changes
if: needs.conditional-changes.outputs.doc == 'false'
runs-on: [macos-latest]
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Go 1.x
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version-file: go.work
id: go
@@ -62,12 +83,14 @@ jobs:
test-windows:
name: Test Windows
needs: conditional-changes
if: needs.conditional-changes.outputs.doc == 'false'
runs-on: [windows-latest]
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Go 1.x
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version-file: go.work
id: go

27
.github/workflows/release.yaml vendored Normal file
View File

@@ -0,0 +1,27 @@
name: release
on:
push:
tags:
- kyaml/v*
- cmd/config/v*
- api/v*
- kustomize/v*
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go 1.x
uses: actions/setup-go@v5
with:
go-version-file: go.work
id: go
- run: ./releasing/create-release.sh "${tag}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref_name }}

View File

@@ -3,7 +3,7 @@
run:
deadline: 5m
go: '1.19'
go: '1.21'
linters:
enable-all: true
@@ -34,6 +34,11 @@ linters:
- golint
- maintidx
- nosnakecase
- testpackage # it's better to keep tests in the same package for now because kustomize does open box testing
- structcheck # abandoned by author
- varcheck # abandoned by author
- maligned # abandoned by author
- interfacer # archived by author
linters-settings:
dupl:

View File

@@ -13,6 +13,7 @@
[CNCF Code of Conduct]: https://github.com/cncf/foundation/blob/master/code-of-conduct.md
[Kubernetes Community Membership]: https://github.com/kubernetes/community/blob/master/community-membership.md
[Kustomize Architecture]: ARCHITECTURE.md
[Contribution Guide]: https://kubectl.docs.kubernetes.io/contributing/kustomize/
[MacOS Dev Guide]: https://kubectl.docs.kubernetes.io/contributing/kustomize/mac/
[Windows Dev Guide]: https://kubectl.docs.kubernetes.io/contributing/kustomize/windows/
@@ -25,13 +26,88 @@ _As contributors and maintainers of this project, and in the interest of fosteri
## Getting Started
Dev guides:
### Forking Kustomize and Working Locally
The Kustomize project uses a "Fork and Pull" workflow that is standard to GitHub. In git terms, your personal fork is referred to as the "origin" and the actual project's git repository is called "upstream". To keep your personal branch (origin) up to date with the project (upstream), it must be configured within your local working copy.
- [Contribution Guide]
- [MacOS Dev Guide]
- [Windows Dev Guide]
### Create a fork in GitHub
1. Visit https://github.com/kubernetes-sigs/kustomize
2. Click the `Fork` button on the top right
General resources for contributors:
### Clone the repository
```bash
# Clone your repository fork from the previous step
git clone --recurse-submodules git@github.com:<your github username>/kustomize.git
cd kustomize
# Configure upstream
git remote add upstream https://github.com/kubernetes-sigs/kustomize
git remote set-url --push upstream no_push
# Review git configuration
git remote -v
```
### Create a working branch
```bash
# Fetch changes from upstream master
cd kustomize
git fetch upstream
git checkout master
git rebase upstream/master
# Create your working branch
git checkout -b myfeature
```
### Sync your working branch
You will need to periodically fetch changes from the `upstream` repository to keep your working branch in sync.
```bash
cd kustomize
git fetch upstream
git checkout myfeature
git rebase upstream/master
```
### Push to GitHub
When your changes are ready for review, push your working branch to your fork on GitHub.
```bash
cd kustomize
git push origin myfeature
```
### Create a Pull Request
1. Visit your fork at `https://github.com/<user>/kustomize`
2. Click the **Compare & Pull Request** button next to your `myfeature` branch.
3. Check out the pull request [process](https://github.com/kubernetes/community/blob/master/contributors/guide/pull-requests.md) for more details and advice.
If you ran `git push` in the previous step, GitHub will return a useful link to create a Pull Request.
### Build Kustomize
The [Kustomize Architecture] document describes the respository organization and the kustomize build process.
```bash
# For go version >= 1.13
unset GOPATH
unset GO111MODULES
# Build kustomize binary and install in go bin path
cd kustomize
make kustomize
# Run unit tests
make test-unit-all
# Run linter
make lint
# Test examples against HEAD
make test-examples-kustomize-against-HEAD
# Run your development version
~/go/bin/kustomize version
```
### General resources for contributors
- [Contributor License Agreement] - Kubernetes projects require that you sign a Contributor License Agreement (CLA) before we can accept your pull requests.
- [Kubernetes Contributor Guide] - Main contributor documentation.
@@ -59,12 +135,144 @@ Kustomize follows the [Kubernetes Community Membership] contributor ladder. Role
The kyaml module within the Kustomize repo has additional owners following the same ladder.
Administrative notes:
For the kustomize project, we have defined some specific guidelines on each step of the ladder:
To reach reviewer status, you must:
- Have been actively involved in kustomize for 3+ months
- Review at least 8 PRs that have been driven through to completion (see the reviewer guide below)
- Author at least 5 PRs that have been approved and merged
- Be a member of the kubernetes-sigs org. This should not be a blocker though, as once you meet the requirements for reviewer here,
the existing kustomize maintainers will be happy to sponsor your request to join the kubernetes-sigs org.
- Once you have met the above requirements, you may submit a PR adding yourself to the kustomize reviewers list, with links to your
contributions in the description.
To reach approver status, you must:
- Meet all the requirements of a reviewer
- Have been actively involved in kustomize for 6+ months
- Review at least 15 PRs that have been driven through to completion (see the reviewer guide below)
- Authored PRs meeting *either* of the following requirements:
- 15 PRs that have been approved and merged
- *OR* 10 PRs that have been approved and merged where some were more difficult, required greater thought/design,
or built up to larger features/long-term goals.
- File 3 issues. This can be any number of things, including but not limited to:
- Bugs with kustomize usage that you've found
- CI or release improvements
- Creating subtasks of a larger feature or project that you are in charge of.
- Long term improvements for the health of the project
- Triage at least 10 untriaged issues, including at least 1 feature request. The kustomize bug scrub is a great place to get practice with doing this, but you can
also follow the triage guide below to get started on your own.
- Demonstrate deeper understanding of kustomize goals. This can take many forms and is a bit subjective, but here are a few examples:
- saying no to an eschewed feature, instead recommending an alternative solution that is more aligned with the declarative configuration model
- active participation in discussion on a feature request issue
- filing an issue describing a long term problem and solution aligned with kustomize goals, for example: https://github.com/kubernetes-sigs/kustomize/issues/5140
- writing up KEPs for features that will improve the kustomize workflow while being aligned with kustomize goals, for example: https://github.com/kubernetes-sigs/kustomize/pull/4558
- Regularly interact with the existing kustomize maintainers, with clear communication about what you are working on or planning to work on. The kustomize
maintainers should know who you are and be familiar with your contributions.
- If you meet *most* of the above requirements while going above and beyond in a few areas, we will still consider your request to become an approver even
if you are missing one or two of the requirements. Please contact the maintainers directly to ask about getting approver status if you fall into this category.
- Otherwise, once you meet all the above requirements, you may:
- request to be added to the kustomize maintainer meeting that occurs each week with the kustomize PMs.
- submit a PR adding yourself to the kustomize approvers list, with links to your contributions in the description.
To reach owner status, you must:
- Meet all the requirements of an approver
- Have been actively involved with kustomize for 1+ year
- Assisted the current owner in driving the roadmap. This can be explicit or implicit help, such as:
- Editing the roadmap directly
- Reviewing the roadmap
- Providing suggestions for issues or prioritization in meetings that indirectly influence the roadmap
- Regularly triage issues and attend the kustomize bug scrub
- Regularly review PRs (1-2 a week)
- Periodically lead the kustomize bug scrub
- Periodically release kustomize (ensuring that there are no release blockers and that release notes are clean)
- Be the primary owner or point of contact for a particular project or area of code
- Ideally, there should be 2-3 owners at a time. Reach out to the current owners if you are interested in ownership. These
requirements are not strict and evaluation is somewhat subjective.
## Reviewer guide
Please watch this talk on how to review code from Tim Hockin: https://www.youtube.com/watch?v=OZVv7-o8i40
For reviewing PRs in kustomize, we have some specific guidelines:
- If the PR is introducing a new feature:
- *It must be implementing an issue that has already been triage/accepted or
a KEP that has been approved.* If it is not, then request the PR author to first file an issue.
- The PR must include thorough tests for the new feature, including unit and integration tests
- The code must be clean and readable, with thought given to how we will maintain the code in the future
- If the feature requires being broken up into multiple PRs to ease review, the feature should not be exposed to users
until the feature is completed in the last PR. For example, while we were building `kustomize localize`, we
built the feature almost entirely under the `api` module as a library with all the needed tests. There was no way
for users to invoke the localize code until the last PR that actually exposed the `kustomize localize` command in the
kustomize binary. This allowed us to continue development of `kustomize localize` without blocking kustomize releases.
If this type of development is not possible, then new features requiring multiple PRs should be
developed in their own feature branch.
- If the PR is introducing a bug fix:
- If the PR is not fixing an issue that has already been triage/accepted, follow the triage guide below on bug
fixes to decide if this is a PR we want to accept.
- The PR should have two distinct commits:
- The first commit should add a test demonstrating incorrect behavior
- The second commit should include the bug fix
- Some sample PRs:
- https://github.com/kubernetes-sigs/kustomize/pull/5263/commits
- https://github.com/kubernetes-sigs/kustomize/pull/3931/commits
- The regression test is absolutely required, and we cannot accept bug fixes without tests.
- If the PR is introducing a performance improvement:
- The PR description should give an indication of how much the performance is being improved and how we
can measure it - benchmark tests are fantastic.
- Other PRs (documentation, CI improvements, etc.) should be reviewed based on your best judgment.
## Triage guide
The possible triage labels are listed here: https://github.com/kubernetes-sigs/kustomize/labels?q=triage.
Triaging a feature request means:
- Understand what the user is asking for, and their use case.
- Verify that it is not an [eschewed feature](https://kubectl.docs.kubernetes.io/faq/kustomize/eschewedfeatures/#build-time-side-effects-from-cli-args-or-env-variables)
- Verify that it is not a duplicate issue.
- Look into workarounds. Is there another way that the user can achieve their use case with existing features?
- If you are new to this role, prior to leaving a comment on the issue, please bring it to weekly standup
for group discussion to make sure that we are all on the same page.
- Once you feel ready, you can label it with a triage label. Here's an [example](https://github.com/kubernetes-sigs/kustomize/issues/5049). You can also
look at other feature request issues to see how they were triaged and resolved. There are a few different triage labels that you can use, you can see the
full list [here](https://github.com/kubernetes-sigs/kustomize/labels?q=triage).
Triaging a bug means:
- First, verify that you can reproduce the issue. If you cannot reproduce the issue or need more information to give
it a go, triage it accordingly.
- Try to understand if this is really a bug or if this is intended behavior from kustomize. If it seems like intended
behavior, do your best to explain to the user why this is the case.
- If it seems to be a genuine bug, you can /triage accept the issue. In addition, investigate if there are workarounds or
alternative solutions for the user that they can try until the issue gets resolved.
The triage party for kustomize is here https://cli.triage.k8s.io/s/kustomize and can be a easy way to
find issues that have not been triaged yet.
## Project/Product Managers
Kustomize will have opportunities to join in a project/product manager role. You can reach out to
the existing kustomize maintainers if you are interested in this type of role. Project management work
can greatly help supplement your contributions as you climb from reviewer to approver
to owner.
Expectations for this role are:
- Triage 1 feature request each week, and bring it to weekly stand-up for discussion. Feature
requests are issues labeled kind/feature, and you can find them [here](https://github.com/kubernetes-sigs/kustomize/issues?q=is%3Aissue+is%3Aopen+kind+feature+label%3Akind%2Ffeature).
Please view the above triage guide for details on how to approach feature request triage.
- Monitor the kustomize Slack channel and try to help users if you can. It is a pretty
active channel, so responding to 4-5 users per week is sufficient even if some
questions go unanswered. If there is an interesting topic or a recurring problem that many
users are having, please bring it up in weekly stand-up.
- Keeping track of a queue of backlog issues or PRs that are not being actively looked at in any existing project board.
- Organizing or reorganizing project tracking boards when it makes sense.
You will also be asked to help with roadmap planning, deprecation communication, prioritization,
and doing research on kustomize usage when appropriate, though these responsibilities will occur less
frequently.
## Administrative notes:
- The [OWNERS file spec] is a useful resources in making changes.
- Maintainers and admins must be added to the appropriate lists in both [Kustomize OWNERS_ALIASES] and [SIG-CLI Teams]. If this isn't done, the individual in question will lack either PR approval rights (Kustomize list) or the appropriate Github repository permissions (community list).
## Contact Information
- [Slack channel]

View File

@@ -3,7 +3,7 @@
#
# Makefile for kustomize CLI and API.
LATEST_RELEASE=v5.0.1
LATEST_RELEASE=v5.4.1
SHELL := /usr/bin/env bash
GOOS = $(shell go env GOOS)
@@ -56,26 +56,24 @@ uninstall-local-tools:
# Build from local source.
$(MYGOBIN)/gorepomod:
cd cmd/gorepomod; \
go install .
cd cmd/gorepomod && go install .
# Build from local source.
$(MYGOBIN)/k8scopy:
cd cmd/k8scopy; \
go install .
cd cmd/k8scopy && go install .
# Build from local source.
$(MYGOBIN)/pluginator:
cd cmd/pluginator; \
go install .
cd cmd/pluginator && go install .
# --- Build targets ---
# Build from local source.
$(MYGOBIN)/kustomize: build-kustomize-api
cd kustomize; \
go install -ldflags "-X sigs.k8s.io/kustomize/api/provenance.buildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')" \
cd kustomize && go install -ldflags \
"-X sigs.k8s.io/kustomize/api/provenance.buildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') \
-X sigs.k8s.io/kustomize/api/provenance.version=$(shell git describe --tags --always --dirty)" \
.
kustomize: $(MYGOBIN)/kustomize
@@ -84,11 +82,11 @@ kustomize: $(MYGOBIN)/kustomize
# plugin-to-api compatibility checks.
.PHONY: build-kustomize-api
build-kustomize-api: $(MYGOBIN)/goimports $(builtinplugins)
cd api; $(MAKE) build
cd api && $(MAKE) build
.PHONY: generate-kustomize-api
generate-kustomize-api:
cd api; $(MAKE) generate
cd api && $(MAKE) generate
# --- Verification targets ---
@@ -108,6 +106,9 @@ verify-kustomize-repo: \
.PHONY: prow-presubmit-check
prow-presubmit-check: \
install-tools \
workspace-sync \
generate-kustomize-builtin-plugins \
builtin-plugins-diff \
test-unit-kustomize-plugins \
test-go-mod \
build-non-plugin-all \
@@ -126,6 +127,10 @@ check-license: $(MYGOBIN)/addlicense
lint: $(MYGOBIN)/golangci-lint $(MYGOBIN)/goimports $(builtinplugins)
./hack/for-each-module.sh "make lint"
.PHONY: apidiff
apidiff: $(MYGOBIN)/go-apidiff ## Run the go-apidiff to verify any API differences compared with origin/master
go-apidiff master --compare-imports --print-compatible --repo-path=.
.PHONY: test-unit-all
test-unit-all: \
test-unit-non-plugin \
@@ -134,14 +139,14 @@ test-unit-all: \
# This target is used by our Github Actions CI to run unit tests for all non-plugin modules in multiple GOOS environments.
.PHONY: test-unit-non-plugin
test-unit-non-plugin:
./hack/for-each-module.sh "make test" "./plugin/*" 16
./hack/for-each-module.sh "make test" "./plugin/*" 20
.PHONY: build-non-plugin-all
build-non-plugin-all:
./hack/for-each-module.sh "make build" "./plugin/*" 16
./hack/for-each-module.sh "make build" "./plugin/*" 20
.PHONY: test-unit-kustomize-plugins
test-unit-kustomize-plugins:
test-unit-kustomize-plugins: build-kustomize-external-go-plugin
./hack/testUnitKustomizePlugins.sh
.PHONY: functions-examples-all
@@ -173,7 +178,12 @@ test-examples-kustomize-against-HEAD: $(MYGOBIN)/kustomize $(MYGOBIN)/mdrip
test-examples-kustomize-against-latest-release: $(MYGOBIN)/mdrip
./hack/testExamplesAgainstKustomize.sh v5@$(LATEST_RELEASE)
# Pushes dependencies in the go.work file back to go.mod files of each workspace module.
.PHONY: workspace-sync
workspace-sync:
go work sync
./hack/doGoMod.sh tidy
# --- Cleanup targets ---
.PHONY: clean
clean: clean-kustomize-external-go-plugin uninstall-tools

View File

@@ -89,9 +89,27 @@ $(pGen)/%.go: $(MYGOBIN)/pluginator $(MYGOBIN)/goimports
$(MYGOBIN)/goimports -w $*.go \
)
# Target is for debugging.
# Generate builtin plugins
.PHONY: generate-kustomize-builtin-plugins
generate-kustomize-builtin-plugins: $(builtinplugins)
generate-kustomize-builtin-plugins: $(builtplugins)
for plugin in $(abspath $(wildcard $(pSrc)/*)); do \
echo "generating $${plugin} ..."; \
set -e; \
cd $${plugin}; \
go generate .; \
done
# Check for diff by comparing current revision of generated plugins on HEAD and newly generated plugins on local branch,
# If diff is found, throw error code 1
.PHONY: builtin-plugins-diff
builtin-plugins-diff: $(builtplugins)
for file in $(abspath $(builtinplugins)); do \
echo "Checking for diff... $${file}" ; \
set -e ; \
if [ "`git diff $${file} | wc -c`" -gt 0 ]; then\
echo "Error(1): diff found on $${file}"; exit 1; \
fi \
done
.PHONY: build-kustomize-external-go-plugin
build-kustomize-external-go-plugin:

View File

@@ -1,14 +1,16 @@
# Copyright 2022 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
GOLANGCI_LINT_VERSION=v1.51.2
GOOS = $(shell go env GOOS)
GOARCH = $(shell go env GOARCH)
MYGOBIN = $(shell go env GOBIN)
ifeq ($(MYGOBIN),)
MYGOBIN = $(shell go env GOPATH)/bin
endif
export PATH := $(MYGOBIN):$(PATH)
REPO_ROOT=$(shell git rev-parse --show-toplevel)
# determines whether to run tests that only behave locally; can be overridden by override variable
export IS_LOCAL = false
@@ -18,8 +20,7 @@ install-out-of-tree-tools: \
$(MYGOBIN)/golangci-lint \
$(MYGOBIN)/helmV3 \
$(MYGOBIN)/mdrip \
$(MYGOBIN)/stringer \
$(MYGOBIN)/goimports
$(MYGOBIN)/stringer
.PHONY: uninstall-out-of-tree-tools
uninstall-out-of-tree-tools:
@@ -29,67 +30,61 @@ uninstall-out-of-tree-tools:
rm -f $(MYGOBIN)/mdrip
rm -f $(MYGOBIN)/stringer
.PHONY: $(MYGOBIN)/golangci-lint
$(MYGOBIN)/golangci-lint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
cd $(REPO_ROOT)/hack && go install github.com/golangci/golangci-lint/cmd/golangci-lint
.PHONY: $(MYGOBIN)/mdrip
$(MYGOBIN)/mdrip:
go install github.com/monopole/mdrip@v1.0.2
cd $(REPO_ROOT)/hack && go install github.com/monopole/mdrip
.PHONY: $(MYGOBIN)/stringer
$(MYGOBIN)/stringer:
go install golang.org/x/tools/cmd/stringer@latest
cd $(REPO_ROOT)/hack && go install golang.org/x/tools/cmd/stringer
.PHONY: $(MYGOBIN)/goimports
$(MYGOBIN)/goimports:
go install golang.org/x/tools/cmd/goimports@latest
cd $(REPO_ROOT)/hack && go install golang.org/x/tools/cmd/goimports
.PHONY: $(MYGOBIN)/mdtogo
$(MYGOBIN)/mdtogo:
go install sigs.k8s.io/kustomize/cmd/mdtogo@latest
cd $(REPO_ROOT)/hack && go install sigs.k8s.io/kustomize/cmd/mdtogo
.PHONY: $(MYGOBIN)/addlicense
$(MYGOBIN)/addlicense:
go install github.com/google/addlicense@latest
$(MYGOBIN)/goreleaser:
go install github.com/goreleaser/goreleaser@v0.179.0 # https://github.com/kubernetes-sigs/kustomize/issues/4542
cd $(REPO_ROOT)/hack && go install github.com/google/addlicense
.PHONY: $(MYGOBIN)/kind
$(MYGOBIN)/kind:
( \
set -e; \
d=$(shell mktemp -d); cd $$d; \
wget -O ./kind https://github.com/kubernetes-sigs/kind/releases/download/v0.7.0/kind-$(GOOS)-$(GOARCH); \
chmod +x ./kind; \
mv ./kind $(MYGOBIN); \
rm -rf $$d; \
)
cd $(REPO_ROOT)/hack && go install sigs.k8s.io/kind
# linux only.
.PHONY: $(MYGOBIN)/controller-gen
$(MYGOBIN)/controller-gen:
cd $(REPO_ROOT)/hack && go install sigs.k8s.io/controller-tools/cmd/controller-gen
.PHONY: $(MYGOBIN)/embedmd
$(MYGOBIN)/embedmd:
cd $(REPO_ROOT)/hack && go install github.com/campoy/embedmd
.PHONY: $(MYGOBIN)/go-bindata
$(MYGOBIN)/go-bindata:
cd $(REPO_ROOT)/hack && go install github.com/go-bindata/go-bindata/v3/go-bindata
.PHONY: $(MYGOBIN)/go-apidiff
$(MYGOBIN)/go-apidiff:
cd $(REPO_ROOT)/hack && go install github.com/joelanford/go-apidiff
.PHONY: $(MYGOBIN)/gh
$(MYGOBIN)/gh:
( \
set -e; \
d=$(shell mktemp -d); cd $$d; \
tgzFile=gh_1.0.0_$(GOOS)_$(GOARCH).tar.gz; \
wget https://github.com/cli/cli/releases/download/v1.0.0/$$tgzFile; \
tar -xvzf $$tgzFile; \
mv gh_1.0.0_$(GOOS)_$(GOARCH)/bin/gh $(MYGOBIN)/gh; \
rm -rf $$d \
)
cd $(REPO_ROOT)/hack && go install github.com/cli/cli/cmd/gh
# linux only.
# This is for testing an example plugin that
# uses kubeval for validation.
# Don't want to add a hard dependence in go.mod file
# to github.com/instrumenta/kubeval.
# Instead, download the binary.
.PHONY: $(MYGOBIN)/kubeval
$(MYGOBIN)/kubeval:
( \
set -e; \
d=$(shell mktemp -d); cd $$d; \
wget https://github.com/instrumenta/kubeval/releases/latest/download/kubeval-$(GOOS)-$(GOARCH).tar.gz; \
tar xf kubeval-$(GOOS)-$(GOARCH).tar.gz; \
mv kubeval $(MYGOBIN); \
rm -rf $$d; \
)
cd $(REPO_ROOT)/hack && go install github.com/instrumenta/kubeval
# Helm V3 differs from helm V2; downloading it to provide coverage for the
# chart inflator plugin under helm v3.
.PHONY: $(MYGOBIN)/helmV3
$(MYGOBIN)/helmV3:
( \
set -e; \

View File

@@ -3,16 +3,28 @@
aliases:
kustomize-owners:
- knverey
- natasha41575
- koba1t
kustomize-approvers:
- knverey
- natasha41575
- koba1t
- varshaprasad96
kustomize-reviewers:
- knverey
- natasha41575
- yuwenma
- annasong20
- koba1t
- stormqueen1990
- varshaprasad96
- ncapps
docs-approvers:
- ncapps
docs-reviewers:
- ncapps
commands-approvers:
- stormqueen1990
commands-reviewers:
- stormqueen1990
# emeritus:
# - liujingfang1
# - Shell32-Natsu
@@ -22,3 +34,6 @@ aliases:
# - mengqiy
# - mortent
# - phanimarupaka
# - natasha41575
# - annasong20
# - yuwenma

View File

@@ -36,11 +36,16 @@ be updated on a regular basis going forward, and such updates
will be reflected in the Kubernetes release notes.
| Kubectl version | Kustomize version |
| --- | --- |
| < v1.14 | n/a |
| v1.14-v1.20 | v2.0.3 |
| v1.21 | v4.0.5 |
| v1.22 | v4.2.0 |
| --------------- | ----------------- |
| < v1.14 | n/a |
| v1.14-v1.20 | v2.0.3 |
| v1.21 | v4.0.5 |
| v1.22 | v4.2.0 |
| v1.23 | v4.4.1 |
| v1.24 | v4.5.4 |
| v1.25 | v4.5.7 |
| v1.26 | v4.5.7 |
| v1.27 | v5.0.1 |
[v2.0.3]: https://github.com/kubernetes-sigs/kustomize/releases/tag/v2.0.3
[#2506]: https://github.com/kubernetes-sigs/kustomize/issues/2506
@@ -63,7 +68,37 @@ This file should declare those resources, and any
customization to apply to them, e.g. _add a common
label_.
![base image][imageBase]
```
base: kustomization + resources
kustomization.yaml deployment.yaml service.yaml
+---------------------------------------------+ +-------------------------------------------------------+ +-----------------------------------+
| apiVersion: kustomize.config.k8s.io/v1beta1 | | apiVersion: apps/v1 | | apiVersion: v1 |
| kind: Kustomization | | kind: Deployment | | kind: Service |
| commonLabels: | | metadata: | | metadata: |
| app: myapp | | name: myapp | | name: myapp |
| resources: | | spec: | | spec: |
| - deployment.yaml | | selector: | | selector: |
| - service.yaml | | matchLabels: | | app: myapp |
| configMapGenerator: | | app: myapp | | ports: |
| - name: myapp-map | | template: | | - port: 6060 |
| literals: | | metadata: | | targetPort: 6060 |
| - KEY=value | | labels: | +-----------------------------------+
+---------------------------------------------+ | app: myapp |
| spec: |
| containers: |
| - name: myapp |
| image: myapp |
| resources: |
| limits: |
| memory: "128Mi" |
| cpu: "500m" |
| ports: |
| - containerPort: 6060 |
+-------------------------------------------------------+
```
File structure:
@@ -99,20 +134,41 @@ Manage traditional [variants] of a configuration - like
_development_, _staging_ and _production_ - using
[overlays] that modify a common [base].
![overlay image][imageOverlay]
```
overlay: kustomization + patches
kustomization.yaml replica_count.yaml cpu_count.yaml
+-----------------------------------------------+ +-------------------------------+ +------------------------------------------+
| apiVersion: kustomize.config.k8s.io/v1beta1 | | apiVersion: apps/v1 | | apiVersion: apps/v1 |
| kind: Kustomization | | kind: Deployment | | kind: Deployment |
| commonLabels: | | metadata: | | metadata: |
| variant: prod | | name: myapp | | name: myapp |
| resources: | | spec: | | spec: |
| - ../../base | | replicas: 80 | | template: |
| patches: | +-------------------------------+ | spec: |
| - path: replica_count.yaml | | containers: |
| - path: cpu_count.yaml | | - name: myapp |
+-----------------------------------------------+ | resources: |
| limits: |
| memory: "128Mi" |
| cpu: "7000m" |
+------------------------------------------+
```
File structure:
> ```
> ~/someApp
> ├── base
>    ├── deployment.yaml
>    ├── kustomization.yaml
>    └── service.yaml
> ├── deployment.yaml
> ├── kustomization.yaml
> └── service.yaml
> └── overlays
> ├── development
>    ├── cpu_count.yaml
>    ├── kustomization.yaml
>    └── replica_count.yaml
> ├── cpu_count.yaml
> ├── kustomization.yaml
> └── replica_count.yaml
> └── production
> ├── cpu_count.yaml
> ├── kustomization.yaml
@@ -166,8 +222,6 @@ is governed by the [Kubernetes Code of Conduct].
[applied]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#apply
[base]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#base
[declarative configuration]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#declarative-application-management
[imageBase]: images/base.jpg
[imageOverlay]: images/overlay.jpg
[kubectl announcement]: https://kubernetes.io/blog/2019/03/25/kubernetes-1-14-release-announcement
[kubernetes documentation]: https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/
[kubernetes style]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#kubernetes-style-object

View File

@@ -1,112 +1,185 @@
# Kustomize roadmap 2022
# Kustomize roadmap 2023-2024
Presented at the [January 26, 2022, SIG-CLI meeting](https://youtu.be/l2plzJ9MRlk?t=1321)
This document describes the items that we hope to make progress on over the next
1 year (H2 2023 and H1 2024). Take this roadmap as more of what we hope to achieve
rather than what we promise to achieve, as some items in this doc are highly dependent
on the success that we have on-ramping new contributors to the project, and other
items will depend on external contributions, which can vary.
kustomize maintainers: @knverey, @natasha41575
If you are interested in contributing to a particular area, you can look through
the project board for that area and assign yourself to one of the issues. It is
recommended to start with smaller issues to ramp up on the project before starting
to tackle larger issues.
[Objective: Improve contributor community](#objective-improve-contributor-community)
Project boards:
https://github.com/orgs/kubernetes-sigs/projects/50
https://github.com/orgs/kubernetes-sigs/projects/51
https://github.com/orgs/kubernetes-sigs/projects/52
https://github.com/orgs/kubernetes-sigs/projects/53
https://github.com/orgs/kubernetes-sigs/projects/54
[Objective: Improve end-user experience](#objective-improve-end-user-experience)
## Kustomize contributors (at time of writing):
[Objective: Improve extension experience](#objective-improve-extension-experience)
kustomize owner: @natasha41575
## Objective: Improve contributor community
kustomize maintainers: @annasong20, @koba1t
**_WHO: End user who also contributes source code._**
Top priority:
- Kustomization v1 (also end-user impact) ([PROJECT](https://github.com/kubernetes-sigs/kustomize/projects/12))
- Remove the following fields:
- [vars](https://github.com/kubernetes-sigs/kustomize/issues/2052)
- [patchesJson6902, patchesStrategicMerge (consolidate on \`patches)](https://github.com/kubernetes-sigs/kustomize/issues/4376)
- [helmChartInflationGenerator, helmCharts, helmGlobals](https://github.com/kubernetes-sigs/kustomize/issues/4401)
- all long-deprecated fields in Kustomization v1 such as \`bases\` and those being accommodate by kustomize edit \[[see code snippet](https://github.com/kubernetes-sigs/kustomize/blob/ee4b7847f0beb6c0d2070673b10f23f7b3e92e82/api/types/fix.go#L15)\]
- Ensure that \`kustomize edit fix\` handles migrations for all those, and that anything it changes is not still present in v1.
- [Add reorder field](https://github.com/kubernetes-sigs/kustomize/issues/3913). Default should be FIFO and legacy should also be supported (could add alphabetic and custom sort support eventually). Replaces -reorder flag.
- [Reconcile openapi and crds field](https://github.com/kubernetes-sigs/kustomize/issues/3944)
- [Consider deprecating configurations field](https://github.com/kubernetes-sigs/kustomize/issues/3945) (old, pre-plugin, pre-openapi global configuration)
- [Add a field to enable the managedby label](https://github.com/kubernetes-sigs/kustomize/issues/4047)
Second priority:
- Improve contributor documentation
- [Instructions to upgrade kustomize-in-kubectl](https://github.com/kubernetes-sigs/kustomize/issues/3951)
Also very valuable to the project:
- [Improve the release process](https://github.com/kubernetes-sigs/kustomize/issues/3952) to support regular biweekly releases [PROJECT](https://github.com/kubernetes-sigs/kustomize/projects/7)
- Release sigs.k8s.io/kustomize/api v1.0.0 [PROJECT](https://github.com/kubernetes-sigs/kustomize/projects/5)
- [Reduce the public surface of the API module](https://github.com/kubernetes-sigs/kustomize/issues/3942)
- [Vendor all transitive deps](https://github.com/kubernetes-sigs/kustomize/issues/3706). Since kustomize is in kubectl, we must do as kubectl does to manage deps, exposing new transitive deps in code review.
- Project administration
- [Rename master branch to main](https://github.com/kubernetes-sigs/kustomize/issues/3954)
kustomize contributors: @varshaprasad96
# H2 2023
## Objective: Improve end-user experience
## Goal: Create kustomize leadership and contributor playbooks
**_WHO: End user that wants kustomize build artifacts (binaries, containers)._**
Contributors: natasha41575, annasong20
Top priorities:
Priority: High
- Bug fixes:
- Fix bugs in basic anchor support: [issue query](https://github.com/kubernetes-sigs/kustomize/issues?q=is%3Aopen+is%3Aissue+label%3Aarea%2Fanchors)
- integer keys support: [#3446](https://github.com/kubernetes-sigs/kustomize/issues/3446)
- kyaml not respecting \`$patch replace|retainKeys\`: [#2037](https://github.com/kubernetes-sigs/kustomize/issues/2037)
- kustomize removing quotes from namespace field values: [#4146](https://github.com/kubernetes-sigs/kustomize/issues/4146)
- Kustomize doesnt support metadata.generateName: [#641](https://github.com/kubernetes-sigs/kustomize/issues/641)
- Send kustomize CLI version number into kubectl ([kubectl issue](https://github.com/kubernetes/kubectl/issues/797) / [kustomize issue](https://github.com/kubernetes-sigs/kustomize/issues/1424))
- Kustomize performance investigations/improvements [PROJECT](https://github.com/kubernetes-sigs/kustomize/projects/13)
- [Support generic resource references in name reference tracking](https://github.com/kubernetes-sigs/kustomize/issues/3418)
- [KEP 4267: retain the resource origin and transformer data in annotations](https://github.com/kubernetes-sigs/kustomize/pull/4267)
Effort: Medium
Secondary priorities:
In the past, when the leads stopped contributing (for various reasons, not covered here)
in various kubernetes projects, it left a wide hole that few could easily fill,
leaving the remaining leads in a bad position and the project understaffed. We should assume
that we will need to onboard new maintainers in the future, and should have playbooks
for doing so. As we grow the contributor base in kustomize, we will build these playbooks for
those who are contributing and those who are looking to grow into kustomize leaders.
To ensure the long term health and stability of the project, we should have:
- kustomize cli v5 ([PROJECT](https://github.com/kubernetes-sigs/kustomize/projects/14))
- [Drop the --reorder flag](https://github.com/kubernetes-sigs/kustomize/issues/3947)
- [Graduate cfg read-only commands out of alpha](https://github.com/kubernetes-sigs/kustomize/issues/4090).
- [Drop the enable-managedby-label](https://github.com/kubernetes-sigs/kustomize/issues/4047)
- Drop old plugin-related fields in favor of [the Catalog-style fields](https://github.com/kubernetes/enhancements/tree/master/keps/sig-cli/2906-kustomize-function-catalog).
- [Drop the helm flags](https://github.com/kubernetes-sigs/kustomize/issues/4401)
- [Confusion around namespace replacement](https://github.com/kubernetes-sigs/kustomize/issues/880).
- On-boarding guides for new contributors
- Clear guidelines for how to climb the kustomize ladder from contributor to approver to owner
- A plan (maybe a schedule) for future kustomize cohorts
- A succession plan, in case the current kustomize leads ever decide to step down
Also very valuable to the project:
## Goal: Onboard 2-5 new contributors to kustomize
- [Overinclusion of root directory error in error messages](https://github.com/kubernetes-sigs/kustomize/issues/4348)
- [Add kustomize localize command](https://github.com/kubernetes-sigs/kustomize/issues/3980)
- [Fix Windows support in test suite](https://github.com/kubernetes-sigs/kustomize/issues/4001)
- Improve end-user documentation [PROJECT](https://github.com/kubernetes-sigs/kustomize/projects/9)
Contributors: natasha41575, annasong20, koba1t
Priority: High
## Objective: Improve extension experience
Effort: High
**_WHO: Plugin developers: end users who extend kustomize, but dont think about internals._**
In order to make progress on kustomize goals in the future, we need to increase the
level of staffing on kustomize. We should leverage community contributions to keep kustomize
healthy and making progress.
This objective is described in detail in the [Kustomize Plugin Graduation KEP](https://github.com/kubernetes/enhancements/tree/master/keps/sig-cli/2953-kustomize-plugin-graduation) / [PROJECT](https://github.com/kubernetes-sigs/kustomize/projects/15) .
The primary means in which we will try to find new kustomize contributors is through the new kustomize
maintainer training cohort. We will lead a group of ~20 kubernetes community members through a 3-6 month
training program, involving talk sessions, bug scrubs, issue triage, PR reviews, and coding projects for
each member.
Top priorities:
See [our call for help](https://groups.google.com/a/kubernetes.io/g/dev/c/M5OphEVsv5o/m/zc6G4H15AAAJ) for more
specific details about the program.
- Fix core usability issues with KRM Function extensions:
- [Better errors for function config failures](https://github.com/kubernetes-sigs/kustomize/issues/4398)
- [Container KRM Mounts are not mounting via function parameters](https://github.com/kubernetes-sigs/kustomize/issues/4290)
- [Resolution of local file references in extensions transformer configuration](https://github.com/kubernetes-sigs/kustomize/issues/4154)
- [Do not silently ignore plugins when config has typo](https://github.com/kubernetes-sigs/kustomize/issues/4399)
- [KRM Exec Function can't locate executable when referencing a base](https://github.com/kubernetes-sigs/kustomize/issues/4347)
- Once core usability issues are fixed, [deprecate legacy exec and Go plugin support](https://github.com/kubernetes/enhancements/tree/master/keps/sig-cli/2953-kustomize-plugin-graduation)
- [Catalog KEP](https://github.com/kubernetes/enhancements/tree/master/keps/sig-cli/2906-kustomize-function-catalog)
The effort from existing kustomize maintainers here will be to:
- Organize the cohort, so that each cohort member feels productive and understands what they should work on
- Align motivation of the cohort members with the work that we assign to them.
- Review PRs from cohort members in a timely manner.
- Be the point(s) of contact for questions/escalations
- Lead weekly stand-ups and monthly bug scrubs
Secondary priorities:
At the end of all this, if we have a small team of contributors to kustomize, who understand its founding
philosophy and intentions, we should be able to keep the project up to date.
- [Remove Starlark support](https://github.com/kubernetes-sigs/kustomize/issues/4349)
- [Composition KEP](https://github.com/kubernetes/enhancements/pull/2300). The implementation is complete in [#4223](https://github.com/kubernetes-sigs/kustomize/pull/4323), but depends on:
- [Convert resources and components to be backed by a reusable generator](https://github.com/kubernetes-sigs/kustomize/issues/4402)
- [Enable explicitly invoked transformers to use default fieldSpecs](https://github.com/kubernetes-sigs/kustomize/issues/4404)
- [Enable built-in generators to be used in the transformers field ](https://github.com/kubernetes-sigs/kustomize/issues/4403)
## Goal: Improve kustomize extensibility through KRM functions and CRD support
Contributors: koba1t, varshaprasad96, external contributors
Also very valuable to the project:
Priority: High
- [Improve docs for kyaml libraries](https://github.com/kubernetes-sigs/kustomize/issues/3950), especially by adding examples.
- [Create a reserved field for plugin runtime information](https://github.com/kubernetes-sigs/kustomize/issues/4405)
- [Develop new standard process for implementing builtin transformers](https://github.com/kubernetes-sigs/kustomize/issues/4400)
Effort: High
Project board: https://github.com/orgs/kubernetes-sigs/projects/53/views/1
For a long time, we have supported KRM functions as the proper way to implement custom generators and transformers.
However, due to limited staffing, we have been unable to drive this feature out of alpha in kustomize. The two
main features which we hope to make progress on are Composition and Catalog, two long-standing proposals for which
numerous users have been waiting for a long time. There are several open issues
regarding KRM functions where our long-term answer has been these two features, but users have been hearing about them
for over a year without seeing any progress. If we can implement them, they will vastly improve usability and security
of KRM functions.
One item that falls under this category that does not currently have a contributor is improving CRD support.
Currently, it is difficult to use CRDs properly, as there are three different fields (configurations, openapi, and crds)
where users have to input their CRD configuration. We need to consolidate these fields into one easy to use feature to
support CRDs. If you are interested in putting together a design proposal for how to tackle this task, please reach
out to the kustomize maintainers.
# H1 2024
## Goal: Improve the kustomize documentation
Contributors: annasong20, external contributions
Priority: High
Effort: High
Project board: https://github.com/orgs/kubernetes-sigs/projects/50
The kustomize documentation is currently fragmented, out of date, and lacks examples to fully understand its value.
We have had a "docs project" for a long time; we need to prioritize implementing it so that the documentation is in
one place, easy to find, and helps new users get started more easily. Some outcomes from this project should be:
- A single, unified website hosted on kustomize.io
- Updated information architecture, and a plan to keep it up to date
- End to end examples of using kustomize, including complex use cases
## Goal: Fix core usability bugs in kustomize
Contributors: external contributions
Priority: High
Effort: High
Project board: https://github.com/orgs/kubernetes-sigs/projects/51
There are several core usability issues that block some users from adopting kustomize features or in
some base block users from using kustomize entirely. These issues range from small bugs with workable but
inconvenient workarounds, to enormous feature gaps.
As part of this goal, we should work toward reducing the number of such issues that we have, making
kustomize work more smoothly and predictably, and be usable for a larger range of users.
There are a lot of important issues in this project, but the biggest and highest priority one is that
kustomize doesn't currently support metadata.GenerateName. Unfortunately, we don't currently have anyone
actively working on this issue, we would need an external contributor to reach out to the kustomize
maintainers to pick it up.
## Goal: Improve kustomize CI, release, & security patch processes
Contributors: external contributions
Priority: Medium
Effort: High
Project board: https://github.com/orgs/kubernetes-sigs/projects/54
The kustomize release process is currently done on-demand and is strictly linear. This means that if we find a CVE,
we are forced to release the next version of kustomize ASAP, and we are required to release every PR that has merged
since the last release. This can put us in a sticky situation if we have a breaking change that we are
not ready to release yet, but we need a patch quickly.
We should try to improve the kustomize release process so that we can release frequently, reliably, and with some
flexibility. The outcome of this effort should be:
- kustomize is released on a regular cadence (biweekly or monthly)
- kustomize is able to separate patch and feature releases, so that we can fix CVEs without needing to release
everything that we have in flight
- We can detect and fix CVEs early
## Goal: Take long-standing alpha commands out of alpha
Contributors: external contributions
Priority: Medium
Effort: Medium
Project board: https://github.com/orgs/kubernetes-sigs/projects/52
There are several commands in kustomize that have been alpha for a long time, including the cfg command group and
localize. Moving them forward can indicate good health of a project and these commands are useful to many users.
Some of these projects can be good starter issues for new contributors to have an easier onramp while others will
require more effort and thought.

View File

@@ -9,7 +9,7 @@
#
# DO NOT REPORT SECURITY VULNERABILITIES DIRECTLY TO THESE NAMES, FOLLOW THE
# INSTRUCTIONS AT https://kubernetes.io/security/
monopole
Liujingfang1
pwittrock
eddiezane
KnVerey
natasha41575
soltysh

View File

@@ -11,3 +11,18 @@ build:
generate: $(MYGOBIN)/k8scopy $(MYGOBIN)/stringer
go generate ./...
lint: lint-api-static
## lint-api-static runs the linter on the API module
## with build-tag kustomize_disable_go_plugin_support
## this aims to catch any issues with the API module
## that would prevent the API module from being used
## when the go plugin support is disabled.
lint-api-static:
$(MYGOBIN)/golangci-lint cache clean # Workaround for https://github.com/golangci/golangci-lint/issues/3228
$(MYGOBIN)/golangci-lint \
-c $$KUSTOMIZE_ROOT/.golangci.yml \
--build-tags kustomize_disable_go_plugin_support \
--path-prefix api \
run ./...

View File

@@ -9,6 +9,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"sigs.k8s.io/kustomize/api/filters/fieldspec"
"sigs.k8s.io/kustomize/api/filters/filtersutil"
"sigs.k8s.io/kustomize/kyaml/kio"
@@ -621,7 +622,7 @@ kind: Pod
t.Run(name, func(t *testing.T) {
err := yaml.Unmarshal([]byte(tc.fieldSpec), &filter.FieldSpec)
assert.NoError(t, err)
require.NoError(t, err)
rw := &kio.ByteReadWriter{
Reader: bytes.NewBufferString(tc.input),
Writer: &bytes.Buffer{},
@@ -635,7 +636,7 @@ kind: Pod
Outputs: []kio.Writer{rw},
}.Execute()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, tc.expected, fieldPaths)
})
}

View File

@@ -6,7 +6,7 @@ package imagetag
import (
"sigs.k8s.io/kustomize/api/filters/filtersutil"
"sigs.k8s.io/kustomize/api/image"
"sigs.k8s.io/kustomize/api/internal/image"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/yaml"
)

View File

@@ -284,9 +284,9 @@ func (f Filter) roleRefFilter() sieveFunc {
return previousIdSelectedByGvk(roleRefGvk)
}
func prefixSuffixEquals(other resource.ResCtx) sieveFunc {
func prefixSuffixEquals(other resource.ResCtx, allowEmpty bool) sieveFunc {
return func(r *resource.Resource) bool {
return r.PrefixesSuffixesEquals(other)
return r.PrefixesSuffixesEquals(other, allowEmpty)
}
}
@@ -325,7 +325,10 @@ func (f Filter) selectReferral(
if len(candidates) == 1 {
return candidates[0], nil
}
candidates = doSieve(candidates, prefixSuffixEquals(f.Referrer))
candidates = doSieve(candidates, prefixSuffixEquals(f.Referrer, true))
if len(candidates) > 1 {
candidates = doSieve(candidates, prefixSuffixEquals(f.Referrer, false))
}
if len(candidates) == 1 {
return candidates[0], nil
}

View File

@@ -6,7 +6,7 @@ package patchjson6902
import (
"strings"
jsonpatch "github.com/evanphx/json-patch"
jsonpatch "gopkg.in/evanphx/json-patch.v4"
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/yaml"
k8syaml "sigs.k8s.io/yaml"

View File

@@ -776,6 +776,133 @@ spec:
autoscaling: true
deepgram-api:
some: value
`,
},
// Issue #4928
"support numeric keys": {
input: `
apiVersion: v1
kind: ConfigMap
metadata:
name: blabla
namespace: blabla-ns
data:
"6443": "foobar"
`,
patch: yaml.MustParse(`
apiVersion: v1
kind: ConfigMap
metadata:
name: blabla
namespace: blabla-ns
data:
"6443": "barfoo"
"9110": "foo-foo"
`),
expected: `
apiVersion: v1
kind: ConfigMap
metadata:
name: blabla
namespace: blabla-ns
data:
"6443": "barfoo"
"9110": "foo-foo"
`,
},
"honor different key style one": {
input: `
apiVersion: v1
kind: ConfigMap
metadata:
name: blabla
namespace: blabla-ns
data:
'6443': "foobar"
`,
patch: yaml.MustParse(`
apiVersion: v1
kind: ConfigMap
metadata:
name: blabla
namespace: blabla-ns
data:
"6443": "barfoo"
9110: "foo-foo"
`),
expected: `
apiVersion: v1
kind: ConfigMap
metadata:
name: blabla
namespace: blabla-ns
data:
'6443': "barfoo"
9110: "foo-foo"
`,
},
"honor different key style two": {
input: `
apiVersion: v1
kind: ConfigMap
metadata:
name: blabla
namespace: blabla-ns
data:
"6443": "foobar"
`,
patch: yaml.MustParse(`
apiVersion: v1
kind: ConfigMap
metadata:
name: blabla
namespace: blabla-ns
data:
"6443": "barfoo"
'9110': "foo-foo"
`),
expected: `
apiVersion: v1
kind: ConfigMap
metadata:
name: blabla
namespace: blabla-ns
data:
"6443": "barfoo"
'9110': "foo-foo"
`,
},
"different key types": {
input: `
apiVersion: v1
kind: ConfigMap
metadata:
name: blabla
namespace: blabla-ns
data:
"6443": "key-string-double-quoted"
`,
patch: yaml.MustParse(`
apiVersion: v1
kind: ConfigMap
metadata:
name: blabla
namespace: blabla-ns
data:
6443: "key-int"
`),
expected: `
apiVersion: v1
kind: ConfigMap
metadata:
name: blabla
namespace: blabla-ns
data:
"6443": "key-int"
`,
},
}

View File

@@ -126,8 +126,8 @@ func applyReplacement(nodes []*yaml.RNode, value *yaml.RNode, targetSelectors []
}
// filter targets by matching resource IDs
for i, id := range ids {
if id.IsSelectedBy(selector.Select.ResId) && !rejectId(selector.Reject, &ids[i]) {
for _, id := range ids {
if id.IsSelectedBy(selector.Select.ResId) && !containsRejectId(selector.Reject, ids) {
err := copyValueToTarget(possibleTarget, value, selector)
if err != nil {
return nil, err
@@ -168,10 +168,15 @@ func matchesAnnoAndLabelSelector(n *yaml.RNode, selector *types.Selector) (bool,
return annoMatch && labelMatch, nil
}
func rejectId(rejects []*types.Selector, id *resid.ResId) bool {
func containsRejectId(rejects []*types.Selector, ids []resid.ResId) bool {
for _, r := range rejects {
if !r.ResId.IsEmpty() && id.IsSelectedBy(r.ResId) {
return true
if r.ResId.IsEmpty() {
continue
}
for _, id := range ids {
if id.IsSelectedBy(r.ResId) {
return true
}
}
}
return false

View File

@@ -1,37 +1,35 @@
module sigs.k8s.io/kustomize/api
go 1.19
go 1.21
require (
github.com/evanphx/json-patch v4.11.0+incompatible
github.com/blang/semver/v4 v4.0.0
github.com/go-errors/errors v1.4.2
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/imdario/mergo v0.3.6
github.com/stretchr/testify v1.8.1
gopkg.in/yaml.v2 v2.4.0
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596
sigs.k8s.io/kustomize/kyaml v0.14.2
sigs.k8s.io/yaml v1.3.0
github.com/stretchr/testify v1.8.4
go.uber.org/goleak v1.3.0
gopkg.in/evanphx/json-patch.v4 v4.12.0
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00
sigs.k8s.io/kustomize/kyaml v0.17.1
sigs.k8s.io/yaml v1.4.0
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.5 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/xlab/treeprint v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
golang.org/x/sys v0.3.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
golang.org/x/sys v0.18.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

View File

@@ -1,60 +1,41 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/evanphx/json-patch v4.11.0+incompatible h1:glyUF9yIYtMHzn8xaKw5rMhdWcwsYV8dZHIq5567/xs=
github.com/evanphx/json-patch v4.11.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE=
github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs=
github.com/go-openapi/jsonreference v0.20.1 h1:FBLnyygC4/IZZr893oiomc9XaghoveYTrLC1F86HID8=
github.com/go-openapi/jsonreference v0.20.1/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k=
github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g=
github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE=
github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k=
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU=
github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/gnostic v0.5.7-v3refs h1:FhTMOKj2VhjpouxvWJAV1TL304uMlb9zcDqkl6cEI54=
github.com/google/gnostic v0.5.7-v3refs/go.mod h1:73MKFl6jIHelAJNaBGFzt3SPtZULs9dYrGFt8OiIsHQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/imdario/mergo v0.3.6 h1:xTNEAn+kxVO7dTZGu0CegyqKZmoWFI0rF8UxjlB2d28=
github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
@@ -65,91 +46,54 @@ github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
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/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/xlab/treeprint v1.1.0 h1:G/1DjNkPpfZCFt9CSh6b5/nY4VimlbHF3Rh4obvtzDk=
github.com/xlab/treeprint v1.1.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ=
github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0=
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 h1:+FNtrFTmVw0YZGpBGX56XDee331t6JAXeK2bcyhLOOc=
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5/go.mod h1:nmDLcffg48OtT/PSW0Hg7FvpRQsQh5OSqIylirxKC7o=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/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-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
golang.org/x/sys v0.0.0-20191002063906-3421d5a6bb1c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/genproto v0.0.0-20201019141844-1ed22bb0c154/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/evanphx/json-patch.v4 v4.12.0 h1:n6jtcsulIzXPJaxegRbvFNNrZDjbij7ny3gmSPG+6V4=
gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596 h1:8cNCQs+WqqnSpZ7y0LMQPKD+RZUHU17VqLPMW3qxnxc=
k8s.io/kube-openapi v0.0.0-20230109183929-3758b55a6596/go.mod h1:/BYxry62FuDzmI+i9B+X2pqfySRmSOW2ARmj5Zbqhj0=
sigs.k8s.io/kustomize/kyaml v0.14.2 h1:9WSwztbzwGszG1bZTziQUmVMrJccnyrLb5ZMKpJGvXw=
sigs.k8s.io/kustomize/kyaml v0.14.2/go.mod h1:AN1/IpawKilWD7V+YvQwRGUvuUOOWpjsHu6uHwonSF4=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/AuzbMm96cd3YHRTU83I780=
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/kustomize/kyaml v0.17.1 h1:TnxYQxFXzbmNG6gOINgGWQt09GghzgTP6mIurOgrLCQ=
sigs.k8s.io/kustomize/kyaml v0.17.1/go.mod h1:9V0mCjIEYjlXuCdYsSXvyoy2BTsLESH7TlGV81S282U=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=

View File

@@ -144,7 +144,7 @@ func loadCrdIntoConfig(
}
_, label := property.Extensions.GetString(xLabelSelector)
if label {
err = theConfig.AddLabelFieldSpec(
err = theConfig.AddCommonLabelsFieldSpec(
makeFs(theGvk, append(path, propName)))
if err != nil {
return

View File

@@ -9,8 +9,8 @@ import (
"github.com/stretchr/testify/require"
. "sigs.k8s.io/kustomize/api/internal/accumulator"
"sigs.k8s.io/kustomize/api/internal/loader"
"sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
"sigs.k8s.io/kustomize/api/loader"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/filesys"
"sigs.k8s.io/kustomize/kyaml/resid"

View File

@@ -590,7 +590,7 @@ func TestNameReferenceUnhappyRun(t *testing.T) {
func TestNameReferencePersistentVolumeHappyRun(t *testing.T) {
rf := provider.NewDefaultDepProvider().GetResourceFactory()
v1 := rf.FromMapWithName(
v1, err := rf.FromMapWithName(
"volume1",
map[string]interface{}{
"apiVersion": "v1",
@@ -599,7 +599,10 @@ func TestNameReferencePersistentVolumeHappyRun(t *testing.T) {
"name": "someprefix-volume1",
},
})
c1 := rf.FromMapWithName(
if err != nil {
t.Fatalf("failed to get new instance with given name: %v", err)
}
c1, err := rf.FromMapWithName(
"claim1",
map[string]interface{}{
"apiVersion": "v1",
@@ -612,9 +615,11 @@ func TestNameReferencePersistentVolumeHappyRun(t *testing.T) {
"volumeName": "volume1",
},
})
if err != nil {
t.Fatalf("failed to get new instance with given name: %v", err)
}
v2 := v1.DeepCopy()
c2 := rf.FromMapWithName(
c2, err := rf.FromMapWithName(
"claim1",
map[string]interface{}{
"apiVersion": "v1",
@@ -627,6 +632,9 @@ func TestNameReferencePersistentVolumeHappyRun(t *testing.T) {
"volumeName": "someprefix-volume1",
},
})
if err != nil {
t.Fatalf("failed to get new instance with given name: %v", err)
}
m1 := resmaptest_test.NewRmBuilder(t, rf).AddR(v1).AddR(c1).ResMap()

View File

@@ -64,7 +64,7 @@ func makeResAccumulator(t *testing.T) *ResAccumulator {
"name": "backendTwo",
}}).ResMap())
if err != nil {
t.Fatalf("unexpected err: %v", err)
t.Fatalf("failed to append resources: %v", err)
}
return ra
}
@@ -143,22 +143,26 @@ func expectLog(t *testing.T, log bytes.Buffer, expect string) {
func TestResolveVarsVarNeedsDisambiguation(t *testing.T) {
ra := makeResAccumulator(t)
rm0 := resmap.New()
err := rm0.Append(
provider.NewDefaultDepProvider().GetResourceFactory().FromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "Service",
"metadata": map[string]interface{}{
"name": "backendOne",
"namespace": "fooNamespace",
},
}))
r, err := provider.NewDefaultDepProvider().GetResourceFactory().FromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "Service",
"metadata": map[string]interface{}{
"name": "backendOne",
"namespace": "fooNamespace",
},
})
if err != nil {
t.Fatalf("unexpected err: %v", err)
t.Fatalf("failed to get instance of resources: %v", err)
}
err = rm0.Append(r)
if err != nil {
t.Fatalf("failed to append a resource to ResMap: %v", err)
}
err = ra.AppendAll(rm0)
if err != nil {
t.Fatalf("unexpected err: %v", err)
t.Fatalf("failed to append a resource to ResAccumulator: %v", err)
}
err = ra.MergeVars([]types.Var{
@@ -227,7 +231,11 @@ func TestResolveVarConflicts(t *testing.T) {
// create accumulators holding apparently conflicting vars that are not
// actually in conflict because they point to the same concrete value.
rm0 := resmap.New()
err := rm0.Append(rf.FromMap(fooAws))
r0, err0 := rf.FromMap(fooAws)
if err0 != nil {
t.Fatalf("failed to get instance of resources: %v", err0)
}
err := rm0.Append(r0)
require.NoError(t, err)
ac0 := MakeEmptyAccumulator()
err = ac0.AppendAll(rm0)
@@ -236,7 +244,11 @@ func TestResolveVarConflicts(t *testing.T) {
require.NoError(t, err)
rm1 := resmap.New()
err = rm1.Append(rf.FromMap(barAws))
r1, err1 := rf.FromMap(barAws)
if err1 != nil {
t.Fatalf("failed to get instance of resources: %v", err1)
}
err = rm1.Append(r1)
require.NoError(t, err)
ac1 := MakeEmptyAccumulator()
err = ac1.AppendAll(rm1)
@@ -255,7 +267,11 @@ func TestResolveVarConflicts(t *testing.T) {
// two above (because it contains a variable whose name is used in the other
// accumulators AND whose concrete values are different).
rm2 := resmap.New()
err = rm2.Append(rf.FromMap(barGcp))
r2, err2 := rf.FromMap(barGcp)
if err2 != nil {
t.Fatalf("failed to get instance of resources: %v", err2)
}
err = rm2.Append(r2)
require.NoError(t, err)
ac2 := MakeEmptyAccumulator()
err = ac2.AppendAll(rm2)

View File

@@ -12,11 +12,12 @@ import (
"regexp"
"strings"
"github.com/imdario/mergo"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/kio"
kyaml "sigs.k8s.io/kustomize/kyaml/yaml"
"sigs.k8s.io/kustomize/kyaml/yaml/merge2"
"sigs.k8s.io/yaml"
)
@@ -53,6 +54,15 @@ func (p *HelmChartInflationGeneratorPlugin) Config(
if h.GeneralConfig().HelmConfig.Command == "" {
return fmt.Errorf("must specify --helm-command")
}
// CLI args takes precedence
if h.GeneralConfig().HelmConfig.KubeVersion != "" {
p.HelmChart.KubeVersion = h.GeneralConfig().HelmConfig.KubeVersion
}
if len(h.GeneralConfig().HelmConfig.ApiVersions) != 0 {
p.HelmChart.ApiVersions = h.GeneralConfig().HelmConfig.ApiVersions
}
p.h = h
if err = yaml.Unmarshal(config, p); err != nil {
return
@@ -91,7 +101,7 @@ func (p *HelmChartInflationGeneratorPlugin) validateArgs() (err error) {
// be under the loader root (unless root restrictions are
// disabled).
if p.ValuesFile == "" {
p.ValuesFile = filepath.Join(p.ChartHome, p.Name, "values.yaml")
p.ValuesFile = filepath.Join(p.absChartHome(), p.Name, "values.yaml")
}
for i, file := range p.AdditionalValuesFiles {
// use Load() to enforce root restrictions
@@ -132,10 +142,17 @@ func (p *HelmChartInflationGeneratorPlugin) errIfIllegalValuesMerge() error {
}
func (p *HelmChartInflationGeneratorPlugin) absChartHome() string {
var chartHome string
if filepath.IsAbs(p.ChartHome) {
return p.ChartHome
chartHome = p.ChartHome
} else {
chartHome = filepath.Join(p.h.Loader().Root(), p.ChartHome)
}
return filepath.Join(p.h.Loader().Root(), p.ChartHome)
if p.Version != "" && p.Repo != "" {
return filepath.Join(chartHome, fmt.Sprintf("%s-%s", p.Name, p.Version))
}
return chartHome
}
func (p *HelmChartInflationGeneratorPlugin) runHelmCommand(
@@ -185,18 +202,33 @@ func (p *HelmChartInflationGeneratorPlugin) replaceValuesInline() error {
if err != nil {
return err
}
chValues := make(map[string]interface{})
if err = yaml.Unmarshal(pValues, &chValues); err != nil {
return err
chValues, err := kyaml.Parse(string(pValues))
if err != nil {
return errors.WrapPrefixf(err, "could not parse values file into rnode")
}
inlineValues, err := kyaml.FromMap(p.ValuesInline)
if err != nil {
return errors.WrapPrefixf(err, "could not parse values inline into rnode")
}
var outValues *kyaml.RNode
switch p.ValuesMerge {
// Function `merge2.Merge` overrides values in dest with values from src.
// To achieve override or merge behavior, we pass parameters in different order.
// Object passed as dest will be modified, so we copy it just in case someone
// decides to use it after this is called.
case valuesMergeOptionOverride:
err = mergo.Merge(
&chValues, p.ValuesInline, mergo.WithOverride)
outValues, err = merge2.Merge(inlineValues, chValues.Copy(), kyaml.MergeOptions{})
case valuesMergeOptionMerge:
err = mergo.Merge(&chValues, p.ValuesInline)
outValues, err = merge2.Merge(chValues, inlineValues.Copy(), kyaml.MergeOptions{})
}
p.ValuesInline = chValues
if err != nil {
return errors.WrapPrefixf(err, "could not merge values")
}
mapValues, err := outValues.Map()
if err != nil {
return errors.WrapPrefixf(err, "could not parse merged values into map")
}
p.ValuesInline = mapValues
return err
}
@@ -281,8 +313,18 @@ func (p *HelmChartInflationGeneratorPlugin) pullCommand() []string {
"pull",
"--untar",
"--untardir", p.absChartHome(),
"--repo", p.Repo,
p.Name}
}
switch {
case strings.HasPrefix(p.Repo, "oci://"):
args = append(args, strings.TrimSuffix(p.Repo, "/")+"/"+p.Name)
case p.Repo != "":
args = append(args, "--repo", p.Repo)
fallthrough
default:
args = append(args, p.Name)
}
if p.Version != "" {
args = append(args, "--version", p.Version)
}

View File

@@ -6,7 +6,7 @@ package builtins
import (
"fmt"
jsonpatch "github.com/evanphx/json-patch"
jsonpatch "gopkg.in/evanphx/json-patch.v4"
"sigs.k8s.io/kustomize/api/filters/patchjson6902"
"sigs.k8s.io/kustomize/api/ifc"
"sigs.k8s.io/kustomize/api/resmap"

View File

@@ -7,104 +7,123 @@ import (
"fmt"
"strings"
jsonpatch "github.com/evanphx/json-patch"
jsonpatch "gopkg.in/evanphx/json-patch.v4"
"sigs.k8s.io/kustomize/api/filters/patchjson6902"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/kio/kioutil"
"sigs.k8s.io/yaml"
)
type PatchTransformerPlugin struct {
loadedPatch *resource.Resource
decodedPatch jsonpatch.Patch
Path string `json:"path,omitempty" yaml:"path,omitempty"`
Patch string `json:"patch,omitempty" yaml:"patch,omitempty"`
Target *types.Selector `json:"target,omitempty" yaml:"target,omitempty"`
Options map[string]bool `json:"options,omitempty" yaml:"options,omitempty"`
smPatches []*resource.Resource // strategic-merge patches
jsonPatches jsonpatch.Patch // json6902 patch
// patchText is pure patch text created by Path or Patch
patchText string
// patchSource is patch source message
patchSource string
Path string `json:"path,omitempty" yaml:"path,omitempty"`
Patch string `json:"patch,omitempty" yaml:"patch,omitempty"`
Target *types.Selector `json:"target,omitempty" yaml:"target,omitempty"`
Options map[string]bool `json:"options,omitempty" yaml:"options,omitempty"`
}
func (p *PatchTransformerPlugin) Config(
h *resmap.PluginHelpers, c []byte) error {
err := yaml.Unmarshal(c, p)
if err != nil {
func (p *PatchTransformerPlugin) Config(h *resmap.PluginHelpers, c []byte) error {
if err := yaml.Unmarshal(c, p); err != nil {
return err
}
p.Patch = strings.TrimSpace(p.Patch)
if p.Patch == "" && p.Path == "" {
return fmt.Errorf(
"must specify one of patch and path in\n%s", string(c))
}
if p.Patch != "" && p.Path != "" {
return fmt.Errorf(
"patch and path can't be set at the same time\n%s", string(c))
}
if p.Path != "" {
loaded, loadErr := h.Loader().Load(p.Path)
if loadErr != nil {
return loadErr
switch {
case p.Patch == "" && p.Path == "":
return fmt.Errorf("must specify one of patch and path in\n%s", string(c))
case p.Patch != "" && p.Path != "":
return fmt.Errorf("patch and path can't be set at the same time\n%s", string(c))
case p.Patch != "":
p.patchText = p.Patch
p.patchSource = fmt.Sprintf("[patch: %q]", p.patchText)
case p.Path != "":
loaded, err := h.Loader().Load(p.Path)
if err != nil {
return fmt.Errorf("failed to get the patch file from path(%s): %w", p.Path, err)
}
p.Patch = string(loaded)
p.patchText = string(loaded)
p.patchSource = fmt.Sprintf("[path: %q]", p.Path)
}
patchSM, errSM := h.ResmapFactory().RF().FromBytes([]byte(p.Patch))
patchJson, errJson := jsonPatchFromBytes([]byte(p.Patch))
patchesSM, errSM := h.ResmapFactory().RF().SliceFromBytes([]byte(p.patchText))
patchesJson, errJson := jsonPatchFromBytes([]byte(p.patchText))
if (errSM == nil && errJson == nil) ||
(patchSM != nil && patchJson != nil) {
(patchesSM != nil && patchesJson != nil) {
return fmt.Errorf(
"illegally qualifies as both an SM and JSON patch: [%v]",
p.Patch)
"illegally qualifies as both an SM and JSON patch: %s",
p.patchSource)
}
if errSM != nil && errJson != nil {
return fmt.Errorf(
"unable to parse SM or JSON patch from [%v]", p.Patch)
"unable to parse SM or JSON patch from %s", p.patchSource)
}
if errSM == nil {
p.loadedPatch = patchSM
if p.Options["allowNameChange"] {
p.loadedPatch.AllowNameChange()
}
if p.Options["allowKindChange"] {
p.loadedPatch.AllowKindChange()
p.smPatches = patchesSM
for _, loadedPatch := range p.smPatches {
if p.Options["allowNameChange"] {
loadedPatch.AllowNameChange()
}
if p.Options["allowKindChange"] {
loadedPatch.AllowKindChange()
}
}
} else {
p.decodedPatch = patchJson
p.jsonPatches = patchesJson
}
return nil
}
func (p *PatchTransformerPlugin) Transform(m resmap.ResMap) error {
if p.loadedPatch == nil {
return p.transformJson6902(m, p.decodedPatch)
if p.smPatches != nil {
return p.transformStrategicMerge(m)
}
// The patch was a strategic merge patch
return p.transformStrategicMerge(m, p.loadedPatch)
return p.transformJson6902(m)
}
// transformStrategicMerge applies the provided strategic merge patch
// to all the resources in the ResMap that match either the Target or
// the identifier of the patch.
func (p *PatchTransformerPlugin) transformStrategicMerge(m resmap.ResMap, patch *resource.Resource) error {
if p.Target == nil {
// transformStrategicMerge applies each loaded strategic merge patch
// to the resource in the ResMap that matches the identifier of the patch.
// If only one patch is specified, the Target can be used instead.
func (p *PatchTransformerPlugin) transformStrategicMerge(m resmap.ResMap) error {
if p.Target != nil {
if len(p.smPatches) > 1 {
// detail: https://github.com/kubernetes-sigs/kustomize/issues/5049#issuecomment-1440604403
return fmt.Errorf("Multiple Strategic-Merge Patches in one `patches` entry is not allowed to set `patches.target` field: %s", p.patchSource)
}
// single patch
patch := p.smPatches[0]
selected, err := m.Select(*p.Target)
if err != nil {
return fmt.Errorf("unable to find patch target %q in `resources`: %w", p.Target, err)
}
return errors.Wrap(m.ApplySmPatch(resource.MakeIdSet(selected), patch))
}
for _, patch := range p.smPatches {
target, err := m.GetById(patch.OrgId())
if err != nil {
return err
return fmt.Errorf("no resource matches strategic merge patch %q: %w", patch.OrgId(), err)
}
if err := target.ApplySmPatch(patch); err != nil {
return errors.Wrap(err)
}
return target.ApplySmPatch(patch)
}
selected, err := m.Select(*p.Target)
if err != nil {
return err
}
return m.ApplySmPatch(resource.MakeIdSet(selected), patch)
return nil
}
// transformJson6902 applies the provided json6902 patch
// to all the resources in the ResMap that match the Target.
func (p *PatchTransformerPlugin) transformJson6902(m resmap.ResMap, patch jsonpatch.Patch) error {
// transformJson6902 applies json6902 Patch to all the resources in the ResMap that match Target.
func (p *PatchTransformerPlugin) transformJson6902(m resmap.ResMap) error {
if p.Target == nil {
return fmt.Errorf("must specify a target for patch %s", p.Patch)
return fmt.Errorf("must specify a target for JSON patch %s", p.patchSource)
}
resources, err := m.Select(*p.Target)
if err != nil {
@@ -114,7 +133,7 @@ func (p *PatchTransformerPlugin) transformJson6902(m resmap.ResMap, patch jsonpa
res.StorePreviousId()
internalAnnotations := kioutil.GetInternalAnnotations(&res.RNode)
err = res.ApplyFilter(patchjson6902.Filter{
Patch: p.Patch,
Patch: p.patchText,
})
if err != nil {
return err
@@ -129,16 +148,17 @@ func (p *PatchTransformerPlugin) transformJson6902(m resmap.ResMap, patch jsonpa
return nil
}
// jsonPatchFromBytes loads a Json 6902 patch from
// a bytes input
func jsonPatchFromBytes(
in []byte) (jsonpatch.Patch, error) {
// jsonPatchFromBytes loads a Json 6902 patch from a bytes input
func jsonPatchFromBytes(in []byte) (jsonpatch.Patch, error) {
ops := string(in)
if ops == "" {
return nil, fmt.Errorf("empty json patch operations")
}
if ops[0] != '[' {
// TODO(5049):
// In the case of multiple yaml documents, return error instead of ignoring all but first.
// Details: https://github.com/kubernetes-sigs/kustomize/pull/5194#discussion_r1256686728
jsonOps, err := yaml.YAMLToJSON(in)
if err != nil {
return nil, err

View File

@@ -74,34 +74,16 @@ func (p *SortOrderTransformerPlugin) Transform(m resmap.ResMap) (err error) {
// Sort
if p.SortOptions.Order == types.LegacySortOrder {
s := newLegacyIDSorter(m.AllIds(), p.SortOptions.LegacySortOptions)
s := newLegacyIDSorter(m.Resources(), p.SortOptions.LegacySortOptions)
sort.Sort(s)
err = applyOrdering(m, s.resids)
if err != nil {
return err
}
}
return nil
}
// applyOrdering takes resources (given in ResMap) and a desired ordering given
// as a sequence of ResIds, and updates the ResMap's resources to match the
// ordering.
func applyOrdering(m resmap.ResMap, ordering []resid.ResId) error {
var err error
resources := make([]*resource.Resource, m.Size())
// Clear and refill with the correct order
for i, id := range ordering {
resources[i], err = m.GetByCurrentId(id)
if err != nil {
return errors.WrapPrefixf(err, "expected match for sorting")
}
}
m.Clear()
for _, r := range resources {
err = m.Append(r)
if err != nil {
return errors.WrapPrefixf(err, "SortOrderTransformer: Failed to append to resources")
// Clear the map and re-add the resources in the sorted order.
m.Clear()
for _, r := range s.resources {
err := m.Append(r)
if err != nil {
return errors.WrapPrefixf(err, "SortOrderTransformer: Failed to append to resources")
}
}
}
return nil
@@ -117,12 +99,17 @@ func applyOrdering(m resmap.ResMap, ordering []resid.ResId) error {
type legacyIDSorter struct {
// resids only stores the metadata of the object. This is an optimization as
// it's expensive to compute these again and again during ordering.
resids []resid.ResId
resids []resid.ResId
// Initially, we sorted the metadata (ResId) of each object and then called GetByCurrentId on each to construct the final list.
// The problem is that GetByCurrentId is inefficient and does a linear scan in a list every time we do that.
// So instead, we sort resources alongside the ResIds.
resources []*resource.Resource
typeOrders map[string]int
}
func newLegacyIDSorter(
resids []resid.ResId,
resources []*resource.Resource,
options *types.LegacySortOptions) *legacyIDSorter {
// Precalculate a resource ranking based on the priority lists.
var typeOrders = func() map[string]int {
@@ -135,10 +122,13 @@ func newLegacyIDSorter(
}
return m
}()
return &legacyIDSorter{
resids: resids,
typeOrders: typeOrders,
ret := &legacyIDSorter{typeOrders: typeOrders}
for _, res := range resources {
ret.resids = append(ret.resids, res.CurId())
ret.resources = append(ret.resources, res)
}
return ret
}
var _ sort.Interface = legacyIDSorter{}
@@ -146,6 +136,7 @@ var _ sort.Interface = legacyIDSorter{}
func (a legacyIDSorter) Len() int { return len(a.resids) }
func (a legacyIDSorter) Swap(i, j int) {
a.resids[i], a.resids[j] = a.resids[j], a.resids[i]
a.resources[i], a.resources[j] = a.resources[j], a.resources[i]
}
func (a legacyIDSorter) Less(i, j int) bool {
if !a.resids[i].Gvk.Equals(a.resids[j].Gvk) {

View File

@@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/assert"
. "sigs.k8s.io/kustomize/api/internal/generators"
"sigs.k8s.io/kustomize/api/kv"
"sigs.k8s.io/kustomize/api/loader"
"sigs.k8s.io/kustomize/api/pkg/loader"
valtest_test "sigs.k8s.io/kustomize/api/testutils/valtest"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/filesys"

View File

@@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/assert"
. "sigs.k8s.io/kustomize/api/internal/generators"
"sigs.k8s.io/kustomize/api/kv"
"sigs.k8s.io/kustomize/api/loader"
"sigs.k8s.io/kustomize/api/pkg/loader"
valtest_test "sigs.k8s.io/kustomize/api/testutils/valtest"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/filesys"

View File

@@ -22,10 +22,16 @@ func ClonerUsingGitExec(repoSpec *RepoSpec) error {
if err = r.run("init"); err != nil {
return err
}
// git relative submodule need origin, see https://github.com/kubernetes-sigs/kustomize/issues/5131
if err = r.run("remote", "add", "origin", repoSpec.CloneSpec()); err != nil {
return err
}
ref := "HEAD"
if repoSpec.Ref != "" {
ref = repoSpec.Ref
}
// we use repoSpec.CloneSpec() instead of origin because on error,
// the prior prints the actual repo url for the user.
if err = r.run("fetch", "--depth=1", repoSpec.CloneSpec(), ref); err != nil {
return err
}

View File

@@ -1,12 +1,13 @@
// Copyright 2020 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package image
package image_test
import (
"testing"
"github.com/stretchr/testify/assert"
"sigs.k8s.io/kustomize/api/internal/image"
)
func TestIsImageMatched(t *testing.T) {
@@ -50,7 +51,7 @@ func TestIsImageMatched(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.testName, func(t *testing.T) {
assert.Equal(t, tc.isMatched, IsImageMatched(tc.value, tc.name))
assert.Equal(t, tc.isMatched, image.IsImageMatched(tc.value, tc.name))
})
}
}
@@ -116,7 +117,7 @@ func TestSplit(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.testName, func(t *testing.T) {
name, tag, digest := Split(tc.value)
name, tag, digest := image.Split(tc.value)
assert.Equal(t, tc.name, name)
assert.Equal(t, tc.tag, tag)
assert.Equal(t, tc.digest, digest)

View File

@@ -25,7 +25,7 @@ func IsRemoteFile(path string) bool {
return err == nil && (u.Scheme == "http" || u.Scheme == "https")
}
// fileLoader is a kustomization's interface to files.
// FileLoader is a kustomization's interface to files.
//
// The directory in which a kustomization file sits
// is referred to below as the kustomization's _root_.
@@ -38,49 +38,48 @@ func IsRemoteFile(path string) bool {
//
// * supplemental data paths
//
// `Load` is used to visit these paths.
// `Load` is used to visit these paths.
//
// These paths refer to resources, patches,
// data for ConfigMaps and Secrets, etc.
// These paths refer to resources, patches,
// data for ConfigMaps and Secrets, etc.
//
// The loadRestrictor may disallow certain paths
// or classes of paths.
// The loadRestrictor may disallow certain paths
// or classes of paths.
//
// * bases (other kustomizations)
//
// `New` is used to load bases.
// `New` is used to load bases.
//
// A base can be either a remote git repo URL, or
// a directory specified relative to the current
// root. In the former case, the repo is locally
// cloned, and the new loader is rooted on a path
// in that clone.
// A base can be either a remote git repo URL, or
// a directory specified relative to the current
// root. In the former case, the repo is locally
// cloned, and the new loader is rooted on a path
// in that clone.
//
// As loaders create new loaders, a root history
// is established, and used to disallow:
// As loaders create new loaders, a root history
// is established, and used to disallow:
//
// - A base that is a repository that, in turn,
// specifies a base repository seen previously
// in the loading stack (a cycle).
// - A base that is a repository that, in turn,
// specifies a base repository seen previously
// in the loading stack (a cycle).
//
// - An overlay depending on a base positioned at
// or above it. I.e. '../foo' is OK, but '.',
// '..', '../..', etc. are disallowed. Allowing
// such a base has no advantages and encourages
// cycles, particularly if some future change
// were to introduce globbing to file
// specifications in the kustomization file.
// - An overlay depending on a base positioned at
// or above it. I.e. '../foo' is OK, but '.',
// '..', '../..', etc. are disallowed. Allowing
// such a base has no advantages and encourages
// cycles, particularly if some future change
// were to introduce globbing to file
// specifications in the kustomization file.
//
// These restrictions assure that kustomizations
// are self-contained and relocatable, and impose
// some safety when relying on remote kustomizations,
// e.g. a remotely loaded ConfigMap generator specified
// to read from /etc/passwd will fail.
//
type fileLoader struct {
type FileLoader struct {
// Loader that spawned this loader.
// Used to avoid cycles.
referrer *fileLoader
referrer *FileLoader
// An absolute, cleaned path to a directory.
// The Load function will read non-absolute
@@ -107,23 +106,9 @@ type fileLoader struct {
cleaner func() error
}
// NewFileLoaderAtCwd returns a loader that loads from PWD.
// A convenience for kustomize edit commands.
func NewFileLoaderAtCwd(fSys filesys.FileSystem) *fileLoader {
return newLoaderOrDie(
RestrictionRootOnly, fSys, filesys.SelfDir)
}
// NewFileLoaderAtRoot returns a loader that loads from "/".
// A convenience for tests.
func NewFileLoaderAtRoot(fSys filesys.FileSystem) *fileLoader {
return newLoaderOrDie(
RestrictionRootOnly, fSys, filesys.Separator)
}
// Repo returns the absolute path to the repo that contains Root if this fileLoader was created from a url
// or the empty string otherwise.
func (fl *fileLoader) Repo() string {
func (fl *FileLoader) Repo() string {
if fl.repoSpec != nil {
return fl.repoSpec.Dir.String()
}
@@ -132,13 +117,13 @@ func (fl *fileLoader) Repo() string {
// Root returns the absolute path that is prepended to any
// relative paths used in Load.
func (fl *fileLoader) Root() string {
func (fl *FileLoader) Root() string {
return fl.root.String()
}
func newLoaderOrDie(
func NewLoaderOrDie(
lr LoadRestrictorFunc,
fSys filesys.FileSystem, path string) *fileLoader {
fSys filesys.FileSystem, path string) *FileLoader {
root, err := filesys.ConfirmDir(fSys, path)
if err != nil {
log.Fatalf("unable to make loader at '%s'; %v", path, err)
@@ -147,12 +132,12 @@ func newLoaderOrDie(
lr, root, fSys, nil, git.ClonerUsingGitExec)
}
// newLoaderAtConfirmedDir returns a new fileLoader with given root.
// newLoaderAtConfirmedDir returns a new FileLoader with given root.
func newLoaderAtConfirmedDir(
lr LoadRestrictorFunc,
root filesys.ConfirmedDir, fSys filesys.FileSystem,
referrer *fileLoader, cloner git.Cloner) *fileLoader {
return &fileLoader{
referrer *FileLoader, cloner git.Cloner) *FileLoader {
return &FileLoader{
loadRestrictor: lr,
root: root,
referrer: referrer,
@@ -164,7 +149,7 @@ func newLoaderAtConfirmedDir(
// New returns a new Loader, rooted relative to current loader,
// or rooted in a temp directory holding a git repo clone.
func (fl *fileLoader) New(path string) (ifc.Loader, error) {
func (fl *FileLoader) New(path string) (ifc.Loader, error) {
if path == "" {
return nil, errors.Errorf("new root cannot be empty")
}
@@ -200,7 +185,7 @@ func (fl *fileLoader) New(path string) (ifc.Loader, error) {
// directory holding a cloned git repo.
func newLoaderAtGitClone(
repoSpec *git.RepoSpec, fSys filesys.FileSystem,
referrer *fileLoader, cloner git.Cloner) (ifc.Loader, error) {
referrer *FileLoader, cloner git.Cloner) (ifc.Loader, error) {
cleaner := repoSpec.Cleaner(fSys)
err := cloner(repoSpec)
if err != nil {
@@ -229,7 +214,7 @@ func newLoaderAtGitClone(
return nil, fmt.Errorf("%q refers to directory outside of repo %q", repoSpec.AbsPath(),
repoSpec.CloneDir())
}
return &fileLoader{
return &FileLoader{
// Clones never allowed to escape root.
loadRestrictor: RestrictionRootOnly,
root: root,
@@ -241,7 +226,7 @@ func newLoaderAtGitClone(
}, nil
}
func (fl *fileLoader) errIfGitContainmentViolation(
func (fl *FileLoader) errIfGitContainmentViolation(
base filesys.ConfirmedDir) error {
containingRepo := fl.containingRepo()
if containingRepo == nil {
@@ -259,7 +244,7 @@ func (fl *fileLoader) errIfGitContainmentViolation(
// Looks back through referrers for a git repo, returning nil
// if none found.
func (fl *fileLoader) containingRepo() *git.RepoSpec {
func (fl *FileLoader) containingRepo() *git.RepoSpec {
if fl.repoSpec != nil {
return fl.repoSpec
}
@@ -271,7 +256,7 @@ func (fl *fileLoader) containingRepo() *git.RepoSpec {
// errIfArgEqualOrHigher tests whether the argument,
// is equal to or above the root of any ancestor.
func (fl *fileLoader) errIfArgEqualOrHigher(
func (fl *FileLoader) errIfArgEqualOrHigher(
candidateRoot filesys.ConfirmedDir) error {
if fl.root.HasPrefix(candidateRoot) {
return fmt.Errorf(
@@ -288,7 +273,7 @@ func (fl *fileLoader) errIfArgEqualOrHigher(
// I.e. Allow a distinction between git URI with
// path foo and tag bar and a git URI with the same
// path but a different tag?
func (fl *fileLoader) errIfRepoCycle(newRepoSpec *git.RepoSpec) error {
func (fl *FileLoader) errIfRepoCycle(newRepoSpec *git.RepoSpec) error {
// TODO(monopole): Use parsed data instead of Raw().
if fl.repoSpec != nil &&
strings.HasPrefix(fl.repoSpec.Raw(), newRepoSpec.Raw()) {
@@ -305,7 +290,7 @@ func (fl *fileLoader) errIfRepoCycle(newRepoSpec *git.RepoSpec) error {
// Load returns the content of file at the given path,
// else an error. Relative paths are taken relative
// to the root.
func (fl *fileLoader) Load(path string) ([]byte, error) {
func (fl *FileLoader) Load(path string) ([]byte, error) {
if IsRemoteFile(path) {
return fl.httpClientGetContent(path)
}
@@ -319,7 +304,7 @@ func (fl *fileLoader) Load(path string) ([]byte, error) {
return fl.fSys.ReadFile(path)
}
func (fl *fileLoader) httpClientGetContent(path string) ([]byte, error) {
func (fl *FileLoader) httpClientGetContent(path string) ([]byte, error) {
var hc *http.Client
if fl.http != nil {
hc = fl.http
@@ -344,6 +329,6 @@ func (fl *fileLoader) httpClientGetContent(path string) ([]byte, error) {
}
// Cleanup runs the cleaner.
func (fl *fileLoader) Cleanup() error {
func (fl *FileLoader) Cleanup() error {
return fl.cleaner()
}

View File

@@ -31,6 +31,11 @@ func TestIsRemoteFile(t *testing.T) {
"https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/examples/helloWorld/configMap.yaml",
true,
},
"malformed https": {
// TODO(annasong): Maybe we want to fix this. Needs more research.
"https:/raw.githubusercontent.com/kubernetes-sigs/kustomize/master/examples/helloWorld/configMap.yaml",
true,
},
"https dir": {
"https://github.com/kubernetes-sigs/kustomize//examples/helloWorld/",
true,
@@ -88,8 +93,9 @@ func MakeFakeFs(td []testData) filesys.FileSystem {
return fSys
}
func makeLoader() *fileLoader {
return NewFileLoaderAtRoot(MakeFakeFs(testCases))
func makeLoader() *FileLoader {
return NewLoaderOrDie(
RestrictionRootOnly, MakeFakeFs(testCases), filesys.Separator)
}
func TestLoaderLoad(t *testing.T) {
@@ -196,13 +202,52 @@ func TestLoaderBadRelative(t *testing.T) {
require.Error(err)
}
func TestLoaderMisc(t *testing.T) {
l := makeLoader()
_, err := l.New("")
func TestNewEmptyLoader(t *testing.T) {
_, err := makeLoader().New("")
require.Error(t, err)
}
_, err = l.New("https://google.com/project")
require.Error(t, err)
func TestNewRemoteLoaderDoesNotExist(t *testing.T) {
_, err := makeLoader().New("https://example.com/org/repo")
require.ErrorContains(t, err, "fetch")
}
func TestLoaderLocalScheme(t *testing.T) {
// It is unlikely but possible for a reference with a url scheme to
// actually refer to a local file or directory.
t.Run("file", func(t *testing.T) {
fSys, dir := setupOnDisk(t)
parts := []string{
"ssh:",
"resource.yaml",
}
require.NoError(t, fSys.Mkdir(dir.Join(parts[0])))
const content = "resource config"
require.NoError(t, fSys.WriteFile(
dir.Join(filepath.Join(parts...)),
[]byte(content),
))
actualContent, err := NewLoaderOrDie(RestrictionRootOnly,
fSys,
dir.String(),
).Load(strings.Join(parts, "//"))
require.NoError(t, err)
require.Equal(t, content, string(actualContent))
})
t.Run("directory", func(t *testing.T) {
fSys, dir := setupOnDisk(t)
parts := []string{
"https:",
"root",
}
require.NoError(t, fSys.MkdirAll(dir.Join(filepath.Join(parts...))))
ldr, err := NewLoaderOrDie(RestrictionRootOnly,
fSys,
dir.String(),
).New(strings.Join(parts, "//"))
require.NoError(t, err)
require.Empty(t, ldr.Repo())
})
}
const (
@@ -212,17 +257,17 @@ const (
// Create a structure like this
//
// /tmp/kustomize-test-random
// ├── base
// │ ├── okayData
// │ ├── symLinkToOkayData -> okayData
// │ └── symLinkToExteriorData -> ../exteriorData
// └── exteriorData
//
// /tmp/kustomize-test-random
// ├── base
// │ ├── okayData
// │ ├── symLinkToOkayData -> okayData
// │ └── symLinkToExteriorData -> ../exteriorData
// └── exteriorData
func commonSetupForLoaderRestrictionTest(t *testing.T) (string, filesys.FileSystem) {
t.Helper()
dir := t.TempDir()
fSys := filesys.MakeFsOnDisk()
fSys, tmpDir := setupOnDisk(t)
dir := tmpDir.String()
fSys.Mkdir(filepath.Join(dir, "base"))
fSys.WriteFile(
@@ -278,7 +323,7 @@ func TestRestrictionRootOnlyInRealLoader(t *testing.T) {
var l ifc.Loader
l = newLoaderOrDie(RestrictionRootOnly, fSys, dir)
l = NewLoaderOrDie(RestrictionRootOnly, fSys, dir)
l = doSanityChecksAndDropIntoBase(t, l)
@@ -299,7 +344,7 @@ func TestRestrictionNoneInRealLoader(t *testing.T) {
var l ifc.Loader
l = newLoaderOrDie(RestrictionNone, fSys, dir)
l = NewLoaderOrDie(RestrictionNone, fSys, dir)
l = doSanityChecksAndDropIntoBase(t, l)
@@ -398,7 +443,7 @@ func TestLoaderDisallowsLocalBaseFromRemoteOverlay(t *testing.T) {
// Establish that a local overlay can navigate
// to the local bases.
l1 = newLoaderOrDie(
l1 = NewLoaderOrDie(
RestrictionRootOnly, fSys, cloneRoot+"/foo/overlay")
require.Equal(cloneRoot+"/foo/overlay", l1.Root())
@@ -446,12 +491,8 @@ func TestLoaderDisallowsLocalBaseFromRemoteOverlay(t *testing.T) {
}
func TestLoaderDisallowsRemoteBaseExitRepo(t *testing.T) {
fSys := filesys.MakeFsOnDisk()
dir, err := filesys.NewTmpConfirmedDir()
require.NoError(t, err)
t.Cleanup(func() {
_ = fSys.RemoveAll(dir.String())
})
fSys, dir := setupOnDisk(t)
repo := dir.Join("repo")
require.NoError(t, fSys.Mkdir(repo))
@@ -560,7 +601,8 @@ func TestLoaderHTTP(t *testing.T) {
},
}
l1 := NewFileLoaderAtRoot(MakeFakeFs(testCasesFile))
l1 := NewLoaderOrDie(
RestrictionRootOnly, MakeFakeFs(testCasesFile), filesys.Separator)
require.Equal("/", l1.Root())
for _, x := range testCasesFile {
@@ -618,3 +660,19 @@ func TestLoaderHTTP(t *testing.T) {
require.Error(err)
}
}
// setupOnDisk sets up a file system on disk and directory that is cleaned after
// test completion.
// TODO(annasong): Move all loader tests that require real file system into
// api/krusty.
func setupOnDisk(t *testing.T) (filesys.FileSystem, filesys.ConfirmedDir) {
t.Helper()
fSys := filesys.MakeFsOnDisk()
dir, err := filesys.NewTmpConfirmedDir()
require.NoError(t, err)
t.Cleanup(func() {
_ = fSys.RemoveAll(dir.String())
})
return fSys, dir
}

View File

@@ -11,8 +11,8 @@ import (
"sigs.k8s.io/kustomize/api/ifc"
"sigs.k8s.io/kustomize/api/internal/generators"
"sigs.k8s.io/kustomize/api/internal/loader"
"sigs.k8s.io/kustomize/api/internal/target"
"sigs.k8s.io/kustomize/api/loader"
"sigs.k8s.io/kustomize/api/provider"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/types"
@@ -381,7 +381,7 @@ func (lc *localizer) localizeFileWithContent(path string, content []byte) (strin
// 2. avoid paths that temporarily traverse outside the current root,
// i.e. ../../../scope/target/current-root. The localized file will be surrounded by
// different directories than its source, and so an uncleaned path may no longer be valid.
locPath = cleanFilePath(lc.fSys, lc.root, path)
locPath = cleanedRelativePath(lc.fSys, lc.root, path)
}
absPath := filepath.Join(lc.dst, locPath)
if err := lc.fSys.MkdirAll(filepath.Dir(absPath)); err != nil {

View File

@@ -144,7 +144,7 @@ func reportFSysDiff(t *testing.T, fSysExpected filesys.FileSystem, fSysActual fi
actualContent, readErr := fSysActual.ReadFile(path)
require.NoError(t, readErr)
expectedContent, findErr := fSysExpected.ReadFile(path)
assert.NoErrorf(t, findErr, "unexpected file %q", path)
require.NoErrorf(t, findErr, "unexpected file %q", path)
if findErr == nil {
assert.Equal(t, string(expectedContent), string(actualContent))
}
@@ -296,8 +296,10 @@ func TestLocalizeFileCleaned(t *testing.T) {
kind: Kustomization
patches:
- path: ../gamma/../../../alpha/beta/./gamma/patch.yaml
- path: /alpha/beta/../beta/./gamma/patch2.yaml
`,
"patch.yaml": podConfiguration,
"patch.yaml": podConfiguration,
"patch2.yaml": podConfiguration,
}
expected, actual := makeFileSystems(t, "/alpha/beta/gamma", kustAndPatch)
@@ -307,8 +309,10 @@ patches:
kind: Kustomization
patches:
- path: patch.yaml
- path: patch2.yaml
`,
"patch.yaml": podConfiguration,
"patch.yaml": podConfiguration,
"patch2.yaml": podConfiguration,
})
checkFSys(t, expected, actual)
}
@@ -1194,19 +1198,40 @@ func TestLocalizeResources(t *testing.T) {
kind: Kustomization
resources:
- pod.yaml
- /a/b/pod2.yaml
- ../../alpha
`,
"pod.yaml": podConfiguration,
"pod.yaml": podConfiguration,
"pod2.yaml": podConfiguration,
"../../alpha/kustomization.yaml": `apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: my-
`,
}
expected, actual := makeFileSystems(t, "/a/b", kustAndResources)
checkRun(t, actual, "/a/b", "/", "/localized-b")
addFiles(t, expected, "/localized-b/a/b", kustAndResources)
checkFSys(t, expected, actual)
// Absolute path of `/a/b/pod2.yaml` is expected to be converted to a path
// relative to the kustomization root.
expectedKustAndResources := map[string]string{
"kustomization.yaml": `apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- pod.yaml
- pod2.yaml
- ../../alpha
`,
"pod.yaml": podConfiguration,
"pod2.yaml": podConfiguration,
"../../alpha/kustomization.yaml": `apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namePrefix: my-
`,
}
expectedFs, actualFs := makeFileSystems(t, "/a/b", kustAndResources)
checkRun(t, actualFs, "/a/b", "/", "/localized-b")
addFiles(t, expectedFs, "/localized-b/a/b", expectedKustAndResources)
checkFSys(t, expectedFs, actualFs)
}
func TestLocalizePathError(t *testing.T) {

View File

@@ -8,7 +8,7 @@ import (
"sigs.k8s.io/kustomize/api/ifc"
"sigs.k8s.io/kustomize/api/internal/git"
"sigs.k8s.io/kustomize/api/loader"
"sigs.k8s.io/kustomize/api/internal/loader"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/filesys"
)
@@ -89,11 +89,8 @@ func (ll *Loader) Load(path string) ([]byte, error) {
if err != nil {
return nil, errors.WrapPrefixf(err, "invalid file reference")
}
if filepath.IsAbs(path) {
return nil, errors.Errorf("absolute paths not yet supported in alpha: file path %q is absolute", path)
}
if !loader.IsRemoteFile(path) && ll.local {
cleanPath := cleanFilePath(ll.fSys, filesys.ConfirmedDir(ll.Root()), path)
cleanPath := cleanedRelativePath(ll.fSys, filesys.ConfirmedDir(ll.Root()), path)
cleanAbs := filepath.Join(ll.Root(), cleanPath)
dir := filesys.ConfirmedDir(filepath.Dir(cleanAbs))
// target cannot reference newDir, as this load would've failed prior to localize;

View File

@@ -276,11 +276,11 @@ func TestLoadFails(t *testing.T) {
checkNewLoader(req, ldr, &args, "/a", "/a", "/a/newDir", fSys)
cases := map[string]string{
"absolute path": "/a/pod.yaml",
"directory": "b",
"non-existent file": "kubectl.yaml",
"file outside root": "../alpha/beta/gamma/delta/deployment.yaml",
"inside dst": "newDir/pod.yaml",
"directory": "b",
"non-existent file": "kubectl.yaml",
"file outside root": "../alpha/beta/gamma/delta/deployment.yaml",
"inside dst": "newDir/pod.yaml",
"winding inside dst": "/a/test/../newDir/pod.yaml",
}
for name, file := range cases {
file := file
@@ -291,8 +291,6 @@ func TestLoadFails(t *testing.T) {
ldr, _, err := NewLoader("./a/../a", "/a/../a", "/a/newDir", fSys)
req.NoError(err)
req.NoError(fSys.WriteFile("/a/newDir/pod.yaml", []byte(podConfiguration)))
_, err = ldr.Load(file)
req.Error(err)
})

View File

@@ -112,9 +112,13 @@ func hasRef(repoURL string) bool {
return repoSpec.Ref != ""
}
// cleanFilePath returns file cleaned, where file is a relative path to root on fSys
func cleanFilePath(fSys filesys.FileSystem, root filesys.ConfirmedDir, file string) string {
abs := root.Join(file)
// cleanedRelativePath returns a cleaned relative path of file to root on fSys
func cleanedRelativePath(fSys filesys.FileSystem, root filesys.ConfirmedDir, file string) string {
abs := file
if !filepath.IsAbs(file) {
abs = root.Join(file)
}
dir, f, err := fSys.CleanedAbs(abs)
if err != nil {
log.Fatalf("cannot clean validated file path %q: %s", abs, err)

View File

@@ -301,3 +301,26 @@ func TestLocRootPath_SymlinkPath(t *testing.T) {
require.NoError(t, err)
require.Equal(t, expected, actual)
}
func TestCleanedRelativePath(t *testing.T) {
fSys := filesys.MakeFsInMemory()
require.NoError(t, fSys.MkdirAll("/root/test"))
require.NoError(t, fSys.WriteFile("/root/test/file.yaml", []byte("")))
require.NoError(t, fSys.WriteFile("/root/filetwo.yaml", []byte("")))
// Absolute path is cleaned to relative path
cleanedPath := cleanedRelativePath(fSys, "/root/", "/root/test/file.yaml")
require.Equal(t, "test/file.yaml", cleanedPath)
// Winding absolute path is cleaned to relative path
cleanedPath = cleanedRelativePath(fSys, "/root/", "/root/test/../filetwo.yaml")
require.Equal(t, "filetwo.yaml", cleanedPath)
// Already clean relative path stays the same
cleanedPath = cleanedRelativePath(fSys, "/root/", "test/file.yaml")
require.Equal(t, "test/file.yaml", cleanedPath)
// Winding relative path is cleaned
cleanedPath = cleanedRelativePath(fSys, "/root/", "test/../filetwo.yaml")
require.Equal(t, "filetwo.yaml", cleanedPath)
}

View File

@@ -33,7 +33,7 @@ func loadDefaultConfig(
// makeTransformerConfigFromBytes returns a TransformerConfig object from bytes
func makeTransformerConfigFromBytes(data []byte) (*TransformerConfig, error) {
var t TransformerConfig
err := yaml.Unmarshal(data, &t)
err := yaml.UnmarshalStrict(data, &t)
if err != nil {
return nil, err
}

View File

@@ -5,9 +5,10 @@ package builtinconfig
import (
"reflect"
"strings"
"testing"
"sigs.k8s.io/kustomize/api/loader"
"sigs.k8s.io/kustomize/api/internal/loader"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/filesys"
"sigs.k8s.io/kustomize/kyaml/resid"
@@ -44,3 +45,28 @@ namePrefix:
t.Fatalf("expected %v\n but go6t %v\n", expected, tCfg)
}
}
func TestLoadDefaultConfigsFromFilesWithMissingFields(t *testing.T) {
fSys := filesys.MakeFsInMemory()
filePathContainsTypo := "config_contains_typo.yaml"
if err := fSys.WriteFile(filePathContainsTypo, []byte(`
namoPrefix:
- path: nameprefix/path
kind: SomeKind
`)); err != nil {
t.Fatal(err)
}
ldr, err := loader.NewLoader(
loader.RestrictionRootOnly, filesys.Separator, fSys)
if err != nil {
t.Fatal(err)
}
errMsg := "error unmarshaling JSON: while decoding JSON: json: unknown field"
_, err = loadDefaultConfig(ldr, []string{filePathContainsTypo})
if err == nil {
t.Fatalf("expected to fail unmarshal yaml, but got nil %s", filePathContainsTypo)
}
if !strings.Contains(err.Error(), errMsg) {
t.Fatalf("expected error %s, but got %s", errMsg, err)
}
}

View File

@@ -47,6 +47,8 @@ type NameBackReferences struct {
// TODO: rename json 'fieldSpecs' to 'referrers' for clarity.
// This will, however, break anyone using a custom config.
Referrers types.FsSlice `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
// Note: If any new pointer based members are added, DeepCopy needs to be updated
}
func (n NameBackReferences) String() string {
@@ -66,6 +68,17 @@ func (s nbrSlice) Less(i, j int) bool {
return s[i].Gvk.IsLessThan(s[j].Gvk)
}
// DeepCopy returns a new copy of nbrSlice
func (s nbrSlice) DeepCopy() nbrSlice {
ret := make(nbrSlice, len(s))
copy(ret, s)
for i, slice := range ret {
ret[i].Referrers = slice.Referrers.DeepCopy()
}
return ret
}
func (s nbrSlice) mergeAll(o nbrSlice) (result nbrSlice, err error) {
result = s
for _, r := range o {

View File

@@ -95,3 +95,29 @@ func TestMergeAll(t *testing.T) {
t.Fatalf("expected\n %v\n but got\n %v\n", expected, actual)
}
}
func TestNbrSlice_DeepCopy(t *testing.T) {
original := make(nbrSlice, 2, 4)
original[0] = NameBackReferences{Gvk: resid.FromKind("A"), Referrers: types.FsSlice{{Path: "a"}}}
original[1] = NameBackReferences{Gvk: resid.FromKind("B"), Referrers: types.FsSlice{{Path: "b"}}}
copied := original.DeepCopy()
original, _ = original.mergeOne(NameBackReferences{Gvk: resid.FromKind("C"), Referrers: types.FsSlice{{Path: "c"}}})
// perform mutations which should not affect original
copied.Swap(0, 1)
copied[0].Referrers[0].Path = "very b" // ensure Referrers are not shared
_, _ = copied.mergeOne(NameBackReferences{Gvk: resid.FromKind("D"), Referrers: types.FsSlice{{Path: "d"}}})
// if DeepCopy does not work, original would be {very b,a,d} instead of {a,b,c}
expected := nbrSlice{
{Gvk: resid.FromKind("A"), Referrers: types.FsSlice{{Path: "a"}}},
{Gvk: resid.FromKind("B"), Referrers: types.FsSlice{{Path: "b"}}},
{Gvk: resid.FromKind("C"), Referrers: types.FsSlice{{Path: "c"}}},
}
if !reflect.DeepEqual(original, expected) {
t.Fatalf("original affected by mutations to copied object:\ngot\t%+v,\nexpected: %+v", original, expected)
}
}

View File

@@ -6,19 +6,22 @@ package builtinconfig
import (
"log"
"sort"
"sync"
"sigs.k8s.io/kustomize/api/ifc"
"sigs.k8s.io/kustomize/api/konfig/builtinpluginconsts"
"sigs.k8s.io/kustomize/api/internal/konfig/builtinpluginconsts"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/errors"
)
// TransformerConfig holds the data needed to perform transformations.
type TransformerConfig struct {
// if any fields are added, update the DeepCopy implementation
NamePrefix types.FsSlice `json:"namePrefix,omitempty" yaml:"namePrefix,omitempty"`
NameSuffix types.FsSlice `json:"nameSuffix,omitempty" yaml:"nameSuffix,omitempty"`
NameSpace types.FsSlice `json:"namespace,omitempty" yaml:"namespace,omitempty"`
CommonLabels types.FsSlice `json:"commonLabels,omitempty" yaml:"commonLabels,omitempty"`
Labels types.FsSlice `json:"labels,omitempty" yaml:"labels,omitempty"`
TemplateLabels types.FsSlice `json:"templateLabels,omitempty" yaml:"templateLabels,omitempty"`
CommonAnnotations types.FsSlice `json:"commonAnnotations,omitempty" yaml:"commonAnnotations,omitempty"`
NameReference nbrSlice `json:"nameReference,omitempty" yaml:"nameReference,omitempty"`
@@ -32,14 +35,44 @@ func MakeEmptyConfig() *TransformerConfig {
return &TransformerConfig{}
}
// DeepCopy returns a new copy of TransformerConfig
func (t *TransformerConfig) DeepCopy() *TransformerConfig {
return &TransformerConfig{
NamePrefix: t.NamePrefix.DeepCopy(),
NameSuffix: t.NameSuffix.DeepCopy(),
NameSpace: t.NameSpace.DeepCopy(),
CommonLabels: t.CommonLabels.DeepCopy(),
Labels: t.Labels.DeepCopy(),
TemplateLabels: t.TemplateLabels.DeepCopy(),
CommonAnnotations: t.CommonAnnotations.DeepCopy(),
NameReference: t.NameReference.DeepCopy(),
VarReference: t.VarReference.DeepCopy(),
Images: t.Images.DeepCopy(),
Replicas: t.Replicas.DeepCopy(),
}
}
// the default transformer config is initialized by MakeDefaultConfig,
// and must only be accessed via that function.
var (
initDefaultConfig sync.Once //nolint:gochecknoglobals
defaultConfig *TransformerConfig //nolint:gochecknoglobals
)
// MakeDefaultConfig returns a default TransformerConfig.
func MakeDefaultConfig() *TransformerConfig {
c, err := makeTransformerConfigFromBytes(
builtinpluginconsts.GetDefaultFieldSpecs())
if err != nil {
log.Fatalf("Unable to make default transformconfig: %v", err)
}
return c
// parsing is expensive when having a large tree with many kustomization modules, so only do it once
initDefaultConfig.Do(func() {
var err error
defaultConfig, err = makeTransformerConfigFromBytes(
builtinpluginconsts.GetDefaultFieldSpecs())
if err != nil {
log.Fatalf("Unable to make default transformconfig: %v", err)
}
})
// return a copy to avoid any mutations to protect the reference copy
return defaultConfig.DeepCopy()
}
// MakeTransformerConfig returns a merger of custom config,
@@ -63,6 +96,7 @@ func (t *TransformerConfig) sortFields() {
sort.Sort(t.NameSuffix)
sort.Sort(t.NameSpace)
sort.Sort(t.CommonLabels)
sort.Sort(t.Labels)
sort.Sort(t.TemplateLabels)
sort.Sort(t.CommonAnnotations)
sort.Sort(t.NameReference)
@@ -83,12 +117,18 @@ func (t *TransformerConfig) AddSuffixFieldSpec(fs types.FieldSpec) (err error) {
return err
}
// AddLabelFieldSpec adds a FieldSpec to CommonLabels
func (t *TransformerConfig) AddLabelFieldSpec(fs types.FieldSpec) (err error) {
// AddCommonLabelsFieldSpec adds a FieldSpec to CommonLabels
func (t *TransformerConfig) AddCommonLabelsFieldSpec(fs types.FieldSpec) (err error) {
t.CommonLabels, err = t.CommonLabels.MergeOne(fs)
return err
}
// AddLabelsFieldSpec adds a FieldSpec to Labels
func (t *TransformerConfig) AddLabelsFieldSpec(fs types.FieldSpec) (err error) {
t.Labels, err = t.Labels.MergeOne(fs)
return err //nolint:wrapcheck
}
// AddAnnotationFieldSpec adds a FieldSpec to CommonAnnotations
func (t *TransformerConfig) AddAnnotationFieldSpec(fs types.FieldSpec) (err error) {
t.CommonAnnotations, err = t.CommonAnnotations.MergeOne(fs)
@@ -131,6 +171,10 @@ func (t *TransformerConfig) Merge(input *TransformerConfig) (
if err != nil {
return nil, errors.WrapPrefixf(err, "failed to merge CommonLabels fieldSpec")
}
merged.Labels, err = t.Labels.MergeAll(input.Labels)
if err != nil {
return nil, errors.WrapPrefixf(err, "failed to merge Labels fieldSpec")
}
merged.TemplateLabels, err = t.TemplateLabels.MergeAll(input.TemplateLabels)
if err != nil {
return nil, errors.WrapPrefixf(err, "failed to merge TemplateLabels fieldSpec")

View File

@@ -4,9 +4,10 @@
package builtinconfig_test
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
. "sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/resid"
@@ -35,13 +36,8 @@ func TestAddNamereferenceFieldSpec(t *testing.T) {
},
}
err := cfg.AddNamereferenceFieldSpec(nbrs)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
if len(cfg.NameReference) != 1 {
t.Fatal("failed to add namereference FieldSpec")
}
require.NoError(t, cfg.AddNamereferenceFieldSpec(nbrs))
require.Len(t, cfg.NameReference, 1, "failed to add namereference FieldSpec")
}
func TestAddFieldSpecs(t *testing.T) {
@@ -53,34 +49,14 @@ func TestAddFieldSpecs(t *testing.T) {
CreateIfNotPresent: true,
}
err := cfg.AddPrefixFieldSpec(fieldSpec)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
if len(cfg.NamePrefix) != 1 {
t.Fatalf("failed to add nameprefix FieldSpec")
}
err = cfg.AddSuffixFieldSpec(fieldSpec)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
if len(cfg.NameSuffix) != 1 {
t.Fatalf("failed to add namesuffix FieldSpec")
}
err = cfg.AddLabelFieldSpec(fieldSpec)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
if len(cfg.CommonLabels) != 1 {
t.Fatalf("failed to add nameprefix FieldSpec")
}
err = cfg.AddAnnotationFieldSpec(fieldSpec)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
if len(cfg.CommonAnnotations) != 1 {
t.Fatalf("failed to add nameprefix FieldSpec")
}
require.NoError(t, cfg.AddPrefixFieldSpec(fieldSpec))
require.Len(t, cfg.NamePrefix, 1, "failed to add nameprefix FieldSpec")
require.NoError(t, cfg.AddSuffixFieldSpec(fieldSpec))
require.Len(t, cfg.NameSuffix, 1, "failed to add namesuffix FieldSpec")
require.NoError(t, cfg.AddCommonLabelsFieldSpec(fieldSpec))
require.Len(t, cfg.CommonLabels, 1, "failed to add labels FieldSpec")
require.NoError(t, cfg.AddAnnotationFieldSpec(fieldSpec))
require.Len(t, cfg.CommonAnnotations, 1, "failed to add nameprefix FieldSpec")
}
func TestMerge(t *testing.T) {
@@ -127,49 +103,58 @@ func TestMerge(t *testing.T) {
},
}
cfga := &TransformerConfig{}
cfga.AddNamereferenceFieldSpec(nameReference[0])
cfga.AddPrefixFieldSpec(fieldSpecs[0])
cfga.AddSuffixFieldSpec(fieldSpecs[0])
require.NoError(t, cfga.AddNamereferenceFieldSpec(nameReference[0]))
require.NoError(t, cfga.AddPrefixFieldSpec(fieldSpecs[0]))
require.NoError(t, cfga.AddSuffixFieldSpec(fieldSpecs[0]))
require.NoError(t, cfga.AddCommonLabelsFieldSpec(fieldSpecs[0]))
require.NoError(t, cfga.AddLabelsFieldSpec(fieldSpecs[0]))
cfgb := &TransformerConfig{}
cfgb.AddNamereferenceFieldSpec(nameReference[1])
cfgb.AddPrefixFieldSpec(fieldSpecs[1])
cfga.AddSuffixFieldSpec(fieldSpecs[1])
require.NoError(t, cfgb.AddNamereferenceFieldSpec(nameReference[1]))
require.NoError(t, cfgb.AddPrefixFieldSpec(fieldSpecs[1]))
require.NoError(t, cfgb.AddSuffixFieldSpec(fieldSpecs[1]))
require.NoError(t, cfgb.AddCommonLabelsFieldSpec(fieldSpecs[1]))
require.NoError(t, cfgb.AddLabelsFieldSpec(fieldSpecs[1]))
actual, err := cfga.Merge(cfgb)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
if len(actual.NamePrefix) != 2 {
t.Fatal("merge failed for namePrefix FieldSpec")
}
if len(actual.NameSuffix) != 2 {
t.Fatal("merge failed for nameSuffix FieldSpec")
}
if len(actual.NameReference) != 1 {
t.Fatal("merge failed for namereference FieldSpec")
}
require.NoError(t, err)
require.Len(t, actual.NamePrefix, 2, "merge failed for namePrefix FieldSpec")
require.Len(t, actual.NameSuffix, 2, "merge failed for nameSuffix FieldSpec")
require.Len(t, actual.NameReference, 1, "merge failed for nameReference FieldSpec")
require.Len(t, actual.Labels, 2, "merge failed for labels FieldSpec")
require.Len(t, actual.CommonLabels, 2, "merge failed for commonLabels FieldSpec")
expected := &TransformerConfig{}
expected.AddNamereferenceFieldSpec(nameReference[0])
expected.AddNamereferenceFieldSpec(nameReference[1])
expected.AddPrefixFieldSpec(fieldSpecs[0])
expected.AddPrefixFieldSpec(fieldSpecs[1])
expected.AddSuffixFieldSpec(fieldSpecs[0])
expected.AddSuffixFieldSpec(fieldSpecs[1])
if !reflect.DeepEqual(actual, expected) {
t.Fatalf("expected: %v\n but got: %v\n", expected, actual)
}
require.NoError(t, expected.AddNamereferenceFieldSpec(nameReference[0]))
require.NoError(t, expected.AddNamereferenceFieldSpec(nameReference[1]))
require.NoError(t, expected.AddPrefixFieldSpec(fieldSpecs[0]))
require.NoError(t, expected.AddPrefixFieldSpec(fieldSpecs[1]))
require.NoError(t, expected.AddSuffixFieldSpec(fieldSpecs[0]))
require.NoError(t, expected.AddSuffixFieldSpec(fieldSpecs[1]))
require.NoError(t, expected.AddCommonLabelsFieldSpec(fieldSpecs[0]))
require.NoError(t, expected.AddCommonLabelsFieldSpec(fieldSpecs[1]))
require.NoError(t, expected.AddLabelsFieldSpec(fieldSpecs[0]))
require.NoError(t, expected.AddLabelsFieldSpec(fieldSpecs[1]))
require.Equal(t, expected, actual)
actual, err = cfga.Merge(nil)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
if !reflect.DeepEqual(actual, cfga) {
t.Fatalf("expected: %v\n but got: %v\n", cfga, actual)
require.NoError(t, err)
require.Equal(t, cfga, actual)
}
func TestMakeDefaultConfig_mutation(t *testing.T) {
a := MakeDefaultConfig()
// mutate
a.NameReference[0].Kind = "mutated"
a.NameReference = a.NameReference[:1]
clean := MakeDefaultConfig()
assert.NotEqualf(t, "mutated", clean.NameReference[0].Kind, "MakeDefaultConfig() did not return a clean copy: %+v", clean.NameReference)
}
func BenchmarkMakeDefaultConfig(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = MakeDefaultConfig()
}
}

View File

@@ -6,6 +6,7 @@ package execplugin
import (
"bytes"
"fmt"
"log"
"os"
"os/exec"
"runtime"
@@ -21,6 +22,7 @@ import (
const (
tmpConfigFilePrefix = "kust-plugin-config-"
maxArgStringLength = 131071
)
// ExecPlugin record the name and args of an executable
@@ -169,23 +171,35 @@ func (p *ExecPlugin) invokePlugin(input []byte) ([]byte, error) {
p.path, append([]string{f.Name()}, p.args...)...)
cmd.Env = p.getEnv()
cmd.Stdin = bytes.NewReader(input)
cmd.Stderr = os.Stderr
var stdErr bytes.Buffer
cmd.Stderr = &stdErr
if _, err := os.Stat(p.h.Loader().Root()); err == nil {
cmd.Dir = p.h.Loader().Root()
}
result, err := cmd.Output()
if err != nil {
return nil, errors.WrapPrefixf(
err, "failure in plugin configured via %s; %v",
f.Name(), err.Error())
fmt.Errorf("failure in plugin configured via %s; %w",
f.Name(), err), stdErr.String())
}
return result, os.Remove(f.Name())
}
func (p *ExecPlugin) getEnv() []string {
env := os.Environ()
env = append(env,
"KUSTOMIZE_PLUGIN_CONFIG_STRING="+string(p.cfg),
"KUSTOMIZE_PLUGIN_CONFIG_ROOT="+p.h.Loader().Root())
pluginConfigString := "KUSTOMIZE_PLUGIN_CONFIG_STRING=" + string(p.cfg)
if len(pluginConfigString) <= maxArgStringLength {
env = append(env, pluginConfigString)
} else {
log.Printf("KUSTOMIZE_PLUGIN_CONFIG_STRING exceeds hard limit of %d characters, the environment variable "+
"will be omitted", maxArgStringLength)
}
pluginConfigRoot := "KUSTOMIZE_PLUGIN_CONFIG_ROOT=" + p.h.Loader().Root()
if len(pluginConfigRoot) <= maxArgStringLength {
env = append(env, pluginConfigRoot)
} else {
log.Printf("KUSTOMIZE_PLUGIN_CONFIG_ROOT exceeds hard limit of %d characters, the environment variable "+
"will be omitted", maxArgStringLength)
}
return env
}

View File

@@ -10,16 +10,22 @@ import (
"testing"
"github.com/stretchr/testify/require"
fLdr "sigs.k8s.io/kustomize/api/internal/loader"
. "sigs.k8s.io/kustomize/api/internal/plugins/execplugin"
pLdr "sigs.k8s.io/kustomize/api/internal/plugins/loader"
"sigs.k8s.io/kustomize/api/internal/plugins/utils"
fLdr "sigs.k8s.io/kustomize/api/loader"
"sigs.k8s.io/kustomize/api/provider"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/filesys"
)
const (
expectedLargeConfigMap = `{"apiVersion":"v1","data":{"password":"password","username":"user"},"kind":"ConfigMap",` +
`"metadata":{"annotations":{"internal.config.kubernetes.io/generatorBehavior":"unspecified",` +
`"internal.config.kubernetes.io/needsHashSuffix":"enabled"},"name":"example-configmap-test"}}`
)
func TestExecPluginConfig(t *testing.T) {
fSys := filesys.MakeFsInMemory()
err := fSys.WriteFile("sed-input.txt", []byte(`
@@ -35,7 +41,7 @@ s/$BAR/bar baz/g
}
pvd := provider.NewDefaultDepProvider()
rf := resmap.NewFactory(pvd.GetResourceFactory())
pluginConfig := rf.RF().FromMap(
pluginConfig, err := rf.RF().FromMap(
map[string]interface{}{
"apiVersion": "someteam.example.com/v1",
"kind": "SedTransformer",
@@ -45,6 +51,9 @@ s/$BAR/bar baz/g
"argsOneLiner": "one two 'foo bar'",
"argsFromFile": "sed-input.txt",
})
if err != nil {
t.Fatalf("failed to writes the data to a file: %v", err)
}
pluginConfig.RemoveBuildAnnotations()
pc := types.DisabledPluginConfig()
@@ -125,3 +134,104 @@ func TestExecPlugin_ErrIfNotExecutable(t *testing.T) {
t.Fatalf("unexpected err: %v", err)
}
}
// TestExecPluginLarge loads PluginConfigs of various (large) sizes. It tests if the env variable is kept below the
// maximum of 131072 bytes.
func TestExecPluginLarge(t *testing.T) {
// Skip this test on windows.
if runtime.GOOS == "windows" {
t.Skipf("always returns nil on Windows")
}
// Add executable plugin.
srcRoot, err := utils.DeterminePluginSrcRoot(filesys.MakeFsOnDisk())
if err != nil {
t.Error(err)
}
executablePlugin := filepath.Join(
srcRoot, "someteam.example.com", "v1", "bashedconfigmap", "BashedConfigMap")
p := NewExecPlugin(executablePlugin)
err = p.ErrIfNotExecutable()
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
// Create a fake filesystem.
fSys := filesys.MakeFsInMemory()
// Load plugin config.
ldr, err := fLdr.NewLoader(
fLdr.RestrictionRootOnly, filesys.Separator, fSys)
if err != nil {
t.Fatal(err)
}
pvd := provider.NewDefaultDepProvider()
rf := resmap.NewFactory(pvd.GetResourceFactory())
pc := types.DisabledPluginConfig()
// Test for various lengths. 131071 is the max length that we can have for any given env var in Bytes.
tcs := []struct {
length int
char rune
}{
{1000, 'a'},
{131071, 'a'},
{131072, 'a'},
{200000, 'a'},
{131071, '安'},
{131074, '安'},
}
for _, tc := range tcs {
t.Logf("Testing with an env var length of %d and character %c", tc.length, tc.char)
pluginConfig, err := rf.RF().FromBytes(buildLargePluginConfig(tc.length, tc.char))
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
yaml, err := pluginConfig.AsYAML()
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
err = p.Config(resmap.NewPluginHelpers(ldr, pvd.GetFieldValidator(), rf, pc), yaml)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
resMap, err := p.Generate()
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
rNodeSlices := resMap.ToRNodeSlice()
for _, rNodeSlice := range rNodeSlices {
json, err := rNodeSlice.MarshalJSON()
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
if string(json) != expectedLargeConfigMap {
t.Fatalf("expected generated JSON to match %q, but got %q instead",
expectedLargeConfigMap, string(json))
}
}
}
}
// buildLargePluginConfig builds a plugin configuration of length: length - len("KUSTOMIZE_PLUGIN_CONFIG_STRING=")
// This allows us to create an environment variable KUSTOMIZE_PLUGIN_CONFIG_STRING=<plugin content> with the exact
// length that's provided in the length parameter. Used as a helper for TestExecPluginLarge.
func buildLargePluginConfig(length int, char rune) []byte {
length -= len("KUSTOMIZE_PLUGIN_CONFIG_STRING=")
var sb strings.Builder
sb.WriteString("apiVersion: someteam.example.com/v1\n")
sb.WriteString("kind: BashedConfigMap\n")
sb.WriteString("metadata:\n")
sb.WriteString(" name: some-random-name\n")
sb.WriteString("argsOneLiner: \"user password\"\n")
sb.WriteString("customArg: ")
// Now, fill up parameter customArg: until we reach the desired length. Account for the fact that runes can be
// 1 to 4 Bytes each.
upperBound := length - sb.Len()
for i := 0; i < upperBound-len(string(char)); i += len(string(char)) {
sb.WriteRune(char)
}
return []byte(sb.String())
}

View File

@@ -0,0 +1,62 @@
// Copyright 2024 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
//go:build !kustomize_disable_go_plugin_support
package loader
import (
"fmt"
"log"
"plugin"
"reflect"
"sigs.k8s.io/kustomize/api/internal/plugins/utils"
"sigs.k8s.io/kustomize/api/konfig"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/resid"
)
// registry is a means to avoid trying to load the same .so file
// into memory more than once, which results in an error.
// Each test makes its own loader, and tries to load its own plugins,
// but the loaded .so files are in shared memory, so one will get
// "this plugin already loaded" errors if the registry is maintained
// as a Loader instance variable. So make it a package variable.
var registry = make(map[string]resmap.Configurable) //nolint:gochecknoglobals
func copyPlugin(c resmap.Configurable) resmap.Configurable {
indirect := reflect.Indirect(reflect.ValueOf(c))
newIndirect := reflect.New(indirect.Type())
newIndirect.Elem().Set(reflect.ValueOf(indirect.Interface()))
newNamed := newIndirect.Interface()
return newNamed.(resmap.Configurable) //nolint:forcetypeassert
}
func (l *Loader) loadGoPlugin(id resid.ResId, absPath string) (resmap.Configurable, error) {
regId := relativePluginPath(id)
if c, ok := registry[regId]; ok {
return copyPlugin(c), nil
}
if !utils.FileExists(absPath) {
return nil, fmt.Errorf(
"expected file with Go object code at: %s", absPath)
}
log.Printf("Attempting plugin load from %q", absPath)
p, err := plugin.Open(absPath)
if err != nil {
return nil, errors.WrapPrefixf(err, "plugin %s fails to load", absPath)
}
symbol, err := p.Lookup(konfig.PluginSymbol)
if err != nil {
return nil, errors.WrapPrefixf(
err, "plugin %s doesn't have symbol %s",
regId, konfig.PluginSymbol)
}
c, ok := symbol.(resmap.Configurable)
if !ok {
return nil, fmt.Errorf("plugin %q not configurable", regId)
}
registry[regId] = c
return copyPlugin(c), nil
}

View File

@@ -0,0 +1,25 @@
// Copyright 2024 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// The build tag "kustomize_disable_go_plugin_support" is used to deactivate the
// kustomize API's dependency on the "plugins" package. This is beneficial for
// applications that need to embed it but do not have requirements for dynamic
// Go plugins.
// Including plugins as a dependency can lead to an increase in binary size due
// to the population of ELF's sections such as .dynsym and .dynstr.
// By utilizing this flag, applications have the flexibility to exclude the
// import if they do not require support for dynamic Go plugins.
//go:build kustomize_disable_go_plugin_support
package loader
import (
"fmt"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/kyaml/resid"
)
func (l *Loader) loadGoPlugin(_ resid.ResId, _ string) (resmap.Configurable, error) {
return nil, fmt.Errorf("plugin load is disabled")
}

View File

@@ -5,18 +5,14 @@ package loader
import (
"fmt"
"log"
"os"
"path/filepath"
"plugin"
"reflect"
"strings"
"sigs.k8s.io/kustomize/api/ifc"
"sigs.k8s.io/kustomize/api/internal/plugins/builtinhelpers"
"sigs.k8s.io/kustomize/api/internal/plugins/execplugin"
"sigs.k8s.io/kustomize/api/internal/plugins/fnplugin"
"sigs.k8s.io/kustomize/api/internal/plugins/utils"
"sigs.k8s.io/kustomize/api/konfig"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/resource"
@@ -287,46 +283,3 @@ func (l *Loader) loadExecOrGoPlugin(resId resid.ResId) (resmap.Configurable, err
return c, nil
}
// registry is a means to avoid trying to load the same .so file
// into memory more than once, which results in an error.
// Each test makes its own loader, and tries to load its own plugins,
// but the loaded .so files are in shared memory, so one will get
// "this plugin already loaded" errors if the registry is maintained
// as a Loader instance variable. So make it a package variable.
var registry = make(map[string]resmap.Configurable)
func (l *Loader) loadGoPlugin(id resid.ResId, absPath string) (resmap.Configurable, error) {
regId := relativePluginPath(id)
if c, ok := registry[regId]; ok {
return copyPlugin(c), nil
}
if !utils.FileExists(absPath) {
return nil, fmt.Errorf(
"expected file with Go object code at: %s", absPath)
}
log.Printf("Attempting plugin load from '%s'", absPath)
p, err := plugin.Open(absPath)
if err != nil {
return nil, errors.WrapPrefixf(err, "plugin %s fails to load", absPath)
}
symbol, err := p.Lookup(konfig.PluginSymbol)
if err != nil {
return nil, errors.WrapPrefixf(
err, "plugin %s doesn't have symbol %s",
regId, konfig.PluginSymbol)
}
c, ok := symbol.(resmap.Configurable)
if !ok {
return nil, fmt.Errorf("plugin '%s' not configurable", regId)
}
registry[regId] = c
return copyPlugin(c), nil
}
func copyPlugin(c resmap.Configurable) resmap.Configurable {
indirect := reflect.Indirect(reflect.ValueOf(c))
newIndirect := reflect.New(indirect.Type())
newIndirect.Elem().Set(reflect.ValueOf(indirect.Interface()))
newNamed := newIndirect.Interface()
return newNamed.(resmap.Configurable)
}

View File

@@ -7,8 +7,8 @@ import (
"testing"
"github.com/stretchr/testify/require"
"sigs.k8s.io/kustomize/api/internal/loader"
. "sigs.k8s.io/kustomize/api/internal/plugins/loader"
"sigs.k8s.io/kustomize/api/loader"
"sigs.k8s.io/kustomize/api/provider"
"sigs.k8s.io/kustomize/api/resmap"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"

View File

@@ -9,7 +9,6 @@ import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"sigs.k8s.io/kustomize/api/konfig"
"sigs.k8s.io/kustomize/api/provider"
@@ -33,11 +32,14 @@ func TestDeterminePluginSrcRoot(t *testing.T) {
}
func makeConfigMap(rf *resource.Factory, name, behavior string, hashValue *string) *resource.Resource {
r := rf.FromMap(map[string]interface{}{
r, err := rf.FromMap(map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": map[string]interface{}{"name": name},
})
if err != nil {
panic(err)
}
annotations := map[string]string{}
if behavior != "" {
annotations[BehaviorAnnotation] = behavior
@@ -53,7 +55,7 @@ func makeConfigMap(rf *resource.Factory, name, behavior string, hashValue *strin
return r
}
func makeConfigMapOptions(rf *resource.Factory, name, behavior string, disableHash bool) *resource.Resource {
func makeConfigMapOptions(rf *resource.Factory, name, behavior string, disableHash bool) (*resource.Resource, error) {
return rf.FromMapAndOption(map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
@@ -89,12 +91,16 @@ func TestUpdateResourceOptions(t *testing.T) {
name := fmt.Sprintf("test%d", i)
err := in.Append(makeConfigMap(rf, name, c.behavior, c.hashValue))
require.NoError(t, err)
err = expected.Append(makeConfigMapOptions(rf, name, c.behavior, !c.needsHash))
config, err := makeConfigMapOptions(rf, name, c.behavior, !c.needsHash)
if err != nil {
t.Errorf("expected new instance with an options but got error: %v", err)
}
err = expected.Append(config)
require.NoError(t, err)
}
actual, err := UpdateResourceOptions(in)
assert.NoError(t, err)
assert.NoError(t, expected.ErrorIfNotEqualLists(actual))
require.NoError(t, err)
require.NoError(t, expected.ErrorIfNotEqualLists(actual))
}
func TestUpdateResourceOptionsWithInvalidHashAnnotationValues(t *testing.T) {

View File

@@ -13,12 +13,12 @@ import (
"sigs.k8s.io/kustomize/api/internal/accumulator"
"sigs.k8s.io/kustomize/api/internal/builtins"
"sigs.k8s.io/kustomize/api/internal/kusterr"
load "sigs.k8s.io/kustomize/api/internal/loader"
"sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
"sigs.k8s.io/kustomize/api/internal/plugins/builtinhelpers"
"sigs.k8s.io/kustomize/api/internal/plugins/loader"
"sigs.k8s.io/kustomize/api/internal/utils"
"sigs.k8s.io/kustomize/api/konfig"
load "sigs.k8s.io/kustomize/api/loader"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/api/types"
@@ -73,6 +73,11 @@ func (kt *KustTarget) Load() error {
k.FixKustomization()
// check that Kustomization is empty
if err := k.CheckEmpty(); err != nil {
return err
}
errs := k.EnforceFields()
if len(errs) > 0 {
return fmt.Errorf(
@@ -197,10 +202,6 @@ func (kt *KustTarget) accumulateTarget(ra *accumulator.ResAccumulator) (
if err != nil {
return nil, errors.WrapPrefixf(err, "accumulating resources")
}
ra, err = kt.accumulateComponents(ra, kt.kustomization.Components)
if err != nil {
return nil, errors.WrapPrefixf(err, "accumulating components")
}
tConfig, err := builtinconfig.MakeTransformerConfig(
kt.ldr, kt.kustomization.Configurations)
if err != nil {
@@ -225,6 +226,14 @@ func (kt *KustTarget) accumulateTarget(ra *accumulator.ResAccumulator) (
if err != nil {
return nil, err
}
// components are expected to execute after reading resources and adding generators ,before applying transformers and validation.
// https://github.com/kubernetes-sigs/kustomize/pull/5170#discussion_r1212101287
ra, err = kt.accumulateComponents(ra, kt.kustomization.Components)
if err != nil {
return nil, errors.WrapPrefixf(err, "accumulating components")
}
err = kt.runTransformers(ra)
if err != nil {
return nil, err
@@ -416,7 +425,14 @@ func (kt *KustTarget) accumulateResources(
}
ldr, err := kt.ldr.New(path)
if err != nil {
if kusterr.IsMalformedYAMLError(errF) { // Some error occurred while tyring to decode YAML file
// If accumulateFile found malformed YAML and there was a failure
// loading the resource as a base, then the resource is likely a
// file. The loader failure message is unnecessary, and could be
// confusing. Report only the file load error.
//
// However, a loader timeout implies there is a git repo at the
// path. In that case, both errors could be important.
if kusterr.IsMalformedYAMLError(errF) && !utils.IsErrTimeout(err) {
return nil, errF
}
return nil, errors.WrapPrefixf(

View File

@@ -275,13 +275,25 @@ var transformerConfigurators = map[builtinhelpers.BuiltinPluginType]func(
if len(kt.kustomization.Labels) == 0 && len(kt.kustomization.CommonLabels) == 0 {
return
}
type labelStruct struct {
Labels map[string]string
FieldSpecs []types.FieldSpec
}
for _, label := range kt.kustomization.Labels {
var c struct {
Labels map[string]string
FieldSpecs []types.FieldSpec
}
var c labelStruct
c.Labels = label.Pairs
fss := types.FsSlice(label.FieldSpecs)
// merge labels specified in the label section of transformer configs
// these apply to selectors and templates
fss, err := fss.MergeAll(tc.Labels)
if err != nil {
return nil, fmt.Errorf("failed to merge labels: %w", err)
}
// merge the custom fieldSpecs with the default
if label.IncludeSelectors {
fss, err = fss.MergeAll(tc.CommonLabels)
@@ -297,7 +309,7 @@ var transformerConfigurators = map[builtinhelpers.BuiltinPluginType]func(
fss, err = fss.MergeOne(types.FieldSpec{Path: "metadata/labels", CreateIfNotPresent: true})
}
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to merge labels: %w", err)
}
c.FieldSpecs = fss
p := f()
@@ -307,10 +319,9 @@ var transformerConfigurators = map[builtinhelpers.BuiltinPluginType]func(
}
result = append(result, p)
}
var c struct {
Labels map[string]string
FieldSpecs []types.FieldSpec
}
var c labelStruct
c.Labels = kt.kustomization.CommonLabels
c.FieldSpecs = tc.CommonLabels
p := f()

View File

@@ -8,12 +8,14 @@ import (
"fmt"
"reflect"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"sigs.k8s.io/kustomize/api/ifc"
. "sigs.k8s.io/kustomize/api/internal/target"
"sigs.k8s.io/kustomize/api/loader"
"sigs.k8s.io/kustomize/api/internal/utils"
"sigs.k8s.io/kustomize/api/pkg/loader"
"sigs.k8s.io/kustomize/api/provider"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/resource"
@@ -79,6 +81,7 @@ func TestLoad(t *testing.T) {
k: types.Kustomization{
TypeMeta: expectedTypeMeta,
},
errContains: "kustomization.yaml is empty",
},
"nonsenseLatin": {
errContains: "found a tab character that violates indentation",
@@ -188,13 +191,67 @@ metadata:
pvd := provider.NewDefaultDepProvider()
resFactory := pvd.GetResourceFactory()
name0 := "dply1"
resources := []*resource.Resource{
resFactory.FromMapWithName("dply1", map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
r0, err := resFactory.FromMapWithName(name0, map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": map[string]interface{}{
"name": "foo-dply1-bar",
"namespace": "ns1",
"labels": map[string]interface{}{
"app": "nginx",
},
"annotations": map[string]interface{}{
"note": "This is a test annotation",
},
},
"spec": map[string]interface{}{
"replica": "3",
"selector": map[string]interface{}{
"matchLabels": map[string]interface{}{
"app": "nginx",
},
},
"template": map[string]interface{}{
"metadata": map[string]interface{}{
"annotations": map[string]interface{}{
"note": "This is a test annotation",
},
"labels": map[string]interface{}{
"app": "nginx",
},
},
},
},
})
if err != nil {
t.Fatalf("failed to get instance with given name %v: %v", name0, err)
}
name1 := "ns1"
r1, err := resFactory.FromMapWithName(name1, map[string]interface{}{
"apiVersion": "v1",
"kind": "Namespace",
"metadata": map[string]interface{}{
"name": "ns1",
"labels": map[string]interface{}{
"app": "nginx",
},
"annotations": map[string]interface{}{
"note": "This is a test annotation",
},
},
})
if err != nil {
t.Fatalf("failed to get instance with given name %v: %v", name1, err)
}
r2, _ := resFactory.FromMapWithName("literalConfigMap",
map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": map[string]interface{}{
"name": "foo-dply1-bar",
"name": "foo-literalConfigMap-bar-g5f6t456f5",
"namespace": "ns1",
"labels": map[string]interface{}{
"app": "nginx",
@@ -203,30 +260,20 @@ metadata:
"note": "This is a test annotation",
},
},
"spec": map[string]interface{}{
"replica": "3",
"selector": map[string]interface{}{
"matchLabels": map[string]interface{}{
"app": "nginx",
},
},
"template": map[string]interface{}{
"metadata": map[string]interface{}{
"annotations": map[string]interface{}{
"note": "This is a test annotation",
},
"labels": map[string]interface{}{
"app": "nginx",
},
},
},
"data": map[string]interface{}{
"DB_USERNAME": "admin",
"DB_PASSWORD": "somepw",
},
}),
resFactory.FromMapWithName("ns1", map[string]interface{}{
})
name2 := "secret"
r3, err := resFactory.FromMapWithName(name2,
map[string]interface{}{
"apiVersion": "v1",
"kind": "Namespace",
"kind": "Secret",
"metadata": map[string]interface{}{
"name": "ns1",
"name": "foo-secret-bar-82c2g5f8f6",
"namespace": "ns1",
"labels": map[string]interface{}{
"app": "nginx",
},
@@ -234,65 +281,33 @@ metadata:
"note": "This is a test annotation",
},
},
}),
resFactory.FromMapWithName("literalConfigMap",
map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": map[string]interface{}{
"name": "foo-literalConfigMap-bar-g5f6t456f5",
"namespace": "ns1",
"labels": map[string]interface{}{
"app": "nginx",
},
"annotations": map[string]interface{}{
"note": "This is a test annotation",
},
},
"data": map[string]interface{}{
"DB_USERNAME": "admin",
"DB_PASSWORD": "somepw",
},
}),
resFactory.FromMapWithName("secret",
map[string]interface{}{
"apiVersion": "v1",
"kind": "Secret",
"metadata": map[string]interface{}{
"name": "foo-secret-bar-82c2g5f8f6",
"namespace": "ns1",
"labels": map[string]interface{}{
"app": "nginx",
},
"annotations": map[string]interface{}{
"note": "This is a test annotation",
},
},
"type": ifc.SecretTypeOpaque,
"data": map[string]interface{}{
"DB_USERNAME": base64.StdEncoding.EncodeToString([]byte("admin")),
"DB_PASSWORD": base64.StdEncoding.EncodeToString([]byte("somepw")),
},
}),
"type": ifc.SecretTypeOpaque,
"data": map[string]interface{}{
"DB_USERNAME": base64.StdEncoding.EncodeToString([]byte("admin")),
"DB_PASSWORD": base64.StdEncoding.EncodeToString([]byte("somepw")),
},
})
if err != nil {
t.Fatalf("failed to get instance with given name %v: %v", name2, err)
}
resources := []*resource.Resource{r0, r1, r2, r3}
expected := resmap.New()
for _, r := range resources {
if err := expected.Append(r); err != nil {
t.Fatalf("unexpected error %v", err)
}
require.NoError(t, expected.Append(r), "failed to append resource: %v")
}
expected.RemoveBuildAnnotations()
expYaml, err := expected.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
kt := makeKustTargetWithRf(t, th.GetFSys(), "/whatever", pvd)
assert.NoError(t, kt.Load())
require.NoError(t, kt.Load())
actual, err := kt.MakeCustomizedResMap()
assert.NoError(t, err)
require.NoError(t, err)
actual.RemoveBuildAnnotations()
actYaml, err := actual.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, string(expYaml), string(actYaml))
}
@@ -312,19 +327,21 @@ configurations:
th.WriteF("/merge-config/name-prefix-rules.yaml", `
namePrefix:
- path: metadata/name
apiVersion: v1
group: apps
version: v1
kind: Deployment
- path: metadata/name
apiVersion: v1
version: v1
kind: Secret
`)
th.WriteF("/merge-config/name-suffix-rules.yaml", `
nameSuffix:
- path: metadata/name
apiVersion: v1
version: v1
kind: ConfigMap
- path: metadata/name
apiVersion: v1
group: apps
version: v1
kind: Deployment
`)
th.WriteF("/merge-config/deployment.yaml", `
@@ -349,31 +366,43 @@ metadata:
pvd := provider.NewDefaultDepProvider()
resFactory := pvd.GetResourceFactory()
resources := []*resource.Resource{
resFactory.FromMapWithName("deployment1", map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": map[string]interface{}{
"name": "foo-deployment1-bar",
"namespace": "ns1",
},
}), resFactory.FromMapWithName("config", map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": map[string]interface{}{
"name": "config-bar",
"namespace": "ns1",
},
}), resFactory.FromMapWithName("secret", map[string]interface{}{
"apiVersion": "v1",
"kind": "Secret",
"metadata": map[string]interface{}{
"name": "foo-secret",
"namespace": "ns1",
},
}),
name0 := "deployment1"
r0, err0 := resFactory.FromMapWithName(name0, map[string]interface{}{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": map[string]interface{}{
"name": "foo-deployment1-bar",
"namespace": "ns1",
},
})
if err0 != nil {
t.Fatalf("failed to get instance with given name %v: %v", name0, err0)
}
name1 := "config"
r1, err1 := resFactory.FromMapWithName(name1, map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": map[string]interface{}{
"name": "config-bar",
"namespace": "ns1",
},
})
if err1 != nil {
t.Fatalf("failed to get instance with given name %v: %v", name1, err1)
}
name2 := "secret"
r2, err2 := resFactory.FromMapWithName(name2, map[string]interface{}{
"apiVersion": "v1",
"kind": "Secret",
"metadata": map[string]interface{}{
"name": "foo-secret",
"namespace": "ns1",
},
})
if err2 != nil {
t.Fatalf("failed to get instance with given name %v: %v", name2, err2)
}
var resources = []*resource.Resource{r0, r1, r2}
expected := resmap.New()
for _, r := range resources {
err := expected.Append(r)
@@ -422,7 +451,7 @@ func TestDuplicateExternalGeneratorsForbidden(t *testing.T) {
configPath: another_config.json
`)
_, err := makeAndLoadKustTarget(t, th.GetFSys(), "/generator").AccumulateTarget()
assert.Error(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), "may not add resource with an already registered id: ManifestGenerator.v1.generators.example/ManifestGenerator")
}
@@ -451,6 +480,83 @@ func TestDuplicateExternalTransformersForbidden(t *testing.T) {
value: 'fail'
`)
_, err := makeAndLoadKustTarget(t, th.GetFSys(), "/transformer").AccumulateTarget()
assert.Error(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), "may not add resource with an already registered id: ValueAnnotator.v1.transformers.example.co/notImportantHere")
}
func TestErrorMessageForMalformedYAML(t *testing.T) {
// These testcases verify behavior for the scenario described in
// https://github.com/kubernetes-sigs/kustomize/issues/5540 .
testcases := map[string]struct {
loaderNewReturnsError error
shouldShowLoadError bool
}{
"shouldShowLoadError": {
loaderNewReturnsError: utils.NewErrTimeOut(time.Second, "git init"),
shouldShowLoadError: true,
},
"shouldNotShowLoadError": {
loaderNewReturnsError: NewErrMissingKustomization("/should-fail/resources.yaml"),
shouldShowLoadError: false,
},
}
th := kusttest_test.MakeHarness(t)
th.WriteF("/should-fail/kustomization.yaml", `resources:
- resources.yaml
`)
th.WriteF("/should-fail/resources.yaml", `<!DOCTYPE html>
<html class="html-devise-layout ui-light-gray" lang="en">
<head prefix="og: http://ogp.me/ns#">
<meta charset="utf-8">
`)
for name, tc := range testcases {
t.Run(name, func(subT *testing.T) {
ldrWrapper := func(baseLoader ifc.Loader) ifc.Loader {
return loaderNewThrowsError{
baseLoader: baseLoader,
newReturnsError: tc.loaderNewReturnsError,
}
}
_, err := makeAndLoadKustTargetWithLoaderOverride(t, th.GetFSys(), "/should-fail", ldrWrapper).AccumulateTarget()
require.Error(t, err)
errString := err.Error()
assert.Contains(t, errString, "accumulating resources from 'resources.yaml'")
assert.Contains(t, errString, "MalformedYAMLError: yaml: line 3: mapping values are not allowed in this context")
if tc.shouldShowLoadError {
assert.Regexp(t, `hit \w+ timeout running '`, errString)
} else {
assert.NotRegexp(t, `hit \w+ timeout running '`, errString)
}
})
}
}
// loaderNewReturnsError duplicates baseLoader's behavior except
// that New() returns the specified error.
type loaderNewThrowsError struct {
baseLoader ifc.Loader
newReturnsError error
}
func (l loaderNewThrowsError) Repo() string {
return l.baseLoader.Repo()
}
func (l loaderNewThrowsError) Root() string {
return l.baseLoader.Root()
}
func (l loaderNewThrowsError) New(_ string) (ifc.Loader, error) {
return nil, l.newReturnsError
}
func (l loaderNewThrowsError) Load(location string) ([]byte, error) {
return l.baseLoader.Load(location) //nolint:wrapcheck // baseLoader's error is sufficient
}
func (l loaderNewThrowsError) Cleanup() error {
return l.baseLoader.Cleanup() //nolint:wrapcheck // baseLoader's error is sufficient
}

View File

@@ -6,9 +6,10 @@ package target_test
import (
"testing"
"sigs.k8s.io/kustomize/api/ifc"
fLdr "sigs.k8s.io/kustomize/api/internal/loader"
pLdr "sigs.k8s.io/kustomize/api/internal/plugins/loader"
"sigs.k8s.io/kustomize/api/internal/target"
fLdr "sigs.k8s.io/kustomize/api/loader"
"sigs.k8s.io/kustomize/api/provider"
"sigs.k8s.io/kustomize/api/resmap"
valtest_test "sigs.k8s.io/kustomize/api/testutils/valtest"
@@ -21,11 +22,7 @@ func makeAndLoadKustTarget(
fSys filesys.FileSystem,
root string) *target.KustTarget {
t.Helper()
kt := makeKustTargetWithRf(t, fSys, root, provider.NewDefaultDepProvider())
if err := kt.Load(); err != nil {
t.Fatalf("Unexpected load error %v", err)
}
return kt
return makeAndLoadKustTargetWithLoaderOverride(t, fSys, root, nil)
}
func makeKustTargetWithRf(
@@ -34,10 +31,37 @@ func makeKustTargetWithRf(
root string,
pvd *provider.DepProvider) *target.KustTarget {
t.Helper()
ldr, err := fLdr.NewLoader(fLdr.RestrictionRootOnly, root, fSys)
return makeKustTargetWithRfAndLoaderOverride(t, fSys, root, pvd, nil)
}
func makeAndLoadKustTargetWithLoaderOverride(
t *testing.T,
fSys filesys.FileSystem,
root string,
ldrWrapperFn func(ifc.Loader) ifc.Loader) *target.KustTarget {
t.Helper()
kt := makeKustTargetWithRfAndLoaderOverride(t, fSys, root, provider.NewDefaultDepProvider(), ldrWrapperFn)
if err := kt.Load(); err != nil {
t.Fatalf("Unexpected load error %v", err)
}
return kt
}
func makeKustTargetWithRfAndLoaderOverride(
t *testing.T,
fSys filesys.FileSystem,
root string,
pvd *provider.DepProvider,
ldrWrapperFn func(ifc.Loader) ifc.Loader) *target.KustTarget {
t.Helper()
baseLoader, err := fLdr.NewLoader(fLdr.RestrictionRootOnly, root, fSys)
if err != nil {
t.Fatal(err)
}
ldr := baseLoader
if ldrWrapperFn != nil {
ldr = ldrWrapperFn(baseLoader)
}
rf := resmap.NewFactory(pvd.GetResourceFactory())
pc := types.DisabledPluginConfig()
return target.NewKustTarget(

View File

@@ -15,11 +15,11 @@ type errTimeOut struct {
cmd string
}
func NewErrTimeOut(d time.Duration, c string) errTimeOut {
return errTimeOut{duration: d, cmd: c}
func NewErrTimeOut(d time.Duration, c string) *errTimeOut {
return &errTimeOut{duration: d, cmd: c}
}
func (e errTimeOut) Error() string {
func (e *errTimeOut) Error() string {
return fmt.Sprintf("hit %s timeout running '%s'", e.duration, e.cmd)
}

View File

@@ -10,7 +10,7 @@ import (
// TimedCall runs fn, failing if it doesn't complete in the given duration.
// The description is used in the timeout error message.
func TimedCall(description string, d time.Duration, fn func() error) error {
done := make(chan error)
done := make(chan error, 1)
timer := time.NewTimer(d)
defer timer.Stop()
go func() { done <- fn() }()

View File

@@ -9,6 +9,7 @@ import (
"time"
"github.com/stretchr/testify/assert"
"go.uber.org/goleak"
. "sigs.k8s.io/kustomize/api/internal/utils"
)
@@ -62,3 +63,20 @@ func TestTimedCallSlowWithError(t *testing.T) {
t.Fail()
}
}
func TestTimedCallGoroutineLeak(t *testing.T) {
defer goleak.VerifyNone(t)
err := TimedCall("function done, no goroutine leaks", timeToWait, func() error {
time.Sleep(tooSlow)
return fmt.Errorf("function done")
})
if assert.Error(t, err) {
assert.EqualError(t, err, errMsg("function done, no goroutine leaks"))
} else {
t.Fail()
}
// The code introduces a 2-second sleep to allow the goroutine to complete its execution.
// Subsequently, it verifies if the goroutine created by the function exits as expected.
time.Sleep(tooSlow)
}

View File

@@ -4,15 +4,47 @@
package krusty_test
import (
"fmt"
"net/http"
"net/http/httptest"
"path/filepath"
"regexp"
"strings"
"testing"
"github.com/stretchr/testify/require"
. "sigs.k8s.io/kustomize/api/internal/target"
"sigs.k8s.io/kustomize/api/konfig"
"sigs.k8s.io/kustomize/api/krusty"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
)
const validResource = `
apiVersion: v1
kind: Service
metadata:
name: myService
spec:
selector:
backend: bungie
ports:
- port: 7002
`
const invalidResource = `apiVersion: v1
kind: Service
metadata:
name: kapacitor
labels:
app.kubernetes.io/name: tick-kapacitor
spec:
selector:
app.kubernetes.io/name: tick-kapacitor
- name: http
port: 9092
protocol: TCP
type: ClusterIP`
func TestTargetMustHaveKustomizationFile(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteF("service.yaml", `
@@ -59,17 +91,7 @@ func TestBaseMustHaveKustomizationFile(t *testing.T) {
resources:
- base
`)
th.WriteF("base/service.yaml", `
apiVersion: v1
kind: Service
metadata:
name: myService
spec:
selector:
backend: bungie
ports:
- port: 7002
`)
th.WriteF("base/service.yaml", validResource)
err := th.RunWithErr(".", th.MakeDefaultOptions())
if err == nil {
t.Fatalf("expected an error")
@@ -160,3 +182,182 @@ spec:
secretName: cert-tls
`)
}
func TestAccumulateResourcesErrors(t *testing.T) {
type testcase struct {
name string
resource string
// resourceFunc generates a resource string using the URL to the local
// test server (optional).
resourceFunc func(string) string
// resourceServerSetup configures the local test server (optional).
resourceServerSetup func(*http.ServeMux)
isAbsolute bool
files map[string]string
// errFile, errDir are regex for the expected error message output
// when kustomize tries to accumulate resource as file and dir,
// respectively. The test substitutes occurrences of "%s" in the
// error strings with the absolute path where kustomize looks for it.
errFile, errDir string
}
populateAbsolutePaths := func(tc testcase, dir string) testcase {
filePaths := make(map[string]string, len(tc.files)+1)
for file, content := range tc.files {
filePaths[filepath.Join(dir, file)] = content
}
resourcePath := filepath.Join(dir, tc.resource)
if tc.isAbsolute {
tc.resource = resourcePath
}
filePaths[filepath.Join(dir, "kustomization.yaml")] = fmt.Sprintf(`
resources:
- %s
`, tc.resource)
tc.files = filePaths
regPath := regexp.QuoteMeta(resourcePath)
tc.errFile = strings.ReplaceAll(tc.errFile, "%s", regPath)
tc.errDir = strings.ReplaceAll(tc.errDir, "%s", regPath)
return tc
}
buildError := func(tc testcase) string {
const (
prefix = "accumulating resources"
filePrefixf = "accumulating resources from '%s'"
fileWrapperIfDirf = "accumulation err='%s'"
separator = ": "
)
parts := []string{
prefix,
strings.Join([]string{
fmt.Sprintf(filePrefixf, regexp.QuoteMeta(tc.resource)),
tc.errFile,
}, separator),
}
if tc.errDir != "" {
parts[1] = fmt.Sprintf(fileWrapperIfDirf, parts[1])
parts = append(parts, tc.errDir)
}
return strings.Join(parts, separator)
}
for _, test := range []testcase{
{
name: "remote file not considered repo",
resourceFunc: func(url string) string {
return fmt.Sprintf("%s/segments-too-few-to-be-repo", url)
},
resourceServerSetup: func(server *http.ServeMux) {
server.HandleFunc("/", func(out http.ResponseWriter, req *http.Request) {
out.WriteHeader(http.StatusNotFound)
})
},
// It's acceptable for the error output of a remote file-like
// resource to not indicate the resource's status as a
// local directory. Though it is possible for a remote file-like
// resource to be a local directory, it is very unlikely.
errFile: `HTTP Error: status code 404 \(Not Found\)\z`,
},
{
name: "remote file qualifies as repo",
resourceFunc: func(url string) string {
return fmt.Sprintf("%s/long/enough/to/have/org/and/repo", url)
},
resourceServerSetup: func(server *http.ServeMux) {
server.HandleFunc("/", func(out http.ResponseWriter, req *http.Request) {
out.WriteHeader(http.StatusInternalServerError)
})
},
// TODO(4788): This error message is technically wrong. Just
// because we fail to GET a resource does not mean the resource is
// not a remote file. We should return the GET status code as well.
errFile: "URL is a git repository",
errDir: `failed to run \S+/git fetch --depth=1 .+`,
},
{
name: "local file qualifies as repo",
// The .example top level domain is reserved for example purposes,
// see RFC 2606.
resource: "package@v1.28.0.example/configs/base",
errFile: `evalsymlink failure on '%s' .+`,
errDir: `failed to run \S+/git fetch --depth=1 .+`,
},
{
name: "relative path does not exist",
resource: "file-or-directory",
errFile: `evalsymlink failure on '%s' .+`,
errDir: `must build at directory: not a valid directory: evalsymlink failure .+`,
},
{
name: "absolute path does not exist",
resource: "file-or-directory",
isAbsolute: true,
errFile: `evalsymlink failure on '%s' .+`,
errDir: `new root '%s' cannot be absolute`,
},
{
name: "relative file violates restrictions",
resource: "../base/resource.yaml",
files: map[string]string{
"../base/resource.yaml": validResource,
},
errFile: "security; file '%s' is not in or below .+",
// TODO(4348): Over-inclusion of directory error message when we
// know resource is file.
errDir: "must build at directory: '%s': file is not directory",
},
{
name: "absolute file violates restrictions",
resource: "../base/resource.yaml",
isAbsolute: true,
files: map[string]string{
"../base/resource.yaml": validResource,
},
errFile: "security; file '%s' is not in or below .+",
// TODO(4348): Over-inclusion of directory error message when we
// know resource is file.
errDir: `new root '%s' cannot be absolute`,
},
{
name: "malformed yaml yields an error",
resource: "service.yaml",
files: map[string]string{
"service.yaml": invalidResource,
},
errFile: "MalformedYAMLError",
},
} {
t.Run(test.name, func(t *testing.T) {
if test.resourceFunc != nil {
// Configure test server handler
handler := http.NewServeMux()
if test.resourceServerSetup != nil {
test.resourceServerSetup(handler)
}
// Start test server
svr := httptest.NewServer(handler)
defer svr.Close()
// Generate resource with test server address
test.resource = test.resourceFunc(svr.URL)
}
// Should use real file system to indicate that we are creating
// new temporary directories on disk when we attempt to fetch repos.
fs, tmpDir := kusttest_test.Setup(t)
root := tmpDir.Join("root")
require.NoError(t, fs.Mkdir(root))
test = populateAbsolutePaths(test, root)
for file, content := range test.files {
dir := filepath.Dir(file)
require.NoError(t, fs.MkdirAll(dir))
require.NoError(t, fs.WriteFile(file, []byte(content)))
}
b := krusty.MakeKustomizer(krusty.MakeDefaultOptions())
_, err := b.Run(fs, root)
require.Regexp(t, buildError(test), err.Error())
})
}
// TODO(annasong): add tests that check accumulateResources errors for
// - repos
// - local directories
}

View File

@@ -8,8 +8,8 @@ import (
"strings"
"testing"
"sigs.k8s.io/kustomize/api/internal/loader"
"sigs.k8s.io/kustomize/api/konfig"
"sigs.k8s.io/kustomize/api/loader"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
)
@@ -39,7 +39,7 @@ resources:
- deploy.yaml
configMapGenerator:
- name: my-configmap
literals:
literals:
- testValue=purple
- otherValue=green
`)
@@ -64,7 +64,7 @@ resources:
configMapGenerator:
- name: my-configmap
behavior: merge
literals:
literals:
- testValue=blue
- compValue=red
`)
@@ -154,7 +154,7 @@ spec:
configMapGenerator:
- name: my-configmap
behavior: merge
literals:
literals:
- otherValue=orange
`),
writeK("prod", `
@@ -319,7 +319,7 @@ resources:
configMapGenerator:
- name: my-configmap
behavior: merge
literals:
literals:
- compValue=red
- testValue=blue
`),
@@ -350,7 +350,7 @@ kind: Component
configMapGenerator:
- name: my-configmap
behavior: merge
literals:
literals:
- otherValue=orange
`),
},
@@ -562,7 +562,7 @@ kind: Component
configMapGenerator:
- name: my-configmap
behavior: merge
literals:
literals:
- otherValue=orange
`),
},
@@ -657,3 +657,113 @@ components:
})
}
}
func TestOrderOfAccumulatedComponent(t *testing.T) {
tests := map[string]struct {
input []FileGen
expectedOutput string
}{
"components_using_a_generated_resource_by_configMapGenerator": {
input: []FileGen{
writeK("", `
resources:
- resource.yaml
components:
- components
configMapGenerator:
- name: generated-resource
literals:
- key=value
options:
disableNameSuffixHash: true`),
writeF("resource.yaml", `
apiVersion: v1
kind: ConfigMap
metadata:
name: config-from-resources
data:
foo: bar`),
writeC("/components", `
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
nameSuffix: -suffix
`),
},
expectedOutput: `
apiVersion: v1
data:
foo: bar
kind: ConfigMap
metadata:
name: config-from-resources-suffix
---
apiVersion: v1
data:
key: value
kind: ConfigMap
metadata:
name: generated-resource-suffix
`},
"components_are_applied_before_replacements_transformer_applied": {
input: []FileGen{
writeK("", `
resources:
- resource.yaml
components:
- components
replacements:
- source:
kind: Pod
name: myapp-pod
fieldPath: metadata.namespace
targets:
- select:
kind: Pod
name: myapp-pod
fieldPaths:
- spec.containers.[name=myapp-container].env.[name=CURRENT_POD_NAMESPACE].value`),
writeF("resource.yaml", `
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
namespace: dev-assa
spec:
containers:
- image: busybox
name: myapp-container
env:
- name: CURRENT_POD_NAMESPACE
value: "$(PLACEHOLDER)"`),
writeC("/components", `
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
namespace: kustomize-namespace`),
},
expectedOutput: `
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
namespace: kustomize-namespace
spec:
containers:
- env:
- name: CURRENT_POD_NAMESPACE
value: kustomize-namespace
image: busybox
name: myapp-container
`},
}
for testName, test := range tests {
t.Run(testName, func(t *testing.T) {
th := kusttest_test.MakeHarness(t)
for _, f := range test.input {
f(th)
}
m := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, test.expectedOutput)
})
}
}

View File

@@ -591,3 +591,184 @@ metadata:
name: test-m8t7bmb6g2
`)
}
// Regression test for https://github.com/kubernetes-sigs/kustomize/issues/5047
func TestPrefixSuffix(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteF("kustomization.yaml", `
resources:
- a
- b
`)
th.WriteF("a/kustomization.yaml", `
resources:
- ../common
namePrefix: a
`)
th.WriteF("b/kustomization.yaml", `
resources:
- ../common
namePrefix: b
`)
th.WriteF("common/kustomization.yaml", `
resources:
- service
configMapGenerator:
- name: "-example-configmap"
`)
th.WriteF("common/service/deployment.yaml", `
kind: Deployment
apiVersion: apps/v1
metadata:
name: "-"
spec:
template:
spec:
containers:
- name: app
envFrom:
- configMapRef:
name: "-example-configmap"
`)
th.WriteF("common/service/kustomization.yaml", `
resources:
- deployment.yaml
nameSuffix: api
`)
m := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: apps/v1
kind: Deployment
metadata:
name: a-api
spec:
template:
spec:
containers:
- envFrom:
- configMapRef:
name: a-example-configmap-6ct58987ht
name: app
---
apiVersion: v1
kind: ConfigMap
metadata:
name: a-example-configmap-6ct58987ht
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: b-api
spec:
template:
spec:
containers:
- envFrom:
- configMapRef:
name: b-example-configmap-6ct58987ht
name: app
---
apiVersion: v1
kind: ConfigMap
metadata:
name: b-example-configmap-6ct58987ht
`)
}
// Regression test for https://github.com/kubernetes-sigs/kustomize/issues/5047
func TestPrefixSuffix2(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteF("kustomization.yaml", `
resources:
- a
- b
`)
th.WriteF("a/kustomization.yaml", `
resources:
- ../common
namePrefix: a
`)
th.WriteF("b/kustomization.yaml", `
resources:
- ../common
namePrefix: b
`)
th.WriteF("common/deployment.yaml", `
apiVersion: apps/v1
kind: Deployment
metadata:
name: "-example"
spec:
template:
spec:
containers:
- name: app
envFrom:
- configMapRef:
name: "-example-configmap"
`)
th.WriteF("common/kustomization.yaml", `
resources:
- deployment.yaml
configMapGenerator:
- name: "-example-configmap"
`)
m := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: apps/v1
kind: Deployment
metadata:
name: a-example
spec:
template:
spec:
containers:
- envFrom:
- configMapRef:
name: a-example-configmap-6ct58987ht
name: app
---
apiVersion: v1
kind: ConfigMap
metadata:
name: a-example-configmap-6ct58987ht
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: b-example
spec:
template:
spec:
containers:
- envFrom:
- configMapRef:
name: b-example-configmap-6ct58987ht
name: app
---
apiVersion: v1
kind: ConfigMap
metadata:
name: b-example-configmap-6ct58987ht
`)
}

View File

@@ -17,12 +17,16 @@ commonLabels:
vars:
- name: APRIL_DIET
objref:
group: foo
version: v1
kind: Giraffe
name: april
fieldref:
fieldpath: spec.diet
- name: KOKO_DIET
objref:
group: foo
version: v1
kind: Gorilla
name: koko
fieldref:
@@ -36,6 +40,7 @@ configurations:
- config/custom.yaml
`)
th.WriteF("base/giraffes.yaml", `
apiVersion: foo/v1
kind: Giraffe
metadata:
name: april
@@ -43,6 +48,7 @@ spec:
diet: mimosa
location: NE
---
apiVersion: foo/v1
kind: Giraffe
metadata:
name: may
@@ -51,6 +57,7 @@ spec:
location: SE
`)
th.WriteF("base/gorilla.yaml", `
apiVersion: foo/v1
kind: Gorilla
metadata:
name: koko
@@ -59,7 +66,7 @@ spec:
location: SW
`)
th.WriteF("base/animalPark.yaml", `
apiVersion: foo
apiVersion: foo/v1
kind: AnimalPark
metadata:
name: sandiego
@@ -94,7 +101,7 @@ varReference:
`)
m := th.Run("base", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: foo
apiVersion: foo/v1
kind: AnimalPark
metadata:
labels:
@@ -109,6 +116,7 @@ spec:
gorillaRef:
name: x-koko
---
apiVersion: foo/v1
kind: Giraffe
metadata:
labels:
@@ -118,6 +126,7 @@ spec:
diet: mimosa
location: NE
---
apiVersion: foo/v1
kind: Giraffe
metadata:
labels:
@@ -127,6 +136,7 @@ spec:
diet: acacia
location: SE
---
apiVersion: foo/v1
kind: Gorilla
metadata:
labels:
@@ -163,7 +173,7 @@ varReference:
`)
m := th.Run("base", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: foo
apiVersion: foo/v1
kind: AnimalPark
metadata:
labels:
@@ -178,6 +188,7 @@ spec:
gorillaRef:
name: x-koko
---
apiVersion: foo/v1
kind: Giraffe
metadata:
labels:
@@ -187,6 +198,7 @@ spec:
diet: mimosa
location: NE
---
apiVersion: foo/v1
kind: Giraffe
metadata:
labels:
@@ -196,6 +208,7 @@ spec:
diet: acacia
location: SE
---
apiVersion: foo/v1
kind: Gorilla
metadata:
labels:
@@ -215,17 +228,20 @@ func TestFixedBug605_BaseCustomizationAvailableInOverlay(t *testing.T) {
nameReference:
- kind: Gorilla
fieldSpecs:
- apiVersion: foo
- group: foo
version: v1
kind: AnimalPark
path: spec/gorillaRef/name
- kind: Giraffe
fieldSpecs:
- apiVersion: foo
- group: foo
version: v1
kind: AnimalPark
path: spec/giraffeRef/name
varReference:
- path: spec/food
apiVersion: foo
group: foo
version: v1
kind: AnimalPark
`)
th.WriteK("overlay", `
@@ -239,6 +255,7 @@ resources:
- ursus.yaml
`)
th.WriteF("overlay/ursus.yaml", `
apiVersion: foo/v1
kind: Gorilla
metadata:
name: ursus
@@ -248,7 +265,7 @@ spec:
`)
// The following replaces the gorillaRef in the AnimalPark.
th.WriteF("overlay/animalPark.yaml", `
apiVersion: foo
apiVersion: foo/v1
kind: AnimalPark
metadata:
name: sandiego
@@ -258,7 +275,7 @@ spec:
`)
m := th.Run("overlay", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: foo
apiVersion: foo/v1
kind: AnimalPark
metadata:
labels:
@@ -274,6 +291,7 @@ spec:
gorillaRef:
name: o-ursus
---
apiVersion: foo/v1
kind: Giraffe
metadata:
labels:
@@ -284,6 +302,7 @@ spec:
diet: mimosa
location: NE
---
apiVersion: foo/v1
kind: Giraffe
metadata:
labels:
@@ -294,6 +313,7 @@ spec:
diet: acacia
location: SE
---
apiVersion: foo/v1
kind: Gorilla
metadata:
labels:
@@ -304,6 +324,7 @@ spec:
diet: bambooshoots
location: SW
---
apiVersion: foo/v1
kind: Gorilla
metadata:
labels:
@@ -314,3 +335,400 @@ spec:
location: Arizona
`)
}
func TestLabelTransformerConfig(t *testing.T) {
testCases := []struct {
name string
kustomization string
transformerConfig string
expectedResult string
}{
{
name: "includeSelectors=false, includeTemplates=false, include template via transformerConfig",
kustomization: `configurations:
- config/configurations.yaml
labels:
- includeSelectors: false
includeTemplates: false
pairs:
location: planet-earth
environment: dev
resources:
- resources/deployment.yaml
`,
transformerConfig: `labels:
- path: spec/template/metadata/labels
create: true
kind: Deployment
`,
expectedResult: `apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: sample-deploy
environment: dev
location: planet-earth
name: sample-deploy
spec:
replicas: 1
selector:
matchLabels:
app: sample-deploy
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: sample-deploy
environment: dev
location: planet-earth
spec:
containers:
- image: hello-world:latest
name: hello-world
`,
},
{
name: "includeSelectors=true, includeTemplates=false, include template via transformerConfig",
kustomization: `configurations:
- config/configurations.yaml
labels:
- includeSelectors: true
includeTemplates: false
pairs:
location: planet-earth
environment: dev
resources:
- resources/deployment.yaml
`,
transformerConfig: `labels:
- path: spec/template/metadata/labels
create: true
kind: Deployment
`,
expectedResult: `apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: sample-deploy
environment: dev
location: planet-earth
name: sample-deploy
spec:
replicas: 1
selector:
matchLabels:
app: sample-deploy
environment: dev
location: planet-earth
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: sample-deploy
environment: dev
location: planet-earth
spec:
containers:
- image: hello-world:latest
name: hello-world
`,
},
{
name: "includeSelectors=false, includeTemplates=true, no transformerConfig",
kustomization: `labels:
- includeSelectors: false
includeTemplates: true
pairs:
location: planet-earth
environment: dev
resources:
- resources/deployment.yaml
`,
expectedResult: `apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: sample-deploy
environment: dev
location: planet-earth
name: sample-deploy
spec:
replicas: 1
selector:
matchLabels:
app: sample-deploy
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: sample-deploy
environment: dev
location: planet-earth
spec:
containers:
- image: hello-world:latest
name: hello-world
`,
},
{
name: "includeSelectors=false, includeTemplates=false, no transformerConfig",
kustomization: `labels:
- includeSelectors: false
includeTemplates: false
pairs:
location: planet-earth
environment: dev
resources:
- resources/deployment.yaml
`,
expectedResult: `apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: sample-deploy
environment: dev
location: planet-earth
name: sample-deploy
spec:
replicas: 1
selector:
matchLabels:
app: sample-deploy
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: sample-deploy
spec:
containers:
- image: hello-world:latest
name: hello-world
`,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", tc.kustomization)
th.WriteF("resources/deployment.yaml",
`apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: sample-deploy
name: sample-deploy
spec:
replicas: 1
selector:
matchLabels:
app: sample-deploy
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: sample-deploy
spec:
containers:
- image: hello-world:latest
name: hello-world
`)
if tc.transformerConfig != "" {
th.WriteF("config/configurations.yaml", tc.transformerConfig)
}
output := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(output, tc.expectedResult)
})
}
}
func TestLabelTransformerConfigWithCustomResources(t *testing.T) {
testCases := []struct {
name string
kustomization string
transformerConfig string
expectedResult string
}{
{
name: "include template via transformerConfig",
kustomization: `configurations:
- config/configurations.yaml
labels:
- includeSelectors: false
includeTemplates: false
pairs:
location: planet-earth
environment: dev
resources:
- resources/custom-resource.yaml
`,
transformerConfig: `labels:
- path: spec/template/metadata/labels
create: true
kind: SampleResource
`,
expectedResult: `apiVersion: custom.example.org/v1
kind: SampleResource
metadata:
labels:
environment: dev
location: planet-earth
name: sample-resource
namespace: sample-namespace
spec:
template:
metadata:
labels:
environment: dev
location: planet-earth
spec:
containers:
- env:
- name: VARIABLE
value: value
image: index.docker.io/library/hello-world
`,
},
{
name: "include selector via transformerConfig",
kustomization: `configurations:
- config/configurations.yaml
labels:
- includeSelectors: false
includeTemplates: false
pairs:
location: planet-earth
environment: dev
resources:
- resources/custom-resource.yaml
`,
transformerConfig: `labels:
- path: spec/selectors/labels
create: true
kind: SampleResource
`,
expectedResult: `apiVersion: custom.example.org/v1
kind: SampleResource
metadata:
labels:
environment: dev
location: planet-earth
name: sample-resource
namespace: sample-namespace
spec:
selectors:
labels:
environment: dev
location: planet-earth
template:
spec:
containers:
- env:
- name: VARIABLE
value: value
image: index.docker.io/library/hello-world
`,
},
{
name: "include selectors and labels via transformerConfig",
kustomization: `configurations:
- config/configurations.yaml
labels:
- includeSelectors: false
includeTemplates: false
pairs:
location: planet-earth
environment: dev
resources:
- resources/custom-resource.yaml
`,
transformerConfig: `
labels:
- path: spec/selectors/labels
create: true
kind: SampleResource
- path: spec/template/metadata/labels
create: true
kind: SampleResource
`,
expectedResult: `apiVersion: custom.example.org/v1
kind: SampleResource
metadata:
labels:
environment: dev
location: planet-earth
name: sample-resource
namespace: sample-namespace
spec:
selectors:
labels:
environment: dev
location: planet-earth
template:
metadata:
labels:
environment: dev
location: planet-earth
spec:
containers:
- env:
- name: VARIABLE
value: value
image: index.docker.io/library/hello-world
`,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", tc.kustomization)
th.WriteF("resources/custom-resource.yaml",
`apiVersion: custom.example.org/v1
kind: SampleResource
metadata:
name: sample-resource
namespace: sample-namespace
spec:
template:
spec:
containers:
- image: index.docker.io/library/hello-world
env:
- name: VARIABLE
value: value
`)
th.WriteF("config/configurations.yaml", tc.transformerConfig)
output := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(output, tc.expectedResult)
})
}
}

View File

@@ -9,9 +9,20 @@ import (
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
)
const expectedResources = `apiVersion: v1
kind: Service
metadata:
name: myService
spec:
ports:
- port: 7002
`
func TestIssue596AllowDirectoriesThatAreSubstringsOfEachOther(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK("base", "")
th.WriteF("base/service.yaml", expectedResources)
th.WriteK("base", `resources:
- service.yaml`)
th.WriteK("overlays/aws", `
resources:
- ../../base
@@ -25,5 +36,5 @@ resources:
- ../aws-nonprod
`)
m := th.Run("overlays/aws-sandbox2.us-east-1", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, "")
th.AssertActualEqualsExpected(m, expectedResources)
}

View File

@@ -7,6 +7,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
)
@@ -41,6 +42,6 @@ spec:
`)
m := th.Run(".", th.MakeDefaultOptions())
_, err := m.AsYaml()
assert.Error(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), "mapping key \"env\" already defined")
}

View File

@@ -4,17 +4,23 @@
package krusty_test
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
. "sigs.k8s.io/kustomize/api/krusty"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
"sigs.k8s.io/kustomize/kyaml/filesys"
)
const (
repoRootDir = "../../"
)
const generateDeploymentDotSh = `#!/bin/sh
cat <<EOF
@@ -61,7 +67,7 @@ func TestFnExecGeneratorInBase(t *testing.T) {
o.PluginConfig.FnpLoadingOptions.EnableExec = true
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
require.NoError(t, err)
th.WriteK(tmpDir.String(), `
resources:
- short_secret.yaml
@@ -86,7 +92,7 @@ stringData:
`)
th.WriteF(filepath.Join(tmpDir.String(), "generateDeployment.sh"), generateDeploymentDotSh)
assert.NoError(t, os.Chmod(filepath.Join(tmpDir.String(), "generateDeployment.sh"), 0777))
require.NoError(t, os.Chmod(filepath.Join(tmpDir.String(), "generateDeployment.sh"), 0777))
th.WriteF(filepath.Join(tmpDir.String(), "gener.yaml"), `
kind: executable
metadata:
@@ -100,7 +106,7 @@ spec:
m := th.Run(tmpDir.String(), o)
yml, err := m.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, `apiVersion: v1
kind: Secret
metadata:
@@ -134,7 +140,7 @@ spec:
- image: nginx
name: nginx
`, string(yml))
assert.NoError(t, fSys.RemoveAll(tmpDir.String()))
require.NoError(t, fSys.RemoveAll(tmpDir.String()))
}
func TestFnExecGeneratorInBaseWithOverlay(t *testing.T) {
@@ -145,11 +151,11 @@ func TestFnExecGeneratorInBaseWithOverlay(t *testing.T) {
o.PluginConfig.FnpLoadingOptions.EnableExec = true
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
require.NoError(t, err)
base := filepath.Join(tmpDir.String(), "base")
prod := filepath.Join(tmpDir.String(), "prod")
assert.NoError(t, fSys.Mkdir(base))
assert.NoError(t, fSys.Mkdir(prod))
require.NoError(t, fSys.Mkdir(base))
require.NoError(t, fSys.Mkdir(prod))
th.WriteK(base, `
resources:
- short_secret.yaml
@@ -176,7 +182,7 @@ stringData:
`)
th.WriteF(filepath.Join(base, "generateDeployment.sh"), generateDeploymentDotSh)
assert.NoError(t, os.Chmod(filepath.Join(base, "generateDeployment.sh"), 0777))
require.NoError(t, os.Chmod(filepath.Join(base, "generateDeployment.sh"), 0777))
th.WriteF(filepath.Join(base, "gener.yaml"), `
kind: executable
metadata:
@@ -189,9 +195,9 @@ spec:
`)
m := th.Run(prod, o)
assert.NoError(t, err)
require.NoError(t, err)
yml, err := m.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, `apiVersion: v1
kind: Secret
metadata:
@@ -225,7 +231,7 @@ spec:
- image: nginx
name: nginx
`, string(yml))
assert.NoError(t, fSys.RemoveAll(tmpDir.String()))
require.NoError(t, fSys.RemoveAll(tmpDir.String()))
}
func TestFnExecGeneratorInOverlay(t *testing.T) {
@@ -236,11 +242,11 @@ func TestFnExecGeneratorInOverlay(t *testing.T) {
o.PluginConfig.FnpLoadingOptions.EnableExec = true
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
require.NoError(t, err)
base := filepath.Join(tmpDir.String(), "base")
prod := filepath.Join(tmpDir.String(), "prod")
assert.NoError(t, fSys.Mkdir(base))
assert.NoError(t, fSys.Mkdir(prod))
require.NoError(t, fSys.Mkdir(base))
require.NoError(t, fSys.Mkdir(prod))
th.WriteK(base, `
resources:
- short_secret.yaml
@@ -267,7 +273,7 @@ stringData:
`)
th.WriteF(filepath.Join(prod, "generateDeployment.sh"), generateDeploymentDotSh)
assert.NoError(t, os.Chmod(filepath.Join(prod, "generateDeployment.sh"), 0777))
require.NoError(t, os.Chmod(filepath.Join(prod, "generateDeployment.sh"), 0777))
th.WriteF(filepath.Join(prod, "gener.yaml"), `
kind: executable
metadata:
@@ -280,9 +286,9 @@ spec:
`)
m := th.Run(prod, o)
assert.NoError(t, err)
require.NoError(t, err)
yml, err := m.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, `apiVersion: v1
kind: Secret
metadata:
@@ -316,7 +322,7 @@ spec:
- image: nginx
name: nginx
`, string(yml))
assert.NoError(t, fSys.RemoveAll(tmpDir.String()))
require.NoError(t, fSys.RemoveAll(tmpDir.String()))
}
func TestFnExecTransformerInBase(t *testing.T) {
@@ -327,9 +333,9 @@ func TestFnExecTransformerInBase(t *testing.T) {
o.PluginConfig.FnpLoadingOptions.EnableExec = true
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
require.NoError(t, err)
base := filepath.Join(tmpDir.String(), "base")
assert.NoError(t, fSys.Mkdir(base))
require.NoError(t, fSys.Mkdir(base))
th.WriteK(base, `
resources:
- secret.yaml
@@ -348,7 +354,7 @@ stringData:
`)
th.WriteF(filepath.Join(base, "krmTransformer.sh"), krmTransformerDotSh)
assert.NoError(t, os.Chmod(filepath.Join(base, "krmTransformer.sh"), 0777))
require.NoError(t, os.Chmod(filepath.Join(base, "krmTransformer.sh"), 0777))
th.WriteF(filepath.Join(base, "krm-transformer.yaml"), `
apiVersion: examples.config.kubernetes.io/v1beta1
kind: MyPlugin
@@ -362,7 +368,7 @@ metadata:
m := th.Run(base, o)
yml, err := m.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, `apiVersion: v1
kind: Secret
metadata:
@@ -371,7 +377,7 @@ stringData:
foo: bar
type: Opaque
`, string(yml))
assert.NoError(t, fSys.RemoveAll(tmpDir.String()))
require.NoError(t, fSys.RemoveAll(tmpDir.String()))
}
func TestFnExecTransformerInBaseWithOverlay(t *testing.T) {
@@ -382,11 +388,11 @@ func TestFnExecTransformerInBaseWithOverlay(t *testing.T) {
o.PluginConfig.FnpLoadingOptions.EnableExec = true
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
require.NoError(t, err)
base := filepath.Join(tmpDir.String(), "base")
prod := filepath.Join(tmpDir.String(), "prod")
assert.NoError(t, fSys.Mkdir(base))
assert.NoError(t, fSys.Mkdir(prod))
require.NoError(t, fSys.Mkdir(base))
require.NoError(t, fSys.Mkdir(prod))
th.WriteK(base, `
resources:
- secret.yaml
@@ -409,7 +415,7 @@ stringData:
`)
th.WriteF(filepath.Join(base, "krmTransformer.sh"), krmTransformerDotSh)
assert.NoError(t, os.Chmod(filepath.Join(base, "krmTransformer.sh"), 0777))
require.NoError(t, os.Chmod(filepath.Join(base, "krmTransformer.sh"), 0777))
th.WriteF(filepath.Join(base, "krm-transformer.yaml"), `
apiVersion: examples.config.kubernetes.io/v1beta1
kind: MyPlugin
@@ -423,7 +429,7 @@ metadata:
m := th.Run(prod, o)
yml, err := m.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, `apiVersion: v1
kind: Secret
metadata:
@@ -432,7 +438,7 @@ stringData:
foo: bar
type: Opaque
`, string(yml))
assert.NoError(t, fSys.RemoveAll(tmpDir.String()))
require.NoError(t, fSys.RemoveAll(tmpDir.String()))
}
func TestFnExecTransformerInOverlay(t *testing.T) {
@@ -443,11 +449,11 @@ func TestFnExecTransformerInOverlay(t *testing.T) {
o.PluginConfig.FnpLoadingOptions.EnableExec = true
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
require.NoError(t, err)
base := filepath.Join(tmpDir.String(), "base")
prod := filepath.Join(tmpDir.String(), "prod")
assert.NoError(t, fSys.Mkdir(base))
assert.NoError(t, fSys.Mkdir(prod))
require.NoError(t, fSys.Mkdir(base))
require.NoError(t, fSys.Mkdir(prod))
th.WriteK(base, `
resources:
- secret.yaml
@@ -470,7 +476,7 @@ stringData:
`)
th.WriteF(filepath.Join(prod, "krmTransformer.sh"), krmTransformerDotSh)
assert.NoError(t, os.Chmod(filepath.Join(prod, "krmTransformer.sh"), 0777))
require.NoError(t, os.Chmod(filepath.Join(prod, "krmTransformer.sh"), 0777))
th.WriteF(filepath.Join(prod, "krm-transformer.yaml"), `
apiVersion: examples.config.kubernetes.io/v1beta1
kind: MyPlugin
@@ -484,7 +490,7 @@ metadata:
m := th.Run(prod, o)
yml, err := m.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, `apiVersion: v1
kind: Secret
metadata:
@@ -493,7 +499,7 @@ stringData:
foo: bar
type: Opaque
`, string(yml))
assert.NoError(t, fSys.RemoveAll(tmpDir.String()))
require.NoError(t, fSys.RemoveAll(tmpDir.String()))
}
func skipIfNoDocker(t *testing.T) {
@@ -508,56 +514,63 @@ func TestFnContainerGenerator(t *testing.T) {
th := kusttest_test.MakeHarness(t)
o := th.MakeOptionsPluginsEnabled()
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
require.NoError(t, err)
th.WriteK(tmpDir.String(), `
resources:
- deployment.yaml
generators:
- project-service-set.yaml
- service-set.yaml
`)
// Create generator config
th.WriteF(filepath.Join(tmpDir.String(), "project-service-set.yaml"), `
apiVersion: blueprints.cloud.google.com/v1alpha1
kind: ProjectServiceSet
th.WriteF(filepath.Join(tmpDir.String(), "service-set.yaml"), `
apiVersion: kustomize.sigs.k8s.io/v1alpha1
kind: ServiceGenerator
metadata:
name: demo
name: simplegenerator
annotations:
config.kubernetes.io/function: |
container:
image: gcr.io/kpt-fn/enable-gcp-services:v0.1.0
image: gcr.io/kustomize-functions/e2econtainersimplegenerator
spec:
services:
- compute.googleapis.com
projectID: foo
port: 8081
`)
// Create another resource just to make sure everything is added
th.WriteF(filepath.Join(tmpDir.String(), "deployment.yaml"), `
apiVersion: apps/v1
kind: Deployment
metadata:
name: foo
name: simplegenerator
`)
build := exec.Command("docker", "build", ".",
"-f", "./cmd/config/internal/commands/e2e/e2econtainersimplegenerator/Dockerfile",
"-t", "gcr.io/kustomize-functions/e2econtainersimplegenerator",
)
build.Dir = repoRootDir
require.NoError(t, run(build))
m := th.Run(tmpDir.String(), o)
actual, err := m.AsYaml()
assert.NoError(t, err)
assert.Equal(t, `apiVersion: apps/v1
require.NoError(t, err)
require.Equal(t, `apiVersion: apps/v1
kind: Deployment
metadata:
name: foo
name: simplegenerator
---
apiVersion: serviceusage.cnrm.cloud.google.com/v1beta1
apiVersion: v1
kind: Service
metadata:
annotations:
blueprints.cloud.google.com/ownerReference: blueprints.cloud.google.com/ProjectServiceSet/demo
config.kubernetes.io/function: |
container:
image: gcr.io/kpt-fn/enable-gcp-services:v0.1.0
name: demo-compute
labels:
app: simplegenerator
name: simplegenerator-svc
spec:
projectRef:
external: foo
resourceID: compute.googleapis.com
ports:
- name: http
port: 8081
protocol: TCP
targetPort: 8081
selector:
app: simplegenerator
`, string(actual))
}
@@ -566,7 +579,7 @@ func TestFnContainerTransformer(t *testing.T) {
th := kusttest_test.MakeHarness(t)
o := th.MakeOptionsPluginsEnabled()
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
require.NoError(t, err)
th.WriteK(tmpDir.String(), `
resources:
- deployment.yaml
@@ -589,12 +602,15 @@ metadata:
container:
image: "gcr.io/kustomize-functions/e2econtainerconfig"
`)
build := exec.Command("docker", "build", ".", "-t", "gcr.io/kustomize-functions/e2econtainerconfig")
build.Dir = "../../cmd/config/internal/commands/e2e/e2econtainerconfig"
assert.NoError(t, build.Run())
build := exec.Command("docker", "build", ".",
"-f", "./cmd/config/internal/commands/e2e/e2econtainerconfig/Dockerfile",
"-t", "gcr.io/kustomize-functions/e2econtainerconfig",
)
build.Dir = repoRootDir
require.NoError(t, run(build))
m := th.Run(tmpDir.String(), o)
actual, err := m.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, `apiVersion: apps/v1
kind: Deployment
metadata:
@@ -608,32 +624,38 @@ metadata:
func TestFnContainerTransformerWithConfig(t *testing.T) {
skipIfNoDocker(t)
//https://docs.docker.com/engine/reference/commandline/build/#git-repositories
build := exec.Command("docker", "build", "https://github.com/GoogleContainerTools/kpt-functions-sdk.git#go-sdk-v0.0.1:ts/hello-world",
"-f", "build/label_namespace.Dockerfile",
"-t", "gcr.io/kpt-functions/label-namespace:go-sdk-v0.0.1",
)
require.NoError(t, run(build))
th := kusttest_test.MakeHarness(t)
o := th.MakeOptionsPluginsEnabled()
fSys := filesys.MakeFsOnDisk()
b := MakeKustomizer(&o)
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "kustomization.yaml"), []byte(`
require.NoError(t, err)
require.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "kustomization.yaml"), []byte(`
resources:
- data1.yaml
- data2.yaml
transformers:
- label_namespace.yaml
`)))
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "data1.yaml"), []byte(`
require.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "data1.yaml"), []byte(`
apiVersion: v1
kind: Namespace
metadata:
name: my-namespace
`)))
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "data2.yaml"), []byte(`
require.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "data2.yaml"), []byte(`
apiVersion: v1
kind: Namespace
metadata:
name: another-namespace
`)))
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "label_namespace.yaml"), []byte(`
require.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "label_namespace.yaml"), []byte(`
apiVersion: v1
kind: ConfigMap
metadata:
@@ -641,7 +663,7 @@ metadata:
annotations:
config.kubernetes.io/function: |-
container:
image: gcr.io/kpt-functions/label-namespace@sha256:4f030738d6d25a207641ca517916431517578bd0eb8d98a8bde04e3bb9315dcd
image: gcr.io/kpt-functions/label-namespace:go-sdk-v0.0.1
data:
label_name: my-ns-name
label_value: function-test
@@ -649,9 +671,9 @@ data:
m, err := b.Run(
fSys,
tmpDir.String())
assert.NoError(t, err)
require.NoError(t, err)
actual, err := m.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, `apiVersion: v1
kind: Namespace
metadata:
@@ -675,37 +697,43 @@ func TestFnContainerEnvVars(t *testing.T) {
fSys := filesys.MakeFsOnDisk()
b := MakeKustomizer(&o)
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "kustomization.yaml"), []byte(`
require.NoError(t, err)
require.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "kustomization.yaml"), []byte(`
generators:
- gener.yaml
`)))
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "gener.yaml"), []byte(`
apiVersion: v1
kind: ConfigMap
require.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "gener.yaml"), []byte(`
apiVersion: kustomize.sigs.k8s.io/v1alpha1
kind: EnvTemplateGenerator
metadata:
name: demo
name: e2econtainerenvgenerator
annotations:
config.kubernetes.io/function: |
container:
image: quay.io/aodinokov/kpt-templater:0.0.1
image: gcr.io/kustomize-functions/e2econtainerenvgenerator
envs:
- TESTTEMPLATE=value
data:
template: |
apiVersion: v1
kind: ConfigMap
metadata:
name: env
data:
value: '{{ env "TESTTEMPLATE" }}'
template: |
apiVersion: v1
kind: ConfigMap
metadata:
name: env
data:
value: %q
`)))
build := exec.Command("docker", "build", ".",
"-f", "./cmd/config/internal/commands/e2e/e2econtainerenvgenerator/Dockerfile",
"-t", "gcr.io/kustomize-functions/e2econtainerenvgenerator",
)
build.Dir = repoRootDir
require.NoError(t, run(build))
m, err := b.Run(
fSys,
tmpDir.String())
assert.NoError(t, err)
require.NoError(t, err)
actual, err := m.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, `apiVersion: v1
data:
value: value
@@ -722,62 +750,54 @@ func TestFnContainerFnMounts(t *testing.T) {
fSys := filesys.MakeFsOnDisk()
b := MakeKustomizer(&o)
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "kustomization.yaml"), []byte(`
require.NoError(t, err)
require.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "kustomization.yaml"), []byte(`
generators:
- gener.yaml
`)))
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "gener.yaml"), []byte(`
apiVersion: v1alpha1
require.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "gener.yaml"), []byte(`
apiVersion: kustomize.sigs.k8s.io/v1alpha1
kind: RenderHelmChart
metadata:
name: demo
annotations:
config.kubernetes.io/function: |
container:
image: gcr.io/kpt-fn/render-helm-chart:v0.1.0
image: gcr.io/kustomize-functions/e2econtainermountbind
mounts:
- type: "bind"
src: "./charts"
dst: "/tmp/charts"
helmCharts:
- name: helloworld-chart
releaseName: test
valuesFile: /tmp/charts/helloworld-values/values.yaml
src: "./yaml"
dst: "/tmp/yaml"
path: /tmp/yaml/resources.yaml
`)))
assert.NoError(t, fSys.MkdirAll(filepath.Join(tmpDir.String(), "charts", "helloworld-chart", "templates")))
assert.NoError(t, fSys.MkdirAll(filepath.Join(tmpDir.String(), "charts", "helloworld-values")))
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "charts", "helloworld-chart", "Chart.yaml"), []byte(`
apiVersion: v2
name: helloworld-chart
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
appVersion: 1.16.0
`)))
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "charts", "helloworld-chart", "templates", "deployment.yaml"), []byte(`
require.NoError(t, fSys.MkdirAll(filepath.Join(tmpDir.String(), "yaml", "tmp")))
require.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "yaml", "resources.yaml"), []byte(`
apiVersion: apps/v1
kind: Deployment
metadata:
name: name
spec:
replicas: {{ .Values.replicaCount }}
`)))
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "charts", "helloworld-values", "values.yaml"), []byte(`
replicaCount: 5
replicas: 3
`)))
build := exec.Command("docker", "build", ".",
"-f", "./cmd/config/internal/commands/e2e/e2econtainermountbind/Dockerfile",
"-t", "gcr.io/kustomize-functions/e2econtainermountbind",
)
build.Dir = repoRootDir
require.NoError(t, run(build))
m, err := b.Run(
fSys,
tmpDir.String())
assert.NoError(t, err)
require.NoError(t, err)
actual, err := m.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, `apiVersion: apps/v1
kind: Deployment
metadata:
name: name
spec:
replicas: 5
replicas: 3
`, string(actual))
}
@@ -788,8 +808,8 @@ func TestFnContainerMountsLoadRestrictions_absolute(t *testing.T) {
fSys := filesys.MakeFsOnDisk()
b := MakeKustomizer(&o)
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "kustomization.yaml"), []byte(`
require.NoError(t, err)
require.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "kustomization.yaml"), []byte(`
generators:
- |-
apiVersion: v1alpha1
@@ -808,7 +828,7 @@ generators:
_, err = b.Run(
fSys,
tmpDir.String())
assert.Error(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), "loading generator plugins: failed to load generator: plugin RenderHelmChart."+
"v1alpha1.[noGrp]/demo.[noNs] with mount path '/tmp/dir' is not permitted; mount paths must"+
" be relative to the current kustomization directory")
@@ -821,8 +841,8 @@ func TestFnContainerMountsLoadRestrictions_outsideCurrentDir(t *testing.T) {
fSys := filesys.MakeFsOnDisk()
b := MakeKustomizer(&o)
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "kustomization.yaml"), []byte(`
require.NoError(t, err)
require.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "kustomization.yaml"), []byte(`
generators:
- |-
apiVersion: v1alpha1
@@ -841,7 +861,7 @@ generators:
_, err = b.Run(
fSys,
tmpDir.String())
assert.Error(t, err)
require.Error(t, err)
assert.Contains(t, err.Error(), "loading generator plugins: failed to load generator: plugin RenderHelmChart."+
"v1alpha1.[noGrp]/demo.[noNs] with mount path './tmp/../../dir' is not permitted; mount paths must "+
"be under the current kustomization directory")
@@ -869,6 +889,15 @@ spec:
replicas: 3
`)
err := th.RunWithErr(".", th.MakeOptionsPluginsEnabled())
assert.Error(t, err)
require.Error(t, err)
assert.EqualError(t, err, "couldn't execute function: root working directory '/' not allowed")
}
// run calls Cmd.Run and wraps the error to include the output to make debugging
// easier. Not safe for real code, but fine for tests.
func run(cmd *exec.Cmd) error {
if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("%w\n--- COMMAND OUTPUT ---\n%s", err, string(out))
}
return nil
}

View File

@@ -6,7 +6,7 @@ package krusty_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
)
@@ -496,7 +496,7 @@ spec:
options := th.MakeDefaultOptions()
// depPatch cannot find target with kind `Deployment` and name `new-name`
// because the resource never had this GVKN
assert.Error(t, th.RunWithErr("overlay", options))
require.Error(t, th.RunWithErr("overlay", options))
}
// Here is a structure of a kustomization of two components, component1

View File

@@ -12,7 +12,8 @@ import (
"sigs.k8s.io/kustomize/kyaml/copyutil"
)
const expectedHelm = `
const (
expectedHelm = `
apiVersion: v1
data:
rcon-password: Q0hBTkdFTUUh
@@ -46,6 +47,98 @@ spec:
type: ClusterIP
`
expectedHelmExternalDNS = `
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app.kubernetes.io/instance: test
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: external-dns
helm.sh/chart: external-dns-6.19.2
name: test-external-dns
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/instance: test
app.kubernetes.io/name: external-dns
template:
metadata:
annotations: null
labels:
app.kubernetes.io/instance: test
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: external-dns
helm.sh/chart: external-dns-6.19.2
spec:
affinity:
nodeAffinity: null
podAffinity: null
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
labelSelector:
matchLabels:
app.kubernetes.io/instance: test
app.kubernetes.io/name: external-dns
topologyKey: kubernetes.io/hostname
weight: 1
containers:
- args:
- --metrics-address=:7979
- --log-level=info
- --log-format=text
- --policy=upsert-only
- --provider=aws
- --registry=txt
- --interval=1m
- --source=service
- --source=ingress
- --aws-api-retries=3
- --aws-zone-type=
- --aws-batch-change-size=1000
env:
- name: AWS_DEFAULT_REGION
value: us-east-1
envFrom: null
image: docker.io/bitnami/external-dns:0.13.4-debian-11-r14
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 2
httpGet:
path: /healthz
port: http
initialDelaySeconds: 10
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
name: external-dns
ports:
- containerPort: 7979
name: http
readinessProbe:
failureThreshold: 6
httpGet:
path: /healthz
port: http
initialDelaySeconds: 5
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 5
resources:
limits: {}
requests: {}
volumeMounts: null
securityContext:
fsGroup: 1001
runAsUser: 1001
serviceAccountName: default
volumes: null
`
)
func TestHelmChartInflationGeneratorOld(t *testing.T) {
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t)
defer th.Reset()
@@ -84,6 +177,64 @@ helmCharts:
th.AssertActualEqualsExpected(m, expectedHelm)
}
func TestHelmChartInflationGeneratorWithOciRepository(t *testing.T) {
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t)
defer th.Reset()
if err := th.ErrIfNoHelm(); err != nil {
t.Skip("skipping: " + err.Error())
}
th.WriteK(th.GetRoot(), `
helmCharts:
- name: external-dns
repo: oci://registry-1.docker.io/bitnamicharts
version: 6.19.2
releaseName: test
valuesInline:
crd:
create: false
rbac:
create: false
serviceAccount:
create: false
service:
enabled: false
`)
m := th.Run(th.GetRoot(), th.MakeOptionsPluginsEnabled())
th.AssertActualEqualsExpected(m, expectedHelmExternalDNS)
}
func TestHelmChartInflationGeneratorWithOciRepositoryWithAppendSlash(t *testing.T) {
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t)
defer th.Reset()
if err := th.ErrIfNoHelm(); err != nil {
t.Skip("skipping: " + err.Error())
}
th.WriteK(th.GetRoot(), `
helmCharts:
- name: external-dns
repo: oci://registry-1.docker.io/bitnamicharts/
version: 6.19.2
releaseName: test
valuesInline:
crd:
create: false
rbac:
create: false
serviceAccount:
create: false
service:
enabled: false
`)
m := th.Run(th.GetRoot(), th.MakeOptionsPluginsEnabled())
th.AssertActualEqualsExpected(m, expectedHelmExternalDNS)
}
// Last mile helm - show how kustomize puts helm charts into different
// namespaces with different customizations.
func TestHelmChartProdVsDev(t *testing.T) {
@@ -416,6 +567,325 @@ metadata:
`)
}
// Reference: https://github.com/kubernetes-sigs/kustomize/issues/5163
func TestHelmChartInflationGeneratorForMultipleChartsDifferentVersion(t *testing.T) {
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t)
defer th.Reset()
if err := th.ErrIfNoHelm(); err != nil {
t.Skip("skipping: " + err.Error())
}
copyValuesFilesTestChartsIntoHarness(t, th)
th.WriteK(th.GetRoot(), `
namespace: default
helmCharts:
- name: test-chart
releaseName: test
version: 1.0.0
skipTests: true
- name: minecraft
repo: https://itzg.github.io/minecraft-server-charts
version: 3.1.3
releaseName: test-1
- name: minecraft
repo: https://itzg.github.io/minecraft-server-charts
version: 3.1.4
releaseName: test-2
`)
m := th.Run(th.GetRoot(), th.MakeOptionsPluginsEnabled())
th.AssertActualEqualsExpected(m, `
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
chart: test-1.0.0
name: my-deploy
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: test
template:
spec:
containers:
- image: test-image:v1.0.0
imagePullPolicy: Always
---
apiVersion: v1
data:
rcon-password: Q0hBTkdFTUUh
kind: Secret
metadata:
labels:
app: test-1-minecraft
chart: minecraft-3.1.3
heritage: Helm
release: test-1
name: test-1-minecraft
namespace: default
type: Opaque
---
apiVersion: v1
kind: Service
metadata:
labels:
app: test-1-minecraft
chart: minecraft-3.1.3
heritage: Helm
release: test-1
name: test-1-minecraft
namespace: default
spec:
ports:
- name: minecraft
port: 25565
protocol: TCP
targetPort: minecraft
selector:
app: test-1-minecraft
type: ClusterIP
---
apiVersion: v1
data:
rcon-password: Q0hBTkdFTUUh
kind: Secret
metadata:
labels:
app: test-2-minecraft
chart: minecraft-3.1.4
heritage: Helm
release: test-2
name: test-2-minecraft
namespace: default
type: Opaque
---
apiVersion: v1
kind: Service
metadata:
labels:
app: test-2-minecraft
chart: minecraft-3.1.4
heritage: Helm
release: test-2
name: test-2-minecraft
namespace: default
spec:
ports:
- name: minecraft
port: 25565
protocol: TCP
targetPort: minecraft
selector:
app: test-2-minecraft
type: ClusterIP
`)
}
func TestHelmChartInflationGeneratorForMultipleKubeVersions(t *testing.T) {
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t)
defer th.Reset()
if err := th.ErrIfNoHelm(); err != nil {
t.Skip("skipping: " + err.Error())
}
copyValuesFilesTestChartsIntoHarness(t, th)
th.WriteK(th.GetRoot(), `
namespace: default
helmCharts:
- name: minecraft
repo: https://itzg.github.io/minecraft-server-charts
version: 4.11.0
releaseName: test
kubeVersion: "1.16"
valuesInline:
minecraftServer:
extraPorts:
- name: map
containerPort: 8123
protocol: TCP
service:
enabled: false
ingress:
enabled: true
`)
m := th.Run(th.GetRoot(), th.MakeOptionsPluginsEnabled())
th.AssertActualEqualsExpected(m, `
apiVersion: v1
data:
rcon-password: Q0hBTkdFTUUh
kind: Secret
metadata:
labels:
app: test-minecraft
app.kubernetes.io/instance: test-minecraft
app.kubernetes.io/name: minecraft
app.kubernetes.io/version: 4.11.0
chart: minecraft-4.11.0
heritage: Helm
release: test
name: test-minecraft-rcon
namespace: default
type: Opaque
---
apiVersion: v1
data:
cf-api-key: Q0hBTkdFTUUh
kind: Secret
metadata:
labels:
app: test-minecraft
app.kubernetes.io/instance: test-minecraft
app.kubernetes.io/name: minecraft
app.kubernetes.io/version: 4.11.0
chart: minecraft-4.11.0
heritage: Helm
release: test
name: test-minecraft-curseforge
namespace: default
type: Opaque
---
apiVersion: v1
kind: Service
metadata:
labels:
app: test-minecraft
app.kubernetes.io/instance: test-minecraft
app.kubernetes.io/name: minecraft
app.kubernetes.io/version: 4.11.0
chart: minecraft-4.11.0
heritage: Helm
release: test
name: test-minecraft
namespace: default
spec:
ports:
- name: minecraft
port: 25565
protocol: TCP
targetPort: minecraft
selector:
app: test-minecraft
type: ClusterIP
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
labels:
app: test-minecraft-map
app.kubernetes.io/instance: test-minecraft
app.kubernetes.io/name: minecraft
app.kubernetes.io/version: 4.11.0
chart: minecraft-4.11.0
heritage: Helm
release: test
name: test-minecraft-map
namespace: default
spec:
rules: null
`)
th.WriteK(th.GetRoot(), `
namespace: default
helmCharts:
- name: minecraft
repo: https://itzg.github.io/minecraft-server-charts
version: 4.11.0
releaseName: test
kubeVersion: "1.27"
valuesInline:
minecraftServer:
extraPorts:
- name: map
containerPort: 8123
protocol: TCP
service:
enabled: false
ingress:
enabled: true
`)
m = th.Run(th.GetRoot(), th.MakeOptionsPluginsEnabled())
th.AssertActualEqualsExpected(m, `
apiVersion: v1
data:
rcon-password: Q0hBTkdFTUUh
kind: Secret
metadata:
labels:
app: test-minecraft
app.kubernetes.io/instance: test-minecraft
app.kubernetes.io/name: minecraft
app.kubernetes.io/version: 4.11.0
chart: minecraft-4.11.0
heritage: Helm
release: test
name: test-minecraft-rcon
namespace: default
type: Opaque
---
apiVersion: v1
data:
cf-api-key: Q0hBTkdFTUUh
kind: Secret
metadata:
labels:
app: test-minecraft
app.kubernetes.io/instance: test-minecraft
app.kubernetes.io/name: minecraft
app.kubernetes.io/version: 4.11.0
chart: minecraft-4.11.0
heritage: Helm
release: test
name: test-minecraft-curseforge
namespace: default
type: Opaque
---
apiVersion: v1
kind: Service
metadata:
labels:
app: test-minecraft
app.kubernetes.io/instance: test-minecraft
app.kubernetes.io/name: minecraft
app.kubernetes.io/version: 4.11.0
chart: minecraft-4.11.0
heritage: Helm
release: test
name: test-minecraft
namespace: default
spec:
ports:
- name: minecraft
port: 25565
protocol: TCP
targetPort: minecraft
selector:
app: test-minecraft
type: ClusterIP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
labels:
app: test-minecraft-map
app.kubernetes.io/instance: test-minecraft
app.kubernetes.io/name: minecraft
app.kubernetes.io/version: 4.11.0
chart: minecraft-4.11.0
heritage: Helm
release: test
name: test-minecraft-map
namespace: default
spec:
rules: null
`)
}
func copyValuesFilesTestChartsIntoHarness(t *testing.T, th *kusttest_test.HarnessEnhanced) {
t.Helper()

View File

@@ -6,7 +6,7 @@ package krusty_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
)
@@ -209,7 +209,7 @@ spec:
- image: whatever
`)
err := th.RunWithErr("gcp", th.MakeDefaultOptions())
assert.Error(t, err)
require.Error(t, err)
}
// Test for issue #3228

View File

@@ -8,11 +8,11 @@ import (
"log"
"sigs.k8s.io/kustomize/api/internal/builtins"
fLdr "sigs.k8s.io/kustomize/api/internal/loader"
pLdr "sigs.k8s.io/kustomize/api/internal/plugins/loader"
"sigs.k8s.io/kustomize/api/internal/target"
"sigs.k8s.io/kustomize/api/internal/utils"
"sigs.k8s.io/kustomize/api/konfig"
fLdr "sigs.k8s.io/kustomize/api/loader"
"sigs.k8s.io/kustomize/api/provenance"
"sigs.k8s.io/kustomize/api/provider"
"sigs.k8s.io/kustomize/api/resmap"

View File

@@ -6,8 +6,6 @@ package krusty_test
import (
"testing"
"github.com/stretchr/testify/assert"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
)
@@ -303,20 +301,15 @@ patchesStrategicMerge:
m = th.Run("overlay", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, expected)
// Technique 4: "patches:" field, one patch file. Fails.
// Technique 4: "patches:" field, one patch file.
th.WriteK("overlay", `
resources:
- ../base
patches:
- path: twoPatchesInOneFile.yaml
`)
err := th.RunWithErr("overlay", th.MakeDefaultOptions())
assert.Error(t, err)
// This should fail, because the semantics of the `patches` field.
// That field allows specific patch targeting to a list of targets,
// while the `patchesStrategicMerge` field accepts patches that
// implicitly identify their targets via GVKN.
assert.Contains(t, err.Error(), "unable to parse SM or JSON patch from ")
m = th.Run("overlay", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, expected)
}
func TestRemoveEmptyDirWithNullFieldInSmp(t *testing.T) {
@@ -1670,7 +1663,7 @@ spec:
template:
spec:
containers:
- image: fluentd:latest
- image: fluentd:latest
name: fluentd
serviceAccountName: fluentd-sa
---

View File

@@ -8,6 +8,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
"sigs.k8s.io/kustomize/kyaml/openapi"
"sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi"
@@ -264,7 +265,7 @@ openapi:
writeCustomResource(th, "mycrd.yaml")
writeTestSchema(th, "./")
err := th.RunWithErr(".", th.MakeDefaultOptions())
assert.Error(t, err)
require.Error(t, err)
assert.Equal(t,
"builtin version and custom schema provided, cannot use both",
err.Error())
@@ -284,7 +285,7 @@ openapi:
`+customSchemaPatch)
writeCustomResource(th, "mycrd.yaml")
err := th.RunWithErr(".", th.MakeDefaultOptions())
assert.Error(t, err)
require.Error(t, err)
assert.Equal(t,
"'/mycrd_schema.json' doesn't exist",
err.Error())

View File

@@ -9,6 +9,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"sigs.k8s.io/kustomize/api/internal/utils"
"sigs.k8s.io/kustomize/api/krusty"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
@@ -417,7 +418,7 @@ func TestAnnoOriginCustomExecGenerator(t *testing.T) {
o.PluginConfig.FnpLoadingOptions.EnableExec = true
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
require.NoError(t, err)
th.WriteK(tmpDir.String(), `
resources:
- short_secret.yaml
@@ -443,7 +444,7 @@ stringData:
`)
th.WriteF(filepath.Join(tmpDir.String(), "generateDeployment.sh"), generateDeploymentDotSh)
assert.NoError(t, os.Chmod(filepath.Join(tmpDir.String(), "generateDeployment.sh"), 0777))
require.NoError(t, os.Chmod(filepath.Join(tmpDir.String(), "generateDeployment.sh"), 0777))
th.WriteF(filepath.Join(tmpDir.String(), "gener.yaml"), `
kind: executable
metadata:
@@ -456,9 +457,9 @@ spec:
`)
m := th.Run(tmpDir.String(), o)
assert.NoError(t, err)
require.NoError(t, err)
yml, err := m.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, `apiVersion: v1
kind: Secret
metadata:
@@ -500,7 +501,7 @@ spec:
- image: nginx
name: nginx
`, string(yml))
assert.NoError(t, fSys.RemoveAll(tmpDir.String()))
require.NoError(t, fSys.RemoveAll(tmpDir.String()))
}
func TestAnnoOriginCustomInlineExecGenerator(t *testing.T) {
@@ -511,7 +512,7 @@ func TestAnnoOriginCustomInlineExecGenerator(t *testing.T) {
o.PluginConfig.FnpLoadingOptions.EnableExec = true
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
require.NoError(t, err)
th.WriteK(tmpDir.String(), `
resources:
- short_secret.yaml
@@ -544,11 +545,11 @@ stringData:
- mkdir /mnt/vda
`)
th.WriteF(filepath.Join(tmpDir.String(), "generateDeployment.sh"), generateDeploymentDotSh)
assert.NoError(t, os.Chmod(filepath.Join(tmpDir.String(), "generateDeployment.sh"), 0777))
require.NoError(t, os.Chmod(filepath.Join(tmpDir.String(), "generateDeployment.sh"), 0777))
m := th.Run(tmpDir.String(), o)
assert.NoError(t, err)
require.NoError(t, err)
yml, err := m.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, `apiVersion: v1
kind: Secret
metadata:
@@ -590,7 +591,7 @@ spec:
- image: nginx
name: nginx
`, string(yml))
assert.NoError(t, fSys.RemoveAll(tmpDir.String()))
require.NoError(t, fSys.RemoveAll(tmpDir.String()))
}
func TestAnnoOriginCustomExecGeneratorWithOverlay(t *testing.T) {
@@ -601,11 +602,11 @@ func TestAnnoOriginCustomExecGeneratorWithOverlay(t *testing.T) {
o.PluginConfig.FnpLoadingOptions.EnableExec = true
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
require.NoError(t, err)
base := filepath.Join(tmpDir.String(), "base")
prod := filepath.Join(tmpDir.String(), "prod")
assert.NoError(t, fSys.Mkdir(base))
assert.NoError(t, fSys.Mkdir(prod))
require.NoError(t, fSys.Mkdir(base))
require.NoError(t, fSys.Mkdir(prod))
th.WriteK(base, `
resources:
- short_secret.yaml
@@ -633,7 +634,7 @@ stringData:
`)
th.WriteF(filepath.Join(base, "generateDeployment.sh"), generateDeploymentDotSh)
assert.NoError(t, os.Chmod(filepath.Join(base, "generateDeployment.sh"), 0777))
require.NoError(t, os.Chmod(filepath.Join(base, "generateDeployment.sh"), 0777))
th.WriteF(filepath.Join(base, "gener.yaml"), `
kind: executable
metadata:
@@ -646,9 +647,9 @@ spec:
`)
m := th.Run(prod, o)
assert.NoError(t, err)
require.NoError(t, err)
yml, err := m.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, `apiVersion: v1
kind: Secret
metadata:
@@ -690,7 +691,7 @@ spec:
- image: nginx
name: nginx
`, string(yml))
assert.NoError(t, fSys.RemoveAll(tmpDir.String()))
require.NoError(t, fSys.RemoveAll(tmpDir.String()))
}
func TestAnnoOriginCustomInlineExecGeneratorWithOverlay(t *testing.T) {
@@ -701,11 +702,11 @@ func TestAnnoOriginCustomInlineExecGeneratorWithOverlay(t *testing.T) {
o.PluginConfig.FnpLoadingOptions.EnableExec = true
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
require.NoError(t, err)
base := filepath.Join(tmpDir.String(), "base")
prod := filepath.Join(tmpDir.String(), "prod")
assert.NoError(t, fSys.Mkdir(base))
assert.NoError(t, fSys.Mkdir(prod))
require.NoError(t, fSys.Mkdir(base))
require.NoError(t, fSys.Mkdir(prod))
th.WriteK(base, `
resources:
- short_secret.yaml
@@ -740,11 +741,11 @@ stringData:
- mkdir /mnt/vda
`)
th.WriteF(filepath.Join(base, "generateDeployment.sh"), generateDeploymentDotSh)
assert.NoError(t, os.Chmod(filepath.Join(base, "generateDeployment.sh"), 0777))
require.NoError(t, os.Chmod(filepath.Join(base, "generateDeployment.sh"), 0777))
m := th.Run(prod, o)
assert.NoError(t, err)
require.NoError(t, err)
yml, err := m.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, `apiVersion: v1
kind: Secret
metadata:
@@ -786,15 +787,15 @@ spec:
- image: nginx
name: nginx
`, string(yml))
assert.NoError(t, fSys.RemoveAll(tmpDir.String()))
require.NoError(t, fSys.RemoveAll(tmpDir.String()))
}
func TestAnnoOriginRemoteBuiltinGenerator(t *testing.T) {
fSys := filesys.MakeFsOnDisk()
b := krusty.MakeKustomizer(krusty.MakeDefaultOptions())
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "kustomization.yaml"), []byte(`
require.NoError(t, err)
require.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "kustomization.yaml"), []byte(`
resources:
- github.com/kubernetes-sigs/kustomize/examples/ldap/base/?ref=v1.0.6
buildMetadata: [originAnnotations]
@@ -810,7 +811,7 @@ buildMetadata: [originAnnotations]
t.FailNow()
}
yml, err := m.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Contains(t, string(yml), `kind: ConfigMap
metadata:
annotations:
@@ -822,7 +823,7 @@ metadata:
apiVersion: builtin
kind: ConfigMapGenerator
name: ldap-configmap-4d7m6k5b42`)
assert.NoError(t, fSys.RemoveAll(tmpDir.String()))
require.NoError(t, fSys.RemoveAll(tmpDir.String()))
}
func TestAnnoOriginInlineBuiltinGenerator(t *testing.T) {
@@ -1011,7 +1012,7 @@ func TestAnnoOriginGeneratorInTransformersField(t *testing.T) {
o.PluginConfig.FnpLoadingOptions.EnableExec = true
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
require.NoError(t, err)
th.WriteK(tmpDir.String(), `
transformers:
- gener.yaml
@@ -1020,7 +1021,7 @@ buildMetadata: [originAnnotations]
th.WriteF(filepath.Join(tmpDir.String(), "generateDeployment.sh"), generateDeploymentDotSh)
assert.NoError(t, os.Chmod(filepath.Join(tmpDir.String(), "generateDeployment.sh"), 0777))
require.NoError(t, os.Chmod(filepath.Join(tmpDir.String(), "generateDeployment.sh"), 0777))
th.WriteF(filepath.Join(tmpDir.String(), "gener.yaml"), `
kind: executable
metadata:
@@ -1033,9 +1034,9 @@ spec:
`)
m := th.Run(tmpDir.String(), o)
assert.NoError(t, err)
require.NoError(t, err)
yml, err := m.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, `apiVersion: apps/v1
kind: Deployment
metadata:
@@ -1062,7 +1063,7 @@ spec:
- image: nginx
name: nginx
`, string(yml))
assert.NoError(t, fSys.RemoveAll(tmpDir.String()))
require.NoError(t, fSys.RemoveAll(tmpDir.String()))
}
func TestAnnoOriginGeneratorInTransformersFieldWithOverlay(t *testing.T) {
@@ -1073,11 +1074,11 @@ func TestAnnoOriginGeneratorInTransformersFieldWithOverlay(t *testing.T) {
o.PluginConfig.FnpLoadingOptions.EnableExec = true
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
require.NoError(t, err)
base := filepath.Join(tmpDir.String(), "base")
prod := filepath.Join(tmpDir.String(), "prod")
assert.NoError(t, fSys.Mkdir(base))
assert.NoError(t, fSys.Mkdir(prod))
require.NoError(t, fSys.Mkdir(base))
require.NoError(t, fSys.Mkdir(prod))
th.WriteK(base, `
transformers:
@@ -1086,7 +1087,7 @@ transformers:
th.WriteF(filepath.Join(base, "generateDeployment.sh"), generateDeploymentDotSh)
assert.NoError(t, os.Chmod(filepath.Join(base, "generateDeployment.sh"), 0777))
require.NoError(t, os.Chmod(filepath.Join(base, "generateDeployment.sh"), 0777))
th.WriteF(filepath.Join(base, "gener.yaml"), `
kind: executable
metadata:
@@ -1105,9 +1106,9 @@ buildMetadata: [originAnnotations, transformerAnnotations]
`)
m := th.Run(prod, o)
assert.NoError(t, err)
require.NoError(t, err)
yml, err := m.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, `apiVersion: apps/v1
kind: Deployment
metadata:
@@ -1139,5 +1140,5 @@ spec:
- image: nginx
name: nginx
`, string(yml))
assert.NoError(t, fSys.RemoveAll(tmpDir.String()))
require.NoError(t, fSys.RemoveAll(tmpDir.String()))
}

View File

@@ -16,10 +16,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"sigs.k8s.io/kustomize/api/internal/loader"
"sigs.k8s.io/kustomize/api/krusty"
"sigs.k8s.io/kustomize/api/loader"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/kyaml/filesys"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
@@ -28,6 +28,7 @@ func TestRemoteLoad_LocalProtocol(t *testing.T) {
root string
simple string
noSuffix string
hash string
multiBaseDev string
withSubmodule string
}
@@ -36,9 +37,10 @@ func TestRemoteLoad_LocalProtocol(t *testing.T) {
// root/
// simple.git/ - base with just a pod
// nosuffix/ - same as simple.git/ without the .git suffix
// hash-xx/ - same as simple.git/ with random hash at xx
// multibase.git/ - base with a dev overlay
// with-submodule.git/ - includes `simple` as a submodule
// submodule/ - the submodule referencing `simple
// submodule/ - the submodule referencing `simple`
createGitRepos := func(t *testing.T) testRepos {
t.Helper()
@@ -50,10 +52,16 @@ func TestRemoteLoad_LocalProtocol(t *testing.T) {
}
}
root := t.TempDir()
hashPath, err := os.MkdirTemp(root, "hash-")
require.NoError(t, err)
hashDir := filepath.Base(hashPath)
bash(fmt.Sprintf(`
set -eux
export ROOT="%s"
export HASH_DIR="%s"
export GIT_AUTHOR_EMAIL=nobody@kustomize.io
export GIT_AUTHOR_NAME=Nobody
export GIT_COMMITTER_EMAIL=nobody@kustomize.io
@@ -85,19 +93,27 @@ cp -r testdata/remoteload/multibase $ROOT/multibase.git
git add .
git commit -m "import"
)
cp -r testdata/remoteload/with-submodule $ROOT/with-submodule.git # see README
cp -r $ROOT/simple.git/. $ROOT/$HASH_DIR
(
mkdir $ROOT/with-submodule.git
cd $ROOT/with-submodule.git
git init --initial-branch=main
git submodule add $ROOT/simple.git submodule
git add .
git commit -m "import"
git checkout -b relative-submodule
git submodule add ../$HASH_DIR submodule
git commit -m "relative submodule"
git checkout main
git submodule add $ROOT/simple.git submodule
git commit -m "submodule"
)
`, root))
`, root, hashDir))
return testRepos{
root: root,
// The strings below aren't currently used, and more serve as documentation.
simple: "simple.git",
noSuffix: "nosuffix",
hash: hashDir,
multiBaseDev: "multibase.git",
withSubmodule: "with-submodule.git",
}
@@ -183,6 +199,15 @@ resources:
`,
expected: simpleBuild,
},
{
name: "has relative submodule",
kustomization: `
resources:
- file://$ROOT/with-submodule.git/submodule?ref=relative-submodule
`,
expected: simpleBuild,
},
{
name: "has timeout",
kustomization: `
@@ -264,7 +289,7 @@ resources:
}
kust := strings.ReplaceAll(test.kustomization, "$ROOT", repos.root)
fSys, tmpDir := createKustDir(t, kust)
fSys, tmpDir := kusttest_test.CreateKustDir(t, kust)
b := krusty.MakeKustomizer(krusty.MakeDefaultOptions())
m, err := b.Run(
@@ -273,7 +298,7 @@ resources:
if test.err != "" {
require.Error(t, err)
require.Contains(t, err.Error(), test.err)
require.Regexp(t, test.err, err.Error())
} else {
require.NoError(t, err)
checkYaml(t, m, strings.ReplaceAll(test.expected, "$ROOT", repos.root))
@@ -368,7 +393,7 @@ resources:
if test.beforeTest != nil {
test.beforeTest(t)
}
fSys, tmpDir := createKustDir(t, test.kustomization)
fSys, tmpDir := kusttest_test.CreateKustDir(t, test.kustomization)
b := krusty.MakeKustomizer(krusty.MakeDefaultOptions())
m, err := b.Run(
@@ -379,7 +404,7 @@ resources:
require.Error(t, err)
assert.Contains(t, err.Error(), test.err)
if test.errT != nil {
assert.ErrorIs(t, err, test.errT)
require.ErrorIs(t, err, test.errT)
}
} else {
require.NoError(t, err)
@@ -424,20 +449,10 @@ func configureGitSSHCommand(t *testing.T) {
})
}
func createKustDir(t *testing.T, content string) (filesys.FileSystem, filesys.ConfirmedDir) {
t.Helper()
fSys := filesys.MakeFsOnDisk()
tmpDir, err := filesys.NewTmpConfirmedDir()
require.NoError(t, err)
require.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "kustomization.yaml"), []byte(content)))
return fSys, tmpDir
}
func checkYaml(t *testing.T, actual resmap.ResMap, expected string) {
t.Helper()
yml, err := actual.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, expected, string(yml))
}

View File

@@ -546,3 +546,71 @@ metadata:
name: red-dc6gc5btkc
`)
}
func TestReplacementTransformerWithSuffixTransformerAndReject(t *testing.T) {
th := kusttest_test.MakeEnhancedHarness(t)
defer th.Reset()
th.WriteF("base/app.yaml", `
apiVersion: apps/v1
kind: Deployment
metadata:
name: original-name
spec:
template:
spec:
containers:
- image: app1:1.0
name: app
`)
th.WriteK("base", `
resources:
- app.yaml
`)
th.WriteK("overlay", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
nameSuffix: -dev
resources:
- ../base
configMapGenerator:
- name: app-config
literals:
- name=something-else
replacements:
- source:
kind: ConfigMap
name: app-config
fieldPath: data.name
targets:
- fieldPaths:
- spec.template.spec.containers.0.name
select:
kind: Deployment
reject:
- name: original-name
`)
m := th.Run("overlay", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: apps/v1
kind: Deployment
metadata:
name: original-name-dev
spec:
template:
spec:
containers:
- image: app1:1.0
name: app
---
apiVersion: v1
data:
name: something-else
kind: ConfigMap
metadata:
name: app-config-dev-97544dk6t8
`)
}

View File

@@ -0,0 +1,10 @@
# submodule
This repo demonstrates kustomize's ability to download git repos
with submodules. The following branches contain
* main: submodule via absolute path
* relative-submodule: submodule via relative path
For the submodule accessed via a relative path, we include a random hash in the
submodule name to avoid accessing an unintended directory in the case kustomize
contains loader bugs (issue #5131).

View File

@@ -9,6 +9,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"sigs.k8s.io/kustomize/api/internal/utils"
"sigs.k8s.io/kustomize/api/krusty"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
@@ -261,8 +262,8 @@ func TestAnnoOriginRemoteBuiltinTransformer(t *testing.T) {
fSys := filesys.MakeFsOnDisk()
b := krusty.MakeKustomizer(krusty.MakeDefaultOptions())
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "kustomization.yaml"), []byte(`
require.NoError(t, err)
require.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "kustomization.yaml"), []byte(`
resources:
- github.com/kubernetes-sigs/kustomize/examples/multibases/production/?ref=v1.0.6
buildMetadata: [transformerAnnotations]
@@ -278,7 +279,7 @@ buildMetadata: [transformerAnnotations]
t.FailNow()
}
yml, err := m.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, `apiVersion: v1
kind: Pod
metadata:
@@ -298,7 +299,7 @@ spec:
- image: nginx:1.7.9
name: nginx
`, string(yml))
assert.NoError(t, fSys.RemoveAll(tmpDir.String()))
require.NoError(t, fSys.RemoveAll(tmpDir.String()))
}
func TestAnnoTransformerBuiltinInline(t *testing.T) {
@@ -356,7 +357,7 @@ func TestAnnoOriginCustomInlineTransformer(t *testing.T) {
o.PluginConfig.FnpLoadingOptions.EnableExec = true
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
require.NoError(t, err)
th.WriteK(tmpDir.String(), `
transformers:
- |-
@@ -375,7 +376,7 @@ buildMetadata: [transformerAnnotations]
// which will cause kustomize to record the plugin origin data as a transformation
th.WriteF(filepath.Join(tmpDir.String(), "generateDeployment.sh"), generateDeploymentWithOriginDotSh)
assert.NoError(t, os.Chmod(filepath.Join(tmpDir.String(), "generateDeployment.sh"), 0777))
require.NoError(t, os.Chmod(filepath.Join(tmpDir.String(), "generateDeployment.sh"), 0777))
th.WriteF(filepath.Join(tmpDir.String(), "gener.yaml"), `
kind: executable
metadata:
@@ -388,9 +389,9 @@ spec:
`)
m := th.Run(tmpDir.String(), o)
assert.NoError(t, err)
require.NoError(t, err)
yml, err := m.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, `apiVersion: apps/v1
kind: Deployment
metadata:
@@ -417,7 +418,7 @@ spec:
- image: nginx
name: nginx
`, string(yml))
assert.NoError(t, fSys.RemoveAll(tmpDir.String()))
require.NoError(t, fSys.RemoveAll(tmpDir.String()))
}
func TestAnnoOriginCustomExecTransformerWithOverlay(t *testing.T) {
@@ -428,11 +429,11 @@ func TestAnnoOriginCustomExecTransformerWithOverlay(t *testing.T) {
o.PluginConfig.FnpLoadingOptions.EnableExec = true
tmpDir, err := filesys.NewTmpConfirmedDir()
assert.NoError(t, err)
require.NoError(t, err)
base := filepath.Join(tmpDir.String(), "base")
prod := filepath.Join(tmpDir.String(), "prod")
assert.NoError(t, fSys.Mkdir(base))
assert.NoError(t, fSys.Mkdir(prod))
require.NoError(t, fSys.Mkdir(base))
require.NoError(t, fSys.Mkdir(prod))
th.WriteK(base, `
transformers:
- gener.yaml
@@ -455,12 +456,12 @@ spec:
// generateDeploymentWithOriginDotSh creates a resource that already has an origin annotation,
// which will cause kustomize to record the plugin origin data as a transformation
th.WriteF(filepath.Join(base, "generateDeployment.sh"), generateDeploymentWithOriginDotSh)
assert.NoError(t, os.Chmod(filepath.Join(base, "generateDeployment.sh"), 0777))
require.NoError(t, os.Chmod(filepath.Join(base, "generateDeployment.sh"), 0777))
m := th.Run(prod, o)
assert.NoError(t, err)
require.NoError(t, err)
yml, err := m.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, `apiVersion: apps/v1
kind: Deployment
metadata:
@@ -487,5 +488,5 @@ spec:
- image: nginx
name: nginx
`, string(yml))
assert.NoError(t, fSys.RemoveAll(tmpDir.String()))
require.NoError(t, fSys.RemoveAll(tmpDir.String()))
}

View File

@@ -377,7 +377,8 @@ spec:
th.WriteF("base/config/knative.yaml", `
images:
- path: spec/runLatest/configuration/revisionTemplate/spec/container/image
apiVersion: serving.knative.dev/v1alpha1
group: serving.knative.dev
version: v1alpha1
kind: Service
`)
}

Some files were not shown because too many files have changed in this diff Show More