Compare commits

...

408 Commits

Author SHA1 Message Date
Kubernetes Prow Robot
be024c92ba Merge pull request #6065 from koba1t/pinToKyaml
Update kyaml to v0.21.1
2026-02-09 21:07:25 +05:30
koba1t
bb26a70573 Update kyaml to v0.21.1 2026-02-10 00:27:48 +09:00
Kubernetes Prow Robot
798d339d10 Merge pull request #6044 from koba1t/fix/namespace_propagation_problem_at_v5.8.0
Fix namespace propagation problem at v5.8.0
2026-02-09 07:21:09 +05:30
Kubernetes Prow Robot
6c8c9cc0e8 Merge pull request #6016 from hmilkovi/fix/helm-4.0
fix: support helm v4 beside v3
2026-02-05 07:02:29 +05:30
Kubernetes Prow Robot
02d23d21f0 Merge pull request #6057 from dims/remove-pkg-errors-dep
Upgrade json-patch to v4.13.0 to remove pkg/errors dependency
2026-02-05 06:18:29 +05:30
Hrvoje Milković
c6ccb4f208 Merge branch 'kubernetes-sigs:master' into fix/helm-4.0 2026-02-04 20:40:03 +01:00
hmilkovi
54848c1049 fix: support helm v4 beside v3 and remove -c flag for helm version as it does nothing
features.
2026-02-04 20:27:15 +01:00
Davanum Srinivas
297f2b59bb Upgrade json-patch to v4.13.0 to remove pkg/errors dependency
The github.com/pkg/errors package is unmaintained and archived.
It was pulled in as a transitive dependency through json-patch v4.12.0.
Upgrading to v4.13.0 removes this dependency while maintaining API
compatibility.

json-patch commit: evanphx/json-patch@106306d

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2026-02-04 14:14:37 -05:00
koba1t
7e45799272 rename to helmRootNamespace 2026-01-13 08:13:23 +09:00
koba1t
4e75138d24 fix: apply namespace propagation for helmCharts only 2026-01-13 08:09:14 +09:00
koba1t
a397f5b491 add tests for regression 2026-01-03 03:27:12 +09:00
Kubernetes Prow Robot
008b7a0c47 Merge pull request #6038 from tsuzu/fix-test-error
Fix a failing test
2025-12-29 00:56:33 +05:30
Tsuzu
6d7267f345 Fix a failing test 2025-12-22 00:11:48 +09:00
Kubernetes Prow Robot
17a06a72be Merge pull request #6020 from koba1t/chore/parallelizing_tests
CI: parallelizing tests
2025-11-26 08:24:37 -08:00
koba1t
e6621df4d5 add aggregation job for all matrix released module tests to define a branch protection rule 2025-11-26 07:07:16 +09:00
koba1t
77cf6d6b88 CI: parallelizing tests 2025-11-26 07:07:13 +09:00
Kubernetes Prow Robot
95a6f1fec3 Merge pull request #6023 from kubernetes-sigs/dependabot/github_actions/actions/checkout-6
build(deps): bump actions/checkout from 5 to 6
2025-11-25 14:02:36 -08:00
dependabot[bot]
c79a356bb2 build(deps): bump actions/checkout from 5 to 6
Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6.
- [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/v5...v6)

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

Signed-off-by: dependabot[bot] <support@github.com>
2025-11-24 00:02:17 +00:00
Kubernetes Prow Robot
311dbbf975 Merge pull request #5990 from ralgozino/fix/allow-empty-strategicmerge-patches-files
fix: allow empty patches files
2025-11-19 13:12:00 -08:00
Kubernetes Prow Robot
77b3446b36 Merge pull request #6010 from koba1t/unpinEverything
Back to development mode; unpin the modules
2025-11-10 02:30:56 -08:00
koba1t
764ad39d1d Back to development mode; unpin the modules 2025-11-10 00:04:26 +09:00
Kubernetes Prow Robot
0054b5e296 Merge pull request #6009 from koba1t/pinToApi
Update api to v0.21.0
2025-11-09 06:38:52 -08:00
koba1t
16391f3dbe Update api to v0.21.0 2025-11-09 23:29:30 +09:00
Kubernetes Prow Robot
6661fefabc Merge pull request #6008 from koba1t/pinToCmdConfig
Update cmd/config to v0.21.0
2025-11-09 06:12:52 -08:00
koba1t
3c59244887 Update cmd/config to v0.21.0 2025-11-09 23:02:27 +09:00
Kubernetes Prow Robot
ade7bd609f Merge pull request #6007 from koba1t/pinToKyaml
Update kyaml to v0.21.0
2025-11-09 05:56:52 -08:00
koba1t
0fc75546f1 Update kyaml to v0.21.0 2025-11-09 22:45:40 +09:00
Joseph Cumines
87617912bf fix(kyaml/yaml): minor nil safety fix for RNode.Content etc (#5985)
* Fix kyaml/yaml field access deref nil value for methods that look "nil-safe"

This change is addressing observed panics within kustomize that obscure the
actual failure. The primary observed problem case involves RNode.Content.

* Fix test case

* Fixes from review
2025-11-02 18:34:07 -08:00
Kubernetes Prow Robot
153a37286d Merge pull request #5679 from koba1t/implements_to_replacements_value_in_the_structured_data
implements to replacements value in the structured data
2025-10-24 20:15:34 -07:00
Kubernetes Prow Robot
de011378a4 Merge pull request #5991 from isarns/fix/labels-without-selector-duplicate-key-error
Fix duplicate key error when adding multiple labels with --without-selector
2025-10-12 19:36:54 -07:00
isarns
4d37afef6f style(cmd-edit-add-label): lint multiple labels without selector test 2025-10-12 18:04:33 +03:00
isarns
f71e4d7309 style(cmd-edit-add-label): lint multiple labels without selector test 2025-10-12 12:34:00 +03:00
isarns
d427f61f84 test(cmd-edit-add-label): add multiple labels without selector test 2025-10-12 12:08:34 +03:00
isarns
9df8bbdc44 fix(cmd-edit-add-label): dubplicate key error 2025-10-05 19:33:51 +03:00
Ramiro Algozino
24ea1b951a fix(kustomize): call json6902 only when needed
Call json6902 transformer only when there are patches to apply.

Addresses #5956
2025-10-02 19:51:09 +02:00
Ramiro Algozino
68fa5177e2 chore: add test for empty patches files
Add test to validate that empty files don't produce an error when using
the `path` option of the `patches` convenience.

Add test to validate that using the deprecated patchesStrategicMerge
still produces an error and no changes have been introduced in old
features.
2025-10-02 19:15:00 +02:00
koba1t
2a1862d8b7 fix nit 2025-09-30 06:48:35 +09:00
Niklas Wagner
278dd6e55d fix: performance recession when propagating namespace to helm (#5971)
* fix: performance recession when propagating namespace to helm

* fix: handle passing namespace downstream more elegant

* Revert "fix: handle passing namespace downstream more elegant"

This reverts commit 976a7cf2aa.

* Revert "fix: performance recession when propagating namespace to helm"

This reverts commit c7612d1dba.

* fix: use annotation to identify helm chart generated resources

* fix: deduplicate code

* fix: missing import in NamespaceTransformer.go

* ci: allow manual trigger of pipeline in fork

* Revert "ci: allow manual trigger of pipeline in fork"

This reverts commit 8948788fe2.

* fix: test cases

* chore: fix code comment was on wrong line

* chore: fix code comment was on wrong line pt2
2025-09-29 14:08:19 -07:00
Kubernetes Prow Robot
b62d746b80 Merge pull request #5942 from totegamma/master
fix fnplugin storagemounts validation
2025-09-29 12:06:17 -07:00
Kubernetes Prow Robot
ab48be3747 Merge pull request #5984 from stormqueen1990/patch-2
Step down as reviewer for kustomize
2025-09-28 12:10:16 -07:00
Mauren
e5bb51847d Step down as reviewer for kustomize
Remove myself from the OWNERS_ALIASES file as I am stepping down from being a reviewer in kustomize for the time being.
2025-09-14 17:00:00 -04:00
Kubernetes Prow Robot
1a988bbed5 Merge pull request #5982 from kubernetes-sigs/dependabot/github_actions/actions/setup-go-6
build(deps): bump actions/setup-go from 5 to 6
2025-09-12 16:52:14 -07:00
totegamma
4bdc3f3f7e add test for plugin loader 2025-09-11 21:40:16 +09:00
dependabot[bot]
66c1478c1b build(deps): bump actions/setup-go from 5 to 6
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 5 to 6.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/v5...v6)

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

Signed-off-by: dependabot[bot] <support@github.com>
2025-09-08 00:02:24 +00:00
koba1t
bbe53c2c45 implements nested structure replacements 2025-09-05 19:37:24 +09:00
Kubernetes Prow Robot
cd30471046 Merge pull request #5963 from koba1t/chore/introduce_go_tool_directive
introduce go tool directive
2025-08-27 17:43:10 -07:00
koba1t
2dc0d0da8b implements to replacements value in the structured data 2025-08-28 04:44:52 +09:00
koba1t
5fd7b14fc8 update releasing/README.md to use
Helps when you have a git repository with multiple Go modules.

It handles tasks one might otherwise attempt with

'''
find ./ -name "go.mod" | xargs {some hack}
'''

Run it from a git repository root.

It walks the repository, reads 'go.mod' files, builds
a model of Go modules and intra-repo module
dependencies, then performs some operation.

Install:
'''
go get sigs.k8s.io/kustomize/cmd/gorepomod
'''

_Commands that change things (everything but 'list')
do nothing but log commands
unless you add the '--doIt' flag,
allowing the change._

_If you want to run 'gorepomod' on your fork or outside of '$GOSRC' directory, add '--local'  flag to your command._

Lists modules and intra-repo dependencies.

Use this to get module names for use in other commands.

Creates a change with mechanical updates
to 'go.mod' and 'go.sum' files.

Creates a change to 'go.mod' files.

For each module _m_ in the repository,
if _m_ depends on a _{module}_, then
_m_'s dependency on _{module} will be
replaced by a relative path to the in-repo
version of _{module}_.

If _conditionalModule_ is specified, then
the replacement of _{module}_ will happen
if _m_ depends on _{conditionalModule}_.

Creates a change to 'go.mod' files.

The opposite of 'unpin'.

The change removes replacements and pins _m_ to a
specific, previously tagged and released version of _{module}_.

The argument _{version}_ defaults to recent version of _{module}_.

_{version}_ should be in semver form, e.g. 'v1.2.3'.

Computes a new version for the module, tags the repo
with that version, and pushes the tag to the remote.

The value of the 2nd argument, either 'patch' (the default),
'minor' or 'major', determines the new version.

If the existing version is _v1.2.7_, then the new version will be:
 - 'patch' -> _v1.2.8_
 - 'minor' -> _v1.3.0_
 - 'major' -> _v2.0.0_

After establishing the version, the command looks for a branch named

> _release-{module}/-v{major}.{minor}_

If the branch doesn't exist, the command creates it and pushes it to the remote.

The command then creates a new tag in the form

> _{module}/v{major}.{minor}.{patch}_

The command pushes this tag to the remote.  This typically triggers
cloud activity to create release artifacts.

This undoes the work of 'release', by deleting the
most recent tag both locally and at the remote.

You can then fix whatever, and re-release.

This, however, must be done almost immediately.

If there's a chance someone (or some cloud robot) already
imported the module at the given tag, then don't do this,
because it will confuse module caches.

Do a new patch release instead. instead of
2025-08-28 02:54:33 +09:00
koba1t
b472396d10 introduce go tool directive 2025-08-28 02:36:10 +09:00
Kubernetes Prow Robot
39086340ad Merge pull request #5967 from seipan/fix/url-encode
Fix infinite loop in HTTP client by validating URLs before requests
2025-08-24 12:13:06 -07:00
Kubernetes Prow Robot
4468c8c9c7 Merge pull request #5970 from stormqueen1990/deps/go-viper-mapstructure
build(deps): bump github.com/go-viper/mapstructure/v2 from v2.3.0 to v2.4.0
2025-08-24 02:51:06 -07:00
Mauren Berti
05fa95ea95 build(deps): bump github.com/go-viper/mapstructure/v2 from v2.3.0 to v2.4.0 2025-08-23 14:48:29 -04:00
Kubernetes Prow Robot
1c0f1bf5ac Merge pull request #5940 from Skaronator/propagate-namespaces
fix: Propagate Namespace correctly to Helm
2025-08-21 04:07:05 -07:00
seipan
2a79ea148d fix: url.ParseRequestURI before http.Get
Signed-off-by: seipan <yamasakipann0218@gmail.com>
2025-08-21 17:18:00 +09:00
Kubernetes Prow Robot
11f9435b50 Merge pull request #5962 from koba1t/chore/update_dependencies_from_security_alert
chore: update dependencies from security alert
2025-08-18 09:45:08 -07:00
Kubernetes Prow Robot
b97b705232 Merge pull request #5964 from kubernetes-sigs/dependabot/github_actions/actions/checkout-5
build(deps): bump actions/checkout from 4 to 5
2025-08-18 06:29:12 -07:00
dependabot[bot]
efbd2a6ef1 build(deps): bump actions/checkout from 4 to 5
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5.
- [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/v4...v5)

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

Signed-off-by: dependabot[bot] <support@github.com>
2025-08-18 00:31:49 +00:00
koba1t
e68c754cce bump github.com/go-viper/mapstructure/v2 from 2.2.1 to 2.3.0 in /cmd/gorepomod 2025-08-18 06:32:36 +09:00
koba1t
c8d3d5709e bump github.com/go-git/go-git/v5 from 5.11.0 to 5.13.0 2025-08-18 06:30:17 +09:00
Kubernetes Prow Robot
ffcda0158e Merge pull request #5961 from koba1t/refactor/nested_format_string
refactor: nested format string
2025-08-17 14:27:07 -07:00
koba1t
785fce97df refactor: nested format string 2025-08-18 06:16:24 +09:00
Kubernetes Prow Robot
caa42b7125 Merge pull request #5960 from stormqueen1990/deps/golang-oauth
build(deps): bump golang.org/x/oauth2 from 0.25.0 to 0.27.0
2025-08-17 14:01:07 -07:00
Mauren Berti
c9a0d10d5a build(deps): bump golang.org/x/oauth2 from 0.25.0 to 0.27.0 2025-08-17 16:20:00 -04:00
yugo kobayashi
87d0629bd1 update go 1.24.6 (#5959)
* update go 1.24.6

* fix non-constant format string error

* update golang.org/x/tools@v0.36.0 and github.com/golangci/golangci-lint@v1.64.8 to pass execute golangci-lint

* add a verpose diff output to prow test

* remove pluginator binary version from generated files
2025-08-17 13:05:12 -07:00
Kubernetes Prow Robot
b581903858 Merge pull request #5958 from adoramshoval/resource-absorbtion-error-verbosity
fix: make AbsorbAll conflict error more verbose
2025-08-16 15:43:07 -07:00
Adoram Shoval
d54e9b2b40 fix: make AbsorbAll conflict error more verbose 2025-08-16 08:09:17 -04:00
Niklas Wagner
75839a81b3 fix: namespace is not correctly propagate with nested kustomization files 2025-08-12 22:46:22 +02:00
zepard
7c04cbb237 Add regex support for Replacement selectors (#5863)
* feat: Add regex support for Replacement selectors

* Add new tests for regex support

* Earlier exit with rejectAny, and fix linting

* Add example Use cases using regex
2025-08-12 11:13:08 -07:00
Kubernetes Prow Robot
f74736130c Merge pull request #5930 from adoramshoval/patch-args
feat: add PatchArgs API type to populate patch options
2025-08-11 13:49:07 -07:00
Adoram Shoval
9043c223d4 feat: add PatchArgs API type to populate patch options
This commit converts the Options section of a patch into an object instead of map.
This allows better clarification of the available options.
2025-08-08 07:34:20 -04:00
Kubernetes Prow Robot
2859474e3c Merge pull request #5951 from koba1t/unpinEverything
Back to development mode; unpin the modules
2025-07-23 06:06:30 -07:00
koba1t
d0d64c5bc4 Back to development mode; unpin the modules 2025-07-23 21:55:58 +09:00
Kubernetes Prow Robot
168971a501 Merge pull request #5950 from koba1t/pinToApi
Update api to v0.20.1
2025-07-23 05:44:29 -07:00
koba1t
0c3ce2c8fb Update api to v0.20.1 2025-07-23 21:34:51 +09:00
Kubernetes Prow Robot
8b42cd9918 Merge pull request #5949 from koba1t/pinToCmdConfig
Update cmd/config to v0.20.1
2025-07-23 05:30:29 -07:00
koba1t
5b313f57c4 Update cmd/config to v0.20.1 2025-07-23 21:20:57 +09:00
Kubernetes Prow Robot
792b241a4a Merge pull request #5948 from koba1t/pinToKyaml
Update kyaml to v0.20.1
2025-07-23 05:18:27 -07:00
koba1t
8192ab34ee Update kyaml to v0.20.1 2025-07-23 21:09:58 +09:00
Kubernetes Prow Robot
87f462af25 Merge pull request #5943 from koba1t/chore/drop_shlex_dependency
drop shlex dependency
2025-07-20 12:50:25 -07:00
koba1t
3866a30826 introduce one const value that indicate to no quote in ShlexSplit() 2025-07-14 20:12:00 +09:00
koba1t
5cb1b4e3f9 remove shlex dependencies 2025-07-14 03:57:51 +09:00
koba1t
b6128950c9 add ShlexSplit() as an alternative to shlex.Split() 2025-07-14 03:54:29 +09:00
koba1t
042a2cf177 add testcases for shlexsplit 2025-07-12 07:14:17 +09:00
totegamma
e115ba6240 fix fnplugin storagemounts validation 2025-07-10 22:08:22 +09:00
Niklas Wagner
9376a5c4b7 Propagate Namespace correctly to Helm 2025-07-08 19:24:46 +02:00
Kubernetes Prow Robot
f9ab532a4a Merge pull request #5937 from koba1t/unpinEverything
Back to development mode; unpin the modules
2025-06-28 00:24:29 -07:00
koba1t
76eb28bad9 Back to development mode; unpin the modules 2025-06-28 16:13:29 +09:00
Kubernetes Prow Robot
7f30f0e23a Merge pull request #5936 from koba1t/pinToApi
Update api to v0.20.0
2025-06-27 23:56:29 -07:00
koba1t
35c9d0fece Update api to v0.20.0 2025-06-28 15:46:34 +09:00
Kubernetes Prow Robot
b1bfac465f Merge pull request #5935 from koba1t/pinToCmdConfig
Update cmd/config to v0.20.0
2025-06-27 23:40:29 -07:00
koba1t
40d1f35940 Update cmd/config to v0.20.0 2025-06-28 15:29:37 +09:00
Kubernetes Prow Robot
1a515925ab Merge pull request #5934 from koba1t/pinToKyaml
Update kyaml to v0.20.0
2025-06-27 23:26:29 -07:00
koba1t
f54b2b4c59 Update kyaml to v0.20.0 2025-06-28 15:16:16 +09:00
Kubernetes Prow Robot
03ae5c93ca Merge pull request #5846 from dmvolod/issue-5845-fix-version
fix: Get version from the BuildInfo.Main.Version if not found in deps and build flag
2025-06-26 14:40:29 -07:00
Kubernetes Prow Robot
0fe722e99a Merge pull request #5931 from dims/drop-usage-of-forked-copies-of-goyaml.v2-and-goyaml.v3
Drop usage of forked copies of goyaml.v2 and goyaml.v3
2025-06-25 10:58:29 -07:00
Davanum Srinivas
a7703f685c Drop usage of forked copies of goyaml.v2 and goyaml.v3
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2025-06-25 13:13:52 -04:00
Kubernetes Prow Robot
ba617e5126 Merge pull request #5921 from ThisIsQasim/imagevolume
feat: Add suport for Image Volumes
2025-06-24 14:10:28 -07:00
Kubernetes Prow Robot
755880462f Merge pull request #5918 from kubernetes-sigs/dependabot/github_actions/joelanford/go-apidiff-0.8.3
build(deps): bump joelanford/go-apidiff from 0.8.2 to 0.8.3
2025-06-10 16:48:55 -07:00
Kubernetes Prow Robot
832f873855 Merge pull request #5927 from kubernetes-sigs/dependabot/go_modules/hack/github.com/cloudflare/circl-1.6.1
build(deps): bump github.com/cloudflare/circl from 1.3.7 to 1.6.1 in /hack
2025-06-10 16:20:56 -07:00
dependabot[bot]
731ffd3d53 build(deps): bump github.com/cloudflare/circl in /hack
Bumps [github.com/cloudflare/circl](https://github.com/cloudflare/circl) from 1.3.7 to 1.6.1.
- [Release notes](https://github.com/cloudflare/circl/releases)
- [Commits](https://github.com/cloudflare/circl/compare/v1.3.7...v1.6.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
2025-06-10 21:23:16 +00:00
ThisIsQasim
32e82514a8 feat: Add suport for Image Volume 2025-06-02 16:22:11 +05:00
dependabot[bot]
13ed4a59f5 build(deps): bump joelanford/go-apidiff from 0.8.2 to 0.8.3
Bumps [joelanford/go-apidiff](https://github.com/joelanford/go-apidiff) from 0.8.2 to 0.8.3.
- [Release notes](https://github.com/joelanford/go-apidiff/releases)
- [Commits](https://github.com/joelanford/go-apidiff/compare/v0.8.2...v0.8.3)

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

Signed-off-by: dependabot[bot] <support@github.com>
2025-05-26 00:31:28 +00:00
Kubernetes Prow Robot
b7340bd369 Merge pull request #5882 from arthurbdiniz/set-git-messages-to-english-for-TestRemoteLoad_LocalProtocol
Set Git messages to English for TestRemoteLoad_LocalProtocol
2025-05-23 01:22:36 -07:00
Kubernetes Prow Robot
367ebb6990 Merge pull request #5888 from lcostea/master
chore: remove unused build arg and address warnings
2025-05-23 00:54:35 -07:00
Kubernetes Prow Robot
616c084805 Merge pull request #5865 from milkshake308/feat_helm_devel_arg
feat(helm): allow the use of devel alias for helmcharts
2025-05-17 12:25:16 -07:00
Kubernetes Prow Robot
dba6dee214 Merge pull request #5907 from kubernetes-sigs/dependabot/go_modules/hack/github.com/getkin/kin-openapi-0.131.0
build(deps): bump github.com/getkin/kin-openapi from 0.120.0 to 0.131.0 in /hack
2025-05-17 12:15:13 -07:00
dependabot[bot]
009369bfc9 build(deps): bump github.com/getkin/kin-openapi in /hack
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.120.0 to 0.131.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.120.0...v0.131.0)

---
updated-dependencies:
- dependency-name: github.com/getkin/kin-openapi
  dependency-version: 0.131.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-05-15 16:47:35 +00:00
Kubernetes Prow Robot
65567a3733 Merge pull request #5890 from gecube/patch-2
fix indent in example yaml at generatorOptions.md
2025-04-28 23:37:54 -07:00
Kubernetes Prow Robot
d53c17b874 Merge pull request #5898 from tabbysable/typo-fix
Fix typo in documentation
2025-04-28 23:09:55 -07:00
Tabitha Sable
aa2c9ca440 Fix typo in documentation
Fix a typo in an example URL in the resources.md Kustomization file documentation
2025-04-28 15:23:15 -05:00
George Gaál
b201d97541 Update generatorOptions.md
fix indentation
2025-04-12 13:38:02 +02:00
Liviu Costea
fd97ddaca1 fix: remove unused build arg and address warnings 2025-04-07 13:18:38 +03:00
Kubernetes Prow Robot
7372f97c19 Merge pull request #5877 from tsuzu/fix-replacements-plugin-omitempty-field
fix: make private one field in replacements transformer struct that had a missing JSON tag
2025-04-03 01:50:37 -07:00
Tsuzu
e3f0349319 Make replacements private 2025-03-31 20:41:41 +09:00
Timur Demin
dd08aec23e fix: Don't panic on multiple $patch: delete strategic merge patches in a single patch file (#5859)
* chore: add test for multiple $patch: delete patches not panicking

* fix: don't panic on multiple deletion SM patches
2025-03-28 06:04:40 -07:00
Kubernetes Prow Robot
2e80cebf21 Merge pull request #5630 from cunyat/feat/5516-replacement-inline-value
Add static value source for replacement
2025-03-28 05:54:40 -07:00
Arthur Diniz
e683487ea8 Set Git messages to English for TestRemoteLoad_LocalProtocol
Ensure consistent error message matching by setting LC_ALL=C in
TestRemoteLoad_LocalProtocol, preventing locale-based variations
in Git output.

Signed-off-by: Arthur Diniz <arthurbdiniz@gmail.com>
2025-03-24 23:29:37 +00:00
Kubernetes Prow Robot
53fa7285e9 Merge pull request #5881 from kubernetes-sigs/dependabot/go_modules/hack/github.com/golang-jwt/jwt/v5-5.2.2
build(deps): bump github.com/golang-jwt/jwt/v5 from 5.2.1 to 5.2.2 in /hack
2025-03-22 13:54:31 -07:00
dependabot[bot]
61b8724e87 build(deps): bump github.com/golang-jwt/jwt/v5 in /hack
Bumps [github.com/golang-jwt/jwt/v5](https://github.com/golang-jwt/jwt) from 5.2.1 to 5.2.2.
- [Release notes](https://github.com/golang-jwt/jwt/releases)
- [Changelog](https://github.com/golang-jwt/jwt/blob/main/VERSION_HISTORY.md)
- [Commits](https://github.com/golang-jwt/jwt/compare/v5.2.1...v5.2.2)

---
updated-dependencies:
- dependency-name: github.com/golang-jwt/jwt/v5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-03-21 22:13:49 +00:00
Julio Chana
31b37540e3 fix: Allow patches with empty files with multiple newlines or comments (#5771)
* fix: Add test, when an empty patch file is given, it should not fail

* fix: Add code so there's no error given if an empty file is given as a patch

* chore: Generate plugin with pluginator

* chore: fix tests

Signed-off-by: Julio Chana <julio.chana@lokalise.com>

* Add t.helper() at start of test function

Signed-off-by: Julio Chana <julio.chana@lokalise.com>

---------

Signed-off-by: Julio Chana <julio.chana@lokalise.com>
2025-03-16 19:15:48 -07:00
Kubernetes Prow Robot
2643c51364 Merge pull request #5873 from skitt/clean-viper
Bump to github.com/spf13/viper v1.20.0
2025-03-15 11:17:47 -07:00
Stephen Kitt
6b830658d1 Bump to github.com/spf13/viper v1.20.0
This includes the go-difflib and go-spew reverts, which means the
corresponding exclusions can be removed. cmd/gorepomod/go.mod loses a
number of indirect dependencies thanks to the spf13/viper cleanup, but
hack/go.mod gains a few.

Signed-off-by: Stephen Kitt <skitt@redhat.com>
2025-03-15 17:13:59 +01:00
milkshake308
5036c077cc fix: incorrect devel chart assertion 2025-02-23 22:33:40 +01:00
milkshake308
418f233314 feat: add test cases for helm devel 2025-02-21 01:15:33 +01:00
milkshake308
c5f69b002f feat: add devel options for helmcharts 2025-02-21 01:13:18 +01:00
Kubernetes Prow Robot
447a60903c Merge pull request #5765 from kundan2707/glossary_link_update
updated link for glossary.md
2025-02-18 19:14:26 -08:00
Kundan Kumar
06535d623a updated link for glossary.md 2025-02-18 20:08:58 +05:30
Matthias Riegler
cc7a71c288 feat: add exec-plugin argument and environment support (#5316)
* feat: add exec-plugin argument and environment support

Previously, the documentation lead to think that this is working, but
it's not been implemented.

This PR is fixing this

Signed-off-by: Matthias Riegler <matthias.riegler@ankorstore.com>

* chore: disable linting for env var split

Signed-off-by: Matthias Riegler <matthias.riegler@ankorstore.com>

---------

Signed-off-by: Matthias Riegler <matthias.riegler@ankorstore.com>
2025-02-16 13:28:21 -08:00
Kubernetes Prow Robot
3be1af6798 Merge pull request #5855 from kubernetes-sigs/dependabot/go_modules/hack/github.com/golang/glog-1.2.4
build(deps): bump github.com/golang/glog from 1.2.0 to 1.2.4 in /hack
2025-02-02 18:40:57 -08:00
dependabot[bot]
33e9361a61 build(deps): bump github.com/golang/glog from 1.2.0 to 1.2.4 in /hack
Bumps [github.com/golang/glog](https://github.com/golang/glog) from 1.2.0 to 1.2.4.
- [Release notes](https://github.com/golang/glog/releases)
- [Commits](https://github.com/golang/glog/compare/v1.2.0...v1.2.4)

---
updated-dependencies:
- dependency-name: github.com/golang/glog
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-01-28 17:38:48 +00:00
Kubernetes Prow Robot
160de8ce76 Merge pull request #5853 from stormqueen1990/patch-1
Step down as commands approver
2025-01-27 11:17:23 -08:00
Mauren
d339dca90c Step down as commands approver
Due to reduced time available to work on Kustomize, I decided to step down from the command approver role for the time being.
2025-01-26 11:13:08 -05:00
Kubernetes Prow Robot
e4fff94c68 Merge pull request #5656 from ah8ad3/refactor-common-labels
Update readme to remove deprecated configuration 'commonLabels'.
2025-01-19 23:22:35 -08:00
Dmitry Volodin
9c68bd2ee2 fix: Get version from the BuildInfo.Main.Version if not found in deps and build flag 2025-01-19 09:25:33 +03:00
Kubernetes Prow Robot
38eb24492a Merge pull request #5847 from koba1t/dependencies/replace_to_carapace-shlex
replace deplecated package github.com/google/shlex with github.com/carapace-sh/carapace-shlex
2025-01-17 05:56:36 -08:00
koba1t
7664c4ba38 replace github.com/google/shlex with https://github.com/carapace-sh/carapace-shlex 2025-01-16 14:54:26 +09:00
Kubernetes Prow Robot
48686ac4a3 Merge pull request #5844 from stormqueen1990/feat/bump-deps
build(deps): bump golang.org/x/net from 0.28.0 to 0.33.0 in /hack
2025-01-15 18:40:34 -08:00
Mauren Berti
f03e31389d build(deps): bump golang.org/x/net from 0.28.0 to 0.33.0 in /hack
Bump the golang.org/x/net dependency and synchronize the workspace using
make workspace-sync
2025-01-15 15:17:23 -05:00
Kubernetes Prow Robot
ba56dd28ca Merge pull request #5841 from koba1t/unpinEverything
Back to development mode; unpin the modules
2025-01-14 07:54:33 -08:00
koba1t
821aebc3b3 Back to development mode; unpin the modules 2025-01-15 00:37:09 +09:00
Kubernetes Prow Robot
95db4aa0ed Merge pull request #5840 from koba1t/pinToApi
Update api to v0.19.0
2025-01-14 07:08:34 -08:00
koba1t
07f62bd986 Update api to v0.19.0 2025-01-14 23:54:58 +09:00
Kubernetes Prow Robot
b69e76509f Merge pull request #5839 from koba1t/pinToCmdConfig
Update cmd/config to v0.19.0
2025-01-14 06:50:33 -08:00
koba1t
8a51255ea1 Update cmd/config to v0.19.0 2025-01-14 23:42:16 +09:00
Kubernetes Prow Robot
ce667b70a0 Merge pull request #5837 from koba1t/pinToKyaml
Update kyaml to v0.19.0
2025-01-14 06:22:33 -08:00
koba1t
1b33db58f2 Update kyaml to v0.19.0 2025-01-14 23:14:25 +09:00
yugo kobayashi
880a7a0187 add go work verification step for github actions (#5833)
* add go work verification step for github actions

* failure-example_this_commit_will_be_failed_to_check_go_work_sync

* Revert "failure-example_this_commit_will_be_failed_to_check_go_work_sync"

This reverts commit d8fd5020dc.
2025-01-07 10:58:29 -08:00
Sebastiaan van Stijn
2867f353c2 downgrade go-difflib and go-spew to tagged releases (#5830)
* workspace sync

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

* downgrade go-difflib and go-spew to tagged releases

commit d35edbf80d updated these dependencies
to untagged versions. The diff in both dependencies show that there's no
code changes, and it's unlikely for those modules to do new releases.

Unfortunate, because of that change all projects depending on kubernetes
or any of it's modules now had to upgrade to unreleased versions of
these.

This patch reverts those updates (but it may take some time before
all other projects can be reverted).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

---------

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-07 03:48:28 +01:00
Kubernetes Prow Robot
214aa2aae2 Merge pull request #5823 from kubernetes-sigs/dependabot/go_modules/hack/golang.org/x/crypto-0.31.0
build(deps): bump golang.org/x/crypto from 0.24.0 to 0.31.0 in /hack
2024-12-17 13:46:53 +01:00
dependabot[bot]
6f62ee7198 build(deps): bump golang.org/x/crypto from 0.24.0 to 0.31.0 in /hack
Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.24.0 to 0.31.0.
- [Commits](https://github.com/golang/crypto/compare/v0.24.0...v0.31.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-12-15 11:52:17 +00:00
Kubernetes Prow Robot
fcc95370ff Merge pull request #5825 from dims/update-to-latest-kube-api-to-drop-govalidator-dependency
Update to latest kube-opeapi to drop govalidator dependency
2024-12-15 12:50:43 +01:00
Davanum Srinivas
84e6594e9b Update golangci/golangci-lint to v1.56.2
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2024-12-14 19:28:39 -05:00
Kubernetes Prow Robot
86af799ce0 Merge pull request #5809 from fktym/fix/add-label-without-selector
fix: "edit add labels" make labels handle -f flag same as commonLabels
2024-12-13 04:26:25 +01:00
Davanum Srinivas
b79c5f652d Update to latest kube-opeapi to drop govalidator dependency
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2024-12-12 18:48:06 -05:00
fktym
70e4d2e24c fix: make labels handle -f flag same as commonLabels 2024-12-12 14:02:53 +09:00
Kubernetes Prow Robot
a8c5b10d39 Merge pull request #5810 from guettli/better-err-msg-on-undefined-loader-behavior
Better error message on undefined loader behavior.
2024-11-30 19:00:58 +00:00
Thomas Guettler
ae7ff36f1b Better error message on undefined loader behavior. 2024-11-25 08:44:36 +01:00
Kubernetes Prow Robot
bb7a280709 Merge pull request #5785 from koba1t/remove_unnecesary_install_command_from_Dockerfile
remove unnecesary install command from Dockerfile
2024-10-10 22:04:21 +01:00
koba1t
d135197eba remove unnecesary install command from Dockerfile 2024-10-09 23:26:16 +09:00
Kubernetes Prow Robot
4c5c585592 Merge pull request #5784 from koba1t/unpinEverything
Back to development mode; unpin the modules
2024-10-09 14:38:23 +01:00
koba1t
4f6e3cbe3f Back to development mode; unpin the modules 2024-10-09 22:20:42 +09:00
Kubernetes Prow Robot
afe7793676 Merge pull request #5783 from koba1t/pinToApi
Update api to v0.18.0
2024-10-09 14:08:22 +01:00
koba1t
ae98655f0f Update api to v0.18.0 2024-10-09 21:58:41 +09:00
Kubernetes Prow Robot
faccc12624 Merge pull request #5782 from koba1t/pinToCmdConfig
Update cmd/config to v0.15.0
2024-10-09 13:46:23 +01:00
koba1t
fdf9f59cb5 Update cmd/config to v0.15.0 2024-10-09 21:37:00 +09:00
Kubernetes Prow Robot
e2967cf3ce Merge pull request #5781 from koba1t/pinToKyaml
Update kyaml to v0.18.1
2024-10-09 13:30:23 +01:00
koba1t
d22fa37ae0 Update kyaml to v0.18.1 2024-10-09 21:20:17 +09:00
Kubernetes Prow Robot
01cce4f6cc Merge pull request #5756 from viniciusdc/5755-kustomize-install
chore: add bad-credentials exception for install script
2024-09-27 03:50:01 +01:00
Kubernetes Prow Robot
54cbcdc698 Merge pull request #5770 from koba1t/add_write_permission_to_run_release_CI
add write permission to run release CI
2024-09-26 23:00:04 +01:00
koba1t
b36b222b26 add write permission to run release CI 2024-09-27 01:36:10 +09:00
Kubernetes Prow Robot
2cd9a2e73a Merge pull request #5768 from dims/remove-starlark-support
Remove starlark support
2024-09-25 18:14:00 +01:00
Davanum Srinivas
d32eacf034 Remove starlark support
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2024-09-23 16:52:05 -04:00
Kubernetes Prow Robot
88f19bffa9 Merge pull request #5763 from koba1t/update_go_1.22.7
Update go 1.22.7
2024-09-16 05:41:13 +01:00
koba1t
a3c0b4add7 disable for a step to skip test when that is docs PR 2024-09-15 01:56:28 +09:00
koba1t
b67ce5bb73 go work sync && ./hack/doGoMod.sh tidy 2024-09-15 01:43:03 +09:00
koba1t
5ba8523df7 update go 1.22.7 2024-09-15 01:40:50 +09:00
Isar_NS
4034e36ee1 Add --helm-debug Flag to Kustomize for Enhanced Helm Debugging (#5751)
* feat: add helm-debug flag

* revert: go.work.sum

* test: add helm chart args helm-debug test

* test: helm debug flag

* refactor: helm debug output

* style: linting

* revert: go.work.sum
2024-09-12 23:43:12 +01:00
Kubernetes Prow Robot
c3872ce3d9 Merge pull request #5745 from isarns/master
Add Annotation to Control Inline List Conversion in Kustomize Resources"
2024-09-12 18:57:13 +01:00
Kubernetes Prow Robot
d35d21c2d0 Merge pull request #5760 from Kavinjsir/patch-docs
Docs: fix kubectl command
2024-09-10 11:39:57 +01:00
Vinicius D. Cerutti
3872752338 chore: add bad-credentials exception for install script
* fix typo at closing if statement
2024-09-09 13:08:41 -03:00
isarns
a5f43ec75a style: linting 2024-09-09 13:26:53 +03:00
isarns
e6266d4559 refactor: fix test with not 'items:' 2024-09-09 13:26:33 +03:00
Tony Jin
99efd6995a docs: fix kubectl command 2024-09-06 15:05:07 -07:00
ah8ad3
5ef10d35ee Update readme to remove deprecated configuration 'commonLabels'. 2024-09-04 18:55:00 +03:30
Daniel Wilson
b7cdd9168a Sort built-in Namespace kind before CRDs with the same name (#5458)
* add core api sort priority for NAmespace kind in gvkLessThan

* fix logic

* fix syntax

* fix syntax

* fix logic

* regenerate builtin plugins
2024-09-03 21:57:17 +01:00
Kubernetes Prow Robot
27d508fa03 Merge pull request #5716 from VannTen/cleanup/wrong_example_config_gen
Remove misleading documentation about config generation
2024-08-29 18:01:30 +01:00
Max Gautier
05339dafe5 Remove misleading documentation about config generation
ConfigMap are not garbage collected, see #3146
2024-08-26 15:00:45 +02:00
isarns
bbb0b08576 test: add empty list test 2024-08-18 14:56:54 +03:00
isarns
77daec89b8 refactor: inlineAnyEmbeddedLists 2024-08-13 14:35:46 +03:00
isarns
a1fd6efe5d feat: annotation to disable list conversion 2024-08-11 17:44:44 +03:00
Ramon Cunyat
6c27970019 Add static value source for replacement
Introduces `sourceValue` on replacement object for replacing from a
static value instead of sourcing from another object.

Solves #5516
2024-07-25 14:32:54 +02:00
John Zheng
cc9dd34216 docs: update patchMultipleObject example to filter with labelSelector (#5700)
* Update patchMultipleObjects.md

* Update patchMultipleObjects.md

* Update patchMultipleObjects.md

* Update patchMultipleObjects.md

* Update patchMultipleObjects.md

* Update patchMultipleObjects.md

* Update patchMultipleObjects.md

* Update patchMultipleObjects.md
2024-07-23 15:02:40 -07:00
Kubernetes Prow Robot
2aaa42f950 Merge pull request #5737 from koba1t/unpinEverything
Back to development mode; unpin the modules
2024-07-19 10:09:37 -07:00
koba1t
f660160a0f Back to development mode; unpin the modules 2024-07-20 01:57:28 +09:00
Varsha
d4248b1213 Merge pull request #5736 from koba1t/pinToApi
Update api to v0.17.3
2024-07-19 09:34:19 -07:00
koba1t
bd8b8a49c9 Update api to v0.17.3 2024-07-20 01:14:03 +09:00
Kubernetes Prow Robot
ddeb572a7f Merge pull request #5735 from koba1t/pinToCmdConfig
Update cmd/config to v0.14.2
2024-07-19 09:07:22 -07:00
koba1t
36d78f67fd Update cmd/config to v0.14.2 2024-07-20 00:55:30 +09:00
Kubernetes Prow Robot
4e52632bd3 Merge pull request #5734 from koba1t/pinToKyaml
Update kyaml to v0.17.2
2024-07-19 08:50:48 -07:00
koba1t
8eacab0fc6 Update kyaml to v0.17.2 2024-07-20 00:28:06 +09:00
Kubernetes Prow Robot
1a41303fbb Merge pull request #5628 from antoooks/release-helper-script
Release helper script
2024-07-16 10:53:06 -07:00
Dennis Zhou
7cbaf78b1a fix:kustomize cfg grep with no arguments causes panic (#5707)
* fix:kustomize cfg grep with no arguments causes panic

* add test for kustomize cfg grep with no arguments
2024-07-10 00:46:40 -07:00
Kubernetes Prow Robot
735ad0beef Merge pull request #5682 from kozjan/add-label-include-templates
fix: include label in templates when adding by cli
2024-07-10 00:46:33 -07:00
Kubernetes Prow Robot
c1de0301f5 Merge pull request #5413 from crenshaw-dev/patch-1
chore(docs): fix grammar error in comment
2024-06-30 11:45:02 -07:00
Kubernetes Prow Robot
5cfd3ab3e7 Merge pull request #5725 from kubernetes-sigs/dependabot/go_modules/hack/golang.org/x/image-0.18.0
build(deps): bump golang.org/x/image from 0.13.0 to 0.18.0 in /hack
2024-06-27 07:47:18 -07:00
dependabot[bot]
dfb30644f4 build(deps): bump golang.org/x/image from 0.13.0 to 0.18.0 in /hack
Bumps [golang.org/x/image](https://github.com/golang/image) from 0.13.0 to 0.18.0.
- [Commits](https://github.com/golang/image/compare/v0.13.0...v0.18.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2024-06-26 19:38:08 +00:00
Kubernetes Prow Robot
e3a7615ccb Merge pull request #5506 from cloud-native-team/master
fix some comments
2024-06-18 12:37:52 -07:00
Kubernetes Prow Robot
b02d02a6cd Merge pull request #5715 from kubernetes-sigs/dependabot/go_modules/hack/github.com/Azure/azure-sdk-for-go/sdk/azidentity-1.6.0
build(deps): bump github.com/Azure/azure-sdk-for-go/sdk/azidentity from 1.3.0 to 1.6.0 in /hack
2024-06-18 12:20:28 -07:00
Kubernetes Prow Robot
804f69bacf Merge pull request #5719 from kubernetes-sigs/dependabot/npm_and_yarn/site/braces-3.0.3
build(deps-dev): bump braces from 3.0.2 to 3.0.3 in /site
2024-06-18 10:11:10 -07:00
dependabot[bot]
9ab7762a40 build(deps): bump github.com/Azure/azure-sdk-for-go/sdk/azidentity
Bumps [github.com/Azure/azure-sdk-for-go/sdk/azidentity](https://github.com/Azure/azure-sdk-for-go) from 1.3.0 to 1.6.0.
- [Release notes](https://github.com/Azure/azure-sdk-for-go/releases)
- [Changelog](https://github.com/Azure/azure-sdk-for-go/blob/main/documentation/release.md)
- [Commits](https://github.com/Azure/azure-sdk-for-go/compare/sdk/azcore/v1.3.0...sdk/azcore/v1.6.0)

---
updated-dependencies:
- dependency-name: github.com/Azure/azure-sdk-for-go/sdk/azidentity
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-06-17 22:01:15 +00:00
dependabot[bot]
44a99b7284 build(deps-dev): bump braces from 3.0.2 to 3.0.3 in /site
Bumps [braces](https://github.com/micromatch/braces) from 3.0.2 to 3.0.3.
- [Changelog](https://github.com/micromatch/braces/blob/master/CHANGELOG.md)
- [Commits](https://github.com/micromatch/braces/compare/3.0.2...3.0.3)

---
updated-dependencies:
- dependency-name: braces
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-06-17 21:47:44 +00:00
Kubernetes Prow Robot
692b40e515 Merge pull request #5718 from koba1t/chore/fix_lint_error_in_kustomizationfile_test.go
fix lint error in kustomizationfile_test.go
2024-06-17 14:46:47 -07:00
koba1t
bef46a1a04 fix lint error in kustomizationfile_test.go 2024-06-18 06:33:57 +09:00
Kubernetes Prow Robot
48d79c745a Merge pull request #5691 from karlkfi/karl-cockroachdb-pin-version
Pin kustomize image in cockroachdb example
2024-06-12 09:39:45 -07:00
Kubernetes Prow Robot
856662835f Merge pull request #5698 from stormqueen1990/fix/validation-name-reference
fix(namereference): add configuration for new admission API
2024-06-08 01:42:58 -07:00
jan.kozlowski
cba3688960 add validation and test case 2024-06-06 14:01:49 +02:00
Oliver F
16a7ce2b8b Fix sortOptions removal when running edit command (#5689)
* Fix sortOptions and Validators removal when running edit command

* fixed linting
2024-06-04 20:26:41 -07:00
Kubernetes Prow Robot
92e862c233 Merge pull request #5544 from sanaasy/sanaasy/add-no-verify-flag
Run kustomize build with kustomize localize and add a no-verify flag.
2024-06-04 20:10:20 -07:00
Sanaa Syed
8db4c4b062 Fix lint error message adn reduce build error message to a string concatination. 2024-06-03 22:22:03 -04:00
Kubernetes Prow Robot
cb432b0350 Merge pull request #5699 from stormqueen1990/chore/deprecation-common-labels
chore: add deprecation comment to commonLabels
2024-05-27 15:15:20 -07:00
Colin O'Dell
88c89f422a fix: always show accumulation errors (#5693)
* fix: always show accumulation errors if the resource was successfully loaded as a base

* chore: regression test

* chore: fix lint violations
2024-05-24 20:13:10 -07:00
Kubernetes Prow Robot
ce80dc9e2b Merge pull request #5705 from koba1t/unpinEverything
Back to development mode; unpin the modules
2024-05-22 08:48:38 -07:00
koba1t
226d56b5cf Back to development mode; unpin the modules 2024-05-23 00:35:50 +09:00
Kubernetes Prow Robot
f309dfc54a Merge pull request #5704 from koba1t/pinToApi
Update api to v0.17.2
2024-05-22 08:16:59 -07:00
koba1t
a34ac31a80 Update api to v0.17.2 2024-05-23 00:04:13 +09:00
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
Mauren Berti
77354d73b9 chore: add deprecation comment to commonLabels
`commonLabels` is deprecated, but the field did not have a deprecation comment,
like other fields do. Add the deprecation comment, as some IDEs use that as a
guideline to show a strikethrough in the field names (and to follow the pattern
of other deprecated fields).
2024-05-19 21:07:00 -04:00
Mauren Berti
3065eb36dd fix(namereference): add configuration for new admission API
Include configuration for the new `ValidatingAdmissionPolicy` and
`ValidationAdmissionPolicyBinding` APIs so that Kustomize can natively configure
the `policyName` field in `ValidatingAdmissionPolicyBinding` with the transformed
name of `ValidatingAdmissionPolicy`.
2024-05-19 20:58:03 -04:00
Sanaa Syed
b67959894e Add --no-verify flag configs along with kustomize build when kustomize localize command is run. 2024-05-15 23:45:29 -04:00
Karl Isenberg
6a829feef8 Pin kustomize image in cockroachdb example
- Pin to v5.4.1 with sha256 as example of how to ensure supply-chain
  security. Pulling the latest kustomize image or source is insecure
  without checksum validation.
- Bump example image tag to v0.1.1
2024-05-06 11:02:20 -07: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
Kurnianto Trilaksono
b1a9bffd8b Update CONTRIBUTING.md
- change breaking change notes

Co-authored-by: Mauren <698465+stormqueen1990@users.noreply.github.com>
2024-04-28 23:28:48 +07:00
jan.kozlowski
a83f102cc9 fix: include label in templates when adding by cli 2024-04-26 23:21:51 +02: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
Kurnianto Trilaksono
25c7e17fb8 add pr rules, fix script 2024-04-24 20:30:34 +08: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
Kurnianto Trilaksono
63329d175a fix logic and add license 2024-03-29 16:49:10 +08: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
Kurnianto Trilaksono
f63e919e3e revert untouched file 2024-03-28 00:01:40 +08:00
Kurnianto Trilaksono
3d840a6584 revert untouched files 2024-03-27 23:56:57 +08: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
Kurnianto Trilaksono
846d3c09eb fix logic 2024-03-27 00:16:03 +08:00
Kurnianto Trilaksono
fbc102dbd3 add change counter 2024-03-27 00:15:00 +08:00
Kurnianto Trilaksono
a7de0cc8cd edit printout 2024-03-27 00:11:53 +08:00
Kurnianto Trilaksono
931f924189 add helper script for releasing 2024-03-24 15:22:04 +08:00
Nick
50dc813731 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

cherrypick updates from feature branch

fix script

fix release script
2024-03-24 14:50:19 +08: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
cui fliter
d56e1d0f46 fix some comments
Signed-off-by: cui fliter <imcusg@gmail.com>
2024-01-05 16:25:48 +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
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
Claudio Busse
7b1eaf1e4f feat: localize absolute paths 2023-11-26 12:22:15 +01:00
sarab
fefa21fa01 Add conditional doc check in go workflow
Add checkout
2023-11-24 14:41:40 +05:30
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
Michael Crenshaw
71546359b8 Add a comment 2023-10-24 09:22:30 -04:00
Michael Crenshaw
234ab80086 chore(docs): fix grammar error in comment 2023-10-23 14:00:29 -04: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
Daniel Strebel
d37c0eb477 fix(examples): move examples from patchesStrategicMerge to patches 2023-06-09 22:32:19 +02:00
472 changed files with 19225 additions and 7848 deletions

View File

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

View File

@@ -13,15 +13,15 @@ jobs:
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
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v4
uses: actions/setup-go@v6
with:
go-version-file: go.work
- name: Execute go-apidiff
uses: joelanford/go-apidiff@v0.7.0
uses: joelanford/go-apidiff@v0.8.3
with:
compare-imports: true
print-compatible: true

View File

@@ -2,86 +2,157 @@ name: Go
on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]
permissions:
contents: read
jobs:
lint:
name: Lint
## TODO: conditional-changes checker is not working
conditional-changes:
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
doc: ${{ steps.filter.outputs.doc }}
steps:
- uses: actions/checkout@v6
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
doc:
- 'site/**'
check-modules:
name: check-synced-go-modules
# 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@v4
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Go 1.x
uses: actions/setup-go@v3
uses: actions/setup-go@v6
with:
go-version-file: go.work
cache: true
cache-dependency-path: |
**/go.sum
id: go
- name: sync go modules
run: make workspace-sync
- name: check for changes with 'make workspace-sync'
run: git diff --exit-code
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@v6
with:
fetch-depth: 0
- name: Set up Go 1.x
uses: actions/setup-go@v6
with:
go-version-file: go.work
cache: true
cache-dependency-path: |
**/go.sum
id: go
- name: Lint
run: make lint
- name: Verify boilerplate
run: make check-license
test-linux:
## Test all modules without plugins and released modules
test-non-released-modules:
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@v4
uses: actions/checkout@v6
- name: Set up Go 1.x
uses: actions/setup-go@v3
uses: actions/setup-go@v6
with:
go-version-file: go.work
cache: true
cache-dependency-path: |
**/go.sum
id: go
- name: Test all modules
run: make test-unit-non-plugin
- name: Test all modules without plugins and released modules
run: make test-unit-non-plugin-and-non-released
env:
KUSTOMIZE_DOCKER_E2E: true
test-macos:
name: Test MacOS
runs-on: [macos-latest]
test-modules:
name: Test ${{ matrix.os }} - ${{ matrix.module }}
# needs: conditional-changes
# if: needs.conditional-changes.outputs.doc == 'false'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
module:
- kyaml
- cmd/config
- api
- kustomize
include:
- module: kyaml
test-cmd: go test -race -v -cover ./...
- module: cmd/config
test-cmd: go test -v -cover ./...
- module: api
test-cmd: go test -v -cover ./... -ldflags "-X sigs.k8s.io/kustomize/api/provenance.buildDate=2023-01-31T23:38:41Z -X sigs.k8s.io/kustomize/api/provenance.version=(test)"
- module: kustomize
test-cmd: go test -v -cover ./...
- os: ubuntu-latest
docker-e2e: true
- os: macos-latest
docker-e2e: false
- os: windows-latest
docker-e2e: false
env:
KUSTOMIZE_DOCKER_E2E: ${{ matrix.docker-e2e }}
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
uses: actions/checkout@v6
- name: Set up Go 1.x
uses: actions/setup-go@v3
uses: actions/setup-go@v6
with:
go-version-file: go.work
cache: true
cache-dependency-path: |
**/go.sum
id: go
- name: Test all modules
run: make test-unit-non-plugin
env:
KUSTOMIZE_DOCKER_E2E: false # docker not installed on mac
- name: Test ${{ matrix.module }}
run: ${{ matrix.test-cmd }}
# TODO (#4001): replace specific modules above with this once Windows tests are passing.
if: ${{ !(matrix.os == 'windows-latest' && (matrix.module == 'api' || matrix.module == 'kustomize')) }}
working-directory: ./${{ matrix.module }}
test-windows:
name: Test Windows
runs-on: [windows-latest]
# Aggregation matrix tests from test-modules for branch protection rules
test-modules-summary:
name: Test Summary
runs-on: ubuntu-latest
needs: test-modules
if: always()
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version-file: go.work
id: go
- name: Test kyaml
run: go test -cover ./...
working-directory: ./kyaml
- name: Test cmd/config
run: go test -cover ./...
working-directory: ./cmd/config
env:
KUSTOMIZE_DOCKER_E2E: false # docker on windows not working well yet
# TODO (#4001): replace specific modules above with this once Windows tests are passing.
#- name: Test all modules
# run: make test-unit-non-plugin
# env:
# KUSTOMIZE_DOCKER_E2E: false # docker on windows not working well yet
- name: Check test results
run: |
if [[ "${{ needs.test-modules.result }}" != "success" ]]; then
echo "Some tests failed or were cancelled"
exit 1
fi
echo "All tests passed successfully"

View File

@@ -1,5 +1,8 @@
name: release
permissions:
contents: write # Allow actions to update dependabot PRs
on:
push:
tags:
@@ -13,11 +16,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Set up Go 1.x
uses: actions/setup-go@v3
uses: actions/setup-go@v6
with:
go-version-file: go.work
id: go

1
.gitignore vendored
View File

@@ -31,3 +31,4 @@ site/.hugo_build.lock
# goreleaser artifacts
**/dist/
/output/

View File

@@ -3,12 +3,13 @@
run:
deadline: 5m
go: '1.20'
go: "1.24"
linters:
enable-all: true
disable:
- cyclop
- depguard
- exhaustivestruct
- forbidigo
- funlen
@@ -24,7 +25,9 @@ linters:
- nlreturn
- noctx
- paralleltest
- perfsprint
- stylecheck
- testifylint
- varnamelen
- wsl
- exhaustruct
@@ -35,6 +38,15 @@ linters:
- 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
# TODO(koba1t): temporarily disabled, will be addressed after upgrading to Go 1.24
- usetesting
- mnd
- copyloopvar
- intrange
linters-settings:
dupl:
@@ -45,14 +57,14 @@ linters-settings:
min-complexity: 30
revive:
rules:
- name: var-naming
arguments:
- [ "ID", "API", "JSON" ] # AllowList
- [ ] # DenyList
- name: var-naming
arguments:
- ["ID", "API", "JSON"] # AllowList
- [] # DenyList
gomnd:
ignored-functions:
- os.WriteFile
- make
- os.WriteFile
- make
gomoddirectives:
replace-local: true
gosec:

View File

@@ -75,14 +75,39 @@ cd kustomize
git push origin myfeature
```
### Pull Request Rules
We are using [Conventional Commits v1.0.0](https://www.conventionalcommits.org/en/v1.0.0/) as the main guideline of making PR. This guideline serves to help contributor and maintainer to classify their changes, thus providing better insight on type of release will be covered on each Kustomize release cycle.
1. Please add these keywords on your PR titles accordingly
| Keyword | Description | Example |
| ------------- | ------------- | ------------- |
| fix | Patching or fixing bugs or improvements introduction from previous release. This type of change will mark a `PATCH` release. | fix: fix null value when generating yaml |
| feat | New features. This change will mark a `MINOR` release. | feat: new transformer and generator for ACME API CRD. |
| chore | Minor improvement outside main code base | chore: add exclusion for transformer test. |
| ci | CI/CD related changes (e.g. github workflow, scripts, CI steps). | ci: remove blocking tests |
| docs | Changes related to documentation. | docs: add rules documentation for PR. |
2. Add `BREAKING CHANGE:` on your commit message as footer to signify breaking changes. This will help maintainers identify `MAJOR` releases.
Example:
```
feat: change YAML parser from `yaml/v1` to `yaml/v2`
BREAKING CHANGE: parse() function now works with 2 arguments.
```
### 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

View File

@@ -3,7 +3,7 @@
#
# Makefile for kustomize CLI and API.
LATEST_RELEASE=v5.2.1
LATEST_RELEASE=v5.8.0
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 ---
@@ -130,29 +128,29 @@ lint: $(MYGOBIN)/golangci-lint $(MYGOBIN)/goimports $(builtinplugins)
./hack/for-each-module.sh "make lint"
.PHONY: apidiff
apidiff: go-apidiff ## Run the go-apidiff to verify any API differences compared with origin/master
$(GOBIN)/go-apidiff master --compare-imports --print-compatible --repo-path=.
.PHONY: go-apidiff
go-apidiff:
go install github.com/joelanford/go-apidiff@v0.6.0
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 \
test-unit-kustomize-plugins
# 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/*" 19
./hack/for-each-module.sh "make test" "./plugin/*" 20
# This target is used by our Github Actions CI to run unit tests for all non-plugin and non-released modules in multiple GOOS environments.
.PHONY: test-unit-non-plugin-and-non-released
test-unit-non-plugin-and-non-released:
./hack/for-each-module.sh "make test" "./plugin/*|./kyaml/go.mod|./cmd/config/go.mod|./api/go.mod|./kustomize/go.mod" 16
.PHONY: build-non-plugin-all
build-non-plugin-all:
./hack/for-each-module.sh "make build" "./plugin/*" 19
./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
@@ -189,7 +187,7 @@ test-examples-kustomize-against-latest-release: $(MYGOBIN)/mdrip
workspace-sync:
go work sync
./hack/doGoMod.sh tidy
# --- Cleanup targets ---
.PHONY: clean
clean: clean-kustomize-external-go-plugin uninstall-tools

View File

@@ -96,10 +96,10 @@ generate-kustomize-builtin-plugins: $(builtplugins)
echo "generating $${plugin} ..."; \
set -e; \
cd $${plugin}; \
go generate pluginator .; \
go generate .; \
done
# Check for diff by comparing current revision of generated plugins on HEAD and newly generated plugins on local branch,
# 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)
@@ -107,7 +107,9 @@ builtin-plugins-diff: $(builtplugins)
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; \
echo "Error(1): diff found on $${file}"; \
git diff $${file};\
exit 1;\
fi \
done

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,21 +3,25 @@
aliases:
kustomize-owners:
- knverey
- natasha41575
- koba1t
kustomize-approvers:
- knverey
- natasha41575
- annasong20
- koba1t
- varshaprasad96
kustomize-reviewers:
- knverey
- natasha41575
- yuwenma
- annasong20
- koba1t
- stormqueen1990
- varshaprasad96
- ncapps
docs-approvers:
- ncapps
docs-reviewers:
- ncapps
commands-approvers: []
commands-reviewers: []
# emeritus:
# - liujingfang1
# - Shell32-Natsu
@@ -27,3 +31,6 @@ aliases:
# - mengqiy
# - mortent
# - phanimarupaka
# - natasha41575
# - annasong20
# - yuwenma

View File

@@ -23,9 +23,9 @@ This tool is sponsored by [sig-cli] ([KEP]).
To find the kustomize version embedded in recent versions of kubectl, run `kubectl version`:
```sh
> kubectl version --short --client
Client Version: v1.26.0
Kustomize Version: v4.5.7
> kubectl version --client
Client Version: v1.31.0
Kustomize Version: v5.4.2
```
The kustomize build flow at [v2.0.3] was added
@@ -76,18 +76,18 @@ kustomization.yaml deployment.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: |
| labels: | | metadata: | | metadata: |
| - includeSelectors: true | | name: myapp | | name: myapp |
| pairs: | | spec: | | spec: |
| app: myapp | | selector: | | selector: |
| resources: | | matchLabels: | | app: myapp |
| - deployment.yaml | | app: myapp | | ports: |
| - service.yaml | | template: | | - port: 6060 |
| configMapGenerator: | | metadata: | | targetPort: 6060 |
| - name: myapp-map | | labels: | +-----------------------------------+
| literals: | | app: myapp |
| - KEY=value | | spec: |
+---------------------------------------------+ | containers: |
| - name: myapp |
| image: myapp |
| resources: |
@@ -142,16 +142,16 @@ kustomization.yaml replica_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" |
| labels: | | metadata: | | metadata: |
| - includeSelectors: true | | name: myapp | | name: myapp |
| pairs: | | spec: | | spec: |
| variant: prod | | replicas: 80 | | template: |
| resources: | +-------------------------------+ | spec: |
| - ../../base | | containers: |
| patches: | | - name: myapp |
| - path: replica_count.yaml | | resources: |
| - path: cpu_count.yaml | | limits: |
+-----------------------------------------------+ | memory: "128Mi" |
| cpu: "7000m" |
+------------------------------------------+
```

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

@@ -879,6 +879,84 @@ spec:
},
},
},
"update image volume in pod template": {
input: `
group: apps
apiVersion: v1
kind: Deployment
metadata:
name: imagevolume
spec:
template:
spec:
volumes:
- name: volume
image:
reference: nginx
`,
expectedOutput: `
group: apps
apiVersion: v1
kind: Deployment
metadata:
name: imagevolume
spec:
template:
spec:
volumes:
- name: volume
image:
reference: apache@12345
`,
filter: Filter{
ImageTag: types.Image{
Name: "nginx",
NewName: "apache",
Digest: "12345",
},
},
fsSlice: []types.FieldSpec{
{
Path: "spec/template/spec/volumes[]/image/reference",
},
},
},
"update image volume in pod spec": {
input: `
apiVersion: v1
kind: Pod
metadata:
name: imagevolume
spec:
volumes:
- name: volume
image:
reference: nginx
`,
expectedOutput: `
apiVersion: v1
kind: Pod
metadata:
name: imagevolume
spec:
volumes:
- name: volume
image:
reference: apache@12345
`,
filter: Filter{
ImageTag: types.Image{
Name: "nginx",
NewName: "apache",
Digest: "12345",
},
},
fsSlice: []types.FieldSpec{
{
Path: "spec/volumes[]/image/reference",
},
},
},
}
for tn, tc := range testCases {

View File

@@ -205,16 +205,14 @@ func getRoleRefGvk(n *resource.Resource) (*resid.Gvk, error) {
return nil, err
}
if apiGroup.IsNil() {
return nil, fmt.Errorf(
"apiGroup cannot be found in roleRef %s", roleRef.MustString())
return nil, fmt.Errorf("apiGroup cannot be found in roleRef %s", roleRef.MustString())
}
kind, err := roleRef.Pipe(yaml.Lookup("kind"))
if err != nil {
return nil, err
}
if kind.IsNil() {
return nil, fmt.Errorf(
"kind cannot be found in roleRef %s", roleRef.MustString())
return nil, fmt.Errorf("kind cannot be found in roleRef %s", roleRef.MustString())
}
return &resid.Gvk{
Group: apiGroup.YNode().Value,
@@ -284,9 +282,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 +323,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 "gopkg.in/evanphx/json-patch.v5"
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

@@ -4,6 +4,7 @@
package replacement
import (
"encoding/json"
"fmt"
"strings"
@@ -11,7 +12,6 @@ import (
"sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/resid"
kyaml_utils "sigs.k8s.io/kustomize/kyaml/utils"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
@@ -23,7 +23,7 @@ type Filter struct {
// Filter replaces values of targets with values from sources
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
for i, r := range f.Replacements {
if r.Source == nil || r.Targets == nil {
if (r.SourceValue == nil && r.Source == nil) || r.Targets == nil {
return nil, fmt.Errorf("replacements must specify a source and at least one target")
}
value, err := getReplacement(nodes, &f.Replacements[i])
@@ -39,6 +39,13 @@ func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
}
func getReplacement(nodes []*yaml.RNode, r *types.Replacement) (*yaml.RNode, error) {
if r.SourceValue != nil && r.Source != nil {
return nil, fmt.Errorf("value and resource selectors are mutually exclusive")
}
if r.SourceValue != nil {
return yaml.NewScalarRNode(*r.SourceValue), nil
}
source, err := selectSourceNode(nodes, r.Source)
if err != nil {
return nil, err
@@ -110,6 +117,10 @@ func applyReplacement(nodes []*yaml.RNode, value *yaml.RNode, targetSelectors []
if len(selector.FieldPaths) == 0 {
selector.FieldPaths = []string{types.DefaultReplacementFieldPath}
}
tsr, err := types.NewTargetSelectorRegex(selector)
if err != nil {
return nil, fmt.Errorf("error creating target selector: %w", err)
}
for _, possibleTarget := range nodes {
ids, err := utils.MakeResIds(possibleTarget)
if err != nil {
@@ -125,9 +136,13 @@ func applyReplacement(nodes []*yaml.RNode, value *yaml.RNode, targetSelectors []
continue
}
if tsr.RejectsAny(ids) {
continue
}
// filter targets by matching resource IDs
for _, id := range ids {
if id.IsSelectedBy(selector.Select.ResId) && !containsRejectId(selector.Reject, ids) {
if tsr.Selects(id) {
err := copyValueToTarget(possibleTarget, value, selector)
if err != nil {
return nil, err
@@ -168,43 +183,37 @@ func matchesAnnoAndLabelSelector(n *yaml.RNode, selector *types.Selector) (bool,
return annoMatch && labelMatch, nil
}
func containsRejectId(rejects []*types.Selector, ids []resid.ResId) bool {
for _, r := range rejects {
if r.ResId.IsEmpty() {
continue
}
for _, id := range ids {
if id.IsSelectedBy(r.ResId) {
return true
}
}
}
return false
}
func copyValueToTarget(target *yaml.RNode, value *yaml.RNode, selector *types.TargetSelector) error {
for _, fp := range selector.FieldPaths {
createKind := yaml.Kind(0) // do not create
if selector.Options != nil && selector.Options.Create {
createKind = value.YNode().Kind
}
// Check if this fieldPath contains structured data access
if err := setValueInStructuredData(target, value, fp, createKind); err == nil {
// Successfully handled as structured data
continue
}
// Fall back to normal path handling
targetFieldList, err := target.Pipe(&yaml.PathMatcher{
Path: kyaml_utils.SmarterPathSplitter(fp, "."),
Create: createKind})
if err != nil {
return errors.WrapPrefixf(err, fieldRetrievalError(fp, createKind != 0))
return errors.WrapPrefixf(err, "%s", fieldRetrievalError(fp, createKind != 0))
}
targetFields, err := targetFieldList.Elements()
if err != nil {
return errors.WrapPrefixf(err, fieldRetrievalError(fp, createKind != 0))
return errors.WrapPrefixf(err, "%s", fieldRetrievalError(fp, createKind != 0))
}
if len(targetFields) == 0 {
return errors.Errorf(fieldRetrievalError(fp, createKind != 0))
return errors.Errorf("%s", fieldRetrievalError(fp, createKind != 0))
}
for _, t := range targetFields {
if err := setFieldValue(selector.Options, t, value); err != nil {
return err
return fmt.Errorf("%w", err)
}
}
}
@@ -247,3 +256,146 @@ func setFieldValue(options *types.FieldOptions, targetField *yaml.RNode, value *
return nil
}
// setValueInStructuredData handles setting values within structured data (JSON/YAML) in scalar fields
func setValueInStructuredData(target *yaml.RNode, value *yaml.RNode, fieldPath string, createKind yaml.Kind) error {
pathParts := kyaml_utils.SmarterPathSplitter(fieldPath, ".")
if len(pathParts) < 2 {
return fmt.Errorf("not a structured data path")
}
// Find the potential scalar field that might contain structured data
var scalarFieldPath []string
var structuredDataPath []string
var foundScalar = false
// Try to find where the scalar field ends and structured data begins
for i := 1; i <= len(pathParts); i++ {
potentialScalarPath := pathParts[:i]
scalarField, err := target.Pipe(yaml.Lookup(potentialScalarPath...))
if err != nil {
continue
}
if scalarField != nil && scalarField.YNode().Kind == yaml.ScalarNode && i < len(pathParts) {
// Try to parse the scalar value as structured data
scalarValue := scalarField.YNode().Value
var parsedNode yaml.Node
if err := yaml.Unmarshal([]byte(scalarValue), &parsedNode); err == nil {
// Successfully parsed - this is structured data
scalarFieldPath = potentialScalarPath
structuredDataPath = pathParts[i:]
foundScalar = true
break
}
}
}
if !foundScalar {
return fmt.Errorf("no structured data found in path")
}
// Get the scalar field containing structured data
scalarField, err := target.Pipe(yaml.Lookup(scalarFieldPath...))
if err != nil {
return fmt.Errorf("%w", err)
}
// Parse the structured data
scalarValue := scalarField.YNode().Value
var parsedNode yaml.Node
if err := yaml.Unmarshal([]byte(scalarValue), &parsedNode); err != nil {
return fmt.Errorf("%w", err)
}
structuredData := yaml.NewRNode(&parsedNode)
// Navigate to the target location within the structured data
targetInStructured, err := structuredData.Pipe(&yaml.PathMatcher{
Path: structuredDataPath,
Create: createKind,
})
if err != nil {
return fmt.Errorf("%w", err)
}
targetFields, err := targetInStructured.Elements()
if err != nil {
return fmt.Errorf("%w", err)
}
if len(targetFields) == 0 {
return fmt.Errorf("unable to find field in structured data")
}
// Set the value in the structured data
for _, t := range targetFields {
if t.YNode().Kind == yaml.ScalarNode {
t.YNode().Value = value.YNode().Value
} else {
t.SetYNode(value.YNode())
}
}
// Serialize the modified structured data back to the scalar field
// Try to detect if original was JSON or YAML and preserve formatting
serializedData, err := serializeStructuredData(structuredData, scalarValue)
if err != nil {
return fmt.Errorf("%w", err)
}
// Update the original scalar field
scalarField.YNode().Value = serializedData
return nil
}
// serializeStructuredData handles the serialization of structured data back to string format
// preserving the original format (JSON vs YAML) and style (pretty vs compact)
func serializeStructuredData(structuredData *yaml.RNode, originalValue string) (string, error) {
firstChar := rune(strings.TrimSpace(originalValue)[0])
if firstChar == '{' || firstChar == '[' {
return serializeAsJSON(structuredData, originalValue)
}
// Fallback to YAML format
return serializeAsYAML(structuredData)
}
// serializeAsJSON converts structured data back to JSON format
func serializeAsJSON(structuredData *yaml.RNode, originalValue string) (string, error) {
modifiedData, err := structuredData.String()
if err != nil {
return "", fmt.Errorf("failed to serialize structured data: %w", err)
}
// Parse the YAML output as JSON
var jsonData interface{}
if err := yaml.Unmarshal([]byte(modifiedData), &jsonData); err != nil {
return "", fmt.Errorf("failed to unmarshal YAML data: %w", err)
}
// Check if original was pretty-printed by looking for newlines and indentation
if strings.Contains(originalValue, "\n") && strings.Contains(originalValue, " ") {
// Pretty-print the JSON to match original formatting
if prettyJSON, err := json.MarshalIndent(jsonData, "", " "); err == nil {
return string(prettyJSON), nil
}
}
// Compact JSON
if compactJSON, err := json.Marshal(jsonData); err == nil {
return string(compactJSON), nil
}
return "", fmt.Errorf("failed to marshal JSON data")
}
// serializeAsYAML converts structured data back to YAML format
func serializeAsYAML(structuredData *yaml.RNode) (string, error) {
modifiedData, err := structuredData.String()
if err != nil {
return "", fmt.Errorf("failed to serialize YAML data: %w", err)
}
return strings.TrimSpace(modifiedData), nil
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,37 +1,33 @@
module sigs.k8s.io/kustomize/api
go 1.20
go 1.24.0
require (
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.13
github.com/stretchr/testify v1.8.1
github.com/stretchr/testify v1.10.0
go.uber.org/goleak v1.3.0
gopkg.in/evanphx/json-patch.v5 v5.6.0
k8s.io/kube-openapi v0.0.0-20230601164746-7562a1006961
sigs.k8s.io/kustomize/kyaml v0.16.0
sigs.k8s.io/yaml v1.4.0
go.yaml.in/yaml/v2 v2.4.2
gopkg.in/evanphx/json-patch.v4 v4.13.0
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7
sigs.k8s.io/kustomize/kyaml v0.21.1
sigs.k8s.io/yaml v1.5.0
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/google/gnostic-models v0.6.9 // 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/sergi/go-diff v1.4.0 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
golang.org/x/sys v0.13.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
go.yaml.in/yaml/v3 v3.0.3 // indirect
golang.org/x/sys v0.35.0 // indirect
google.golang.org/protobuf v1.36.5 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

View File

@@ -1,37 +1,31 @@
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/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
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/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/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
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 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g=
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
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/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/google/gnostic-models v0.6.9 h1:MU/8wDLif2qCXZmzncUQ/BOfxWfthHi63KqpoNbWqVw=
github.com/google/gnostic-models v0.6.9/go.mod h1:CiWsm0s6BSQd1hRn8/QmxqB6BesYcbSZxsz9b0KuDBw=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
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.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
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.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
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=
@@ -40,53 +34,52 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
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/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
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/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw=
github.com/sergi/go-diff v1.4.0/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
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/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
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/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
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=
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.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
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.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
go.yaml.in/yaml/v3 v3.0.3 h1:bXOww4E/J3f66rav3pX3m8w6jDE4knZjGOw8b5Y6iNE=
go.yaml.in/yaml/v3 v3.0.3/go.mod h1:tBHosrYAkRZjRAOREWbDnBXUf08JOwYq++0QNwQiWzI=
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
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.v5 v5.6.0 h1:BMT6KIwBD9CaU91PJCZIe46bDmBWa9ynTQgJIOpfQBk=
gopkg.in/evanphx/json-patch.v5 v5.6.0/go.mod h1:/kvTRh1TVm5wuM6OkHxqXtE/1nUZZpihg29RtuIyfvk=
gopkg.in/evanphx/json-patch.v4 v4.13.0 h1:czT3CmqEaQ1aanPc5SdlgQrrEIb8w/wwCvWWnfEbYzo=
gopkg.in/evanphx/json-patch.v4 v4.13.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/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/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=
k8s.io/kube-openapi v0.0.0-20230601164746-7562a1006961 h1:pqRVJGQJz6oeZby8qmPKXYIBjyrcv7EHCe/33UkZMYA=
k8s.io/kube-openapi v0.0.0-20230601164746-7562a1006961/go.mod h1:l8HTwL5fqnlns4jOveW1L75eo7R9KFHxiE0bsPGy428=
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7 h1:hcha5B1kVACrLujCKLbr8XWMxCxzQx42DY8QKYJrDLg=
k8s.io/kube-openapi v0.0.0-20241212222426-2c72e554b1e7/go.mod h1:GewRfANuJ70iYzvn+i4lezLDAFzvjxZYK1gn1lWcfas=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
sigs.k8s.io/kustomize/kyaml v0.16.0 h1:6J33uKSoATlKZH16unr2XOhDI+otoe2sR3M8PDzW3K0=
sigs.k8s.io/kustomize/kyaml v0.16.0/go.mod h1:xOK/7i+vmE14N2FdFyugIshB8eF6ALpy7jI87Q2nRh4=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/kustomize/kyaml v0.21.1 h1:IVlbmhC076nf6foyL6Taw4BkrLuEsXUXNpsE+ScX7fI=
sigs.k8s.io/kustomize/kyaml v0.21.1/go.mod h1:hmxADesM3yUN2vbA5z1/YTBnzLJ1dajdqpQonwBL1FQ=
sigs.k8s.io/yaml v1.5.0 h1:M10b2U7aEUY6hRtU870n2VTPgR5RZiL/I6Lcc2F4NUQ=
sigs.k8s.io/yaml v1.5.0/go.mod h1:wZs27Rbxoai4C0f8/9urLZtZtF3avA3gKvGyPdDqTO4=

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

@@ -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

@@ -170,7 +170,7 @@ func (ra *ResAccumulator) FixBackReferences() (err error) {
// Intersection drops the resources which "other" does not have.
func (ra *ResAccumulator) Intersection(other resmap.ResMap) error {
otherIds := other.AllIds()
otherIds := other.AllIds() //nolint:revive
for _, curId := range ra.resMap.AllIds() {
toDelete := true
for _, otherId := range otherIds {

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

@@ -1,6 +1,4 @@
// Code generated by pluginator on AnnotationsTransformer; DO NOT EDIT.
// pluginator {(devel) unknown }
package builtins
import (

View File

@@ -1,6 +1,4 @@
// Code generated by pluginator on ConfigMapGenerator; DO NOT EDIT.
// pluginator {(devel) unknown }
package builtins
import (

View File

@@ -1,6 +1,4 @@
// Code generated by pluginator on HashTransformer; DO NOT EDIT.
// pluginator {(devel) unknown }
package builtins
import (

View File

@@ -1,6 +1,4 @@
// Code generated by pluginator on HelmChartInflationGenerator; DO NOT EDIT.
// pluginator {(devel) unknown }
package builtins
import (
@@ -10,13 +8,16 @@ import (
"os/exec"
"path/filepath"
"regexp"
"slices"
"strings"
"github.com/imdario/mergo"
"sigs.k8s.io/kustomize/api/konfig"
"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"
)
@@ -61,6 +62,9 @@ func (p *HelmChartInflationGeneratorPlugin) Config(
if len(h.GeneralConfig().HelmConfig.ApiVersions) != 0 {
p.HelmChart.ApiVersions = h.GeneralConfig().HelmConfig.ApiVersions
}
if h.GeneralConfig().HelmConfig.Debug {
p.HelmChart.Debug = h.GeneralConfig().HelmConfig.Debug
}
p.h = h
if err = yaml.Unmarshal(config, p); err != nil {
@@ -167,13 +171,17 @@ func (p *HelmChartInflationGeneratorPlugin) runHelmCommand(
fmt.Sprintf("HELM_DATA_HOME=%s/.data", p.ConfigHome)}
cmd.Env = append(os.Environ(), env...)
err := cmd.Run()
errorOutput := stderr.String()
if slices.Contains(args, "--debug") {
errorOutput = " Helm stack trace:\n" + errorOutput + "\nHelm template:\n" + stdout.String() + "\n"
}
if err != nil {
helm := p.h.GeneralConfig().HelmConfig.Command
err = errors.WrapPrefixf(
fmt.Errorf(
"unable to run: '%s %s' with env=%s (is '%s' installed?): %w",
helm, strings.Join(args, " "), env, helm, err),
stderr.String(),
"%s", errorOutput,
)
}
return stdout.Bytes(), err
@@ -201,18 +209,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
}
@@ -272,11 +295,14 @@ func (p *HelmChartInflationGeneratorPlugin) Generate() (rm resmap.ResMap, err er
rm, resMapErr := p.h.ResmapFactory().NewResMapFromBytes(stdout)
if resMapErr == nil {
if err := p.markHelmGeneratedResources(rm); err != nil {
return nil, err
}
return rm, nil
}
// try to remove the contents before first "---" because
// helm may produce messages to stdout before it
r := &kio.ByteReader{Reader: bytes.NewBufferString(string(stdout)), OmitReaderAnnotations: true}
r := &kio.ByteReader{Reader: bytes.NewBuffer(stdout), OmitReaderAnnotations: true}
nodes, err := r.Read()
if err != nil {
return nil, fmt.Errorf("error reading helm output: %w", err)
@@ -287,6 +313,9 @@ func (p *HelmChartInflationGeneratorPlugin) Generate() (rm resmap.ResMap, err er
if err != nil {
return nil, fmt.Errorf("could not parse rnode slice into resource map: %w", err)
}
if err := p.markHelmGeneratedResources(rm); err != nil {
return nil, err
}
return rm, nil
}
return nil, fmt.Errorf("could not parse bytes into resource map: %w", resMapErr)
@@ -312,6 +341,9 @@ func (p *HelmChartInflationGeneratorPlugin) pullCommand() []string {
if p.Version != "" {
args = append(args, "--version", p.Version)
}
if p.Devel {
args = append(args, "--devel")
}
return args
}
@@ -326,9 +358,18 @@ func (p *HelmChartInflationGeneratorPlugin) chartExistsLocally() (string, bool)
return path, s.IsDir()
}
// checkHelmVersion will return an error if the helm version is not V3
func (p *HelmChartInflationGeneratorPlugin) markHelmGeneratedResources(rm resmap.ResMap) error {
for _, r := range rm.Resources() {
if err := r.RNode.PipeE(kyaml.SetAnnotation(konfig.HelmGeneratedAnnotation, "true")); err != nil {
return fmt.Errorf("failed to set helm annotation: %w", err)
}
}
return nil
}
// checkHelmVersion will return an error if the helm version is not V3 or V4
func (p *HelmChartInflationGeneratorPlugin) checkHelmVersion() error {
stdout, err := p.runHelmCommand([]string{"version", "-c", "--short"})
stdout, err := p.runHelmCommand([]string{"version", "--short"})
if err != nil {
return err
}
@@ -344,8 +385,8 @@ func (p *HelmChartInflationGeneratorPlugin) checkHelmVersion() error {
v = v[1:]
}
majorVersion := strings.Split(v, ".")[0]
if majorVersion != "3" {
return fmt.Errorf("this plugin requires helm V3 but got v%s", v)
if majorVersion != "3" && majorVersion != "4" {
return fmt.Errorf("this plugin requires helm V3 or V4 but got v%s", v)
}
return nil
}

View File

@@ -1,6 +1,4 @@
// Code generated by pluginator on IAMPolicyGenerator; DO NOT EDIT.
// pluginator {(devel) unknown }
package builtins
import (

View File

@@ -1,6 +1,4 @@
// Code generated by pluginator on ImageTagTransformer; DO NOT EDIT.
// pluginator {(devel) unknown }
package builtins
import (

View File

@@ -1,6 +1,4 @@
// Code generated by pluginator on LabelTransformer; DO NOT EDIT.
// pluginator {(devel) unknown }
package builtins
import (

View File

@@ -1,12 +1,11 @@
// Code generated by pluginator on NamespaceTransformer; DO NOT EDIT.
// pluginator {(devel) unknown }
package builtins
import (
"fmt"
"sigs.k8s.io/kustomize/api/filters/namespace"
"sigs.k8s.io/kustomize/api/konfig"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/errors"
@@ -14,6 +13,8 @@ import (
)
// Change or set the namespace of non-cluster level resources.
//
//nolint:tagalign
type NamespaceTransformerPlugin struct {
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
@@ -51,6 +52,10 @@ func (p *NamespaceTransformerPlugin) Transform(m resmap.ResMap) error {
// Don't mutate empty objects?
continue
}
if annotations := r.GetAnnotations(konfig.HelmGeneratedAnnotation); annotations[konfig.HelmGeneratedAnnotation] == "true" {
// Don't apply namespace on Helm generated manifest. Helm should take care of it.
continue
}
r.StorePreviousId()
if err := r.ApplyFilter(namespace.Filter{
Namespace: p.Namespace,

View File

@@ -1,12 +1,10 @@
// Code generated by pluginator on PatchJson6902Transformer; DO NOT EDIT.
// pluginator {(devel) unknown }
package builtins
import (
"fmt"
jsonpatch "gopkg.in/evanphx/json-patch.v5"
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

@@ -1,6 +1,4 @@
// Code generated by pluginator on PatchStrategicMergeTransformer; DO NOT EDIT.
// pluginator {(devel) unknown }
package builtins
import (

View File

@@ -1,13 +1,11 @@
// Code generated by pluginator on PatchTransformer; DO NOT EDIT.
// pluginator {(devel) unknown }
package builtins
import (
"fmt"
"strings"
jsonpatch "gopkg.in/evanphx/json-patch.v5"
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"
@@ -24,10 +22,10 @@ type PatchTransformerPlugin struct {
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"`
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 *types.PatchArgs `json:"options,omitempty" yaml:"options,omitempty"`
}
func (p *PatchTransformerPlugin) Config(h *resmap.PluginHelpers, c []byte) error {
@@ -56,8 +54,9 @@ func (p *PatchTransformerPlugin) Config(h *resmap.PluginHelpers, c []byte) error
patchesSM, errSM := h.ResmapFactory().RF().SliceFromBytes([]byte(p.patchText))
patchesJson, errJson := jsonPatchFromBytes([]byte(p.patchText))
if (errSM == nil && errJson == nil) ||
(patchesSM != nil && patchesJson != nil) {
if ((errSM == nil && errJson == nil) ||
(patchesSM != nil && patchesJson != nil)) &&
(len(patchesSM) > 0 && len(patchesJson) > 0) {
return fmt.Errorf(
"illegally qualifies as both an SM and JSON patch: %s",
p.patchSource)
@@ -69,10 +68,14 @@ func (p *PatchTransformerPlugin) Config(h *resmap.PluginHelpers, c []byte) error
if errSM == nil {
p.smPatches = patchesSM
for _, loadedPatch := range p.smPatches {
if p.Options["allowNameChange"] {
if p.Options == nil {
continue
}
if p.Options.AllowNameChange {
loadedPatch.AllowNameChange()
}
if p.Options["allowKindChange"] {
if p.Options.AllowKindChange {
loadedPatch.AllowKindChange()
}
}
@@ -86,7 +89,10 @@ func (p *PatchTransformerPlugin) Transform(m resmap.ResMap) error {
if p.smPatches != nil {
return p.transformStrategicMerge(m)
}
return p.transformJson6902(m)
if p.jsonPatches != nil {
return p.transformJson6902(m)
}
return nil
}
// transformStrategicMerge applies each loaded strategic merge patch

View File

@@ -1,6 +1,4 @@
// Code generated by pluginator on PrefixTransformer; DO NOT EDIT.
// pluginator {(devel) unknown }
package builtins
import (

View File

@@ -1,6 +1,4 @@
// Code generated by pluginator on ReplacementTransformer; DO NOT EDIT.
// pluginator {(devel) unknown }
package builtins
import (
@@ -16,7 +14,7 @@ import (
// Replace values in targets with values from a source
type ReplacementTransformerPlugin struct {
ReplacementList []types.ReplacementField `json:"replacements,omitempty" yaml:"replacements,omitempty"`
Replacements []types.Replacement `json:"omitempty" yaml:"omitempty"`
replacements []types.Replacement
}
func (p *ReplacementTransformerPlugin) Config(
@@ -49,19 +47,19 @@ func (p *ReplacementTransformerPlugin) Config(
if err := yaml.Unmarshal(content, &repl); err != nil {
return err
}
p.Replacements = append(p.Replacements, repl...)
p.replacements = append(p.replacements, repl...)
case reflect.Map:
repl := types.Replacement{}
if err := yaml.Unmarshal(content, &repl); err != nil {
return err
}
p.Replacements = append(p.Replacements, repl)
p.replacements = append(p.replacements, repl)
default:
return fmt.Errorf("unsupported replacement type encountered within replacement path: %v", items.Kind())
}
} else {
// replacement information is already loaded
p.Replacements = append(p.Replacements, r.Replacement)
p.replacements = append(p.replacements, r.Replacement)
}
}
return nil
@@ -69,7 +67,7 @@ func (p *ReplacementTransformerPlugin) Config(
func (p *ReplacementTransformerPlugin) Transform(m resmap.ResMap) (err error) {
return m.ApplyFilter(replacement.Filter{
Replacements: p.Replacements,
Replacements: p.replacements,
})
}

View File

@@ -1,6 +1,4 @@
// Code generated by pluginator on ReplicaCountTransformer; DO NOT EDIT.
// pluginator {(devel) unknown }
package builtins
import (

View File

@@ -1,6 +1,4 @@
// Code generated by pluginator on SecretGenerator; DO NOT EDIT.
// pluginator {(devel) unknown }
package builtins
import (

View File

@@ -1,6 +1,4 @@
// Code generated by pluginator on SortOrderTransformer; DO NOT EDIT.
// pluginator {(devel) unknown }
package builtins
import (
@@ -74,34 +72,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 +97,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 +120,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 +134,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) {
@@ -160,6 +149,9 @@ func gvkLessThan(gvk1, gvk2 resid.Gvk, typeOrders map[string]int) bool {
if index1 != index2 {
return index1 < index2
}
if (gvk1.Kind == types.NamespaceKind && gvk2.Kind == types.NamespaceKind) && (gvk1.Group == "" || gvk2.Group == "") {
return legacyGVKSortString(gvk1) > legacyGVKSortString(gvk2)
}
return legacyGVKSortString(gvk1) < legacyGVKSortString(gvk2)
}

View File

@@ -1,6 +1,4 @@
// Code generated by pluginator on SuffixTransformer; DO NOT EDIT.
// pluginator {(devel) unknown }
package builtins
import (

View File

@@ -1,6 +1,4 @@
// Code generated by pluginator on ValueAddTransformer; DO NOT EDIT.
// pluginator {(devel) unknown }
package builtins
import (

View File

@@ -10,9 +10,13 @@ images:
create: true
- path: spec/initContainers[]/image
create: true
- path: spec/volumes[]/image/reference
create: true
- path: spec/template/spec/containers[]/image
create: true
- path: spec/template/spec/initContainers[]/image
create: true
- path: spec/template/spec/volumes[]/image/reference
create: true
`
)

View File

@@ -421,6 +421,13 @@ nameReference:
fieldSpecs:
- path: spec/ingressClassName
kind: Ingress
- kind: ValidatingAdmissionPolicy
group: admissionregistration.k8s.io
fieldSpecs:
- path: spec/policyName
kind: ValidatingAdmissionPolicyBinding
group: admissionregistration.k8s.io
`
)

View File

@@ -169,7 +169,7 @@ func (fl *FileLoader) New(path string) (ifc.Loader, error) {
}
root, err := filesys.ConfirmDir(fl.fSys, fl.root.Join(path))
if err != nil {
return nil, errors.WrapPrefixf(err, ErrRtNotDir.Error())
return nil, errors.WrapPrefixf(err, "%s", ErrRtNotDir.Error())
}
if err = fl.errIfGitContainmentViolation(root); err != nil {
return nil, err
@@ -311,7 +311,11 @@ func (fl *FileLoader) httpClientGetContent(path string) ([]byte, error) {
} else {
hc = &http.Client{}
}
resp, err := hc.Get(path)
parsedURL, err := url.ParseRequestURI(path)
if err != nil {
return nil, errors.Wrap(err)
}
resp, err := hc.Get(parsedURL.String())
if err != nil {
return nil, errors.Wrap(err)
}

View File

@@ -676,3 +676,15 @@ func setupOnDisk(t *testing.T) (filesys.FileSystem, filesys.ConfirmedDir) {
})
return fSys, dir
}
// TestLoaderHTTPMalformedURL tests that malformed URLs are properly handled
// to prevent infinite loops in http.Client.Get
func TestLoaderHTTPMalformedURL(t *testing.T) {
require := require.New(t)
malformedURL := "https://example.com/example?ref=main - ../../example/example.yaml"
l1 := NewLoaderOrDie(
RestrictionRootOnly, MakeFakeFs([]testData{}), filesys.Separator)
_, err := l1.Load(malformedURL)
require.Error(err)
require.Equal("HTTP Error: status code 400 (Bad Request)", err.Error())
}

View File

@@ -28,7 +28,7 @@ func NewLoader(
}
root, err := filesys.ConfirmDir(fSys, target)
if err != nil {
return nil, errors.WrapPrefixf(err, ErrRtNotDir.Error())
return nil, errors.WrapPrefixf(err, "%s", ErrRtNotDir.Error())
}
return newLoaderAtConfirmedDir(
lr, root, fSys, nil, git.ClonerUsingGitExec), nil

View File

@@ -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

@@ -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,6 +5,7 @@ package builtinconfig
import (
"reflect"
"strings"
"testing"
"sigs.k8s.io/kustomize/api/internal/loader"
@@ -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

@@ -15,12 +15,15 @@ import (
)
// TransformerConfig holds the data needed to perform transformations.
//
//nolint:tagalign
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"`
@@ -41,6 +44,7 @@ func (t *TransformerConfig) DeepCopy() *TransformerConfig {
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(),
@@ -94,6 +98,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)
@@ -114,12 +119,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)
@@ -162,6 +173,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,51 +103,43 @@ 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) {
@@ -182,9 +150,7 @@ func TestMakeDefaultConfig_mutation(t *testing.T) {
a.NameReference = a.NameReference[:1]
clean := MakeDefaultConfig()
if clean.NameReference[0].Kind == "mutated" {
t.Errorf("MakeDefaultConfig() did not return a clean copy: %+v", clean.NameReference)
}
assert.NotEqualf(t, "mutated", clean.NameReference[0].Kind, "MakeDefaultConfig() did not return a clean copy: %+v", clean.NameReference)
}
func BenchmarkMakeDefaultConfig(b *testing.B) {

View File

@@ -6,13 +6,12 @@ package execplugin
import (
"bytes"
"fmt"
"log"
"os"
"os/exec"
"runtime"
"strings"
"github.com/google/shlex"
"sigs.k8s.io/kustomize/api/internal/plugins/utils"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/kyaml/errors"
@@ -21,6 +20,7 @@ import (
const (
tmpConfigFilePrefix = "kust-plugin-config-"
maxArgStringLength = 131071
)
// ExecPlugin record the name and args of an executable
@@ -93,7 +93,11 @@ func (p *ExecPlugin) processOptionalArgsFields() error {
return err
}
if c.ArgsOneLiner != "" {
p.args, _ = shlex.Split(c.ArgsOneLiner)
argsTolenSlice, err := ShlexSplit(c.ArgsOneLiner)
if err != nil {
return fmt.Errorf("failed to parse argsOneLiner: %w", err)
}
p.args = argsTolenSlice
}
if c.ArgsFromFile != "" {
content, err := p.h.Loader().Load(c.ArgsFromFile)
@@ -157,35 +161,46 @@ func (p *ExecPlugin) invokePlugin(input []byte) ([]byte, error) {
_, err = f.Write(p.cfg)
if err != nil {
return nil, errors.WrapPrefixf(
err, "writing plugin config to "+f.Name())
err, "writing plugin config to %s", f.Name())
}
err = f.Close()
if err != nil {
return nil, errors.WrapPrefixf(
err, "closing plugin config file "+f.Name())
err, "closing plugin config file %s", f.Name())
}
//nolint:gosec
cmd := exec.Command(
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),
"%s", 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

@@ -20,6 +20,12 @@ import (
"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 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package execplugin
import (
"fmt"
"strings"
"unicode"
)
// ShlexSplit splits a string into a slice of strings using shell-style rules for quoting and commenting
// Similar to Python's shlex.split with comments enabled
func ShlexSplit(s string) ([]string, error) {
return shlexSplit(s)
}
func shlexSplit(s string) ([]string, error) {
result := []string{}
// noQuote is used to track if we are not in a quoted
const noQuote = 0
var current strings.Builder
var quote rune = noQuote
var escaped bool
for _, r := range s {
switch {
case escaped:
current.WriteRune(r)
escaped = false
case r == '\\' && quote != '\'':
escaped = true
case (r == '\'' || r == '"') && quote == noQuote:
quote = r
case r == quote:
quote = noQuote
case r == '#' && quote == noQuote:
// Comment starts, ignore the rest of the line
if current.Len() > 0 {
result = append(result, current.String())
}
return result, nil
case unicode.IsSpace(r) && quote == noQuote:
if current.Len() > 0 {
result = append(result, current.String())
current.Reset()
}
default:
current.WriteRune(r)
}
}
if quote != noQuote {
return nil, fmt.Errorf("unclosed quote in string")
}
if current.Len() > 0 {
result = append(result, current.String())
}
return result, nil
}

View File

@@ -0,0 +1,183 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package execplugin
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestShlexSplit(t *testing.T) {
testCases := []struct {
name string
input string
expected []string
wantErr bool
}{
{
name: "basic space separation",
input: `hello world`,
expected: []string{"hello", "world"},
wantErr: false,
},
{
name: "double quoted string",
input: `"hello world"`,
expected: []string{"hello world"},
wantErr: false,
},
{
name: "single quoted string",
input: `'hello world'`,
expected: []string{"hello world"},
wantErr: false,
},
{
name: "mixed quotes and words",
input: `hello "world test"`,
expected: []string{"hello", "world test"},
wantErr: false,
},
{
name: "single quotes with spaces",
input: `hello 'world test'`,
expected: []string{"hello", "world test"},
wantErr: false,
},
{
name: "nested quotes - single in double",
input: `"hello 'nested' world"`,
expected: []string{"hello 'nested' world"},
wantErr: false,
},
{
name: "nested quotes - double in single",
input: `'hello "nested" world'`,
expected: []string{"hello \"nested\" world"},
wantErr: false,
},
{
name: "escaped space",
input: `hello\ world`,
expected: []string{"hello world"},
wantErr: false,
},
{
name: "escaped quotes in double quotes",
input: `"hello \"world\""`,
expected: []string{"hello \"world\""},
wantErr: false,
},
{
name: "single quote in single quotes",
input: `'can'\''t'`,
expected: []string{"can't"},
wantErr: false,
},
{
name: "complex argument list",
input: `arg1 "arg 2" 'arg 3' arg4`,
expected: []string{"arg1", "arg 2", "arg 3", "arg4"},
wantErr: false,
},
{
name: "echo command with escaped quotes",
input: `echo "Hello, \"World!\""`,
expected: []string{"echo", "Hello, \"World!\""},
wantErr: false,
},
{
name: "grep command with quoted search term",
input: `grep -r "search term" /path/to/dir`,
expected: []string{"grep", "-r", "search term", "/path/to/dir"},
wantErr: false,
},
{
name: "ls command with quoted filename",
input: `ls -la "file with spaces.txt"`,
expected: []string{"ls", "-la", "file with spaces.txt"},
wantErr: false,
},
{
name: "empty string",
input: ``,
expected: []string{},
wantErr: false,
},
{
name: "multiple spaces",
input: ` multiple spaces `,
expected: []string{"multiple", "spaces"},
wantErr: false,
},
{
name: "with comment string",
input: `echo "Hello, W#orld!" ${USER} # This is a comment`,
expected: []string{"echo", "Hello, W#orld!", "${USER}"},
wantErr: false,
},
{
name: "comment only",
input: `# this line is just a comment`,
expected: []string{},
wantErr: false,
},
// may cause an error in shlex at python3
{
name: "unclosed double quote",
input: `"unclosed quote`,
expected: nil,
wantErr: true,
},
{
name: "unclosed single quote",
input: `'unclosed quote`,
expected: nil,
wantErr: true,
},
{
name: "mixed unclosed quotes",
input: `"mixed 'quotes`,
expected: nil,
wantErr: true,
},
{
name: "single quote closed with double quote",
input: `"hello world'`,
expected: nil,
wantErr: true,
},
{
name: "double quote closed with single quote",
input: `'hello world"`,
expected: nil,
wantErr: true,
},
}
// execute each test case
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
// call the ShlexSplit function
result, err := ShlexSplit(tc.input)
// check for expected error
if tc.wantErr {
if err == nil {
t.Errorf("FAIL: Expected error but got none, Expected: %q\n", tc.expected)
}
return
}
if assert.NoError(t, err, "FAIL: Unexpected error %q for input %q", err, tc.input) {
// check if the result matches the expected output
assert.Equal(t, tc.expected, result,
"FAIL: Result mismatch,Input %q, Expected %q, Got: %q\n",
tc.input, tc.expected, result,
)
}
})
}
}

View File

@@ -77,7 +77,6 @@ func NewFnPlugin(o *types.FnPluginLoadingOptions) *FnPlugin {
runFns: runfn.RunFns{
Functions: []*yaml.RNode{},
Network: o.Network,
EnableStarlark: o.EnableStar,
EnableExec: o.EnableExec,
StorageMounts: toStorageMounts(o.Mounts),
Env: o.Env,

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"
@@ -38,7 +34,8 @@ type Loader struct {
}
func NewLoader(
pc *types.PluginConfig, rf *resmap.Factory, fs filesys.FileSystem) *Loader {
pc *types.PluginConfig, rf *resmap.Factory, fs filesys.FileSystem,
) *Loader {
return &Loader{pc: pc, rf: rf, fs: fs}
}
@@ -62,7 +59,8 @@ func (l *Loader) Config() *types.PluginConfig {
func (l *Loader) LoadGenerators(
ldr ifc.Loader, v ifc.Validator, rm resmap.ResMap) (
result []*resmap.GeneratorWithProperties, err error) {
result []*resmap.GeneratorWithProperties, err error,
) {
for _, res := range rm.Resources() {
g, err := l.LoadGenerator(ldr, v, res)
if err != nil {
@@ -78,7 +76,8 @@ func (l *Loader) LoadGenerators(
}
func (l *Loader) LoadGenerator(
ldr ifc.Loader, v ifc.Validator, res *resource.Resource) (resmap.Generator, error) {
ldr ifc.Loader, v ifc.Validator, res *resource.Resource,
) (resmap.Generator, error) {
c, err := l.loadAndConfigurePlugin(ldr, v, res)
if err != nil {
return nil, err
@@ -91,7 +90,8 @@ func (l *Loader) LoadGenerator(
}
func (l *Loader) LoadTransformers(
ldr ifc.Loader, v ifc.Validator, rm resmap.ResMap) ([]*resmap.TransformerWithProperties, error) {
ldr ifc.Loader, v ifc.Validator, rm resmap.ResMap,
) ([]*resmap.TransformerWithProperties, error) {
var result []*resmap.TransformerWithProperties
for _, res := range rm.Resources() {
t, err := l.LoadTransformer(ldr, v, res)
@@ -108,7 +108,8 @@ func (l *Loader) LoadTransformers(
}
func (l *Loader) LoadTransformer(
ldr ifc.Loader, v ifc.Validator, res *resource.Resource) (*resmap.TransformerWithProperties, error) {
ldr ifc.Loader, v ifc.Validator, res *resource.Resource,
) (*resmap.TransformerWithProperties, error) {
c, err := l.loadAndConfigurePlugin(ldr, v, res)
if err != nil {
return nil, err
@@ -183,7 +184,8 @@ func isBuiltinPlugin(res *resource.Resource) bool {
func (l *Loader) loadAndConfigurePlugin(
ldr ifc.Loader,
v ifc.Validator,
res *resource.Resource) (c resmap.Configurable, err error) {
res *resource.Resource,
) (c resmap.Configurable, err error) {
if isBuiltinPlugin(res) {
switch l.pc.BpLoadingOptions {
case types.BploLoadFromFileSys:
@@ -196,7 +198,7 @@ func (l *Loader) loadAndConfigurePlugin(
c, err = l.makeBuiltinPlugin(res.GetGvk())
default:
err = fmt.Errorf(
"unknown plugin loader behavior specified: %v",
"unknown plugin loader behavior specified: %s %v", res.GetGvk().String(),
l.pc.BpLoadingOptions)
}
} else {
@@ -249,7 +251,7 @@ func (l *Loader) loadPlugin(res *resource.Resource) (resmap.Configurable, error)
return nil, errors.Errorf("plugin %s with mount path '%s' is not permitted; "+
"mount paths must be relative to the current kustomization directory", res.OrgId(), mount.Src)
}
if strings.HasPrefix(filepath.Clean(mount.Src), "../") {
if strings.HasPrefix(filepath.Clean(mount.Src), "..") {
return nil, errors.Errorf("plugin %s with mount path '%s' is not permitted; "+
"mount paths must be under the current kustomization directory", res.OrgId(), mount.Src)
}
@@ -286,47 +288,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

@@ -18,7 +18,6 @@ import (
)
const (
//nolint:gosec
secretGenerator = `
apiVersion: builtin
kind: SecretGenerator
@@ -96,3 +95,43 @@ func TestLoaderWithWorkingDir(t *testing.T) {
npLdr.Config().FnpLoadingOptions.WorkingDir,
"the plugin working dir is not updated")
}
func TestLoaderWithStorageMounts(t *testing.T) {
const storageMountTransformer = `
apiVersion: com.example.kustomize/v1
kind: Test
metadata:
name: test-transformer
annotations:
config.kubernetes.io/function: |
container:
image: test
mounts:
- type: bind
src: ../
dst: /mount
`
p := provider.NewDefaultDepProvider()
rmF := resmap.NewFactory(p.GetResourceFactory())
fsys := filesys.MakeFsInMemory()
fLdr, err := loader.NewLoader(
loader.RestrictionRootOnly,
filesys.Separator, fsys)
if err != nil {
t.Fatal(err)
}
configs, err := rmF.NewResMapFromBytes([]byte(storageMountTransformer))
if err != nil {
t.Fatal(err)
}
c := types.EnabledPluginConfig(types.BploLoadFromFileSys)
pLdr := NewLoader(c, rmF, fsys)
if pLdr == nil {
t.Fatal("expect non-nil loader")
}
_, err = pLdr.LoadTransformers(
fLdr, valtest_test.MakeFakeValidator(), configs)
if err == nil { // should fail because src specified is outside root
t.Fatal("the loader allowed a mount outside root")
}
}

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
@@ -97,8 +99,8 @@ func TestUpdateResourceOptions(t *testing.T) {
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

@@ -29,13 +29,14 @@ import (
// KustTarget encapsulates the entirety of a kustomization build.
type KustTarget struct {
kustomization *types.Kustomization
kustFileName string
ldr ifc.Loader
validator ifc.Validator
rFactory *resmap.Factory
pLdr *loader.Loader
origin *resource.Origin
kustomization *types.Kustomization
kustFileName string
ldr ifc.Loader
validator ifc.Validator
rFactory *resmap.Factory
pLdr *loader.Loader
origin *resource.Origin
helmRootNamespace string // namespace inherited from parent kustomization for HelmCharts
}
// NewKustTarget returns a new instance of KustTarget.
@@ -425,7 +426,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(
@@ -442,9 +450,6 @@ func (kt *KustTarget) accumulateResources(
ra, err = kt.accumulateDirectory(ra, ldr, false)
}
if err != nil {
if kusterr.IsMalformedYAMLError(errF) { // Some error occurred while tyring to decode YAML file
return nil, errF
}
return nil, errors.WrapPrefixf(
err, "accumulation err='%s'", errF.Error())
}
@@ -453,7 +458,7 @@ func (kt *KustTarget) accumulateResources(
return ra, nil
}
// accumulateResources fills the given resourceAccumulator
// accumulateComponents fills the given resourceAccumulator
// with resources read from the given list of paths.
func (kt *KustTarget) accumulateComponents(
ra *accumulator.ResAccumulator, paths []string) (*accumulator.ResAccumulator, error) {
@@ -492,6 +497,16 @@ func (kt *KustTarget) accumulateDirectory(
}
subKt.kustomization.BuildMetadata = kt.kustomization.BuildMetadata
subKt.origin = kt.origin
// Propagate namespace to child kustomization's helmRootNamespace for HelmCharts
// This ensures Helm charts in base kustomizations inherit namespace from overlays
// without affecting other transformers like patches
// Fixes https://github.com/kubernetes-sigs/kustomize/issues/6031
// Fixes https://github.com/kubernetes-sigs/kustomize/issues/6027
if kt.kustomization.Namespace != "" {
subKt.helmRootNamespace = kt.kustomization.Namespace
} else if kt.helmRootNamespace != "" {
subKt.helmRootNamespace = kt.helmRootNamespace
}
var bytes []byte
if openApiPath, exists := subKt.Kustomization().OpenAPI["path"]; exists {
bytes, err = ldr.Load(openApiPath)

View File

@@ -166,6 +166,16 @@ var generatorConfigurators = map[builtinhelpers.BuiltinPluginType]func(
for _, chart := range kt.kustomization.HelmCharts {
c.HelmGlobals = globals
c.HelmChart = chart
// Pass kustomize namespace to helm
// Fixes https://github.com/kubernetes-sigs/kustomize/issues/5566
// Also propagate parent namespace for multi-level kustomization hierarchies
if c.HelmChart.Namespace == "" {
if kt.kustomization.Namespace != "" {
c.HelmChart.Namespace = kt.kustomization.Namespace
} else if kt.helmRootNamespace != "" {
c.HelmChart.Namespace = kt.helmRootNamespace
}
}
p := f()
if err = kt.configureBuiltinPlugin(p, c, bpt); err != nil {
return nil, err
@@ -250,10 +260,10 @@ var transformerConfigurators = map[builtinhelpers.BuiltinPluginType]func(
return
}
var c struct {
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"`
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 *types.PatchArgs `json:"options,omitempty" yaml:"options,omitempty"`
}
for _, pc := range kt.kustomization.Patches {
c.Target = pc.Target
@@ -275,13 +285,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 +319,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 +329,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

@@ -6,13 +6,17 @@ package target_test
import (
"encoding/base64"
"fmt"
"net/http"
"net/http/httptest"
"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/internal/utils"
"sigs.k8s.io/kustomize/api/pkg/loader"
"sigs.k8s.io/kustomize/api/provider"
"sigs.k8s.io/kustomize/api/resmap"
@@ -189,13 +193,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",
@@ -204,30 +262,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",
},
@@ -235,65 +283,37 @@ 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()
require.NoError(t, expected.RemoveTransformerAnnotations())
require.NoError(t, expected.RemoveOriginAnnotations())
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()
require.NoError(t, actual.RemoveTransformerAnnotations())
require.NoError(t, actual.RemoveOriginAnnotations())
actYaml, err := actual.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, string(expYaml), string(actYaml))
}
@@ -313,19 +333,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", `
@@ -350,37 +372,51 @@ 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)
require.NoError(t, err)
}
expected.RemoveBuildAnnotations()
require.NoError(t, expected.RemoveTransformerAnnotations())
require.NoError(t, expected.RemoveOriginAnnotations())
expYaml, err := expected.AsYaml()
require.NoError(t, err)
@@ -389,6 +425,8 @@ metadata:
actual, err := kt.MakeCustomizedResMap()
require.NoError(t, err)
actual.RemoveBuildAnnotations()
require.NoError(t, actual.RemoveTransformerAnnotations())
require.NoError(t, actual.RemoveOriginAnnotations())
actYaml, err := actual.AsYaml()
require.NoError(t, err)
require.Equal(t, string(expYaml), string(actYaml))
@@ -423,7 +461,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")
}
@@ -452,6 +490,151 @@ 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
}
func TestErrorMessageForMalformedYAMLAndInvalidBase(t *testing.T) {
// These testcases verify behavior for the scenario described in
// https://github.com/kubernetes-sigs/kustomize/issues/5692 .
// Use a test server to fake the remote file response
handler := http.NewServeMux()
handler.HandleFunc("/", func(out http.ResponseWriter, req *http.Request) {
// Per issue #5692, the server should return a 200 status code with a response body that fails to parse as YAML
out.WriteHeader(http.StatusOK)
_, _ = out.Write([]byte(`<!DOCTYPE html>
<html class="html-devise-layout ui-light-gray" lang="en">
<head prefix="og: http://ogp.me/ns#">`))
})
svr := httptest.NewServer(handler)
defer svr.Close()
th := kusttest_test.MakeHarness(t)
th.WriteF("/should-fail/kustomization.yml", "resources:\n- "+svr.URL)
th.WriteF("/should-fail/remote-repo/kustomization.yml", "this: is not a kustomization file!")
ldrWrapper := func(baseLoader ifc.Loader) ifc.Loader {
return &loaderWithRenamedRoots{
baseLoader: baseLoader,
fakeRootMap: map[string]string{
// Use the "remote-repo" subdir instead of the remote git repo
svr.URL: "remote-repo",
},
}
}
_, err := makeAndLoadKustTargetWithLoaderOverride(t, th.GetFSys(), "/should-fail", ldrWrapper).AccumulateTarget()
require.Error(t, err)
errString := err.Error()
assert.Contains(t, errString, "accumulating resources from '"+svr.URL+"'")
assert.Contains(t, errString, "MalformedYAMLError: yaml: line 3: mapping values are not allowed in this context")
assert.Contains(t, errString, `invalid Kustomization: json: unknown field "this"`)
}
// loaderWithRenamedRoots is a loader that can map New() roots to some other name
type loaderWithRenamedRoots struct {
baseLoader ifc.Loader
fakeRootMap map[string]string
}
func (l loaderWithRenamedRoots) Repo() string {
return l.baseLoader.Repo()
}
func (l loaderWithRenamedRoots) Root() string {
return l.baseLoader.Root()
}
func (l loaderWithRenamedRoots) New(newRoot string) (ifc.Loader, error) {
if otherRoot, ok := l.fakeRootMap[newRoot]; ok {
return l.baseLoader.New(otherRoot) //nolint:wrapcheck // baseLoader's error is sufficient
}
return l.baseLoader.New(newRoot) //nolint:wrapcheck // baseLoader's error is sufficient
}
func (l loaderWithRenamedRoots) Load(path string) ([]byte, error) {
return l.baseLoader.Load(path) //nolint:wrapcheck // baseLoader's error is sufficient
}
func (l loaderWithRenamedRoots) Cleanup() error {
return l.baseLoader.Cleanup() //nolint:wrapcheck // baseLoader's error is sufficient
}

View File

@@ -6,6 +6,7 @@ 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"
@@ -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

@@ -46,4 +46,7 @@ const (
// Label key that indicates the resources are validated by a validator
ValidatedByLabelKey = "validated-by"
// Annotation key for marking helm-generated resources to skip namespace transformation
HelmGeneratedAnnotation = ConfigAnnoDomain + "/helm-generated"
)

View File

@@ -5,6 +5,8 @@ package krusty_test
import (
"fmt"
"net/http"
"net/http/httptest"
"path/filepath"
"regexp"
"strings"
@@ -29,6 +31,20 @@ spec:
- 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", `
@@ -169,10 +185,15 @@ spec:
func TestAccumulateResourcesErrors(t *testing.T) {
type testcase struct {
name string
resource string
isAbsolute bool
files map[string]string
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
@@ -221,9 +242,14 @@ resources:
for _, test := range []testcase{
{
name: "remote file not considered repo",
// The example.com second-level domain is reserved and
// safe to access, see RFC 2606.
resource: "https://example.com/segments-too-few-to-be-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
@@ -231,8 +257,15 @@ resources:
errFile: `HTTP Error: status code 404 \(Not Found\)\z`,
},
{
name: "remote file qualifies as repo",
resource: "https://example.com/long/enough/to/have/org/and/repo",
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.
@@ -283,8 +316,29 @@ resources:
// 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)
@@ -306,5 +360,4 @@ resources:
// TODO(annasong): add tests that check accumulateResources errors for
// - repos
// - local directories
// - files that yield malformed yaml errors
}

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

@@ -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,12 +4,14 @@
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"
@@ -65,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
@@ -90,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:
@@ -104,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:
@@ -138,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) {
@@ -149,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
@@ -180,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:
@@ -193,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:
@@ -229,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) {
@@ -240,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
@@ -271,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:
@@ -284,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:
@@ -320,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) {
@@ -331,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
@@ -352,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
@@ -366,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:
@@ -375,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) {
@@ -386,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
@@ -413,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
@@ -427,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:
@@ -436,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) {
@@ -447,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
@@ -474,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
@@ -488,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:
@@ -497,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) {
@@ -512,7 +514,7 @@ 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
@@ -545,12 +547,12 @@ metadata:
"-t", "gcr.io/kustomize-functions/e2econtainersimplegenerator",
)
build.Dir = repoRootDir
assert.NoError(t, build.Run())
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: simplegenerator
@@ -577,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
@@ -605,10 +607,10 @@ metadata:
"-t", "gcr.io/kustomize-functions/e2econtainerconfig",
)
build.Dir = repoRootDir
assert.NoError(t, build.Run())
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:
@@ -627,33 +629,33 @@ func TestFnContainerTransformerWithConfig(t *testing.T) {
"-f", "build/label_namespace.Dockerfile",
"-t", "gcr.io/kpt-functions/label-namespace:go-sdk-v0.0.1",
)
assert.NoError(t, build.Run())
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:
@@ -669,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:
@@ -695,12 +697,12 @@ 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(`
require.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "gener.yaml"), []byte(`
apiVersion: kustomize.sigs.k8s.io/v1alpha1
kind: EnvTemplateGenerator
metadata:
@@ -724,14 +726,14 @@ template: |
"-t", "gcr.io/kustomize-functions/e2econtainerenvgenerator",
)
build.Dir = repoRootDir
assert.NoError(t, build.Run())
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
@@ -748,12 +750,12 @@ 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(`
require.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "gener.yaml"), []byte(`
apiVersion: kustomize.sigs.k8s.io/v1alpha1
kind: RenderHelmChart
metadata:
@@ -768,8 +770,8 @@ metadata:
dst: "/tmp/yaml"
path: /tmp/yaml/resources.yaml
`)))
assert.NoError(t, fSys.MkdirAll(filepath.Join(tmpDir.String(), "yaml", "tmp")))
assert.NoError(t, fSys.WriteFile(filepath.Join(tmpDir.String(), "yaml", "resources.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:
@@ -782,14 +784,14 @@ spec:
"-t", "gcr.io/kustomize-functions/e2econtainermountbind",
)
build.Dir = repoRootDir
assert.NoError(t, build.Run())
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:
@@ -806,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
@@ -826,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")
@@ -839,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
@@ -859,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")
@@ -887,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

@@ -21,10 +21,31 @@ kind: Secret
metadata:
labels:
app: test-minecraft
chart: minecraft-3.1.3
app.kubernetes.io/instance: test-minecraft
app.kubernetes.io/name: minecraft
app.kubernetes.io/version: 4.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test
name: test-minecraft
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.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test
name: test-minecraft-curseforge
namespace: default
type: Opaque
---
apiVersion: v1
@@ -32,10 +53,14 @@ kind: Service
metadata:
labels:
app: test-minecraft
chart: minecraft-3.1.3
app.kubernetes.io/instance: test-minecraft
app.kubernetes.io/name: minecraft
app.kubernetes.io/version: 4.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test
name: test-minecraft
namespace: default
spec:
ports:
- name: minecraft
@@ -150,7 +175,7 @@ func TestHelmChartInflationGeneratorOld(t *testing.T) {
helmChartInflationGenerator:
- chartName: minecraft
chartRepoUrl: https://itzg.github.io/minecraft-server-charts
chartVersion: 3.1.3
chartVersion: 4.26.4
releaseName: test
`)
@@ -158,6 +183,54 @@ helmChartInflationGenerator:
th.AssertActualEqualsExpected(m, expectedHelm)
}
func TestHelmChartNamespacePropagation(t *testing.T) {
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t)
defer th.Reset()
if err := th.ErrIfNoHelm(); err != nil {
t.Skip("skipping: " + err.Error())
}
chartDir := filepath.Join(th.GetRoot(), "charts", "service")
require.NoError(t, th.GetFSys().MkdirAll(filepath.Join(chartDir, "templates")))
th.WriteF(filepath.Join(chartDir, "Chart.yaml"), `
apiVersion: v2
name: service
type: application
version: 1.0.0
`)
th.WriteF(filepath.Join(chartDir, "values.yaml"), ``)
th.WriteF(filepath.Join(chartDir, "templates", "service.yaml"), `
apiVersion: v1
kind: Service
metadata:
name: the-bug
namespace: {{ .Release.Namespace }}
annotations:
this-service-is-deployed-in-namespace: {{ .Release.Namespace }}
`)
th.WriteF(filepath.Join(th.GetRoot(), "values.yaml"), ``)
th.WriteK(th.GetRoot(), `
helmGlobals:
chartHome: ./charts
namespace: the-actual-namespace
helmCharts:
- name: service
releaseName: service
valuesFile: values.yaml
`)
m := th.Run(th.GetRoot(), th.MakeOptionsPluginsEnabled())
th.AssertActualEqualsExpected(m, `apiVersion: v1
kind: Service
metadata:
annotations:
this-service-is-deployed-in-namespace: the-actual-namespace
name: the-bug
namespace: the-actual-namespace
`)
}
func TestHelmChartInflationGenerator(t *testing.T) {
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t)
defer th.Reset()
@@ -169,7 +242,7 @@ func TestHelmChartInflationGenerator(t *testing.T) {
helmCharts:
- name: minecraft
repo: https://itzg.github.io/minecraft-server-charts
version: 3.1.3
version: 4.26.4
releaseName: test
`)
@@ -252,7 +325,7 @@ func TestHelmChartProdVsDev(t *testing.T) {
helmCharts:
- name: minecraft
repo: https://itzg.github.io/minecraft-server-charts
version: 3.1.3
version: 4.26.4
releaseName: test
`)
th.WriteK(dirProd, `
@@ -287,10 +360,30 @@ kind: Secret
metadata:
labels:
app: test-minecraft
chart: minecraft-3.1.3
app.kubernetes.io/instance: test-minecraft
app.kubernetes.io/name: minecraft
app.kubernetes.io/version: 4.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test
name: myProd-test-minecraft
name: myProd-test-minecraft-rcon
namespace: prod
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.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test
name: myProd-test-minecraft-curseforge
namespace: prod
type: Opaque
---
@@ -299,7 +392,10 @@ kind: Service
metadata:
labels:
app: test-minecraft
chart: minecraft-3.1.3
app.kubernetes.io/instance: test-minecraft
app.kubernetes.io/name: minecraft
app.kubernetes.io/version: 4.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test
name: myProd-test-minecraft
@@ -325,10 +421,30 @@ kind: Secret
metadata:
labels:
app: test-minecraft
chart: minecraft-3.1.3
app.kubernetes.io/instance: test-minecraft
app.kubernetes.io/name: minecraft
app.kubernetes.io/version: 4.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test
name: myDev-test-minecraft
name: myDev-test-minecraft-rcon
namespace: dev
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.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test
name: myDev-test-minecraft-curseforge
namespace: dev
type: Opaque
---
@@ -337,7 +453,10 @@ kind: Service
metadata:
labels:
app: test-minecraft
chart: minecraft-3.1.3
app.kubernetes.io/instance: test-minecraft
app.kubernetes.io/name: minecraft
app.kubernetes.io/version: 4.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test
name: myDev-test-minecraft
@@ -359,10 +478,30 @@ kind: Secret
metadata:
labels:
app: test-minecraft
chart: minecraft-3.1.3
app.kubernetes.io/instance: test-minecraft
app.kubernetes.io/name: minecraft
app.kubernetes.io/version: 4.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test
name: myProd-test-minecraft
name: myProd-test-minecraft-rcon
namespace: prod
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.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test
name: myProd-test-minecraft-curseforge
namespace: prod
type: Opaque
---
@@ -371,7 +510,10 @@ kind: Service
metadata:
labels:
app: test-minecraft
chart: minecraft-3.1.3
app.kubernetes.io/instance: test-minecraft
app.kubernetes.io/name: minecraft
app.kubernetes.io/version: 4.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test
name: myProd-test-minecraft
@@ -586,11 +728,11 @@ helmCharts:
skipTests: true
- name: minecraft
repo: https://itzg.github.io/minecraft-server-charts
version: 3.1.3
version: 4.26.4
releaseName: test-1
- name: minecraft
repo: https://itzg.github.io/minecraft-server-charts
version: 3.1.4
version: 4.26.4
releaseName: test-2
`)
@@ -621,10 +763,30 @@ kind: Secret
metadata:
labels:
app: test-1-minecraft
chart: minecraft-3.1.3
app.kubernetes.io/instance: test-1-minecraft
app.kubernetes.io/name: minecraft
app.kubernetes.io/version: 4.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test-1
name: test-1-minecraft
name: test-1-minecraft-rcon
namespace: default
type: Opaque
---
apiVersion: v1
data:
cf-api-key: Q0hBTkdFTUUh
kind: Secret
metadata:
labels:
app: test-1-minecraft
app.kubernetes.io/instance: test-1-minecraft
app.kubernetes.io/name: minecraft
app.kubernetes.io/version: 4.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test-1
name: test-1-minecraft-curseforge
namespace: default
type: Opaque
---
@@ -633,7 +795,10 @@ kind: Service
metadata:
labels:
app: test-1-minecraft
chart: minecraft-3.1.3
app.kubernetes.io/instance: test-1-minecraft
app.kubernetes.io/name: minecraft
app.kubernetes.io/version: 4.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test-1
name: test-1-minecraft
@@ -655,10 +820,30 @@ kind: Secret
metadata:
labels:
app: test-2-minecraft
chart: minecraft-3.1.4
app.kubernetes.io/instance: test-2-minecraft
app.kubernetes.io/name: minecraft
app.kubernetes.io/version: 4.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test-2
name: test-2-minecraft
name: test-2-minecraft-rcon
namespace: default
type: Opaque
---
apiVersion: v1
data:
cf-api-key: Q0hBTkdFTUUh
kind: Secret
metadata:
labels:
app: test-2-minecraft
app.kubernetes.io/instance: test-2-minecraft
app.kubernetes.io/name: minecraft
app.kubernetes.io/version: 4.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test-2
name: test-2-minecraft-curseforge
namespace: default
type: Opaque
---
@@ -667,7 +852,10 @@ kind: Service
metadata:
labels:
app: test-2-minecraft
chart: minecraft-3.1.4
app.kubernetes.io/instance: test-2-minecraft
app.kubernetes.io/name: minecraft
app.kubernetes.io/version: 4.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test-2
name: test-2-minecraft
@@ -698,7 +886,7 @@ namespace: default
helmCharts:
- name: minecraft
repo: https://itzg.github.io/minecraft-server-charts
version: 4.11.0
version: 4.26.4
releaseName: test
kubeVersion: "1.16"
valuesInline:
@@ -724,8 +912,8 @@ metadata:
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
app.kubernetes.io/version: 4.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test
name: test-minecraft-rcon
@@ -741,8 +929,8 @@ metadata:
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
app.kubernetes.io/version: 4.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test
name: test-minecraft-curseforge
@@ -756,8 +944,8 @@ metadata:
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
app.kubernetes.io/version: 4.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test
name: test-minecraft
@@ -779,8 +967,8 @@ metadata:
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
app.kubernetes.io/version: 4.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test
name: test-minecraft-map
@@ -794,7 +982,7 @@ namespace: default
helmCharts:
- name: minecraft
repo: https://itzg.github.io/minecraft-server-charts
version: 4.11.0
version: 4.26.4
releaseName: test
kubeVersion: "1.27"
valuesInline:
@@ -820,8 +1008,8 @@ metadata:
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
app.kubernetes.io/version: 4.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test
name: test-minecraft-rcon
@@ -837,8 +1025,8 @@ metadata:
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
app.kubernetes.io/version: 4.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test
name: test-minecraft-curseforge
@@ -852,8 +1040,8 @@ metadata:
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
app.kubernetes.io/version: 4.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test
name: test-minecraft
@@ -875,8 +1063,8 @@ metadata:
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
app.kubernetes.io/version: 4.26.4
chart: minecraft-4.26.4
heritage: Helm
release: test
name: test-minecraft-map
@@ -886,6 +1074,229 @@ spec:
`)
}
func TestHelmChartNamespacePropagationViaResources(t *testing.T) {
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t)
defer th.Reset()
if err := th.ErrIfNoHelm(); err != nil {
t.Skip("skipping: " + err.Error())
}
// Create base directory with helm chart
baseDir := th.MkDir("base")
chartDir := filepath.Join(baseDir, "charts", "service")
require.NoError(t, th.GetFSys().MkdirAll(filepath.Join(chartDir, "templates")))
th.WriteF(filepath.Join(chartDir, "Chart.yaml"), `
apiVersion: v2
name: service
type: application
version: 1.0.0
`)
th.WriteF(filepath.Join(chartDir, "values.yaml"), ``)
th.WriteF(filepath.Join(chartDir, "templates", "service.yaml"), `
apiVersion: v1
kind: Service
metadata:
name: test-service
namespace: {{ .Release.Namespace }}
annotations:
deployed-in-namespace: {{ .Release.Namespace }}
`)
// Base kustomization with helmCharts
th.WriteK(baseDir, `
helmGlobals:
chartHome: ./charts
helmCharts:
- name: service
releaseName: service
`)
// Overlay that references base via resources and sets namespace
overlayDir := th.MkDir("overlay")
th.WriteK(overlayDir, `
namespace: production
resources:
- ../base
`)
m := th.Run(overlayDir, th.MakeOptionsPluginsEnabled())
th.AssertActualEqualsExpected(m, `apiVersion: v1
kind: Service
metadata:
annotations:
deployed-in-namespace: production
name: test-service
namespace: production
`)
}
func TestHelmChartDifferentNamespaces(t *testing.T) {
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t)
defer th.Reset()
if err := th.ErrIfNoHelm(); err != nil {
t.Skip("skipping: " + err.Error())
}
chartDir := filepath.Join(th.GetRoot(), "charts", "service")
require.NoError(t, th.GetFSys().MkdirAll(filepath.Join(chartDir, "templates")))
th.WriteF(filepath.Join(chartDir, "Chart.yaml"), `
apiVersion: v2
name: service
type: application
version: 1.0.0
`)
th.WriteF(filepath.Join(chartDir, "values.yaml"), ``)
th.WriteF(filepath.Join(chartDir, "templates", "service.yaml"), `
apiVersion: v1
kind: Service
metadata:
name: test-service
namespace: {{ .Release.Namespace }}
annotations:
helm-namespace: {{ .Release.Namespace }}
`)
// Test with different namespaces in transformer vs helmCharts.namespace
th.WriteK(th.GetRoot(), `
helmGlobals:
chartHome: ./charts
namespace: transformer-ns
helmCharts:
- name: service
releaseName: service
namespace: helm-ns
`)
m := th.Run(th.GetRoot(), th.MakeOptionsPluginsEnabled())
// helmCharts.namespace should take precedence
th.AssertActualEqualsExpected(m, `apiVersion: v1
kind: Service
metadata:
annotations:
helm-namespace: helm-ns
name: test-service
namespace: helm-ns
`)
}
func TestHelmChartSameNamespace(t *testing.T) {
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t)
defer th.Reset()
if err := th.ErrIfNoHelm(); err != nil {
t.Skip("skipping: " + err.Error())
}
chartDir := filepath.Join(th.GetRoot(), "charts", "service")
require.NoError(t, th.GetFSys().MkdirAll(filepath.Join(chartDir, "templates")))
th.WriteF(filepath.Join(chartDir, "Chart.yaml"), `
apiVersion: v2
name: service
type: application
version: 1.0.0
`)
th.WriteF(filepath.Join(chartDir, "values.yaml"), ``)
th.WriteF(filepath.Join(chartDir, "templates", "service.yaml"), `
apiVersion: v1
kind: Service
metadata:
name: test-service
namespace: {{ .Release.Namespace }}
annotations:
deployed-namespace: {{ .Release.Namespace }}
`)
// Test with same namespace in both places
th.WriteK(th.GetRoot(), `
helmGlobals:
chartHome: ./charts
namespace: shared-namespace
helmCharts:
- name: service
releaseName: service
namespace: shared-namespace
`)
m := th.Run(th.GetRoot(), th.MakeOptionsPluginsEnabled())
th.AssertActualEqualsExpected(m, `apiVersion: v1
kind: Service
metadata:
annotations:
deployed-namespace: shared-namespace
name: test-service
namespace: shared-namespace
`)
}
// Regression test: verify that HelmCharts in base kustomizations
// still receive namespace from overlay after fixing namespace propagation issues.
// This test ensures the fix for https://github.com/kubernetes-sigs/kustomize/issues/6031
// and https://github.com/kubernetes-sigs/kustomize/issues/6027
// does not break the HelmChart namespace propagation feature from
// https://github.com/kubernetes-sigs/kustomize/issues/5566
func TestHelmChartNamespacePropagationViaResourcesThreeLevels(t *testing.T) {
th := kusttest_test.MakeEnhancedHarnessWithTmpRoot(t)
defer th.Reset()
if err := th.ErrIfNoHelm(); err != nil {
t.Skip("skipping: " + err.Error())
}
// Create base directory with helm chart (Level 1)
baseDir := th.MkDir("base")
chartDir := filepath.Join(baseDir, "charts", "service")
require.NoError(t, th.GetFSys().MkdirAll(filepath.Join(chartDir, "templates")))
th.WriteF(filepath.Join(chartDir, "Chart.yaml"), `
apiVersion: v2
name: service
type: application
version: 1.0.0
`)
th.WriteF(filepath.Join(chartDir, "values.yaml"), ``)
th.WriteF(filepath.Join(chartDir, "templates", "service.yaml"), `
apiVersion: v1
kind: Service
metadata:
name: test-service
namespace: {{ .Release.Namespace }}
annotations:
helm-namespace: {{ .Release.Namespace }}
`)
// Base kustomization with helmCharts (no namespace)
th.WriteK(baseDir, `
helmGlobals:
chartHome: ./charts
helmCharts:
- name: service
releaseName: service
`)
// Mid-layer that references base via resources (no namespace) (Level 2)
midDir := th.MkDir("mid")
th.WriteK(midDir, `
namePrefix: mid-
resources:
- ../base
`)
// Top overlay that references mid-layer and sets namespace (Level 3)
overlayDir := th.MkDir("overlay")
th.WriteK(overlayDir, `
namespace: production
resources:
- ../mid
`)
m := th.Run(overlayDir, th.MakeOptionsPluginsEnabled())
th.AssertActualEqualsExpected(m, `apiVersion: v1
kind: Service
metadata:
annotations:
helm-namespace: production
name: mid-test-service
namespace: production
`)
}
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

@@ -4,6 +4,7 @@
package krusty_test
import (
"strings"
"testing"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
@@ -1282,6 +1283,72 @@ metadata:
}
}
func TestSinglePatchWithMultiplePatchDeleteDirectives(t *testing.T) {
th := kusttest_test.MakeHarness(t)
makeCommonFilesForMultiplePatchTests(th)
th.WriteF("overlay/staging/deployment-patch1.yaml", `
$patch: delete
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
---
$patch: delete
apiVersion: v1
kind: Service
metadata:
name: nginx
`)
th.WriteF("overlay/staging/deployment-patch2.yaml", `
apiVersion: v1
kind: ConfigMap
metadata:
name: configmap-in-base
data:
foo2: bar2
`)
th.WriteK("overlay/staging", `
namePrefix: staging-
commonLabels:
env: staging
patches:
- path: deployment-patch1.yaml
- path: deployment-patch2.yaml
resources:
- ../../base
configMapGenerator:
- name: configmap-in-overlay
literals:
- hello=world
`)
m := th.Run("overlay/staging", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: v1
data:
foo: bar
foo2: bar2
kind: ConfigMap
metadata:
annotations:
note: This is a test annotation
labels:
app: mynginx
env: staging
org: example.com
team: foo
name: staging-team-foo-configmap-in-base-8cmgkm9f44
---
apiVersion: v1
data:
hello: world
kind: ConfigMap
metadata:
labels:
env: staging
name: staging-configmap-in-overlay-dc6fm46dhm
`)
}
func TestMultiplePatchesBothWithPatchDeleteDirective(t *testing.T) {
th := kusttest_test.MakeHarness(t)
makeCommonFilesForMultiplePatchTests(th)
@@ -1700,3 +1767,108 @@ metadata:
name: fluentd-sa-abc
`)
}
// TestEmptyPatchFilesShouldBeIgnored verifies that empty patch files are ignored.
// Tests three cases:
// 1. Completely empty file
// 2. File with only comments
// 3. File with whitespace and comments
func TestEmptyPatchFilesShouldBeIgnored(t *testing.T) {
th := kusttest_test.MakeHarness(t)
// Write a basic resource
th.WriteF("deployment.yaml", `
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
template:
spec:
containers:
- name: nginx
image: nginx
`)
// Create empty patch files of different types
th.WriteF("empty.yaml", ``)
th.WriteF("comments-only.yaml", `
# This is a comment
# Another comment
`)
th.WriteF("whitespace.yaml", `
# Comments with whitespace
# Indented comment
`)
// Reference empty patches in kustomization
th.WriteK(".", `
resources:
- deployment.yaml
patches:
- path: empty.yaml
- path: comments-only.yaml
- path: whitespace.yaml
`)
// Empty patches should be ignored, output should be unchanged
m := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
template:
spec:
containers:
- image: nginx
name: nginx
`)
}
// TestEmptyPatchesStrategicMergeFails verifies that empty patch files are
// handled correctly with the deprecated patchesStrategicMerge field
func TestEmptyPatchesStrategicMergeFails(t *testing.T) {
th := kusttest_test.MakeHarness(t)
// Create a basic resource
th.WriteF("resource.yaml", `
apiVersion: v1
kind: ConfigMap
metadata:
name: dummy
data:
dummy: value
`)
// Create an empty patch file
th.WriteF("empty-patch.yaml", ``)
// Create a patch file with only comments
th.WriteF("comments-patch.yaml", `
# This is just a comment
# Another comment
`)
// Create kustomization using patchesStrategicMerge
th.WriteK(".", `
resources:
- resource.yaml
patchesStrategicMerge:
- empty-patch.yaml
- comments-patch.yaml
`)
// This fails with message
err := th.RunWithErr(".", th.MakeDefaultOptions())
if err == nil {
t.Fatalf("expected error for empty patchesStrategicMerge files but got none")
}
if !strings.Contains(err.Error(), "patch appears to be empty") {
t.Fatalf("unexpected error: %v", err)
}
}

View File

@@ -786,3 +786,85 @@ spec:
name: tester
`)
}
func TestBackReferenceAdmissionPolicy(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
resources:
- admission.yaml
namePrefix: a-prefix-
`)
th.WriteF("admission.yaml", `---
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingAdmissionPolicy
metadata:
name: sample-policy
spec:
failurePolicy: Fail
paramKind:
apiVersion: apps/v1
kind: Deployment
matchConstraints:
resourceRules:
- apiGroups:
- apps
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- deployments
validations:
- expression: "!object.metadata.name.startsWith('test-')"
message: prefix 'test-' is not allowed
reason: Invalid
---
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: sample-policy-binding
spec:
policyName: sample-policy
validationActions:
- Deny
`)
m := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingAdmissionPolicy
metadata:
name: a-prefix-sample-policy
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups:
- apps
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- deployments
paramKind:
apiVersion: apps/v1
kind: Deployment
validations:
- expression: '!object.metadata.name.startsWith(''test-'')'
message: prefix 'test-' is not allowed
reason: Invalid
---
apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingAdmissionPolicyBinding
metadata:
name: a-prefix-sample-policy-binding
spec:
policyName: a-prefix-sample-policy
validationActions:
- Deny
`)
}

View File

@@ -0,0 +1,343 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package krusty_test
import (
"testing"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
)
// Regression test for https://github.com/kubernetes-sigs/kustomize/issues/6031
// This test verifies that namespace propagation from overlay to base does not
// break strategic merge patches when combined with nameSuffix.
//
// The issue: In v5.8.0, namespace was propagated to child kustomization early,
// causing patches to fail because they couldn't find resources with the
// propagated namespace.
func TestNamespacePropagationDoesNotBreakPatchWithNameSuffix(t *testing.T) {
th := kusttest_test.MakeHarness(t)
// Base kustomization with nameSuffix
th.WriteK("base", `
resources:
- configmap.yaml
nameSuffix: -schedule_job_1
`)
th.WriteF("base/configmap.yaml", `
apiVersion: v1
kind: ConfigMap
metadata:
name: hoge
data:
configs.yaml: TO_BE_SPECIFIED
`)
// Overlay with namespace and patch
// The patch targets the original name (before nameSuffix is applied)
// This is the expected behavior per kustomize documentation
th.WriteK("overlay", `
resources:
- ../base
patches:
- path: schedule_job_1.yaml
namespace: hoge-dev
`)
th.WriteF("overlay/schedule_job_1.yaml", `
apiVersion: v1
kind: ConfigMap
metadata:
name: hoge-schedule_job_1
data:
configs.yaml: |
case_configs:
- id: 1
name: dummy1
client: client1
`)
m := th.Run("overlay", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: v1
data:
configs.yaml: |
case_configs:
- id: 1
name: dummy1
client: client1
kind: ConfigMap
metadata:
name: hoge-schedule_job_1
namespace: hoge-dev
`)
}
// Regression test for https://github.com/kubernetes-sigs/kustomize/issues/6027
// This test verifies that namespace propagation does not break
// configMapGenerator merge behavior when the generator is in a base
// and the namespace is set in an overlay.
//
// The issue: In v5.8.0, namespace was propagated to child kustomization early,
// causing generator merge to fail because resources in the base didn't have
// namespace yet, but the overlay's generator had namespace from propagation.
func TestNamespacePropagationDoesNotBreakGeneratorMerge(t *testing.T) {
th := kusttest_test.MakeHarness(t)
// Generator config resource
th.WriteK("cm-generator", `
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- resources/general.yaml
`)
th.WriteF("cm-generator/resources/general.yaml", `
apiVersion: builtin
kind: ConfigMapGenerator
metadata:
name: general-environment
behavior: merge
envs:
- configuration/general
`)
th.WriteF("cm-generator/configuration/general", `
COMMON_ENV=common
`)
// Base kustomization with generator
th.WriteK("base", `
generators:
- ../cm-generator
configMapGenerator:
- name: general-environment
behavior: create
`)
th.WriteF("base/configuration/general", `
BASE_LAYER_ENV=base
`)
// Overlay with namespace and same generator reference
th.WriteK("overlay", `
namespace: abc
generators:
- ../cm-generator
resources:
- ../base
`)
th.WriteF("overlay/configuration/general", `
OVERLAY_ENV=overlay
`)
m := th.Run("overlay", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: v1
data:
BASE_LAYER_ENV: base
OVERLAY_ENV: overlay
kind: ConfigMap
metadata:
name: general-environment-826bch2dh9
namespace: abc
`)
}
// Test to verify namespace propagation still works correctly for
// simple overlay/base scenarios without patches or generators.
func TestNamespaceTransformerInOverlayAppliedToBase(t *testing.T) {
th := kusttest_test.MakeHarness(t)
// Base kustomization without namespace
th.WriteK("base", `
resources:
- deployment.yaml
`)
th.WriteF("base/deployment.yaml", `
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 1
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: app
image: my-image:latest
`)
// Overlay with namespace
th.WriteK("overlay", `
resources:
- ../base
namespace: production
`)
m := th.Run("overlay", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
namespace: production
spec:
replicas: 1
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- image: my-image:latest
name: app
`)
}
// Test for three-level kustomization hierarchy with namespace in top overlay
// This verifies namespace transformer is applied correctly across multiple levels.
func TestNamespaceTransformerWithThreeLevelHierarchy(t *testing.T) {
th := kusttest_test.MakeHarness(t)
// Level 1: Base
th.WriteK("base", `
resources:
- configmap.yaml
`)
th.WriteF("base/configmap.yaml", `
apiVersion: v1
kind: ConfigMap
metadata:
name: base-config
data:
key: value
`)
// Level 2: Mid-layer (no namespace)
th.WriteK("mid", `
resources:
- ../base
namePrefix: mid-
`)
// Level 3: Overlay with namespace
th.WriteK("overlay", `
resources:
- ../mid
namespace: top-ns
namePrefix: top-
`)
m := th.Run("overlay", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: v1
data:
key: value
kind: ConfigMap
metadata:
name: top-mid-base-config
namespace: top-ns
`)
}
// Test that patches in overlay can target resources from base
// when base has nameSuffix and overlay has namespace.
// This is a more complex version of TestNamespacePropagationDoesNotBreakPatchWithNameSuffix
func TestPatchTargetingWithNameSuffixAndNamespace(t *testing.T) {
th := kusttest_test.MakeHarness(t)
// Base with nameSuffix
th.WriteK("base", `
resources:
- deployment.yaml
nameSuffix: -v2
`)
th.WriteF("base/deployment.yaml", `
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
replicas: 1
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: app
image: myimage:v1
`)
// Overlay with namespace and patch
th.WriteK("overlay", `
resources:
- ../base
namespace: production
patches:
- target:
kind: Deployment
name: myapp-v2
patch: |
- op: replace
path: /spec/replicas
value: 3
`)
m := th.Run("overlay", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-v2
namespace: production
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- image: myimage:v1
name: app
`)
}

View File

@@ -692,7 +692,6 @@ resources:
th.AssertActualEqualsExpected(m, namespaceNeedInVarExpectedOutput)
}
//nolint:gosec
const namespaceNeedInVarMyAppWithNamespace string = `
resources:
- elasticsearch-dev-service.yaml

View File

@@ -0,0 +1,228 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package krusty_test
import (
"testing"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
)
// test for https://github.com/kubernetes-sigs/kustomize/issues/4240
func TestSuffix5042(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
resources:
- resource.yaml
`)
th.WriteF("resource.yaml", `
apiVersion: example.com/v1alpha1
kind: MyResource
metadata:
name: service
---
apiVersion: example.com/v1alpha1
kind: MyResourceTwo
metadata:
name: test
rules: []
`)
m := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: example.com/v1alpha1
kind: MyResource
metadata:
name: service
---
apiVersion: example.com/v1alpha1
kind: MyResourceTwo
metadata:
name: test
rules: []
`)
}
func TestListSuffix5042(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
resources:
- resource.yaml
`)
th.WriteF("resource.yaml", `
apiVersion: example.com/v1alpha1
kind: MyResource
metadata:
name: service
---
apiVersion: example.com/v1alpha1
kind: MyResourceList
metadata:
name: test
rules: []
`)
m := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: example.com/v1alpha1
kind: MyResource
metadata:
name: service
---
apiVersion: example.com/v1alpha1
kind: MyResourceList
metadata:
name: test
rules: []
`)
}
func TestListSuffix5485(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
resources:
- resource.yaml
`)
th.WriteF("resource.yaml", `
apiVersion: infra.protonbase.io/v1alpha1
kind: AccessWhiteList
metadata:
name: wlmls5769f
namespace: dc7i4hyxzw
spec:
rules:
- sourceIps: 0.0.0.0/16
`)
m := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: infra.protonbase.io/v1alpha1
kind: AccessWhiteList
metadata:
name: wlmls5769f
namespace: dc7i4hyxzw
spec:
rules:
- sourceIps: 0.0.0.0/16
`)
}
func TestListToIndividualResources(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
resources:
- list.yaml
`)
th.WriteF("list.yaml", `
apiVersion: v1
kind: PodList
items:
- apiVersion: v1
kind: Pod
metadata:
name: my-pod-1
namespace: default
labels:
app: my-app
spec:
containers:
- name: my-container
image: nginx:1.19.10
ports:
- containerPort: 80
- apiVersion: v1
kind: Pod
metadata:
name: my-pod-2
namespace: default
labels:
app: my-app
spec:
containers:
- name: my-container
image: nginx:1.19.10
ports:
- containerPort: 80
- apiVersion: v1
kind: Pod
metadata:
name: my-pod-3
namespace: default
labels:
app: my-app
spec:
containers:
- name: my-container
image: nginx:1.19.10
ports:
- containerPort: 80
`)
m := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: v1
kind: Pod
metadata:
labels:
app: my-app
name: my-pod-1
namespace: default
spec:
containers:
- image: nginx:1.19.10
name: my-container
ports:
- containerPort: 80
---
apiVersion: v1
kind: Pod
metadata:
labels:
app: my-app
name: my-pod-2
namespace: default
spec:
containers:
- image: nginx:1.19.10
name: my-container
ports:
- containerPort: 80
---
apiVersion: v1
kind: Pod
metadata:
labels:
app: my-app
name: my-pod-3
namespace: default
spec:
containers:
- image: nginx:1.19.10
name: my-container
ports:
- containerPort: 80
`)
}
// Empty list should result in no resources
func TestEmptyList(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
resources:
- emptyList.yaml
`)
th.WriteF("emptyList.yaml", `
apiVersion: v1
kind: PodList
items: []
`)
m := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, "")
}

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

@@ -282,6 +282,8 @@ resources:
},
}
t.Setenv("LC_ALL", "C")
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if test.skip {
@@ -404,7 +406,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)
@@ -453,6 +455,6 @@ 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

@@ -614,3 +614,391 @@ metadata:
name: app-config-dev-97544dk6t8
`)
}
// regex selector: append in annotation by visitor name
func TestReplacementTransformerAppendToAnnotationUsingRegex(t *testing.T) {
th := kusttest_test.MakeEnhancedHarness(t)
defer th.Reset()
th.WriteF("base/app1.yaml", `
apiVersion: apps/v1
kind: Deployment
metadata:
name: d1
spec:
template:
spec:
containers:
- image: app1:1.0
name: app
`)
th.WriteF("base/app2.yaml", `
apiVersion: apps/v1
kind: Deployment
metadata:
name: d2
spec:
template:
spec:
containers:
- image: app2:1.0
name: app
`)
th.WriteF("base/cm1.yaml", `
apiVersion: apps/v1
kind: ConfigMap
metadata:
name: cm1
`)
th.WriteF("base/cm2.yaml", `
apiVersion: apps/v1
kind: ConfigMap
metadata:
name: cm2
`)
th.WriteF("base/pg1.yaml", `
apiVersion: apps/v1
kind: postgresql
metadata:
name: pg1
`)
th.WriteK("base", `
resources:
- app1.yaml
- app2.yaml
- cm1.yaml
- cm2.yaml
- pg1.yaml
replacements:
- source:
kind: ConfigMap
name: cm1
targets:
- reject:
- kind: ConfigMap
name: c.1
select:
kind: Deployment|ConfigMap|postgresql
fieldPaths:
- metadata.annotations.visitedby
options:
index: -1
delimiter: ","
create: true
- source:
kind: ConfigMap
name: cm2
targets:
- reject:
- kind: ConfigMap
name: .*2
select:
kind: Deployment|ConfigMap|postgresql
fieldPaths:
- metadata.annotations.visitedby
options:
index: -1
delimiter: ","
create: true
`)
m := th.Run("base", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
visitedby: cm2,cm1,
name: d1
spec:
template:
spec:
containers:
- image: app1:1.0
name: app
---
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
visitedby: cm2,cm1,
name: d2
spec:
template:
spec:
containers:
- image: app2:1.0
name: app
---
apiVersion: apps/v1
kind: ConfigMap
metadata:
annotations:
visitedby: cm2,
name: cm1
---
apiVersion: apps/v1
kind: ConfigMap
metadata:
annotations:
visitedby: cm1,
name: cm2
---
apiVersion: apps/v1
kind: postgresql
metadata:
annotations:
visitedby: cm2,cm1,
name: pg1
`)
}
// selector regex: construct service url
func TestReplacementTransformerServiceNamespaceUrlUsingRegex(t *testing.T) {
th := kusttest_test.MakeEnhancedHarness(t)
defer th.Reset()
th.WriteF("base/d1.yaml", `
apiVersion: apps/v1
kind: Deployment
metadata:
name: d1
spec:
template:
spec:
containers:
- image: app1:1.0
name: app
env:
- name: APP1_SERVICE
value: "d1.app1"
`)
th.WriteF("base/d2.yaml", `
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: d2
spec:
template:
spec:
containers:
- image: app1:1.0
name: app
env:
- name: APP1_SERVICE
value: "d2.app1"
`)
th.WriteF("base/sts1.yaml", `
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: sts1
spec:
template:
spec:
containers:
- image: app1:1.0
name: app
env:
- name: APP1_SERVICE
value: "app1"
`)
th.WriteF("base/cm1.yaml", `
apiVersion: apps/v1
kind: ConfigMap
metadata:
name: cm1
data:
APP1_SERVICE_PORT: "8080"
`)
th.WriteF("base/svc1.yaml", `
apiVersion: v1
kind: Service
metadata:
name: svc1
namespace: svc1-namespace
spec:
selector:
app.kubernetes.io/name: app1
ports:
- protocol: TCP
port: 80
targetPort: 9376
`)
th.WriteK("base", `
resources:
- d1.yaml
- d2.yaml
- sts1.yaml
- cm1.yaml
- svc1.yaml
replacements:
- source:
kind: Service
name: svc1
fieldPath: metadata.namespace
targets:
- select:
kind: Deployment|.*Set
fieldPaths:
- spec.template.spec.containers.*.env.[name=APP1_SERVICE].value
options:
index: 99
delimiter: "."
- source:
kind: ConfigMap
name: cm1
fieldPath: data.APP1_SERVICE_PORT
targets:
- select:
kind: Deployment|.*Set
fieldPaths:
- spec.template.spec.containers.*.env.[name=APP1_SERVICE].value
options:
index: 99
delimiter: ":"
`)
m := th.Run("base", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: apps/v1
kind: Deployment
metadata:
name: d1
spec:
template:
spec:
containers:
- env:
- name: APP1_SERVICE
value: d1.app1.svc1-namespace:8080
image: app1:1.0
name: app
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: d2
spec:
template:
spec:
containers:
- env:
- name: APP1_SERVICE
value: d2.app1.svc1-namespace:8080
image: app1:1.0
name: app
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: sts1
spec:
template:
spec:
containers:
- env:
- name: APP1_SERVICE
value: app1.svc1-namespace:8080
image: app1:1.0
name: app
---
apiVersion: apps/v1
data:
APP1_SERVICE_PORT: "8080"
kind: ConfigMap
metadata:
name: cm1
---
apiVersion: v1
kind: Service
metadata:
name: svc1
namespace: svc1-namespace
spec:
ports:
- port: 80
protocol: TCP
targetPort: 9376
selector:
app.kubernetes.io/name: app1
`)
}
func TestReplacementTransformerWithSuffixTransformerAndRejectUsingRegex(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
namePrefix: pre-
resources:
- ../base
configMapGenerator:
- name: app-config
literals:
- name=something-else
replacements:
- source:
kind: ConfigMap
name: app-config
fieldPath: data.name
targets:
- reject:
- name: .*original.*
select:
kind: Deployment
fieldPaths:
- spec.template.spec.containers.0.name
- select:
kind: ConfigMap
name: app-config
fieldPaths:
- data.name-copy
options:
create: true
`)
m := th.Run("overlay", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, `
apiVersion: apps/v1
kind: Deployment
metadata:
name: pre-original-name-dev
spec:
template:
spec:
containers:
- image: app1:1.0
name: app
---
apiVersion: v1
data:
name: something-else
name-copy: something-else
kind: ConfigMap
metadata:
name: pre-app-config-dev-7266b7f2m9
`)
}

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
`)
}

View File

@@ -460,7 +460,7 @@ vars:
objref: &config-map-ref
kind: ConfigMap
name: kustomize-vars
apiVersion: v1
version: v1
fieldref:
fieldpath: data.DBT_TARGET
- name: SUSPENDED
@@ -500,10 +500,12 @@ nameReference:
varReference:
- path: spec/workflowSpec/arguments/parameters/value
kind: CronWorkflow
apiVersion: argoproj.io/v1alpha1
group: argoproj.io
version: v1alpha1
- path: spec
kind: CronWorkflow
apiVersion: argoproj.io/v1alpha1
group: argoproj.io
version: v1alpha1
`)
th.WriteF("vars.env", `
DBT_TARGET=development

View File

@@ -12,9 +12,6 @@ import (
// TODO: delete this when we find a better way to generate release notes.
func main() {
fmt.Println(`
This 'main' exists only to make goreleaser create release notes for the API.
See https://github.com/goreleaser/goreleaser/issues/981
and https://github.com/kubernetes-sigs/kustomize/tree/master/releasing`)
fmt.Println(`This 'main' exists only to create release notes for the API.`)
fmt.Println(provenance.GetProvenance())
}

13
api/pkg/util/image.go Normal file
View File

@@ -0,0 +1,13 @@
// Copyright 2024 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package util
import (
"sigs.k8s.io/kustomize/api/internal/image"
)
// Splits image string name into name, tag and digest
func SplitImageName(imageName string) (name string, tag string, digest string) {
return image.Split(imageName)
}

View File

@@ -8,6 +8,8 @@ import (
"runtime"
"runtime/debug"
"strings"
"github.com/blang/semver/v4"
)
// These variables are set at build time using ldflags.
@@ -17,12 +19,21 @@ var (
// During a release, this will be set to the release tag, e.g. "kustomize/v4.5.7"
version = developmentVersion
// build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
buildDate = "unknown"
buildDate = unknown
)
// This default value, (devel), matches
// the value debug.BuildInfo uses for an unset main module version.
const developmentVersion = "(devel)"
const (
// This default value, (devel), matches
// the value debug.BuildInfo uses for an unset main module version.
developmentVersion = "(devel)"
// ModulePath is kustomize module path, defined in kustomize/go.mod
ModulePath = "sigs.k8s.io/kustomize/kustomize/v5"
// This is default value, unknown, substituted when
// the value can't be determined from debug.BuildInfo.
unknown = "unknown"
)
// Provenance holds information about the build of an executable.
type Provenance struct {
@@ -45,7 +56,7 @@ func GetProvenance() Provenance {
p := Provenance{
BuildDate: buildDate,
Version: version,
GitCommit: "unknown",
GitCommit: unknown,
GoOs: runtime.GOOS,
GoArch: runtime.GOARCH,
GoVersion: runtime.Version(),
@@ -60,11 +71,57 @@ func GetProvenance() Provenance {
// We could consider adding other info such as the commit date in the future.
if setting.Key == "vcs.revision" {
p.GitCommit = setting.Value
break
}
}
p.Version = FindVersion(info, p.Version)
return p
}
// FindVersion searches for a version in the depth of dependencies including replacements,
// otherwise, it tries to get version from debug.BuildInfo Main.
func FindVersion(info *debug.BuildInfo, version string) string {
for _, dep := range info.Deps {
if dep != nil && dep.Path == ModulePath {
if dep.Version == developmentVersion {
continue
}
v, err := GetMostRecentTag(*dep)
if err != nil {
fmt.Printf("failed to get most recent tag for %s: %v\n", dep.Path, err)
continue
}
return v
}
}
if version == developmentVersion && info.Main.Version != "" {
return info.Main.Version
}
return version
}
func GetMostRecentTag(m debug.Module) (string, error) {
for m.Replace != nil {
m = *m.Replace
}
split := strings.Split(m.Version, "-")
sv, err := semver.Parse(strings.TrimPrefix(split[0], "v"))
if err != nil {
return "", fmt.Errorf("failed to parse version %s: %w", m.Version, err)
}
if len(split) > 1 && sv.Patch > 0 {
sv.Patch -= 1
}
return fmt.Sprintf("v%s", sv.FinalizeVersion()), nil
}
// Short returns the shortened provenance stamp.
func (v Provenance) Short() string {
return fmt.Sprintf(

View File

@@ -5,6 +5,7 @@ package provenance_test
import (
"fmt"
"runtime/debug"
"testing"
"github.com/stretchr/testify/assert"
@@ -45,3 +46,107 @@ func TestProvenance_Semver(t *testing.T) {
p.Version = "kustomize/v4.11.12"
assert.Equal(t, "v4.11.12", p.Semver())
}
func mockModule(version string) debug.Module {
return debug.Module{
Path: provenance.ModulePath,
Version: version,
Replace: nil,
}
}
func mockBuildInfo(mainVersion, depsVersion string) *debug.BuildInfo {
module := mockModule(depsVersion)
return &debug.BuildInfo{
Main: debug.Module{
Version: mainVersion,
},
Deps: []*debug.Module{
&module,
},
}
}
func TestFindVersion(t *testing.T) {
tests := []struct {
name string
version string
buildInfo *debug.BuildInfo
expectedVersion string
}{
{
name: "The version from LD_FLAGS is not overridden by main and dependencies versions",
version: "v2.3.4",
buildInfo: mockBuildInfo("v1.2.3", "(devel)"),
expectedVersion: "v2.3.4",
},
{
name: "The version from LD_FLAGS is overridden by the main version",
version: "(devel)",
buildInfo: mockBuildInfo("v1.2.3", "(devel)"),
expectedVersion: "v1.2.3",
},
{
name: "The version from LD_FLAGS is overridden by the version from dependencies",
version: "(devel)",
buildInfo: mockBuildInfo("v1.2.3", "v1.2.3-0.20210101010101-abcdefabcdef"),
expectedVersion: "v1.2.2",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
version := provenance.FindVersion(tt.buildInfo, tt.version)
assert.Equal(t, tt.expectedVersion, version)
})
}
}
func TestGetMostRecentTag(t *testing.T) {
tests := []struct {
name string
module debug.Module
isError bool
expectedTag string
}{
{
name: "Standard version",
module: mockModule("v1.2.3"),
expectedTag: "v1.2.3",
},
{
name: "Pseudo-version with patch increment",
module: mockModule("v0.0.0-20210101010101-abcdefabcdef"),
expectedTag: "v0.0.0",
},
{
name: "Invalid semver string",
module: mockModule("invalid-version"),
isError: true,
},
{
name: "Valid semver with patch increment and pre-release info",
module: mockModule("v1.2.3-0.20210101010101-abcdefabcdef"),
expectedTag: "v1.2.2",
},
{
name: "Valid semver no patch increment",
module: mockModule("v1.2.0"),
expectedTag: "v1.2.0",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tag, err := provenance.GetMostRecentTag(tt.module)
if err != nil {
if !tt.isError {
assert.NoError(t, err)
}
} else {
assert.Equal(t, tt.expectedTag, tag)
}
})
}
}

View File

@@ -8,6 +8,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"sigs.k8s.io/kustomize/api/ifc"
loader "sigs.k8s.io/kustomize/api/internal/loader"
"sigs.k8s.io/kustomize/api/kv"
@@ -61,19 +62,19 @@ metadata:
"namespace": "test",
}}).ResMap()
expYaml, err := expected.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
fSys := filesys.MakeFsInMemory()
assert.NoError(t, fSys.WriteFile("deployment.yaml", []byte(resourceStr)))
require.NoError(t, fSys.WriteFile("deployment.yaml", []byte(resourceStr)))
ldr, err := loader.NewLoader(
loader.RestrictionRootOnly, filesys.Separator, fSys)
assert.NoError(t, err)
require.NoError(t, err)
m, err := rmF.FromFile(ldr, "deployment.yaml")
assert.NoError(t, err)
require.NoError(t, err)
mYaml, err := m.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, expYaml, mYaml)
}
@@ -102,11 +103,11 @@ metadata:
"name": "cm2",
}}).ResMap()
expYaml, err := expected.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
m, err := rmF.NewResMapFromBytes(encoded)
assert.NoError(t, err)
require.NoError(t, err)
mYaml, err := m.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, expYaml, mYaml)
}
@@ -219,13 +220,13 @@ BAR=baz
}
}
r, err := rmF.NewResMapFromConfigMapArgs(kvLdr, tc.input)
assert.NoError(t, err, tc.description)
require.NoError(t, err, tc.description)
r.RemoveBuildAnnotations()
rYaml, err := r.AsYaml()
assert.NoError(t, err, tc.description)
require.NoError(t, err, tc.description)
tc.expected.RemoveBuildAnnotations()
expYaml, err := tc.expected.AsYaml()
assert.NoError(t, err, tc.description)
require.NoError(t, err, tc.description)
assert.Equal(t, expYaml, rYaml)
}
}
@@ -257,7 +258,7 @@ func TestNewResMapFromSecretArgs(t *testing.T) {
}
actual.RemoveBuildAnnotations()
actYaml, err := actual.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
expected := resmaptest_test.NewRmBuilder(t, rf).Add(
map[string]interface{}{
@@ -273,7 +274,7 @@ func TestNewResMapFromSecretArgs(t *testing.T) {
},
}).ResMap()
expYaml, err := expected.AsYaml()
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, string(expYaml), string(actYaml))
}

View File

@@ -181,6 +181,10 @@ func (m *resWrangler) GetMatchingResourcesByAnyId(
matches IdMatcher) []*resource.Resource {
var result []*resource.Resource
for _, r := range m.rList {
if r.RNode.IsNilOrEmpty() {
continue
}
for _, id := range append(r.PrevIds(), r.CurId()) {
if matches(id) {
result = append(result, r)
@@ -593,7 +597,7 @@ func (m *resWrangler) appendReplaceOrMerge(res *resource.Resource) error {
default:
return fmt.Errorf(
"id %#v exists; behavior must be merge or replace", id)
"id %#v exists; can not use behavior: '%s', behavior must be merge or replace", id, res.Behavior())
}
i, err := m.Replace(res)
if err != nil {

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