Compare commits

...

1689 Commits

Author SHA1 Message Date
Natasha Sarkar
daa3e5e2c2 Merge pull request #4647 from natasha41575/increase_cpu
increase vm size for cloud build
2022-05-20 20:21:22 +00:00
natasha41575
12adc1ff95 increase vm size for cloud build 2022-05-20 13:20:58 -07:00
Natasha Sarkar
41283c4727 Merge pull request #4646 from natasha41575/pinToApi
Update api to v0.11.5
2022-05-20 19:34:52 +00:00
natasha41575
30740f87f1 Update api to v0.11.5 2022-05-20 12:26:43 -07:00
Natasha Sarkar
6c8db65a90 Merge pull request #4645 from natasha41575/pinToCmdConfig
Update cmd/config to v0.10.7
2022-05-20 19:14:52 +00:00
natasha41575
35b5b7554f Update cmd/config to v0.10.7 2022-05-20 12:03:17 -07:00
Natasha Sarkar
6395344bcb Merge pull request #4644 from natasha41575/pinToKyaml
Update kyaml to v0.13.7
2022-05-20 18:51:47 +00:00
natasha41575
4a3bb926c5 Update kyaml to v0.13.7 2022-05-20 11:43:49 -07:00
Kubernetes Prow Robot
ba5335cf48 Merge pull request #4635 from konrad945/master
Testing code leaked to production
2022-05-19 10:49:21 -07:00
Anna Song
03ac2e1ada Proposal for new command "kustomize localize" (#4590)
* Propose kustomize localize

Write mini KEP proposal for new command kustomize localize.

* Incomplete commit

* Update proposal based on Katrina's feedback

Changes are summarized in comments in PR

* Address feedback in comments
2022-05-15 10:28:17 -07:00
Kubernetes Prow Robot
1cf5b00af8 Merge pull request #4639 from annasong20/document-no-ports
Document urls cannot specify ports
2022-05-13 09:43:48 -07:00
Anna Song
9097f7b5a6 Document urls cannot specify ports 2022-05-13 09:15:30 -07:00
Kubernetes Prow Robot
0c8174544f Merge pull request #4638 from annasong20/skip-more-flaky
Skip more flaky tests
2022-05-12 16:39:48 -07:00
Anna Song
a37572d193 Skip more flaky tests 2022-05-12 16:23:42 -07:00
konrad945
ba7315ca76 Update testing_test.go 2022-05-12 19:38:15 +02:00
konrad945
ddf768195c Rename testing.go to testing_test.go 2022-05-12 16:43:27 +02:00
konrad945
b11cc3ae67 Fix comments 2022-05-12 16:42:28 +02:00
Kubernetes Prow Robot
22668eae16 Merge pull request #4634 from unrolled/unrolled-4338-copyright
Update copyright to match k8s docs site
2022-05-11 11:31:03 -07:00
Cory Jacobsen
02eb788b78 Update copyright to match k8s docs site 2022-05-11 16:59:24 +00:00
Anna Song
41fb6915b3 Document remote files in remoteBuild.md (#4624)
* Add file to remote build spec

* Address PR feedback
2022-05-10 11:21:43 -07:00
Kubernetes Prow Robot
596519d3f2 Merge pull request #4631 from annasong20/localize-test
Add test directory for command localize
2022-05-10 11:13:43 -07:00
Kubernetes Prow Robot
d3d92157fa Merge pull request #4567 from mvgmb/master
Add support for remote OpenAPI schema
2022-05-10 11:01:43 -07:00
Anna Song
c83ebd9530 Add test directory for command localize
Create simple kustomization directory that `kustomize localize` can download as remote reference in test.
2022-05-10 10:58:33 -07:00
Kubernetes Prow Robot
c3b5d8fa19 Merge pull request #4629 from KnVerey/configure_templateparser
fn framework: bugfix for schema providers + configurable template extensions
2022-05-09 17:25:43 -07:00
Katrina Verey
7a773a3a48 Configure wrapcheck linter to recognize wrapping done by kyaml's errors package 2022-05-09 17:02:02 -04:00
Kubernetes Prow Robot
46d4934b68 Merge pull request #4606 from unrolled/unrolled-4338-config-site-setup
Configuring hugo settings to match cli-experimental settings
2022-05-06 12:13:04 -07:00
Kubernetes Prow Robot
d0ef2f70a1 Merge pull request #4627 from annasong20/remove-flaky-tests
Skip flaky tests
2022-05-06 11:31:04 -07:00
Anna Song
b8d2ff2afa Fix TODO comment syntax 2022-05-06 09:24:23 -07:00
Anna Song
7e0158e1e9 Skip flaky tests
Skip tests that behave reliably locally, but are flaky on macOS server.
2022-05-06 08:12:39 -07:00
Agustina Barbetta
5948f6aa63 [Address #3937] Add labels to template/metadata if includeTemplates is true (#4209)
* add labels in template/metadata by default

* update comment

* fix kustomization labels test

* Add spec/template/metadata/labels when includeTemplate is true

* remove unnecessary test changes

* add error wrap

* Revert "add error wrap"

This reverts commit 0a203df83edb90a400b35d5521487b984619e919.

* add error wrap at template fieldSpec merge
2022-05-05 11:24:22 -07:00
Kubernetes Prow Robot
496a962a53 Merge pull request #4615 from annasong20/add-remote-resource-tests
Fix Issue #4588
2022-05-05 10:30:21 -07:00
Anna Song
17b42a99f5 Skip ssh tests
Skip ssh tests and correct error msg that's different on server.
2022-05-05 09:26:44 -07:00
Anna Song
271f393218 Address feedback
Change asserts to, on fail, fail tests. Address feedback on previous commit. Enable ssh to check if server has ssh keys.
2022-05-04 18:54:12 -07:00
Anna Song
c0dc68d6e7 Add url tests
Write comprehensive suite of integration tests for remote resources, as specified by Issue #4588
2022-05-03 13:53:03 -07:00
annelausf
188e35fbfd Added code for fields with dots(.) in their names work as needed (#4591)
* Added code for fields with dots(.) in their names work as needed

Co-authored-by: sarjamil <sjamil@salesforce.com>

* Fixed imports

Co-authored-by: sarjamil <sjamil@salesforce.com>

* Removed comments

Co-authored-by: sarjamil <sjamil@salesforce.com>

* Fix filter method

Co-authored-by: sarjamil <sjamil@salesforce.com>

* Fixed failing tests

Co-authored-by: sarjamil <sjamil@salesforce.com>

* Remove comments

Add co-author to PR.

Co-authored-by: sarjamil <sjamil@salesforce.com>

* Add co-author to PR.

Co-authored-by: sarjamil sjamil@salesforce.com

Co-authored-by: sarjamil <sjamil@salesforce.com>
2022-05-02 14:30:33 -07:00
Kubernetes Prow Robot
233b6adf7e Merge pull request #4605 from m-Bilal/fix-4559
Fix kustomize 4.5.3+ breaking remote resources (4559)
2022-05-02 13:34:31 -07:00
Cory Jacobsen
41296b9814 Configuring hugo settings to match cli-experimental 2022-04-27 17:12:30 +00:00
Mohd Bilal
66e4e1582b fix kustomize 4.5.3+ breaking remote resources (4559) 2022-04-23 06:25:24 +00:00
Katrina Verey
2e230b4d4b Regression test and fix for APIs that satisfy ValidationSchemaProvider but not Validator 2022-04-22 17:19:49 -04:00
Katrina Verey
bcae65770a Configurable extensions for template parser 2022-04-21 18:28:13 -04:00
Mário Bezerra
d49e5aa5aa Add tests for remote OpenAPI schema 2022-04-20 00:03:22 -03:00
Mário Bezerra
94af647556 Add support for remote OpenAPI schema 2022-04-19 23:58:04 -03:00
Natasha Sarkar
9d5491c2e2 fix containerized function mounts issue (#4489)
* fix containerized function mounts issue

* skip path test on windows

* move test out of temp dir

* update tests to deal with new working dir restrictions

* code review
2022-04-18 14:25:50 -07:00
Natasha Sarkar
cf89eae804 openapi parsing performance improvement with protobuffer (#4568)
* update necessary dependencies

* update openapi test structure

* remove old swagger files and generate new ones

* use protobuffer to parse openapi for performance improvement
2022-04-18 11:10:43 -07:00
Eng Zer Jun
9452a031ba test: use T.TempDir to create temporary test directory (#4587)
* test: use `T.TempDir` to create temporary test directory

This commit replaces `ioutil.TempDir` with `t.TempDir` in tests. The
directory created by `t.TempDir` is automatically removed when the test
and all its subtests complete.

Prior to this commit, temporary directory created using `ioutil.TempDir`
needs to be removed manually by calling `os.RemoveAll`, which is omitted
in some tests. The error handling boilerplate e.g.
	defer func() {
		if err := os.RemoveAll(dir); err != nil {
			t.Fatal(err)
		}
	}
is also tedious, but `t.TempDir` handles this for us nicely.

Reference: https://pkg.go.dev/testing#T.TempDir
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>

* test: fix `TestInit_noargs` on Windows

--- FAIL: TestInit_noargs (0.01s)
    testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\RUNNER~1\AppData\Local\Temp\TestInit_noargs3136084632\001: The process cannot access the file because it is being used by another process.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>

* test: fix `TestTreeCommandDefaultCurDir_files` on Windows

--- FAIL: TestTreeCommandDefaultCurDir_files (0.01s)
    testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\RUNNER~1\AppData\Local\Temp\TestTreeCommandDefaultCurDir_files716679291\001: The process cannot access the file because it is being used by another process.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>

* test: fix `TestCreateSetterCommand` on Windows

--- FAIL: TestCreateSetterCommand (13.27s)
    --- FAIL: TestCreateSetterCommand/add_replicas (1.45s)
        testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\RUNNER~1\AppData\Local\Temp\TestCreateSetterCommandadd_replicas176222064\001\k8s-cli-487197005.yaml: The process cannot access the file because it is being used by another process.
    ...
    and all subtests
    ...

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>

* test: fix `TestCreateSubstitutionCommand` on Windows

--- FAIL: TestCreateSubstitutionCommand (4.16s)
    --- FAIL: TestCreateSubstitutionCommand/substitution_replicas (1.30s)
        testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\RUNNER~1\AppData\Local\Temp\TestCreateSubstitutionCommandsubstitution_replicas1352417113\001\k8s-cli-3183612276.yaml: The process cannot access the file because it is being used by another process.
    ...
    and all subtests
    ...

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>

* test: fix `TestDeleteSetterCommand` on Windows

--- FAIL: TestDeleteSetterCommand (4.36s)
    --- FAIL: TestDeleteSetterCommand/delete_replicas (1.31s)
        testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\RUNNER~1\AppData\Local\Temp\TestDeleteSetterCommanddelete_replicas3949811929\001\k8s-cli-957077271.yaml: The process cannot access the file because it is being used by another process.
    ...
    and all subtests
    ...

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>

* test: fix `TestDeleteSubstitutionCommand` on Windows

--- FAIL: TestDeleteSubstitutionCommand (2.35s)
    --- FAIL: TestDeleteSubstitutionCommand/delete_only_subst_if_setter_has_same_name_-_long_ref (1.15s)
        testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\RUNNER~1\AppData\Local\Temp\TestDeleteSubstitutionCommanddelete_only_subst_if_setter_has_same_name_-_long_ref2039728641\001\k8s-cli-1602861478.yaml: The process cannot access the file because it is being used by another process.
    ...
    and all subtests
    ...

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>

* test: fix `TestSetCommand` on Windows

--- FAIL: TestSetCommand (13.76s)
    --- FAIL: TestSetCommand/set_replicas (1.13s)
        testing.go:1090: TempDir RemoveAll cleanup: remove C:\Users\RUNNER~1\AppData\Local\Temp\TestSetCommandset_replicas3781384539\001\k8s-cli-1030344459.yaml: The process cannot access the file because it is being used by another process.
    ...
    and all subtests
    ...

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-04-18 09:32:41 -07:00
Dipto Chakrabarty
a464ed0c59 add tagsuffix to take image tag suffix (#4364)
* add tagsuffix to take image tag suffix

* add comments to warn about specifications

* add test and error handle

* fix indent

* update comment

* fix merge errors and return updates

* update image update and fix example

* fix yamls formats

remove tabs in yamls

fix space in image name

tag error in name

* fix spacing issue

format of yaml

set example as above

* spacing of spec in testing templates

* change to switch case
2022-04-14 10:00:47 -07:00
Kubernetes Prow Robot
ec212711d4 Merge pull request #4577 from koba1t/fix/replacement_wildcard_and_create_option_error_message
fix error message using replacement wildcard and create option
2022-04-13 13:44:46 -07:00
koba1t
2f2e14e953 fix lint error to nolint:goerr113 2022-04-13 12:43:35 +09:00
koba1t
ed72bb02d4 fix lint error 2022-04-13 05:20:53 +09:00
koba1t
02e0b38bb0 fix lint error 2022-04-13 05:09:52 +09:00
koba1t
01ab069bd2 fix error message 2022-04-13 04:55:21 +09:00
koba1t
cdc4a5083b fix lint error 2022-04-12 12:53:58 +09:00
koba1t
5e84de2a89 fix errror message using replacement wildcard and create option 2022-04-12 05:14:24 +09:00
Kubernetes Prow Robot
e5041bae6f Merge pull request #4576 from kubernetes-sigs/dependabot/github_actions/actions/setup-go-3
Bump actions/setup-go from 2 to 3
2022-04-11 10:14:06 -07:00
dependabot[bot]
0d600af35a Bump actions/setup-go from 2 to 3
Bumps [actions/setup-go](https://github.com/actions/setup-go) from 2 to 3.
- [Release notes](https://github.com/actions/setup-go/releases)
- [Commits](https://github.com/actions/setup-go/compare/v2...v3)

---
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>
2022-04-11 01:05:22 +00:00
Kubernetes Prow Robot
0989b26098 Merge pull request #4571 from KnVerey/releaser_1.18
Install goreleaser into go 1.18 image for build
2022-04-07 14:11:23 -07:00
Jennifer Cwagenberg
7888aef305 Raise error for external generators or transformers (#4565)
* Raise error if duplicate orgids for external transformers or external generators are configured

* Remove output of resources in error message

* Remove trailing newline
2022-04-06 15:46:25 -07:00
Katrina Verey
fe604fd3d1 Install goreleaser into go 1.18 image for build 2022-04-06 15:51:37 -04:00
Kubernetes Prow Robot
4fc02497ae Merge pull request #4564 from KnVerey/rework_ci
Make CI much more effective
2022-04-06 12:36:26 -07:00
Katrina Verey
e96c38e3ab Use verbose mode in all test runs 2022-04-05 15:56:32 -04:00
Katrina Verey
29104d6fa9 Ignore XML in license header script 2022-04-05 15:03:13 -04:00
Katrina Verey
df57e196d8 more makefile cleanup 2022-04-05 14:55:50 -04:00
Katrina Verey
f3c825f550 Make sure build targets all install into Go bin 2022-04-05 14:40:33 -04:00
Katrina Verey
03c94eabb7 Base makefile and root makefile target for functions/examples 2022-04-05 14:37:18 -04:00
Katrina Verey
c071cdaedd More makefile cleanup 2022-04-05 14:31:17 -04:00
Katrina Verey
f68a0c50d9 less redundancy in presubmit 2022-04-04 20:50:56 -04:00
Katrina Verey
db34e923c5 rever meaning of verify kustomize target 2022-04-04 20:40:07 -04:00
Katrina Verey
df80b29694 Test other modules on all platforms 2022-04-04 20:14:49 -04:00
Katrina Verey
ea193328e3 Run all non plugin module builds 2022-04-04 19:23:08 -04:00
Katrina Verey
2d4bce5112 Do not run ineffective targets, do run all module tests 2022-04-04 18:13:00 -04:00
Katrina Verey
af06ae6b69 add kustomize module to tests that run on master 2022-04-04 17:47:33 -04:00
Katrina Verey
46875b6ac4 More makefile cleanup 2022-04-04 16:46:41 -04:00
Katrina Verey
0fa010c7e7 Add missing boilerplate 2022-04-04 14:24:04 -04:00
Katrina Verey
3e652d6fea Add helpful error message to license check 2022-04-04 14:22:24 -04:00
Katrina Verey
f54014ce3b Add latest to go install commands 2022-04-04 14:10:29 -04:00
Katrina Verey
08924dc2f5 Fix root var and add sanity check 2022-04-04 14:03:29 -04:00
Kubernetes Prow Robot
49c0ed1326 Merge pull request #4563 from turrisxyz/naveensrinivasan/set-permissions
Add permissions to GitHub actions
2022-04-01 15:18:09 -07:00
Katrina Verey
7440f974b8 Lint needs goimports 2022-04-01 18:02:15 -04:00
Katrina Verey
ab9b89213b Delete duplicate copies of the license template 2022-04-01 17:56:06 -04:00
Katrina Verey
9fc012cc4e Do not change what the presubmit does yet 2022-04-01 17:55:52 -04:00
Katrina Verey
877d72b10b Run license check in CI 2022-04-01 17:42:59 -04:00
Naveen
c743f13d0d Add permissions to GitHub actions
- Included permissions for the action. https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions

Setting token permissions to read-only follows the principle of least privilege. This is important because attackers may use a compromised token with write access to push malicious code into the project.

https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
2022-04-01 16:34:21 -05:00
Katrina Verey
0d32543ebd Makefiles for all modules 2022-04-01 17:31:34 -04:00
Kubernetes Prow Robot
28ee975948 Merge pull request #4543 from turrisxyz/dependabot
Included githubactions in the dependabot config
2022-04-01 09:44:46 -07:00
Katrina Verey
2a9adbeb1e Makefile cleanup 2022-03-31 19:02:19 -04:00
Kubernetes Prow Robot
672c751715 Merge pull request #4560 from KnVerey/go1.18-tools
Update and re-enable linters
2022-03-31 10:59:02 -07:00
Katrina Verey
d3a7b9008b Enable linting from specific rev in CI 2022-03-31 11:37:37 -04:00
Katrina Verey
b0d2e4bdcd Enable more linters for new code 2022-03-31 11:37:26 -04:00
Katrina Verey
71bf0d5d14 Update full linter list and enable some easily resolved new ones 2022-03-31 11:37:26 -04:00
Katrina Verey
0a9c5cb0cf Refactor to fix gocyclo complaint 2022-03-31 11:37:26 -04:00
Katrina Verey
ff4136b1a2 cmd/config linter updates 2022-03-31 11:37:26 -04:00
Katrina Verey
1567b96ed3 Replace protobuf dep flagged by linter as deprecated 2022-03-31 11:37:26 -04:00
Katrina Verey
14947e449b Address new linter complaints 2022-03-31 11:37:26 -04:00
Katrina Verey
b368b347d1 Replace deprecated linters 2022-03-30 17:57:49 -04:00
Katrina Verey
5c359bda28 Go 1.18 compatibility updates 2022-03-30 17:57:48 -04:00
Natasha Sarkar
c94b5d8f25 Merge pull request #4553 from natasha41575/unpin
unpin modules and test against latest release
2022-03-28 17:45:50 -07:00
natasha41575
b699204a9e unpin modules and test against latest release 2022-03-28 16:21:42 -07:00
Natasha Sarkar
cf3a452ddd Merge pull request #4552 from KnVerey/version-mismatch
Copy of go 1.18 created version mismatch, reverting for now
2022-03-28 16:06:20 -07:00
Katrina Verey
faad014f96 Copy of go 1.18 created version mismatch, reverting for now 2022-03-28 19:03:47 -04:00
Natasha Sarkar
8e46ef57be Merge pull request #4551 from KnVerey/pipe_fail
Debug exit 141 failure
2022-03-28 15:46:23 -07:00
Katrina Verey
458d48430a Debug exit 141 failure 2022-03-28 18:45:07 -04:00
Kubernetes Prow Robot
3cecdc6214 Merge pull request #4550 from KnVerey/pinToApi
Update api to api/v0.11.4
2022-03-28 15:37:41 -07:00
Katrina Verey
7cac778866 Update api to api/v0.11.4 2022-03-28 18:27:12 -04:00
Katrina Verey
0aa379c228 Merge pull request #4549 from KnVerey/pinToCmdConfig
Update cmd/config to v0.10.6
2022-03-28 18:08:01 -04:00
Kubernetes Prow Robot
cd0f9b0c5b Merge pull request #4548 from KnVerey/improve-logs
Improve logging for changelong builder
2022-03-28 15:07:41 -07:00
Katrina Verey
651f0c1097 Update cmd/config to v0.10.6 2022-03-28 17:57:06 -04:00
Katrina Verey
6348ea9515 Improve logging for changelong builder 2022-03-28 17:54:09 -04:00
Katrina Verey
4b64f1e0e8 Merge pull request #4547 from KnVerey/pinToKyaml
Update kyaml to v0.13.6
2022-03-28 17:25:47 -04:00
Katrina Verey
7306402cca Update kyaml to v0.13.6 2022-03-28 17:07:02 -04:00
Natasha Sarkar
485f7d44d9 Merge pull request #4537 from KnVerey/release-updates
Converge local and cloud gorelease scripts, improve release notes
2022-03-28 13:41:02 -07:00
Katrina Verey
9e57ab72fc Copy newer Go into goreleaser image 2022-03-28 16:29:24 -04:00
Natasha Sarkar
d17ef91d94 Merge pull request #4545 from film42/gt/add_missing_refs
Add more name refs to PodTemplate for ConfigMap and Secret
2022-03-28 13:21:55 -07:00
Garrett Thornburg
e97cecf9dc Add more name refs to PodTemplate for ConfigMap and Secret 2022-03-28 14:00:17 -06:00
Katrina Verey
5833f4ca80 Make Goreleaser use the tag passed to the script 2022-03-28 14:37:29 -04:00
Katrina Verey
e86c479690 Converge local and cloud gorelease scripts, improve release notes 2022-03-28 13:43:18 -04:00
Naveen
d082c75b65 Included githubactions in the dependabot config
This should help with keeping the GitHub actions updated on new releases. This will also help with keeping it secure.

Dependabot helps in keeping the supply chain secure https://docs.github.com/en/code-security/dependabot

GitHub actions up to date https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot

https://github.com/ossf/scorecard/blob/main/docs/checks.md#dependency-update-tool

Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com>
2022-03-27 17:06:31 -05:00
Kubernetes Prow Robot
d2e59002ae Merge pull request #4538 from natasha41575/kubeopenapiupgrade
move to google/gnostic v0.5.7-v3refs
2022-03-25 15:37:58 -07:00
natasha41575
c857ff8371 move to google/gnostic v0.5.7-v3refs 2022-03-25 15:05:18 -07:00
Kubernetes Prow Robot
866e84059f Merge pull request #4541 from annasong20/bug4487
Added test for bug 4487: cannot parse keys with dots
2022-03-25 14:59:58 -07:00
Anna Song
497d2ee031 Added test for bug 4487: cannot parse keys with dots 2022-03-25 17:45:55 -04:00
Katrina Verey
c4febc59d5 Merge pull request #4536 from kubernetes-sigs/updateProwExamplesTarget
Test examples against latest release
2022-03-24 17:51:18 -04:00
Katrina Verey
19955e73ff Test examples against latest release 2022-03-24 17:32:17 -04:00
Katrina Verey
271bf31ce9 Merge pull request #4535 from KnVerey/unpinEverything
Back to development mode; unpin the modules
2022-03-24 17:31:12 -04:00
Katrina Verey
809182c6b6 Back to development mode; unpin the modules 2022-03-24 17:07:20 -04:00
Katrina Verey
0dd3d84104 Merge pull request #4531 from KnVerey/update-release-instr
Update release instructions for kubectl integration
2022-03-24 17:04:27 -04:00
Natasha Sarkar
de6b978491 Merge pull request #4534 from KnVerey/add-git-to-builder
Add git to image build docker step
2022-03-24 13:47:55 -07:00
Katrina Verey
8fa8e14eeb Add git to image build docker step 2022-03-24 16:42:39 -04:00
Natasha Sarkar
26b5e628cf Merge pull request #4533 from natasha41575/pinToApi
Pin to api v0.11.3
2022-03-24 13:36:04 -07:00
natasha41575
80853c61b8 Pin to api v0.11.3 2022-03-24 13:34:47 -07:00
Natasha Sarkar
c5ff592810 Merge pull request #4532 from natasha41575/pinToCmdConfig
Pin to cmd/config v0.10.5
2022-03-24 13:16:34 -07:00
natasha41575
b9df5686f4 Pin to cmd/config v0.10.5 2022-03-24 13:15:30 -07:00
Katrina Verey
7ff87ef5b9 Update release instructions for kubectl integration 2022-03-24 16:07:02 -04:00
Natasha Sarkar
c4d38108cf Merge pull request #4530 from natasha41575/pinToKyaml
Pin to kyaml v0.13.4
2022-03-24 13:01:01 -07:00
natasha41575
784ae5efa3 Pin to kyaml v0.13.4 2022-03-24 12:58:51 -07:00
Natasha Sarkar
e8640724a9 Merge pull request #4497 from m-Bilal/fix-3812
Fix 3812; Error message changed and check for MalformedYamlError
2022-03-24 09:55:44 -07:00
Shoshana Malfatto
7b0ec99d90 retain quotes in namespace transformer filter (#4421)
* check tag values for double quoting

* reuse setentry

* don't override single quotes in merge and fix cm generator immutable val

* get rid of comment

* starlark annotation tests

* don't commit test image changes

* set network to bool

* isSet bool

* updating e2e config tool

* leave createtag

* fn command failing unmarshal test

* fn command test

* don't set style in run-fs

* use setentry to set tag

* remove e2e test changes and make IsStringValue an RNode method
2022-03-23 14:25:19 -07:00
Kubernetes Prow Robot
fbfcb0479a Merge pull request #4527 from yuwenma/cobra
Bump cobra dependency to pick up latest vulnerability solution
2022-03-23 14:05:20 -07:00
Yuwen Ma
3421fcf81e bump dependency cobra to pick up latest vulnerability solution 2022-03-23 13:47:03 -07:00
Rafael Leal
97de780feb Fix error during expansion of !!merge <<: anchor tags (#4383)
* WIP

* Fix merge corner cases

* Add test for explicit !!merge tag

* Fix tests

* Cleanup

* Cleanup

* Fix deanchoring lists

* Add test case for keeping comments

* Add MapEntrySetter and fix json marshalling after deanchoring

* Keep duplicated keys

* Move MergeTag definition to yaml alias

* Remove go-spew from api

* Add support for sequence nodes on merge tags

* Add docstring to MapEntrySetter.Key

* Add docstring to MapEntrySetter struct

* Add tests to MapEntrySetter

* Fix duplicate merge key

* Revert whitespace changes on forked go-yaml

* Remove AssocMapEntry function

* Refactoring merge order

* Return errors on VisitFields and PipeE

* Add tests for each non-conforming map merges
2022-03-23 09:36:17 -07:00
Robert Facciol
3490fb8716 Initial commit for a tutorial on getting started with kustomize (#4516)
* Initial commit for a tutorial on getting started with kustomize

* add build commands and update comment with name of the file

* Update site/content/en/docs/Getting started/first_kustomization.md

Co-authored-by: David Jacob <davidmjacob86@gmail.com>

* Update site/content/en/docs/Getting started/first_kustomization.md

Co-authored-by: David Jacob <davidmjacob86@gmail.com>

* fix typo

* Update site/content/en/docs/Getting started/first_kustomization.md

Co-authored-by: Natasha Sarkar <natashasarkar@google.com>

* Update site/content/en/docs/Getting started/first_kustomization.md

Co-authored-by: Natasha Sarkar <natashasarkar@google.com>

* Update site/content/en/docs/Getting started/first_kustomization.md

Co-authored-by: Natasha Sarkar <natashasarkar@google.com>

* Update site/content/en/docs/Getting started/first_kustomization.md

Co-authored-by: Natasha Sarkar <natashasarkar@google.com>

* Update site/content/en/docs/Getting started/first_kustomization.md

Co-authored-by: Natasha Sarkar <natashasarkar@google.com>

* Update site/content/en/docs/Getting started/first_kustomization.md

Co-authored-by: Natasha Sarkar <natashasarkar@google.com>

* Update site/content/en/docs/Getting started/first_kustomization.md

Co-authored-by: Natasha Sarkar <natashasarkar@google.com>

* Update site/content/en/docs/Getting started/first_kustomization.md

Co-authored-by: Natasha Sarkar <natashasarkar@google.com>

* updates following review

* updates to getting started guide

* Update site/content/en/docs/Getting started/first_kustomization.md

Co-authored-by: Katrina Verey <kn.verey@gmail.com>

* Update site/content/en/docs/Getting started/first_kustomization.md

Co-authored-by: Katrina Verey <kn.verey@gmail.com>

* updates to consolidate example into one folder

Co-authored-by: David Jacob <davidmjacob86@gmail.com>
Co-authored-by: Natasha Sarkar <natashasarkar@google.com>
Co-authored-by: Katrina Verey <kn.verey@gmail.com>
2022-03-22 13:21:58 -07:00
Kubernetes Prow Robot
2fe04496c2 Merge pull request #4485 from roopeshvs/master
Support for multiple replacements in a single file when replacing using path
2022-03-18 11:42:13 -07:00
Kubernetes Prow Robot
b0d7721049 Merge pull request #4513 from joebowbeer/patch-2
Update valueAdd.md
2022-03-17 11:54:42 -07:00
Kubernetes Prow Robot
18f22f10a3 Merge pull request #4511 from NoicFank/master
fix broken link
2022-03-17 11:12:54 -07:00
Kubernetes Prow Robot
3ae5aa9e13 Merge pull request #4494 from lack/replacement/string-int-autoconvert
Preserve scalar types when using the replacement filter
2022-03-16 10:06:19 -07:00
Kubernetes Prow Robot
48f21e920a Merge pull request #4508 from DavidJacob/kustomize-io-website
New kustomize.io website
2022-03-10 15:33:08 -08:00
Joe Bowbeer
dcdefca70e Update valueAdd.md
Signed-off-by: Joe Bowbeer <joe.bowbeer@gmail.com>
2022-03-10 23:29:45 +00:00
David Jacob
c64351aa01 Exclude site directory from go.mod search 2022-03-09 18:03:04 +01:00
David Jacob
c60979ee3e Remove license and background image and moinitor wording changes 2022-03-09 17:47:29 +01:00
Jim Ramsay
cb80659c22 Preserve scalar types when using the replacement filter
Erasing the scalar type tag leads to unfortunate circumstances, in that
the resulting yaml code is valid yaml, but will not meet the object
spec.

For example, using the replacement transformer to take a port number as
a string from a ConfigMap and set a Pod port would previously end up
with:
 - containerPort: "8080"
when the spec requires that this is not a string:
 - containerPort: 8080

Added unit tests for conversion to and from integers and booleans, plus
creation from string and creation from integer.

The creation behavior needs some refinement in a future PR.

Signed-off-by: Jim Ramsay <i.am@jimramsay.com>
2022-03-09 06:39:12 -05:00
Dingzhu Lurong
b1086ac49b fix broken link 2022-03-09 16:00:59 +08:00
David Jacob
1fcd66258f Add the kustomize.io docsy template 2022-03-06 12:29:12 +01:00
roopeshvs
d1d578c392 support for multiple replacements in a single file 2022-03-04 12:46:45 +05:30
Kubernetes Prow Robot
f67dd5bbbd Merge pull request #4504 from rob8714/remove-site-and-docs-folder-v2
Remove site and docs folder
2022-03-02 12:49:13 -08:00
Natasha Sarkar
ac5c51ba2c Merge pull request #4503 from KnVerey/fix-more-links
Remove more links to defunct site
2022-03-02 11:57:26 -08:00
rob8714
53cc76fe43 added images folder to images that would break in README and additionally updated overlays.jpg to remove the reference to 'bases' 2022-03-02 20:37:39 +01:00
rob8714
07eb595eb2 Remove site folder 2022-03-02 20:34:00 +01:00
rob8714
8cb7acfdcb Remove docs folder 2022-03-02 20:33:37 +01:00
Katrina Verey
975482390f Remove more links to defunct site 2022-03-02 14:04:17 -05:00
Kubernetes Prow Robot
701695c343 Merge pull request #4499 from olegsu/fix-community-docs
fix: broken reference to roadmap objectives
2022-03-01 17:31:13 -08:00
Katrina Verey
8db1267983 Merge pull request #4502 from KnVerey/fix-links
Replace links to removed site
2022-03-01 20:02:22 -05:00
Katrina Verey
da7ec577b2 Replace links to removed site 2022-03-01 19:17:55 -05:00
Oleg Sucharevich
d17b171207 fix: broken reference to roadmap objectives 2022-03-01 20:11:32 +02:00
Kubernetes Prow Robot
70ce89d993 Merge pull request #4434 from jwmatthews/install_arch
Install arch appropriate build if the 'arch' command is present
2022-02-28 09:18:57 -08:00
Mohd Bilal
e25db3df2e Test case updated 2022-02-27 09:11:00 +00:00
Mohd Bilal
3eae520532 test case added 2022-02-27 08:11:42 +00:00
Mohd Bilal
3ec7b10bc0 Error message corrected 2022-02-27 07:48:55 +00:00
Mohd Bilal
6dabba1d23 misspell corrected 2022-02-27 07:47:59 +00:00
Mohd Bilal
bd05631887 Error type MalformedYamlError created. api.internal.target.kusttarget.accumulateResources checks for this new error type 2022-02-27 07:21:16 +00:00
Kubernetes Prow Robot
6950a0d246 Merge pull request #4467 from KnVerey/fn-cfg-openapi-validation
fn framework: Enable validation using openAPI schema for functionConfig
2022-02-24 10:32:31 -08:00
Katrina Verey
c90504a19d Enable validation using function config schema from KRMFunctionDefinition 2022-02-24 13:20:29 -05:00
Kyle Cronin
8dab94964f Fix image name parsing with tag and digest (#4406)
* Fix image name parsing with name and digest

Image names may contain both tag name and digest.  For example
`nginx:1.21.5@sha256:7826426c9d8d310c62fc68bcd5e8dde70cb39d4fbbd30eda3b1bd03e35fbde29`. Kustomizations with image transforms will not match
these image because the image parser assumes either a tag or digest, but not
both.

For a real life example of kuberenetes deployments that might need to perform
these types of transforms is from the [tekton-pipelines](https://github.com/tektoncd/pipeline) project (see the release.yaml).

* Return digest property from image name parser

image.Split now returns 3 fields: name, tag, and digest. The tag and digest
fields no longer include their respective delimiters (`:` and `@`).

* Fix merge file indentation

* Refactor imagetag updater string builder
2022-02-16 09:02:37 -08:00
Kubernetes Prow Robot
ff40460d3b Merge pull request #4424 from koba1t/feature/allow_setting_every_array_element_in_replacements
Allow setting every array element in replacements
2022-02-09 17:03:46 -08:00
Kubernetes Prow Robot
a7f4db7fb4 Merge pull request #4030 from thatsmydoing/url-format
Update supported URLs in remoteBuild.md
2022-02-09 16:37:47 -08:00
Natasha Sarkar
5d0762411c Merge pull request #4468 from natasha41575/updateProwExamplesTarget
Test examples against latest release
2022-02-09 16:26:34 -08:00
natasha41575
b4e116346e Test examples against latest release 2022-02-09 16:16:10 -08:00
Natasha Sarkar
9091919699 Merge pull request #4466 from natasha41575/pinToApi
Pin to api v0.11.2
2022-02-09 15:19:28 -08:00
natasha41575
702a56e2f1 Pin to api v0.11.2 2022-02-09 15:09:41 -08:00
Natasha Sarkar
00a9c59dd7 Merge pull request #4465 from natasha41575/pinToCmdConfig
Pin to cmd/config v0.10.4
2022-02-09 14:57:04 -08:00
natasha41575
4dfc2a9507 Pin to cmd/config v0.10.4 2022-02-09 14:44:37 -08:00
Sylvain Rabot
2f17803c0a Fix pseudo git HTTP urls broken since 59c82659 (#4453)
* Fix pseudo git HTTP urls broken since 59c82659

Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>

* Add test for Git resources using HTTP URLs

Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
2022-02-09 14:23:49 -08:00
koba1t
5ed96a34d7 rename IsMatchEveryIndex to IsWildcard 2022-02-10 05:13:29 +09:00
Kubernetes Prow Robot
14cb815b5d Merge pull request #4452 from KnVerey/2022-roadmap
Commit 2022 roadmap presented to SIG-CLI
2022-02-07 23:30:54 -08:00
Kubernetes Prow Robot
a5df6f7fd9 Merge pull request #4387 from Neo2308/remove-exclude-statements
Remove exclude statements
2022-02-07 08:49:44 -08:00
John Matthews
4f5dfb5d42 Updating with 'uname -m' 2022-02-05 09:02:28 -05:00
Katrina Verey
6374d3d593 Commit 2022 roadmap presented to SIG-CLI 2022-02-04 12:25:34 -05:00
koba1t
22f9daa3ab replacements allow to replace multi values 2022-02-04 04:09:50 +09:00
Natasha Sarkar
c3c7013f09 Merge pull request #4450 from natasha41575/updateProwExamplesTarget
Test examples against latest release
2022-02-02 14:12:00 -08:00
natasha41575
3277ff9dbf Test examples against latest release 2022-02-02 12:02:01 -08:00
Natasha Sarkar
746bd18a8c Merge pull request #4449 from natasha41575/pinToApi
Pin to api v0.11.1
2022-02-02 11:02:13 -08:00
natasha41575
d7763045ea Pin to api v0.11.1 2022-02-02 11:01:54 -08:00
Kubernetes Prow Robot
30612cfd17 Merge pull request #4447 from KnVerey/update_release_instr
Update release instructions to check for blockers
2022-02-02 11:00:06 -08:00
Natasha Sarkar
3006846d67 Merge pull request #4448 from natasha41575/pinToCmdConfig
Pin to cmd/config v0.10.4
2022-02-02 10:45:53 -08:00
natasha41575
2f9617ff56 Pin to cmd/config v0.10.4 2022-02-02 10:45:22 -08:00
Natasha Sarkar
28b3e9fb9c Merge pull request #4446 from natasha41575/pinToKyaml
Pin to kyaml v0.13.3
2022-02-02 10:41:19 -08:00
Katrina Verey
6a7caf4192 Update release instructions to check for blockers 2022-02-02 13:37:39 -05:00
natasha41575
32e13bdf66 Pin to kyaml v0.13.3 2022-02-02 10:36:53 -08:00
Kubernetes Prow Robot
fcfd30ca18 Merge pull request #4445 from KnVerey/ordering_regression_4388
Fix regression 4388
2022-02-02 09:58:21 -08:00
Katrina Verey
a86723c3a3 Fix regression 4388 2022-02-02 12:36:03 -05:00
Natasha Sarkar
01d7fae382 Merge pull request #4443 from natasha41575/updateProwExamplesTarget
Test examples against latest release
2022-02-01 16:43:20 -08:00
Natasha Sarkar
39349c4fbc Merge pull request #4442 from natasha41575/unpinEverything
Back to development mode; unpin the modules
2022-02-01 16:43:07 -08:00
natasha41575
836a721a47 Test examples against latest release 2022-02-01 16:33:47 -08:00
natasha41575
78e8d4318a Back to development mode; unpin the modules 2022-02-01 16:32:40 -08:00
Natasha Sarkar
67591762a6 Merge pull request #4441 from natasha41575/pinToApi
Pin to api v0.11.0
2022-02-01 16:18:57 -08:00
natasha41575
f38648df34 Pin to api v0.11.0 2022-02-01 16:08:14 -08:00
Natasha Sarkar
d46bb0a453 Merge pull request #4440 from natasha41575/pinToCmdConfig
Pin to cmd/config v0.10.3
2022-02-01 15:45:47 -08:00
natasha41575
939545a007 Pin to cmd/config v0.10.3 2022-02-01 15:29:55 -08:00
Natasha Sarkar
fb768687ea Merge pull request #4439 from KnVerey/update-year
Miscellaneous cleanup
2022-02-01 15:10:19 -08:00
Katrina Verey
7bc51153d0 Add missing header 2022-02-01 18:06:27 -05:00
Natasha Sarkar
2b3d9dd67b Merge pull request #4438 from natasha41575/pinToKyaml
Pin to kyaml v0.13.2
2022-02-01 14:51:46 -08:00
Katrina Verey
98fce99f96 Commit missing go.sum updates 2022-02-01 17:42:37 -05:00
Katrina Verey
3c1e695f3f Update year in all the addlicense targets 2022-02-01 17:41:44 -05:00
natasha41575
91ff4eefb2 Pin to kyaml v0.13.2 2022-02-01 14:41:11 -08:00
Kubernetes Prow Robot
f0c0d931fe Merge pull request #4437 from natasha41575/fixMake
fix test-unit-kustomize-api
2022-02-01 14:25:49 -08:00
natasha41575
f5b2b751eb fix test-unit-kustomize-api 2022-02-01 14:16:00 -08:00
Kubernetes Prow Robot
cfd9278fd8 Merge pull request #4431 from sdowell/implement-trackable-filters
Implement trackable filters
2022-02-01 10:14:10 -08:00
koba1t
b79d77a8a7 add replacements every element match test 2022-01-30 18:52:53 +09:00
John Matthews
91f65b3441 Install arch appropriate build if the 'arch' command is present 2022-01-29 11:17:48 -05:00
Sam Dowell
ba55d95542 feat: implement TrackableFilter for suffix
This change updates the suffix filter to implement the TrackableFilter
interface. This provides the functionality for the user to track which
fields were updated by the suffix filter.
2022-01-28 21:25:35 +00:00
Sam Dowell
851b3fc28c feat: implement TrackableFilter for replicacount
This change updates the replicacount filter to implement the
TrackableFilter interface. This provides the functionality for the
user to track which fields were updated by the replicacount filter.
2022-01-28 21:25:34 +00:00
Sam Dowell
90493ec374 feat: implement TrackableFilter for prefix
This change updates the prefix filter to implement the TrackableFilter
interface. This provides the functionality for the user to track which
fields were updated by the prefix filter.
2022-01-28 21:25:34 +00:00
Sam Dowell
51b767b06e feat: implement TrackableFilter for namespace
This change updates the namespace filter to implement the TrackableFilter
interface. This provides the functionality for the user to track which
fields were updated by the namespace filter.
2022-01-28 21:25:34 +00:00
Sam Dowell
e3160373f0 test: add testutil for mutation tracker
This change provides a common test util for a mutation tracker stub.
This is intended to reduce the duplicated boilerplate as additional
filters implement the TrackableFilter interface.
2022-01-28 21:25:34 +00:00
Kubernetes Prow Robot
a5b61016bb Merge pull request #4425 from sdowell/fieldspec-sequencenode-fieldpath
fix: set FieldPath for SequenceNode elements
2022-01-27 10:22:00 -08:00
Kubernetes Prow Robot
d62cc6d6a2 Merge pull request #4426 from KnVerey/update-maintainers
Update owners file
2022-01-26 17:44:51 -08:00
Natasha Sarkar
bcebad1664 new command kustomize edit add buildmetadata (#4413)
* new command kustomize edit add buildmetadata

* new commands kustomize edit set buildmetadata and kustomize edit remove buildmetadata
2022-01-26 15:34:50 -08:00
Sam Dowell
9abf5fca3c fix: set FieldPath for SequenceNode elements
The FieldPath was not being set for nodes underneath a SequenceNode
during fieldspec's traversal. This is in part because handleSequence
uses VisitElements in contrast to a PathGetter as is done by handleMap.

The accuracy of FieldPath is more relevant now with the recently added
support of mutation trackers in filtersutil. This change fixes the
case where a mutation tracker callback is called on a SequenceNode
element and the node does not have an accurate FieldPath value.
2022-01-26 23:33:25 +00:00
koba1t
26b9af0379 Allow setting every array element in replacements 2022-01-27 06:17:23 +09:00
Kubernetes Prow Robot
c65ef489ca Merge pull request #4418 from sdowell/imagetag-trackable-filter
Imagetag trackable filter
2022-01-25 14:15:41 -08:00
Kubernetes Prow Robot
c754eadabc Merge pull request #4396 from mengqiy/oabench
Add benchmark test for parsing openapi in protobuf format
2022-01-25 12:23:42 -08:00
Mengqi Yu
816e2365bf Add benchmark test for parsing openapi in protobuf format 2022-01-25 12:10:25 -08:00
Sam Dowell
302cc866ad implement TrackableFilter interface with imagetag
This change updates the imagetag filter to implement the TrackableFilter
interface. This provides the functionality for the user to track which
fields were updated by the imagetag filter.
2022-01-24 22:42:48 +00:00
Sam Dowell
bf97d23a00 refactor: use SetScalar in imagetag filter
This change refactors imagetag to reuse the abstraction provided by
filtersutil. This change is intended to make imagetag more consistent
with other filters by using the same layer of abstraction (filtersutil),
and to prepare for upcoming changes which are planned to be implemented
at the filtersutil layer.
2022-01-24 22:02:16 +00:00
sdowell
3687250ca2 Add TrackableFilter interface (#4410)
* add kio filter interface

This interface is an extension of the Filter interface which can be used
for filters which are capable of tracking which fields they mutate.

* add TrackableSetter struct to filtersutil

This struct provides an abstraction to help Filters implement the
TrackableFilter interface

* implement TrackableFilter with annotations

This updates the annotations filter to implement the TrackableFilter
interface by reusing the TrackableSetter abstraction provided by
filtersutil.

This is done to provide a generic and consistent experience across the
filters

* implement TrackableFilter with labels

This updates the labels filter to implement the TrackableFilter
interface by reusing the TrackableSetter abstraction provided by
filtersutil.

This is done to provide a generic and consistent experience across the
filters
2022-01-24 11:05:32 -08:00
Kubernetes Prow Robot
69e5228264 Merge pull request #4411 from koba1t/fix_run-fns_command_help_message_typo
fix deprecated help message to `kustomize fn run --help`
2022-01-21 10:59:20 -08:00
koba1t
7af5ce56bd fix deprecated command on run-fns help docs 2022-01-21 08:39:59 +09:00
Kubernetes Prow Robot
d711b275f0 Merge pull request #4373 from natasha41575/TransformerAnnotationsFull
set transformer annotations when the option is specified
2022-01-19 21:47:51 -08:00
natasha41575
9577d61167 move origin to be an attribute of KustTarget 2022-01-19 17:26:19 -08:00
natasha41575
2c23b960ff set transformer annotation when the option is specified 2022-01-19 17:17:47 -08:00
Kubernetes Prow Robot
6e5d2674ce Merge pull request #4377 from natasha41575/managedBy
deprecate enable-managedby-label flag in favor of a field
2022-01-19 17:03:51 -08:00
natasha41575
2554d690c8 deprecate enable-managedby-label flag in favor of a field 2022-01-19 16:53:27 -08:00
Katrina Verey
cec9298b2d Update owners file to reflect active contributors 2022-01-18 22:32:01 -05:00
Thomas Dy
54ae9ba9fc Update supported URLs in remoteBuild.md 2022-01-18 17:27:30 +09:00
Neo2308
b73dfe7f35 Remove exclude statements 2022-01-14 16:49:02 +05:30
Kubernetes Prow Robot
6e82b210a9 Merge pull request #4385 from kubernetes-sigs/revert-4329-configMapIssue
Revert "[fix] configMapGenerator: extra space in end of line gives "\n" instead of line breaks"
2022-01-12 11:52:13 -08:00
Natasha Sarkar
b0636459dd Revert "[fix] configMapGenerator: extra space in end of line gives "\n" instead of line breaks" 2022-01-12 09:30:41 -08:00
Kubernetes Prow Robot
13e26004fd Merge pull request #4357 from natasha41575/TransformerAnnotations
define methods, types, and unit tests for transformer annotations
2022-01-10 15:32:28 -08:00
Kubernetes Prow Robot
a1a0a49822 Merge pull request #4370 from sonthonaxrk/fix-helm-globals
Fix helm globals
2022-01-10 10:13:13 -08:00
Kubernetes Prow Robot
ff2a3d368b Merge pull request #4294 from Jimmyscene/master
fix: prevent read file from throwing away OpenAPI config
2022-01-10 10:01:12 -08:00
Kubernetes Prow Robot
1c5ce6975f Merge pull request #4312 from m-Bilal/fix-4240
Fixes 4240; added null check on namespace when resource is a RoleBinding
2022-01-10 09:43:13 -08:00
Rollo
fe99674fcd Fix helm globals 2022-01-10 10:54:20 +00:00
m-Bilal
7674c220b1 Improved error message and test cases for 4240 2022-01-09 19:05:49 +05:30
Kubernetes Prow Robot
469ae33b50 Merge pull request #4369 from sdowell/labels-filter-set-entry
feat: add SetEntryCallback to labels filter
2022-01-06 16:06:30 -08:00
Sam Dowell
fbd949a95d feat: add SetEntryCallback to labels filter
Add a configurable callback that is invoked each time a label is applied
by the labels filter. This is useful for scenarios such as tracking
labels as they are applied.
2022-01-06 01:01:09 +00:00
Kubernetes Prow Robot
c996d1fcab Merge pull request #4367 from natasha41575/KubectlInstructions
instructions for how to upgrade kustomize in kubectl
2022-01-04 18:14:33 -08:00
natasha41575
41917ca588 instructions for how to upgrade kustomize in kubectl 2022-01-04 17:47:47 -08:00
Kubernetes Prow Robot
37668d87c4 Merge pull request #4361 from natasha41575/EditAddGenerator
add kustomize edit add generator command
2022-01-04 17:24:32 -08:00
natasha41575
92197fda9e add kustomize edit add generator command 2022-01-04 15:26:46 -08:00
m-Bilal
ff7b2f20d5 Throwing error instead of silently ignoring invalid input 2022-01-01 21:52:37 +05:30
Kubernetes Prow Robot
59c8268245 Merge pull request #4334 from sylr/handle-http-errors
Handle HTTP error codes in file loader
2021-12-30 16:18:51 -08:00
natasha41575
4f21d60045 helper methods, types, and unit tests for transformer annotations 2021-12-29 15:27:34 -08:00
Kubernetes Prow Robot
77b1af2d91 Merge pull request #4352 from natasha41575/FilterErrors
prevent internal annotations from showing up in the errors thrown by filters
2021-12-29 13:45:22 -08:00
Kubernetes Prow Robot
bb0a520f40 Merge pull request #4355 from natasha41575/OriginTests
test coverage for origin annotations for generated resources
2021-12-29 11:41:22 -08:00
natasha41575
987437857f test coverage for origin annotations for generated resources 2021-12-28 12:41:47 -08:00
Kubernetes Prow Robot
1843b6f25f Merge pull request #4310 from sylr/upgrade-cobra
Upgrade cobra for better zsh support
2021-12-23 13:58:29 -08:00
Sylvain Rabot
31b7cf9e0a Upgrade cobra for better zsh support
Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
2021-12-23 19:49:24 +01:00
Natasha Sarkar
964bb38ba2 add origin annotation for resources generated by generators (#4341)
* add origin annotation for resources generated by builtin and custom generators

* decouple origin data from generator data and account for inline generators
2021-12-23 10:40:29 -08:00
natasha41575
c659306ee2 don't surface entire node content in error message 2021-12-22 16:56:02 -08:00
Kubernetes Prow Robot
233f1a3c2a Merge pull request #4344 from natasha41575/ResIdStr
improve gvk and resid strings for error messages
2021-12-22 12:27:03 -08:00
Kubernetes Prow Robot
75de98e2ef Merge pull request #4055 from lstoll/lstoll-unrelated-name-reference
ConfigMapGenerator should not update unrelated ClusterRole rule
2021-12-22 12:15:04 -08:00
Julian
3dbc88bf94 Refactor the PrefixSuffixTransformer into separate prefix- and suffix transformers (#4318)
* Refactor prefix filter into its own filter, decoupled from the prefixsuffix filter

* Refactor prefix transformer into its own transformer, decoupled from the prefixsuffix transformer

* Refactor suffix filter into its own filter, decoupled from the prefixsuffix filter

* Refactor suffix transformer into its own transformer, decoupled from the prefixsuffix transformer

* Add a default nameSuffix field spec in addition to the namePrefix

* Remove the PrefixSuffixTransformer from the list of builtin transformers

* Add a multi-transformer to builtinhelpers.TransformFactories

* Remove the implementation of the prefixsuffixtransformer.PrefixSuffixTransformer

* Resolve style and format related feedback from the pull request

* Add test to test the legacy PrefixSuffixTransformer for BC purposes
2021-12-22 12:01:06 -08:00
Katrina Verey
d701792aa1 Update test demonstrating bug to pass, update comments 2021-12-22 14:53:50 -05:00
Lincoln Stoll
4079056501 ConfigMapGenerator should not update unrelated ClusterRole rule
When using the ConfigMap generator, a lease object entry is updated with the
generated configmap name. This should not happen as it's an unrelated object
type.

As a workaround a unique name can be used for the ConfigMap.

Fails on kustomize version 4.2.0 and kubectl version v1.21.2
2021-12-22 14:47:40 -05:00
natasha41575
6dfc238aa2 improve gvk and resid strings for error messages 2021-12-22 11:39:07 -08:00
Kubernetes Prow Robot
3608f335fd Merge pull request #3924 from monopole/architecture
Add ARCHITECTURE.md
2021-12-22 11:35:04 -08:00
Katrina Verey
56efec5abc Minor updates and clarifications 2021-12-22 14:23:00 -05:00
monopole
2a608bd71c Add ARCHITECTURE.md 2021-12-22 12:07:27 -05:00
Kubernetes Prow Robot
ee4b7847f0 Merge pull request #4221 from devstein/master
docs: Update Plugin Links
2021-12-20 16:37:07 -08:00
Kubernetes Prow Robot
ec38bbeb99 Merge pull request #4342 from natasha41575/moduleSpanDefault
Remove module span check
2021-12-15 11:45:51 -08:00
natasha41575
26999664e6 remove multi-module check 2021-12-15 11:06:38 -08:00
Kubernetes Prow Robot
c0b61b9442 Merge pull request #4332 from natasha41575/OriginCollection
collect origin data only when the option is set
2021-12-13 13:10:26 -08:00
Kubernetes Prow Robot
274a76fe84 Merge pull request #4267 from natasha41575/TransformerAnnotationsProposal
Proposal: Option for transformer annotations
2021-12-13 12:05:58 -08:00
natasha41575
a8f58b4080 collect origin data only when the option is set 2021-12-13 11:38:03 -08:00
natasha41575
542b7c7c4c proposal for transformer annotations option 2021-12-10 12:31:19 -08:00
Sylvain Rabot
16495c6ed7 Test HTTP Error thrown by the file loader
Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
2021-12-10 09:28:54 +01:00
Sylvain Rabot
738573b079 Error on HTTP resources are not nescessarly protocol related
Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
2021-12-10 09:27:37 +01:00
Sylvain Rabot
e65e571ed1 Do not try to load HTTP resources from FS when error occurs
It is useless and it clogs the error message.

Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
2021-12-08 18:24:29 +01:00
Sylvain Rabot
49b464fd4d Handle HTTP error codes in file loader
GitHub release files like https://github.com/fluxcd/helm-controller/releases/download/v0.14.0/helm-controller.crds.yaml
seems to be hosted on Azure and it seems that there are egress limits that can be reached, e.g.:

```xml
<?xml version="1.0" encoding="utf-8"?><Error><Code>ServerBusy</Code><Message>Egress is over the account limit.
RequestId:f4a46b38-001e-0046-2437-ec16e2000000
Time:2021-12-08T13:28:03.8542138Z</Message></Error>
```

This patch allows to have a clear Error message instead of just `missing Resource metadata`:

```
Error: accumulating resources: accumulation err='accumulating resources from 'https://github.com/fluxcd/source-controller/releases/download/v0.19.0/source-controller.crds.yaml': URL returned error 503 (Service Unavailable)': evalsymlink failure on '/private/var/folders/hq/ttl6jyh539q55fz6282w0jyc0000gn/T/kustomize-3508224975/releases/download/v0.19.0/source-controller.crds.yaml' : lstat /private/var/folders/hq/ttl6jyh539q55fz6282w0jyc0000gn/T/kustomize-3508224975/releases: no such file or directory
```

Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
2021-12-08 14:31:35 +01:00
Kubernetes Prow Robot
9a875add84 Merge pull request #4329 from natasha41575/configMapIssue
[fix] configMapGenerator: extra space in end of line gives "\n" instead of line breaks
2021-12-07 18:07:40 -08:00
natasha41575
a3d547ccd3 fix issue with multiline configmap data with extra space 2021-12-03 15:28:22 -08:00
natasha41575
c4a8a99834 add regression tests for multiline configmap with space 2021-12-03 15:12:21 -08:00
Kubernetes Prow Robot
bc3b249489 Merge pull request #4328 from mengqiy/undeprecate
Remove the deprecation warning for a few RNode helpers
2021-12-03 14:12:36 -08:00
Mengqi Yu
cd2c6a1ad1 Remove the deprecation warning for a few RNode helpers
The Pipe method is not as intuitive as these helpers. These helpers
are convenient and useful. Deprecating them before we have better
alternatives is premature.
2021-12-03 11:47:34 -08:00
Kubernetes Prow Robot
8c6af9440c Merge pull request #4327 from mengqiy/fixanno
use internal.config.kubernetes.io prefix instead of internal.config.k8s.io
2021-12-03 10:02:27 -08:00
Mengqi Yu
6850408f6c update test for cmd/config 2021-12-02 14:00:45 -08:00
Mengqi Yu
ec445049be update tests for api 2021-12-02 14:00:32 -08:00
Mengqi Yu
646915cb86 use internal.config.kubernetes.io prefix instead of internal.config.k8s.io 2021-12-02 14:00:18 -08:00
Kubernetes Prow Robot
fe551be87b Merge pull request #4326 from natasha41575/deprecateStringAndDatePrefixer
deprecate StringPrefixer and DatePrefixer
2021-12-02 10:41:44 -08:00
natasha41575
30280f81af deprecate stringprefixer and dateprefixer 2021-12-02 10:30:56 -08:00
Kubernetes Prow Robot
8cb60f0c5d Merge pull request #4325 from sdowell/kyaml-fn-sort-results
feat: Add Sort method to kyaml fn Results
2021-12-02 10:01:33 -08:00
Sam Dowell
9d29f57789 feat: Add Sort method to kyaml fn Results
Issues: GoogleContainerTools/kpt#2195
2021-12-01 20:57:48 +00:00
Kubernetes Prow Robot
a3e1c99915 Merge pull request #4307 from sdowell/annotations-filter-set-entry
feat: Add SetEntryCallback to annotations filter
2021-11-29 18:20:56 -08:00
Sam Dowell
0fe1236e20 feat: Add SetEntryCallback to annotations filter
Add a configurable callback that is invoked each time an
annotation is applied by the annotations filter. This is useful
for scenarios such as tracking annotations as they are applied.

Issues: GoogleContainerTools/kpt#2448
2021-11-30 01:21:42 +00:00
m-Bilal
b28f1e55b7 fixes 4240; added null check on namespace when resource is a RoleBinding 2021-11-27 19:53:49 +05:30
Kubernetes Prow Robot
25ee506af4 Merge pull request #4300 from yuwenma/refactor-builtin
Move api/builtin to internal
2021-11-22 16:04:16 -08:00
Yuwen Ma
a1c5d79d94 Move api/builtin to internal 2021-11-22 15:54:18 -08:00
Kubernetes Prow Robot
de5210b43a Merge pull request #4299 from yuwenma/nameReference-doc
[Doc] Improve `nameReference`  docs, examples and builtin references.
2021-11-22 13:25:32 -08:00
Yuwen Ma
d9c4c749e2 improve docs with examples for nameReference 2021-11-22 13:10:13 -08:00
Natasha Sarkar
01420768c8 Merge pull request #4241 from Goodwine/kyaml-result-provider
Handle "Result" errors as non-fatal errors in kyaml FilterFuncs
2021-11-22 11:07:18 -08:00
Natasha Sarkar
d11342489a Merge pull request #4297 from mengqiy/anno
kyaml/fn/framework ensures the annotation output format matches the input
2021-11-19 12:37:01 -08:00
Mengqi Yu
bd7bad19a1 add to BuildAnnotations 2021-11-19 12:13:12 -08:00
Mengqi Yu
dfc627068b update tests for cmd/config module 2021-11-19 07:30:31 -08:00
Mengqi Yu
166c2e766b update tests for api module 2021-11-19 07:30:31 -08:00
Mengqi Yu
2ee2d3e389 use custom id as key of the mapping and make kio.Pipeline behave the same as framework.Execute 2021-11-19 07:30:31 -08:00
Mengqi Yu
81edfb7ee8 default result.severity to info when formatting string 2021-11-19 07:30:31 -08:00
Mengqi Yu
4e7aebc20c address comments 2021-11-18 14:58:04 -08:00
Mengqi Yu
5caed5b90a kyaml/fn/framework ensures the annotation output format matches the input
If the input only contains legacy format anntations (path, index, id), the
output will be the same.
2021-11-17 14:09:19 -08:00
Jimmyscene
f4d8ccda10 fix: prevent read file from throwing away OpenAPI config 2021-11-16 22:59:34 -05:00
Goodwine
4cde50ab14 fix typo
Co-authored-by: Katrina Verey <kn.verey@gmail.com>
2021-11-11 16:33:17 -08:00
Kubernetes Prow Robot
2f115223cc Merge pull request #4285 from KnVerey/updateProwExamplesTarget
Test examples against latest release
2021-11-11 16:12:28 -08:00
Katrina Verey
92c505a211 Test examples against latest release 2021-11-11 16:00:51 -08:00
Kubernetes Prow Robot
e9ea7657ee Merge pull request #4284 from KnVerey/unpinEverything
Back to development mode; unpin the modules
2021-11-11 15:59:15 -08:00
Katrina Verey
4bcc57de74 Back to development mode; unpin the modules 2021-11-11 15:49:01 -08:00
Kubernetes Prow Robot
b2d65ddc98 Merge pull request #4283 from KnVerey/pinToApi
Pin to api v0.10.1
2021-11-11 15:27:14 -08:00
Carlos Ortiz García
894ffec36a Handle kyaml Filter errors type Result as non-breaking errors and store in ResourceList
- Result can only count as error when passed as pointer, this makes easy use of "errors.As"
- Existing Filter() implementations that return Result from the `framework` package won't return an error anymore but modify the ResourceList
2021-11-11 15:26:07 -08:00
Katrina Verey
3db4a94281 Pin to api v0.10.1 2021-11-11 15:18:05 -08:00
Kubernetes Prow Robot
326a57a9cc Merge pull request #4282 from KnVerey/pinToCmdConfig
Pin to cmd/config v0.10.2
2021-11-11 15:03:14 -08:00
Katrina Verey
9dfdebc6c7 Pin to cmd/config v0.10.2 2021-11-11 14:53:17 -08:00
Natasha Sarkar
b896e04c20 Merge pull request #4281 from KnVerey/pinToKyaml
Pin to kyaml v0.13.0
2021-11-11 14:39:53 -08:00
Katrina Verey
6ecae1ad50 Also pin patch and patchjson transformers 2021-11-11 14:30:39 -08:00
Katrina Verey
9abb72e4d6 Pin to kyaml v0.13.0 2021-11-11 14:12:13 -08:00
Kubernetes Prow Robot
6365b3d0cf Merge pull request #4280 from KnVerey/more_releases
Add s390x and ppc64le binaries to releases
2021-11-11 13:52:07 -08:00
Katrina Verey
33c2ea01c4 Add s390x and ppc64le binaries to releases 2021-11-11 13:37:50 -08:00
Kubernetes Prow Robot
863ff0ef1b Merge pull request #4262 from patricknelson/fix-windows-build
Fix windows build, add clarity to goreleaser build (due to race conditions).
2021-11-11 13:32:08 -08:00
Patrick Nelson
a5117083ec Step 2 of 2: Adding windows build back and added ability to reproduce goreleaser builds locally (localbuild.sh) in a way exactly consistent with Cloud Build (cloudbuild.sh) but as a *build* only, without being coupled to Cloud Build or it's dependencies (like Cloud KMS, GitHub, etc). 2021-11-11 12:17:42 -08:00
Patrick Nelson
a143688a1d Step 1 of 2: Renaming localbuild.sh to cloudbuild-local.sh (preserve commit history) to make way for new localbuild.sh which will actually be entirely local, since this script is still very specific to Cloud Build. 2021-11-10 19:03:22 -08:00
Kubernetes Prow Robot
0676d0bd11 Merge pull request #4266 from Serializator/issue-4111-patchJson6902
Fix name suffix not being applied when "patchesJson6902" is used
2021-11-10 15:13:50 -08:00
Julian van den Berkmortel
b6cb6c8ae9 fix build annotations getting lost after applying JSON 6902 patch 2021-11-10 23:02:42 +01:00
Julian van den Berkmortel
b16e4ec566 add test to demonstrate internal annotations getting lost (#4111) 2021-11-10 21:33:50 +01:00
Mohd Bilal
cb1cbbe044 Fixes 4108; remove hidden files in kustomize edit command to correctly mimic shell globbing behaviour (#4170)
* util and util_test corrected

* fixed behaviour of fsondisk with test updated

* glob behaviour fixed in fsnode

* removed commented code
2021-11-10 08:51:26 -08:00
Kubernetes Prow Robot
86fb408b2c Merge pull request #4276 from natasha41575/fixFunctionSpec
fix function spec example
2021-11-09 21:05:26 -08:00
natasha41575
ca5d691199 fix function spec example 2021-11-09 20:56:36 -08:00
Kubernetes Prow Robot
394567079d Merge pull request #4272 from mengqiy/pointer
Make ResourceList follow k8s api conventions
2021-11-09 15:41:26 -08:00
Kubernetes Prow Robot
e0c8ebc41f Merge pull request #4235 from Goodwine/kyaml-wrap-bug
Fix kyaml readwriter inconsistencies when wrapping resources
2021-11-09 12:37:48 -08:00
Kubernetes Prow Robot
8668691ade Merge pull request #4271 from natasha41575/ReplacementsEdit
Fix: replacements entries get source and targets with null value appended
2021-11-09 10:49:47 -08:00
Mengqi Yu
374d790a21 Make ResourceList follow k8s api conventions
Make optional fields as pointers.
Add omitempty for optional fields.
2021-11-08 21:35:49 -08:00
natasha41575
d8f406d06f add omitempty tag to replacement sources and targets 2021-11-08 12:33:30 -08:00
natasha41575
46b3cd2109 modify edit test for null replacements fields 2021-11-08 12:21:45 -08:00
Carlos Ortiz García
20c608989a Move kio.ByteRW tests from framework_test to byteio_readwriter_test 2021-11-08 11:55:02 -08:00
Carlos Ortiz García
ba4d83f75f only override wrapping kind if it wasn't set already 2021-11-08 11:29:57 -08:00
Carlos Ortiz García
067559127d test cases for framework wrapping/unwrapping bug 2021-11-08 10:13:00 -08:00
Kubernetes Prow Robot
37ab5579f0 Merge pull request #4229 from natasha41575/annotationAndLabelSelectionInReplacements
Annotation and label selection in replacement targets
2021-11-04 13:08:23 -07:00
natasha41575
ef5f1d347d support label and annotation selection in replacement targets 2021-11-04 12:25:15 -07:00
Kubernetes Prow Robot
2c4b195516 Merge pull request #4259 from MikaelSmith/fix-patch-example
docs: Update example for patching multiple objects
2021-11-01 16:01:54 -07:00
Kubernetes Prow Robot
04396ab4e6 Merge pull request #4203 from timofurrer/config-map-consistency
Add consistency to ConfigMap spelling
2021-11-01 15:47:54 -07:00
Kubernetes Prow Robot
4fd77b3a6e Merge pull request #4248 from natasha41575/resourceListResults
[breaking] update results field of ResourceList to implement function spec v1
2021-10-29 14:51:09 -07:00
natasha41575
3ea8b79925 update results field of ResourceList to implement function spec v1 2021-10-29 14:28:50 -07:00
Natasha Sarkar
71b978da1a Merge pull request #4253 from natasha41575/resourceListSDKHelpers
provide utility helpers for preserving internal annotations
2021-10-29 14:25:06 -07:00
Natasha Sarkar
7110298c52 Merge pull request #4249 from natasha41575/resourceListV1
bump ResourceList from v1alpha1 to v1
2021-10-29 14:24:10 -07:00
natasha41575
b4a69f08c0 provide utility helpers for preserving internal annotations 2021-10-29 12:30:55 -07:00
Michael Smith
572d5841c6 docs: Update example for patching multiple objects
Updates the example for patching multiple objects to match the
implementation in #1355, which supports name as a regular expression
(not wildcard pattern).
2021-10-26 12:28:42 -07:00
Kubernetes Prow Robot
984a2dab3d Merge pull request #4242 from natasha41575/configmapissue
fix issue with quotations being dropped in configmap generation
2021-10-24 18:54:22 -07:00
natasha41575
c3c02887ec bump ResourceList from v1alpha1 to v1 2021-10-19 16:15:27 -07:00
natasha41575
ba051c863b fix issue with quote being dropped in configmap generation 2021-10-14 18:30:28 -07:00
natasha41575
4d59146e48 test for dropped quote in configmap generation 2021-10-14 18:13:49 -07:00
Kubernetes Prow Robot
5765ab4dbc Merge pull request #4236 from Goodwine/docs-fn
Update documents from 'kustomize configuration' to 'kustomize fn'
2021-10-13 18:35:28 -07:00
Kubernetes Prow Robot
4769751943 Merge pull request #4160 from osherdp/fix/github-rate-limiter-output
Return a meaningful message if we hit the rate-limiter of GitHub
2021-10-13 18:23:28 -07:00
Kubernetes Prow Robot
e506ce021e Merge pull request #4230 from yutachaos/feature/update_unified_go_version
Update go version 1.16 for CI
2021-10-13 18:09:28 -07:00
Kubernetes Prow Robot
ed763991de Merge pull request #4227 from natasha41575/MigrateIndexPathIdAnnotations
fix bug with migrating kyaml reader path, index, and id annotations
2021-10-12 18:37:48 -07:00
natasha41575
55ac9ca88d fix bug with migrating annotations 2021-10-12 15:42:54 -07:00
Carlos Ortiz García
548f5ffca9 Update documents from 'configuration' to 'fn' 2021-10-11 12:35:22 -05:00
yutachaos
dd3377b1a0 Update CI go version 1.16
Signed-off-by: yutachaos <18604471+yutachaos@users.noreply.github.com>
2021-10-08 14:02:50 +09:00
natasha41575
605239a1e5 test to demonstrate broken annotation selection 2021-10-07 15:40:23 -07:00
Kubernetes Prow Robot
67c58ad4f4 Merge pull request #4210 from natasha41575/openapiFromComponent
fix issue with getting openapi schema from components
2021-10-04 19:27:49 -07:00
natasha41575
11e19a3d0f separate custom openapi test from the others 2021-10-04 18:48:54 -07:00
Kubernetes Prow Robot
6fffcb9203 Merge pull request #4202 from cedarkuo/update-helloworld-example-readme
Updated README to use 'resources' instead of 'bases' in overlays example.
2021-10-04 14:26:41 -07:00
Devin Stein
3479b6691e docs: Update plugin links 2021-10-04 12:58:16 -07:00
Kubernetes Prow Robot
68790e00a9 Merge pull request #4216 from mengqiy/updatedockerfilegen
update the dockerfile gen command
2021-09-29 13:51:22 -07:00
Mengqi Yu
6cf06fac12 update the dockerfile gen command 2021-09-29 13:34:11 -07:00
natasha41575
0d8c107362 fix issue with openapi schema from components 2021-09-27 17:00:14 -07:00
natasha41575
f30e45c549 test to demonstrate issue with openapi from components (#4179) 2021-09-27 16:29:08 -07:00
Kubernetes Prow Robot
250ea13767 Merge pull request #4208 from KnVerey/release_instructions
Small improvements to release instructions
2021-09-27 11:41:45 -07:00
Katrina Verey
608128738d Small improvements to release instructions 2021-09-27 10:44:02 -07:00
Kubernetes Prow Robot
7153f33466 Merge pull request #4207 from KnVerey/updateProwExamplesTarget
Test examples against latest release
2021-09-27 10:11:36 -07:00
Kubernetes Prow Robot
274b12318d Merge pull request #4205 from natasha41575/releasing
add link to k8s-staging-kustomize project to releasing instructions
2021-09-27 10:01:37 -07:00
Katrina Verey
94c82f61a3 Test examples against latest release 2021-09-27 09:51:01 -07:00
Kubernetes Prow Robot
d260f50573 Merge pull request #4206 from KnVerey/unpinEverything
Back to development mode; unpin the modules
2021-09-27 09:47:37 -07:00
Katrina Verey
40c014a991 Back to development mode; unpin the modules 2021-09-27 09:37:38 -07:00
natasha41575
75c8aec29d add link to k8s-staging-kustomize project to releasing instructions 2021-09-27 09:35:40 -07:00
Kubernetes Prow Robot
fcb9c0065e Merge pull request #4200 from KnVerey/go1.17_build_tags
Add go 1.17 build tags, which go fmt auto-synchronizes
2021-09-27 09:27:36 -07:00
Katrina Verey
63ec6bdb3d Merge pull request #4199 from KnVerey/pinToApi
Pin to api v0.10.0
2021-09-27 09:13:36 -07:00
Kubernetes Prow Robot
25bfe6f306 Merge pull request #4204 from KnVerey/release_updates
Use keyring from kustomize GCP project with new token
2021-09-27 09:01:35 -07:00
Timo Furrer
635c4fd43b Merge branch 'master' into config-map-consistency 2021-09-27 09:16:42 +02:00
Timo Furrer
c455215f55 Add consistency to ConfigMap spelling 2021-09-27 09:11:56 +02:00
cedarkuo
8f56f51307 Updated README to use 'resources' instead of 'bases' in overlays example.
Kubernetes v1.21 upgrade kustomize-in-kubectl to v4.0.5. https://github.com/kubernetes/kubernetes/pull/98946
So I think this example could update back to use resources instead of bases?
2021-09-27 12:40:36 +08:00
Katrina Verey
70a8ed6ed3 Add go 1.17 build tags, which go fmt auto-synchronizes 2021-09-24 17:28:21 -07:00
Katrina Verey
febfaf16dc Use keyring from kustomize GCP project with new token 2021-09-24 20:24:10 -04:00
Katrina Verey
8268b17700 Pin to api v0.10.0 2021-09-24 16:58:20 -07:00
Kubernetes Prow Robot
0889995a61 Merge pull request #4198 from KnVerey/pinToCmdConfig
Pin to cmd/config v0.10.1
2021-09-24 16:34:21 -07:00
Katrina Verey
4e476ae574 Pin to cmd/config v0.10.1 2021-09-24 16:07:21 -07:00
Kubernetes Prow Robot
7efd7d23fe Merge pull request #4197 from KnVerey/pinToKyaml
Pin to kyaml v0.12.0
2021-09-24 14:07:50 -07:00
Katrina Verey
6fb944815b Pin to kyaml v0.12.0 2021-09-24 12:23:09 -07:00
Kubernetes Prow Robot
5e3432fbbe Merge pull request #4196 from natasha41575/test
fix tests for reader annotations
2021-09-24 08:31:24 -07:00
natasha41575
f0c6bd7773 fix tests for reader annotations 2021-09-24 08:20:44 -07:00
Jeff Regan
dd579c905d Merge pull request #4180 from yuwenma/fix-4124
[Fix 4124]  Skip local resource until all transformations have completed.
2021-09-24 08:05:19 -07:00
Jeff Regan
22b735885a Merge pull request #4190 from natasha41575/MigrateIndexPathIdAnnotations
Migrate index path id annotations
2021-09-24 08:00:15 -07:00
Kubernetes Prow Robot
b7c5058e37 Merge pull request #4177 from sylr/helm-v3.6
Upgrade Helm v3 to v3.6.3
2021-09-24 07:45:24 -07:00
Kubernetes Prow Robot
baff5f4359 Merge pull request #4187 from monopole/deanchorCall
Do YAML anchor expansion shortly after reading YAML.
2021-09-22 13:14:33 -07:00
monopole
dce4ea5846 Add AnchorsAweigh option to ByteReader to toggle YAML alias/anchor expansion 2021-09-22 12:44:08 -07:00
Kubernetes Prow Robot
c47fc48607 Merge pull request #4193 from phanimarupaka/AddressBareSeqNodeComments
Clean up bare sequence node wrapping
2021-09-20 15:46:23 -07:00
Phani Teja Marupaka
1d9b6cbe57 Clean up bare sequence node wrapping 2021-09-20 15:35:40 -07:00
Kubernetes Prow Robot
1cb93123fc Merge pull request #4189 from phanimarupaka/SkipNonKRMResources
Handle parsing of bare sequence yaml nodes
2021-09-20 11:40:24 -07:00
Kubernetes Prow Robot
c6cb42ec27 Merge pull request #4185 from KnVerey/standardize_owners_files
Use standard Kubernetes project roles for ownership
2021-09-20 10:44:10 -07:00
Natasha Sarkar
67a5f6d68f support krm spec v1 and legacy path, index, and id annotations 2021-09-17 17:10:10 -07:00
Phani Teja Marupaka
e997cc5486 Handle parsing of bare sequence yaml nodes 2021-09-17 14:19:27 -07:00
Kubernetes Prow Robot
53577a5190 Merge pull request #4176 from m-Bilal/fix-4123
Fixes 4123; Length check on originalFields of kustomizationFile to prevent panic
2021-09-16 13:15:27 -07:00
Kubernetes Prow Robot
c1ae234a64 Merge pull request #4163 from natasha41575/multipleGvksInOpenApi
support multiple gvks in custom openapi schema
2021-09-16 12:59:26 -07:00
Natasha Sarkar
02cb395ec2 support multiple gvks in custom openapi schema 2021-09-16 12:43:18 -07:00
Kubernetes Prow Robot
65e7529ca0 Merge pull request #4097 from natasha41575/deprecateFn
deprecate fn wrap, xargs, sink, source commands
2021-09-16 12:25:27 -07:00
Natasha Sarkar
f70743b267 deprecate some fn commands 2021-09-16 11:48:02 -07:00
Yuwen Ma
f4382738ab [fix 4124] Skip local resource until all transformations have completed.
Resources annotated as "local-config" are expected to be ignored. This skip local resource happens in "accumulateResources" which happens before any transformation operations.
However, the local resource may be needed in transformations.
Thus, this change removes the "drop local resource" logic from accumulateResources and removes these local resource after all transformation operations and var operations are done.

Note:
None of the existing ResMap functions can drop the resource slice easily: "Clear" will ruin the resource order, "AppendAll" only adds non-existing resource, "AbsorbAll" only add or modify but not delete.
Thus, we introduce a new func "Intersection" for resourceAccumulator that specificaly removes the resource by ID and keep the original order.
2021-09-16 11:15:05 -07:00
Yuwen Ma
a100dca303 [Fix 4124] Add unittest with the given example. 2021-09-16 11:14:07 -07:00
Jeff Regan
50414208d1 Merge pull request #4186 from monopole/cleanupTest
Clean up factor_test before adding DeAnchor call
2021-09-15 17:47:19 -07:00
monopole
e17a007719 Clean up factor_test before adding DeAnchor call 2021-09-15 17:26:50 -07:00
Katrina Verey
dd3c5f5c0a Use standard Kubernetes project roles for ownership 2021-09-15 16:04:58 -07:00
Sylvain Rabot
fb3f560e0c Upgrade Helm v3 to v3.6.3
Helm has started to build darwin/arm64 from v3.6.0.

Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
2021-09-12 18:18:41 +02:00
m-Bilal
12c177a365 fixes 4123; added length check on originalFields of kustomizationFile to prevent panic when kustomization file began with a comment(or a blank line) followed by a document separator 2021-09-12 17:35:23 +05:30
John Howard
402f6ca72b Precompute IsNamespaceScoped to avoid expensive schema reads (#4152)
* Precompute IsNamespaceScoped to avoid expensive schema reads

See https://github.com/GoogleContainerTools/kpt/issues/2469

For the `gcr.io/kpt-fn/set-namespace:v0.1` function, over 50% of CPU
time is spent on IsNamespaceScoped. Instead of unmarshalling 100k lines
of JSON to determine this, instead just precompute it. We can ensure
this never is inaccurate as the test verifies the precomputed result is
up to date.

In real world kpt pipelines this cuts execution of set-namespace (and
similar functions, just an example of a trivial function) from 2.0s to
1.0s. Because these functions are run in long pipelines over many
resources, this adds up a lot.

* Add documentation
2021-09-09 10:08:11 -07:00
Kubernetes Prow Robot
2b8a39373e Merge pull request #4172 from phanimarupaka/CopyReferenceNodesBeforeComparing
Copy reference nodes before copying comments and syncing order
2021-09-08 11:29:56 -07:00
Phani Teja Marupaka
17f18604e4 Copy reference nodes before copying comments and syncing order 2021-09-07 16:58:06 -07:00
Kubernetes Prow Robot
99e404cb61 Merge pull request #4169 from invidian/fix-typo
api/krusty: fix typo fileystem -> filesystem
2021-09-07 11:41:17 -07:00
Kubernetes Prow Robot
d4e3b4f832 Merge pull request #4171 from justinsb/cache_orgid
Cache the OrgId for nameReferenceTransformer
2021-09-07 11:17:16 -07:00
Justin SB
6552b90657 Cache the OrgId for nameReferenceTransformer
Because this is in an inner loop and is fairly memory-allocation
expensive even on a single allocation, it comes up top-of-the-list in
memory allocation pprof profiles, for example with the coredns
ClusterAddon.

Add simple caching.
2021-09-07 14:06:38 -04:00
Mateusz Gozdek
bf57d698b1 api/krusty: fix typo fileystem -> filesystem
Part of https://github.com/kubernetes/kubernetes/pull/104747.

Signed-off-by: Mateusz Gozdek <mgozdekof@gmail.com>
2021-09-05 11:33:10 +02:00
Kubernetes Prow Robot
4d002af735 Merge pull request #4165 from natasha41575/nameRefAfterKindChange
update name references after kind change
2021-09-03 12:56:52 -07:00
Natasha Sarkar
2bfc7cc1b0 throw error instead of panic when replacements source.fieldPath doesn't exist (#4166)
* test for missing source.fieldPath in replacements

* throw error instead of panic when replacements source.fieldPath doesn't exist
2021-09-03 11:10:53 -07:00
Natasha Sarkar
0244f0919e update name references after kind change 2021-09-02 12:10:01 -07:00
Natasha Sarkar
f122fb12f3 Merge pull request #4158 from kubernetes-sigs/revert-4157-fix/github-rate-limiter-output
Revert "Return a meaningful message if we hit the rate-limiter of GitHub"
2021-08-31 13:29:11 -07:00
Osher De Paz
f7cd553044 return a meaningful message if we hit the rate-limiter of GitHub 2021-08-31 23:26:49 +03:00
Natasha Sarkar
7d0b7e2113 Revert "Return a meaningful message if we hit the rate-limiter of GitHub" 2021-08-31 13:13:36 -07:00
Kubernetes Prow Robot
c3a67cfdca Merge pull request #4157 from osherdp/fix/github-rate-limiter-output
Return a meaningful message if we hit the rate-limiter of GitHub
2021-08-31 12:42:22 -07:00
Osher De Paz
4315e982be return a meaningful message if we hit the rate-limiter of GitHub 2021-08-31 16:19:39 +03:00
Kubernetes Prow Robot
634464353f Merge pull request #4128 from KnVerey/mini_proposal_process
Introduce in-repo proposal process
2021-08-30 17:22:28 -07:00
Kubernetes Prow Robot
9c36004493 Merge pull request #4143 from KnVerey/release_updates
Release updates
2021-08-30 16:08:29 -07:00
Katrina Verey
1b1034442c Enable real release after dry run without manual cleanup 2021-08-30 15:09:40 -07:00
Katrina Verey
a89863c84c Update release instructions 2021-08-30 15:09:40 -07:00
Katrina Verey
f7340e0615 Proposal template feedback 2021-08-30 12:10:02 -07:00
Kubernetes Prow Robot
bf6b207cc9 Merge pull request #4141 from KnVerey/unpinEverything
Back to development mode; unpin the modules
2021-08-24 12:46:58 -07:00
Katrina Verey
f93b4877f7 Back to development mode; unpin the modules 2021-08-24 12:35:26 -07:00
Kubernetes Prow Robot
cd17338759 Merge pull request #4139 from KnVerey/pinToApi
Pin to api v0.9.0
2021-08-24 12:04:58 -07:00
Katrina Verey
c46867c3a7 Pin to api v0.9.0 2021-08-24 11:54:43 -07:00
Kubernetes Prow Robot
3c321ef79c Merge pull request #4138 from KnVerey/pinToCmdConfig
Pin to cmd/config v0.10.0
2021-08-24 11:38:58 -07:00
Katrina Verey
7938fdb596 Pin to cmd/config v0.10.0 2021-08-24 11:27:56 -07:00
Kubernetes Prow Robot
a2111869e6 Merge pull request #4137 from KnVerey/pinToKyaml
Pin to kyaml v0.11.1
2021-08-24 11:10:59 -07:00
Katrina Verey
f8288e2f02 Pin to kyaml v0.11.1 2021-08-24 10:59:16 -07:00
Jeff Regan
f2f90d1185 Merge pull request #4114 from monopole/anchorsAweigh
Add YAML anchor/alias expansion.
2021-08-24 09:51:49 -07:00
Kubernetes Prow Robot
459e800ecf Merge pull request #4134 from phanimarupaka/FieldOrderingForNullFields
Preserve field order: Add test for null value
2021-08-23 16:44:14 -07:00
Phani Teja Marupaka
8f00d3fd53 Add test for null value 2021-08-21 15:58:49 -07:00
Kubernetes Prow Robot
cd94cb13c6 Merge pull request #4132 from natasha41575/moveWorkDirCheck
move check for working dir for exec functions
2021-08-20 11:11:31 -07:00
Natasha Sarkar
e100be620e move check for working dir for exec functions 2021-08-20 10:59:29 -07:00
Natasha Sarkar
1e1b9b484a exec function working dir is the kustomization that referenced it (#4125)
* exec function working dir is the kustomization that referenced it

* suggested changes

* more code review

* use a field instead of an annotation

* more code review
2021-08-19 20:15:24 -07:00
Katrina Verey
3e7246690f Introduce in-repo proposal process 2021-08-19 17:00:20 -07:00
monopole
360585dfaf Add YAML anchor/alias expansion. 2021-08-19 11:55:09 -07:00
Kubernetes Prow Robot
f604619dd5 Merge pull request #4086 from campoy/pkgio-writer-filesys
Add FileSystem interface to LocalPackageWriter
2021-08-19 11:51:25 -07:00
Francesc Campoy
0fa056327a Skip in-memory tests for Windows and generate temporary directories correctly for Windows tests. 2021-08-19 10:27:39 -07:00
Francesc Campoy
6db2bf69f3 Add FileSystem interface to LocalPackageReadWriter and hook to LocalPackageWriter 2021-08-19 10:27:38 -07:00
Francesc Campoy
20fb9578c0 Adapt tests to new FileSystem field 2021-08-19 10:27:38 -07:00
Francesc Campoy
4eb8232495 Added FileSystem field to kio.LocalPackageWriter 2021-08-19 10:27:38 -07:00
Jeff Regan
6c4e8019f8 Merge pull request #4094 from brianpursley/merge3-test
Add unit tests to cover existing behavior of three way merge and strategic merge patch
2021-08-19 07:41:18 -07:00
Jeff Regan
28707bf5df Merge pull request #4065 from natasha41575/originDataAsAnnotation
option for origin data as annotation
2021-08-18 19:08:54 -07:00
Mike Borozdin
023a580f00 support for darwin and linux (#4122)
* support for darwin and linux

* updated to use go for env variables
2021-08-17 15:58:08 -07:00
Kubernetes Prow Robot
a2eaae5555 Merge pull request #4113 from KnVerey/kyaml_container_patch_kinds
Enable fn framework container patches to work with more kinds
2021-08-17 11:31:13 -07:00
Katrina Verey
75df1a5422 kyaml presubmit formatting 2021-08-17 11:13:54 -07:00
Katrina Verey
f0b4cc4581 ContainerPatch supports all common workload paths 2021-08-17 11:13:52 -07:00
Katrina Verey
7a41e479c9 Filter helper for fallback field lookup 2021-08-17 11:13:10 -07:00
Natasha Sarkar
3350c7213c option for origin data as annotation 2021-08-12 20:09:41 -07:00
Adrian Berger
7b5e43d343 Feature: Add edit set annotation (#4073)
* Add edit set annotation feature

* Apply suggested code improvements

* Apply suggested changes

* Fix regex, add more tests

* Add constant for common error message

* Fix too many characters per line error

* Use string concatenation instead, add FailNow call
2021-08-10 16:00:40 -07:00
Kubernetes Prow Robot
06661ea310 Merge pull request #4112 from natasha41575/updateOpenAPI
update openapi to v1.21.2
2021-08-10 10:44:40 -07:00
Natasha Sarkar
38b2b33503 update openapi to v1.21.2 2021-08-10 10:30:12 -07:00
Natasha Sarkar
f735d6fb3a Merge pull request #4110 from KnVerey/update-openapi-scripts
Update openapi updater scripts
2021-08-10 09:38:11 -07:00
Katrina Verey
5cb5e07ac0 Update openapi updater scripts 2021-08-09 11:44:27 -07:00
Kubernetes Prow Robot
54778504ed Merge pull request #4087 from campoy/fsnode-alias-fix
Avoid aliasing in fsnode by forcing copies for file contents
2021-08-04 20:32:56 -07:00
Kubernetes Prow Robot
1bfe0d08dc Merge pull request #4102 from monopole/anchorsNotHonored
Kyaml anchor failure test.
2021-08-04 19:40:55 -07:00
monopole
56da9a58fc Kyaml anchor failure test. 2021-08-04 17:10:04 -07:00
Kubernetes Prow Robot
54383bca25 Merge pull request #4085 from campoy/pkgio-reader-filesys
Add a filesys.FileSystem interface to kio.LocalPackageReader
2021-08-03 15:33:04 -07:00
Kubernetes Prow Robot
88461b4fed Merge pull request #4088 from natasha41575/noMoreGenArgs
replace genargs with two separate annotations
2021-08-03 14:07:03 -07:00
brianpursley
aabbea3e78 Add unit tests for current behavior of strategic merge patch 2021-08-02 20:36:55 -04:00
brianpursley
adedca09f2 Add unit tests for current behavior of three way merge 2021-08-02 20:36:28 -04:00
Natasha Sarkar
9a27a9f19f replace genargs with two separate annotations 2021-07-29 15:46:09 -07:00
Kubernetes Prow Robot
3ebdb3fcef Merge pull request #4091 from natasha41575/RemovePathAnno
remove annotations added by the kyaml reader
2021-07-28 11:28:48 -07:00
Natasha Sarkar
97e7cb1512 remove annotations added by the kyaml reader 2021-07-27 17:56:58 -07:00
Francesc Campoy
262a2d9288 Avoid testing in memory for Windows tests 2021-07-26 16:14:46 -07:00
Kubernetes Prow Robot
91b862b556 Merge pull request #4084 from kubernetes-sigs/kustomize-in-kubectl-1.22
Update kustomize-in-kubectl chart for 1.22
2021-07-26 13:42:34 -07:00
Katrina Verey
b8ffc725c7 Update kustomize-in-kubectl chart for 1.22 2021-07-26 13:23:45 -07:00
Jeff Regan
76f1411922 Merge pull request #4082 from monopole/autoChanges
Automated go.sum and fmt changes under go 1.16.6
2021-07-24 09:42:29 -07:00
monopole
d1003d6f8f Automated changes under go 1.16.6 2021-07-24 09:18:58 -07:00
Natasha Sarkar
91f74e8d16 replace Resource.options with annotations (#4061) 2021-07-23 18:19:05 -07:00
Kubernetes Prow Robot
94c5096a95 Merge pull request #4048 from natasha41575/DeprecateCfgCmds
Deprecate some cfg commands
2021-07-21 18:15:51 -07:00
Kubernetes Prow Robot
f35aeb6a8e Merge pull request #4077 from abutcher/cdpath
Unset CDPATH in hack/install_kustomize.sh
2021-07-21 10:14:07 -07:00
Kubernetes Prow Robot
d6ce846047 Merge pull request #4076 from KnVerey/kyaml_fixture_fix
Make UpdateExpectedFromActual work with hierarchical testdata directories
2021-07-21 08:52:08 -07:00
Andrew Butcher
ec069e4f19 Unset CDPATH to restore default cd behavior. 2021-07-21 11:38:44 -04:00
Katrina Verey
c5adafd9ce Make UpdateExpectedFromActual work with hierarchical testdata directories 2021-07-20 18:13:04 -07:00
Natasha Sarkar
16dcc98cff deprecate some cfg commands 2021-07-19 14:31:20 -07:00
Kubernetes Prow Robot
59c410a70a Merge pull request #4063 from dosmanak/mdrip_MYGOBIN
fix: Allow custom MYGOBIN in mdrip invocations
2021-07-19 10:30:52 -07:00
Francesc Campoy
9b586162d0 Add FileSystem interface to LocalPackageReadWriter and hook to LocalPackageReader 2021-07-16 14:48:22 -07:00
Francesc Campoy
803885049b Avoid aliasing in fsnode by forcing copies for file contents and add a test 2021-07-16 13:56:08 -07:00
Francesc Campoy
be4fe7540e Simplified tests with helper func 2021-07-16 11:06:32 -07:00
Francesc Campoy
927568eea2 Replace os.Stat call with FileSystem.Exists 2021-07-16 09:27:20 -07:00
Francesc Campoy
436d5e717c All LocalPackageReader tests adapted, one fails 2021-07-16 09:12:42 -07:00
Francesc Campoy
d37fa66ebc Adapt more LocalPackageReader tests 2021-07-15 18:21:42 -07:00
Francesc Campoy
e8a4bf6edc Add FileSystem field to LocalPackageReader and one of its tests 2021-07-15 18:06:30 -07:00
Kubernetes Prow Robot
35d1c3f9b4 Merge pull request #4072 from natasha41575/Revert
revert 'fix kyaml issue with multiline scalars'
2021-07-15 14:37:02 -07:00
Natasha Sarkar
e17785af21 revert 'fix kyaml issue with multiline scalars' 2021-07-15 14:24:39 -07:00
Natasha Sarkar
0537b59f27 support yaml formatted openapi schema (#4017)
* support yaml formatted openapi schema

* suggested changes
2021-07-15 14:11:02 -07:00
Kubernetes Prow Robot
339e33d2f3 Merge pull request #4071 from KnVerey/update-yaml-script
Update fork updater script
2021-07-15 10:06:45 -07:00
Natasha Sarkar
f082ac02cf fix multiline scalar value issue 2021-07-15 08:41:03 -07:00
Katrina Verey
9538ae1258 Update fork updater script 2021-07-15 08:31:32 -07:00
Kubernetes Prow Robot
34981b664f Merge pull request #4069 from natasha41575/LineBreakIssue
fix kyaml issue with multiline scalars
2021-07-14 16:20:47 -07:00
Natasha Sarkar
477d8930e0 fix kyaml issue with multiline scalars 2021-07-14 15:19:21 -07:00
Kubernetes Prow Robot
b5091a566a Merge pull request #4067 from natasha41575/demonstrateLineBreakIssue
demonstrate line break preservation issue in kyaml
2021-07-14 11:52:18 -07:00
Natasha Sarkar
9981c45554 demonstrate line break preservation issue in kyaml 2021-07-14 11:39:14 -07:00
phani
0f736ec7fd Handle comments for seq indent derivation (#4064)
* Handle comments for seq indent derivation

* Suggested changes
2021-07-13 17:46:26 -07:00
Kubernetes Prow Robot
7826ad1e06 Merge pull request #4031 from rjferguson21/prefix-overlay-fail
Add failing test for replacements when using an overlay with a namePrefix
2021-07-13 14:42:01 -07:00
Frank Farzan
f4e6816338 Expand documentation of annotations used in manifests and KRM functions API (#3995)
* Expand documentation of annotations used in manifests and KRM function wire format.

- Reserve `internal.config.kubernetes.io` for control annotations
- Document `local-config` annotation in a seperate document (It's
  orthogonal to KRM functions).
- There is a internal annotation that uses `config.k8s.io` instead of
  `config.kubernetes.io` used by other annotations. See [1] and [2]. We
  should avoid using two seperate annotation prefixes and audit the
  codebase for any other annotation. Given the `id` control annotation is used
  for comment preservation (no existing function should be modifying
  it), I suggest moving this over to use
  `fn-ctrl.config.kubernets.io/id`.

[1]: 7e8ba62e9f/kyaml/fn/runtime/runtimeutil/runtimeutil.go (L195)
[2]: https://github.com/kubernetes-sigs/kustomize/pull/2465

* Move path/index annotation to use internal prefix

* Clarify MUST NOT vs SHOULD NOT for internal annotations

* Update cmd/config/docs/api-conventions/functions-spec.md

Co-authored-by: Katrina Verey <kn.verey@gmail.com>

* Update cmd/config/docs/api-conventions/functions-spec.md

Co-authored-by: Katrina Verey <kn.verey@gmail.com>

* Update cmd/config/docs/api-conventions/manifest-annotations.md

Co-authored-by: Katrina Verey <kn.verey@gmail.com>

* Remove kusotmization as example

Co-authored-by: Katrina Verey <kn.verey@gmail.com>
2021-07-13 11:58:00 -07:00
Kubernetes Prow Robot
4a13725678 Merge pull request #4043 from phanimarupaka/PreserveIndentation
Make seq indent configurable and add retain seq indent functionality
2021-07-13 10:24:30 -07:00
Petr Studeny
ab9b010856 fix: Allow custom MYGOBIN in mdrip invokations 2021-07-13 14:34:50 +02:00
Phani Teja Marupaka
29be7fabe4 Suggested changes 2021-07-12 23:34:03 -07:00
Phani Teja Marupaka
74e867833a First sequence indent wins 2021-07-09 14:10:30 -07:00
Rob Ferguson
91dc6d2a0f add additional replacement transformer test with todos for failures 2021-07-09 12:45:47 -05:00
Rob Ferguson
3c1fd0e9cf add replacement test failures 2021-07-09 10:39:38 -05:00
Rob Ferguson
4deeb7d59b make replacement transformer test pass and add todo 2021-07-09 09:49:08 -05:00
Phani Teja Marupaka
89b12cfc62 Change annotation name, error if conflicting options 2021-07-09 01:32:48 -07:00
Phani Teja Marupaka
c07ffa5c1e Update comments, tests, not expose indent option 2021-07-09 00:17:09 -07:00
Kubernetes Prow Robot
259fcfcef8 Merge pull request #4002 from natasha41575/resref
replace Resource.refBy with annotations
2021-07-08 17:26:54 -07:00
Phani Teja Marupaka
f81201b74d Add options, keep seqindent annotation equivalent to index annotation 2021-07-08 14:54:23 -07:00
Phani Teja Marupaka
6dbc74b32e Suggested changes 2021-07-07 23:22:15 -07:00
Phani Teja Marupaka
ed38b5fe2b Make seq indent configurable and add retain seq indent functionality 2021-07-07 16:53:40 -07:00
Natasha Sarkar
a84badb834 replace Resource.refBy with annotations 2021-07-07 15:22:36 -07:00
phani
e1804cbc76 Retain field order after running any arbitrary functions on resources (#4021)
* Reorder resource fields

* Fix comment conflict

* Update e2e test ordering

* Suggested changes
2021-07-07 10:12:44 -07:00
Kubernetes Prow Robot
d13eef7951 Merge pull request #4040 from zhouhaibing089/fix-iampolicy-mod
iampolicygenerator: update module name
2021-07-07 09:46:44 -07:00
Kubernetes Prow Robot
0b4c6baf44 Merge pull request #4039 from zhouhaibing089/handle-dot-git-suffix
api/internal/git: handle .git suffix in repospec
2021-07-07 09:24:43 -07:00
Haibing Zhou
b3af54340c iampolicygenerator: update module name
The previous module name is incorrect and seems to be copied from
another builtin plugin. This change fixes the name.
2021-07-05 14:11:32 -07:00
Haibing Zhou
8c14b9d1af api/internal/git: handle .git suffix in repospec
This change adds a new test case for parsing url with `.git` suffix. In
that case, we should have the full url as clone spec with an empty
abspath.
2021-07-05 13:10:35 -07:00
Natasha Sarkar
d818ccae92 Merge pull request #4037 from natasha41575/pin
Unpin modules
2021-07-02 14:25:03 -07:00
Natasha Sarkar
4cea8b9785 Unpin modules 2021-07-02 14:10:05 -07:00
Kubernetes Prow Robot
84a36801e0 Merge pull request #4036 from joebowbeer/patch-1
Fix broken KEP link in README
2021-07-02 13:58:10 -07:00
Joe Bowbeer
6eb7b3508d Fix broken KEP link in README 2021-07-02 13:12:22 -07:00
Rob Ferguson
2a5f4ac7d7 add failing test for replacements 2021-07-02 08:54:52 -05:00
Kubernetes Prow Robot
518a16d3ac Merge pull request #4014 from brianpursley/doc-separator
Updated ByteReader to allow white space and comments content after --- when splitting YAML documents
2021-07-01 14:25:51 -07:00
Jeff Regan
d53a2ad45d Merge pull request #4027 from monopole/deleteWindowsBuild
Temporarily remove windows build.
2021-06-30 15:37:56 -07:00
monopole
bb02a7645b Temporarily remove windows build. 2021-06-30 15:36:57 -07:00
Jeff Regan
5a9d90c872 Merge pull request #4026 from monopole/upgradeGoReleaser
release process: upgrade to goreleaser v0.172.1 calling go1.16.5
2021-06-30 14:04:18 -07:00
monopole
4fd7269643 release process: upgrade to goreleaser v0.172.1 calling go go1.16.5 2021-06-30 14:02:55 -07:00
Kubernetes Prow Robot
1eb3c1a075 Merge pull request #4025 from KnVerey/pinToApi
Pin to api v0.8.11
2021-06-30 12:53:03 -07:00
Katrina Verey
a1746f2f8c Pin to api v0.8.11 2021-06-30 12:42:04 -07:00
Kubernetes Prow Robot
b727febd08 Merge pull request #4023 from mengqiy/jsontag
add missing json tags
2021-06-30 12:37:03 -07:00
Natasha Sarkar
c819d69ae4 Merge pull request #4022 from KnVerey/pinToCmdConfig
Pin to cmd/config v0.9.13
2021-06-30 12:26:40 -07:00
Katrina Verey
bb6f83fb96 Pin to cmd/config v0.9.13 2021-06-30 12:16:04 -07:00
Mengqi Yu
02d14d724a add missing json tags 2021-06-30 12:15:50 -07:00
Katrina Verey
aa92d83d8c Pin to kyaml (#4020)
* Pin to kyaml

* Pin prefixsuffixtransformer to kyaml 0.11.0

* Pin replicacounttransformer to kyaml 0.11.0
2021-06-30 11:59:03 -07:00
Natasha Sarkar
5427ab7cc3 Merge pull request #4013 from KnVerey/go-yaml-fork
Internal go-yaml/yaml fork
2021-06-30 10:41:27 -07:00
Katrina Verey
e583f199b8 Comment out part of script that is likely only needed on first run 2021-06-30 10:18:11 -07:00
Katrina Verey
b465c20f65 Remove pinning to external fork 2021-06-30 10:15:02 -07:00
Natasha Sarkar
5c2c617ff0 fix affected cmd/config tests 2021-06-30 10:14:45 -07:00
Natasha Sarkar
3ab0665c19 fix affected kyaml tests 2021-06-30 10:14:45 -07:00
Natasha Sarkar
4b66043735 compact sequence indent 2021-06-30 10:14:45 -07:00
Natasha Sarkar
979f03e76c remove serialization hack after bump 2021-06-30 10:14:44 -07:00
Natasha Sarkar
c8b049f57f point to natasha's fork 2021-06-30 10:14:33 -07:00
Katrina Verey
f3d8883046 Internalize forked code 2021-06-30 10:13:33 -07:00
Natasha Sarkar
e308f321d3 fix leading newline issue 2021-06-30 10:13:33 -07:00
Natasha Sarkar
beea785ead tests for compactSeqIndent 2021-06-30 10:13:33 -07:00
Natasha Sarkar
95c5b686be add defaultSeqIndent method 2021-06-30 10:13:32 -07:00
Natasha Sarkar
0ddf68cc8a compact sequence indentation option 2021-06-30 10:13:32 -07:00
Katrina Verey
4cadad5cfe Internal copy of go-yaml at 496545a6307b2a7d7a710fd516e5e16e8ab62dbc 2021-06-30 10:13:30 -07:00
Katrina Verey
9e4a6397d6 Instructions and script for go-yaml fork 2021-06-28 17:04:04 -07:00
Katrina Verey
2e8a3b7c45 Use the forked go-yaml module 2021-06-28 15:29:32 -07:00
Kubernetes Prow Robot
276d0430bf Merge pull request #4018 from phanimarupaka/DontAddFormatTags
Handle null values while formatting
2021-06-27 17:05:24 -07:00
Phani Teja Marupaka
1aa7a1e709 Handle null values while formatting 2021-06-27 16:55:16 -07:00
brianpursley
78737f5a38 Updated ByteReader to allow white space and comments on the same line after --- and throw an error if anything else is detected 2021-06-24 21:32:39 -04:00
Kubernetes Prow Robot
dac84d867e Merge pull request #4010 from natasha41575/openapicommanddocs
fix openapi command help page
2021-06-23 08:54:10 -07:00
Natasha Sarkar
217e5c7268 fix openapi command help page 2021-06-22 18:46:34 -07:00
Jeff Regan
936ac37a2e Update repospec_test.go 2021-06-21 14:30:11 -07:00
Kubernetes Prow Robot
cb4f5c3983 Merge pull request #4006 from runewake2/validate-data-map
Introduce Validate Data Map Function
2021-06-18 12:34:06 -07:00
Sam Wronski
1801d33287 Add error when datamap is nil 2021-06-18 10:14:17 -07:00
Sam Wronski
b01da61d83 Update argument name 2021-06-17 16:12:09 -07:00
Natasha Sarkar
23e28bb18a change marshal indent to 2 (#4005) 2021-06-17 13:34:04 -07:00
Sam Wronski
a1f1c2d32f Add documentation 2021-06-17 11:47:56 -07:00
Sam Wronski
10331d9560 Add GetValidatedDataMap to rnode 2021-06-17 01:46:35 -07:00
Francesc Campoy
60038d44f9 Add filesys.FileSystem to ignoreFileMatcher (#3994) 2021-06-16 17:16:20 -07:00
Kubernetes Prow Robot
24d06f83ca Merge pull request #3998 from yhrn/star-fix
Remove debug fmt.Println breaking kpt Starlark output
2021-06-16 15:53:59 -07:00
Kubernetes Prow Robot
e76638f98d Merge pull request #4000 from KnVerey/readme_update
Update kubectl kustomize section of readme
2021-06-16 14:47:59 -07:00
Kubernetes Prow Robot
ef1b9d4854 Merge pull request #3999 from campoy/patch-1
Test api in workflows
2021-06-16 14:29:59 -07:00
Katrina Verey
3c0f805674 Update kubectl kustomize section of readme 2021-06-16 14:26:40 -07:00
Francesc Campoy
324581594c Test api for all platforms and skip those breaking on Windows 2021-06-16 14:18:48 -07:00
Francesc Campoy
7fae7d1bd6 Move api/filesys to kyaml/filesys (#3997)
* Move api/filesys to kyaml/filesys

* Add deprecated version of api/filesys with aliases to new code

* Use new kyaml/filesys package and update dependencies

* Migrate to kyaml/filesys and update dependencies

* Skip tests that break on Windows
2021-06-16 11:42:00 -07:00
Mattias Öhrn
0af3a75708 Remove debug fmt.Println breaking kpt Starlark output 2021-06-16 12:27:17 +02:00
Kubernetes Prow Robot
d39d7db9ed Merge pull request #3966 from pacoxu/json-patch-v4.11.0
json-patch upgrade to v4.11.0
2021-06-15 15:25:43 -07:00
Kubernetes Prow Robot
a04a6de0ef Merge pull request #3991 from natasha41575/convertvarstoreplacements
convert vars to replacements: mapping value with dot
2021-06-15 15:07:43 -07:00
Kubernetes Prow Robot
69a6708f9b Merge pull request #3996 from khrisrichardson/kustomize-build-as-current-user
expose --as-current-user flag to kustomize build command
2021-06-15 12:53:43 -07:00
Khris Richardson
c19a972739 expose --as-current-user via AddFunctionBasicsFlags 2021-06-15 12:30:37 -07:00
Khris Richardson
2e674337b3 expose --as-current-user via GetRunFnRunner 2021-06-15 12:30:17 -07:00
Khris Richardson
727e24f365 append AsCurrentUser to FnPluginLoadingOptions 2021-06-15 12:29:59 -07:00
Natasha Sarkar
7e8ba62e9f Merge pull request #3986 from campoy/filesys-default
Filesys default
2021-06-14 12:55:35 -07:00
Kubernetes Prow Robot
fe60d0c403 Merge pull request #3992 from mortent/AllowErrorForResourceHandler
Allow the Handle function of the ResourceHandler interface to return an error
2021-06-14 09:55:04 -07:00
Morten Torkildsen
2e0556b544 Allow the Handle function of the ResourceHandler interface to return an error 2021-06-13 15:06:08 -07:00
Kubernetes Prow Robot
479acac581 Merge pull request #3987 from mortent/AddResourceHandlerForMerge3
Allow users to customize handling of deleted resources for merge3
2021-06-11 18:19:00 -07:00
Natasha Sarkar
3b37fed24b convert vars to replacements: mapping value with dot 2021-06-11 13:45:04 -07:00
Kubernetes Prow Robot
8fdb3f1703 Merge pull request #3926 from natasha41575/ConvertVarsToReplacements
convert vars to replacements
2021-06-11 13:01:00 -07:00
Morten Torkildsen
95e242353b Allow users to customize handling of deleted resources for merge3 2021-06-11 11:37:24 -07:00
Francesc Campoy
199802a176 Ensure 'not exist' errors wrap os.ErrNotExist (#3982)
* Ensure 'not exist' errors wrap os.ErrNotExist

* Update go.sum

* Use an error type to avoid changing the error's string
2021-06-11 09:44:59 -07:00
Kubernetes Prow Robot
065432e074 Merge pull request #3984 from natasha41575/replacementWithDot
Replacement with dot
2021-06-10 18:12:13 -07:00
Francesc Campoy
62fd36facb Updating go.sum 2021-06-10 16:56:50 -07:00
Natasha Sarkar
f121e74744 convert vars to replacements 2021-06-10 15:29:28 -07:00
Jeff Regan
5aa2f534be Merge pull request #3985 from monopole/stringslice
Gather some string slice utils.
2021-06-10 14:30:15 -07:00
monopole
86dd74fd62 Gather some string slice utils. 2021-06-10 13:34:20 -07:00
Natasha Sarkar
218da9858f support mapping values with '.' in replacements fieldpaths 2021-06-10 11:33:05 -07:00
Natasha Sarkar
cebda58437 test for '.' in replacement mapping value 2021-06-10 11:15:05 -07:00
Francesc Campoy
6a82437bc9 Renaming to better name 2021-06-10 09:53:49 -07:00
Francesc Campoy
6b9e8eb891 Add a new type that defaults to FsOnDisk for convenience 2021-06-09 18:00:30 -07:00
Jeff Regan
615984bf2d Merge pull request #3977 from KnVerey/roadmap
Commit roadmap presented to SIG-CLI
2021-06-09 14:43:01 -07:00
Katrina Verey
bc6ac8a68a Commit roadmap presented to SIG-CLI 2021-06-09 14:37:54 -07:00
Kubernetes Prow Robot
39f24ef8d2 Merge pull request #3956 from natasha41575/ReplacementPreviousIds
replacements should be able to use previous IDs
2021-06-09 10:45:26 -07:00
pacoxu
24294d3bd0 upgrade json-patch 4.11.0
Signed-off-by: pacoxu <paco.xu@daocloud.io>
2021-06-09 12:34:19 +08:00
Jeff Regan
234fcbfc02 Update OWNERS_ALIASES 2021-06-08 16:59:45 -07:00
Jeff Regan
b54093ebca Merge pull request #3972 from KnVerey/contributor_ladder
Document contributor roles
2021-06-08 16:43:18 -07:00
Katrina Verey
db307a7084 Document contributor roles 2021-06-08 16:39:37 -07:00
Jeff Regan
a0c7997b66 Merge pull request #3963 from natasha41575/KustomizeEditFix
small `api` changes for kustomize fix
2021-06-08 13:52:06 -07:00
Natasha Sarkar
7458a53a73 copy method for selector 2021-06-08 11:18:38 -07:00
Natasha Sarkar
cf6e6ca4db omitempty for replacement type 2021-06-08 11:18:27 -07:00
Natasha Sarkar
e847ec7474 ReadDir method for filesys 2021-06-08 11:18:11 -07:00
Jeff Regan
440026b9b3 Merge pull request #3965 from mengqiy/listcomments
handle comments in list correctly
2021-06-07 17:32:53 -07:00
Kubernetes Prow Robot
64331ad845 Merge pull request #3964 from ash2k/ash2k/handle-errors2
Handle errors
2021-06-07 16:26:03 -07:00
Mengqi Yu
294070b3ab address comments 2021-06-07 15:06:57 -07:00
Mengqi Yu
cabbea0d97 handle comments in list correctly 2021-06-07 14:57:49 -07:00
Jeff Regan
732a8522df Merge pull request #3968 from monopole/fixFailingHelmTest
Don't run helm inflator test against released version.
2021-06-07 13:19:02 -07:00
monopole
8f82c4c748 Don't run helm inflator test against released version. 2021-06-07 12:26:12 -07:00
Jeff Regan
d0bc25f339 Update byteio_writer.go 2021-06-07 12:25:04 -07:00
Jeff Regan
ed3200e4f5 Remove bad TODO 2021-06-04 17:56:42 -07:00
Mikhail Mazurskiy
a3ed120efb Handle errors 2021-06-05 09:43:13 +10:00
Jeff Regan
f1b191c02f Update README.md 2021-06-04 16:22:59 -07:00
Jeff Regan
1493b24b46 Update README.md 2021-06-04 16:21:25 -07:00
Kubernetes Prow Robot
5993eae1aa Merge pull request #3934 from yhrn/fix-json-sink
Sink: Force JSON encoding for .json files
2021-06-04 11:38:38 -07:00
Mattias Öhrn
3e506eae02 PR feedback - more tests and some cleanup 2021-06-04 11:06:22 +02:00
Kubernetes Prow Robot
0305860078 Merge pull request #3962 from natasha41575/resourceRef
remove metadata field from resourceRef schema
2021-06-03 15:57:02 -07:00
Natasha Sarkar
0205090e0d remove metadata field from resourceRef schema 2021-06-03 12:46:51 -07:00
Natasha Sarkar
6adefe4562 replacements should be able to use previous IDs 2021-06-03 12:14:27 -07:00
Jeff Regan
da1bd901b4 Merge pull request #3939 from KnVerey/framework_test_helpers
[kyaml] Improvements to frameworktestutil
2021-06-03 11:14:54 -07:00
Jeff Regan
636b9c7aeb Merge pull request #3931 from natasha41575/ReplacementOverwritesSource
Fix issues with replacements
2021-06-03 10:57:01 -07:00
Mattias Öhrn
942f112ef5 Fix kyaml tests 2021-06-03 08:31:03 +02:00
Mattias Öhrn
03bbb076bf plugin/builtin/iampolicygenerator/go.sum tidy 2021-06-03 08:30:38 +02:00
Mattias Öhrn
e468d6b4d2 Fixing cmd/config/internal/commands/e2e/e2e_test.go 2021-06-03 08:29:53 +02:00
Kubernetes Prow Robot
57206a628d Merge pull request #3955 from mengqiy/betterresults
Check for empty GKNN when formatting results
2021-06-02 18:05:38 -07:00
Mengqi Yu
f061bb887b Check for empty GKNN when formatting results 2021-06-02 16:32:18 -07:00
Kubernetes Prow Robot
75fd9a43a3 Merge pull request #3925 from frankfarzan/krm-functions-spec
Fully specify KRM Functions Spec and graduate it to v1.
2021-06-02 12:10:42 -07:00
Frank Farzan
58165dfc89 comments 2021-06-02 10:53:49 -07:00
Frank Farzan
0e8257c387 comments 2021-06-02 10:50:39 -07:00
Kubernetes Prow Robot
62e78f8349 Merge pull request #3940 from Shell32-Natsu/resource-factory
add an option to include local configs
2021-06-01 17:20:12 -07:00
Natasha Sarkar
84724a3ebf smarter path splitter for replacements 2021-06-01 17:15:54 -07:00
Donny Xia
23544e0431 code review 2021-06-01 16:25:41 -07:00
Donny Xia
b1fda3d62e add an option to include local configs 2021-06-01 13:38:36 -07:00
Natasha Sarkar
b8ae69b748 copy target rnode in replacements 2021-06-01 13:24:51 -07:00
Natasha Sarkar
4014440d06 test to demonstrate '.' in list element path issue 2021-06-01 13:24:51 -07:00
Natasha Sarkar
74b0b3adc6 test to demonstrate multiple fieldpaths issue in replacements 2021-06-01 13:24:51 -07:00
Katrina Verey
382f09a126 Make frameworktestutil assertions configurable
Also refactor to share common code between results checkers
2021-06-01 12:20:23 -07:00
Katrina Verey
f9afdc5c95 Improve frameworktestutil usability with complex error messages 2021-06-01 12:20:17 -07:00
Mattias Öhrn
5e4fb4796e Only encoding non-wrapped single .json items as JSON 2021-06-01 20:44:21 +02:00
Katrina Verey
76f8988865 Mark updated tests as skipped instead of passed 2021-05-31 10:56:32 -07:00
Mattias Öhrn
fa3e829eb6 Sink: Force JSON encoding for .json files 2021-05-31 08:00:54 +02:00
Jeff Regan
d9435bd1b1 Merge pull request #3898 from dmizelle/add-helm-include-crds
Add includeCRDs Field to HelmChart
2021-05-27 16:04:07 -07:00
Kubernetes Prow Robot
af96bb4bda Merge pull request #3914 from natasha41575/GkeServiceAccountGenerator
Gke service account generator
2021-05-27 15:36:23 -07:00
Kubernetes Prow Robot
8607e0adec Merge pull request #3930 from monopole/demo3929
Demonstrate issue 3929
2021-05-26 17:04:06 -07:00
Natasha Sarkar
5a2a7709a4 add IAMPolicyGenerator 2021-05-26 16:54:38 -07:00
monopole
437e8f90f6 Demonstrate issue 3929 2021-05-26 16:29:55 -07:00
Jeff Regan
06ac670951 Merge pull request #3911 from ash2k/ash2k/handle-errors
Handle errors
2021-05-25 21:05:26 -07:00
Frank Farzan
3ee1579688 Fully specify KRM Functions Spec and graduate it to v1.
- Define the OpenAPI schema for ResourceList
- Graduate `ResourceList` to apiVersion `v1`. Many functions have been implemented
  and we are effectively treating the spec as backwards compatible.
- Add `results` field to the spec. This has been implemented in the
  orchestrator and couple of functions libraries for a while, but hasn't been
  yet standardized leading to minor discrepencies. Concurrent to this PR,
  we need to udpate the fn framework (kyaml) to be compatible with
  the standard and update the orchestrator to be backwards compatible.
- Include per-resource annotations (previously a seperate doc)
- Remove support for non-ResourceList wire formats. In practice, this is
  not widely used and complicates the standard. The orchestrators can
  easily covert a List to a ResourceList.
2021-05-25 16:09:32 -07:00
Jeff Regan
5954314b98 Merge pull request #3917 from zhouhao3/clean-tempfile
Cleanup tempfiles
2021-05-24 20:01:33 -07:00
Jeff Regan
c0324456a7 Merge pull request #3921 from monopole/deleteScriptsDir
Consolidate scripts into k8s-traditional hack dir.
2021-05-24 17:25:01 -07:00
monopole
172adc404f Consolidate scripts into k8s-traditional hack dir. 2021-05-24 17:09:11 -07:00
Jeff Regan
501748192b Merge pull request #3920 from monopole/unpinEverything
Back to development mode; unpin the modules
2021-05-24 09:42:57 -07:00
monopole
f6e6ac0320 Back to development mode; unpin the modules 2021-05-24 09:30:04 -07:00
Zhou Hao
a10ce1d787 cleanup tempfiles for runfn_test
Signed-off-by: Zhou Hao <zhouhao@fujitsu.com>
2021-05-24 17:01:44 +08:00
Zhou Hao
839cc2467c cleanup tempfiles for fmtr_test
Signed-off-by: Zhou Hao <zhouhao@fujitsu.com>
2021-05-24 15:52:28 +08:00
Mikhail Mazurskiy
dbc11ed29f Handle errors 2021-05-21 16:53:14 +10:00
Jeff Regan
0f614e92f7 Merge pull request #3909 from monopole/pinToApi
Pin to api v0.8.10
2021-05-20 13:44:39 -07:00
monopole
afaf7c62bc Pin to api v0.8.10 2021-05-20 13:34:27 -07:00
Jeff Regan
78d22069d7 Merge pull request #3910 from monopole/noMorePluginPin
No more plugin pinning.
2021-05-20 13:32:25 -07:00
monopole
22720a8b7a No more plugin pinning. 2021-05-20 13:31:50 -07:00
Jeff Regan
38c66d213a Update README.md 2021-05-20 13:14:28 -07:00
Jeff Regan
871de80544 Merge pull request #3908 from monopole/pinToCmdConfig
Pin to cmd/config v0.9.12
2021-05-20 13:05:20 -07:00
monopole
c24daec480 Pin to cmd/config v0.9.12 2021-05-20 12:54:56 -07:00
Jeff Regan
0849d12572 Update README.md 2021-05-20 12:54:06 -07:00
Jeff Regan
23bd8ff749 Merge pull request #3907 from monopole/fixFormatting
Fix go.mod in plugins.
2021-05-20 12:53:00 -07:00
monopole
b5759305af Fix go.mod in plugins. 2021-05-20 12:52:34 -07:00
Jeff Regan
da518668b5 Merge pull request #3906 from monopole/pinToKyaml
Pin to kyaml v0.10.20
2021-05-20 12:46:05 -07:00
monopole
51605beb3b Pin to kyaml v0.10.20 2021-05-20 12:35:01 -07:00
Jeff Regan
2646861a4c Update README.md 2021-05-20 12:29:15 -07:00
Jeff Regan
f8c910bd3b Update go.mod 2021-05-20 12:27:03 -07:00
Jeff Regan
cb82dced8a Merge pull request #3905 from monopole/fixMakefile
Fix makefile install-tools for Go 1.16
2021-05-20 11:12:12 -07:00
monopole
f618f9ce96 Fix makefile install-tools for Go 1.16 2021-05-20 10:54:13 -07:00
Jeff Regan
020dc9c216 Merge pull request #3903 from monopole/fixRepoSpecTest
Fix repospec test
2021-05-20 09:54:12 -07:00
monopole
a6b9445702 Fix repospec test 2021-05-20 09:52:59 -07:00
Jeff Regan
36408a120c Update HelmChartInflationGenerator.go 2021-05-19 17:34:44 -07:00
Jeff Regan
c1bca9cd62 Merge pull request #3900 from joshdk/master
URL based configuration for git exec timeouts and git submodule cloning
2021-05-19 16:10:35 -07:00
Jeff Regan
701973b73e Merge pull request #3899 from KnVerey/embedfs
[kyaml fn framework] Swap pkger for embed.FS compatibility
2021-05-19 09:29:23 -07:00
Josh Komoroske
24a64bdee3 URL based configuration for git exec timeouts and git submodule cloning
Adds a number of user-accessable options for configuring internal git resource
cloning behavior.
- Git commands are executed with a configurable timeout by including a parameter
  like "?timeout=2m30s" in the resource URL. This can improve cloning a large
  repository, or over a slow network.
- Git submodule cloning can be disabled by including a parameter like
  "?submodules=false" in the resource URL.
- Switch the overall query parsing to use url.Parse() and be more extensible.
2021-05-19 00:07:02 -07:00
Katrina Verey
3f3d3b17a4 Replace pkger with embed.FS compatibility 2021-05-18 12:07:42 -07:00
Katrina Verey
53c87a32e9 Reset openapi in Filter and show use of pkger with filepath 2021-05-18 11:20:42 -07:00
Katrina Verey
0fdf0f825f TemplateProcessor can add custom resource schemas to openapi 2021-05-18 11:20:42 -07:00
Devon Mizelle
73da51d0ac Apply suggestions from code review
Co-authored-by: Steven E. Harris <seh@panix.com>
2021-05-17 12:18:33 -04:00
Devon Mizelle
df10d5a17d Add includeCRDs Field to HelmChart
This commit adds functionality for a user to specify that `helm` should
include CRDs when inflating a Helm Chart.

As of Helm v3, the `install-crd` hook is no more, with
`CustomResourceDefinitions` existing in the root of the chart, under the
`crds` directory.

When calling `helm template`, `helm` does not output these CRDs unless
the user passes the `--include-crds` flag to the command.

With this commit, users can set `includeCRDs: true` as part of their helm
chart definition in `kustomize.yaml` to have these included as part of
the output.

Signed-off-by: Devon Mizelle <devon.mizelle@onepeloton.com>
2021-05-14 16:46:30 -04:00
Jeff Regan
9557888b32 Merge pull request #3889 from sylr/fix-tests-macos
Fix api tests on MacOS
2021-05-13 15:22:18 -07:00
Jeff Regan
3e14a31312 Merge pull request #3893 from natasha41575/fixTests
use assert statements for kustomize edit tests
2021-05-12 16:33:27 -07:00
Natasha Sarkar
dca13a4770 use assert statements for kustomize edit tests 2021-05-12 16:20:12 -07:00
Kubernetes Prow Robot
017a094438 Merge pull request #3888 from monopole/popRNodeUp
Remove delegation to RNode in Resource
2021-05-11 13:35:14 -07:00
Kubernetes Prow Robot
b8e7cf04b6 Merge pull request #3832 from cehoffman/helm-chart-namespace
Add ability to set target namespace for helm chart template
2021-05-11 13:09:13 -07:00
Sylvain Rabot
a8dacdaffc Fix api tests on MacOS
On MacOS /var is a symlink for /private/var and we can end up having the
loader having a /private/var path while the TMPDIR has a /var path which
triggers a panic.

Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
2021-05-11 20:02:56 +02:00
monopole
5c4e363f11 Remove delegation to RNode in Resource. 2021-05-11 10:49:17 -07:00
Kubernetes Prow Robot
1e3ce57077 Merge pull request #3886 from monopole/applyFilter
Introduce resmap.ApplyFilter.
2021-05-11 08:31:36 -07:00
monopole
01ddeb476d Introduce resmap.ApplyFilter. 2021-05-10 20:47:57 -07:00
Jeff Regan
714af0cd66 Merge pull request #3884 from monopole/nitterFix
Simplify kind and name change code.
2021-05-09 16:21:52 -07:00
monopole
82abd7e9ea Simplify kind and name change code. 2021-05-09 16:20:39 -07:00
Jeff Regan
823ff2d048 Update go.mod 2021-05-08 08:02:28 -07:00
Kubernetes Prow Robot
fcfdf6be51 Merge pull request #3880 from Shell32-Natsu/func-filter-result
Make result in function filter public
2021-05-06 15:43:02 -07:00
Donny Xia
627118c438 skip tests instead of comment out 2021-05-06 12:33:17 -07:00
Donny Xia
5bb7364967 Fix linter error 2021-05-06 09:54:35 -07:00
Donny Xia
a46926c1eb Disable tests that use non-exist image 2021-05-06 09:54:26 -07:00
Donny Xia
4f760a0850 make result public in function filter 2021-05-06 09:45:11 -07:00
Jeff Regan
e905411207 Update go.mod 2021-05-05 13:02:57 -07:00
Jeff Regan
1eb77a6cab Update README.md 2021-05-05 08:27:58 -07:00
Jeff Regan
8b1704bcf3 Merge pull request #3874 from monopole/depprobcheck
Add a dependency debugging directory.
2021-05-04 22:21:33 -07:00
monopole
a0edb2d966 Add a dependency debugging directory. 2021-05-04 22:11:52 -07:00
Kubernetes Prow Robot
02dff45d7d Merge pull request #3870 from Shell32-Natsu/fix-image-helm
add helm fields to ordered fields
2021-05-04 06:25:13 -07:00
Donny Xia
3cf18adae9 fix test 2021-05-03 17:02:55 -07:00
Donny Xia
2bec25b46e add new fields to ordered fields 2021-05-03 16:57:27 -07:00
Kubernetes Prow Robot
8ee308d5d6 Merge pull request #3863 from monopole/simplifyGvk
Simplify gvk, speed up cluster-scoped checks.
2021-05-03 16:06:20 -07:00
Jeff Regan
3c3c97f9b5 Merge pull request #3854 from natasha41575/updateOpenApiFetch
update openapi fetch command
2021-05-03 12:20:26 -07:00
Kubernetes Prow Robot
c3e8f6008e Merge pull request #3838 from monopole/helmNamespace
A last-mile helm example, with namespace and prefix
2021-05-03 11:02:08 -07:00
monopole
660847225d Simplify gvk, speed up cluster-scoped checks. 2021-05-02 13:17:33 -07:00
Jeff Regan
48d16f877b Merge pull request #3864 from monopole/runMoreTests
Run e2e tests against 4.1.2
2021-05-02 13:17:04 -07:00
monopole
a4f4945455 Run e2e tests against 4.1.2 2021-05-02 13:01:24 -07:00
Jeff Regan
bd7229ea17 Merge pull request #3862 from monopole/updateGoSums
Update plugin go.mod, go.sum w/r to kyaml.
2021-05-02 10:38:22 -07:00
monopole
72441ce3ef Update plugin go.mod, go.sum w/r to kyaml. 2021-05-02 10:22:22 -07:00
Jeff Regan
fe5b7a3b41 Merge pull request #3861 from monopole/backToDevMode
Require kyaml v0.10.19, and unpin everything.
2021-04-30 23:01:18 -07:00
monopole
a4db686b6c Unpin everything. 2021-04-30 22:49:38 -07:00
Jeff Regan
10026758d3 Merge pull request #3860 from monopole/moveResidFromApiToKyamlModule
Move resid from api to kyaml module
2021-04-30 22:14:24 -07:00
monopole
c8dddac5b9 Move resid package from api to kyaml 2021-04-30 20:39:32 -07:00
monopole
5a8a4d47a5 More pinning. 2021-04-30 20:21:36 -07:00
monopole
6c35c06f3e Pin the plugins. 2021-04-30 20:11:14 -07:00
monopole
1235047742 Establish pin state. 2021-04-30 19:32:43 -07:00
Jeff Regan
6c041c3a79 Merge pull request #3859 from monopole/pinToCmdConfig
Pin to cmd/config v0.9.11
2021-04-30 18:57:12 -07:00
monopole
1e7260b69a Pin to cmd/config v0.9.11 2021-04-30 18:46:59 -07:00
Jeff Regan
1de5fe608f Merge pull request #3858 from monopole/gorepoModAdjustments
In module lists, handle allowed replacements.
2021-04-30 18:36:25 -07:00
monopole
6c9bf58e7f In module lists, handle allowed replacements. 2021-04-30 18:35:59 -07:00
Jeff Regan
accd71a105 Update README.md 2021-04-30 18:15:54 -07:00
Jeff Regan
e3fd691459 Merge pull request #3857 from monopole/pinToKyaml_v0.10.18
Pin to kyaml/v0.10.18
2021-04-30 18:10:06 -07:00
monopole
3a508da641 Pin to kyaml/v0.10.18 2021-04-30 17:39:24 -07:00
Jeff Regan
a64a1022e6 Merge pull request #3855 from monopole/allowReplacements
When releasing, allow certain replacements.
2021-04-30 17:08:52 -07:00
monopole
b6fba0ad5c When releasing, allow certain replacements. 2021-04-30 17:08:16 -07:00
Natasha Sarkar
45fc67062e update openapi fetch command 2021-04-30 16:00:19 -07:00
Kubernetes Prow Robot
32cef014bb Merge pull request #3844 from MaXinjian/0428
Fix small golint warning
2021-04-30 14:13:58 -07:00
Ma Xinjian
677ec868e0 Fix golint warning
golint warning: if block ends with a return statement, so drop this else and outdent its block

Signed-off-by: Ma Xinjian <maxj.fnst@fujitsu.com>
2021-04-30 09:22:57 +08:00
Kubernetes Prow Robot
7716b1bd3d Merge pull request #3821 from phanimarupaka/OverrideIsSameResourceImpl
Support multiple implementations for IsSameResource
2021-04-28 08:42:50 -07:00
Phani Teja Marupaka
8a529ca399 Update merge3 with deafult GVKNN matcher 2021-04-27 23:53:54 -07:00
Phani Teja Marupaka
914a82bfa4 Support multiple implementations for IsSameResource 2021-04-27 23:53:43 -07:00
Jeff Regan
197c95f6ef Merge pull request #3843 from monopole/upgradeReplace
Update go.sum in replacements.
2021-04-27 16:32:01 -07:00
monopole
323672bc38 Update go.sum in replacements. 2021-04-27 16:14:32 -07:00
Kubernetes Prow Robot
66ce6f8801 Merge pull request #3827 from gautierdelorme/rm-go-openapi-spec-validate-strfmt
remove go-openapi/spec,validate,strfmt
2021-04-26 12:33:16 -07:00
Gautier Delorme
6bc9d7358c remove go-openapi/spec,validate,strfmt from plugins
Signed-off-by: Gautier Delorme <gautier.delorme@gmail.com>
2021-04-25 16:57:39 +02:00
Gautier Delorme
bcbfa069ae remove go-openapi/spec,validate,strfmt from kustomize/
Signed-off-by: Gautier Delorme <gautier.delorme@gmail.com>
2021-04-25 16:57:39 +02:00
Gautier Delorme
7e622e1382 remove go-openapi/spec,validate,strfmt from cmd/config/
Signed-off-by: Gautier Delorme <gautier.delorme@gmail.com>
2021-04-25 16:57:39 +02:00
Gautier Delorme
a2871181fe remove go-openapi/spec,validate,strfmt from kyaml/
Signed-off-by: Gautier Delorme <gautier.delorme@gmail.com>
2021-04-25 16:57:39 +02:00
Gautier Delorme
86c3863bc9 remove go-openapi/spec,validate,strfmt from api/
Signed-off-by: Gautier Delorme <gautier.delorme@gmail.com>
2021-04-25 16:57:34 +02:00
Jeff Regan
14d2f4bb15 Merge pull request #3841 from monopole/deleteCrawl
Delete internal/crawl.
2021-04-23 19:43:01 -07:00
monopole
c6f575ce37 Delete internal/crawl. 2021-04-23 19:24:15 -07:00
Jeff Regan
e86fd7f009 Merge pull request #3822 from benjamintanweihao/patch-1
Fix typo
2021-04-23 12:46:30 -07:00
monopole
d03a5ab95f Add another last mile helm example. 2021-04-23 11:10:45 -07:00
Jeff Regan
8ef9f75de7 Merge pull request #3839 from monopole/harnessMkDir
Add testharness mkdir function.
2021-04-23 11:10:22 -07:00
monopole
cf3a125940 Add testharness mkdir function. 2021-04-23 11:09:34 -07:00
Kubernetes Prow Robot
8049f7b1af Merge pull request #3836 from monopole/ownerAliasChange
Update OWNER_ALIASES
2021-04-23 10:45:39 -07:00
Kubernetes Prow Robot
985fe4821d Merge pull request #3835 from monopole/useResIdInReplacements
Use resid.ResId in replacements.
2021-04-23 10:25:41 -07:00
monopole
c828b1e49a Use resid.ResId in replacements. 2021-04-23 09:30:05 -07:00
Jeff Regan
d5d44ce3fe Merge pull request #3837 from navist2020/modify/Error_log_info
modify Error log info
2021-04-23 08:01:19 -07:00
navist2020
5d3dac04fa modify Error log info 2021-04-23 14:40:05 +08:00
monopole
d2f5fe13aa Update OWNER_ALIASES 2021-04-22 21:20:16 -07:00
Jeff Regan
705c6ad5ce Merge pull request #3834 from monopole/pinPluginsToV0.0.0
Pin plugins to v0.0.0
2021-04-22 17:20:18 -07:00
monopole
94f8d4ec63 Pin plugins to v0.0.0 2021-04-22 17:06:33 -07:00
Francesc Campoy
225bae8491 Make fsNode handle correctly consecutive reads and writes (#3820)
* Make fsNode handle correctly consecutive reads and writes

* Check for directories in ReadFile and add some error checks

* Update comment

* Improved docs and added better test

* Move test into its own file protected by built constraint

* Use manual test since iotest.TestReader is only available in Go 1.16
2021-04-22 16:50:01 -07:00
Chris Hoffman
53f78260a9 Add ability to set target namespace for helm chart template 2021-04-22 18:31:26 -05:00
Jeff Regan
06add3ab35 Merge pull request #3737 from natasha41575/ReplacementTransformer
replacement transformer that uses the new replacement filter
2021-04-22 11:22:51 -07:00
Benjamin Tan Wei Hao
a59ec8fe23 Fix typo 2021-04-21 16:53:21 +08:00
Jeff Regan
f93cee9440 Merge pull request #3813 from monopole/unpinEverything
Back to dev mode; unpin the modules.
2021-04-16 03:12:33 -07:00
Kubernetes Prow Robot
21e65990c1 Merge pull request #3795 from jlandowner/master
Support immutable attribute on generators
2021-04-15 22:36:22 -07:00
monopole
38e9c34f08 Back to dev mode; unpin the modules. 2021-04-15 22:15:57 -07:00
Natasha Sarkar
038bc7713b add replacement transformer 2021-04-15 14:12:33 -07:00
Jeff Regan
a5914abad8 Merge pull request #3811 from monopole/pinToApi
Pin to api v0.8.8
2021-04-15 13:32:54 -07:00
monopole
3f2b98ff01 Pin to api v0.8.8 2021-04-15 13:21:06 -07:00
Jeff Regan
aa1dd9ddc2 Merge pull request #3810 from monopole/mergo_0.3.5
Back to mergo v0.3.5
2021-04-15 13:11:16 -07:00
monopole
5ba45f1ef8 Back to mergo v0.3.5 2021-04-15 12:48:20 -07:00
Jeff Regan
f3752dc75c Update args.go 2021-04-15 12:31:29 -07:00
Jeff Regan
d5f4da1261 Merge pull request #3809 from monopole/unpinEverything
Back to development mode; unpin the modules
2021-04-15 09:13:28 -07:00
Kubernetes Prow Robot
7680392d96 Merge pull request #3808 from fenggw-fnst/work
Fix typo
2021-04-14 20:21:49 -07:00
monopole
d8015d3c93 Back to development mode; unpin the modules 2021-04-14 20:08:13 -07:00
Jeff Regan
7487e2f9cb Merge pull request #3807 from monopole/pinToApi
Pin to api v0.8.7
2021-04-14 20:03:46 -07:00
Guangwen Feng
4b8bc7d6ba Fix typo
Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
2021-04-15 10:55:28 +08:00
monopole
59af49522e Pin to api v0.8.7 2021-04-14 19:47:59 -07:00
Jeff Regan
72d3eb15e0 Update remoteBuild.md 2021-04-14 19:26:42 -07:00
Jeff Regan
14e31de6b1 Merge pull request #3806 from monopole/unpinApi
Unpin the api
2021-04-14 19:03:18 -07:00
monopole
162b8f3d37 Unpin the api 2021-04-14 18:44:16 -07:00
Kubernetes Prow Robot
003cf61a48 Merge pull request #3805 from KnVerey/downgrade-mergo
Downgrade mergo to v0.3.7
2021-04-14 16:11:51 -07:00
Katrina Verey
74f0df8b9d Downgrade mergo to v0.3.7 2021-04-14 14:58:02 -07:00
Jeff Regan
0df531e7c6 Merge pull request #3802 from monopole/pinToApi
Pin to api v0.8.6
2021-04-13 12:22:20 -07:00
monopole
e3ce61647f Pin to api v0.8.6 2021-04-13 12:05:52 -07:00
Jeff Regan
768132f65f Merge pull request #3801 from monopole/pinToCmdConfig
Pin to cmd/config v0.9.10
2021-04-13 11:37:55 -07:00
monopole
6a708bcc23 Pin to cmd/config v0.9.10 2021-04-13 11:24:17 -07:00
Jeff Regan
d8182f8d81 Merge pull request #3800 from monopole/fixGoModNit
Fix go.sum nit
2021-04-13 11:19:21 -07:00
monopole
99b6a5920e Fix go.sum nit 2021-04-13 11:15:36 -07:00
Jeff Regan
8877c81468 Merge pull request #3799 from monopole/pinToKyaml_v0.10.17
Pin to kyaml@v0.10.17
2021-04-13 11:01:50 -07:00
monopole
88911bbb61 Pin to kyaml@v0.10.17 2021-04-13 10:31:18 -07:00
jlandowner
82ff64c374 Support immutable attribute on generators 2021-04-13 01:02:58 +00:00
Jeff Regan
01c477570a Merge pull request #3750 from minchao/fix-wordpress-init-command
Fix init command in wordpress example
2021-04-12 16:46:19 -07:00
Kubernetes Prow Robot
f8dad80a79 Merge pull request #3784 from monopole/flagEnableHelm
Add flag --enable-helm
2021-04-12 13:52:15 -07:00
monopole
240cda089a Add flag --enable-helm 2021-04-12 13:40:21 -07:00
Kubernetes Prow Robot
c94c193b5b Merge pull request #3793 from jeremyrickard/better-update-handling
Add check of UpdateExpectedFromActual before skipping test
2021-04-12 12:52:15 -07:00
Jeremy
9989b5fc84 Add check of UpdateExpectedFromActual before skipping test
Signed-off-by: Jeremy <jeremyrrickard@gmail.com>
2021-04-12 13:12:53 -06:00
Jeff Regan
aeba50488b Merge pull request #3792 from monopole/nits
Fix nits, add internal GetRoot func.
2021-04-12 07:53:00 -07:00
monopole
9c43518a15 Fix nits, add internal GetRoot func. 2021-04-12 07:51:01 -07:00
Jeff Regan
9d50890174 Merge pull request #3790 from monopole/enhanceHarness
Enhance the enhanced test harness.
2021-04-11 18:50:00 -07:00
monopole
3af1ae4159 Enhance test harness. 2021-04-11 18:14:30 -07:00
Kubernetes Prow Robot
5100568b0c Merge pull request #3788 from monopole/helmPrep
upgrade to helm 3.5.4 and imdario/mergo v0.3.12
2021-04-09 15:52:22 -07:00
monopole
aa5b4814d6 upgrade to helm 3.5.4 and imdario/mergo v0.3.12 2021-04-09 15:05:41 -07:00
Kubernetes Prow Robot
264b3ff338 Merge pull request #3773 from natasha41575/ReplacementFieldOptions
use field options to refine replacements
2021-04-09 12:15:16 -07:00
Natasha Sarkar
a40c74e545 use field options to refine replacements 2021-04-09 11:15:49 -07:00
Kubernetes Prow Robot
f61b075d3b Merge pull request #3775 from Shell32-Natsu/kyaml-filter
Enable LocalPackageReader to ignore specific path
2021-04-08 09:52:03 -07:00
Donny Xia
629d822604 Merge pull request #3783 from natasha41575/AddNatasha
add natasha to maintainers
2021-04-08 09:39:55 -07:00
Jeff Regan
bf64f109b9 Merge pull request #3782 from natasha41575/ReplacementRejectField
add use of rejects field in replacement filter
2021-04-08 09:15:53 -07:00
Natasha Sarkar
5f93fc53f4 add natasha to maintainers 2021-04-07 17:08:30 -07:00
Natasha Sarkar
0fe3f303e8 add use of rejects field in replacement filter 2021-04-07 16:00:18 -07:00
Donny Xia
7825050b18 Enable LocalPackageReader to ignore specific path 2021-04-05 12:46:20 -07:00
Jeff Regan
ed688a87e4 Update README.md 2021-04-02 17:34:22 -07:00
Jeff Regan
629fdee26a Merge pull request #3774 from monopole/fixGoSums
Fix go sum files.
2021-04-02 16:04:48 -07:00
Kubernetes Prow Robot
ca58ce775a Merge pull request #3771 from natasha41575/ReplacementFilterTests
add more tests for replacement filter
2021-04-02 16:02:12 -07:00
monopole
0990d96c52 Fix go sum files. 2021-04-02 15:50:24 -07:00
Natasha Sarkar
94c45e0f9f add more tests for replacement filter 2021-04-02 11:30:10 -07:00
Kubernetes Prow Robot
ca527a8e4c Merge pull request #3735 from natasha41575/ReplacementFilter
add replacement filter to support replacmenttransformer
2021-03-31 18:03:21 -07:00
Natasha Sarkar
fa0b237178 add replacement filter to support replacmenttransformer 2021-03-31 17:04:43 -07:00
Kubernetes Prow Robot
a9bcf7187a Merge pull request #3558 from zhijianli88/GOBIN
Makefile: check and use GOBIN environment variable first
2021-03-31 10:01:01 -07:00
Kubernetes Prow Robot
a49d429909 Merge pull request #3768 from monopole/pinToKyaml
Pin to kyaml v0.10.16
2021-03-30 15:00:58 -07:00
monopole
c63288024d Pin to kyaml v0.10.16 2021-03-30 14:40:52 -07:00
Kubernetes Prow Robot
f374a12f24 Merge pull request #3759 from phanimarupaka/NoKptfileInTreeOutput
Don't print Krmfile file in tree output
2021-03-30 09:37:57 -07:00
Kubernetes Prow Robot
c7156d0586 Merge pull request #3733 from RyanSquared/add-crd-webhook-namespace-transformer
Add CustomResourceDefinition webhook namespace transformer
2021-03-26 11:50:43 -07:00
Jeff Regan
d3b7d3ab70 Merge pull request #3754 from webwurst/patch-3
Fix indentation
2021-03-26 11:37:36 -07:00
Jeff Regan
197bb9d9e3 Merge pull request #3744 from KnVerey/plugin-dir-error
Do no require exec/go plugin home to use fn plugins
2021-03-26 11:26:48 -07:00
Phani Teja Marupaka
fa96878cfc Don't print Kustomization file in tree output 2021-03-25 17:01:30 -07:00
Kubernetes Prow Robot
558995536d Merge pull request #3748 from phanimarupaka/AvoidSetPanic
Check if value is provided
2021-03-25 10:23:30 -07:00
Katrina Verey
3255c73c71 Loader FS and empty env fix 2021-03-24 18:44:29 -07:00
Tobias Bradtke
fd486c1f23 Fix indentation 2021-03-24 22:29:31 +01:00
Kubernetes Prow Robot
b0a40e2752 Merge pull request #3743 from Shell32-Natsu/label
Add labels field to kustomization
2021-03-24 12:25:28 -07:00
Donny Xia
ccb95ab269 add conflict check 2021-03-24 10:41:37 -07:00
minchao
e6b52e7295 Fix init command in wordpress example 2021-03-24 11:19:53 +08:00
Jeff Regan
4a6ec9063d Merge pull request #3747 from natasha41575/RemoveOldReplacementTransformer
remove old untested replacement transformer
2021-03-23 16:47:16 -07:00
Phani Teja Marupaka
c3beadacd9 Check if value is provided 2021-03-23 15:40:35 -07:00
Natasha Sarkar
5f3bd4b4c2 remove old untested replacement transformer 2021-03-23 14:28:53 -07:00
Katrina Verey
e77c284924 Do no require exec/go plugin home to use fn plugins 2021-03-23 10:47:16 -07:00
Donny Xia
5ed2067be9 Add labels field to kustomization 2021-03-22 17:01:45 -07:00
Jeff Regan
7b38ce4ef2 Merge pull request #3740 from monopole/fixNitsIn3731
Fix nits in 3731
2021-03-20 07:31:28 -07:00
monopole
700a112b28 Fix nits in 3731 2021-03-20 07:05:56 -07:00
Jeff Regan
e05ce0f05b Merge pull request #3731 from dfsdevops/test-validating-webhook
added test showing broken namespace reference when combining resource…
2021-03-20 06:40:08 -07:00
Jeff Regan
b8cfa3ca9b Merge pull request #3738 from phanimarupaka/MakeDirOptionalForTree
Make dir optional for tree command
2021-03-20 06:38:35 -07:00
Phani Teja Marupaka
26a8455717 Make dir optional for tree command 2021-03-19 16:58:16 -07:00
Jeff Regan
710db98dbf Merge pull request #3685 from natasha41575/PatchServicePort
fixed disappearing port issue
2021-03-17 11:00:39 -07:00
Dylan Schultz
0d152c4784 added comment referring test to issue 3732 2021-03-17 10:52:41 -07:00
Kubernetes Prow Robot
1729c95135 Merge pull request #3734 from monopole/removeMergeConflictCode
Remove dead merge conflict code.
2021-03-17 09:51:58 -07:00
monopole
6f6d41f17f Remove dead merge conflict code. 2021-03-17 06:35:30 -07:00
RyanSquared
3ff5263ff6 api/konfig/builtinpluginconsts/namespace: Add CustomResourceDefinition webhook namespace transformer 2021-03-16 19:35:18 -05:00
Dylan Schultz
5bb668533f added test showing broken namespace reference when combining resources from two different bases 2021-03-16 17:01:39 -07:00
Jeff Regan
eb48b1b718 Merge pull request #3730 from monopole/typeAlias
Type alias for spec.Schema
2021-03-16 16:54:41 -07:00
monopole
1f837fdfec Type alias for spec.Schema 2021-03-16 16:18:10 -07:00
Kubernetes Prow Robot
1301384670 Merge pull request #3729 from Shell32-Natsu/helm-deps
handle helm output properly
2021-03-16 15:12:56 -07:00
Donny Xia
a9c20a2eb7 handle helm output properly 2021-03-16 13:09:04 -07:00
Kubernetes Prow Robot
297bdc3825 Merge pull request #3727 from monopole/fix3394
Allow patch removal of emptyDir {}
2021-03-16 10:06:35 -07:00
Jeff Regan
831f99c95b Merge pull request #3715 from natasha41575/SpeedUpCustomParsing
Speed up custom parsing
2021-03-15 22:26:27 -07:00
Jeff Regan
5247aa5750 Update resource.go 2021-03-15 22:22:43 -07:00
monopole
74d5646526 Allow patch removal of emptyDir {} 2021-03-15 18:34:36 -07:00
Natasha Sarkar
2f6a611e62 add example of using custom schema 2021-03-15 18:08:12 -07:00
Kubernetes Prow Robot
d0dbc3e87b Merge pull request #3721 from monopole/removeWrappyLayer
Remove the wrappy package in service of 3588
2021-03-15 16:54:34 -07:00
monopole
235101a614 Drop uses of 'unstructured' terminology. 2021-03-15 15:59:06 -07:00
monopole
123a5d6e56 Remove the wrappy layer. 2021-03-15 15:59:06 -07:00
Jeff Regan
e4bbd04a43 Merge pull request #3644 from natasha41575/AllowGeneralNameChanges
allow general name and kind changes via an options field in patches
2021-03-15 15:49:04 -07:00
Jeff Regan
75120b2a92 Merge pull request #3708 from saschagrunert/test-version
Take provenance version into account for build test
2021-03-15 13:16:29 -07:00
Jeff Regan
cb423ad300 Merge pull request #3725 from JohanWork/bug-demo-components-link
Fix broken link kep 1802
2021-03-15 12:40:31 -07:00
Johan Hansson
c81b5bd3c2 updated formatting 2021-03-14 21:49:23 +01:00
Kubernetes Prow Robot
b3cec39c25 Merge pull request #3720 from Shell32-Natsu/helm-version
support new version string in helm
2021-03-12 15:33:03 -08:00
Donny Xia
5fc6cab49f support new version string in helm 2021-03-12 12:01:02 -08:00
Donny Xia
c636ee616b Merge pull request #3713 from jkroepke/patch-1
HelmChartInflationGenerator: inherit environment variables to helm command
2021-03-12 10:10:54 -08:00
Natasha Sarkar
f96ac2d61e allow general name and kind changes via an options field in patches 2021-03-10 14:58:58 -08:00
Natasha Sarkar
a513c56d88 parse custom schema only once when necessary 2021-03-10 13:45:53 -08:00
Natasha Sarkar
ed3ab9f532 updated krusty tests for custom schema 2021-03-10 13:45:34 -08:00
Jeff Regan
bab8c34c1f Merge pull request #3709 from monopole/removeKyamlBranching
Remove branching on kyaml enablement
2021-03-09 14:45:26 -08:00
monopole
839fd2b971 Remove branching on kyaml enablement 2021-03-09 14:29:27 -08:00
Jeff Regan
26e9b8b3b8 Merge pull request #3714 from monopole/backToDev
Unpin all modules (back to dev mode).
2021-03-09 14:17:36 -08:00
monopole
ddfb4ff02d Unpin all modules (back to dev mode). 2021-03-09 14:01:26 -08:00
Jan-Otto Kröpke
a5e6295923 HelmChartInflationGenerator: inherit environment variables to helm command 2021-03-09 19:44:53 +01:00
Sascha Grunert
e2e495027d Take provenance version into account for build test
The result of the test will be different depending on how it has being
build via `-ldflags=-X sigs.k8s.io/kustomize/api/provenance.version=…`.

We now additionally query this version within the test to make it more
robust.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2021-03-09 09:52:45 +01:00
Natasha Sarkar
397744f436 fixed disappearing ports issue 2021-03-08 17:03:22 -08:00
Jeff Regan
9e8e7a7fe9 Merge pull request #3704 from monopole/pinToApi
Pin to api v0.8.5
2021-03-08 12:13:15 -08:00
monopole
4d66f9a093 Pin to api v0.8.5 2021-03-08 11:46:32 -08:00
Jeff Regan
81cac9b633 Merge pull request #3702 from monopole/pinToCmdConfig
Pin to cmd/config v0.9.7
2021-03-08 11:42:47 -08:00
Jeff Regan
43edc6dd7f Update README.md 2021-03-08 11:32:24 -08:00
Jeff Regan
f313cca52b Update go.sum 2021-03-08 11:30:52 -08:00
monopole
243e7cca1f Pin to cmd/config v0.9.7 2021-03-08 11:21:35 -08:00
Jeff Regan
b9c36caa1c Merge pull request #3701 from monopole/pinToKyamlAndCliUtils
Pin to kyaml v0.10.15
2021-03-08 11:19:42 -08:00
monopole
711b4ff4bb Pin to kyaml v0.10.15 2021-03-08 11:18:42 -08:00
Jeff Regan
8d72528eb5 Merge pull request #3700 from natasha41575/UpdateKustomizationWithEnvs
add env to kustomization openapi spec
2021-03-08 11:05:45 -08:00
Kubernetes Prow Robot
6590cce5c1 Merge pull request #3699 from Shell32-Natsu/image-transformer
cleanup image transformer
2021-03-08 10:56:12 -08:00
Natasha Sarkar
12c0360ba3 add env to kustomization openapi spec 2021-03-08 10:51:32 -08:00
Donny Xia
8e8fa5409d cleanup image transformer 2021-03-08 10:41:43 -08:00
Jeff Regan
5af35f4f1a Merge pull request #3695 from simster7/readlink
Use portable method to emulate 'readlink -f' behavior
2021-03-08 10:24:27 -08:00
Kubernetes Prow Robot
412e73cf76 Merge pull request #3697 from monopole/podTemplate
Add PodTemplate field to namereference config.
2021-03-08 10:07:43 -08:00
monopole
ec27642e2f Add PodTemplate field to namereference config. 2021-03-08 09:52:08 -08:00
Kubernetes Prow Robot
7165b1ec40 Merge pull request #3692 from monopole/reinstateEnv
Reinstate configmap/secret generator 'env' field.
2021-03-08 09:41:43 -08:00
Simon Behar
6dd50de7a4 Use portable method to emulate 'readlink -f' behavior
Signed-off-by: Simon Behar <simbeh7@gmail.com>
2021-03-08 09:27:38 -08:00
monopole
a8b851f84a Reinstate configmap/secret generator env field. 2021-03-07 20:42:41 -08:00
Jeff Regan
9c4966ccc8 Merge pull request #3691 from monopole/fixGoSum
Fix go.sum
2021-03-07 20:17:32 -08:00
monopole
d0bb1cd0fa Fix go.sum 2021-03-07 20:16:16 -08:00
Jeff Regan
102cf87f36 Merge pull request #3690 from monopole/pinToCmdConfig
Pin to cmd/config v0.9.6
2021-03-07 18:42:21 -08:00
monopole
584a6c2a86 Pin to cmd/config v0.9.6 2021-03-07 18:19:02 -08:00
Jeff Regan
03c6f8fff4 Merge pull request #3689 from kubernetes-sigs/pinToKyaml
Pin to kyaml v0.10.14
2021-03-07 18:17:08 -08:00
monopole
90de9b78df Pin to kyaml v0.10.14 2021-03-07 18:00:24 -08:00
Jeff Regan
34f1f2967e Merge pull request #3688 from monopole/undoreplace
Undo kyaml/go.mod lint replacements.
2021-03-07 15:01:59 -08:00
monopole
9a9df7436e Undo kyaml/go.mod lint replacements. 2021-03-07 14:36:05 -08:00
Jeff Regan
c036830c70 Merge pull request #3676 from rhtenhove/master
allow most recent release with specific path
2021-03-07 12:47:28 -08:00
Ruben ten Hove
ebbd0c7b5a check if version exists 2021-03-06 13:55:39 +01:00
Jeff Regan
7264a3a65d Merge pull request #3686 from monopole/extractFunctionEnablers
Extract flags that enable alpha function features.
2021-03-05 20:25:58 -08:00
monopole
f3a958bbf7 Extract flags that enable alpha function features. 2021-03-05 19:55:59 -08:00
Jeff Regan
14bf6f8a27 Merge pull request #3684 from monopole/gomodup
Full tree go mod tidy
2021-03-05 19:55:42 -08:00
monopole
60c8a0498b Full tree go mod tidy. 2021-03-05 18:22:32 -08:00
Jeff Regan
774d768e7b Merge pull request #3579 from KnVerey/framework_refactor
Functions Framework Revamp
2021-03-05 15:58:07 -08:00
Jeff Regan
efef397acf Merge pull request #3679 from natasha41575/MultibyteDataTest
add test for multibyte string
2021-03-05 11:56:46 -08:00
Jeff Regan
5793653630 Merge pull request #3673 from natasha41575/PanicDuplicateKeys
Return error instead of panicking for duplicate keys
2021-03-05 11:55:33 -08:00
Natasha Sarkar
4ee3d05bd8 add test for multibyte string 2021-03-04 17:41:44 -08:00
Kubernetes Prow Robot
a1df3e030f Merge pull request #3669 from justinsb/benchmark_swagger_unpack
Add benchmarks to measure impact of swagger parsing
2021-03-04 17:04:21 -08:00
Kubernetes Prow Robot
4e0332551a Merge pull request #3667 from natasha41575/UpgradeYaml.V2
upgraded to yaml.v2 v2.4.0
2021-03-04 16:48:24 -08:00
Ruben ten Hove
216ab488a6 allow most recent release with specific path 2021-03-04 17:19:39 +01:00
Natasha Sarkar
722b0131f0 return error for duplicate keys rather than panicking 2021-03-03 12:13:24 -08:00
Natasha Sarkar
93dd571df9 regression test for panic on duplicate keys 2021-03-03 11:18:42 -08:00
Katrina Verey
a7000dd9c6 Update unpinned pluginator to new framework 2021-03-03 08:27:19 -08:00
Katrina Verey
5c4b5b1bf0 Improvements to kyaml fn framework
This commit creates a new version of the alpha configuration functions framework. Goals include:
- Make it easy to build multi-version APIs with the framework (not previously facilitated at all).
- Simplify the framework's APIs where redundant configuration options exist (leaving the most powerful, replacing others with helpers to maintain usability they provided).
- Make the Framework's APIs more consistent (e.g. between the various template types, usage of kio.Filter, field names)
- Decouple responsibilities (e.g. command creation, resource list processing, generation of templating functions).
- Make the framework even more powerfully pluggable (e.g. any kio.Filter can be a selector, and the selector the framework provides is itself a filter built from reusable abstractions).
- Improve documentation.
- Make container patches merge fields (notably list fields like `env`) correctly.
2021-03-03 08:27:19 -08:00
Justin SB
8e57ee9111 Add benchmarks to measure impact of swagger parsing
Example results:

BenchmarkSwaggerParse-72               2         882910241 ns/op
BenchmarkAsssetUnpack-72              62          19654866 ns/op
2021-03-03 09:11:42 -05:00
Natasha Sarkar
60bd8d15d9 upgraded to yaml.v2 v2.4.0 2021-03-02 18:04:21 -08:00
Jeff Regan
1d524b6fbe Merge pull request #3666 from natasha41575/UpdateToGo1.16
updated go version to 1.16
2021-03-02 17:20:46 -08:00
Natasha Sarkar
e9c97a4c4e updated go version to 1.16 2021-03-02 16:40:08 -08:00
Kubernetes Prow Robot
48c89cb698 Merge pull request #3661 from natasha41575/TrimOpenApi
update openapi version to v1.20.4
2021-03-02 16:39:19 -08:00
Natasha Sarkar
af1e692a5e fix lint error 2021-03-02 16:03:26 -08:00
Natasha Sarkar
57e7db0423 update openapi version to v1.20.4 2021-03-02 13:46:11 -08:00
Jeff Regan
7fb6fa0f35 Merge pull request #3648 from lcostea/lcostea/smaller_docker_image
feat: Reduce docker image size
2021-02-28 13:01:00 -08:00
Jeff Regan
50c3875354 Merge pull request #3654 from monopole/unpinEverything
Back to development mode; unpin the modules
2021-02-28 13:00:44 -08:00
monopole
efc03bf329 Back to development mode; unpin the modules 2021-02-28 12:41:31 -08:00
Jeff Regan
9785bda7be Merge pull request #3653 from monopole/pinToApi
Pin to api v0.8.4
2021-02-28 12:20:17 -08:00
monopole
29bfdfc1ef Pin to api v0.8.4 2021-02-28 12:06:30 -08:00
Jeff Regan
4f72cb8d00 Merge pull request #3652 from monopole/pinToCmdConfig
Pin to cmd/config v0.9.5
2021-02-28 12:01:11 -08:00
monopole
a45e90b1e4 Pin to cmd/config v0.9.5 2021-02-28 11:40:30 -08:00
Jeff Regan
6b6bc45f2c Update go.sum 2021-02-28 11:29:19 -08:00
Jeff Regan
e4a34f2a48 Merge pull request #3651 from monopole/pinToKyamlAndCliUtils
Pin to kyaml v0.10.13
2021-02-28 11:26:39 -08:00
monopole
4a2ed901b3 Pin to kyaml v0.10.13 2021-02-28 11:04:30 -08:00
Jeff Regan
ba67bc0f18 Merge pull request #3650 from monopole/unpinEverything
Unpin kyaml, cmd/config and api.
2021-02-28 10:46:03 -08:00
monopole
be8d60fb9f Unpin kyaml, cmd/config and api. 2021-02-28 10:26:07 -08:00
Jeff Regan
d9d5bb83f0 Merge pull request #3649 from monopole/updateGeneratedFiles
Update generated files
2021-02-28 10:24:21 -08:00
monopole
cfa7645d3b Update generated files under cmd/config.
sed -i 's|version: v0.18.10|version: v0.19.8|' cmd/config/internal/commands/internal/k8sgen/k8scopy.yaml
(cd cmd/config/; make generate)
2021-02-28 10:11:39 -08:00
monopole
2e6ef91a7c Update generated files under kyaml.
sed -i 's|version: v0.17.0|version: v0.19.8|' kyaml/yaml/internal/k8sgen/k8scopy.yaml
rm kyaml/yaml/internal/k8sgen/pkg/labels/zz_generated.deepcopy.go
(cd kyaml; make generate)
2021-02-28 10:10:52 -08:00
Jeff Regan
508f294e0c k8scopy should rename zz_generated.foo.go
Files whose names start with zz_generated get special treatment from
https://github.com/kubernetes/kubernetes/blob/master/build/common.sh
 (and ./hack/verify-generated-files-remake.sh, etc.).
We don't want that, so modify those file names.
2021-02-28 09:21:35 -08:00
Liviu Costea
a81ebe9842 feat: Reduce docker image size 2021-02-28 12:45:57 +02:00
Jeff Regan
c92fb809c6 Delete older releasing program (replaced by gorepomod). 2021-02-27 06:52:25 -08:00
Jeff Regan
043e8c36e5 Merge pull request #3645 from monopole/pinToApi
Pin to api api/v0.8.3
2021-02-26 17:04:45 -08:00
monopole
7965195c29 Pin to api api/v0.8.3 2021-02-26 16:50:46 -08:00
Jeff Regan
4263d18c1a Update kustomize/api/internal/crawl/go.sum 2021-02-26 16:40:04 -08:00
Jeff Regan
827fb1e1da Merge pull request #3643 from monopole/pinToCmdConfig
Pin to cmd/config v0.9.4
2021-02-26 16:21:30 -08:00
monopole
03c77cee9b Pin to cmd/config v0.9.4 2021-02-26 15:51:25 -08:00
Jeff Regan
2db34e7127 Merge pull request #3642 from monopole/pinToKyamlAndCliUtils
Pin to kyaml v0.10.12
2021-02-26 15:49:11 -08:00
monopole
821b14bfd1 Pin to kyaml v0.10.12 2021-02-26 15:35:13 -08:00
Jeff Regan
33b4735f98 Merge pull request #3641 from monopole/dropReGenerationDirectives
Drop regeneration directives from copied code.
2021-02-26 15:18:24 -08:00
monopole
bbebd1e56a Drop regeneration directives from copied code. 2021-02-26 14:34:22 -08:00
Jeff Regan
c9d9348944 Drop commands replacement from go.mod 2021-02-25 11:15:22 -08:00
Jeff Regan
555c4cb279 Merge pull request #3638 from monopole/pinToApi
Pin to api v0.8.2
2021-02-25 08:19:56 -08:00
monopole
3da90dbde7 Pin to api v0.8.2 2021-02-25 08:04:59 -08:00
Jeff Regan
4ac0f59b8a Merge pull request #3637 from monopole/pinToCmdConfig
Pin to cmd/config v0.9.3
2021-02-25 07:56:06 -08:00
monopole
2b9c69f964 Pin to cmd/config v0.9.3 2021-02-25 07:03:38 -08:00
Jeff Regan
437c960d86 Merge pull request #3636 from monopole/moregosum
More go sum changes.
2021-02-25 07:02:01 -08:00
monopole
131aba8f14 More go sum changes. 2021-02-25 07:01:32 -08:00
Jeff Regan
ada02703cf Merge pull request #3634 from monopole/pinToKyamlAndCliUtils
Pin to kyaml v0.10.11
2021-02-25 07:00:31 -08:00
monopole
f96dfb5772 Pin to kyaml v0.10.11 2021-02-24 21:30:40 -08:00
Jeff Regan
57b3e70cef Merge pull request #3633 from monopole/goSumFix
More go tidy adjustments.
2021-02-24 20:09:02 -08:00
monopole
f4fbcc6fb4 More go tidy adjustments.
ALLOW_MODULE_SPAN
2021-02-24 19:50:37 -08:00
Jeff Regan
867da9631a Merge pull request #3632 from monopole/dropMoreDeps
Remove tool deps from shippable modules.
2021-02-24 18:09:20 -08:00
monopole
cd2b0fce7e Remove tool deps from shippable modules. 2021-02-24 17:37:16 -08:00
Kubernetes Prow Robot
66504c263c Merge pull request #3631 from natasha41575/KrustyTestPaths
Change paths for krusty tests to relative, and have top level be '.'
2021-02-24 16:55:25 -08:00
Jeff Regan
bce4f75fc5 Merge pull request #3630 from natasha41575/UseCustomOpenApiSchema
kustomization openapi data should be parsed for custom schema
2021-02-24 16:32:05 -08:00
Natasha Sarkar
8b082aff5a Change paths for krusty tests to relative, and have top level be '.' instead of 'app' 2021-02-24 16:23:45 -08:00
Natasha Sarkar
48e4cad72e kustomization openapi data should be parsed for custom schema 2021-02-24 15:27:50 -08:00
Kubernetes Prow Robot
30e53a992b Merge pull request #3617 from natasha41575/UseCustomOpenApiSchema
add openapi/path field to use custom openapi schema document
2021-02-24 15:03:24 -08:00
Kubernetes Prow Robot
2df9f85a20 Merge pull request #3621 from natasha41575/OpenApiFetchCommand
added `kustomize openapi fetch` command to get schema from local cluster
2021-02-24 14:37:24 -08:00
Jeff Regan
01733d970a Merge pull request #3608 from argyle-systems/repeat-base-test
Add repeatbase_test.
2021-02-24 14:22:16 -08:00
Kubernetes Prow Robot
ac178c539c Merge pull request #3629 from pwittrock/main
Fork starlib/util for serialization libs.
2021-02-24 14:11:26 -08:00
Phillip Wittrock
61dcb3f548 Fork starlib/util for serialization libs.
Prevents pulling in excessive transitive deps.

See: https://github.com/kubernetes/kubernetes/pull/98946
2021-02-24 11:17:08 -08:00
Chico Venancio
6f15b1e56d Simplify paths and rename objects 2021-02-24 15:13:32 -03:00
Kubernetes Prow Robot
9a94c5ecd3 Merge pull request #3613 from phanimarupaka/DefaultRFalseForListSetters
List setters default false for recurse-subpackages
2021-02-24 07:56:50 -08:00
Kubernetes Prow Robot
2ba148d9b5 Merge pull request #3615 from pwittrock/main
fn framework support for legacy kustomize plugin io
2021-02-24 07:40:51 -08:00
Natasha Sarkar
5a0e193002 moved common resource definitions to separate function 2021-02-23 17:21:16 -08:00
Jeff Regan
3265f64cd5 Merge pull request #3546 from zhijianli88/master
Fix ineffectual assignment to err
2021-02-22 10:24:11 -08:00
Jeff Regan
c2b1ab8303 Add makeKubectlPr.sh 2021-02-22 06:51:37 -08:00
Natasha Sarkar
7dd0ade0f9 add openapi/path field to use custom openapi schema document 2021-02-19 14:19:22 -08:00
Natasha Sarkar
316e4314ed added openapi fetch command to get schema from local cluster 2021-02-19 11:08:31 -08:00
Donny Xia
324353eaf6 Merge pull request #3619 from natasha41575/PatchDeleteOnObjectPanic
fixed panic on patch delete for objects
2021-02-19 10:32:36 -08:00
Natasha Sarkar
6361c3b1b7 fixed panic on patch delete for objects 2021-02-18 10:47:13 -08:00
Phillip Wittrock
f7d13ade35 fn framework support for legacy kustomize plugin io 2021-02-17 09:19:02 -08:00
Kubernetes Prow Robot
99e82890e1 Merge pull request #3606 from qrilka/patch-1
Add name reference for fastcgi-params-configmap
2021-02-17 08:39:09 -08:00
Kubernetes Prow Robot
4a35bfa84c Merge pull request #3612 from Shell32-Natsu/edit-metadata
fix edit commands remove metadata
2021-02-16 15:09:06 -08:00
Phani Teja Marupaka
27f28d5fe0 List setters default false for recurse-subpackages 2021-02-16 14:48:19 -08:00
Donny Xia
c04cf01b45 fix test 2021-02-16 14:31:32 -08:00
Donny Xia
5614852b33 fix edit commands remove metadata 2021-02-16 14:17:09 -08:00
Kubernetes Prow Robot
4f23ae5e1a Merge pull request #3611 from Shell32-Natsu/release-doc
add doc for releasing image
2021-02-16 13:25:06 -08:00
Donny Xia
3bd088a77c update links 2021-02-16 12:57:41 -08:00
Chico Venancio
fe30a9321a Adds repeatbase_test 2021-02-16 16:23:53 -03:00
Donny Xia
c715b82ad7 add doc for releasing image 2021-02-16 11:03:08 -08:00
Kirill Zaborsky
44d308cbba Add name reference for fastcgi-params-configmap
See https://kubernetes.github.io/ingress-nginx/user-guide/fcgi-services/#the-nginxingresskubernetesiofastcgi-params-configmap-annotation
2021-02-15 12:38:41 +03:00
Jeff Regan
c9e7f627fe Update makeKubectlPr.sh 2021-02-13 15:29:39 -08:00
Jeff Regan
00fa7e636c Merge pull request #3604 from monopole/tweakMake
git stTweak make
2021-02-13 14:04:49 -08:00
monopole
c7a504c9cf Add 4.0.1 to example tests and unpin. 2021-02-13 13:51:59 -08:00
Jeff Regan
516ff1fa56 Merge pull request #3603 from monopole/pinForRelease
Pin for kustomize/v4.0.1 release.
2021-02-13 13:07:33 -08:00
monopole
81562a7a37 Pin for kustomize/v4.0.1 release. 2021-02-13 12:55:18 -08:00
Jeff Regan
ba0baa828c Merge pull request #3600 from natasha41575/TestExamplesAgainst4.0
Test examples against 4.0
2021-02-13 12:47:30 -08:00
Jeff Regan
420f03d429 Merge pull request #3601 from monopole/addBuildTest
Hyphenate flags and add more build command tests.
2021-02-13 12:26:48 -08:00
monopole
6cf48442df Hyphenate flags and add more build command tests. 2021-02-13 11:59:08 -08:00
Jeff Regan
8cf7bc67bb Create makeKubectlPr.sh 2021-02-13 07:26:13 -08:00
Natasha Sarkar
48d6af6e38 test examples against kustomize 4.0 2021-02-12 17:08:45 -08:00
Kubernetes Prow Robot
0309a0fb07 Merge pull request #3599 from natasha41575/unpinEverything
Back to development mode; unpin the modules
2021-02-12 15:33:04 -08:00
Natasha Sarkar
d7b29455ab Back to development mode; unpin the modules 2021-02-12 15:09:16 -08:00
Natasha Sarkar
a414f75f1b Merge pull request #3598 from monopole/majorVersionChangeToV4
Increment major version from v3 to v4
2021-02-12 14:40:50 -08:00
monopole
1c3832f897 Increment major version from v3 to v4 2021-02-12 13:26:41 -08:00
Jeff Regan
3ec62c6e26 Merge pull request #3597 from monopole/fixGoSum
Fix crawl/go.sum
2021-02-12 13:20:47 -08:00
Jeff Regan
c7ee4c281e Fix crawl/go.sum 2021-02-12 13:19:37 -08:00
Jeff Regan
471ff0c4bb Merge pull request #3595 from natasha41575/pinToApi
Pin to api v0.8.1
2021-02-12 13:01:53 -08:00
Natasha Sarkar
cd0d416a11 Pin to api v0.8.1 2021-02-12 12:40:49 -08:00
Jeff Regan
4a1a2bfdd8 Merge pull request #3594 from natasha41575/pinToCmdConfig
Pin to cmd/config v0.9.2
2021-02-12 12:33:25 -08:00
Natasha Sarkar
8d75824bb6 Pin to cmd/config v0.9.2 2021-02-12 12:30:01 -08:00
Jeff Regan
232e615afe Merge pull request #3592 from natasha41575/pinToKyaml
Pin to kyaml v0.10.10
2021-02-12 12:20:04 -08:00
Natasha Sarkar
50bfa0564c Pin to kyaml v0.10.10 2021-02-12 12:04:11 -08:00
Jeff Regan
d0b101dc90 Update README.md 2021-02-12 11:24:36 -08:00
Jeff Regan
526ae9ff57 Merge pull request #3590 from monopole/morePublicSutff
Make more high level build methods public.
2021-02-12 11:21:37 -08:00
monopole
b553997447 Make more high level build methods public. 2021-02-12 10:58:20 -08:00
Jeff Regan
66b7c5968b Merge pull request #3589 from monopole/dropEnableKyamlFlag
Delete --enable_kyaml flag.
2021-02-12 10:57:28 -08:00
monopole
003b4946a2 Delete --enable_kyaml flag. 2021-02-12 09:26:36 -08:00
Kubernetes Prow Robot
2d7b6a57ca Merge pull request #3586 from monopole/dropGetter
Drop go-getter use.
2021-02-11 19:14:47 -08:00
Kubernetes Prow Robot
ecda4f423e Merge pull request #3584 from Shell32-Natsu/binarydata
fix merging ConfigMap with binaryData
2021-02-11 17:12:47 -08:00
monopole
9dc4004fbe Tidy go.sum after dropping go-getter. 2021-02-11 16:48:40 -08:00
monopole
a815774e5e Drop the go-getter dependence. 2021-02-11 16:48:39 -08:00
Kubernetes Prow Robot
f170af70fd Merge pull request #3582 from alexal/fix/3575
Kustomize file should be ignored when adding resources and components
2021-02-11 16:28:47 -08:00
Donny Xia
6518393f5d support binaryData merge 2021-02-11 15:34:16 -08:00
Donny Xia
dd72ea1e6a add functions for binaryData 2021-02-11 15:34:16 -08:00
Jeff Regan
dbbe340b4f Simplify gorepomod manager 2021-02-11 15:25:19 -08:00
Jeff Regan
38b30b0edc Merge pull request #3583 from monopole/addKyamlReplacements
Add kyaml replacements to modules with dependency on api.
2021-02-11 15:18:46 -08:00
Jeff Regan
10f9a5afda Merge pull request #3580 from pwittrock/main
Support fnframework to write expected testdata based on observed results
2021-02-11 15:06:38 -08:00
monopole
8a61bff299 Run: gorepomod unpin kyaml api --doIt 2021-02-11 15:05:01 -08:00
monopole
52fbe73d49 Modify gorepomod to unpin conditionally. 2021-02-11 15:04:16 -08:00
Alex Rodin
17ecec2f0a Kustomize file should be ignored when adding resources and components 2021-02-11 15:53:47 -05:00
Jeff Regan
aeb6024e72 Merge pull request #3581 from monopole/dropHashicorpMultierror
Drop hashicorp multierror due to MPL
2021-02-11 12:42:44 -08:00
monopole
e33addc16b Drop hashicorp multierror due to MPL 2021-02-11 12:24:22 -08:00
Phillip Wittrock
2db4121c6a Support fnframework to write expected testdata based on observed results 2021-02-11 09:48:50 -08:00
Li Zhijian
d203c2328a kyaml: set proper GOBIN
Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
2021-02-10 14:07:45 +08:00
Li Zhijian
ec0e42709a functions/examples: set proper GOBIN
Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
2021-02-10 14:07:14 +08:00
Li Zhijian
abae65d8f1 cmd: set proper GOBIN
Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
2021-02-10 14:06:29 +08:00
Li Zhijian
054f18701a Makefile/scripts: check and use GOBIN environment variable first
'go get/install' will install binaries into GOBIN when it's set which is not
always same with GOPATH/bin

Fix below error:
$ hack/testExamplesAgainstKustomize.sh HEAD
Installing kustomize HEAD
On linux, and not on remote CI.  Running expensive tests.
make: Nothing to be done for '/home/lizj/gosrc/bin/helm'.
Removing kustomize HEAD
rm: cannot remove '/home/lizj/gosrc/bin/kustomize': No such file or directory

Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
2021-02-10 14:06:00 +08:00
Jeff Regan
c764bc1618 Merge pull request #3573 from monopole/unpinEverything
Unpin everything, back to development mode.
2021-02-09 17:34:23 -08:00
monopole
2d2fbe9f14 Unpin everything, back to development mode. 2021-02-09 16:42:11 -08:00
Jeff Regan
7073371c1a Merge pull request #3572 from monopole/fix3571
Sort release versions using a version sensitive sort
2021-02-09 16:30:17 -08:00
monopole
dc25a6a1ce Fix #3571 with a -V 2021-02-09 16:28:31 -08:00
Jeff Regan
602ad8aa98 Merge pull request #3569 from monopole/pinToApi
Pin to api v0.8.0
2021-02-09 15:50:17 -08:00
monopole
1fa3b224b1 Pin to api v0.8.0 2021-02-09 14:44:12 -08:00
Jeff Regan
5a328ababf Merge pull request #3568 from monopole/deleteK8sIoDeps
Delete dependence on k8s.io/...
2021-02-09 14:30:54 -08:00
monopole
3ae1aa7cd7 Delete dependence on k8s.io/... 2021-02-09 14:15:54 -08:00
monopole
703fee93af Delete kyaml replacements. 2021-02-09 13:00:50 -08:00
Jeff Regan
3e4a59c1cd Merge pull request #3567 from monopole/unpinEverything
Unpin from api.
2021-02-09 11:46:29 -08:00
monopole
f98edf1b55 Unpin from api. 2021-02-09 11:22:46 -08:00
Jeff Regan
e41d94ddef Merge pull request #3566 from monopole/pinToApi
Pin to api
2021-02-09 11:18:44 -08:00
monopole
0508c89b4b Pin to api 2021-02-09 10:59:18 -08:00
Jeff Regan
e653cffab6 Merge pull request #3565 from monopole/pinToCmdConfig
Pin to cmd/config v0.9.1
2021-02-09 10:38:46 -08:00
monopole
e036f85b71 Pin to cmd/config v0.9.1 2021-02-09 10:17:53 -08:00
Jeff Regan
cee1324d18 Merge pull request #3564 from kubernetes-sigs/pinToKyamlAndCliUtils
Pin to kyaml v0.10.9
2021-02-09 10:14:01 -08:00
monopole
b062ce0f66 Pin to kyaml v0.10.9 2021-02-09 09:57:21 -08:00
Jeff Regan
fbcb15b15f Merge pull request #3563 from monopole/commitGeneratedCode
Commit generated doc changes.
2021-02-09 09:19:32 -08:00
monopole
8eb062637f Commit generated doc changes. 2021-02-09 09:18:31 -08:00
Jeff Regan
2fe85be932 Merge pull request #3557 from natasha41575/PatchMergeIssue
fixed ports merging issue and refactored some kyaml/walk code
2021-02-09 08:48:19 -08:00
Jeff Regan
44edfa87fe Merge pull request #3562 from monopole/changeGenMessage
Fix message in generated code.
2021-02-09 08:08:04 -08:00
monopole
bbccee0219 Fix message in generated code. 2021-02-09 07:34:32 -08:00
Jeff Regan
7cdc6cbe2f Merge pull request #3561 from monopole/unpin
Unpin; back to development mode.
2021-02-09 07:13:20 -08:00
monopole
264bfa8998 Unpin; back to development mode. 2021-02-09 06:54:18 -08:00
Jeff Regan
041181afe4 Merge pull request #3560 from monopole/dropQuantityProto
Drop unused quantity protobuf - avoid bad init.
2021-02-09 06:36:56 -08:00
monopole
5db79285a7 Drop unused quantity protobuf - avoid bad init. 2021-02-09 06:19:13 -08:00
Jeff Regan
556692c9f5 Merge pull request #3556 from monopole/dropKubeOpenAi
Drop dependence on k8s.io/kube-openapi
2021-02-08 18:01:02 -08:00
Natasha Sarkar
71f4cecb4c fixed ports merging issue and refactored some kyaml.walk code 2021-02-08 17:49:10 -08:00
monopole
d4d5fca2a5 Drop dependence on k8s.io/kube-openapi 2021-02-08 17:31:54 -08:00
Jeff Regan
811e1dca05 Merge pull request #3554 from monopole/pinToCmdConfig
Pin to cmd/config v0.9.0
2021-02-08 16:46:36 -08:00
monopole
09bc6e76b1 Pin to cmd/config v0.9.0 2021-02-08 16:30:57 -08:00
Jeff Regan
065b14c5c5 Merge pull request #3553 from monopole/pinToKyamlAndCliUtils
Pin to kyaml v0.10.8
2021-02-08 16:24:49 -08:00
monopole
adb2f2237a Pin to kyaml v0.10.8 2021-02-08 16:09:17 -08:00
Jeff Regan
024bbd0777 Merge pull request #3549 from monopole/removeApiMachDep
Remove grep's dependence on apimachinery.
2021-02-08 15:34:53 -08:00
monopole
ca1929abfb Remove grep's dependence on apimachinery. 2021-02-08 15:16:46 -08:00
Jeff Regan
a13ef4da65 Update Makefile 2021-02-08 15:14:47 -08:00
Jeff Regan
81ec59fa62 Update Makefile 2021-02-08 14:58:31 -08:00
Jeff Regan
075a2d6c0f Merge pull request #3552 from monopole/tweakCopier
Fix prefix bug in copier.
2021-02-08 14:45:12 -08:00
monopole
1df430255a Fix prefix bug in copier. 2021-02-08 14:39:25 -08:00
Jeff Regan
94d06e1e18 Merge pull request #3550 from Shell32-Natsu/value-add
fix forward slash in value add path
2021-02-08 13:39:58 -08:00
Jeff Regan
c3b240639d Merge pull request #3551 from monopole/fixKyamlMake
Normalize deps in kyaml makefile.
2021-02-08 13:34:40 -08:00
monopole
4de6db3d59 Normalize deps in makefile. 2021-02-08 13:21:42 -08:00
Donny Xia
58216d1d33 fix forward slash in value add path 2021-02-08 13:11:24 -08:00
Jeff Regan
4c456d60a4 Merge pull request #3548 from monopole/moveCopier
Move the k8s-related code generator.
2021-02-08 12:49:41 -08:00
monopole
582bc4de01 Move the k8s code generator. 2021-02-08 12:32:13 -08:00
Li Zhijian
a167084ccf api/internal/crawl/index/elasticsearch: Fix ineffectual assignment to err
Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
2021-02-08 13:55:17 +08:00
Jeff Regan
a3a11bf3f4 Merge pull request #3545 from monopole/testExamplesAgainstLatestReleases
Test examples against latest releases.
2021-02-07 10:52:26 -08:00
monopole
4e96502ec6 Test examples against latest releases. 2021-02-07 10:31:34 -08:00
Jeff Regan
1ae8303bdc Merge pull request #3544 from monopole/pinToApi
Pin to api v0.7.3
2021-02-07 08:56:03 -08:00
monopole
41df2bed1f Pin to api v0.7.3 2021-02-07 08:40:52 -08:00
Jeff Regan
1f1304194d Update cloudbuild.sh 2021-02-07 07:57:10 -08:00
Jeff Regan
4157933c8d Update cloudbuild.sh 2021-02-07 07:47:06 -08:00
Jeff Regan
a79253e02f Merge pull request #3543 from monopole/releaserUpdates
Use goreleaser/v0.155.0, --parallelism 4
2021-02-07 07:21:14 -08:00
monopole
3b35b121b3 Use goreleaser/v0.155.0, --parallelism 4 2021-02-07 07:19:39 -08:00
Jeff Regan
3c94d20599 Deleting goarch=arm build, leaving arm64
Hitting hard step limit of 10m
Increasing timeout field in cloudbuild.yaml past 10m seems to have no effect.
Maybe break goreleaser step into multiple substeps?
2021-02-06 09:45:01 -08:00
Jeff Regan
1faeb91cc4 Set build timeout=800s, goreleaser timeout =720s 2021-02-06 09:16:02 -08:00
Jeff Regan
9f1ef993a1 Set FlagEnableKyamlDefaultValue = true 2021-02-06 08:31:12 -08:00
Jeff Regan
55d8cb3d3a Merge pull request #3541 from monopole/pinToApi
Pin to api v0.6.9
2021-02-06 08:16:35 -08:00
monopole
a684592639 Pin to api v0.6.9 2021-02-06 07:59:54 -08:00
Jeff Regan
386d10834b Set FlagEnableKyamlDefaultValue = false 2021-02-06 07:16:55 -08:00
Jeff Regan
af32126e80 Merge pull request #3540 from monopole/pinToCmdConfig
Pin to cmd/config v0.8.9
2021-02-05 22:01:41 -08:00
monopole
b0cfa15b9c Pin to cmd/config v0.8.9 2021-02-05 21:40:42 -08:00
Jeff Regan
62e7df6812 Merge pull request #3539 from monopole/pinToKyamlAndCliUtils
Pin to kyaml v0.10.7 and cli-utils v0.23.1
2021-02-05 21:29:06 -08:00
monopole
c077ed4b58 Pin to kyaml v0.10.7 and cli-utils v0.23.1 2021-02-05 20:34:05 -08:00
Jeff Regan
156beb300c Update README.md 2021-02-05 20:23:59 -08:00
Jeff Regan
25b02d2d6c Merge pull request #3538 from monopole/fixnits
Make starlarkmixer plugin module name match path.
2021-02-05 18:07:34 -08:00
monopole
781098843e Make starlarkmixer plugin module name match path. 2021-02-05 17:57:12 -08:00
Jeff Regan
af3ffa7059 Merge pull request #3493 from natasha41575/UseIntermediateName
Allow references to intermediate IDs after multiple name transformations
2021-02-05 16:31:31 -08:00
Donny Xia
9d7b8952a0 Merge pull request #3535 from MaXinjian/tmpfile
Cleanup tempfiles introduced in confirmeddir_test.go
2021-02-05 12:57:05 -08:00
Natasha Sarkar
cb400c895e added test to check for resources with the same name in different layers 2021-02-05 12:35:59 -08:00
Ma Xinjian
9a8dcf6a8e Cleanup tempfiles introduced in confirmeddir_test.go
Signed-off-by: Ma Xinjian <maxj.fnst@cn.fujitsu.com>
2021-02-05 13:26:58 +08:00
Natasha Sarkar
384b71b5f5 Allow references to intermediate names 2021-02-04 20:38:08 -08:00
Kubernetes Prow Robot
4345cd2ade Merge pull request #3534 from KnVerey/starlark_genformer
Fix function/exec transformer plugin ability to add/remove resources
2021-02-04 19:54:51 -08:00
Katrina Verey
1460d13d50 Allow exec and function transformers to delete resources 2021-02-04 13:01:09 -08:00
Katrina Verey
97a2b15be6 Allow exec and function transformers to generate resources 2021-02-04 13:01:09 -08:00
Katrina Verey
f927cf0b8e Regression test for inability to add resources in function-based transfomer 2021-02-04 13:01:09 -08:00
Jeff Regan
cbb121e651 Merge pull request #3533 from monopole/updateNRtest
Update namerefence tests for apimachinery code path.
2021-02-04 12:15:17 -08:00
monopole
447b315a61 Update namerefence tests for apimachinery code path. 2021-02-04 12:14:16 -08:00
Kubernetes Prow Robot
b3cb61b80f Merge pull request #3532 from monopole/commandsOption3
Expose some top level kustomize commands.
2021-02-04 10:02:26 -08:00
monopole
b9f05dd357 Expose some top level kustomize commands.
The PR exposes some of the top level kustomize commands
(especially `build`) for reuse in other command line tools
(expecially `kubectl`, see #1500).

This PR represents option 3 from the following list of ways
this exposure could be arranged.

1. Expose the commands in the `api` module.

```
REPO/api/go.mod
REPO/api/builtins
REPO/api/commands <- new
REPO/api/...
```

Disadvantage: This would make `api` module depend on cobra.
That's bad for clients that want to depend on the api, but
want to write their own commands at their own version of
cobra.  The `api` module shouldn't depend on UX libraries
like cobra.

2. Expose the commands in their own `commands` module.

They'd appear alongside `api`, e.g. `

```
REPO/api/go.mod
REPO/api/builtins
REPO/api/...
REPO/commands/go.mod
REPO/commands/build
REPO/commands/edit
REPO/commands/...
```

Advantage: The commands would be consumed by the kustomize
binary and the kubectl binary in the same way.

Disadvantage: The kustomize binary module and the commands
module could evolve separately with their own version
numbers, creating confusion.

3. Expose the commands in the existing `kustomize` module

```
REPO/api/go.mod
REPO/api/builtins
REPO/api/...
REPO/kustomize/go.mod
REPO/kustomize/main.go
REPO/kustomize/commands/build
REPO/kustomize/commands/edit
REPO/kustomize/commands/...
```

Outside users, e.g. kubectl, could then

```
import sigs.k8s.io/kustomize/kustomize/v3/commands/build
```

and hopefully still get the `main` package
as they do now via:

```
go get sigs.k8s.io/kustomize/kustomize/v3
```

Advantage: 1) The kustomize binary ships at the same version
as the commands - which makes sense as the binary's
_version_ refers to how the CLI operates (command names,
flags, etc.).  This makes it easy to related the version of
a kustomize binary with the version of commands running in
some other CLI binary.  2) The path to the kustomize binary
doesn't change.

Disadvantage: It's an atypical Go module arrangement.
Usually `main` packages live as leaves under a directory
called `cmd` inside a module, rather than at the _top_ of
the module.  This might cause some problems.  If so, we can
go with option 4.

4. Same as 3, but move `main.go` (the `main` package) down one step.

```
REPO/api/go.mod
REPO/api/builtins
REPO/api/...
REPO/kustomize/go.mod
REPO/kustomize/cmd/main.go
REPO/kustomize/commands/build
REPO/kustomize/commands/edit
REPO/kustomize/commands/...
```
2021-02-04 08:35:01 -08:00
Jeff Regan
1ee16d9f52 Merge pull request #3525 from natasha41575/RefactorNameTransformers
Refactored resource to store all previous names and namespaces
2021-02-03 16:53:16 -08:00
Natasha Sarkar
43157f5d35 cleaned up resource refactoring 2021-02-03 14:30:25 -08:00
Natasha Sarkar
cd918483f9 removed some prefix methods from resource 2021-02-03 12:02:12 -08:00
Natasha Sarkar
f71854a0c8 Refactored resource to store all previous names and namespaces 2021-02-03 12:01:09 -08:00
Kubernetes Prow Robot
6246262965 Merge pull request #3529 from monopole/fix3489
Fix 3489
2021-02-03 11:04:28 -08:00
monopole
d3ea87220b Fix Issue 3489. 2021-02-03 10:49:17 -08:00
Jeff Regan
61daea0202 Merge pull request #3245 from natasha41575/UseOpenApiVersions
Use `openApi` field in kustomization file to specify OpenAPI schema version
2021-02-03 10:35:08 -08:00
Jeff Regan
a54cd12b39 Delete fixgomod.sh 2021-02-03 10:20:28 -08:00
Kubernetes Prow Robot
11ce6363b4 Merge pull request #3528 from monopole/refactorNameref
Refactor nameref for readability.
2021-02-03 10:16:29 -08:00
monopole
4de26ccf9d Refactor nameref for readability. 2021-02-02 19:02:41 -08:00
Jeff Regan
7801830152 Merge pull request #3527 from monopole/addTests
Add tests in support of Issue 3489.
2021-02-02 18:53:31 -08:00
monopole
aae2be1a79 Add tests in support of Issue 3489. 2021-02-02 18:35:46 -08:00
Kubernetes Prow Robot
79e15c05d5 Merge pull request #3522 from Shell32-Natsu/chart-generator
fix relative path to values file
2021-02-02 15:44:28 -08:00
Donny Xia
507244e6f8 fix relative path to values file 2021-02-01 13:55:48 -08:00
Jeff Regan
3892e3c910 Merge pull request #3519 from monopole/fieldspectest
More fieldspec filter tests and comments.
2021-01-31 20:01:47 -08:00
monopole
dcb26d0901 More fieldspec tests. 2021-01-31 19:08:48 -08:00
Jeff Regan
f5f1a15226 Merge pull request #3518 from monopole/nits
Improve name reference transformer testing.
2021-01-31 09:04:45 -08:00
monopole
64644643d4 Improve name reference transformer testing. 2021-01-31 08:40:47 -08:00
Jeff Regan
4d1eebbb82 Merge pull request #3517 from monopole/pathSplitter
Expose smart path splitter as a utility.
2021-01-31 07:56:42 -08:00
monopole
b3a9314e27 Expose smart path splitter as a utility. 2021-01-31 06:45:04 -08:00
Kubernetes Prow Robot
86168cebbc Merge pull request #3514 from natasha41575/TestForPortsIssue
Add test for ports issue #3513
2021-01-29 12:51:49 -08:00
Natasha Sarkar
57a53797d3 Add test for ports issue #3513 2021-01-29 11:10:00 -08:00
Kubernetes Prow Robot
f5beffe394 Merge pull request #3512 from monopole/improveNameRefTests
Add test for issue 3489 and improve error messages.
2021-01-29 10:49:41 -08:00
monopole
4287e28ff4 Add test for issue 3489 and improve error messages. 2021-01-29 06:55:23 -08:00
Jeff Regan
a5cdd98414 Merge pull request #3498 from piyushpgupta/patch-1
Update README.md
2021-01-27 17:20:22 -08:00
Piyush Gupta
16a49c50c4 Update README.md 2021-01-28 09:17:39 +09:00
Piyush Gupta
a6f29f2bf7 Update README.md 2021-01-28 09:17:10 +09:00
Piyush Gupta
22fcf3b3fa Update README.md 2021-01-28 09:16:28 +09:00
Piyush Gupta
a31b846fa5 Update README.md 2021-01-28 09:10:59 +09:00
Jeff Regan
22fb23071b Merge pull request #3483 from msk-/master
Bug: configMapRefs in patches are not resolved correctly in diamond structure
2021-01-27 15:43:49 -08:00
Jeff Regan
382cf5c2e0 Merge pull request #3506 from natasha41575/FixSmpDirectiveWhenElementNotFound
$patch:delete should not add elements when element is not found
2021-01-27 11:24:38 -08:00
Jeff Regan
8d4508a041 Merge pull request #3484 from kubernetes-sigs/issue3377
Demonstrate issue #3377 is fixed.
2021-01-26 16:53:58 -08:00
Natasha Sarkar
4d5657f037 smpdirectives shouldn't add elements when element isn't found 2021-01-26 16:43:30 -08:00
Natasha Sarkar
5958edda14 don't merge patches until they are applied 2021-01-26 16:43:15 -08:00
Natasha Sarkar
48676fe34b updated patch delete test 2021-01-26 16:42:59 -08:00
Jeff Regan
a8278b6da9 Merge pull request #3495 from MaXinjian/install
Add support to install kustomize to specified directory
2021-01-26 12:30:46 -08:00
Kubernetes Prow Robot
31d6e24fa4 Merge pull request #3491 from Shell32-Natsu/error-message
add error message for AsYAML
2021-01-26 12:26:30 -08:00
Jeff Regan
25e11e9020 Update install_kustomize.sh 2021-01-26 12:15:20 -08:00
Jeff Regan
d8e2a76ef3 Merge pull request #3499 from MaXinjian/validator
Fix wrong Validator dir
2021-01-26 12:01:41 -08:00
Jeff Regan
cff7bd4eb2 Merge pull request #3496 from msk-/use-usr-bin-env-bash-for-scripts
Use `/usr/bin/env bash` instead of `/bin/bash` in scripts
2021-01-26 12:01:01 -08:00
Kubernetes Prow Robot
58db58202c Merge pull request #3500 from Shell32-Natsu/ingress-name-ref
support anchor in filedspec
2021-01-26 11:48:31 -08:00
Donny Xia
fc29d7e108 Merge pull request #3503 from dimw/3487-set-image-tag-name
Add support for setting new tag while preserving the current name
2021-01-26 10:32:33 -08:00
dimw
ae060cc225 Add documentation/help on preserving the digest
Issue: #3487
2021-01-25 22:06:44 +01:00
dimw
9b4fdcf35a Add support for setting the name while keeping the digest
- And the other way around

Issue: #3487
2021-01-25 21:38:28 +01:00
dimw
bb2d63ab58 Use raw string to avoid double escape
Issue: #3487
2021-01-25 21:15:05 +01:00
dimw
b5012385c8 Add support for setting new tag while preserving the current name
- As well as setting new name while keeping the tag

Issue: #3487
2021-01-25 15:31:19 +01:00
Natasha Sarkar
659a7de8f9 edited kyaml libraries to use the openapi field from the kustomization file 2021-01-22 16:07:18 -08:00
Natasha Sarkar
866dbf2017 added an openapi field to the kustomization file 2021-01-22 16:06:57 -08:00
Donny Xia
ef89df6123 support anchor in filedspec 2021-01-22 11:01:07 -08:00
Ma Xinjian
97f23966af Fix wrong Validator dir
Signed-off-by: Ma Xinjian <maxj.fnst@cn.fujitsu.com>
2021-01-22 13:54:34 +08:00
Piyush Gupta
5059033b13 Update README.md
Fixed the typo #
2021-01-21 22:41:54 +09:00
msk-
d91e8af702 Use /usr/bin/env bash instead of /bin/bash for scripts to support more systems 2021-01-21 10:43:18 +00:00
msk-
1bef8c4cdd Added ASCII art per PR feedback 2021-01-21 10:13:42 +00:00
msk-
9b87f78511 Modified test name per PR feedback 2021-01-21 10:04:19 +00:00
msk-
eda827c317 Added line break to all WriteK, WriteF calls per PR feedback 2021-01-21 10:03:18 +00:00
Ma Xinjian
be57e1f6c2 Add support to install kustomize to specified directory
Signed-off-by: Ma Xinjian <maxj.fnst@cn.fujitsu.com>
2021-01-21 15:59:04 +08:00
Kubernetes Prow Robot
021c3ce3fc Merge pull request #3494 from KnVerey/template-cmd-without-cobra
[kyaml] Framework/TemplateCommand usability improvements
2021-01-20 16:49:01 -08:00
Katrina Verey
4f184e8ce3 Add validation hook to template command execution 2021-01-20 15:53:46 -08:00
Katrina Verey
2e0d6d42bf Improve framework usability without cobra 2021-01-20 15:53:10 -08:00
Donny Xia
6cf6eb9f76 use reource.AsYAML in resWrangler.AsYAML 2021-01-20 12:51:25 -08:00
Donny Xia
ffed8f1430 add error message for AsYAML 2021-01-20 10:40:59 -08:00
monopole
3d17503329 Demonstrate that #3377 is fixed. 2021-01-19 19:06:36 -08:00
msk-
7ac37867dc tidy-up, added desired behaviour 2021-01-19 18:00:02 +00:00
msk-
d8f2d2256d Fixed test 2021-01-19 17:57:42 +00:00
msk-
463b776486 Initial test commit 2021-01-19 17:41:44 +00:00
Jeff Regan
d28ce28130 Merge pull request #3478 from kubernetes-sigs/testAgainst3.9.2
Test examples against v3.9.2 and v3.8.9
2021-01-17 11:14:46 -08:00
monopole
4f72faeecb Test examples against v3.9.2 and v3.8.9 2021-01-17 10:54:13 -08:00
Jeff Regan
29814b556b Update README.md 2021-01-17 10:25:19 -08:00
Jeff Regan
d94ed369fa Merge pull request #3477 from kubernetes-sigs/unpinEverything
Back to development mode; unpin the modules
2021-01-17 10:25:10 -08:00
monopole
0cf18987d7 Back to development mode; unpin the modules 2021-01-17 10:10:12 -08:00
Jeff Regan
a6374db2cb Update README.md 2021-01-17 10:09:08 -08:00
Jeff Regan
e98eada736 Merge pull request #3476 from kubernetes-sigs/pinToApi
Pin to api v0.7.2
2021-01-17 09:36:37 -08:00
monopole
8a65ece956 Pin to api v0.7.2 2021-01-17 09:19:41 -08:00
Jeff Regan
4cdc3b0bad Merge pull request #3475 from kubernetes-sigs/pinToCmdConfig
Pin to cmd/config v0.8.8
2021-01-17 09:09:20 -08:00
monopole
40bf89abcd Pin to cmd/config v0.8.8 2021-01-17 08:40:13 -08:00
Jeff Regan
7f548eddd0 Merge pull request #3474 from kubernetes-sigs/pinToKyamlAndCliUtils
Pin to kyaml v0.10.6 and cli-utils v0.22.4
2021-01-17 07:17:43 -08:00
monopole
86e9983bb7 Pin to kyaml v0.10.6 and cli-utils v0.22.4 2021-01-17 06:55:10 -08:00
Jeff Regan
cbbcfde99d Update multiplepatch_test.go 2021-01-16 20:43:57 -08:00
Jeff Regan
304a9e57ee Update factory_test.go 2021-01-16 20:36:46 -08:00
Jeff Regan
f23f26aa05 Update factory_test.go 2021-01-16 20:24:39 -08:00
Jeff Regan
720857623f Merge pull request #3473 from monopole/doImportantStuff
Fix unfiled bug in port replacement where ports were being quoted.
2021-01-16 18:02:06 -08:00
monopole
065c2b861a Fix unfiled bug; don't quote port numbers. 2021-01-16 16:56:48 -08:00
monopole
2a16af80bf Simplify, document and add more tests to var replacement. 2021-01-16 16:48:26 -08:00
Jeff Regan
81d324c68c Merge pull request #3472 from monopole/issue3449
Reproduce issue #3449
2021-01-16 16:47:45 -08:00
monopole
b8702561ef Add test for issue 3449 2021-01-16 16:45:13 -08:00
Jeff Regan
ea039b36bc Merge pull request #3471 from monopole/mergeExpansionRefvar
Merge expansion package into refvar package.
2021-01-16 13:54:32 -08:00
monopole
561cef1d5c Merge expansion package into refvar package. 2021-01-16 13:50:56 -08:00
Jeff Regan
62c5e424a6 Merge pull request #3470 from monopole/annotateIssue3304
Annotate code with decisions on issue 3304 in kyaml conversion
2021-01-16 09:09:49 -08:00
monopole
45b1bf17d3 Annotate decisions on issue 3304 in api. 2021-01-16 08:08:52 -08:00
monopole
11dce34407 Annotate decisions on issue 3304 in plugins. 2021-01-16 08:08:39 -08:00
Kubernetes Prow Robot
550a89295a Merge pull request #3469 from monopole/labelAndAnnotationQuoting
Always quote non-string values in labels and annotations
2021-01-15 18:43:43 -08:00
monopole
8083b3607f Harden anno transformer test. 2021-01-15 17:37:46 -08:00
monopole
cb42142161 Fix api tests that accomodated bad label and anno quoting. 2021-01-15 17:37:46 -08:00
monopole
cb59e0ef5f Always tag label and annotations values as strings. 2021-01-15 17:37:46 -08:00
Jeff Regan
1a4a9fcdaf Update go.mod 2021-01-15 17:33:00 -08:00
Kubernetes Prow Robot
eb8dc5e20a Merge pull request #3462 from mikhail-nikitin/master
$patch: delete of not existing elements
2021-01-15 14:23:43 -08:00
Jeff Regan
0fb30a1010 In plugin tests, yell FAILURE on failure. 2021-01-15 13:58:09 -08:00
Jeff Regan
fdfdfa9e4d Update go.mod 2021-01-15 13:56:18 -08:00
Jeff Regan
6042aca7a4 Update CalvinDuplicator.go 2021-01-15 13:33:46 -08:00
Jeff Regan
94962c8bac Update CalvinDuplicator_test.go 2021-01-15 13:10:40 -08:00
Mikhail Nikitin
f6ddea435c Make test file paths consistent and relative
Signed-off-by: Mikhail Nikitin <mikhail.nikitin@ispringsolutions.com>
2021-01-15 22:50:23 +03:00
Jeff Regan
a9d4b7615f Merge pull request #3466 from monopole/renameAnnotations
Rename id annotations to build annotations.
2021-01-15 11:27:49 -08:00
Jeff Regan
822cac26f9 Merge pull request #3467 from monopole/calvinDuplicator
Add calvin duplicator example plugin.
2021-01-15 07:58:11 -08:00
monopole
97eedc8a43 Add calvin duplicator example plugin. 2021-01-15 07:22:46 -08:00
monopole
2cb972de3b Rename id annotations to build annotations. 2021-01-15 06:43:13 -08:00
Jeff Regan
79d0d6b5e1 Merge pull request #3465 from monopole/pdbTest
Add test covering pod disruption budget treatment.
2021-01-15 06:38:38 -08:00
monopole
fabaf35c72 Add test covering pod disruption budget treatment. 2021-01-15 06:09:52 -08:00
Mikhail Nikitin
e13f8803eb Add test case of deleting not existing elements 2021-01-15 00:08:49 +03:00
Jeff Regan
64ffbcb15d Merge pull request #3461 from monopole/anotherTest
Add another test covering fix of 3412
2021-01-14 11:52:56 -08:00
monopole
b41df2293b Add another test covering fix of 3412 2021-01-14 11:32:34 -08:00
Kubernetes Prow Robot
e3fcec122a Merge pull request #3460 from monopole/fix3412
Fix 3412, retaining quotes in configmap data fields
2021-01-14 11:25:32 -08:00
monopole
1edf9b630c Update configmap test with quotes fixed. 2021-01-14 11:01:37 -08:00
monopole
7c6bf2e21d When merging configmaps, retain proper quoting. 2021-01-14 11:01:06 -08:00
monopole
b3fc306f6a Move some code to make it reusable without import cycles. 2021-01-14 10:29:51 -08:00
Jeff Regan
e92d048af2 Merge pull request #3441 from natasha41575/namePrefixNamespaceBehavior
Update name references by checking both the original and current namespaces
2021-01-13 16:21:05 -08:00
Kubernetes Prow Robot
f76059b824 Merge pull request #3454 from monopole/evenMoreTests
Add more tests and explain some quoting behavior.
2021-01-13 16:05:03 -08:00
monopole
bb41d018b5 Add more tests and explain some strange quotes. 2021-01-13 15:49:12 -08:00
Kubernetes Prow Robot
cf8815b0a0 Merge pull request #3453 from Shell32-Natsu/wnode-field-value
fix GetFieldValue cannot handle slice index
2021-01-13 15:07:03 -08:00
Donny Xia
64beee22e9 fix GetFieldValue cannot handle slice index 2021-01-13 14:14:01 -08:00
Jeff Regan
79afd219a5 Merge pull request #3450 from monopole/anotherTest
Add a test that only loads an annotated resource.
2021-01-13 11:27:14 -08:00
monopole
c68cf40d75 Add a test that only loads an annotated resource. 2021-01-13 10:56:50 -08:00
Kubernetes Prow Robot
c7337a7d87 Merge pull request #3445 from KnVerey/resource_list_empty_items
[kio] Unwrap ResourceList with a functionConfig but no items
2021-01-12 17:04:35 -08:00
Jeff Regan
875e265e5d Merge pull request #3372 from natasha41575/AddNameAnnotations
Refactor resource to use annotations in the yaml instead of fields in resource struct
2021-01-12 16:38:48 -08:00
Katrina Verey
bdbfb28139 Unwrap ResourceList with a functionConfig but no items 2021-01-12 16:13:40 -08:00
Natasha Sarkar
d54bc674f2 Update name references by checking both the original and current namespaces 2021-01-11 18:08:52 -08:00
Natasha Sarkar
bd4580d73a Manage name changes (prefix/suffix) via YAML annotations rather than via in-memory-only fields. 2021-01-11 13:08:45 -08:00
Kubernetes Prow Robot
ea5d08bac5 Merge pull request #3438 from monopole/fix3424
Fix 3424 by avoiding a JSON round trip
2021-01-11 10:18:24 -08:00
monopole
14a1a0e4a8 Fix 3424 by avoiding a JSON round trip 2021-01-10 20:39:01 -08:00
Jeff Regan
497e8038a3 Merge pull request #3439 from monopole/clarifyErrorMessage
Clarify var-related error message.
2021-01-10 20:38:39 -08:00
monopole
44b5acad51 Clarify var-related error message. 2021-01-10 20:35:55 -08:00
Jeff Regan
e5e19f7c09 Merge pull request #3431 from Shell32-Natsu/newline
keep \n in the end of resource yaml
2021-01-10 12:51:36 -08:00
Jeff Regan
a03843dfc7 Merge pull request #3437 from monopole/regressionTestsForKyaml
In kyaml, loosen interpretation of string node and add tests.
2021-01-10 12:28:30 -08:00
monopole
b7cce27d40 In kyaml, loosen interpretation of string node and add tests. 2021-01-10 12:08:50 -08:00
Jeff Regan
126f5481f3 Merge pull request #3436 from monopole/addTestsAroundVarRefTransformer
Add var ref replacement tests and more doc.
2021-01-10 09:38:30 -08:00
monopole
30dcf38609 Add var ref replacement tests and more doc. 2021-01-10 09:16:52 -08:00
Jeff Regan
1a2779b2c3 Merge pull request #3434 from monopole/reduceComplexityInNameReferenceTransformer
Reduce complexity in NameReferenceTransformer.
2021-01-10 07:12:23 -08:00
monopole
658b62c6f1 Reduce complexity in NameReferenceTransformer. 2021-01-10 06:56:06 -08:00
Jeff Regan
cf0bb49610 Merge pull request #3433 from monopole/anotherTowards3412
Improve handling of empty resource maps.
2021-01-09 07:20:19 -08:00
monopole
c2fbb709da Don't swallow error in SM patch and use new RNode Map method. 2021-01-09 07:00:21 -08:00
monopole
1a002005c1 Add RNode.Map method and test to help decoding. 2021-01-09 06:57:01 -08:00
Jeff Regan
4f468fcc90 Merge pull request #3432 from monopole/towards3412
Short circuit anno/label transformer for performance.
2021-01-08 18:53:47 -08:00
monopole
769f65d6c4 Short circuit anno/label transformer for performance. 2021-01-08 18:02:58 -08:00
Donny Xia
378eaedc82 keep \n in the end of resource yaml 2021-01-08 15:36:36 -08:00
Jeff Regan
6f2f401f6b Merge pull request #3428 from monopole/confineApplyToJson
Confine calls to ApplyToJSON.
2021-01-07 20:53:55 -08:00
monopole
614e853db3 Confine calls to ApplyToJSON. 2021-01-07 20:31:10 -08:00
Jeff Regan
33be04db45 Merge pull request #3427 from monopole/avoidCycle
Move plugin lister to avoid import cycle.
2021-01-07 19:27:45 -08:00
monopole
8c6a9f6495 Move plugin lister to avoid import cycle. 2021-01-07 18:46:04 -08:00
Jeff Regan
03b2fff0ee Merge pull request #3425 from monopole/issue3424
Add test for issue 3424
2021-01-07 15:55:47 -08:00
monopole
69cade143f Add test for issue 3424 2021-01-06 16:23:12 -08:00
Jeff Regan
90f45651d1 Merge pull request #3416 from HansK-p/Fix-link-to-lugins-doc
Updated link to Kustomize plugins documentation
2021-01-06 15:49:19 -08:00
Hans Kristian Nordengen
1b740034f7 Updated link to Kustomize plugins documentation 2021-01-03 19:44:32 +01:00
Jeff Regan
a2d8e686de Merge pull request #3411 from monopole/unpinApiKyamlCmdConfig
Unpin kyaml, cmd/config, api
2020-12-29 18:17:48 -08:00
jregan
ce2ab487a5 Unpin kyaml, cmd/config, api 2020-12-29 16:18:12 -08:00
Jeff Regan
7439f1809e Merge pull request #3410 from monopole/pinToApiv0.7.1
Pin to api/v0.7.1 (--enableKyaml=true)
2020-12-29 09:43:42 -08:00
jregan
6977c83a83 Pin to api/v0.7.1 (--enableKyaml=true) 2020-12-29 09:24:25 -08:00
Jeff Regan
7b9eb05058 Merge pull request #3408 from monopole/enableKyamlForApiv0.7.1
Set FlagEnableKyamlDefaultValue = true
2020-12-29 08:36:33 -08:00
jregan
e2806a09fd Set FlagEnableKyamlDefaultValue = true 2020-12-29 08:17:45 -08:00
Jeff Regan
f30fea4c07 Merge pull request #3407 from monopole/pinToApiv0.6.8
Pin to api/v0.6.8
2020-12-29 07:44:13 -08:00
jregan
8732671919 Pin to api/v0.6.8 2020-12-29 07:27:11 -08:00
Jeff Regan
07cada36fa Merge pull request #3406 from monopole/pinToCmdConfig_v0.8.7
Pin to cmd/confg v0.8.7
2020-12-29 07:11:12 -08:00
jregan
0d6b232b49 Pin to cmd/confg v0.8.7 2020-12-29 06:55:07 -08:00
Jeff Regan
61455fe489 Merge pull request #3404 from monopole/pinKyamlv0.10.5
Pin to kyaml v0.10.5
2020-12-28 20:50:59 -08:00
jregan
c63ed033ad Pin to kyaml v0.10.5
ALLOW_MODULE_SPAN
2020-12-28 20:30:22 -08:00
Jeff Regan
455bd0c563 Merge pull request #3403 from monopole/betterPin
Unpin versioned and unversioned pins.
2020-12-28 18:11:39 -08:00
jregan
9ad4b1ddca Unpin versioned and unversioned pins. 2020-12-28 18:10:53 -08:00
Jeff Regan
d529eb8777 Merge pull request #3402 from monopole/upgradeGopkg.in_yaml.v3
Pin to gopkg.in/yaml.v3 v3.0.0-20200313102051
2020-12-28 18:02:41 -08:00
jregan
f7b2f0c067 Pin to gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
This is the last commit in yaml.v3 before

  ae27a74434

which changed the indentation of sequence.

That change has has large downstream impact on tests in the kustomize
repo.  To upgrade beyond this point in yaml.v3 means many changes to
indentation in "expected" values in tests.  That should be done in a
PR dedicated to that purpose, after specific consideration the change.

ALLOW_MODULE_SPAN
2020-12-28 17:28:01 -08:00
Jeff Regan
ff6b337ebe Update README.md 2020-12-28 14:06:43 -08:00
Jeff Regan
76f05f3a40 Update cli-utils release instructions. 2020-12-28 13:57:21 -08:00
Jeff Regan
d181a73f56 Set FlagEnableKyamlDefaultValue = false for v3.8.9
In the 3.8 branch, this is false.  In the 3.9 branch, it's true.
2020-12-28 13:32:56 -08:00
Jeff Regan
979fe3b457 Merge pull request #3401 from monopole/close3393
Regression coverage for configmap generation.
2020-12-28 13:09:37 -08:00
Kubernetes Prow Robot
bec45093e2 Merge pull request #3400 from monopole/dropClose
Drop channel close in timed call.
2020-12-28 10:06:28 -08:00
jregan
c113c41c9c Regression coverage for configmap generation. 2020-12-28 09:53:34 -08:00
jregan
99c9edfc3d Drop close in timed call. 2020-12-28 08:31:42 -08:00
Jeff Regan
cde6a5741e Merge pull request #3399 from fwolter/patch-1
Fix typo
2020-12-28 05:40:49 -08:00
Fabian Wolter
a315eb56ec Fix typo 2020-12-27 20:11:30 +01:00
Kubernetes Prow Robot
90654b39bf Merge pull request #3398 from monopole/close3343
Close 3343
2020-12-27 07:30:27 -08:00
jregan
24c4c66403 Close 3343 2020-12-26 10:43:58 -08:00
Jeff Regan
2b5029952c Merge pull request #3397 from monopole/towards3304
Drop another difference between kyaml and apimachinery
2020-12-26 10:32:50 -08:00
jregan
6a3bb5df44 Drop another difference between kyaml and apimachinery 2020-12-26 10:12:33 -08:00
Jeff Regan
d9623ab307 Merge pull request #3382 from monopole/emptyMapMania
Isolate tests related to #3396
2020-12-26 09:44:21 -08:00
jregan
dd1df5a30e Remaining problems. 2020-12-26 09:28:01 -08:00
Jeff Regan
0e13a9c02b Merge pull request #3395 from monopole/isolateEmptyDirTests
Isolate patch conflation problem to one test.
2020-12-26 08:58:52 -08:00
jregan
eb26d79fa0 Isolate patch conflation problem to one test.
See #3394
2020-12-26 08:41:48 -08:00
Jeff Regan
7f8da385c0 Merge pull request #3392 from monopole/isolateQuoting
Isolate scalar int and bool quoting oddities to one test set.
2020-12-23 18:26:52 -08:00
jregan
1426137883 Isolate scalar quoting oddities to one test set.
The apimachinery code path, in its final marshalling
for output, calls Marshall

  https://github.com/go-yaml/yaml/blob/v2/yaml.go#L199

This code path (via apimachinery Unstructured types)
has no JSON schema tags

  https://yaml.org/spec/1.2/spec.html#id2803311

so it adds quotes to values that smell like
booleans and ints (e.g. `false` becomes `"false"`).

The kyaml code path, OTOH, uses such tags,
so generally does not quote ints and booleans.

This PR isolates this difference in behavior to
one set of tests (using data fields in configmaps
in api/krusty/configmaps_test.go) so that
they don't confuse other tests that cover
completely different behaviors.
2020-12-23 17:08:25 -08:00
Kubernetes Prow Robot
d90d77cdaf Merge pull request #3366 from natasha41575/QuotedScalarValueWithColon
if setter value ends in colon, treat it as a string
2020-12-23 11:54:26 -08:00
Jeff Regan
1ffd790cfb Merge pull request #3388 from Shell32-Natsu/secret-type
Fix type ignored in secret generator
2020-12-22 17:51:07 -08:00
Jeff Regan
454906d093 Merge pull request #3389 from monopole/moreMergeTests
More merge tests, clearer method names.
2020-12-22 17:49:26 -08:00
jregan
8b97274af3 More merge tests, clearer method names. 2020-12-22 17:26:12 -08:00
Donny Xia
b1056b43cb Merge pull request #3383 from antoninbas/add-role-resourceNames-to-configMap-builtin-nameref-resolver
Add Role / ClusterRole resourceNames to ConfigMap nameref resolver
2020-12-22 14:43:19 -08:00
Donny Xia
e411942a74 Fix type ignored in secret generator 2020-12-22 14:37:13 -08:00
Kubernetes Prow Robot
6b30b72ebc Merge pull request #3385 from monopole/elimateExtraneousEmtpyMaps
Eliminate extraneous label and anno maps.
2020-12-22 08:54:26 -08:00
jregan
9ddf0fe304 Eliminate extraneous label and anno maps. 2020-12-22 08:37:40 -08:00
Jeff Regan
8a952a1b26 Merge pull request #3384 from monopole/badBlank
Fix roleref test failing under enableKyaml
2020-12-22 06:47:55 -08:00
jregan
fff484e98b Fix test failing under enableKyaml 2020-12-22 06:24:27 -08:00
Antonin Bas
e819a2ba9d Add Role / ClusterRole resourceNames to ConfigMap nameref resolver
While it is possible to use a kustomizeconfig.yml for this, with a
custom namereference, this functionality should probably be built-in.

This is similar to previous PRs, like this one:
https://github.com/kubernetes-sigs/kustomize/pull/592
2020-12-21 21:02:19 -08:00
Natasha Sarkar
4908654c09 if setter value ends in colon, treat it as a string 2020-12-21 11:54:30 -08:00
Jeff Regan
586515ebc4 Merge pull request #3379 from monopole/messingWithMerge
Fix configmap merge problem under kyaml.
2020-12-21 09:22:02 -08:00
jregan
735befef19 Add kunstruct impl of Get/SetDataMap, replace Resource.Merge 2020-12-21 07:22:03 -08:00
jregan
35087ed0cc Add RNode.Set/GetDataMap to ease configmap generation. 2020-12-21 07:18:51 -08:00
Jeff Regan
f84f8f28fd Merge pull request #3376 from monopole/oops
Drop another go.mod version replacement omission.
2020-12-20 17:07:36 -08:00
jregan
45e118458c Drop another go.mod version replacement omission. 2020-12-20 17:06:26 -08:00
Jeff Regan
1102153ae3 Merge pull request #3375 from monopole/removeVersionNumbers
In module replacements, drop specific version numbers.
2020-12-20 16:45:54 -08:00
jregan
338910d36c In module replacements, drop specific version numbers. 2020-12-20 16:23:23 -08:00
Kubernetes Prow Robot
38e9770f40 Merge pull request #3374 from monopole/deleteOldChartInflator
Delete old example helm chart inflator.
2020-12-20 11:24:25 -08:00
Kubernetes Prow Robot
20a4153893 Merge pull request #3373 from monopole/unpinKyaml
Unpin kyaml
2020-12-20 11:00:24 -08:00
jregan
51fba009b3 Delete old example helm chart inflator. 2020-12-20 10:45:43 -08:00
jregan
002215d719 Unpin kyaml 2020-12-20 10:31:17 -08:00
Kubernetes Prow Robot
f9d1e800e4 Merge pull request #3371 from mortent/UseIndexForOrderingFunctions
Multiple declarative functions in the same file should execute in order
2020-12-17 17:24:25 -08:00
Jeff Regan
82db6cd73d Merge pull request #3370 from monopole/fixAnotherNit
Fix formatting nit with enableKyaml
2020-12-17 12:49:25 -08:00
Morten Torkildsen
3c25584658 Multiple declarative functions in the same file should execute in order 2020-12-17 12:13:42 -08:00
jregan
c32a809dbd Fix formatting nit with enableKyaml 2020-12-17 11:21:46 -08:00
Jeff Regan
02be687778 Merge pull request #3369 from monopole/unpinApi
Unpin api module.
2020-12-17 10:02:20 -08:00
jregan
c0a754e7b0 Unpin api module. 2020-12-17 09:38:14 -08:00
Jeff Regan
63e441a673 Merge pull request #3368 from monopole/fixSlash
Fix apiversion slash
2020-12-17 09:20:00 -08:00
jregan
bd27d5f8bb Fix apiversion slash 2020-12-17 08:42:15 -08:00
Kubernetes Prow Robot
0aa250c6e2 Merge pull request #3359 from Shell32-Natsu/resmap-from-rnodes
Avoid error when the node has local-config
2020-12-16 11:00:30 -08:00
Jeff Regan
e269ad4a80 Merge pull request #3356 from JaredTan95/update_extension_version
upgrade admissionregistration.k8s.io/v1beta1 version to v1
2020-12-16 10:44:08 -08:00
Jeff Regan
9db6b37b88 Merge pull request #3357 from yuvalk/yuvalk/master
add curl timeout to install script
2020-12-16 10:43:13 -08:00
JaredTan95
2361b70967 fix unit test 2020-12-16 10:05:04 +08:00
Donny Xia
d016326877 avoid error when the node has local-config 2020-12-15 13:29:19 -08:00
Donny Xia
67e445c10b Merge pull request #3353 from epcim/helmValuesOnInflatorConfig-plugin
Helm values on inflator config plugin
2020-12-15 10:21:47 -08:00
Jeff Regan
76970a6b05 Merge pull request #3354 from Shell32-Natsu/set-image
describe the format of image tag that is allowed
2020-12-15 09:44:20 -08:00
Kubernetes Prow Robot
66db1df79a Merge pull request #3346 from Shell32-Natsu/ynode-iszero
Add function to check is YNode zero
2020-12-15 09:43:48 -08:00
Yuval Kashtan
6442047e52 add curl timeout to install script
This is important to improve reliency of other automations/scripts that are using this script internally. Otherwise install script might stall forever in some cases.
2020-12-15 12:01:15 +02:00
Petr Michalec
8ac6954de1 helm values on inflator config - test
Signed-off-by: Petr Michalec <epcim@apealive.net>
2020-12-15 08:39:17 +01:00
Petr Michalec
494977b9d0 helm values on inflator config - builtin
Signed-off-by: Petr Michalec <epcim@apealive.net>
2020-12-15 08:38:59 +01:00
Petr Michalec
0a0a6e1018 helm values on inflator config - plugin
Signed-off-by: Petr Michalec <epcim@apealive.net>
2020-12-15 08:38:37 +01:00
Petr Michalec
fa69d4ba9d helm values on inflator config - types
Signed-off-by: Petr Michalec <epcim@apealive.net>
2020-12-15 08:37:34 +01:00
JaredTan95
36bdcca735 update plugin api version.
Signed-off-by: JaredTan95 <jian.tan@daocloud.io>
2020-12-15 12:22:57 +08:00
JaredTan95
c71a4534a0 update kyaml api version. 2020-12-15 12:21:27 +08:00
JaredTan95
97402f1136 update crd_test.go api version. 2020-12-15 12:20:10 +08:00
JaredTan95
1329afa3ca update imagetag_test.go api version. 2020-12-15 12:19:37 +08:00
Donny Xia
60c8f4c594 Merge pull request #3350 from shibataka000/add-topologyspreadconstraints-to-builtin-common-label-field
Add topologySpreadConstraints to builtin common label field
2020-12-14 10:13:23 -08:00
Donny Xia
428e25b856 Merge pull request #3349 from montmanu/update-docker-path
add kustomize to PATH
2020-12-14 10:12:45 -08:00
Donny Xia
8dd6f2b185 describe the format of image tag that is allowed 2020-12-14 10:09:01 -08:00
Takao Shibata
a3bf3ba608 Add topologySpreadConstraints to builtin label field 2020-12-14 14:18:02 +09:00
Christopher Montoro
b97e59c57e add kustomize to PATH 2020-12-13 18:03:35 -05:00
Donny Xia
bae3228557 Add function to check is YNode zero 2020-12-11 14:55:44 -08:00
Jeff Regan
cc43a2d732 Merge pull request #3342 from Shell32-Natsu/wnode-slice
fix wnode get slice issue
2020-12-11 09:07:16 -08:00
Donny Xia
d25e1effb7 Unpin api 2020-12-10 15:13:22 -08:00
Donny Xia
485b8121d3 fix wnode get slice issue 2020-12-10 15:12:57 -08:00
Jeff Regan
401118728a Update kustomization.yaml 2020-12-10 14:20:36 -08:00
Kubernetes Prow Robot
0f45bd9583 Merge pull request #3339 from monopole/updateTests
Update tests of examples against new releases.
2020-12-10 12:58:13 -08:00
jregan
97e4353755 Update test of examples against new releases. 2020-12-10 12:37:47 -08:00
Jeff Regan
826b5d9792 Merge pull request #3338 from monopole/updateGoSum
Auto update go.sum
2020-12-10 11:27:28 -08:00
jregan
8c9da15156 Auto update go.sum 2020-12-10 11:26:51 -08:00
Kubernetes Prow Robot
e18d619c9e Merge pull request #3337 from monopole/pinToApiv0.7.0_enableKyamlByDefault
Pin kustomize to api/v0.7.0, enabling kyaml by default
2020-12-10 11:08:15 -08:00
jregan
f8a3c04286 Pin kustomize to api/v0.7.0, enabling kyaml by default
ALLOW_MODULE_SPAN
2020-12-10 10:48:52 -08:00
Kubernetes Prow Robot
1a4c82241a Merge pull request #3335 from monopole/enableKyamlByDefault
Flip default value of --enable_kyaml from false to true.
2020-12-10 10:38:14 -08:00
jregan
81ca271e62 Flip default value of --enable_kyaml from false to true. 2020-12-10 10:12:49 -08:00
Kubernetes Prow Robot
72262c5e71 Merge pull request #3334 from monopole/pinKustToApiv0.6.7
Pin kustomize to api/v0.6.7
2020-12-10 09:42:14 -08:00
jregan
125762d94d Pin kustomize to api/v0.6.7 2020-12-09 22:33:02 -08:00
Jeff Regan
0ecbd5905b Merge pull request #3332 from monopole/pinToApi0.6.7
Pin to api v0.6.7
2020-12-09 19:45:48 -08:00
jregan
cb2b376065 Pin to api v0.6.7 2020-12-09 19:20:29 -08:00
Jeff Regan
595e59b919 Merge pull request #3330 from monopole/loaderTest
Provide timeouts for all remote loads.
2020-12-09 17:33:03 -08:00
jregan
6bbc829593 Add a loader test. 2020-12-09 17:17:21 -08:00
Kubernetes Prow Robot
3dd9c6c0b5 Merge pull request #3331 from monopole/unpinKust
Unpin kustomize from api.
2020-12-09 16:04:53 -08:00
jregan
c04c13a12a Unpin kustomize from api. 2020-12-09 15:44:09 -08:00
Jeff Regan
05eccab823 Update loader.go 2020-12-09 15:17:52 -08:00
Jeff Regan
dd946e1343 Merge pull request #3328 from monopole/pin_to_api_v0.6.6
Pin to api v0.6.6
2020-12-07 17:48:32 -08:00
jregan
b4ad4b6984 Pin to api v0.6.6 2020-12-07 17:29:46 -08:00
Jeff Regan
13dee68d3b Merge pull request #3327 from monopole/pin_to_cmdConfig_v0.9.6
Pin to cmd/config v0.8.6
2020-12-07 17:22:31 -08:00
jregan
e849b160bc Pin to cmd/config v0.8.6 2020-12-07 17:02:55 -08:00
Jeff Regan
87987d3382 Merge pull request #3326 from monopole/pin_to_kyaml_v0.10.3_cliutils_v0.22.1
Pin to kyaml v0.10.3 cliutils v0.22.1
2020-12-07 16:53:35 -08:00
jregan
575b4efc18 Pin to kyaml v0.10.3 cliutils v0.22.1 2020-12-07 16:26:52 -08:00
Jeff Regan
b1a460985c Merge pull request #3325 from monopole/autoGoMo
Automated Go mod cache updates.
2020-12-07 13:44:23 -08:00
jregan
e1fd74bb61 Automated Go mod cache updates. 2020-12-07 13:23:20 -08:00
Jeff Regan
8a673b82bd Merge pull request #3287 from yujunz/getter
Upgrade go-getter
2020-12-07 13:11:26 -08:00
Jeff Regan
d2e995b3e2 Merge pull request #3306 from thatsmydoing/single-fetch
Don't fetch default branch if ref is specified
2020-12-07 13:10:26 -08:00
Jeff Regan
f2e025ea53 Update manager.go 2020-12-07 12:57:32 -08:00
Jeff Regan
dade85e40e Merge pull request #3324 from kubernetes-sigs/revert-3316-helmValuesOnInflatorConfigSpec
Revert "helm values on inflator config"
2020-12-07 12:53:49 -08:00
Jeff Regan
51ba54ad82 Revert "helm values on inflator config" 2020-12-07 12:52:31 -08:00
Jeff Regan
4144775a3b Merge pull request #3316 from epcim/helmValuesOnInflatorConfigSpec
helm values on inflator config
2020-12-07 12:51:42 -08:00
Jeff Regan
ff9b215ae7 Update taggedmodule.go 2020-12-07 12:09:09 -08:00
Jeff Regan
cd5ae17335 Merge pull request #3322 from monopole/fixModNames
Fix some plugin module names.
2020-12-07 12:08:14 -08:00
jregan
e3d022325b Fix some plugin module names. 2020-12-07 11:59:13 -08:00
Kubernetes Prow Robot
e6dc03bea4 Merge pull request #3315 from monopole/hoserface
Add more tests
2020-12-07 10:31:11 -08:00
jregan
d08b9c30ee What is this? 2020-12-07 10:16:30 -08:00
Petr Michalec
f6e5eedee2 helm values on inflator config spec. 2020-12-07 13:49:30 +01:00
Jeff Regan
212b2cff12 Merge pull request #3312 from monopole/conflicting
Extract conflict detection to its own interface.
2020-12-06 09:00:41 -08:00
jregan
f66e5bb923 Extract conflict detection to it's own interface.
This PR
 - defines a patch conflict detector interface,
 - extracts implementations of the interface from the
   merginator code, making the merginator code
   independent of --enable_kyaml.
 - injects those implementations into kustomize
   as a function of --enable_kyaml.

So, instead of using different merginators to combine
resmaps, this pr allows the use of a single patch merge
code path that uses different conflict detectors.

So instead of debating how to merge, we're now only
considering whether to warn on conflict detection
in one transformer.

This PR is in service of #3304, eliminating seven
instances where --enable_kyaml was consulted.  These
were cases where conflict detection wasn't an issue
(but merging patches was).
2020-12-06 08:38:45 -08:00
Kubernetes Prow Robot
23bc91f233 Merge pull request #3311 from drewwells/patch-1
absolute path to entrypoint
2020-12-04 18:05:25 -08:00
Drew Wells
9c421c7410 absolute path to entrypoint
Make the kustomize container tolerant of alternative working directory. 
Mounting my project and making it the working directory will now work.

ie. docker run -w /pkg -v $(shell pwd):/pkg kustomize version
2020-12-04 18:27:57 -06:00
Jeff Regan
c63dfd6772 Merge pull request #3310 from monopole/nits
Spelling nits.
2020-12-04 12:30:36 -08:00
jregan
1a5aa63d54 Spelling nits. 2020-12-04 12:29:39 -08:00
Jeff Regan
1583cef8d9 Merge pull request #3309 from monopole/autoUpdate
Automated doc update.
2020-12-04 10:51:54 -08:00
jregan
a7c91c37e9 Automated doc update. 2020-12-04 10:51:22 -08:00
Kubernetes Prow Robot
c1dca7fdb5 Merge pull request #3302 from natasha41575/TestGvknChange
tests for gvkn changing
2020-12-04 10:29:59 -08:00
Natasha Sarkar
724bbe9452 connected allowresourcesidchanges bool to allow_id_changes flag 2020-12-02 18:03:09 -08:00
Natasha Sarkar
deb2b21cbe added allowresourceidchanges bool to options struct 2020-12-02 18:02:09 -08:00
Kubernetes Prow Robot
709f499b44 Merge pull request #3305 from monopole/moreHacking
In PatchStrategicMergeTransformer's test, highlight remaining work
2020-12-02 10:38:50 -08:00
jregan
dbaa2d6092 hacking 2020-12-02 10:23:13 -08:00
Thomas Dy
6445e03d1a Don't fetch default branch if ref is specified
Currently, we always fetch the default branch with an initial git clone
and then fetch the ref after if it's specified. This changes it to only
make one fetch instead of two if a ref is specified.
2020-12-02 16:16:30 +09:00
Jeff Regan
19ff1b307e Merge pull request #3301 from rumstead/master
[Docs] Fixing README link to kubectl book.
2020-12-01 16:56:25 -08:00
Jeff Regan
55f44a29c6 Update README.md 2020-12-01 16:48:41 -08:00
Jeff Regan
1f1873a6ed Merge pull request #3299 from monopole/demoteReplacementTransformer
Move ReplacementTransformer plugin to untested folder
2020-12-01 12:45:53 -08:00
rumstead
6e3c4ecc72 Update README.md 2020-12-01 13:18:59 -05:00
jregan
c37c7b6b2c Move ReplacementTransformer plugin to untested. 2020-12-01 10:04:00 -08:00
Jeff Regan
42acdcc1d0 Merge pull request #3298 from monopole/makeUntestedPluginDir
Start directory for 'untested' plugins.
2020-12-01 09:52:59 -08:00
jregan
67db23b24b Start directory for 'untested' plugins. 2020-12-01 07:32:44 -08:00
Kubernetes Prow Robot
35a19fb8a9 Merge pull request #3296 from monopole/secretGeneratorTestKYaml
Adjust SecretGeneratorTest to pass with --enable_kyaml
2020-11-30 19:50:57 -08:00
Kubernetes Prow Robot
a6c2e982f9 Merge pull request #3292 from Shell32-Natsu/helm-extra-args
Add field extraArgs to helm generator
2020-11-30 19:50:49 -08:00
Kubernetes Prow Robot
a053ff6907 Merge pull request #3295 from monopole/addSmPatchTests
Add more tests for reswrangler ApplySmPatch
2020-11-30 19:24:50 -08:00
jregan
64201c8352 Adjust SecretGeneratorTest to pass with --enable_kyaml 2020-11-30 19:17:15 -08:00
jregan
d5ce26e423 Patchtransformers - drop copied code, improve deletion handling. 2020-11-30 18:43:35 -08:00
Kubernetes Prow Robot
09497f0830 Merge pull request #3294 from monopole/goSumCatchup
Automated go.sum updates.
2020-11-30 18:42:50 -08:00
jregan
32dd194aca Automated go.sum updates. 2020-11-30 18:16:23 -08:00
Jeff Regan
4122787bd8 Merge pull request #3293 from natasha41575/FixOpenApiInfoSpacing
Made output of `kustomize openapi info` command more readable
2020-11-30 18:15:16 -08:00
Yujun Zhang
485cb3831e Upgrade go-getter
* Provide a detector for repositories hosted on GitLab.com
* Update github.com/ulikunitz/xz@v0.5.8 for CVE-2020-16845
2020-12-01 09:39:03 +08:00
Natasha Sarkar
2ccb73a2a3 made output of kustomize openapi info command more readable 2020-11-30 14:56:20 -08:00
Kubernetes Prow Robot
83377cf597 Merge pull request #3291 from monopole/thrashing
Patchtransformers - drop copied code, improve deletion handling.
2020-11-30 14:26:50 -08:00
Donny Xia
2bf73c60c3 Add field extraArgs to helm generator 2020-11-30 14:22:25 -08:00
jregan
4a55a07c14 Patchtransformers - drop copied code, improve deletion handling. 2020-11-30 11:58:43 -08:00
Kubernetes Prow Robot
5279ad904b Merge pull request #3282 from pwittrock/main
Fn framework utilities for parsing templates from directories
2020-11-30 08:42:50 -08:00
Phillip Wittrock
736f110f04 Fn framework template and process options
- Refactor framework code to be simpler
- Add TemplatesFn feature
- Add PreProcessFilters feature
- Add PostProcessFilters features
- Add TemplatesFromDir
- Add PatchTemplatesFromDir
- Add PatchContainerTemplatesFromDir
2020-11-30 08:23:34 -08:00
Jeff Regan
c9ab1270fa Merge pull request #3290 from monopole/idSet
Add resource id set.
2020-11-30 05:42:26 -08:00
jregan
bb5fc9086b Add resource id set. 2020-11-30 05:37:53 -08:00
Kubernetes Prow Robot
e8c85456cc Merge pull request #3279 from monopole/addGeneratedCode
Add label and annotation selector code.
2020-11-28 22:36:48 -08:00
jregan
aa9a397808 Kyaml: disable generation on each build. 2020-11-28 05:55:16 -08:00
jregan
60ea8de5f1 Complete WNode implementation. 2020-11-26 14:48:00 -08:00
jregan
56c8df7b85 Add RNode implementation of label and annotation selectors. 2020-11-26 14:47:23 -08:00
Jeff Regan
a51e4234c4 Merge pull request #3283 from Shell32-Natsu/docker
Add git and openssh in docker image
2020-11-26 08:18:44 -08:00
Jeff Regan
50cd01e5f7 Update Makefile 2020-11-26 07:00:13 -08:00
Jeff Regan
42b082a6b1 Merge pull request #3285 from monopole/improveSelectTest
Add labels to selector test.
2020-11-26 06:57:14 -08:00
jregan
c3cdd15769 Clean up selector test. 2020-11-26 06:36:24 -08:00
Donny Xia
c3a8b6f359 Add git and openssh in docker image 2020-11-25 15:02:47 -08:00
Jeff Regan
4af4483e12 Merge pull request #3281 from Shell32-Natsu/update-go-version
update Go version to 1.15
2020-11-25 14:05:24 -08:00
Donny Xia
8f7bcb9b16 update Go version to 1.15 2020-11-25 12:41:20 -08:00
Jeff Regan
f54d904766 Merge pull request #3277 from monopole/moreRNodeSetters
More RNode setters and WNode delegation
2020-11-25 10:20:06 -08:00
Jeff Regan
ba91b6f79f Merge pull request #3278 from SyamSundarKirubakaran/doc-site-changes
Remove `zh` site contents and redirect to new site
2020-11-25 09:09:07 -08:00
Syam Sundar K
851acafe32 generate site 2020-11-25 21:42:09 +05:30
Syam Sundar K
14eac6020f remove duplicate contents and redirect 2020-11-25 21:41:27 +05:30
Jeff Regan
e45d667b4d Delete .gitattributes
Didn't work as desired.
2020-11-25 07:59:58 -08:00
Jeff Regan
cbdf4a0e43 Update .gitattributes 2020-11-25 07:53:35 -08:00
jregan
aed7e5aaf9 Delegate more from WNode to RNode.
The implementations in WNode are supposed to be thin,
as it will be removed once #2506 closes.

The change also makes some addjustments for the
upcoming flip of the enable_kyaml flag, pointing to
issue #3271.
2020-11-25 07:11:06 -08:00
jregan
ec64ef705b Add metadata getters and setters to RNode.
These setters completely remove the field if the argument
is empty, rather than setting the field to an empty value,
mimicing apimachinery behavior.
2020-11-25 07:03:12 -08:00
Jeff Regan
1e0eb58bc9 Merge pull request #3273 from Shell32-Natsu/reenable-multi-module-check
Re-enable multi-module check
2020-11-24 19:18:16 -08:00
Jeff Regan
fd2fe35863 Merge pull request #3275 from monopole/tryGitAttributes
Start a gitattributes file.
2020-11-24 19:12:23 -08:00
jregan
ebdbd81ed8 Start a gitattributes file. 2020-11-24 18:50:46 -08:00
Donny Xia
c9d2ae6b49 Re-enable multi-module check 2020-11-24 16:29:01 -08:00
Kubernetes Prow Robot
e8c212a10f Merge pull request #3272 from monopole/moreTests
Add more tests around yaml parsing.
2020-11-24 14:34:39 -08:00
jregan
1eb378254a Add more tests around yaml parsing. 2020-11-24 14:15:45 -08:00
Kubernetes Prow Robot
0d030e3095 Merge pull request #3270 from pwittrock/main
Improved fn framework support for patching
2020-11-24 12:22:39 -08:00
Phillip Wittrock
f2706dce68 Improved fn framework support for patching
- Generate patches with a func
- Generate patches for containers
2020-11-24 12:02:55 -08:00
Jeff Regan
f8194bd3c2 Merge pull request #3267 from monopole/generatedCode
Add generated code.
2020-11-23 16:51:41 -08:00
jregan
eb5227680e Add generated code. 2020-11-23 16:47:00 -08:00
Jeff Regan
27e89f271f Merge pull request #3266 from monopole/modsToMakefile
Consistently prefix make targets with clean, generate, build.
2020-11-23 16:37:34 -08:00
jregan
626f2f9d1d Another cleaning target in Makefile. 2020-11-23 16:14:47 -08:00
Jeff Regan
ffda124ca5 Update Makefile 2020-11-23 06:48:53 -08:00
Jeff Regan
fd677f635e Update README.md 2020-11-22 21:01:28 -08:00
Jeff Regan
14b1388c6a Merge pull request #3263 from monopole/useLessReflectionInTests
In some tests, replace reflection with yaml compare.
2020-11-22 20:34:38 -08:00
jregan
5248fd0cd9 In some tests, replace reflection with yaml compare. 2020-11-22 18:48:32 -08:00
Jeff Regan
b6ae9f80d3 Merge pull request #3257 from monopole/binaryData
Secrets and ConfigMaps with binary data in kyaml
2020-11-21 15:11:29 -08:00
Jeff Regan
2ad502d5a8 Merge pull request #3261 from monopole/depProviderInjection
Use DepProvider in tests to access kyaml impls.
2020-11-21 15:07:45 -08:00
jregan
a5f3d5c823 Use DepProvider in tests to access kyaml impls. 2020-11-21 14:49:44 -08:00
Jeff Regan
c65875cacc Merge pull request #3259 from pwittrock/main
fn/framework support for reading from stdin in standalone
2020-11-21 14:44:54 -08:00
Phillip Wittrock
82b2d83ede fn/framework support for reading from stdin in standalone
- speficy '-' to read from stdin when running standalone
2020-11-21 09:17:26 -08:00
Jeff Regan
7e01aec5a4 Update Makefile 2020-11-21 07:14:04 -08:00
Jeff Regan
9e8a84c5ff Merge pull request #3251 from Shell32-Natsu/krm-function-converter
[KRM function converter] Get plugin config from data field
2020-11-21 06:25:42 -08:00
Jeff Regan
849d5c4a8d Merge branch 'master' into krm-function-converter 2020-11-21 06:10:25 -08:00
Jeff Regan
00352cbc58 Merge pull request #3256 from Shell32-Natsu/pluginator-api-version
update module api version in wrapper
2020-11-21 06:09:04 -08:00
jregan
b88e770b1d binary data nope 2020-11-20 17:55:20 -08:00
Jeff Regan
eda7a9f8d6 Merge pull request #3258 from monopole/goSumAutomated
Automated go.sum change.
2020-11-20 17:55:01 -08:00
jregan
114b3f4b00 Automated go.sum change. 2020-11-20 17:18:14 -08:00
Donny Xia
6cb339142d update module api version in wrapper 2020-11-20 16:28:38 -08:00
Kubernetes Prow Robot
052a6b4e96 Merge pull request #3255 from Shell32-Natsu/rnode-format
fix rnode string format converted from resmap
2020-11-20 15:07:33 -08:00
Donny Xia
4add7eccd0 fix rnode string format converted from resmap 2020-11-20 14:34:11 -08:00
Kubernetes Prow Robot
a0a89e1adc Merge pull request #3250 from pwittrock/main
Function framework support for patching containers
2020-11-20 12:42:51 -08:00
Donny Xia
10fd4b4bbe Merge pull request #3252 from runewake2/notes
Update release notes generation
2020-11-20 10:24:03 -08:00
Donny Xia
e15ede037d Merge pull request #3253 from yujunz/remote-build
Fix test against examples
2020-11-20 09:47:47 -08:00
Yujun Zhang
32a2f5ffa9 Fix test against examples
Tests in examples.remoteBuild.md were skipped unexpectedly
2020-11-20 20:10:07 +08:00
Sam Wronski
4f74203f6c Fix variable name: "currentTag" -> "fullTag" 2020-11-19 15:37:39 -08:00
Sam Wronski
5b0cbcb5fb Update release notes generation
- Notes use tags instead commit sha
2020-11-19 14:28:05 -08:00
Donny Xia
2f4c35347e Get plugin config from data field 2020-11-19 13:11:47 -08:00
Phillip Wittrock
be5db09db1 Function framework support for patching containers 2020-11-19 10:01:12 -08:00
Jeff Regan
a6833bc4c0 Merge pull request #3211 from Shell32-Natsu/krm-plugin-tool
modify pluginator to support convert builtin plugin to krm function
2020-11-18 15:59:29 -08:00
Donny Xia
2ae323bb26 move files into internal 2020-11-18 12:21:59 -08:00
Donny Xia
7e74271071 fix script name 2020-11-18 12:21:59 -08:00
Donny Xia
260e093547 modify pluginator to add support for krm function 2020-11-18 12:21:59 -08:00
Jeff Regan
47b12fa3dc Merge pull request #3240 from Shell32-Natsu/list-builtin
Add command to list builtin plugins
2020-11-18 11:13:39 -08:00
Jeff Regan
38801cd966 Merge pull request #3238 from Shell32-Natsu/managed-by-label
fix invalid managed-by label value
2020-11-18 11:09:28 -08:00
Jeff Regan
c49e177b9c Merge pull request #3247 from monopole/secretsAndMaps
Secrets and ConfigMaps with string data in kyaml
2020-11-18 10:00:38 -08:00
jregan
486be07e22 Add WNodeFactory.MakeConfigMap,MakeSecret 2020-11-18 09:45:43 -08:00
Donny Xia
a12db91a10 mark the list-builtin command alpha 2020-11-18 09:38:03 -08:00
jregan
f7613631d1 Add some kyaml filters for k8s metadata. 2020-11-18 08:57:13 -08:00
Kubernetes Prow Robot
8a77494c7d Merge pull request #3239 from pwittrock/framework
Function framework features
2020-11-17 17:58:04 -08:00
Kubernetes Prow Robot
af25469c8b Merge pull request #3219 from phanimarupaka/RefactorOpenAPI
Refactor open api
2020-11-17 11:26:04 -08:00
Phillip Wittrock
8c4841c28f Support for framework.Selector substitutions 2020-11-17 08:52:34 -08:00
Phani Teja Marupaka
b6a4dd446a Refactor openAPI
Refactor global openapi
2020-11-16 23:03:56 -08:00
Jeff Regan
606654756d Update kfns.go 2020-11-16 21:38:25 -08:00
Jeff Regan
97c18518ea Update rnode.go 2020-11-16 21:37:28 -08:00
Jeff Regan
2dca4ab987 Merge pull request #3242 from monopole/useConst
Gather and use some of the kyaml constants.
2020-11-16 21:31:13 -08:00
jregan
712276176c Gather and use some of the kyaml constants. 2020-11-16 21:26:18 -08:00
Donny Xia
c610e3a364 Add command to list builtin plugins 2020-11-16 17:18:56 -08:00
Phillip Wittrock
02e7589323 Function framework testutil support for functions which refer to local files
Some functions may read local files using relative paths.  Update the test
framework to `cd` into the directory containing the config.yaml before
running the function.
2020-11-16 16:35:07 -08:00
Kubernetes Prow Robot
2ae180ca23 Merge pull request #3235 from pwittrock/framework
fn framework TemplatePatch support
2020-11-16 14:14:05 -08:00
Donny Xia
98900c43f7 fix invalid managed-by label value 2020-11-16 14:05:21 -08:00
Phillip Wittrock
02b14d919b fn framework -- add support for patch templates 2020-11-16 14:01:08 -08:00
Phillip Wittrock
bd0a699ff6 Refactor fn/framework tests to use a common library. 2020-11-16 14:00:55 -08:00
Jeff Regan
02b4b56c60 Merge pull request #3233 from monopole/sliceFromBytes
Implement WNodeFactory.SliceFromBytes
2020-11-16 11:57:09 -08:00
jregan
0cac05448b Implement WNodeFactory.SliceFromBytes and FromMap 2020-11-16 11:33:04 -08:00
jregan
e1c3caeba6 Introduce some RNode validation methods. 2020-11-16 11:32:23 -08:00
Jeff Regan
a25429ae3b Merge pull request #3236 from runewake2/mergeless-releases
Remove merge commits from release notes
2020-11-16 11:22:01 -08:00
Kubernetes Prow Robot
e557677fed Merge pull request #3229 from Shell32-Natsu/krm-plugin-tool-helpers
Add methods to convert ResMap to and from RNodes
2020-11-16 11:12:06 -08:00
Donny Xia
59e0b593cf Merge pull request #3232 from justinsb/hint_about_bytereader
Expand rnode function comments to point to multi-object options.
2020-11-16 10:12:54 -08:00
Sam Wronski
3fa906505c Remove merge commits from release notes 2020-11-16 09:47:57 -08:00
Justin SB
a823f3043f Expand rnode function comments to point to multi-object options.
The rnode Parse and ReadFile functions only return a single object;
suggest kio.ByteReader for the case of parsing multiple objects.
2020-11-15 13:07:28 -05:00
Jeff Regan
b2ba82a0bd Merge pull request #3231 from monopole/fromMap
Add RNode FromMap factory method.
2020-11-14 13:33:12 -08:00
jregan
a4f22cb84f Add RNode fromMap method. 2020-11-14 13:10:53 -08:00
Jeff Regan
22f41c789a Merge pull request #3230 from monopole/fmtFix
Fix go fmt.
2020-11-14 11:03:59 -08:00
jregan
966d0a054c Fix go fmt. 2020-11-14 11:02:44 -08:00
Kubernetes Prow Robot
97f3ac2da1 Merge pull request #3185 from aodinokov/streamline-fn-plugin-kyaml-part
Allowing RunFns not to stop on empty result
2020-11-13 13:47:04 -08:00
Donny Xia
536b69e5dc add methods to convert resmap to&from rnodes 2020-11-13 13:41:34 -08:00
Kubernetes Prow Robot
c7aaa18d0c Merge pull request #3227 from radTuti/master
update kustomize download script
2020-11-13 11:39:05 -08:00
tuti
a45523bb95 dry release_url 2020-11-13 11:25:35 -08:00
Kubernetes Prow Robot
376f59f0f6 Merge pull request #3222 from natasha41575/EditSetLabel
added kustomize edit set label
2020-11-13 11:15:04 -08:00
tuti
34863346b0 include arch type in grep string 2020-11-13 11:09:56 -08:00
Kubernetes Prow Robot
9569ca93d9 Merge pull request #3220 from natasha41575/OpenApiVersionField
Add multiple versions of OpenAPI schema to kyaml
2020-11-13 10:39:05 -08:00
Kubernetes Prow Robot
09377ac19c Merge pull request #3223 from sylr/azure-file
Add namereference for PersistentVolume
2020-11-13 10:25:04 -08:00
Jeff Regan
a25300dfd6 Merge pull request #3225 from Shell32-Natsu/inline-transformer
support inline transformer and generator
2020-11-13 10:05:43 -08:00
Kubernetes Prow Robot
50e9e90b17 Merge pull request #3226 from phanimarupaka/DeprecateV1Setters
Delete v1 setters code
2020-11-13 09:21:06 -08:00
tuti
e3ad472933 allow downloading older releases 2020-11-12 18:19:02 -08:00
tuti
154f894774 fix latest release download failure 2020-11-12 18:17:47 -08:00
Natasha Sarkar
4d7600d4ef updated comments and readme 2020-11-12 18:02:11 -08:00
tuti
0a0a0ccddc Merge branch 'master' from kubernetes-sigs/kustomize 2020-11-12 17:59:53 -08:00
Phani Teja Marupaka
2278e01b7f Delete v1 setters code 2020-11-12 15:29:07 -08:00
Donny Xia
abc88c56c4 support inline transformer and generator 2020-11-12 15:19:14 -08:00
Kubernetes Prow Robot
eddd872eca Merge pull request #3221 from pwittrock/framework
Function framework standalone feature
2020-11-12 13:52:25 -08:00
Sylvain Rabot
febede115e Add namereference for PersistentVolume
Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
2020-11-12 22:47:33 +01:00
Natasha Sarkar
a2087f07d4 added kustomize edit set label 2020-11-12 13:26:52 -08:00
Phillip Wittrock
8b9d8a266d Support standalone mode for framework functions 2020-11-12 11:54:58 -08:00
Phillip Wittrock
5557e1ff3c Retain element ordering when merge resources 2020-11-12 08:54:16 -08:00
Phillip Wittrock
1c009ca217 More control over bytereadwriter options
- Override wrapping
- Override function config
2020-11-12 08:54:16 -08:00
Natasha Sarkar
bdb59d2cd2 updated releasing readme 2020-11-11 18:09:41 -08:00
Natasha Sarkar
b61a115e76 added support for multiple kubernetes openapi schemas 2020-11-11 18:09:41 -08:00
Jeff Regan
66221d17d4 Merge pull request #3217 from Shell32-Natsu/image
remove a tag from image
2020-11-11 16:22:51 -08:00
Kubernetes Prow Robot
c83f256dbe Merge pull request #3218 from monopole/unpinEverything
Unpin everything post v3.8.7 release
2020-11-11 15:58:52 -08:00
jregan
fa3caaacee Unpin everything post v3.8.7 release 2020-11-11 15:45:09 -08:00
Kubernetes Prow Robot
0a0a2ed586 Merge pull request #3209 from pwittrock/main
Remove duplicate docs content
2020-11-11 15:44:52 -08:00
Donny Xia
aff1db13e0 remove a tag from image 2020-11-11 15:41:32 -08:00
Kubernetes Prow Robot
ad092cc7a9 Merge pull request #3216 from monopole/pin_api_v0.6.5
Pin to api_v0.6.5
2020-11-11 15:08:50 -08:00
jregan
0a9fc6c8cb Pin to api_v0.6.5 2020-11-11 14:56:25 -08:00
Kubernetes Prow Robot
881d33ac5c Merge pull request #3214 from monopole/pin_cmd_config_v0.8.5
Pin to cmd/config/v0.8.5
2020-11-11 14:48:50 -08:00
jregan
842e4f5dc5 Pin to cmd/config/v0.8.5 2020-11-11 14:34:30 -08:00
Kubernetes Prow Robot
ef612286e4 Merge pull request #3213 from monopole/pinToCli-utils_v0.21.1
Pin to cli-utils_v0.21.1 kyaml_v0.9.4
2020-11-11 13:40:50 -08:00
jregan
636c9fcddf Pin to cli-utils_v0.21.1 kyaml_v0.9.4 2020-11-11 13:26:05 -08:00
Kubernetes Prow Robot
333945d361 Merge pull request #3207 from runewake2/local-presubmit
Skip multi-mod check if PULL_NUMBER unset
2020-11-11 08:34:29 -08:00
Phillip Wittrock
afff3ce5ab update docs site 2020-11-11 08:30:00 -08:00
Phillip Wittrock
71b763888c Remove duplicate kustomize docs content 2020-11-11 08:29:43 -08:00
Jeff Regan
c5cd539b01 Merge pull request #3118 from brianpursley/kustomize-2893
Implement WNode methods
2020-11-11 08:15:29 -08:00
Sam Wronski
4b89c2afa2 Skip multi-mod check if PULL_NUMBER unset 2020-11-10 16:22:48 -08:00
Kubernetes Prow Robot
630fc9b973 Merge pull request #3206 from monopole/disableHelmTests
Disable helm inflator tests.
2020-11-10 16:12:42 -08:00
jregan
a468743b81 Disable helm inflator tests. 2020-11-10 15:22:25 -08:00
Kubernetes Prow Robot
e9a74b87e3 Merge pull request #3203 from Shell32-Natsu/fix-helm
fix helm chart inflation generator
2020-11-10 10:36:41 -08:00
Donny Xia
64f8d2ae38 add one more test 2020-11-10 10:25:05 -08:00
Donny Xia
5ab320c216 fix helm chart inflation generator 2020-11-10 10:03:26 -08:00
Kubernetes Prow Robot
6131f86d23 Merge pull request #3197 from Shell32-Natsu/doc
add link for component reference
2020-11-10 09:14:40 -08:00
Jeff Regan
e7609559ce Merge pull request #3201 from monopole/tmpRemoveCheck
Temporarily remove cross-module PR check.
2020-11-10 08:23:12 -08:00
Donny Xia
c2bdac7a6b Merge pull request #3200 from natasha41575/CleanTestComments
cleaned comments
2020-11-09 21:30:35 -08:00
Jeffrey Regan
4cc2c4f623 Temporarily remove cross-module PR check. 2020-11-09 20:47:06 -08:00
Natasha Sarkar
155c42679c cleaned comments 2020-11-09 20:17:51 -08:00
Donny Xia
88239445ce add link for component reference 2020-11-09 12:05:06 -08:00
Kubernetes Prow Robot
d66fc462ec Merge pull request #3159 from natasha41575/MergeKeyList
use merge key list instead of a single merge key
2020-11-09 11:51:58 -08:00
Natasha Sarkar
6788af083b updated tests for multiple merge keys 2020-11-09 11:35:37 -08:00
Natasha Sarkar
df0576a270 use merge key tuple instead of single merge key 2020-11-09 11:34:31 -08:00
Jeff Regan
f4d8ebb1da Merge pull request #3182 from pwittrock/master
Redirect kustomize site to the unified site
2020-11-07 08:59:07 -08:00
Kubernetes Prow Robot
0acac39640 Merge pull request #3192 from Shell32-Natsu/multierror
Improve the readability for multiple errors in kusttarget
2020-11-06 17:21:38 -08:00
Donny Xia
65db82df0c Merge pull request #3177 from Shell32-Natsu/json-patch
Improve json patch plugin
2020-11-06 16:17:24 -08:00
Donny Xia
68951bb37e format 2020-11-06 15:38:33 -08:00
Donny Xia
b18910aa6d format 2020-11-06 15:38:18 -08:00
Donny Xia
f780f7a3c2 update go.sum 2020-11-06 15:18:41 -08:00
Donny Xia
7966386615 improve format 2020-11-06 15:17:56 -08:00
Donny Xia
2130ba72cc improve format 2020-11-06 15:17:43 -08:00
Donny Xia
94d26ba53a improve the readability for multiple errors 2020-11-06 15:16:48 -08:00
Jeff Regan
c53f31ca4f Merge pull request #3169 from Shell32-Natsu/patch-target
support regex in GVK selection
2020-11-06 15:15:40 -08:00
Jeff Regan
b58075cbc3 Merge pull request #3176 from natasha41575/ElementSetterList
add ElementSetterList and ElementMatcherList to fns.go
2020-11-06 13:40:48 -08:00
Jeff Regan
b3e82a2fe7 Merge pull request #3187 from runewake2/multi-module-golang
Run multi-module check during presubmit
2020-11-06 13:33:29 -08:00
Donny Xia
78c26f55b5 support regex in GVK selection 2020-11-06 13:23:55 -08:00
Jeff Regan
ec2a6e4e4b Update Makefile 2020-11-06 13:15:43 -08:00
Natasha Sarkar
886f73aa0f added test case for no values 2020-11-06 13:14:25 -08:00
Natasha Sarkar
73d91dda6e changed handling of empty values 2020-11-06 11:42:17 -08:00
Natasha Sarkar
9f06376ab2 updated associative sequence 2020-11-05 17:22:54 -08:00
Natasha Sarkar
e785bab474 updated matchelementlist 2020-11-05 17:03:52 -08:00
Natasha Sarkar
8f80a898b6 removed elementsetterlist and updated elementsetter 2020-11-05 16:50:18 -08:00
Sam Wronski
fe84d119d6 Use gomodule when running prchecker 2020-11-05 16:03:36 -08:00
Sam Wronski
03b847a749 Use PULL_NUMBER env from prow 2020-11-05 15:44:40 -08:00
Sam Wronski
9d2f257acf Install dependencies from go module 2020-11-05 15:28:37 -08:00
Jeff Regan
129b25ceff Merge pull request #3167 from Shell32-Natsu/patch-test
re-enable test for edit patch add
2020-11-05 15:07:14 -08:00
Jeff Regan
57f4ea5354 Merge pull request #3166 from phanimarupaka/DeferOpenAPICleanup
Defer openAPI cleanup
2020-11-05 14:48:00 -08:00
Phani Teja Marupaka
ec2cc2d421 Defer openAPI cleanup 2020-11-05 13:49:43 -08:00
Sam Wronski
712eb6d276 Refactor changeset spanning function naming 2020-11-05 12:23:45 -08:00
Natasha Sarkar
a04e3a575c added test case for different length keys/values 2020-11-05 12:19:54 -08:00
Natasha Sarkar
03e2fed925 checked array length 2020-11-05 12:16:17 -08:00
Jeff Regan
c37b3b2525 Merge pull request #3170 from natasha41575/MultipleMergeKeyTests
added tests for merge key tuple behavior
2020-11-05 12:12:59 -08:00
Donny Xia
ceeba8764f update Makefile 2020-11-05 12:06:06 -08:00
Donny Xia
04d133a66f re-enable test for edit patch add 2020-11-05 12:06:06 -08:00
Natasha Sarkar
99aaa80e1d updated stale comments 2020-11-05 11:40:36 -08:00
Natasha Sarkar
1f806b0aa2 add elementsetterlist and elementmatcherlist to fns.go 2020-11-05 11:37:45 -08:00
Sam Wronski
1f697e3792 Run multi-module check during presubmit 2020-11-05 11:21:15 -08:00
Alexey Odinokov
28cdcc2e46 Allowing RunFns not to stop on empty result
Introducing the additional flag
ContinueOnEmptyResult that is false by default
to keep compatibility with the previous behavior.
Based on [1]

[1]
https://github.com/kubernetes-sigs/kustomize/pull/3112
2020-11-05 07:19:20 +00:00
Natasha Sarkar
c0ecd1d1ad added more tests 2020-11-04 19:07:58 -08:00
Natasha Sarkar
3923c63182 added some tests to merge3/element_test.go 2020-11-04 19:07:58 -08:00
Natasha Sarkar
9943e74187 updated comments 2020-11-04 19:07:58 -08:00
Natasha Sarkar
3b504fa3e5 added StringList set 2020-11-04 19:07:58 -08:00
Kubernetes Prow Robot
9fb25fc5a7 Merge pull request #3139 from runewake2/multi-module-golang
Update Multi Module Check to Scan Commits
2020-11-04 12:14:52 -08:00
Phillip Wittrock
4d99217a7c Build kustomize docs site with redirects to new unified at cli-experimental 2020-11-04 11:18:56 -08:00
Phillip Wittrock
0834e152b2 Redirect kustomize docs to the new unified site. 2020-11-04 11:15:40 -08:00
Donny Xia
ff276af317 use same logic with path transformer 2020-11-03 17:14:08 -08:00
Donny Xia
3b79944190 improve target in JSON6902 transformer 2020-11-03 17:13:43 -08:00
Kubernetes Prow Robot
d8d57eae29 Merge pull request #3174 from Shell32-Natsu/elementsetter-test
add tests for ElementSetter
2020-11-03 15:42:04 -08:00
Donny Xia
c803ca83a4 fix linter error 2020-11-03 15:29:01 -08:00
Donny Xia
6bed275234 add more tests for ElementSetter 2020-11-03 15:23:34 -08:00
Jeff Regan
8e5df26e4c Merge pull request #3173 from natasha41575/StringListSet
added StringList set
2020-11-03 13:34:56 -08:00
Donny Xia
3fed68b694 clarify the comments 2020-11-03 13:09:12 -08:00
Natasha Sarkar
0e59c36d03 added StringList set 2020-11-03 12:42:37 -08:00
Jeff Regan
00fdf71dc3 Merge pull request #2951 from dearchap/cm_merge
Add ability to specify behavior adding configmap
2020-11-03 12:02:45 -08:00
Donny Xia
be327e7443 add tests for ElementSetter 2020-11-03 11:54:44 -08:00
Donny Xia
be8d2fe016 Merge pull request #3161 from mikebz/mb_remove_travis
removing travis references
2020-11-03 11:15:58 -08:00
Mike Borozdin
072ae36fe6 removing travis references 2020-11-03 10:04:42 -08:00
Naveen Gogineni
b5d8b8d258 Add ability to specify behavior when running "kustomize edit add configmap" command 2020-11-02 16:09:51 -05:00
Jeff Regan
e6b21174f1 Merge pull request #3143 from Shell32-Natsu/helm-inflator-builtin
Convert helminflator to builtin plugin HelmChartGenerator
2020-11-02 12:30:02 -08:00
Donny Xia
49094cf999 Merge pull request #3164 from Shell32-Natsu/cloudbuild
fix version in releasing/cloudbuild_kustomize_image.yaml
2020-11-02 11:12:11 -08:00
Donny Xia
d2c7db6ca0 update chart examples 2020-11-02 11:03:31 -08:00
Donny Xia
d141f9b973 fix version 2020-11-02 10:52:04 -08:00
Sam Wronski
877da8da6d Update module span to check commits
- Use regex to detect if check should run
- Update scan to be per-commit
2020-11-02 10:29:40 -08:00
Kubernetes Prow Robot
8596e63203 Merge pull request #3163 from Shell32-Natsu/cloudbuild
update version in image creation
2020-11-02 10:16:15 -08:00
Donny Xia
b2df55e9d7 update version in image creation 2020-11-02 09:55:06 -08:00
Donny Xia
6daf8f8820 Merge pull request #3160 from Shell32-Natsu/cloudbuild
update cloudbuild for image pushing job
2020-11-02 09:39:48 -08:00
Donny Xia
e75d4fc87d convert helm inflator to builtin plugin 2020-10-30 23:18:54 -07:00
Donny Xia
9ae07634f2 update cloudbuild for image pushing job 2020-10-30 12:19:17 -07:00
Donny Xia
981959ffcf Merge pull request #3155 from radTuti/master
fix binary install script
2020-10-29 22:01:18 -07:00
tuti
dc31321b05 fix binary install script 2020-10-29 17:51:54 -07:00
Kubernetes Prow Robot
64dc3e14ff Merge pull request #3153 from Shell32-Natsu/master
unpin modules
2020-10-29 16:32:05 -07:00
Donny Xia
da0893bac0 unpin modules 2020-10-29 16:17:45 -07:00
Kubernetes Prow Robot
c1747439cd Merge pull request #3152 from Shell32-Natsu/master
Pin to api 0.6.4
2020-10-29 16:06:05 -07:00
Donny Xia
f68986827b Pin to api 0.6.4 2020-10-29 15:53:34 -07:00
brianpursley
027b7d61ea Implemented the following WNode methods:
* GetFieldValue
* GetSlice
* GetString
* Map
* SetAnnotations
* SetGvk
* SetLabels
* SetName
* SetNamespace
2020-10-18 20:09:42 -04:00
13027 changed files with 164340 additions and 1015123 deletions

View File

@@ -8,7 +8,7 @@ assignees: ""
---
<!--
Please read this page: https://kubernetes-sigs.github.io/kustomize/contributing/bugs/ before
Please read this page: https://kubectl.docs.kubernetes.io/contributing/kustomize/bugs/ before
filing a bug
-->

6
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"

View File

@@ -6,6 +6,9 @@ on:
pull_request:
branches: [ master ]
permissions:
contents: read
jobs:
lint:
@@ -14,18 +17,21 @@ jobs:
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ^1.13
go-version: ^1.16
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Lint
run: ./travis/kyaml-pre-commit.sh
env:
KUSTOMIZE_DOCKER_E2E: false # don't need to do e2e tests for linting
run: make lint
- name: Verify boilerplate
run: make check-license
test-linux:
name: Test Linux
@@ -33,21 +39,16 @@ jobs:
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ^1.13
go-version: ^1.16
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Test kyaml
run: go test -cover ./...
working-directory: ./kyaml
- name: Test cmd/config
run: go test -cover ./...
working-directory: ./cmd/config
- name: Test all modules
run: make test-unit-non-plugin
env:
KUSTOMIZE_DOCKER_E2E: true
@@ -57,21 +58,16 @@ jobs:
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ^1.13
go-version: ^1.16
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Test kyaml
run: go test -cover ./...
working-directory: ./kyaml
- name: Test cmd/config
run: go test -cover ./...
working-directory: ./cmd/config
- name: Test all modules
run: make test-unit-non-plugin
env:
KUSTOMIZE_DOCKER_E2E: false # docker not installed on mac
@@ -81,9 +77,9 @@ jobs:
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: ^1.13
go-version: ^1.16
id: go
- name: Check out code into the Go module directory
@@ -98,3 +94,9 @@ jobs:
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

10
.gitignore vendored
View File

@@ -21,3 +21,13 @@
*.DS_store
.bin
# Hugo site
publishedSite/
site/public/
site/resources/
site/.hugo_build.lock
**/node_modules/
# goreleaser artifacts
**/dist/

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "site/themes/docsy"]
path = site/themes/docsy
url = https://github.com/google/docsy.git

View File

@@ -1,50 +0,0 @@
run:
deadline: 5m
linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
# - dogsled
- dupl
# - errcheck
# - funlen
# - gochecknoinits
- goconst
# - gocritic
- gocyclo
- gofmt
- goimports
- golint
- gosec
- gosimple
- govet
- ineffassign
- interfacer
- lll
- misspell
- nakedret
# - scopelint
- staticcheck
- structcheck
# stylecheck demands that acronyms not be treated as words
# in camelCase, so JsonOp become JSONOp, etc. Yuck.
# - stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
# - whitespace
linters-settings:
dupl:
threshold: 400
lll:
line-length: 170
gocyclo:
min-complexity: 15
golint:
min-confidence: 0.85

136
.golangci.yml Normal file
View File

@@ -0,0 +1,136 @@
# Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
run:
deadline: 5m
linters:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- asciicheck
- bidichk
- bodyclose
- contextcheck
# - cyclop
- deadcode
- depguard
- dogsled
- dupl
- durationcheck
- errcheck
- errname
- errorlint
- exhaustive
# - exhaustivestruct
- exportloopref
# - forbidigo
- forcetypeassert
# - funlen
# - gci
- gochecknoglobals
- gochecknoinits
# - gocognit
- goconst
- gocritic
- gocyclo
# - godot
# - godox
- goerr113
- gofmt
# - gofumpt
- goheader
- goimports
- gomnd
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- gosimple
- govet
# - ifshort # too many false positives
- importas
- ineffassign
# - ireturn
- lll
- makezero
- misspell
- nakedret
- nestif
- nilerr
# - nilnil
# - nlreturn
# - noctx
- nolintlint
# - paralleltest
- prealloc
- predeclared
- promlinter
- revive
- rowserrcheck
- sqlclosecheck
- staticcheck
- structcheck
# - stylecheck
- tagliatelle
- tenv
- testpackage
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- varcheck
# - varnamelen
- wastedassign
- whitespace
- wrapcheck
# - wsl
linters-settings:
dupl:
threshold: 400
lll:
line-length: 170
gocyclo:
min-complexity: 30
revive:
rules:
- name: var-naming
arguments:
- [ "ID", "API", "JSON" ] # AllowList
- [ ] # DenyList
gomoddirectives:
replace-local: true
gosec:
config:
G306: "0644"
gomnd:
ignored-functions:
- ioutil.WriteFile
wrapcheck:
ignoreSigs:
# defaults
- .Errorf(
- errors.New(
- errors.Unwrap(
- .Wrap(
- .Wrapf(
- .WithMessage(
- .WithMessagef(
- .WithStack(
# from kyaml's errors package
- .WrapPrefixf(
issues:
new-from-rev: c94b5d8f2 # enables us to enforce a larger set of linters for new code than pass on existing code
max-same-issues: 0
exclude-rules:
- linters:
- revive
text: "don't use leading"
- linters:
- staticcheck
text: "SA1019: kioutil.Legacy"

299
ARCHITECTURE.md Normal file
View File

@@ -0,0 +1,299 @@
# Architecture
* _Updated: December 2021_
This document describes the repository organization and the kustomize
build process. It's meant to lower the barrier to learning and
contributing to the code base.
If not kept up to date, it will just be a historical snapshot.
## Repository layout
[human-edited docs]: https://github.com/kubernetes-sigs/cli-experimental/tree/master/site
[generated docs]: https://github.com/kubernetes-sigs/cli-experimental/tree/master/docs
[rendered docs]: https://kubectl.docs.kubernetes.io
[openapi]: https://kubernetes.io/blog/2016/12/kubernetes-supports-openapi
[`api` module]: https://github.com/kubernetes-sigs/kustomize/blob/master/api/go.mod
[`api`]: #the-api-module
[`cmd/config` module]: https://github.com/kubernetes-sigs/kustomize/blob/master/cmd/config/go.mod
[`cmd/config`]: #the-cmdconfig-module
[`kustomize` module]: https://github.com/kubernetes-sigs/kustomize/blob/master/kustomize/go.mod
[`kustomize`]: #the-kustomize-module
[`kyaml` module]: https://github.com/kubernetes-sigs/kustomize/blob/master/kyaml/go.mod
[`kyaml`]: #the-kyaml-module
[`kyaml/kio.Filter`]: https://github.com/Kubernetes-sigs/kustomize/blob/master/kyaml/kio/kio.go
[`go-yaml`]: https://github.com/go-yaml/yaml/tree/v3
[3922]: https://github.com/kubernetes-sigs/kustomize/issues/3922
| directory | purpose |
| ---------: | :---------- |
| `api` | The [`api`] module, holding high level kustomize code, suitable for import by other programs. |
| `cmd` | Various Go programs aiding repo management. See also `hack`. As an outlier, includes the special [`cmd/config`] module. |
| `docs` | Old home of documentation; contains pointers to new homes: [human-edited docs], [generated docs] and [rendered docs]. |
| `examples` | Full kustomization examples that run as pre-merge tests. |
| `functions` | Examples of plugins in KRM function form. TODO([3922]): Move under `plugin`. |
| `hack` | Various shell scripts to help with code management. |
| `kustomize` | The [`kustomize`] module holds the `main.go` for kustomize. |
| `kyaml` | The [`kyaml`] module, holding Kubernetes-specific YAML editing packages used by the [`api`] module. Wraps [`go-yaml`] v3.|
| `plugin` | Examples of Kustomize plugins. |
| `releasing` | Instructions for releasing the various modules. |
| `site` | Old generated documentation, kept to provide redirection links to the new docs. |
## Modules
[semantically versioned]: https://semver.org
[Go modules]: https://github.com/golang/go/wiki/Modules
The [Go modules] in the kustomize repository are [semantically versioned].
### `kustomize`
> _Depends on [`api`], [`cmd/config`], [`kyaml`]_
The [`kustomize` module] contains the `main.go` for `kustomize`, buildable with
```
(cd kustomize; go install .)
```
[appears in kubectl]: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/kubectl/pkg/cmd/kustomize/kustomize.go
Below this are packages containing
[cobra](http://github.com/spf13/cobra) commands implementing `build`,
`edit`, `fix`, etc., packages linked together by `main.go`.
These command packages are intentionally public, semantically
versioned, and can be used in other programs. Specifically, the
`kustomize build` command [appears in kubectl] as `kubectl kustomize`.
The code in the `build` package is dominated by flag validation,
with minimal business logic. The critical lines are something
like
```
# Make a kustomizer.
k := krusty.MakeKustomizer(
HonorKustomizeFlags(krusty.MakeDefaultOptions()),
)
# Run the kustomizer, sending location of kustomization.yaml
m := k.Run(fSys, "/path/to/dir")
# Write the result as YAML.
writer.Write(m.AsYaml())
```
The `krusty` package is in the [`api`] module.
### `api`
> _Depends on [`kyaml`] and code generated from builtin plugin modules_
The [`api` module] is used by CLI programs like `kustomize` and `kubectl`
to read and honor `kustomization.yaml` files and all that implies.
The main public packages in the [`api` module] are
| package | |
| --------: | :---------- |
| `filters` | Implementations of [`kyaml/kio.Filter`] used by kustomize to transform Kubernetes objects. |
| `konfig` | Configuration methods and constants in the kustomize API. |
| `krusty` | Primary API entry point. Holds the kustomizer and hundreds of tests for it. |
| `loader` | Loads kustomization files and the files they refer to, enforcing security rules. |
| `resmap` | The primary internal data structure over which the kustomizer and filters work. |
| `types` | The `Kustomization` object and ancillary structs. |
### `cmd/config`
> _Depends on [`kyaml`]_
This module contains cobra commands and kyaml-based functionality to
provide unix-like file manipulation commands to kustomize like `grep`
and `tree`. These commands may be included in any program that
manipulates k8s YAML (e.g. kustomize).
### `kyaml`
> _Has no in-repo dependence_
The [`kyaml` module] is a kubernetes-focussed enhancement of [go-yaml].
The YAML manipulation performed by a kustomize is based on these libraries.
These libraries evolve independently of kustomize, and other programs depend on them.
The key public packages in the [`kyaml` module] include
| package | |
| --------: | :---------- |
| `errors` | Wrapper for the go-errors/errors lib |
| `filesys` | A kustomize-specific file system abstraction, to ease writing tests |
| `fn/framework` | An SDK for writing KRM Functions in Go |
| `fn/runtime` | Implements the runtime for KRM Function extensions |
| `kio` | Libraries for reading and writing collections of Kubernetes resources as RNodes |
| `openapi` | Loads and accesses openapi schemas for schema-aware resource manipultaion |
| `resid` | Representations to aid in unique identification of Kubernetes resources |
| `yaml` | A Kubernetes-focused wrapper of [go-yaml], notably including the RNode object |
-------
## How _kustomize build_ works
The command `kustomize build` accepts a single string argument,
which must resolve to a directory, possibly in a git repository,
called the _kustomization root_.
This directory must contain a file called `kustomization.yaml`, with
YAML that marshals into a single instance of a `Kustomization` object.
For the remainder of this document, the word _kustomization_ refers to
either of these things.
This kustomization is the access point to a directed, acyclic graph of
Kubernetes objects, including other kustomizations, to include in a
build.
Execution of `build` starts and ends in the [`api`] module,
frequently dipping into the [`kyaml`] module for lower level
YAML manipulation.
### The `build` flow
- Validate command lines arguments and flags.
- Make a `Kustomizer` as a function of those arguments.
- Call `Run` on the kustomizer, passing it the path to the
kustomization.
`Run` returns an instance of `ResMap`, the `api` package's
representation of a set of kubernetes `Resource` objects.
This structure offers resource lookup methods (map behavior),
but also retains the resources in the order they were
specified in kustomization files (list behavior).
Post-run, the objects are fully hydrated, per the
instructions in the kustomization.
- Marshal the objects as YAML to a file or `stdout`.
### The `Run` function
- Create various objects
- A `ResMap` factory.
Makes `ResMaps` from byte streams, other `ResMaps`, etc.
- A file `loader.Loader`.
It's fed an appropriate set of restrictions, and the path to the kustomization.
- A plugin loader.
It finds plugins (transformers, generators or validators)
and prepares them for running.
- A `KustTarget` encapsulating all of the above.
A KustTarget contains one `Kustomization` and represents
everything that kustomization can reach. This will include
other `KustTarget` instances, each having a smaller purview than
the one referencing it.
- Call `KustTarget.Load` to load its kustomization.
This step deals with deprecations and field changes.
- Load [openapi] data specified by the kustomization.
This is needed to recognize k8s kinds and their special
properties, e.g. which kinds are cluster-scoped, which kinds
refer to others, etc.
- Call `KustTarget.makeCustomizedResmap` to create the `ResMap` result.
This visits everything referenced by the kustomization,
performing all generation, transformation and validation.
- Finish the `Run` with
- Optional reordering of objects in `ResMap`, overriding the
FIFO rule.
- Optional addition of _kustomize build annotations_ to the
resources. E.g. from which repo and file the resource was
read, the fact that kustomize touched the resource, etc.
These kustomize-specific annotations are intended for
server-side data analytics, file structure traceability and
reconstruction, etc.
### The `makeCustomizedResmap` function
This function starts the process of object transformation,
as well as accumulation of recursively referenced data.
- Call `ra := KustTarget.AccumulateTarget`.
The result, `ra`, is a resource accumulator that contains
everything referred to by the current kustomization, now fully
hydrated.
- Uniquify names of generated objects by appending content hashes.
This cannot be done until the objects are complete.
- Fix all name references (given that names may have changed).
E.g. if a ConfigMaps was given a generated name, all objects that
refer to that ConfigMap must be given its name.
- Resolve vars, replacing them with whatever they refer to (a legacy feature).
### The `AccumulateTarget` function
- Call `AccumulateResources` over the `resources` field (this can recurse).
- Call `AccumulateComponents` over the `components` field (this can recurse),
- Load legacy (pre-plugin) global kustomize configuration,
- Load legacy (pre-openapi) _Custom Resource Definition_ data.
- In the context of the data loaded above, run the kustomization's
- generators,
- transformers,
- and validators.
- Accumulate `vars` (make note of them for later replacement).
### `AccumulateResources` and component accumulation
- If the path is a file:
- Accumulate the objects in the file (treating them
as opaque kubernetes objects).
- If the path is a directory:
- Create a new `KustTarget` referring to that directory's kustomization.
- Call `subRa := KustTarget.AccumulateTarget`.
- Call `ra.MergeAccumulator(subRa)`
This completes a recursion.
- If the path is a git URL:
- Clone the repository to a temporary directory.
- Process the path optionally specified in the URL
as a path in the clone.
- If no path specified, work from the repository root.
That's as deep as this discussion will go.
The deeper this document goes into the details, the faster
it will get out of date.

View File

@@ -1,6 +1,25 @@
[SIG-CLI]: https://github.com/kubernetes/community/tree/master/sig-cli
[Slack channel]: https://kubernetes.slack.com/messages/kustomize
[Mailing list]: https://groups.google.com/forum/#!forum/kubernetes-sig-cli
[OWNERS file spec]: https://github.com/kubernetes/community/blob/master/contributors/guide/owners.md
[Kustomize OWNERS_ALIASES]: https://github.com/kubernetes-sigs/kustomize/blob/8049f7b1af52e8a7ec26faf6cf714f560d0043c5/OWNERS_ALIASES
[SIG-CLI Teams]: https://github.com/kubernetes/org/blob/main/config/kubernetes-sigs/sig-cli/teams.yaml
[Github permissions]: https://docs.github.com/en/organizations/managing-access-to-your-organizations-repositories/repository-permission-levels-for-an-organization#repository-access-for-each-permission-level
[Contributor License Agreement]: https://git.k8s.io/community/CLA.md
[Kubernetes Contributor Guide]: http://git.k8s.io/community/contributors/guide
[Contributor Cheat Sheet]: https://git.k8s.io/community/contributors/guide/contributor-cheatsheet/README.md
[CNCF Code of Conduct]: https://github.com/cncf/foundation/blob/master/code-of-conduct.md
[Kubernetes Community Membership]: https://github.com/kubernetes/community/blob/master/community-membership.md
[Contribution Guide]: https://kubectl.docs.kubernetes.io/contributing/kustomize/
[MacOS Dev Guide]: https://kubectl.docs.kubernetes.io/contributing/kustomize/mac/
[Windows Dev Guide]: https://kubectl.docs.kubernetes.io/contributing/kustomize/windows/
# Contributing Guidelines
Welcome to Kubernetes. We are excited about the prospect of you joining our [community](https://github.com/kubernetes/community)! The Kubernetes community abides by the CNCF [code of conduct](code-of-conduct.md). Here is an excerpt:
Welcome to Kubernetes. We are excited about the prospect of you joining our [community](https://github.com/kubernetes/community)! The Kubernetes community abides by the [CNCF Code of Conduct]. Here is an excerpt:
_As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities._
@@ -8,19 +27,45 @@ _As contributors and maintainers of this project, and in the interest of fosteri
Dev guides:
- [Mac](docs/macDevGuide.md)
- [Contribution Guide]
- [MacOS Dev Guide]
- [Windows Dev Guide]
We have full documentation on how to get started contributing here:
General resources for contributors:
- [Contributor License Agreement](https://git.k8s.io/community/CLA.md) Kubernetes projects require that you sign a Contributor License Agreement (CLA) before we can accept your pull requests
- [Kubernetes Contributor Guide](http://git.k8s.io/community/contributors/guide) - Main contributor documentation, or you can just jump directly to the [contributing section](http://git.k8s.io/community/contributors/guide#contributing)
- [Contributor Cheat Sheet](https://git.k8s.io/community/contributors/guide/contributor-cheatsheet/README.md) - Common resources for existing developers
- [Contributor License Agreement] - Kubernetes projects require that you sign a Contributor License Agreement (CLA) before we can accept your pull requests.
- [Kubernetes Contributor Guide] - Main contributor documentation.
- [Contributor Cheat Sheet] - Common resources for existing developers.
Here are some additional ideas to help you get started with Kustomize:
- Attend a Kustomize Bug Scrub. Check the [SIG-CLI] meetings list to find the next one.
- Help triage issues by confirming validity and applying the appropriate `kind` label (e.g. comment `/kind bug`).
- Pick up an issue to fix. Issues with the `help-wanted` label are a good place to start, but you can also look for any issue with the `triage/accepted` label and no assignee. Remember to `/assign` yourself to let others know you're working on it.
- Help confirm new issues labelled `kind/bug` by reproducing them with the latest release.
- Support Kustomize users by responding to questions on issues labelled `kind/support` or in the [Slack channel].
## Mentorship
- [Mentoring Initiatives](https://git.k8s.io/community/mentoring) - We have a diverse set of mentorship programs available that are always looking for volunteers!
## Contributor Ladder
Kustomize follows the [Kubernetes Community Membership] contributor ladder. Roles are as follows:
1. Contributor: Anyone who actively contributes code, issues or reviews to the project. All contributors must sign the [Contributor License Agreement].
1. Reviewer: Contributors with a history of review and authorship on Kustomize. Has LGTM rights on the Kustomize repo (as do all kubernetes-sigs org members). Active contributors are encouraged to join the reviewers list to be automatically pinged on PRs.
1. Approver: Highly experienced active reviewer and contributor to Kustomize. Has both LTGM and approval rights on the Kustomize repo, as well as "maintain" [Github permissions].
1. Owner: Approver who sets technical direction and makes or approves design decisions for the project. Has LGTM and approval rights on the Kustomize repo as well as "admin" [Github permissions].
The kyaml module within the Kustomize repo has additional owners following the same ladder.
Administrative notes:
- The [OWNERS file spec] is a useful resources in making changes.
- Maintainers and admins must be added to the appropriate lists in both [Kustomize OWNERS_ALIASES] and [SIG-CLI Teams]. If this isn't done, the individual in question will lack either PR approval rights (Kustomize list) or the appropriate Github repository permissions (community list).
## Contact Information
- [Slack channel](https://kubernetes.slack.com/messages/sig-cli)
- [Mailing list](https://groups.google.com/forum/#!forum/kubernetes-sig-cli)
- [Slack channel]
- [Mailing list]

401
Makefile
View File

@@ -3,231 +3,159 @@
#
# Makefile for kustomize CLI and API.
MYGOBIN := $(shell go env GOPATH)/bin
SHELL := /bin/bash
LATEST_V4_RELEASE=v4.5.4
SHELL := /usr/bin/env bash
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)
.PHONY: all
all: verify-kustomize
# Provide defaults for REPO_OWNER and REPO_NAME if not present.
# Typically these values would be provided by Prow.
ifndef REPO_OWNER
REPO_OWNER := "kubernetes-sigs"
endif
.PHONY: verify-kustomize
verify-kustomize: \
lint-kustomize \
test-unit-kustomize-all \
test-examples-kustomize-against-HEAD \
test-examples-kustomize-against-3.8.0 \
test-examples-kustomize-against-3.8.2
ifndef REPO_NAME
REPO_NAME := "kustomize"
endif
# The following target referenced by a file in
# https://github.com/kubernetes/test-infra/tree/master/config/jobs/kubernetes-sigs/kustomize
.PHONY: prow-presubmit-check
prow-presubmit-check: \
lint-kustomize \
test-unit-kustomize-all \
test-unit-cmd-all \
test-go-mod \
test-examples-kustomize-against-HEAD \
test-examples-kustomize-against-3.8.0 \
test-examples-kustomize-against-3.8.2
.PHONY: verify-kustomize-e2e
verify-kustomize-e2e: test-examples-e2e-kustomize
# --- Plugins ---
include Makefile-plugins.mk
# Other builds in this repo might want a different linter version.
# Without one Makefile to rule them all, the different makes
# cannot assume that golanci-lint is at the version they want
# since everything uses the same implicit GOPATH.
# This installs in a temp dir to avoid overwriting someone else's
# linter, then installs in MYGOBIN with a new name.
# Version pinned by hack/go.mod
$(MYGOBIN)/golangci-lint-kustomize:
( \
set -e; \
cd hack; \
GO111MODULE=on go build -tags=tools -o $(MYGOBIN)/golangci-lint-kustomize github.com/golangci/golangci-lint/cmd/golangci-lint; \
)
# Install from version specified in api/go.mod.
$(MYGOBIN)/mdrip:
cd api; \
go install github.com/monopole/mdrip
# --- Tool management ---
include Makefile-tools.mk
# Install from version specified in api/go.mod.
$(MYGOBIN)/stringer:
cd api; \
go install golang.org/x/tools/cmd/stringer
.PHONY: install-tools
install-tools: \
install-local-tools \
install-out-of-tree-tools
# Install from version specified in api/go.mod.
$(MYGOBIN)/goimports:
cd api; \
go install golang.org/x/tools/cmd/goimports
.PHONY: uninstall-tools
uninstall-tools: \
uninstall-local-tools \
uninstall-out-of-tree-tools
.PHONY: install-local-tools
install-local-tools: \
$(MYGOBIN)/gorepomod \
$(MYGOBIN)/k8scopy \
$(MYGOBIN)/pluginator
.PHONY: uninstall-local-tools
uninstall-local-tools:
rm -f $(MYGOBIN)/gorepomod
rm -f $(MYGOBIN)/k8scopy
rm -f $(MYGOBIN)/pluginator
# Build from local source.
$(MYGOBIN)/gorepomod:
cd cmd/gorepomod; \
go install .
# Build from local source.
$(MYGOBIN)/k8scopy:
cd cmd/k8scopy; \
go install .
# Build from local source.
$(MYGOBIN)/pluginator:
cd cmd/pluginator; \
go install .
# Build from local source.
$(MYGOBIN)/prchecker:
cd cmd/prchecker; \
go install .
# --- Build targets ---
# Build from local source.
$(MYGOBIN)/kustomize:
$(MYGOBIN)/kustomize: build-kustomize-api
cd kustomize; \
go install .
.PHONY: install-tools
install-tools: \
$(MYGOBIN)/goimports \
$(MYGOBIN)/golangci-lint-kustomize \
$(MYGOBIN)/gh \
$(MYGOBIN)/gorepomod \
$(MYGOBIN)/mdrip \
$(MYGOBIN)/pluginator \
$(MYGOBIN)/prchecker \
$(MYGOBIN)/stringer
### Begin kustomize plugin rules.
#
# The rules to deal with builtin plugins are a bit
# complicated because
#
# - Every builtin plugin is a Go plugin -
# meaning it gets its own module directory
# (outside of the api module) with Go
# code in a 'main' package per Go plugin rules.
# - kustomize locates plugins using the
# 'apiVersion' and 'kind' fields from the
# plugin config file.
# - k8s wants CamelCase in 'kind' fields.
# - The module name (the last name in the path)
# must be the lowercased 'kind' of the
# plugin because Go and related tools
# demand lowercase in import paths, but
# allow CamelCase in file names.
# - the generated code must live in the api
# module (it's linked into the api).
# Where all generated builtin plugin code should go.
pGen=api/builtins
# Where the builtin Go plugin modules live.
pSrc=plugin/builtin
_builtinplugins = \
AnnotationsTransformer.go \
ConfigMapGenerator.go \
HashTransformer.go \
ImageTagTransformer.go \
LabelTransformer.go \
LegacyOrderTransformer.go \
NamespaceTransformer.go \
PatchJson6902Transformer.go \
PatchStrategicMergeTransformer.go \
PatchTransformer.go \
PrefixSuffixTransformer.go \
ReplicaCountTransformer.go \
SecretGenerator.go \
ValueAddTransformer.go
# Maintaining this explicit list of generated files, and
# adding it as a dependency to a few targets, to assure
# they get recreated if deleted. The rules below on how
# to make them don't, by themselves, assure they will be
# recreated if deleted.
builtinplugins = $(patsubst %,$(pGen)/%,$(_builtinplugins))
# These rules are verbose, but assure that if a source file
# is modified, the corresponding generated file, and only
# that file, will be recreated.
$(pGen)/AnnotationsTransformer.go: $(pSrc)/annotationstransformer/AnnotationsTransformer.go
$(pGen)/ConfigMapGenerator.go: $(pSrc)/configmapgenerator/ConfigMapGenerator.go
$(pGen)/HashTransformer.go: $(pSrc)/hashtransformer/HashTransformer.go
$(pGen)/ImageTagTransformer.go: $(pSrc)/imagetagtransformer/ImageTagTransformer.go
$(pGen)/LabelTransformer.go: $(pSrc)/labeltransformer/LabelTransformer.go
$(pGen)/LegacyOrderTransformer.go: $(pSrc)/legacyordertransformer/LegacyOrderTransformer.go
$(pGen)/NamespaceTransformer.go: $(pSrc)/namespacetransformer/NamespaceTransformer.go
$(pGen)/PatchJson6902Transformer.go: $(pSrc)/patchjson6902transformer/PatchJson6902Transformer.go
$(pGen)/PatchStrategicMergeTransformer.go: $(pSrc)/patchstrategicmergetransformer/PatchStrategicMergeTransformer.go
$(pGen)/PatchTransformer.go: $(pSrc)/patchtransformer/PatchTransformer.go
$(pGen)/PrefixSuffixTransformer.go: $(pSrc)/prefixsuffixtransformer/PrefixSuffixTransformer.go
$(pGen)/ReplicaCountTransformer.go: $(pSrc)/replicacounttransformer/ReplicaCountTransformer.go
$(pGen)/SecretGenerator.go: $(pSrc)/secretgenerator/SecretGenerator.go
$(pGen)/ValueAddTransformer.go: $(pSrc)/valueaddtransformer/ValueAddTransformer.go
# The (verbose but portable) Makefile way to convert to lowercase.
toLowerCase = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))
$(pGen)/%.go: $(MYGOBIN)/pluginator
@echo "generating $*"
( \
set -e; \
cd $(pSrc)/$(call toLowerCase,$*); \
go generate .; \
cd ../../../$(pGen); \
$(MYGOBIN)/goimports -w $*.go \
)
# Target is for debugging.
.PHONY: generate-kustomize-builtin-plugins
generate-kustomize-builtin-plugins: $(builtinplugins)
.PHONY: kustomize-external-go-plugin-build
kustomize-external-go-plugin-build:
./hack/buildExternalGoPlugins.sh ./plugin
.PHONY: kustomize-external-go-plugin-clean
kustomize-external-go-plugin-clean:
./hack/buildExternalGoPlugins.sh ./plugin clean
### End kustomize plugin rules.
.PHONY: lint-kustomize
lint-kustomize: install-tools $(builtinplugins)
cd api; \
$(MYGOBIN)/golangci-lint-kustomize -c ../.golangci-kustomize.yml run ./...
cd kustomize; \
$(MYGOBIN)/golangci-lint-kustomize -c ../.golangci-kustomize.yml run ./...
cd cmd/pluginator; \
$(MYGOBIN)/golangci-lint-kustomize -c ../../.golangci-kustomize.yml run ./...
kustomize: $(MYGOBIN)/kustomize
# Used to add non-default compilation flags when experimenting with
# plugin-to-api compatibility checks.
.PHONY: build-kustomize-api
build-kustomize-api: $(builtinplugins)
cd api; go build ./...
build-kustomize-api: $(MYGOBIN)/goimports $(builtinplugins)
cd api; $(MAKE) build
.PHONY: test-unit-kustomize-api
test-unit-kustomize-api: build-kustomize-api
cd api; go test ./... -ldflags "-X sigs.k8s.io/kustomize/api/provenance.version=v444.333.222"
.PHONY: generate-kustomize-api
generate-kustomize-api:
cd api; $(MAKE) generate
# --- Verification targets ---
.PHONY: verify-kustomize-repo
verify-kustomize-repo: \
install-tools \
lint \
check-license \
test-unit-all \
build-non-plugin-all \
test-go-mod \
test-examples-kustomize-against-HEAD \
test-examples-kustomize-against-v4-release
# The following target referenced by a file in
# https://github.com/kubernetes/test-infra/tree/master/config/jobs/kubernetes-sigs/kustomize
.PHONY: prow-presubmit-check
prow-presubmit-check: \
install-tools \
test-unit-kustomize-plugins \
test-go-mod \
build-non-plugin-all \
test-examples-kustomize-against-HEAD \
test-examples-kustomize-against-v4-release
.PHONY: license
license: $(MYGOBIN)/addlicense
./hack/add-license.sh run
.PHONY: check-license
check-license: $(MYGOBIN)/addlicense
./hack/add-license.sh check
.PHONY: lint
lint: $(MYGOBIN)/golangci-lint $(MYGOBIN)/goimports $(builtinplugins)
./hack/for-each-module.sh "make lint"
.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/*" 15
.PHONY: build-non-plugin-all
build-non-plugin-all:
./hack/for-each-module.sh "make build" "./plugin/*" 15
.PHONY: test-unit-kustomize-plugins
test-unit-kustomize-plugins:
./hack/testUnitKustomizePlugins.sh
.PHONY: test-unit-kustomize-cli
test-unit-kustomize-cli:
cd kustomize; go test ./...
.PHONY: test-unit-kustomize-all
test-unit-kustomize-all: \
test-unit-kustomize-api \
test-unit-kustomize-cli \
test-unit-kustomize-plugins
test-unit-cmd-all:
./travis/kyaml-pre-commit.sh
.PHONY: functions-examples-all
functions-examples-all:
for dir in $(abspath $(wildcard functions/examples/*/.)); do \
echo -e "\n---Running make tasks for function $$dir---"; \
set -e; \
cd $$dir; $(MAKE) all; \
done
test-go-mod:
./travis/check-go-mod.sh
./hack/for-each-module.sh "go list -m -json all > /dev/null && go mod tidy -v"
.PHONY:
test-examples-e2e-kustomize: $(MYGOBIN)/mdrip $(MYGOBIN)/kind
verify-kustomize-e2e: $(MYGOBIN)/mdrip $(MYGOBIN)/kind
( \
set -e; \
/bin/rm -f $(MYGOBIN)/kustomize; \
@@ -241,109 +169,16 @@ test-examples-kustomize-against-HEAD: $(MYGOBIN)/kustomize $(MYGOBIN)/mdrip
./hack/testExamplesAgainstKustomize.sh HEAD
.PHONY:
test-examples-kustomize-against-3.8.0: $(MYGOBIN)/mdrip
( \
set -e; \
tag=v3.8.0; \
/bin/rm -f $(MYGOBIN)/kustomize; \
echo "Installing kustomize $$tag."; \
GO111MODULE=on go get sigs.k8s.io/kustomize/kustomize/v3@$${tag}; \
./hack/testExamplesAgainstKustomize.sh $$tag; \
echo "Reinstalling kustomize from HEAD."; \
cd kustomize; go install .; \
)
test-examples-kustomize-against-v4-release: $(MYGOBIN)/mdrip
./hack/testExamplesAgainstKustomize.sh v4@$(LATEST_V4_RELEASE)
.PHONY:
test-examples-kustomize-against-3.8.2: $(MYGOBIN)/mdrip
( \
set -e; \
tag=v3.8.2; \
/bin/rm -f $(MYGOBIN)/kustomize; \
echo "Installing kustomize $$tag."; \
GO111MODULE=on go get sigs.k8s.io/kustomize/kustomize/v3@$${tag}; \
./hack/testExamplesAgainstKustomize.sh $$tag; \
echo "Reinstalling kustomize from HEAD."; \
cd kustomize; go install .; \
)
# 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.
$(MYGOBIN)/kubeval:
( \
set -e; \
d=$(shell mktemp -d); cd $$d; \
wget https://github.com/instrumenta/kubeval/releases/latest/download/kubeval-linux-amd64.tar.gz; \
tar xf kubeval-linux-amd64.tar.gz; \
mv kubeval $(MYGOBIN); \
rm -rf $$d; \
)
# linux only.
# This is for testing an example plugin that uses helm to inflate a chart
# for subsequent kustomization.
# Don't want to add a hard dependence in go.mod file to helm.
# Instead, download the binaries.
$(MYGOBIN)/helmV2:
( \
set -e; \
d=$(shell mktemp -d); cd $$d; \
tgzFile=helm-v2.13.1-linux-amd64.tar.gz; \
wget https://storage.googleapis.com/kubernetes-helm/$$tgzFile; \
tar -xvzf $$tgzFile; \
mv linux-amd64/helm $(MYGOBIN)/helmV2; \
rm -rf $$d \
)
# Helm V3 differs from helm V2; downloading it to provide coverage for the
# chart inflator plugin under helm v3.
$(MYGOBIN)/helmV3:
( \
set -e; \
d=$(shell mktemp -d); cd $$d; \
tgzFile=helm-v3.2.0-rc.1-linux-amd64.tar.gz; \
wget https://get.helm.sh/$$tgzFile; \
tar -xvzf $$tgzFile; \
mv linux-amd64/helm $(MYGOBIN)/helmV3; \
rm -rf $$d \
)
# Default version of helm is v2 for the time being.
$(MYGOBIN)/helm: $(MYGOBIN)/helmV2
ln -s $(MYGOBIN)/helmV2 $(MYGOBIN)/helm
$(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-$(shell uname)-amd64; \
chmod +x ./kind; \
mv ./kind $(MYGOBIN); \
rm -rf $$d; \
)
# linux only.
$(MYGOBIN)/gh:
( \
set -e; \
d=$(shell mktemp -d); cd $$d; \
tgzFile=gh_1.0.0_linux_amd64.tar.gz; \
wget https://github.com/cli/cli/releases/download/v1.0.0/$$tgzFile; \
tar -xvzf $$tgzFile; \
mv gh_1.0.0_linux_amd64/bin/gh $(MYGOBIN)/gh; \
rm -rf $$d \
)
# --- Cleanup targets ---
.PHONY: clean
clean: kustomize-external-go-plugin-clean
clean: clean-kustomize-external-go-plugin uninstall-tools
go clean --cache
rm -f $(builtinplugins)
rm -f $(MYGOBIN)/pluginator
rm -f $(MYGOBIN)/kustomize
rm -f $(MYGOBIN)/golangci-lint-kustomize
# Nuke the site from orbit. It's the only way to be sure.
.PHONY: nuke

38
Makefile-modules.mk Normal file
View File

@@ -0,0 +1,38 @@
# Copyright 2022 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
MYGOBIN = $(shell go env GOBIN)
ifeq ($(MYGOBIN),)
MYGOBIN = $(shell go env GOPATH)/bin
endif
export PATH := $(MYGOBIN):$(PATH)
# only set this if not already set, so importing makefiles can override it
export KUSTOMIZE_ROOT ?= $(shell pwd | sed -E 's|(.*\/kustomize)/(.*)|\1|')
include $(KUSTOMIZE_ROOT)/Makefile-tools.mk
.PHONY: lint test fix fmt tidy vet build
lint: $(MYGOBIN)/golangci-lint
$(MYGOBIN)/golangci-lint \
-c $$KUSTOMIZE_ROOT/.golangci.yml \
--path-prefix $(shell pwd | sed -E 's|(.*\/kustomize)/(.*)|\2|') \
run ./...
test:
go test -v -timeout 45m -cover ./...
fix:
go fix ./...
fmt:
go fmt ./...
tidy:
go mod tidy
vet:
go vet ./...
build:
go build -v -o $(MYGOBIN) ./...

102
Makefile-plugins.mk Normal file
View File

@@ -0,0 +1,102 @@
# Copyright 2022 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
### Kustomize plugin rules.
#
# The rules to deal with builtin plugins are a bit
# complicated because
#
# - Every builtin plugin is a Go plugin -
# meaning it gets its own module directory
# (outside of the api module) with Go
# code in a 'main' package per Go plugin rules.
# - kustomize locates plugins using the
# 'apiVersion' and 'kind' fields from the
# plugin config file.
# - k8s wants CamelCase in 'kind' fields.
# - The module name (the last name in the path)
# must be the lowercased 'kind' of the
# plugin because Go and related tools
# demand lowercase in import paths, but
# allow CamelCase in file names.
# - the generated code must live in the api
# module (it's linked into the api).
# Where all generated builtin plugin code should go.
pGen=api/internal/builtins
# Where the builtin Go plugin modules live.
pSrc=plugin/builtin
_builtinplugins = \
AnnotationsTransformer.go \
ConfigMapGenerator.go \
IAMPolicyGenerator.go \
HashTransformer.go \
ImageTagTransformer.go \
LabelTransformer.go \
LegacyOrderTransformer.go \
NamespaceTransformer.go \
PatchJson6902Transformer.go \
PatchStrategicMergeTransformer.go \
PatchTransformer.go \
PrefixTransformer.go \
SuffixTransformer.go \
ReplacementTransformer.go \
ReplicaCountTransformer.go \
SecretGenerator.go \
ValueAddTransformer.go \
HelmChartInflationGenerator.go
# Maintaining this explicit list of generated files, and
# adding it as a dependency to a few targets, to assure
# they get recreated if deleted. The rules below on how
# to make them don't, by themselves, assure they will be
# recreated if deleted.
builtinplugins = $(patsubst %,$(pGen)/%,$(_builtinplugins))
# These rules are verbose, but assure that if a source file
# is modified, the corresponding generated file, and only
# that file, will be recreated.
$(pGen)/AnnotationsTransformer.go: $(pSrc)/annotationstransformer/AnnotationsTransformer.go
$(pGen)/ConfigMapGenerator.go: $(pSrc)/configmapgenerator/ConfigMapGenerator.go
$(pGen)/GkeSaGenerator.go: $(pSrc)/gkesagenerator/GkeSaGenerator.go
$(pGen)/HashTransformer.go: $(pSrc)/hashtransformer/HashTransformer.go
$(pGen)/ImageTagTransformer.go: $(pSrc)/imagetagtransformer/ImageTagTransformer.go
$(pGen)/LabelTransformer.go: $(pSrc)/labeltransformer/LabelTransformer.go
$(pGen)/LegacyOrderTransformer.go: $(pSrc)/legacyordertransformer/LegacyOrderTransformer.go
$(pGen)/NamespaceTransformer.go: $(pSrc)/namespacetransformer/NamespaceTransformer.go
$(pGen)/PatchJson6902Transformer.go: $(pSrc)/patchjson6902transformer/PatchJson6902Transformer.go
$(pGen)/PatchStrategicMergeTransformer.go: $(pSrc)/patchstrategicmergetransformer/PatchStrategicMergeTransformer.go
$(pGen)/PatchTransformer.go: $(pSrc)/patchtransformer/PatchTransformer.go
$(pGen)/PrefixTransformer.go: $(pSrc)/prefixtransformer/PrefixTransformer.go
$(pGen)/SuffixTransformer.go: $(pSrc)/suffixtransformer/SuffixTransformer.go
$(pGen)/ReplacementTransformer.go: $(pSrc)/replacementtransformer/ReplacementTransformer.go
$(pGen)/ReplicaCountTransformer.go: $(pSrc)/replicacounttransformer/ReplicaCountTransformer.go
$(pGen)/SecretGenerator.go: $(pSrc)/secretgenerator/SecretGenerator.go
$(pGen)/ValueAddTransformer.go: $(pSrc)/valueaddtransformer/ValueAddTransformer.go
$(pGen)/HelmChartInflationGenerator.go: $(pSrc)/helmchartinflationgenerator/HelmChartInflationGenerator.go
# The (verbose but portable) Makefile way to convert to lowercase.
toLowerCase = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))
$(pGen)/%.go: $(MYGOBIN)/pluginator
@echo "generating $*"
( \
set -e; \
cd $(pSrc)/$(call toLowerCase,$*); \
go generate .; \
cd ../../../$(pGen); \
$(MYGOBIN)/goimports -w $*.go \
)
# Target is for debugging.
.PHONY: generate-kustomize-builtin-plugins
generate-kustomize-builtin-plugins: $(builtinplugins)
.PHONY: build-kustomize-external-go-plugin
build-kustomize-external-go-plugin:
./hack/buildExternalGoPlugins.sh ./plugin
.PHONY: clean-kustomize-external-go-plugin
clean-kustomize-external-go-plugin:
./hack/buildExternalGoPlugins.sh ./plugin clean

100
Makefile-tools.mk Normal file
View File

@@ -0,0 +1,100 @@
# Copyright 2022 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
MYGOBIN = $(shell go env GOBIN)
ifeq ($(MYGOBIN),)
MYGOBIN = $(shell go env GOPATH)/bin
endif
export PATH := $(MYGOBIN):$(PATH)
.PHONY: install-out-of-tree-tools
install-out-of-tree-tools: \
$(MYGOBIN)/goimports \
$(MYGOBIN)/golangci-lint \
$(MYGOBIN)/helmV3 \
$(MYGOBIN)/mdrip \
$(MYGOBIN)/stringer \
$(MYGOBIN)/goimports
.PHONY: uninstall-out-of-tree-tools
uninstall-out-of-tree-tools:
rm -f $(MYGOBIN)/goimports
rm -f $(MYGOBIN)/golangci-lint
rm -f $(MYGOBIN)/helmV3
rm -f $(MYGOBIN)/mdrip
rm -f $(MYGOBIN)/stringer
$(MYGOBIN)/golangci-lint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
$(MYGOBIN)/mdrip:
go install github.com/monopole/mdrip@v1.0.2
$(MYGOBIN)/stringer:
go install golang.org/x/tools/cmd/stringer@latest
$(MYGOBIN)/goimports:
go install golang.org/x/tools/cmd/goimports@latest
$(MYGOBIN)/mdtogo:
go install sigs.k8s.io/kustomize/cmd/mdtogo@latest
$(MYGOBIN)/addlicense:
go install github.com/google/addlicense@latest
$(MYGOBIN)/statik:
go install github.com/rakyll/statik@latest
$(MYGOBIN)/goreleaser:
go install github.com/goreleaser/goreleaser@v0.179.0 # https://github.com/kubernetes-sigs/kustomize/issues/4542
$(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; \
)
# linux only.
$(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 \
)
# 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.
$(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; \
)
# Helm V3 differs from helm V2; downloading it to provide coverage for the
# chart inflator plugin under helm v3.
$(MYGOBIN)/helmV3:
( \
set -e; \
d=$(shell mktemp -d); cd $$d; \
tgzFile=helm-v3.6.3-$(GOOS)-$(GOARCH).tar.gz; \
wget https://get.helm.sh/$$tgzFile; \
tar -xvzf $$tgzFile; \
mv $(GOOS)-$(GOARCH)/helm $(MYGOBIN)/helmV3; \
rm -rf $$d \
)

6
OWNERS
View File

@@ -1,4 +1,6 @@
# See https://github.com/kubernetes/community/blob/master/community-membership.md
approvers:
- kustomize-admins
- kustomize-maintainers
- kustomize-approvers
reviewers:
- kustomize-reviewers

View File

@@ -1,14 +1,29 @@
# Keep *-owners and *-approvers lists in sync with *-admins and *-maintainers in
# https://github.com/kubernetes/org/blob/main/config/kubernetes-sigs/sig-cli/teams.yaml
aliases:
kustomize-admins:
- monopole
- pwittrock
kustomize-maintainers:
- droot
- justinsb
- liujingfang1
kustomize-owners:
- knverey
- natasha41575
kustomize-approvers:
- knverey
- natasha41575
kustomize-reviewers:
- knverey
- natasha41575
- yuwenma
kyaml-approvers:
- mengqiy
- monopole
- pwittrock
- mortent
- phanimarupaka
kyaml-reviewers:
- mengqiy
- mortent
- phanimarupaka
emeritus-approvers:
- liujingfang1
- Shell32-Natsu
- justinsb
- monopole
- pwittrock

View File

@@ -11,8 +11,8 @@ and it's like [`sed`], in that it emits edited text.
This tool is sponsored by [sig-cli] ([KEP]).
- [Installation instructions](https://kubernetes-sigs.github.io/kustomize/installation)
- [General documentation](https://kubernetes-sigs.github.io/kustomize)
- [Installation instructions](https://kubectl.docs.kubernetes.io/installation/kustomize/)
- [General documentation](https://kubectl.docs.kubernetes.io/references/kustomize/)
- [Examples](examples)
[![Build Status](https://prow.k8s.io/badge.svg?jobs=kustomize-presubmit-master)](https://prow.k8s.io/job-history/kubernetes-jenkins/pr-logs/directory/kustomize-presubmit-master)
@@ -20,15 +20,27 @@ This tool is sponsored by [sig-cli] ([KEP]).
## kubectl integration
Since [v1.14][kubectl announcement] the kustomize build system has been included in kubectl.
The kustomize build flow at [v2.0.3] was added
to [kubectl v1.14][kubectl announcement]. The kustomize
flow in kubectl remained frozen at v2.0.3 until kubectl v1.21,
which [updated it to v4.0.5][kust-in-kubectl update]. It will
be updated on a regular basis going forward, and such updates
will be reflected in the Kubernetes release notes.
| kubectl version | kustomize version |
|---------|--------|
| v1.16.0 | [v2.0.3](/../../tree/v2.0.3) |
| v1.15.x | [v2.0.3](/../../tree/v2.0.3) |
| v1.14.x | [v2.0.3](/../../tree/v2.0.3) |
| Kubectl version | Kustomize version |
| --- | --- |
| < v1.14 | n/a |
| v1.14-v1.20 | v2.0.3 |
| v1.21 | v4.0.5 |
| v1.22 | v4.2.0 |
For examples and guides for using the kubectl integration please see the [kubectl book] or the [kubernetes documentation].
[v2.0.3]: https://github.com/kubernetes-sigs/kustomize/releases/tag/v2.0.3
[#2506]: https://github.com/kubernetes-sigs/kustomize/issues/2506
[#1500]: https://github.com/kubernetes-sigs/kustomize/issues/1500
[kust-in-kubectl update]: https://github.com/kubernetes/kubernetes/blob/4d75a6238a6e330337526e0513e67d02b1940b63/CHANGELOG/CHANGELOG-1.21.md#kustomize-updates-in-kubectl
For examples and guides for using the kubectl integration please
see the [kubernetes documentation].
## Usage
@@ -129,8 +141,9 @@ The YAML can be directly [applied] to a cluster:
## Community
- [file a bug](https://kubernetes-sigs.github.io/kustomize/contributing/bugs/) instructions
- [contribute a feature](https://kubernetes-sigs.github.io/kustomize/contributing/features/) instructions
- [file a bug](https://kubectl.docs.kubernetes.io/contributing/kustomize/bugs/)
- [contribute a feature](https://kubectl.docs.kubernetes.io/contributing/kustomize/features/)
- [propose a larger enhancement](https://github.com/kubernetes-sigs/kustomize/tree/master/proposals)
### Code of conduct
@@ -139,27 +152,22 @@ is governed by the [Kubernetes Code of Conduct].
[`make`]: https://www.gnu.org/software/make
[`sed`]: https://www.gnu.org/software/sed
[DAM]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#declarative-application-management
[KEP]: https://github.com/kubernetes/enhancements/blob/master/keps/sig-cli/0008-kustomize.md
[DAM]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#declarative-application-management
[KEP]: https://github.com/kubernetes/enhancements/blob/master/keps/sig-cli/2377-Kustomize/README.md
[Kubernetes Code of Conduct]: code-of-conduct.md
[applied]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#apply
[base]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#base
[declarative configuration]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#declarative-application-management
[imageBase]: docs/images/base.jpg
[imageOverlay]: docs/images/overlay.jpg
[applied]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#apply
[base]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#base
[declarative configuration]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#declarative-application-management
[imageBase]: images/base.jpg
[imageOverlay]: images/overlay.jpg
[kubectl announcement]: https://kubernetes.io/blog/2019/03/25/kubernetes-1-14-release-announcement
[kubectl book]: https://kubectl.docs.kubernetes.io/pages/app_customization/introduction.html
[kubernetes documentation]: https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/
[kubernetes style]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#kubernetes-style-object
[kustomization]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#kustomization
[overlay]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#overlay
[overlays]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#overlay
[kubernetes style]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#kubernetes-style-object
[kustomization]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#kustomization
[overlay]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#overlay
[overlays]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#overlay
[release page]: https://github.com/kubernetes-sigs/kustomize/releases
[resource]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#resource
[resources]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#resource
[resource]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#resource
[resources]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#resource
[sig-cli]: https://github.com/kubernetes/community/blob/master/sig-cli/README.md
[variant]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#variant
[variants]: https://kubernetes-sigs.github.io/kustomize/api-reference/glossary#variant
[v2.0.3]: https://github.com/kubernetes-sigs/kustomize/releases/tag/v2.0.3
[v2.1.0]: https://github.com/kubernetes-sigs/kustomize/releases/tag/v2.1.0
[workflows]: https://kubernetes-sigs.github.io/kustomize/guides
[variants]: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#variant

112
ROADMAP.md Normal file
View File

@@ -0,0 +1,112 @@
# Kustomize roadmap 2022
Presented at the [January 26, 2022, SIG-CLI meeting](https://youtu.be/l2plzJ9MRlk?t=1321)
kustomize maintainers: @knverey, @natasha41575
[Objective: Improve contributor community](#objective-improve-contributor-community)
[Objective: Improve end-user experience](#objective-improve-end-user-experience)
[Objective: Improve extension experience](#objective-improve-extension-experience)
## Objective: Improve contributor community
**_WHO: End user who also contributes source code._**
Top priority:
- Kustomization v1 (also end-user impact) ([PROJECT](https://github.com/kubernetes-sigs/kustomize/projects/12))
- Remove the following fields:
- [vars](https://github.com/kubernetes-sigs/kustomize/issues/2052)
- [patchesJson6902, patchesStrategicMerge (consolidate on \`patches)](https://github.com/kubernetes-sigs/kustomize/issues/4376)
- [helmChartInflationGenerator, helmCharts, helmGlobals](https://github.com/kubernetes-sigs/kustomize/issues/4401)
- all long-deprecated fields in Kustomization v1 such as \`bases\` and those being accommodate by kustomize edit \[[see code snippet](https://github.com/kubernetes-sigs/kustomize/blob/ee4b7847f0beb6c0d2070673b10f23f7b3e92e82/api/types/fix.go#L15)\]
- Ensure that \`kustomize edit fix\` handles migrations for all those, and that anything it changes is not still present in v1.
- [Add reorder field](https://github.com/kubernetes-sigs/kustomize/issues/3913). Default should be FIFO and legacy should also be supported (could add alphabetic and custom sort support eventually). Replaces -reorder flag.
- [Reconcile openapi and crds field](https://github.com/kubernetes-sigs/kustomize/issues/3944)
- [Consider deprecating configurations field](https://github.com/kubernetes-sigs/kustomize/issues/3945) (old, pre-plugin, pre-openapi global configuration)
- [Add a field to enable the managedby label](https://github.com/kubernetes-sigs/kustomize/issues/4047)
Second priority:
- Improve contributor documentation
- [Instructions to upgrade kustomize-in-kubectl](https://github.com/kubernetes-sigs/kustomize/issues/3951)
Also very valuable to the project:
- [Improve the release process](https://github.com/kubernetes-sigs/kustomize/issues/3952) to support regular biweekly releases [PROJECT](https://github.com/kubernetes-sigs/kustomize/projects/7)
- Release sigs.k8s.io/kustomize/api v1.0.0 [PROJECT](https://github.com/kubernetes-sigs/kustomize/projects/5)
- [Reduce the public surface of the API module](https://github.com/kubernetes-sigs/kustomize/issues/3942)
- [Vendor all transitive deps](https://github.com/kubernetes-sigs/kustomize/issues/3706). Since kustomize is in kubectl, we must do as kubectl does to manage deps, exposing new transitive deps in code review.
- Project administration
- [Rename master branch to main](https://github.com/kubernetes-sigs/kustomize/issues/3954)
## Objective: Improve end-user experience
**_WHO: End user that wants kustomize build artifacts (binaries, containers)._**
Top priorities:
- Bug fixes:
- Fix bugs in basic anchor support: [issue query](https://github.com/kubernetes-sigs/kustomize/issues?q=is%3Aopen+is%3Aissue+label%3Aarea%2Fanchors)
- integer keys support: [#3446](https://github.com/kubernetes-sigs/kustomize/issues/3446)
- kyaml not respecting \`$patch replace|retainKeys\`: [#2037](https://github.com/kubernetes-sigs/kustomize/issues/2037)
- kustomize removing quotes from namespace field values: [#4146](https://github.com/kubernetes-sigs/kustomize/issues/4146)
- Kustomize doesnt support metadata.generateName: [#641](https://github.com/kubernetes-sigs/kustomize/issues/641)
- Send kustomize CLI version number into kubectl ([kubectl issue](https://github.com/kubernetes/kubectl/issues/797) / [kustomize issue](https://github.com/kubernetes-sigs/kustomize/issues/1424))
- Kustomize performance investigations/improvements [PROJECT](https://github.com/kubernetes-sigs/kustomize/projects/13)
- [Support generic resource references in name reference tracking](https://github.com/kubernetes-sigs/kustomize/issues/3418)
- [KEP 4267: retain the resource origin and transformer data in annotations](https://github.com/kubernetes-sigs/kustomize/pull/4267)
Secondary priorities:
- kustomize cli v5 ([PROJECT](https://github.com/kubernetes-sigs/kustomize/projects/14))
- [Drop the --reorder flag](https://github.com/kubernetes-sigs/kustomize/issues/3947)
- [Graduate cfg read-only commands out of alpha](https://github.com/kubernetes-sigs/kustomize/issues/4090).
- [Drop the enable-managedby-label](https://github.com/kubernetes-sigs/kustomize/issues/4047)
- Drop old plugin-related fields in favor of [the Catalog-style fields](https://github.com/kubernetes/enhancements/tree/master/keps/sig-cli/2906-kustomize-function-catalog).
- [Drop the helm flags](https://github.com/kubernetes-sigs/kustomize/issues/4401)
- [Confusion around namespace replacement](https://github.com/kubernetes-sigs/kustomize/issues/880).
Also very valuable to the project:
- [Overinclusion of root directory error in error messages](https://github.com/kubernetes-sigs/kustomize/issues/4348)
- [Add kustomize localize command](https://github.com/kubernetes-sigs/kustomize/issues/3980)
- [Fix Windows support in test suite](https://github.com/kubernetes-sigs/kustomize/issues/4001)
- Improve end-user documentation [PROJECT](https://github.com/kubernetes-sigs/kustomize/projects/9)
## Objective: Improve extension experience
**_WHO: Plugin developers: end users who extend kustomize, but dont think about internals._**
This objective is described in detail in the [Kustomize Plugin Graduation KEP](https://github.com/kubernetes/enhancements/tree/master/keps/sig-cli/2953-kustomize-plugin-graduation) / [PROJECT](https://github.com/kubernetes-sigs/kustomize/projects/15) .
Top priorities:
- Fix core usability issues with KRM Function extensions:
- [Better errors for function config failures](https://github.com/kubernetes-sigs/kustomize/issues/4398)
- [Container KRM Mounts are not mounting via function parameters](https://github.com/kubernetes-sigs/kustomize/issues/4290)
- [Resolution of local file references in extensions transformer configuration](https://github.com/kubernetes-sigs/kustomize/issues/4154)
- [Do not silently ignore plugins when config has typo](https://github.com/kubernetes-sigs/kustomize/issues/4399)
- [KRM Exec Function can't locate executable when referencing a base](https://github.com/kubernetes-sigs/kustomize/issues/4347)
- Once core usability issues are fixed, [deprecate legacy exec and Go plugin support](https://github.com/kubernetes/enhancements/tree/master/keps/sig-cli/2953-kustomize-plugin-graduation)
- [Catalog KEP](https://github.com/kubernetes/enhancements/tree/master/keps/sig-cli/2906-kustomize-function-catalog)
Secondary priorities:
- [Remove Starlark support](https://github.com/kubernetes-sigs/kustomize/issues/4349)
- [Composition KEP](https://github.com/kubernetes/enhancements/pull/2300). The implementation is complete in [#4223](https://github.com/kubernetes-sigs/kustomize/pull/4323), but depends on:
- [Convert resources and components to be backed by a reusable generator](https://github.com/kubernetes-sigs/kustomize/issues/4402)
- [Enable explicitly invoked transformers to use default fieldSpecs](https://github.com/kubernetes-sigs/kustomize/issues/4404)
- [Enable built-in generators to be used in the transformers field ](https://github.com/kubernetes-sigs/kustomize/issues/4403)
Also very valuable to the project:
- [Improve docs for kyaml libraries](https://github.com/kubernetes-sigs/kustomize/issues/3950), especially by adding examples.
- [Create a reserved field for plugin runtime information](https://github.com/kubernetes-sigs/kustomize/issues/4405)
- [Develop new standard process for implementing builtin transformers](https://github.com/kubernetes-sigs/kustomize/issues/4400)

14
api/Makefile Normal file
View File

@@ -0,0 +1,14 @@
# Copyright 2022 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
include ../Makefile-modules.mk
test:
go test -v -timeout 45m -cover ./... -ldflags "-X sigs.k8s.io/kustomize/api/provenance.version=v444.333.222"
cd krusty/openapitests; OPENAPI_TEST=true go test -v -timeout 45m -p 1 -cover ./...
build:
go build -ldflags "-X sigs.k8s.io/kustomize/api/provenance.version=v444.333.222" ./...
generate: $(MYGOBIN)/k8scopy $(MYGOBIN)/stringer
go generate ./...

View File

@@ -1,188 +0,0 @@
// Code generated by pluginator on ImageTagTransformer; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
package builtins
import (
"fmt"
"regexp"
"strings"
"sigs.k8s.io/kustomize/api/filters/imagetag"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/filtersutil"
"sigs.k8s.io/yaml"
)
// Find matching image declarations and replace
// the name, tag and/or digest.
type ImageTagTransformerPlugin struct {
ImageTag types.Image `json:"imageTag,omitempty" yaml:"imageTag,omitempty"`
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
}
func (p *ImageTagTransformerPlugin) Config(
_ *resmap.PluginHelpers, c []byte) (err error) {
p.ImageTag = types.Image{}
p.FieldSpecs = nil
return yaml.Unmarshal(c, p)
}
func (p *ImageTagTransformerPlugin) Transform(m resmap.ResMap) error {
for _, r := range m.Resources() {
// traverse all fields at first
err := filtersutil.ApplyToJSON(imagetag.LegacyFilter{
ImageTag: p.ImageTag,
}, r)
if err != nil {
return err
}
// then use user specified field specs
err = filtersutil.ApplyToJSON(imagetag.Filter{
ImageTag: p.ImageTag,
FsSlice: p.FieldSpecs,
}, r)
if err != nil {
return err
}
}
return nil
}
func (p *ImageTagTransformerPlugin) mutateImage(in interface{}) (interface{}, error) {
original, ok := in.(string)
if !ok {
return nil, fmt.Errorf("image path is not of type string but %T", in)
}
if !isImageMatched(original, p.ImageTag.Name) {
return original, nil
}
name, tag := split(original)
if p.ImageTag.NewName != "" {
name = p.ImageTag.NewName
}
if p.ImageTag.NewTag != "" {
tag = ":" + p.ImageTag.NewTag
}
if p.ImageTag.Digest != "" {
tag = "@" + p.ImageTag.Digest
}
return name + tag, nil
}
// findAndReplaceImage replaces the image name and
// tags inside one object.
// It searches the object for container session
// then loops though all images inside containers
// session, finds matched ones and update the
// image name and tag name
func (p *ImageTagTransformerPlugin) findAndReplaceImage(obj map[string]interface{}) error {
paths := []string{"containers", "initContainers"}
updated := false
for _, path := range paths {
containers, found := obj[path]
if found && containers != nil {
if _, err := p.updateContainers(containers); err != nil {
return err
}
updated = true
}
}
if !updated {
return p.findContainers(obj)
}
return nil
}
func (p *ImageTagTransformerPlugin) updateContainers(in interface{}) (interface{}, error) {
containers, ok := in.([]interface{})
if !ok {
return nil, fmt.Errorf(
"containers path is not of type []interface{} but %T", in)
}
for i := range containers {
container := containers[i].(map[string]interface{})
containerImage, found := container["image"]
if !found {
continue
}
imageName := containerImage.(string)
if isImageMatched(imageName, p.ImageTag.Name) {
newImage, err := p.mutateImage(imageName)
if err != nil {
return nil, err
}
container["image"] = newImage
}
}
return containers, nil
}
func (p *ImageTagTransformerPlugin) findContainers(obj map[string]interface{}) error {
for key := range obj {
switch typedV := obj[key].(type) {
case map[string]interface{}:
err := p.findAndReplaceImage(typedV)
if err != nil {
return err
}
case []interface{}:
for i := range typedV {
item := typedV[i]
typedItem, ok := item.(map[string]interface{})
if ok {
err := p.findAndReplaceImage(typedItem)
if err != nil {
return err
}
}
}
}
}
return nil
}
func isImageMatched(s, t string) bool {
// Tag values are limited to [a-zA-Z0-9_.{}-].
// Some tools like Bazel rules_k8s allow tag patterns with {} characters.
// More info: https://github.com/bazelbuild/rules_k8s/pull/423
pattern, _ := regexp.Compile("^" + t + "(@sha256)?(:[a-zA-Z0-9_.{}-]*)?$")
return pattern.MatchString(s)
}
// split separates and returns the name and tag parts
// from the image string using either colon `:` or at `@` separators.
// Note that the returned tag keeps its separator.
func split(imageName string) (name string, tag string) {
// check if image name contains a domain
// if domain is present, ignore domain and check for `:`
ic := -1
if slashIndex := strings.Index(imageName, "/"); slashIndex < 0 {
ic = strings.LastIndex(imageName, ":")
} else {
lastIc := strings.LastIndex(imageName[slashIndex:], ":")
// set ic only if `:` is present
if lastIc > 0 {
ic = slashIndex + lastIc
}
}
ia := strings.LastIndex(imageName, "@")
if ic < 0 && ia < 0 {
return imageName, ""
}
i := ic
if ia > 0 {
i = ia
}
name = imageName[:i]
tag = imageName[i:]
return
}
func NewImageTagTransformerPlugin() resmap.TransformerPlugin {
return &ImageTagTransformerPlugin{}
}

View File

@@ -1,95 +0,0 @@
// Code generated by pluginator on PatchJson6902Transformer; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
package builtins
import (
"fmt"
jsonpatch "github.com/evanphx/json-patch"
"github.com/pkg/errors"
"sigs.k8s.io/kustomize/api/filters/patchjson6902"
"sigs.k8s.io/kustomize/api/ifc"
"sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/filtersutil"
"sigs.k8s.io/yaml"
)
type PatchJson6902TransformerPlugin struct {
ldr ifc.Loader
decodedPatch jsonpatch.Patch
Target types.PatchTarget `json:"target,omitempty" yaml:"target,omitempty"`
Path string `json:"path,omitempty" yaml:"path,omitempty"`
JsonOp string `json:"jsonOp,omitempty" yaml:"jsonOp,omitempty"`
}
func (p *PatchJson6902TransformerPlugin) Config(
h *resmap.PluginHelpers, c []byte) (err error) {
p.ldr = h.Loader()
err = yaml.Unmarshal(c, p)
if err != nil {
return err
}
if p.Target.Name == "" {
return fmt.Errorf("must specify the target name")
}
if p.Path == "" && p.JsonOp == "" {
return fmt.Errorf("empty file path and empty jsonOp")
}
if p.Path != "" {
if p.JsonOp != "" {
return fmt.Errorf("must specify a file path or jsonOp, not both")
}
rawOp, err := p.ldr.Load(p.Path)
if err != nil {
return err
}
p.JsonOp = string(rawOp)
if p.JsonOp == "" {
return fmt.Errorf("patch file '%s' empty seems to be empty", p.Path)
}
}
if p.JsonOp[0] != '[' {
// if it doesn't seem to be JSON, imagine
// it is YAML, and convert to JSON.
op, err := yaml.YAMLToJSON([]byte(p.JsonOp))
if err != nil {
return err
}
p.JsonOp = string(op)
}
p.decodedPatch, err = jsonpatch.DecodePatch([]byte(p.JsonOp))
if err != nil {
return errors.Wrapf(err, "decoding %s", p.JsonOp)
}
if len(p.decodedPatch) == 0 {
return fmt.Errorf(
"patch appears to be empty; file=%s, JsonOp=%s", p.Path, p.JsonOp)
}
return err
}
func (p *PatchJson6902TransformerPlugin) Transform(m resmap.ResMap) error {
id := resid.NewResIdWithNamespace(
resid.Gvk{
Group: p.Target.Group,
Version: p.Target.Version,
Kind: p.Target.Kind,
},
p.Target.Name,
p.Target.Namespace,
)
obj, err := m.GetById(id)
if err != nil {
return err
}
return filtersutil.ApplyToJSON(patchjson6902.Filter{
Patch: p.JsonOp,
}, obj)
}
func NewPatchJson6902TransformerPlugin() resmap.TransformerPlugin {
return &PatchJson6902TransformerPlugin{}
}

View File

@@ -1,120 +0,0 @@
// Code generated by pluginator on PatchStrategicMergeTransformer; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
package builtins
import (
"fmt"
"strings"
"github.com/pkg/errors"
"sigs.k8s.io/kustomize/api/filters/patchstrategicmerge"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/filtersutil"
"sigs.k8s.io/yaml"
)
type PatchStrategicMergeTransformerPlugin struct {
h *resmap.PluginHelpers
loadedPatches []*resource.Resource
Paths []types.PatchStrategicMerge `json:"paths,omitempty" yaml:"paths,omitempty"`
Patches string `json:"patches,omitempty" yaml:"patches,omitempty"`
}
func (p *PatchStrategicMergeTransformerPlugin) Config(
h *resmap.PluginHelpers, c []byte) (err error) {
p.h = h
err = yaml.Unmarshal(c, p)
if err != nil {
return err
}
if len(p.Paths) == 0 && p.Patches == "" {
return fmt.Errorf("empty file path and empty patch content")
}
if len(p.Paths) != 0 {
for _, onePath := range p.Paths {
res, err := p.h.ResmapFactory().RF().SliceFromBytes([]byte(onePath))
if err == nil {
p.loadedPatches = append(p.loadedPatches, res...)
continue
}
res, err = p.h.ResmapFactory().RF().SliceFromPatches(
p.h.Loader(), []types.PatchStrategicMerge{onePath})
if err != nil {
return err
}
p.loadedPatches = append(p.loadedPatches, res...)
}
}
if p.Patches != "" {
res, err := p.h.ResmapFactory().RF().SliceFromBytes([]byte(p.Patches))
if err != nil {
return err
}
p.loadedPatches = append(p.loadedPatches, res...)
}
if len(p.loadedPatches) == 0 {
return fmt.Errorf(
"patch appears to be empty; files=%v, Patch=%s", p.Paths, p.Patches)
}
return err
}
func (p *PatchStrategicMergeTransformerPlugin) Transform(m resmap.ResMap) error {
patches, err := p.h.ResmapFactory().Merge(p.loadedPatches)
if err != nil {
return err
}
for _, patch := range patches.Resources() {
target, err := m.GetById(patch.OrgId())
if err != nil {
return err
}
patchCopy := patch.DeepCopy()
patchCopy.SetName(target.GetName())
patchCopy.SetNamespace(target.GetNamespace())
patchCopy.SetGvk(target.GetGvk())
node, err := filtersutil.GetRNode(patchCopy)
if err != nil {
return err
}
err = filtersutil.ApplyToJSON(patchstrategicmerge.Filter{
Patch: node,
}, target)
if err != nil {
// Check for an error string from UnmarshalJSON that's indicative
// of an object that's missing basic KRM fields, and thus may have been
// entirely deleted (an acceptable outcome). This error handling should
// be deleted along with use of ResMap and apimachinery functions like
// UnmarshalJSON.
if !strings.Contains(err.Error(), "Object 'Kind' is missing") {
// Some unknown error, let it through.
return err
}
if !target.IsEmpty() {
return errors.Wrapf(
err, "with unexpectedly non-empty object map of size %d",
len(target.Map()))
}
// Fall through to handle deleted object.
}
if target.IsEmpty() {
// This means all fields have been removed from the object.
// This can happen if a patch required deletion of the
// entire resource (not just a part of it). This means
// the overall resmap must shrink by one.
err = m.Remove(target.CurId())
if err != nil {
return err
}
}
}
return nil
}
func NewPatchStrategicMergeTransformerPlugin() resmap.TransformerPlugin {
return &PatchStrategicMergeTransformerPlugin{}
}

View File

@@ -1,195 +0,0 @@
// Code generated by pluginator on PatchTransformer; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
package builtins
import (
"fmt"
"strings"
jsonpatch "github.com/evanphx/json-patch"
"github.com/pkg/errors"
"sigs.k8s.io/kustomize/api/filters/patchjson6902"
"sigs.k8s.io/kustomize/api/filters/patchstrategicmerge"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/filtersutil"
"sigs.k8s.io/yaml"
)
type PatchTransformerPlugin struct {
loadedPatch *resource.Resource
decodedPatch jsonpatch.Patch
Path string `json:"path,omitempty" yaml:"path,omitempty"`
Patch string `json:"patch,omitempty" yaml:"patch,omitempty"`
Target *types.Selector `json:"target,omitempty" yaml:"target,omitempty"`
}
func (p *PatchTransformerPlugin) Config(
h *resmap.PluginHelpers, c []byte) error {
err := yaml.Unmarshal(c, p)
if err != nil {
return err
}
p.Patch = strings.TrimSpace(p.Patch)
if p.Patch == "" && p.Path == "" {
return fmt.Errorf(
"must specify one of patch and path in\n%s", string(c))
}
if p.Patch != "" && p.Path != "" {
return fmt.Errorf(
"patch and path can't be set at the same time\n%s", string(c))
}
if p.Path != "" {
loaded, loadErr := h.Loader().Load(p.Path)
if loadErr != nil {
return loadErr
}
p.Patch = string(loaded)
}
patchSM, errSM := h.ResmapFactory().RF().FromBytes([]byte(p.Patch))
patchJson, errJson := jsonPatchFromBytes([]byte(p.Patch))
if (errSM == nil && errJson == nil) ||
(patchSM != nil && patchJson != nil) {
return fmt.Errorf(
"illegally qualifies as both an SM and JSON patch: [%v]",
p.Patch)
}
if errSM != nil && errJson != nil {
return fmt.Errorf(
"unable to parse SM or JSON patch from [%v]", p.Patch)
}
if errSM == nil {
p.loadedPatch = patchSM
} else {
p.decodedPatch = patchJson
}
return nil
}
func (p *PatchTransformerPlugin) Transform(m resmap.ResMap) error {
if p.loadedPatch == nil {
return p.transformJson6902(m, p.decodedPatch)
} else {
// The patch was a strategic merge patch
return p.transformStrategicMerge(m, p.loadedPatch)
}
}
// transformStrategicMerge applies the provided strategic merge patch
// to all the resources in the ResMap that match either the Target or
// the identifier of the patch.
func (p *PatchTransformerPlugin) transformStrategicMerge(m resmap.ResMap, patch *resource.Resource) error {
if p.Target == nil {
target, err := m.GetById(patch.OrgId())
if err != nil {
return err
}
return p.applySMPatch(target, patch)
}
resources, err := m.Select(*p.Target)
if err != nil {
return err
}
for _, res := range resources {
patchCopy := patch.DeepCopy()
patchCopy.SetName(res.GetName())
patchCopy.SetNamespace(res.GetNamespace())
patchCopy.SetGvk(res.GetGvk())
err := p.applySMPatch(res, patchCopy)
if err != nil {
// Check for an error string from UnmarshalJSON that's indicative
// of an object that's missing basic KRM fields, and thus may have been
// entirely deleted (an acceptable outcome). This error handling should
// be deleted along with use of ResMap and apimachinery functions like
// UnmarshalJSON.
if !strings.Contains(err.Error(), "Object 'Kind' is missing") {
// Some unknown error, let it through.
return err
}
if !res.IsEmpty() {
return errors.Wrapf(
err, "with unexpectedly non-empty object map of size %d",
len(res.Map()))
}
// Fall through to handle deleted object.
}
if res.IsEmpty() {
// This means all fields have been removed from the object.
// This can happen if a patch required deletion of the
// entire resource (not just a part of it). This means
// the overall resmap must shrink by one.
err = m.Remove(res.CurId())
if err != nil {
return err
}
}
}
return nil
}
// applySMPatch applies the provided strategic merge patch to the
// given resource.
func (p *PatchTransformerPlugin) applySMPatch(resource, patch *resource.Resource) error {
node, err := filtersutil.GetRNode(patch)
if err != nil {
return err
}
n, ns := resource.GetName(), resource.GetNamespace()
err = filtersutil.ApplyToJSON(patchstrategicmerge.Filter{
Patch: node,
}, resource)
if !resource.IsEmpty() {
resource.SetName(n)
resource.SetNamespace(ns)
}
return err
}
// transformJson6902 applies the provided json6902 patch
// to all the resources in the ResMap that match the Target.
func (p *PatchTransformerPlugin) transformJson6902(m resmap.ResMap, patch jsonpatch.Patch) error {
if p.Target == nil {
return fmt.Errorf("must specify a target for patch %s", p.Patch)
}
resources, err := m.Select(*p.Target)
if err != nil {
return err
}
for _, res := range resources {
err = filtersutil.ApplyToJSON(patchjson6902.Filter{
Patch: p.Patch,
}, res)
if err != nil {
return err
}
}
return nil
}
// jsonPatchFromBytes loads a Json 6902 patch from
// a bytes input
func jsonPatchFromBytes(
in []byte) (jsonpatch.Patch, error) {
ops := string(in)
if ops == "" {
return nil, fmt.Errorf("empty json patch operations")
}
if ops[0] != '[' {
jsonOps, err := yaml.YAMLToJSON(in)
if err != nil {
return nil, err
}
ops = string(jsonOps)
}
return jsonpatch.DecodePatch([]byte(ops))
}
func NewPatchTransformerPlugin() resmap.TransformerPlugin {
return &PatchTransformerPlugin{}
}

View File

@@ -1,101 +0,0 @@
// Code generated by pluginator on PrefixSuffixTransformer; DO NOT EDIT.
// pluginator {unknown 1970-01-01T00:00:00Z }
package builtins
import (
"errors"
"sigs.k8s.io/kustomize/api/filters/prefixsuffix"
"sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/filtersutil"
"sigs.k8s.io/yaml"
)
// Add the given prefix and suffix to the field.
type PrefixSuffixTransformerPlugin struct {
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
Suffix string `json:"suffix,omitempty" yaml:"suffix,omitempty"`
FieldSpecs types.FsSlice `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
}
// A Gvk skip list for prefix/suffix modification.
// hard coded for now - eventually should be part of config.
var prefixSuffixFieldSpecsToSkip = types.FsSlice{
{Gvk: resid.Gvk{Kind: "CustomResourceDefinition"}},
{Gvk: resid.Gvk{Group: "apiregistration.k8s.io", Kind: "APIService"}},
{Gvk: resid.Gvk{Kind: "Namespace"}},
}
func (p *PrefixSuffixTransformerPlugin) Config(
_ *resmap.PluginHelpers, c []byte) (err error) {
p.Prefix = ""
p.Suffix = ""
p.FieldSpecs = nil
err = yaml.Unmarshal(c, p)
if err != nil {
return
}
if p.FieldSpecs == nil {
return errors.New("fieldSpecs is not expected to be nil")
}
return
}
func (p *PrefixSuffixTransformerPlugin) Transform(m resmap.ResMap) error {
// Even if both the Prefix and Suffix are empty we want
// to proceed with the transformation. This allows to add contextual
// information to the resources (AddNamePrefix and AddNameSuffix).
for _, r := range m.Resources() {
// TODO: move this test into the filter (i.e. make a better filter)
if p.shouldSkip(r.OrgId()) {
continue
}
id := r.OrgId()
// current default configuration contains
// only one entry: "metadata/name" with no GVK
for _, fs := range p.FieldSpecs {
// TODO: this is redundant to filter (but needed for now)
if !id.IsSelected(&fs.Gvk) {
continue
}
// TODO: move this test into the filter.
if smellsLikeANameChange(&fs) {
// "metadata/name" is the only field.
// this will add a prefix and a suffix
// to the resource even if those are
// empty
r.AddNamePrefix(p.Prefix)
r.AddNameSuffix(p.Suffix)
}
err := filtersutil.ApplyToJSON(prefixsuffix.Filter{
Prefix: p.Prefix,
Suffix: p.Suffix,
FieldSpec: fs,
}, r)
if err != nil {
return err
}
}
}
return nil
}
func smellsLikeANameChange(fs *types.FieldSpec) bool {
return fs.Path == "metadata/name"
}
func (p *PrefixSuffixTransformerPlugin) shouldSkip(id resid.ResId) bool {
for _, path := range prefixSuffixFieldSpecsToSkip {
if id.IsSelected(&path.Gvk) {
return true
}
}
return false
}
func NewPrefixSuffixTransformerPlugin() resmap.TransformerPlugin {
return &PrefixSuffixTransformerPlugin{}
}

51
api/builtins/builtins.go Normal file
View File

@@ -0,0 +1,51 @@
// Copyright 2021 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// Deprecated: Package api/builtins will not be available in API v1.
package builtins
import (
internal "sigs.k8s.io/kustomize/api/internal/builtins"
)
type (
AnnotationsTransformerPlugin = internal.AnnotationsTransformerPlugin
ConfigMapGeneratorPlugin = internal.ConfigMapGeneratorPlugin
HashTransformerPlugin = internal.HashTransformerPlugin
HelmChartInflationGeneratorPlugin = internal.HelmChartInflationGeneratorPlugin
IAMPolicyGeneratorPlugin = internal.IAMPolicyGeneratorPlugin
ImageTagTransformerPlugin = internal.ImageTagTransformerPlugin
LabelTransformerPlugin = internal.LabelTransformerPlugin
LegacyOrderTransformerPlugin = internal.LegacyOrderTransformerPlugin
NamespaceTransformerPlugin = internal.NamespaceTransformerPlugin
PatchJson6902TransformerPlugin = internal.PatchJson6902TransformerPlugin
PatchStrategicMergeTransformerPlugin = internal.PatchStrategicMergeTransformerPlugin
PatchTransformerPlugin = internal.PatchTransformerPlugin
PrefixTransformerPlugin = internal.PrefixTransformerPlugin
SuffixTransformerPlugin = internal.SuffixTransformerPlugin
ReplacementTransformerPlugin = internal.ReplacementTransformerPlugin
ReplicaCountTransformerPlugin = internal.ReplicaCountTransformerPlugin
SecretGeneratorPlugin = internal.SecretGeneratorPlugin
ValueAddTransformerPlugin = internal.ValueAddTransformerPlugin
)
var (
NewAnnotationsTransformerPlugin = internal.NewAnnotationsTransformerPlugin
NewConfigMapGeneratorPlugin = internal.NewConfigMapGeneratorPlugin
NewHashTransformerPlugin = internal.NewHashTransformerPlugin
NewHelmChartInflationGeneratorPlugin = internal.NewHelmChartInflationGeneratorPlugin
NewIAMPolicyGeneratorPlugin = internal.NewIAMPolicyGeneratorPlugin
NewImageTagTransformerPlugin = internal.NewImageTagTransformerPlugin
NewLabelTransformerPlugin = internal.NewLabelTransformerPlugin
NewLegacyOrderTransformerPlugin = internal.NewLegacyOrderTransformerPlugin
NewNamespaceTransformerPlugin = internal.NewNamespaceTransformerPlugin
NewPatchJson6902TransformerPlugin = internal.NewPatchJson6902TransformerPlugin
NewPatchStrategicMergeTransformerPlugin = internal.NewPatchStrategicMergeTransformerPlugin
NewPatchTransformerPlugin = internal.NewPatchTransformerPlugin
NewPrefixTransformerPlugin = internal.NewPrefixTransformerPlugin
NewSuffixTransformerPlugin = internal.NewSuffixTransformerPlugin
NewReplacementTransformerPlugin = internal.NewReplacementTransformerPlugin
NewReplicaCountTransformerPlugin = internal.NewReplicaCountTransformerPlugin
NewSecretGeneratorPlugin = internal.NewSecretGeneratorPlugin
NewValueAddTransformerPlugin = internal.NewValueAddTransformerPlugin
)

61
api/filesys/filesys.go Normal file
View File

@@ -0,0 +1,61 @@
// Copyright 2021 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// Package filesys provides a file system abstraction,
// a subset of that provided by golang.org/pkg/os,
// with an on-disk and in-memory representation.
//
// Deprecated: use sigs.k8s.io/kustomize/kyaml/filesys instead.
package filesys
import "sigs.k8s.io/kustomize/kyaml/filesys"
const (
// Separator is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.Separator.
Separator = filesys.Separator
// SelfDir is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.SelfDir.
SelfDir = filesys.SelfDir
// ParentDir is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.ParentDir.
ParentDir = filesys.ParentDir
)
type (
// FileSystem is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.FileSystem.
FileSystem = filesys.FileSystem
// FileSystemOrOnDisk is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.FileSystemOrOnDisk.
FileSystemOrOnDisk = filesys.FileSystemOrOnDisk
// ConfirmedDir is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.ConfirmedDir.
ConfirmedDir = filesys.ConfirmedDir
)
// MakeEmptyDirInMemory is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.MakeEmptyDirInMemory.
func MakeEmptyDirInMemory() FileSystem { return filesys.MakeEmptyDirInMemory() }
// MakeFsInMemory is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.MakeFsInMemory.
func MakeFsInMemory() FileSystem { return filesys.MakeFsInMemory() }
// MakeFsOnDisk is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.MakeFsOnDisk.
func MakeFsOnDisk() FileSystem { return filesys.MakeFsOnDisk() }
// NewTmpConfirmedDir is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.NewTmpConfirmedDir.
func NewTmpConfirmedDir() (filesys.ConfirmedDir, error) { return filesys.NewTmpConfirmedDir() }
// RootedPath is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.RootedPath.
func RootedPath(elem ...string) string { return filesys.RootedPath(elem...) }
// StripTrailingSeps is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.StripTrailingSeps.
func StripTrailingSeps(s string) string { return filesys.StripTrailingSeps(s) }
// StripLeadingSeps is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.StripLeadingSeps.
func StripLeadingSeps(s string) string { return filesys.StripLeadingSeps(s) }
// PathSplit is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.PathSplit.
func PathSplit(incoming string) []string { return filesys.PathSplit(incoming) }
// PathJoin is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.PathJoin.
func PathJoin(incoming []string) string { return filesys.PathJoin(incoming) }
// InsertPathPart is deprecated, use sigs.k8s.io/kustomize/kyaml/filesys.InsertPathPart.
func InsertPathPart(path string, pos int, part string) string {
return filesys.InsertPathPart(path, pos, part)
}

View File

@@ -1,50 +0,0 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// Package filesys provides a file system abstraction layer.
package filesys
import (
"path/filepath"
)
const (
Separator = string(filepath.Separator)
SelfDir = "."
ParentDir = ".."
)
// FileSystem groups basic os filesystem methods.
// It's supposed be functional subset of https://golang.org/pkg/os
type FileSystem interface {
// Create a file.
Create(path string) (File, error)
// MkDir makes a directory.
Mkdir(path string) error
// MkDirAll makes a directory path, creating intervening directories.
MkdirAll(path string) error
// RemoveAll removes path and any children it contains.
RemoveAll(path string) error
// Open opens the named file for reading.
Open(path string) (File, error)
// IsDir returns true if the path is a directory.
IsDir(path string) bool
// CleanedAbs converts the given path into a
// directory and a file name, where the directory
// is represented as a ConfirmedDir and all that implies.
// If the entire path is a directory, the file component
// is an empty string.
CleanedAbs(path string) (ConfirmedDir, string, error)
// Exists is true if the path exists in the file system.
Exists(path string) bool
// Glob returns the list of matching files,
// emulating https://golang.org/pkg/path/filepath/#Glob
Glob(pattern string) ([]string, error)
// ReadFile returns the contents of the file at the given path.
ReadFile(path string) ([]byte, error)
// WriteFile writes the data to a file at the given path,
// overwriting anything that's already there.
WriteFile(path string, data []byte) error
// Walk walks the file system with the given WalkFunc.
Walk(path string, walkFn filepath.WalkFunc) error
}

View File

@@ -1,165 +0,0 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package filesys_test
import (
"io/ioutil"
"os"
"path"
"path/filepath"
"reflect"
"testing"
. "sigs.k8s.io/kustomize/api/filesys"
)
func makeTestDir(t *testing.T) (FileSystem, string) {
fSys := MakeFsOnDisk()
td, err := ioutil.TempDir("", "kustomize_testing_dir")
if err != nil {
t.Fatalf("unexpected error %s", err)
}
testDir, err := filepath.EvalSymlinks(td)
if err != nil {
t.Fatalf("unexpected error %s", err)
}
if !fSys.Exists(testDir) {
t.Fatalf("expected existence")
}
if !fSys.IsDir(testDir) {
t.Fatalf("expected directory")
}
return fSys, testDir
}
func TestCleanedAbs_1(t *testing.T) {
fSys, testDir := makeTestDir(t)
defer os.RemoveAll(testDir)
d, f, err := fSys.CleanedAbs("")
if err != nil {
t.Fatalf("unexpected err=%v", err)
}
wd, err := os.Getwd()
if err != nil {
t.Fatalf("unexpected err=%v", err)
}
if d.String() != wd {
t.Fatalf("unexpected d=%s", d)
}
if f != "" {
t.Fatalf("unexpected f=%s", f)
}
}
func TestCleanedAbs_2(t *testing.T) {
fSys, testDir := makeTestDir(t)
defer os.RemoveAll(testDir)
d, f, err := fSys.CleanedAbs("/")
if err != nil {
t.Fatalf("unexpected err=%v", err)
}
if d != "/" {
t.Fatalf("unexpected d=%s", d)
}
if f != "" {
t.Fatalf("unexpected f=%s", f)
}
}
func TestCleanedAbs_3(t *testing.T) {
fSys, testDir := makeTestDir(t)
defer os.RemoveAll(testDir)
err := fSys.WriteFile(
filepath.Join(testDir, "foo"), []byte(`foo`))
if err != nil {
t.Fatalf("unexpected err=%v", err)
}
d, f, err := fSys.CleanedAbs(filepath.Join(testDir, "foo"))
if err != nil {
t.Fatalf("unexpected err=%v", err)
}
if d.String() != testDir {
t.Fatalf("unexpected d=%s", d)
}
if f != "foo" {
t.Fatalf("unexpected f=%s", f)
}
}
func TestCleanedAbs_4(t *testing.T) {
fSys, testDir := makeTestDir(t)
defer os.RemoveAll(testDir)
err := fSys.MkdirAll(filepath.Join(testDir, "d1", "d2"))
if err != nil {
t.Fatalf("unexpected err=%v", err)
}
err = fSys.WriteFile(
filepath.Join(testDir, "d1", "d2", "bar"),
[]byte(`bar`))
if err != nil {
t.Fatalf("unexpected err=%v", err)
}
d, f, err := fSys.CleanedAbs(
filepath.Join(testDir, "d1", "d2"))
if err != nil {
t.Fatalf("unexpected err=%v", err)
}
if d.String() != filepath.Join(testDir, "d1", "d2") {
t.Fatalf("unexpected d=%s", d)
}
if f != "" {
t.Fatalf("unexpected f=%s", f)
}
d, f, err = fSys.CleanedAbs(
filepath.Join(testDir, "d1", "d2", "bar"))
if err != nil {
t.Fatalf("unexpected err=%v", err)
}
if d.String() != filepath.Join(testDir, "d1", "d2") {
t.Fatalf("unexpected d=%s", d)
}
if f != "bar" {
t.Fatalf("unexpected f=%s", f)
}
}
func TestReadFilesRealFS(t *testing.T) {
fSys, testDir := makeTestDir(t)
defer os.RemoveAll(testDir)
err := fSys.WriteFile(path.Join(testDir, "foo"), []byte(`foo`))
if err != nil {
t.Fatalf("unexpected error %s", err)
}
if !fSys.Exists(path.Join(testDir, "foo")) {
t.Fatalf("expected foo")
}
if fSys.IsDir(path.Join(testDir, "foo")) {
t.Fatalf("expected foo not to be a directory")
}
err = fSys.WriteFile(path.Join(testDir, "bar"), []byte(`bar`))
if err != nil {
t.Fatalf("unexpected error %s", err)
}
files, err := fSys.Glob(path.Join("testDir", "*"))
expected := []string{
path.Join(testDir, "bar"),
path.Join(testDir, "foo"),
}
if err != nil {
t.Fatalf("expected no error")
}
if reflect.DeepEqual(files, expected) {
t.Fatalf("incorrect files found by glob: %v", files)
}
}

View File

@@ -1,125 +0,0 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package filesys
import (
"os"
"path/filepath"
"strings"
)
// RootedPath returns a rooted path, e.g. "/foo/bar" as
// opposed to "foo/bar".
func RootedPath(elem ...string) string {
return Separator + filepath.Join(elem...)
}
// StripTrailingSeps trims trailing filepath separators from input.
func StripTrailingSeps(s string) string {
k := len(s)
for k > 0 && s[k-1] == filepath.Separator {
k--
}
return s[:k]
}
// StripLeadingSeps trims leading filepath separators from input.
func StripLeadingSeps(s string) string {
k := 0
for k < len(s) && s[k] == filepath.Separator {
k++
}
return s[k:]
}
// PathSplit converts a file path to a slice of string.
// If the path is absolute (if the path has a leading slash),
// then the first entry in the result is an empty string.
// Desired: path == PathJoin(PathSplit(path))
func PathSplit(incoming string) []string {
if incoming == "" {
return []string{}
}
dir, path := filepath.Split(incoming)
if dir == string(os.PathSeparator) {
if path == "" {
return []string{""}
}
return []string{"", path}
}
dir = strings.TrimSuffix(dir, string(os.PathSeparator))
if dir == "" {
return []string{path}
}
return append(PathSplit(dir), path)
}
// PathJoin converts a slice of string to a file path.
// If the first entry is an empty string, then the returned
// path is absolute (it has a leading slash).
// Desired: path == PathJoin(PathSplit(path))
func PathJoin(incoming []string) string {
if len(incoming) == 0 {
return ""
}
if incoming[0] == "" {
return string(os.PathSeparator) + filepath.Join(incoming[1:]...)
}
return filepath.Join(incoming...)
}
// InsertPathPart inserts 'part' at position 'pos' in the given filepath.
// The first position is 0.
//
// E.g. if part == 'PEACH'
//
// OLD : NEW : POS
// --------------------------------------------------------
// {empty} : PEACH : irrelevant
// / : /PEACH : irrelevant
// pie : PEACH/pie : 0 (or negative)
// /pie : /PEACH/pie : 0 (or negative)
// raw : raw/PEACH : 1 (or larger)
// /raw : /raw/PEACH : 1 (or larger)
// a/nice/warm/pie : a/nice/warm/PEACH/pie : 3
// /a/nice/warm/pie : /a/nice/warm/PEACH/pie : 3
//
// * An empty part results in no change.
//
// * Absolute paths get their leading '/' stripped, treated like
// relative paths, and the leading '/' is re-added on output.
// The meaning of pos is intentionally the same in either absolute or
// relative paths; if it weren't, this function could convert absolute
// paths to relative paths, which is not desirable.
//
// * For robustness (liberal input, conservative output) Pos values that
// that are too small (large) to index the split filepath result in a
// prefix (postfix) rather than an error. Use extreme position values
// to assure a prefix or postfix (e.g. 0 will always prefix, and
// 9999 will presumably always postfix).
func InsertPathPart(path string, pos int, part string) string {
if part == "" {
return path
}
parts := PathSplit(path)
if pos < 0 {
pos = 0
} else if pos > len(parts) {
pos = len(parts)
}
if len(parts) > 0 && parts[0] == "" && pos < len(parts) {
// An empty string at 0 indicates an absolute path, and means
// we must increment pos. This change means that a position
// specification has the same meaning in relative and absolute paths.
// E.g. in either the path 'a/b/c' or the path '/a/b/c',
// 'a' is at 0, 'b' is at 1 and 'c' is at 2, and inserting at
// zero means a new first field _without_ changing an absolute
// path to a relative path.
pos++
}
result := make([]string, len(parts)+1)
copy(result, parts[0:pos])
result[pos] = part
return PathJoin(append(result, parts[pos:]...))
}

View File

@@ -1,374 +0,0 @@
package filesys_test
import (
"os"
"path/filepath"
"testing"
. "sigs.k8s.io/kustomize/api/filesys"
)
// Confirm behavior of filepath.Match
func TestFilePathMatch(t *testing.T) {
cases := []struct {
pattern string
path string
expected bool
}{
{
pattern: "*e*",
path: "hey",
expected: true,
},
{
pattern: "*e*",
path: "hay",
expected: false,
},
{
pattern: "*e*",
path: filepath.Join("h", "e", "y"),
expected: false,
},
{
pattern: "*/e/*",
path: filepath.Join("h", "e", "y"),
expected: true,
},
{
pattern: "h/e/*",
path: filepath.Join("h", "e", "y"),
expected: true,
},
{
pattern: "*/e/y",
path: filepath.Join("h", "e", "y"),
expected: true,
},
{
pattern: "*/*/*",
path: filepath.Join("h", "e", "y"),
expected: true,
},
{
pattern: "*/*/*",
path: filepath.Join("h", "e", "y", "there"),
expected: false,
},
{
pattern: "*/*/*/t*e",
path: filepath.Join("h", "e", "y", "there"),
expected: true,
},
}
for _, item := range cases {
match, err := filepath.Match(item.pattern, item.path)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
if match != item.expected {
t.Fatalf("'%s' '%s' %v\n", item.pattern, item.path, match)
}
}
}
// Confirm behavior of filepath.Split
func TestFilePathSplit(t *testing.T) {
cases := []struct {
full string
dir string
file string
}{
{
full: "",
dir: "",
file: "",
},
{
full: SelfDir,
dir: "",
file: SelfDir,
},
{
full: "rabbit.jpg",
dir: "",
file: "rabbit.jpg",
},
{
full: "/",
dir: "/",
file: "",
},
{
full: "/beans",
dir: "/",
file: "beans",
},
{
full: "/home/foo/bar",
dir: "/home/foo/",
file: "bar",
},
{
full: "/usr/local/",
dir: "/usr/local/",
file: "",
},
{
full: "/usr//local//go",
dir: "/usr//local//",
file: "go",
},
}
for _, p := range cases {
dir, file := filepath.Split(p.full)
if dir != p.dir || file != p.file {
t.Fatalf(
"in '%s',\ngot dir='%s' (expected '%s'),\n got file='%s' (expected %s).",
p.full, dir, p.dir, file, p.file)
}
}
}
func TestPathSplitAndJoin(t *testing.T) {
cases := map[string]struct {
original string
expected []string
}{
"Empty": {
original: "",
expected: []string{},
},
"One": {
original: "hello",
expected: []string{"hello"},
},
"Two": {
original: "hello/there",
expected: []string{"hello", "there"},
},
"Three": {
original: "hello/my/friend",
expected: []string{"hello", "my", "friend"},
},
}
for n, c := range cases {
f := func(t *testing.T, original string, expected []string) {
actual := PathSplit(original)
if len(actual) != len(expected) {
t.Fatalf(
"expected len %d, got len %d",
len(expected), len(actual))
}
for i := range expected {
if expected[i] != actual[i] {
t.Fatalf(
"at i=%d, expected '%s', got '%s'",
i, expected[i], actual[i])
}
}
joined := PathJoin(actual)
if joined != original {
t.Fatalf(
"when rejoining, expected '%s', got '%s'",
original, joined)
}
}
t.Run("relative"+n, func(t *testing.T) {
f(t, c.original, c.expected)
})
t.Run("absolute"+n, func(t *testing.T) {
f(t,
string(os.PathSeparator)+c.original,
append([]string{""}, c.expected...))
})
}
}
func TestInsertPathPart(t *testing.T) {
cases := map[string]struct {
original string
pos int
part string
expected string
}{
"rootOne": {
original: "/",
pos: 0,
part: "___",
expected: "/___",
},
"rootTwo": {
original: "/",
pos: 444,
part: "___",
expected: "/___",
},
"rootedFirst": {
original: "/apple",
pos: 0,
part: "___",
expected: "/___/apple",
},
"rootedSecond": {
original: "/apple",
pos: 444,
part: "___",
expected: "/apple/___",
},
"rootedThird": {
original: "/apple/banana",
pos: 444,
part: "___",
expected: "/apple/banana/___",
},
"emptyLow": {
original: "",
pos: -3,
part: "___",
expected: "___",
},
"emptyHigh": {
original: "",
pos: 444,
part: "___",
expected: "___",
},
"peachPie": {
original: "a/nice/warm/pie",
pos: 3,
part: "PEACH",
expected: "a/nice/warm/PEACH/pie",
},
"rootedPeachPie": {
original: "/a/nice/warm/pie",
pos: 3,
part: "PEACH",
expected: "/a/nice/warm/PEACH/pie",
},
"longStart": {
original: "a/b/c/d/e/f",
pos: 0,
part: "___",
expected: "___/a/b/c/d/e/f",
},
"rootedLongStart": {
original: "/a/b/c/d/e/f",
pos: 0,
part: "___",
expected: "/___/a/b/c/d/e/f",
},
"longMiddle": {
original: "a/b/c/d/e/f",
pos: 3,
part: "___",
expected: "a/b/c/___/d/e/f",
},
"rootedLongMiddle": {
original: "/a/b/c/d/e/f",
pos: 3,
part: "___",
expected: "/a/b/c/___/d/e/f",
},
"longEnd": {
original: "a/b/c/d/e/f",
pos: 444,
part: "___",
expected: "a/b/c/d/e/f/___",
},
"rootedLongEnd": {
original: "/a/b/c/d/e/f",
pos: 444,
part: "___",
expected: "/a/b/c/d/e/f/___",
},
}
for n, c := range cases {
t.Run(n, func(t *testing.T) {
actual := InsertPathPart(c.original, c.pos, c.part)
if actual != c.expected {
t.Fatalf("expected '%s', got '%s'", c.expected, actual)
}
})
}
}
func TestStripTrailingSeps(t *testing.T) {
cases := []struct {
full string
rem string
}{
{
full: "foo",
rem: "foo",
},
{
full: "",
rem: "",
},
{
full: "foo/",
rem: "foo",
},
{
full: "foo///bar///",
rem: "foo///bar",
},
{
full: "/////",
rem: "",
},
{
full: "/",
rem: "",
},
}
for _, p := range cases {
dir := StripTrailingSeps(p.full)
if dir != p.rem {
t.Fatalf(
"in '%s', got dir='%s' (expected '%s')",
p.full, dir, p.rem)
}
}
}
func TestStripLeadingSeps(t *testing.T) {
cases := []struct {
full string
rem string
}{
{
full: "foo",
rem: "foo",
},
{
full: "",
rem: "",
},
{
full: "/foo",
rem: "foo",
},
{
full: "///foo///bar///",
rem: "foo///bar///",
},
{
full: "/////",
rem: "",
},
{
full: "/",
rem: "",
},
}
for _, p := range cases {
dir := StripLeadingSeps(p.full)
if dir != p.rem {
t.Fatalf(
"in '%s', got dir='%s' (expected '%s')",
p.full, dir, p.rem)
}
}
}

View File

@@ -19,18 +19,26 @@ type Filter struct {
// FsSlice contains the FieldSpecs to locate the namespace field
FsSlice types.FsSlice
trackableSetter filtersutil.TrackableSetter
}
var _ kio.Filter = Filter{}
var _ kio.TrackableFilter = &Filter{}
// WithMutationTracker registers a callback which will be invoked each time a field is mutated
func (f *Filter) WithMutationTracker(callback func(key, value, tag string, node *yaml.RNode)) {
f.trackableSetter.WithMutationTracker(callback)
}
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
keys := filtersutil.SortedMapKeys(f.Annotations)
keys := yaml.SortedMapKeys(f.Annotations)
_, err := kio.FilterAll(yaml.FilterFunc(
func(node *yaml.RNode) (*yaml.RNode, error) {
for _, k := range keys {
if err := node.PipeE(fsslice.Filter{
FsSlice: f.FsSlice,
SetValue: filtersutil.SetEntry(
SetValue: f.trackableSetter.SetEntry(
k, f.Annotations[k], yaml.NodeTagString),
CreateKind: yaml.MappingNode, // Annotations are MappingNodes.
CreateTag: yaml.NodeTagMap,

View File

@@ -11,16 +11,20 @@ import (
"sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
filtertest_test "sigs.k8s.io/kustomize/api/testutils/filtertest"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
var annosFs = builtinconfig.MakeDefaultConfig().CommonAnnotations
func TestAnnotations_Filter(t *testing.T) {
mutationTrackStub := filtertest_test.MutationTrackerStub{}
testCases := map[string]struct {
input string
expectedOutput string
filter Filter
fsslice types.FsSlice
input string
expectedOutput string
filter Filter
fsslice types.FsSlice
setEntryCallback func(key, value, tag string, node *yaml.RNode)
expectedSetEntryArgs []filtertest_test.SetValueArg
}{
"add": {
input: `
@@ -210,17 +214,86 @@ metadata:
"b": "b1",
}},
},
// test usage of SetEntryCallback
"set_entry_callback": {
input: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
`,
expectedOutput: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
annotations:
a: a1
b: b1
spec:
template:
metadata:
annotations:
a: a1
b: b1
`,
filter: Filter{
Annotations: annoMap{
"a": "a1",
"b": "b1",
},
},
setEntryCallback: mutationTrackStub.MutationTracker,
fsslice: []types.FieldSpec{
{
Path: "spec/template/metadata/annotations",
CreateIfNotPresent: true,
},
},
expectedSetEntryArgs: []filtertest_test.SetValueArg{
{
Key: "a",
Value: "a1",
Tag: "!!str",
NodePath: []string{"metadata", "annotations"},
},
{
Key: "a",
Value: "a1",
Tag: "!!str",
NodePath: []string{"spec", "template", "metadata", "annotations"},
},
{
Key: "b",
Value: "b1",
Tag: "!!str",
NodePath: []string{"metadata", "annotations"},
},
{
Key: "b",
Value: "b1",
Tag: "!!str",
NodePath: []string{"spec", "template", "metadata", "annotations"},
},
},
},
}
for tn, tc := range testCases {
mutationTrackStub.Reset()
t.Run(tn, func(t *testing.T) {
filter := tc.filter
filter.FsSlice = append(annosFs, tc.fsslice...)
filter.WithMutationTracker(tc.setEntryCallback)
filter.FsSlice = append(annosFs, tc.fsslice...) //nolint:gocritic
if !assert.Equal(t,
strings.TrimSpace(tc.expectedOutput),
strings.TrimSpace(filtertest_test.RunFilter(t, tc.input, filter))) {
t.FailNow()
}
if !assert.Equal(t, tc.expectedSetEntryArgs, mutationTrackStub.SetValueArgs()) {
t.FailNow()
}
})
}
}

View File

@@ -28,7 +28,9 @@ metadata:
`)}},
Filters: []kio.Filter{Filter{
Annotations: map[string]string{
"foo": "bar",
"foo": "bar",
"booleanValue": "true",
"numberValue": "42",
},
FsSlice: fss,
}},
@@ -44,12 +46,16 @@ metadata:
// metadata:
// name: instance
// annotations:
// booleanValue: "true"
// foo: bar
// numberValue: "42"
// ---
// apiVersion: example.com/v1
// kind: Bar
// metadata:
// name: instance
// annotations:
// booleanValue: "true"
// foo: bar
// numberValue: "42"
}

8
api/filters/doc.go Normal file
View File

@@ -0,0 +1,8 @@
// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package filters
// Package filters collects various implementations
// sigs.k8s.io/kustomize/kyaml/kio.Filter used by kustomize
// transformers to modify kubernetes objects.

View File

@@ -4,17 +4,29 @@
package fieldspec
import (
"fmt"
"strings"
"sigs.k8s.io/kustomize/api/filters/filtersutil"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/resid"
"sigs.k8s.io/kustomize/kyaml/utils"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
var _ yaml.Filter = Filter{}
// Filter applies a single fieldSpec to a single object
// Filter possibly mutates its object argument using a FieldSpec.
// If the object matches the FieldSpec, and the node found
// by following the fieldSpec's path is non-null, this filter calls
// the setValue function on the node at the end of the path.
// If any part of the path doesn't exist, the filter returns
// without doing anything and without error, unless it was set
// to create the path. If set to create, it creates a tree of maps
// along the path, and the leaf node gets the setValue called on it.
// Error on GVK mismatch, empty or poorly formed path.
// Filter expect kustomize style paths, not JSON paths.
// Filter stores internal state and should not be reused
type Filter struct {
// FieldSpec contains the path to the value to set.
@@ -34,47 +46,52 @@ type Filter struct {
func (fltr Filter) Filter(obj *yaml.RNode) (*yaml.RNode, error) {
// check if the FieldSpec applies to the object
if match, err := isMatchGVK(fltr.FieldSpec, obj); !match || err != nil {
return obj, errors.Wrap(err)
if match := isMatchGVK(fltr.FieldSpec, obj); !match {
return obj, nil
}
fltr.path = splitPath(fltr.FieldSpec.Path)
fltr.path = utils.PathSplitter(fltr.FieldSpec.Path, "/")
if err := fltr.filter(obj); err != nil {
s, _ := obj.String()
return nil, errors.WrapPrefixf(err,
"obj '%s' at path '%v'", s, fltr.FieldSpec.Path)
"considering field '%s' of object %s", fltr.FieldSpec.Path, resid.FromRNode(obj))
}
return obj, nil
}
// Recursively called.
func (fltr Filter) filter(obj *yaml.RNode) error {
if len(fltr.path) == 0 {
// found the field -- set its value
return fltr.SetValue(obj)
}
if obj.IsTaggedNull() {
if obj.IsTaggedNull() || obj.IsNil() {
return nil
}
switch obj.YNode().Kind {
case yaml.SequenceNode:
return fltr.seq(obj)
return fltr.handleSequence(obj)
case yaml.MappingNode:
return fltr.field(obj)
return fltr.handleMap(obj)
case yaml.AliasNode:
return fltr.filter(yaml.NewRNode(obj.YNode().Alias))
default:
return errors.Errorf("expected sequence or mapping node")
}
}
// field calls filter on the field matching the next path element
func (fltr Filter) field(obj *yaml.RNode) error {
// handleMap calls filter on the map field matching the next path element
func (fltr Filter) handleMap(obj *yaml.RNode) error {
fieldName, isSeq := isSequenceField(fltr.path[0])
if fieldName == "" {
return fmt.Errorf("cannot set or create an empty field name")
}
// lookup the field matching the next path element
var lookupField yaml.Filter
var operation yaml.Filter
var kind yaml.Kind
tag := yaml.NodeTagEmpty
switch {
case !fltr.FieldSpec.CreateIfNotPresent || fltr.CreateKind == 0 || isSeq:
// dont' create the field if we don't find it
lookupField = yaml.Lookup(fieldName)
// don't create the field if we don't find it
operation = yaml.Lookup(fieldName)
if isSeq {
// The query path thinks this field should be a sequence;
// accept this hint for use later if the tag is NodeTagNull.
@@ -82,21 +99,25 @@ func (fltr Filter) field(obj *yaml.RNode) error {
}
case len(fltr.path) <= 1:
// create the field if it is missing: use the provided node kind
lookupField = yaml.LookupCreate(fltr.CreateKind, fieldName)
operation = yaml.LookupCreate(fltr.CreateKind, fieldName)
kind = fltr.CreateKind
tag = fltr.CreateTag
default:
// create the field if it is missing: must be a mapping node
lookupField = yaml.LookupCreate(yaml.MappingNode, fieldName)
operation = yaml.LookupCreate(yaml.MappingNode, fieldName)
kind = yaml.MappingNode
tag = yaml.NodeTagMap
}
// locate (or maybe create) the field
field, err := obj.Pipe(lookupField)
if err != nil || field == nil {
field, err := obj.Pipe(operation)
if err != nil {
return errors.WrapPrefixf(err, "fieldName: %s", fieldName)
}
if field == nil {
// No error if field not found.
return nil
}
// if the value exists, but is null and kind is set,
// then change it to the creation type
@@ -114,8 +135,10 @@ func (fltr Filter) field(obj *yaml.RNode) error {
}
// seq calls filter on all sequence elements
func (fltr Filter) seq(obj *yaml.RNode) error {
func (fltr Filter) handleSequence(obj *yaml.RNode) error {
if err := obj.VisitElements(func(node *yaml.RNode) error {
// set an accurate FieldPath for nested elements
node.AppendToFieldPath(obj.FieldPath()...)
// recurse on each element -- re-allocating a Filter is
// not strictly required, but is more consistent with field
// and less likely to have side effects
@@ -125,56 +148,35 @@ func (fltr Filter) seq(obj *yaml.RNode) error {
return errors.WrapPrefixf(err,
"visit traversal on path: %v", fltr.path)
}
return nil
}
// isSequenceField returns true if the path element is for a sequence field.
// isSequence also returns the path element with the '[]' suffix trimmed
func isSequenceField(name string) (string, bool) {
isSeq := strings.HasSuffix(name, "[]")
name = strings.TrimSuffix(name, "[]")
return name, isSeq
shorter := strings.TrimSuffix(name, "[]")
return shorter, shorter != name
}
// isMatchGVK returns true if the fs.GVK matches the obj GVK.
func isMatchGVK(fs types.FieldSpec, obj *yaml.RNode) (bool, error) {
meta, err := obj.GetMeta()
if err != nil {
return false, err
}
if fs.Kind != "" && fs.Kind != meta.Kind {
func isMatchGVK(fs types.FieldSpec, obj *yaml.RNode) bool {
if kind := obj.GetKind(); fs.Kind != "" && fs.Kind != kind {
// kind doesn't match
return false, err
return false
}
// parse the group and version from the apiVersion field
group, version := parseGV(meta.APIVersion)
group, version := resid.ParseGroupVersion(obj.GetApiVersion())
if fs.Group != "" && fs.Group != group {
// group doesn't match
return false, nil
return false
}
if fs.Version != "" && fs.Version != version {
// version doesn't match
return false, nil
return false
}
return true, nil
}
func splitPath(path string) []string {
ps := strings.Split(path, "/")
var res []string
res = append(res, ps[0])
for i := 1; i < len(ps); i++ {
lastIndex := len(res) - 1
if strings.HasSuffix(res[lastIndex], "\\") {
res[lastIndex] = strings.TrimSuffix(res[lastIndex], "\\") + "/" + ps[i]
} else {
res = append(res, ps[i])
}
}
return res
return true
}

View File

@@ -15,206 +15,239 @@ import (
"sigs.k8s.io/kustomize/kyaml/yaml"
)
type TestCase struct {
name string
input string
expected string
filter fieldspec.Filter
fieldSpec string
error string
}
var tests = []TestCase{
{
name: "update",
fieldSpec: `
func TestFilter_Filter(t *testing.T) {
testCases := map[string]struct {
input string
expected string
filter fieldspec.Filter
fieldSpec string
error string
}{
"path not found": {
fieldSpec: `
path: a/b
group: foo
kind: Bar
`,
input: `
input: `
apiVersion: foo
kind: Bar
xxx:
`,
expected: `
apiVersion: foo
kind: Bar
xxx:
`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
},
},
"empty path": {
fieldSpec: `
group: foo
version: v1
kind: Bar
`,
input: `
apiVersion: foo/v1
kind: Bar
xxx:
`,
expected: `
apiVersion: foo
kind: Bar
xxx:
`,
error: `considering field '' of object Bar.v1.foo/[noName].[noNs]: cannot set or create an empty field name`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
},
},
"update": {
fieldSpec: `
path: a/b
group: foo
kind: Bar
`,
input: `
apiVersion: foo/v1beta1
kind: Bar
a:
b: c
`,
expected: `
expected: `
apiVersion: foo/v1beta1
kind: Bar
a:
b: e
`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
},
},
},
{
name: "update-kind-not-match",
fieldSpec: `
"update-kind-not-match": {
fieldSpec: `
path: a/b
group: foo
kind: Bar1
`,
input: `
input: `
apiVersion: foo/v1beta1
kind: Bar2
a:
b: c
`,
expected: `
expected: `
apiVersion: foo/v1beta1
kind: Bar2
a:
b: c
`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
},
},
},
{
name: "update-group-not-match",
fieldSpec: `
"update-group-not-match": {
fieldSpec: `
path: a/b
group: foo1
kind: Bar
`,
input: `
input: `
apiVersion: foo2/v1beta1
kind: Bar
a:
b: c
`,
expected: `
expected: `
apiVersion: foo2/v1beta1
kind: Bar
a:
b: c
`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
},
},
},
{
name: "update-version-not-match",
fieldSpec: `
"update-version-not-match": {
fieldSpec: `
path: a/b
group: foo
version: v1beta1
kind: Bar
`,
input: `
input: `
apiVersion: foo/v1beta2
kind: Bar
a:
b: c
`,
expected: `
expected: `
apiVersion: foo/v1beta2
kind: Bar
a:
b: c
`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
},
},
},
{
name: "bad-version",
fieldSpec: `
"bad-version": {
fieldSpec: `
path: a/b
group: foo
version: v1beta1
kind: Bar
`,
input: `
input: `
apiVersion: foo/v1beta2/something
kind: Bar
a:
b: c
`,
expected: `
expected: `
apiVersion: foo/v1beta2/something
kind: Bar
a:
b: c
`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
},
},
},
{
name: "bad-meta",
fieldSpec: `
"bad-meta": {
fieldSpec: `
path: a/b
group: foo
version: v1beta1
kind: Bar
`,
input: `
input: `
a:
b: c
`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
expected: `
a:
b: c
`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
},
},
error: "missing Resource metadata",
},
{
name: "miss-match-type",
fieldSpec: `
"miss-match-type": {
fieldSpec: `
path: a/b/c
kind: Bar
`,
input: `
input: `
kind: Bar
a:
b: a
`,
error: "obj 'kind: Bar\na:\n b: a\n' at path 'a/b/c': " +
"expected sequence or mapping node",
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
error: `considering field 'a/b/c' of object Bar.[noVer].[noGrp]/[noName].[noNs]: expected sequence or mapping node`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
},
},
},
{
name: "add",
fieldSpec: `
"add": {
fieldSpec: `
path: a/b/c/d
group: foo
create: true
kind: Bar
`,
input: `
input: `
apiVersion: foo/v1beta1
kind: Bar
a: {}
`,
expected: `
expected: `
apiVersion: foo/v1beta1
kind: Bar
a: {b: {c: {d: e}}}
`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
CreateKind: yaml.ScalarNode,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
CreateKind: yaml.ScalarNode,
},
},
},
{
name: "update-in-sequence",
fieldSpec: `
"update-in-sequence": {
fieldSpec: `
path: a/b[]/c/d
group: foo
kind: Bar
`,
input: `
input: `
apiVersion: foo/v1beta1
kind: Bar
a:
@@ -222,7 +255,7 @@ a:
- c:
d: a
`,
expected: `
expected: `
apiVersion: foo/v1beta1
kind: Bar
a:
@@ -230,244 +263,237 @@ a:
- c:
d: e
`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
},
},
},
// Don't create a sequence
{
name: "empty-sequence-no-create",
fieldSpec: `
// Don't create a sequence
"empty-sequence-no-create": {
fieldSpec: `
path: a/b[]/c/d
group: foo
create: true
kind: Bar
`,
input: `
input: `
apiVersion: foo/v1beta1
kind: Bar
a: {}
`,
expected: `
expected: `
apiVersion: foo/v1beta1
kind: Bar
a: {}
`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
CreateKind: yaml.ScalarNode,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
CreateKind: yaml.ScalarNode,
},
},
},
// Create a new field for an element in a sequence
{
name: "empty-sequence-create",
fieldSpec: `
// Create a new field for an element in a sequence
"empty-sequence-create": {
fieldSpec: `
path: a/b[]/c/d
group: foo
create: true
kind: Bar
`,
input: `
input: `
apiVersion: foo/v1beta1
kind: Bar
a:
b:
- c: {}
`,
expected: `
expected: `
apiVersion: foo/v1beta1
kind: Bar
a:
b:
- c: {d: e}
`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
CreateKind: yaml.ScalarNode,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
CreateKind: yaml.ScalarNode,
},
},
},
{
name: "group v1",
fieldSpec: `
"group v1": {
fieldSpec: `
path: a/b
group: v1
create: true
kind: Bar
`,
input: `
input: `
apiVersion: v1
kind: Bar
`,
expected: `
expected: `
apiVersion: v1
kind: Bar
`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
CreateKind: yaml.ScalarNode,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
CreateKind: yaml.ScalarNode,
},
},
},
{
name: "version v1",
fieldSpec: `
"version v1": {
fieldSpec: `
path: a/b
version: v1
create: true
kind: Bar
`,
input: `
input: `
apiVersion: v1
kind: Bar
`,
expected: `
expected: `
apiVersion: v1
kind: Bar
a:
b: e
`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
CreateKind: yaml.ScalarNode,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("e"),
CreateKind: yaml.ScalarNode,
},
},
},
{
name: "successfully set field on array entry no sequence hint",
fieldSpec: `
"successfully set field on array entry no sequence hint": {
fieldSpec: `
path: spec/containers/image
version: v1
kind: Bar
`,
input: `
input: `
apiVersion: v1
kind: Bar
spec:
containers:
- image: foo
`,
expected: `
expected: `
apiVersion: v1
kind: Bar
spec:
containers:
- image: bar
`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("bar"),
CreateKind: yaml.ScalarNode,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("bar"),
CreateKind: yaml.ScalarNode,
},
},
},
{
name: "successfully set field on array entry with sequence hint",
fieldSpec: `
"successfully set field on array entry with sequence hint": {
fieldSpec: `
path: spec/containers[]/image
version: v1
kind: Bar
`,
input: `
input: `
apiVersion: v1
kind: Bar
spec:
containers:
- image: foo
`,
expected: `
expected: `
apiVersion: v1
kind: Bar
spec:
containers:
- image: bar
`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("bar"),
CreateKind: yaml.ScalarNode,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("bar"),
CreateKind: yaml.ScalarNode,
},
},
},
{
name: "failure to set field on array entry with sequence hint in path",
fieldSpec: `
"failure to set field on array entry with sequence hint in path": {
fieldSpec: `
path: spec/containers[]/image
version: v1
kind: Bar
`,
input: `
input: `
apiVersion: v1
kind: Bar
spec:
containers:
`,
expected: `
expected: `
apiVersion: v1
kind: Bar
spec:
containers: []
`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("bar"),
CreateKind: yaml.ScalarNode,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("bar"),
CreateKind: yaml.ScalarNode,
},
},
},
{
name: "failure to set field on array entry, no sequence hint in path",
fieldSpec: `
"failure to set field on array entry, no sequence hint in path": {
fieldSpec: `
path: spec/containers/image
version: v1
kind: Bar
`,
input: `
input: `
apiVersion: v1
kind: Bar
spec:
containers:
`,
expected: `
expected: `
apiVersion: v1
kind: Bar
spec:
containers:
`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("bar"),
CreateKind: yaml.ScalarNode,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("bar"),
CreateKind: yaml.ScalarNode,
},
},
},
{
name: "filedname with slash '/'",
fieldSpec: `
"fieldname with slash '/'": {
fieldSpec: `
path: a/b\/c/d
version: v1
kind: Bar
`,
input: `
input: `
apiVersion: v1
kind: Bar
a:
b/c:
d: foo
`,
expected: `
expected: `
apiVersion: v1
kind: Bar
a:
b/c:
d: bar
`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("bar"),
CreateKind: yaml.ScalarNode,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("bar"),
CreateKind: yaml.ScalarNode,
},
},
},
{
name: "filedname with multiple '/'",
fieldSpec: `
"fieldname with multiple '/'": {
fieldSpec: `
path: a/b\/c/d\/e/f
version: v1
kind: Bar
`,
input: `
input: `
apiVersion: v1
kind: Bar
a:
@@ -475,7 +501,7 @@ a:
d/e:
f: foo
`,
expected: `
expected: `
apiVersion: v1
kind: Bar
a:
@@ -483,25 +509,24 @@ a:
d/e:
f: bar
`,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("bar"),
CreateKind: yaml.ScalarNode,
filter: fieldspec.Filter{
SetValue: filtersutil.SetScalar("bar"),
CreateKind: yaml.ScalarNode,
},
},
},
}
}
func TestFilter_Filter(t *testing.T) {
for i := range tests {
test := tests[i]
t.Run(test.name, func(t *testing.T) {
err := yaml.Unmarshal([]byte(test.fieldSpec), &test.filter.FieldSpec)
for n := range testCases {
tc := testCases[n]
t.Run(n, func(t *testing.T) {
err := yaml.Unmarshal([]byte(tc.fieldSpec), &tc.filter.FieldSpec)
if !assert.NoError(t, err) {
t.FailNow()
}
out := &bytes.Buffer{}
rw := &kio.ByteReadWriter{
Reader: bytes.NewBufferString(test.input),
Reader: bytes.NewBufferString(tc.input),
Writer: out,
OmitReaderAnnotations: true,
}
@@ -509,11 +534,11 @@ func TestFilter_Filter(t *testing.T) {
// run the filter
err = kio.Pipeline{
Inputs: []kio.Reader{rw},
Filters: []kio.Filter{kio.FilterAll(test.filter)},
Filters: []kio.Filter{kio.FilterAll(tc.filter)},
Outputs: []kio.Writer{rw},
}.Execute()
if test.error != "" {
if !assert.EqualError(t, err, test.error) {
if tc.error != "" {
if !assert.EqualError(t, err, tc.error) {
t.FailNow()
}
// stop rest of test
@@ -526,10 +551,92 @@ func TestFilter_Filter(t *testing.T) {
// check results
if !assert.Equal(t,
strings.TrimSpace(test.expected),
strings.TrimSpace(tc.expected),
strings.TrimSpace(out.String())) {
t.FailNow()
}
})
}
}
func TestFilter_FieldPaths(t *testing.T) {
testCases := map[string]struct {
input string
fieldSpec string
expected []string
}{
"fieldpath containing SequenceNode": {
input: `
apiVersion: v1
kind: Pod
metadata:
name: app
spec:
containers:
- name: store
image: redis:6.2.6
- name: server
image: nginx:latest
`,
fieldSpec: `
path: spec/containers[]/image
kind: Pod
`,
expected: []string{
"spec.containers.image",
"spec.containers.image",
},
},
"fieldpath with MappingNode": {
input: `
apiVersion: v1
kind: Pod
metadata:
name: app
spec:
containers:
- name: store
image: redis:6.2.6
- name: server
image: nginx:latest
`,
fieldSpec: `
path: metadata/name
kind: Pod
`,
expected: []string{
"metadata.name",
},
},
}
for name, tc := range testCases {
var fieldPaths []string
trackableSetter := filtersutil.TrackableSetter{}
trackableSetter.WithMutationTracker(func(key, value, tag string, node *yaml.RNode) {
fieldPaths = append(fieldPaths, strings.Join(node.FieldPath(), "."))
})
filter := fieldspec.Filter{
SetValue: trackableSetter.SetScalar("foo"),
}
t.Run(name, func(t *testing.T) {
err := yaml.Unmarshal([]byte(tc.fieldSpec), &filter.FieldSpec)
assert.NoError(t, err)
rw := &kio.ByteReadWriter{
Reader: bytes.NewBufferString(tc.input),
Writer: &bytes.Buffer{},
OmitReaderAnnotations: true,
}
// run the filter
err = kio.Pipeline{
Inputs: []kio.Reader{rw},
Filters: []kio.Filter{kio.FilterAll(filter)},
Outputs: []kio.Writer{rw},
}.Execute()
assert.NoError(t, err)
assert.Equal(t, tc.expected, fieldPaths)
})
}
}

View File

@@ -1,49 +0,0 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package fieldspec
import (
"strings"
"sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
// Return true for 'v' followed by a 1 or 2, and don't look at rest.
// I.e. 'v1', 'v1beta1', 'v2', would return true.
func looksLikeACoreApiVersion(s string) bool {
if len(s) < 2 {
return false
}
if s[0:1] != "v" {
return false
}
return s[1:2] == "1" || s[1:2] == "2"
}
// parseGV parses apiVersion field into group and version.
func parseGV(apiVersion string) (group, version string) {
// parse the group and version from the apiVersion field
parts := strings.SplitN(apiVersion, "/", 2)
group = parts[0]
if len(parts) > 1 {
version = parts[1]
}
// Special case the original "apiVersion" of what
// we now call the "core" (empty) group.
if version == "" && looksLikeACoreApiVersion(group) {
version = group
group = ""
}
return
}
// GetGVK parses the metadata into a GVK
func GetGVK(meta yaml.ResourceMeta) resid.Gvk {
group, version := parseGV(meta.APIVersion)
return resid.Gvk{
Group: group,
Version: version,
Kind: meta.Kind,
}
}

View File

@@ -1,156 +0,0 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package fieldspec
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
func TestParseGV(t *testing.T) {
testCases := map[string]struct {
input string
expectedGroup string
expectedVersion string
}{
"empty": {
input: "",
expectedGroup: "",
expectedVersion: "",
},
"certSigning": {
input: "certificates.k8s.io/v1beta1",
expectedGroup: "certificates.k8s.io",
expectedVersion: "v1beta1",
},
"extensions": {
input: "extensions/v1beta1",
expectedGroup: "extensions",
expectedVersion: "v1beta1",
},
"normal": {
input: "apps/v1",
expectedGroup: "apps",
expectedVersion: "v1",
},
"justApps": {
input: "apps",
expectedGroup: "apps",
expectedVersion: "",
},
"coreV1": {
input: "v1",
expectedGroup: "",
expectedVersion: "v1",
},
"coreV2": {
input: "v2",
expectedGroup: "",
expectedVersion: "v2",
},
"coreV2Beta1": {
input: "v2beta1",
expectedGroup: "",
expectedVersion: "v2beta1",
},
}
for tn, tc := range testCases {
t.Run(tn, func(t *testing.T) {
group, version := parseGV(tc.input)
if !assert.Equal(t, tc.expectedGroup, group) {
t.FailNow()
}
if !assert.Equal(t, tc.expectedVersion, version) {
t.FailNow()
}
})
}
}
func TestGetGVK(t *testing.T) {
testCases := map[string]struct {
input string
expected resid.Gvk
parseError string
metaError string
}{
"empty": {
input: `
`,
parseError: "EOF",
},
"junk": {
input: `
congress: effective
`,
metaError: "missing Resource metadata",
},
"normal": {
input: `
apiVersion: apps/v1
kind: Deployment
`,
expected: resid.Gvk{Group: "apps", Version: "v1", Kind: "Deployment"},
},
"apiVersionOnlyWithSlash": {
input: `
apiVersion: apps/v1
`,
expected: resid.Gvk{Group: "apps", Version: "v1", Kind: ""},
},
"apiVersionOnlyNoSlash1": {
input: `
apiVersion: apps
`,
expected: resid.Gvk{Group: "apps", Version: "", Kind: ""},
},
"apiVersionOnlyNoSlash2": {
input: `
apiVersion: v1
`,
expected: resid.Gvk{Group: "", Version: "v1", Kind: ""},
},
}
for tn, tc := range testCases {
t.Run(tn, func(t *testing.T) {
obj, err := yaml.Parse(tc.input)
if len(tc.parseError) != 0 {
if err == nil {
t.Error("expected parse error")
return
}
if !strings.Contains(err.Error(), tc.parseError) {
t.Errorf("expected parse err '%s', got '%v'", tc.parseError, err)
}
return
}
if !assert.NoError(t, err) {
t.FailNow()
}
meta, err := obj.GetMeta()
if len(tc.metaError) != 0 {
if err == nil {
t.Error("expected meta error")
return
}
if !strings.Contains(err.Error(), tc.metaError) {
t.Errorf("expected meta err '%s', got '%v'", tc.metaError, err)
}
return
}
if !assert.NoError(t, err) {
t.FailNow()
}
gvk := GetGVK(meta)
if !assert.Equal(t, tc.expected, gvk) {
t.FailNow()
}
})
}
}

View File

@@ -1,21 +0,0 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package filtersutil
import (
"sort"
)
// SortedMapKeys returns a sorted slice of keys to the given map.
// Writing this function never gets old.
func SortedMapKeys(m map[string]string) []string {
keys := make([]string, len(m))
i := 0
for k := range m {
keys[i] = k
i++
}
sort.Strings(keys)
return keys
}

View File

@@ -1,34 +0,0 @@
package filtersutil_test
import (
"testing"
"github.com/stretchr/testify/assert"
"sigs.k8s.io/kustomize/api/filters/filtersutil"
)
func TestSortedKeys(t *testing.T) {
testCases := map[string]struct {
input map[string]string
expected []string
}{
"empty": {
input: map[string]string{},
expected: []string{}},
"one": {
input: map[string]string{"a": "aaa"},
expected: []string{"a"}},
"three": {
input: map[string]string{"c": "ccc", "b": "bbb", "a": "aaa"},
expected: []string{"a", "b", "c"}},
}
for tn, tc := range testCases {
t.Run(tn, func(t *testing.T) {
if !assert.Equal(t,
filtersutil.SortedMapKeys(tc.input),
tc.expected) {
t.FailNow()
}
})
}
}

View File

@@ -1,3 +1,6 @@
// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package filtersutil
import (
@@ -21,9 +24,6 @@ func SetEntry(key, value, tag string) SetFn {
Value: value,
Tag: tag,
}
if tag == yaml.NodeTagString && yaml.IsYaml1_1NonString(n) {
n.Style = yaml.DoubleQuotedStyle
}
return func(node *yaml.RNode) error {
return node.PipeE(yaml.FieldSetter{
Name: key,
@@ -31,3 +31,39 @@ func SetEntry(key, value, tag string) SetFn {
})
}
}
type TrackableSetter struct {
// SetValueCallback will be invoked each time a field is set
setValueCallback func(key, value, tag string, node *yaml.RNode)
}
// WithMutationTracker registers a callback which will be invoked each time a field is mutated
func (s *TrackableSetter) WithMutationTracker(callback func(key, value, tag string, node *yaml.RNode)) {
s.setValueCallback = callback
}
// SetScalar returns a SetFn to set a scalar value
// if a mutation tracker has been registered, the tracker will be invoked each
// time a scalar is set
func (s TrackableSetter) SetScalar(value string) SetFn {
origSetScalar := SetScalar(value)
return func(node *yaml.RNode) error {
if s.setValueCallback != nil {
s.setValueCallback("", value, "", node)
}
return origSetScalar(node)
}
}
// SetEntry returns a SetFn to set an entry in a map
// if a mutation tracker has been registered, the tracker will be invoked each
// time an entry is set
func (s TrackableSetter) SetEntry(key, value, tag string) SetFn {
origSetEntry := SetEntry(key, value, tag)
return func(node *yaml.RNode) error {
if s.setValueCallback != nil {
s.setValueCallback(key, value, tag, node)
}
return origSetEntry(node)
}
}

View File

@@ -0,0 +1,6 @@
// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// Package gkesagenerator contains a kio.Filter that that generates a
// iampolicy-related resources for a given cloud provider
package iampolicygenerator

View File

@@ -0,0 +1,46 @@
// Copyright 2021 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package iampolicygenerator
import (
"log"
"os"
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
func ExampleFilter() {
f := Filter{}
var err = yaml.Unmarshal([]byte(`
cloud: gke
kubernetesService:
namespace: k8s-namespace
name: k8s-sa-name
serviceAccount:
name: gsa-name
projectId: project-id
`), &f)
if err != nil {
log.Fatal(err)
}
err = kio.Pipeline{
Inputs: []kio.Reader{},
Filters: []kio.Filter{f},
Outputs: []kio.Writer{kio.ByteWriter{Writer: os.Stdout}},
}.Execute()
if err != nil {
log.Fatal(err)
}
// Output:
// apiVersion: v1
// kind: ServiceAccount
// metadata:
// annotations:
// iam.gke.io/gcp-service-account: gsa-name@project-id.iam.gserviceaccount.com
// name: k8s-sa-name
// namespace: k8s-namespace
}

View File

@@ -0,0 +1,55 @@
// Copyright 2021 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package iampolicygenerator
import (
"fmt"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
type Filter struct {
IAMPolicyGenerator types.IAMPolicyGeneratorArgs `json:",inline,omitempty" yaml:",inline,omitempty"`
}
// Filter adds a GKE service account object to nodes
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
switch f.IAMPolicyGenerator.Cloud {
case types.GKE:
IAMPolicyResources, err := f.generateGkeIAMPolicyResources()
if err != nil {
return nil, err
}
nodes = append(nodes, IAMPolicyResources...)
default:
return nil, fmt.Errorf("cloud provider %s not supported yet", f.IAMPolicyGenerator.Cloud)
}
return nodes, nil
}
func (f Filter) generateGkeIAMPolicyResources() ([]*yaml.RNode, error) {
var result []*yaml.RNode
input := fmt.Sprintf(`
apiVersion: v1
kind: ServiceAccount
metadata:
annotations:
iam.gke.io/gcp-service-account: %s@%s.iam.gserviceaccount.com
name: %s
`, f.IAMPolicyGenerator.ServiceAccount.Name,
f.IAMPolicyGenerator.ProjectId,
f.IAMPolicyGenerator.KubernetesService.Name)
if f.IAMPolicyGenerator.Namespace != "" {
input += fmt.Sprintf("\n namespace: %s", f.IAMPolicyGenerator.Namespace)
}
sa, err := yaml.Parse(input)
if err != nil {
return nil, err
}
return append(result, sa), nil
}

View File

@@ -0,0 +1,75 @@
// Copyright 2021 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package iampolicygenerator
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
filtertest "sigs.k8s.io/kustomize/api/testutils/filtertest"
"sigs.k8s.io/kustomize/api/types"
)
func TestFilter(t *testing.T) {
testCases := map[string]struct {
args types.IAMPolicyGeneratorArgs
expected string
}{
"with namespace": {
args: types.IAMPolicyGeneratorArgs{
Cloud: types.GKE,
KubernetesService: types.KubernetesService{
Namespace: "k8s-namespace",
Name: "k8s-sa-name",
},
ServiceAccount: types.ServiceAccount{
Name: "gsa-name",
ProjectId: "project-id",
},
},
expected: `
apiVersion: v1
kind: ServiceAccount
metadata:
annotations:
iam.gke.io/gcp-service-account: gsa-name@project-id.iam.gserviceaccount.com
name: k8s-sa-name
namespace: k8s-namespace
`,
},
"without namespace": {
args: types.IAMPolicyGeneratorArgs{
Cloud: types.GKE,
KubernetesService: types.KubernetesService{
Name: "k8s-sa-name",
},
ServiceAccount: types.ServiceAccount{
Name: "gsa-name",
ProjectId: "project-id",
},
},
expected: `
apiVersion: v1
kind: ServiceAccount
metadata:
annotations:
iam.gke.io/gcp-service-account: gsa-name@project-id.iam.gserviceaccount.com
name: k8s-sa-name
`,
},
}
for tn, tc := range testCases {
t.Run(tn, func(t *testing.T) {
f := Filter{
IAMPolicyGenerator: tc.args,
}
actual := filtertest.RunFilter(t, "", f)
if !assert.Equal(t, strings.TrimSpace(tc.expected), strings.TrimSpace(actual)) {
t.FailNow()
}
})
}
}

View File

@@ -23,9 +23,17 @@ type Filter struct {
// FsSlice contains the FieldSpecs to locate an image field,
// e.g. Path: "spec/myContainers[]/image"
FsSlice types.FsSlice `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
trackableSetter filtersutil.TrackableSetter
}
var _ kio.Filter = Filter{}
var _ kio.TrackableFilter = &Filter{}
// WithMutationTracker registers a callback which will be invoked each time a field is mutated
func (f *Filter) WithMutationTracker(callback func(key, value, tag string, node *yaml.RNode)) {
f.trackableSetter.WithMutationTracker(callback)
}
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
_, err := kio.FilterAll(yaml.FilterFunc(f.filter)).Filter(nodes)
@@ -40,8 +48,11 @@ func (f Filter) filter(node *yaml.RNode) (*yaml.RNode, error) {
return node, nil
}
if err := node.PipeE(fsslice.Filter{
FsSlice: f.FsSlice,
SetValue: updateImageTagFn(f.ImageTag),
FsSlice: f.FsSlice,
SetValue: imageTagUpdater{
ImageTag: f.ImageTag,
trackableSetter: f.trackableSetter,
}.SetImageValue,
}); err != nil {
return nil, err
}
@@ -59,11 +70,3 @@ func (f Filter) isOnDenyList(node *yaml.RNode) bool {
// https://github.com/kubernetes-sigs/kustomize/issues/890
return meta.Kind == `CustomResourceDefinition`
}
func updateImageTagFn(imageTag types.Image) filtersutil.SetFn {
return func(node *yaml.RNode) error {
return node.PipeE(imageTagUpdater{
ImageTag: imageTag,
})
}
}

View File

@@ -10,18 +10,22 @@ import (
"github.com/stretchr/testify/assert"
filtertest "sigs.k8s.io/kustomize/api/testutils/filtertest"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
func TestImageTagUpdater_Filter(t *testing.T) {
mutationTrackerStub := filtertest.MutationTrackerStub{}
testCases := map[string]struct {
input string
expectedOutput string
filter Filter
fsSlice types.FsSlice
input string
expectedOutput string
filter Filter
fsSlice types.FsSlice
setValueCallback func(key, value, tag string, node *yaml.RNode)
expectedSetValueArgs []filtertest.SetValueArg
}{
"ignore CustomResourceDefinition": {
input: `
apiVersion: apiextensions.k8s.io/v1beta1
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: whatever
@@ -30,7 +34,7 @@ spec:
- image: whatever
`,
expectedOutput: `
apiVersion: apiextensions.k8s.io/v1beta1
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: whatever
@@ -658,17 +662,237 @@ spec:
},
},
},
"mutation tracker": {
input: `
group: apps
apiVersion: v1
kind: Deployment
metadata:
name: deploy1
spec:
template:
spec:
containers:
- image: nginx:1.7.9
name: nginx-tagged
- image: nginx:latest
name: nginx-latest
- image: foobar:1
name: replaced-with-digest
- image: postgres:1.8.0
name: postgresdb
initContainers:
- image: nginx
name: nginx-notag
- image: nginx@sha256:111111111111111111
name: nginx-sha256
- image: alpine:1.8.0
name: init-alpine
`,
expectedOutput: `
group: apps
apiVersion: v1
kind: Deployment
metadata:
name: deploy1
spec:
template:
spec:
containers:
- image: busybox:v3
name: nginx-tagged
- image: busybox:v3
name: nginx-latest
- image: foobar:1
name: replaced-with-digest
- image: postgres:1.8.0
name: postgresdb
initContainers:
- image: busybox:v3
name: nginx-notag
- image: busybox:v3
name: nginx-sha256
- image: alpine:1.8.0
name: init-alpine
`,
filter: Filter{
ImageTag: types.Image{
Name: "nginx",
NewName: "busybox",
NewTag: "v3",
},
},
fsSlice: []types.FieldSpec{
{
Path: "spec/template/spec/containers[]/image",
},
{
Path: "spec/template/spec/initContainers[]/image",
},
},
setValueCallback: mutationTrackerStub.MutationTracker,
expectedSetValueArgs: []filtertest.SetValueArg{
{
Value: "busybox:v3",
NodePath: []string{"spec", "template", "spec", "containers", "image"},
},
{
Value: "busybox:v3",
NodePath: []string{"spec", "template", "spec", "containers", "image"},
},
{
Value: "busybox:v3",
NodePath: []string{"spec", "template", "spec", "initContainers", "image"},
},
{
Value: "busybox:v3",
NodePath: []string{"spec", "template", "spec", "initContainers", "image"},
},
},
},
"image with tag and digest new name": {
input: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
spec:
image: nginx:1.2.1@sha256:46d5b90a7f4e9996351ad893a26bcbd27216676ad4d5316088ce351fb2c2c3dd
`,
expectedOutput: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
spec:
image: apache:1.2.1@sha256:46d5b90a7f4e9996351ad893a26bcbd27216676ad4d5316088ce351fb2c2c3dd
`,
filter: Filter{
ImageTag: types.Image{
Name: "nginx",
NewName: "apache",
},
},
fsSlice: []types.FieldSpec{
{
Path: "spec/image",
},
},
},
"image with tag and digest new name new tag": {
input: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
spec:
image: nginx:1.2.1@sha256:46d5b90a7f4e9996351ad893a26bcbd27216676ad4d5316088ce351fb2c2c3dd
`,
expectedOutput: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
spec:
image: apache:1.3.0
`,
filter: Filter{
ImageTag: types.Image{
Name: "nginx",
NewName: "apache",
NewTag: "1.3.0",
},
},
fsSlice: []types.FieldSpec{
{
Path: "spec/image",
},
},
},
"image with tag and digest new name new tag and digest": {
input: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
spec:
image: nginx:1.2.1@sha256:46d5b90a7f4e9996351ad893a26bcbd27216676ad4d5316088ce351fb2c2c3dd
`,
expectedOutput: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
spec:
image: apache:1.3.0@sha256:xyz
`,
filter: Filter{
ImageTag: types.Image{
Name: "nginx",
NewName: "apache",
NewTag: "1.3.0",
Digest: "sha256:xyz",
},
},
fsSlice: []types.FieldSpec{
{
Path: "spec/image",
},
},
},
"updateimagesuffix": {
input: `
group: apps
apiVersion: v1
kind: Deployment
metadata:
name: deploysuffix
spec:
template:
spec:
containers:
- image: redis:6.2.6
name: redis
`,
expectedOutput: `
group: apps
apiVersion: v1
kind: Deployment
metadata:
name: deploysuffix
spec:
template:
spec:
containers:
- image: redis:6.2.6-alpine
name: redis
`,
filter: Filter{
ImageTag: types.Image{
Name: "redis",
TagSuffix: "-alpine",
},
},
fsSlice: []types.FieldSpec{
{
Path: "spec/template/spec/containers[]/image",
},
},
},
}
for tn, tc := range testCases {
mutationTrackerStub.Reset()
t.Run(tn, func(t *testing.T) {
filter := tc.filter
filter.WithMutationTracker(tc.setValueCallback)
filter.FsSlice = tc.fsSlice
if !assert.Equal(t,
strings.TrimSpace(tc.expectedOutput),
strings.TrimSpace(filtertest.RunFilter(t, tc.input, filter))) {
t.FailNow()
}
assert.Equal(t, tc.expectedSetValueArgs, mutationTrackerStub.SetValueArgs())
})
}
}

View File

@@ -4,7 +4,9 @@
package imagetag
import (
"sigs.k8s.io/kustomize/api/internal/utils"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/errors"
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
@@ -74,28 +76,17 @@ func (f findFieldsFilter) walk(node *yaml.RNode) error {
return err
}
key := n.Key.YNode().Value
if contains(f.fields, key) {
if utils.StringSliceContains(f.fields, key) {
return f.fieldCallback(n.Value)
}
return nil
})
case yaml.SequenceNode:
return node.VisitElements(func(n *yaml.RNode) error {
return f.walk(n)
})
return errors.Wrap(node.VisitElements(f.walk))
}
return nil
}
func contains(slice []string, str string) bool {
for _, s := range slice {
if s == str {
return true
}
}
return false
}
func checkImageTagsFn(imageTag types.Image) fieldCallback {
return func(node *yaml.RNode) error {
if node.YNode().Kind != yaml.SequenceNode {

View File

@@ -4,6 +4,8 @@
package imagetag
import (
"sigs.k8s.io/kustomize/api/filters/filtersutil"
"sigs.k8s.io/kustomize/api/image"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/yaml"
@@ -13,31 +15,57 @@ import (
// that will update the value of the yaml node based on the provided
// ImageTag if the current value matches the format of an image reference.
type imageTagUpdater struct {
Kind string `yaml:"kind,omitempty"`
ImageTag types.Image `yaml:"imageTag,omitempty"`
Kind string `yaml:"kind,omitempty"`
ImageTag types.Image `yaml:"imageTag,omitempty"`
trackableSetter filtersutil.TrackableSetter
}
func (u imageTagUpdater) Filter(rn *yaml.RNode) (*yaml.RNode, error) {
func (u imageTagUpdater) SetImageValue(rn *yaml.RNode) error {
if err := yaml.ErrorIfInvalid(rn, yaml.ScalarNode); err != nil {
return nil, err
return err
}
value := rn.YNode().Value
if !image.IsImageMatched(value, u.ImageTag.Name) {
return rn, nil
return nil
}
name, tag := image.Split(value)
name, tag, digest := image.Split(value)
if u.ImageTag.NewName != "" {
name = u.ImageTag.NewName
}
if u.ImageTag.NewTag != "" {
tag = ":" + u.ImageTag.NewTag
}
if u.ImageTag.Digest != "" {
tag = "@" + u.ImageTag.Digest
// overriding tag or digest will replace both original tag and digest values
switch {
case u.ImageTag.NewTag != "" && u.ImageTag.Digest != "":
tag = u.ImageTag.NewTag
digest = u.ImageTag.Digest
case u.ImageTag.NewTag != "":
tag = u.ImageTag.NewTag
digest = ""
case u.ImageTag.Digest != "":
tag = ""
digest = u.ImageTag.Digest
case u.ImageTag.TagSuffix != "":
tag += u.ImageTag.TagSuffix
digest = ""
}
return rn.Pipe(yaml.FieldSetter{StringValue: name + tag})
// build final image name
if tag != "" {
name += ":" + tag
}
if digest != "" {
name += "@" + digest
}
return u.trackableSetter.SetScalar(name)(rn)
}
func (u imageTagUpdater) Filter(rn *yaml.RNode) (*yaml.RNode, error) {
if err := u.SetImageValue(rn); err != nil {
return nil, err
}
return rn, nil
}

View File

@@ -20,18 +20,26 @@ type Filter struct {
// FsSlice identifies the label fields.
FsSlice types.FsSlice
trackableSetter filtersutil.TrackableSetter
}
var _ kio.Filter = Filter{}
var _ kio.TrackableFilter = &Filter{}
// WithMutationTracker registers a callback which will be invoked each time a field is mutated
func (f *Filter) WithMutationTracker(callback func(key, value, tag string, node *yaml.RNode)) {
f.trackableSetter.WithMutationTracker(callback)
}
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
keys := filtersutil.SortedMapKeys(f.Labels)
keys := yaml.SortedMapKeys(f.Labels)
_, err := kio.FilterAll(yaml.FilterFunc(
func(node *yaml.RNode) (*yaml.RNode, error) {
for _, k := range keys {
if err := node.PipeE(fsslice.Filter{
FsSlice: f.FsSlice,
SetValue: filtersutil.SetEntry(
SetValue: f.trackableSetter.SetEntry(
k, f.Labels[k], yaml.NodeTagString),
CreateKind: yaml.MappingNode, // Labels are MappingNodes.
CreateTag: yaml.NodeTagMap,

View File

@@ -8,16 +8,20 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"sigs.k8s.io/kustomize/api/resid"
filtertest_test "sigs.k8s.io/kustomize/api/testutils/filtertest"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/resid"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
func TestLabels_Filter(t *testing.T) {
mutationTrackerStub := filtertest_test.MutationTrackerStub{}
testCases := map[string]struct {
input string
expectedOutput string
filter Filter
input string
expectedOutput string
filter Filter
setEntryCallback func(key, value, tag string, node *yaml.RNode)
expectedSetEntryArgs []filtertest_test.SetValueArg
}{
"add": {
input: `
@@ -399,15 +403,74 @@ metadata:
},
},
},
// test usage of SetEntryCallback
"set_entry_callback": {
input: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
labels:
witcher: geralt
`,
expectedOutput: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
labels:
witcher: geralt
mage: yennefer
a:
b:
mage: yennefer
`,
filter: Filter{
Labels: labelMap{
"mage": "yennefer",
},
FsSlice: []types.FieldSpec{
{
Path: "metadata/labels",
CreateIfNotPresent: true,
},
{
Path: "a/b",
CreateIfNotPresent: true,
},
},
},
setEntryCallback: mutationTrackerStub.MutationTracker,
expectedSetEntryArgs: []filtertest_test.SetValueArg{
{
Key: "mage",
Value: "yennefer",
Tag: "!!str",
NodePath: []string{"metadata", "labels"},
},
{
Key: "mage",
Value: "yennefer",
Tag: "!!str",
NodePath: []string{"a", "b"},
},
},
},
}
for tn, tc := range testCases {
mutationTrackerStub.Reset()
t.Run(tn, func(t *testing.T) {
tc.filter.WithMutationTracker(tc.setEntryCallback)
if !assert.Equal(t,
strings.TrimSpace(tc.expectedOutput),
strings.TrimSpace(filtertest_test.RunFilter(t, tc.input, tc.filter))) {
t.FailNow()
}
if !assert.Equal(t, tc.expectedSetEntryArgs, mutationTrackerStub.SetValueArgs()) {
t.FailNow()
}
})
}
}

View File

@@ -1,3 +1,6 @@
// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// Package nameref contains a kio.Filter implementation of the kustomize
// name reference transformer.
package nameref

View File

@@ -1,107 +1,194 @@
// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package nameref
import (
"encoding/json"
"fmt"
"strings"
"github.com/pkg/errors"
"sigs.k8s.io/kustomize/api/filters/fieldspec"
"sigs.k8s.io/kustomize/api/filters/filtersutil"
"sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/api/types"
kyaml_filtersutil "sigs.k8s.io/kustomize/kyaml/filtersutil"
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/resid"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
// Filter will update the name reference
// Filter updates a name references.
type Filter struct {
FieldSpec types.FieldSpec `json:"fieldSpec,omitempty" yaml:"fieldSpec,omitempty"`
Referrer *resource.Resource
Target resid.Gvk
// Referrer refers to another resource X by X's name.
// E.g. A Deployment can refer to a ConfigMap.
// The Deployment is the Referrer,
// the ConfigMap is the ReferralTarget.
// This filter seeks to repair the reference in Deployment, given
// that the ConfigMap's name may have changed.
Referrer *resource.Resource
// NameFieldToUpdate is the field in the Referrer
// that holds the name requiring an update.
// This is the field to write.
NameFieldToUpdate types.FieldSpec
// ReferralTarget is the source of the new value for
// the name, always in the 'metadata/name' field.
// This is the field to read.
ReferralTarget resid.Gvk
// Set of resources to scan to find the ReferralTarget.
ReferralCandidates resmap.ResMap
isRoleRef bool
}
// At time of writing, in practice this is called with a slice with only
// one entry, the node also referred to be the resource in the Referrer field.
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
return kio.FilterAll(yaml.FilterFunc(f.run)).Filter(nodes)
}
// The node passed in here is the same node as held in Referrer;
// that's how the referrer's name field is updated.
// Currently, however, this filter still needs the extra methods on Referrer
// to consult things like the resource Id, its namespace, etc.
// TODO(3455): No filter should use the Resource api; all information
// about names should come from annotations, with helper methods
// on the RNode object. Resource should get stupider, RNode smarter.
func (f Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
err := node.PipeE(fieldspec.Filter{
FieldSpec: f.FieldSpec,
if err := f.confirmNodeMatchesReferrer(node); err != nil {
// sanity check.
return nil, err
}
f.NameFieldToUpdate.Gvk = f.Referrer.GetGvk()
if err := node.PipeE(fieldspec.Filter{
FieldSpec: f.NameFieldToUpdate,
SetValue: f.set,
})
return node, err
}); err != nil {
return nil, errors.Wrapf(
err, "updating name reference in '%s' field of '%s'",
f.NameFieldToUpdate.Path, f.Referrer.CurId().String())
}
return node, nil
}
// This function is called on the node found at FieldSpec.Path.
// It's some node in the Referrer.
func (f Filter) set(node *yaml.RNode) error {
if yaml.IsMissingOrNull(node) {
return nil
}
if strings.HasSuffix(f.FieldSpec.Path, "roleRef/name") {
f.isRoleRef = true
}
switch node.YNode().Kind {
case yaml.ScalarNode:
return f.setScalar(node)
case yaml.MappingNode:
// Kind: ValidatingWebhookConfiguration
// FieldSpec is webhooks/clientConfig/service
return f.setMapping(node)
case yaml.SequenceNode:
return f.setSequence(node)
return applyFilterToSeq(seqFilter{
setScalarFn: f.setScalar,
setMappingFn: f.setMapping,
}, node)
default:
return fmt.Errorf(
"node is expected to be either a string or a slice of string or a map of string")
return fmt.Errorf("node must be a scalar, sequence or map")
}
}
func (f Filter) setSequence(node *yaml.RNode) error {
return applyFilterToSeq(seqFilter{
setScalarFn: f.setScalar,
setMappingFn: f.setMapping,
}, node)
// This method used when NameFieldToUpdate doesn't lead to
// one scalar field (typically called 'name'), but rather
// leads to a map field (called anything). In this case we
// must complete the field path, looking for both a 'name'
// and a 'namespace' field to help select the proper
// ReferralTarget to read the name and namespace from.
func (f Filter) setMapping(node *yaml.RNode) error {
if node.YNode().Kind != yaml.MappingNode {
return fmt.Errorf("expect a mapping node")
}
nameNode, err := node.Pipe(yaml.FieldMatcher{Name: "name"})
if err != nil {
return errors.Wrap(err, "trying to match 'name' field")
}
if nameNode == nil {
// This is a _configuration_ error; the field path
// specified in NameFieldToUpdate.Path doesn't resolve
// to a map with a 'name' field, so we have no idea what
// field to update with a new name.
return fmt.Errorf("path config error; no 'name' field in node")
}
candidates, err := f.filterMapCandidatesByNamespace(node)
if err != nil {
return err
}
oldName := nameNode.YNode().Value
referral, err := f.selectReferral(oldName, candidates)
if err != nil || referral == nil {
// Nil referral means nothing to do.
return err
}
f.recordTheReferral(referral)
if referral.GetName() == oldName && referral.GetNamespace() == "" {
// The name has not changed, nothing to do.
return nil
}
if err = node.PipeE(yaml.FieldSetter{
Name: "name",
StringValue: referral.GetName(),
}); err != nil {
return err
}
if referral.GetNamespace() == "" {
// Don't write an empty string into the namespace field, as
// it should not replace the value "default". The empty
// string is handled as a wild card here, not as an implicit
// specification of the "default" k8s namespace.
return nil
}
return node.PipeE(yaml.FieldSetter{
Name: "namespace",
StringValue: referral.GetNamespace(),
})
}
func (f Filter) setMapping(node *yaml.RNode) error {
return setNameAndNs(
node,
f.Referrer,
f.Target,
f.ReferralCandidates,
f.isRoleRef,
)
func (f Filter) filterMapCandidatesByNamespace(
node *yaml.RNode) ([]*resource.Resource, error) {
namespaceNode, err := node.Pipe(yaml.FieldMatcher{Name: "namespace"})
if err != nil {
return nil, errors.Wrap(err, "trying to match 'namespace' field")
}
if namespaceNode == nil {
return f.ReferralCandidates.Resources(), nil
}
namespace := namespaceNode.YNode().Value
nsMap := f.ReferralCandidates.GroupedByOriginalNamespace()
if candidates, ok := nsMap[namespace]; ok {
return candidates, nil
}
nsMap = f.ReferralCandidates.GroupedByCurrentNamespace()
// This could be nil, or an empty list.
return nsMap[namespace], nil
}
func (f Filter) setScalar(node *yaml.RNode) error {
newValue, err := getSimpleNameField(
node.YNode().Value,
f.Referrer,
f.Target,
f.ReferralCandidates,
f.ReferralCandidates.Resources(),
f.isRoleRef,
)
if err != nil {
referral, err := f.selectReferral(
node.YNode().Value, f.ReferralCandidates.Resources())
if err != nil || referral == nil {
// Nil referral means nothing to do.
return err
}
err = filtersutil.SetScalar(newValue)(node)
if err != nil {
return err
f.recordTheReferral(referral)
if referral.GetName() == node.YNode().Value {
// The name has not changed, nothing to do.
return nil
}
return nil
return node.PipeE(yaml.FieldSetter{StringValue: referral.GetName()})
}
// In the resource, make a note that it is referred to by the Referrer.
func (f Filter) recordTheReferral(referral *resource.Resource) {
referral.AppendRefBy(f.Referrer.CurId())
}
// getRoleRefGvk returns a Gvk in the roleRef field. Return error
// if the roleRef, roleRef/apiGroup or roleRef/kind is missing.
func getRoleRefGvk(res json.Marshaler) (*resid.Gvk, error) {
n, err := kyaml_filtersutil.GetRNode(res)
if err != nil {
return nil, err
}
func getRoleRefGvk(n *resource.Resource) (*resid.Gvk, error) {
roleRef, err := n.Pipe(yaml.Lookup("roleRef"))
if err != nil {
return nil, err
@@ -114,14 +201,16 @@ func getRoleRefGvk(res json.Marshaler) (*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,
@@ -129,169 +218,182 @@ func getRoleRefGvk(res json.Marshaler) (*resid.Gvk, error) {
}, nil
}
func filterReferralCandidates(
referrer *resource.Resource,
matches []*resource.Resource,
target resid.Gvk,
) []*resource.Resource {
var ret []*resource.Resource
for _, m := range matches {
// If target kind is not ServiceAccount, we shouldn't consider condidates which
// doesn't have same namespace.
if target.Kind != "ServiceAccount" && m.GetNamespace() != referrer.GetNamespace() {
continue
// sieveFunc returns true if the resource argument satisfies some criteria.
type sieveFunc func(*resource.Resource) bool
// doSieve uses a function to accept or ignore resources from a list.
// If list is nil, returns immediately.
// It's a filter obviously, but that term is overloaded here.
func doSieve(list []*resource.Resource, fn sieveFunc) (s []*resource.Resource) {
for _, r := range list {
if fn(r) {
s = append(s, r)
}
if !referrer.PrefixesSuffixesEquals(m) {
continue
}
ret = append(ret, m)
}
return ret
return
}
// selectReferral picks the referral among a subset of candidates.
// It returns the current name and namespace of the selected candidate.
// Note that the content of the referricalCandidateSubset slice is most of the time
// identical to the referralCandidates resmap. Still in some cases, such
// as ClusterRoleBinding, the subset only contains the resources of a specific
// namespace.
func selectReferral(
oldName string,
referrer *resource.Resource,
target resid.Gvk,
referralCandidates resmap.ResMap,
referralCandidateSubset []*resource.Resource,
isRoleRef bool) (string, string, error) {
var roleRefGvk *resid.Gvk
if isRoleRef {
var err error
roleRefGvk, err = getRoleRefGvk(referrer)
if err != nil {
return "", "", err
}
}
for _, res := range referralCandidateSubset {
id := res.OrgId()
// If the we are processing a roleRef, the apiGroup and Kind in the
// roleRef are needed to be considered.
if (!isRoleRef || id.IsSelected(roleRefGvk)) &&
id.IsSelected(&target) && res.GetOriginalName() == oldName {
matches := referralCandidates.GetMatchingResourcesByOriginalId(id.Equals)
// If there's more than one match,
// filter the matches by prefix and suffix
if len(matches) > 1 {
filteredMatches := filterReferralCandidates(referrer, matches, target)
if len(filteredMatches) > 1 {
return "", "", fmt.Errorf(
"multiple matches for %s:\n %v",
id, getIds(filteredMatches))
}
// Check is the match the resource we are working on
if len(filteredMatches) == 0 || res != filteredMatches[0] {
continue
}
func acceptAll(r *resource.Resource) bool {
return true
}
func previousNameMatches(name string) sieveFunc {
return func(r *resource.Resource) bool {
for _, id := range r.PrevIds() {
if id.Name == name {
return true
}
// In the resource, note that it is referenced
// by the referrer.
res.AppendRefBy(referrer.CurId())
// Return transformed name of the object,
// complete with prefixes, hashes, etc.
return res.GetName(), res.GetNamespace(), nil
}
return false
}
}
func previousIdSelectedByGvk(gvk *resid.Gvk) sieveFunc {
return func(r *resource.Resource) bool {
for _, id := range r.PrevIds() {
if id.IsSelected(gvk) {
return true
}
}
return false
}
}
// If the we are updating a 'roleRef/name' field, the 'apiGroup' and 'kind'
// fields in the same 'roleRef' map must be considered.
// If either object is cluster-scoped, there can be a referral.
// E.g. a RoleBinding (which exists in a namespace) can refer
// to a ClusterRole (cluster-scoped) object.
// https://kubernetes.io/docs/reference/access-authn-authz/rbac/#role-and-clusterrole
// Likewise, a ClusterRole can refer to a Secret (in a namespace).
// Objects in different namespaces generally cannot refer to other
// with some exceptions (e.g. RoleBinding and ServiceAccount are both
// namespaceable, but the former can refer to accounts in other namespaces).
func (f Filter) roleRefFilter() sieveFunc {
if !strings.HasSuffix(f.NameFieldToUpdate.Path, "roleRef/name") {
return acceptAll
}
roleRefGvk, err := getRoleRefGvk(f.Referrer)
if err != nil {
return acceptAll
}
return previousIdSelectedByGvk(roleRefGvk)
}
func prefixSuffixEquals(other resource.ResCtx) sieveFunc {
return func(r *resource.Resource) bool {
return r.PrefixesSuffixesEquals(other)
}
}
func (f Filter) sameCurrentNamespaceAsReferrer() sieveFunc {
referrerCurId := f.Referrer.CurId()
if referrerCurId.IsClusterScoped() {
// If the referrer is cluster-scoped, let anything through.
return acceptAll
}
return func(r *resource.Resource) bool {
if r.CurId().IsClusterScoped() {
// Allow cluster-scoped through.
return true
}
if r.GetKind() == "ServiceAccount" {
// Allow service accounts through, even though they
// are in a namespace. A RoleBinding in another namespace
// can reference them.
return true
}
return referrerCurId.IsNsEquals(r.CurId())
}
}
// selectReferral picks the best referral from a list of candidates.
func (f Filter) selectReferral(
// The name referral that may need to be updated.
oldName string,
candidates []*resource.Resource) (*resource.Resource, error) {
candidates = doSieve(candidates, previousNameMatches(oldName))
candidates = doSieve(candidates, previousIdSelectedByGvk(&f.ReferralTarget))
candidates = doSieve(candidates, f.roleRefFilter())
candidates = doSieve(candidates, f.sameCurrentNamespaceAsReferrer())
if len(candidates) == 1 {
return candidates[0], nil
}
candidates = doSieve(candidates, prefixSuffixEquals(f.Referrer))
if len(candidates) == 1 {
return candidates[0], nil
}
if len(candidates) == 0 {
return nil, nil
}
if allNamesAreTheSame(candidates) {
// Just take the first one.
return candidates[0], nil
}
ids := getIds(candidates)
f.failureDetails(candidates)
return nil, fmt.Errorf(" found multiple possible referrals: %s", ids)
}
func (f Filter) failureDetails(resources []*resource.Resource) {
fmt.Printf(
"\n**** Too many possible referral targets to referrer:\n%s\n",
f.Referrer.MustYaml())
for i, r := range resources {
fmt.Printf(
"--- possible referral %d:\n%s", i, r.MustYaml())
fmt.Println("------")
}
}
func allNamesAreTheSame(resources []*resource.Resource) bool {
name := resources[0].GetName()
for i := 1; i < len(resources); i++ {
if name != resources[i].GetName() {
return false
}
}
return oldName, "", nil
return true
}
// utility function to replace a simple string by the new name
func getSimpleNameField(
oldName string,
referrer *resource.Resource,
target resid.Gvk,
referralCandidates resmap.ResMap,
referralCandidateSubset []*resource.Resource,
isRoleRef bool) (string, error) {
newName, _, err := selectReferral(oldName, referrer, target,
referralCandidates, referralCandidateSubset, isRoleRef)
return newName, err
}
func getIds(rs []*resource.Resource) []string {
func getIds(rs []*resource.Resource) string {
var result []string
for _, r := range rs {
result = append(result, r.CurId().String()+"\n")
result = append(result, r.CurId().String())
}
return result
return strings.Join(result, ", ")
}
// utility function to replace name field within a map RNode
// and leverage the namespace field.
func setNameAndNs(
in *yaml.RNode,
referrer *resource.Resource,
target resid.Gvk,
referralCandidates resmap.ResMap,
isRoleRef bool) error {
if in.YNode().Kind != yaml.MappingNode {
return fmt.Errorf("expect a mapping node")
}
// Get name field
nameNode, err := in.Pipe(yaml.FieldMatcher{
Name: "name",
})
if err != nil || nameNode == nil {
return fmt.Errorf("cannot find field 'name' in node")
}
// Get namespace field
namespaceNode, err := in.Pipe(yaml.FieldMatcher{
Name: "namespace",
})
if err != nil {
return fmt.Errorf("error when find field 'namespace'")
}
// check is namespace matched
// name will bot be updated if the namespace doesn't match
subset := referralCandidates.Resources()
if namespaceNode != nil {
namespace := namespaceNode.YNode().Value
bynamespace := referralCandidates.GroupedByOriginalNamespace()
if _, ok := bynamespace[namespace]; !ok {
return nil
}
subset = bynamespace[namespace]
}
oldName := nameNode.YNode().Value
newname, newnamespace, err := selectReferral(oldName, referrer, target,
referralCandidates, subset, isRoleRef)
if err != nil {
return err
}
if (newname == oldName) && (newnamespace == "") {
// no candidate found.
return nil
}
// set name
in.Pipe(yaml.FieldSetter{
Name: "name",
StringValue: newname,
})
if newnamespace != "" {
// We don't want value "" to replace value "default" since
// the empty string is handled as a wild card here not default namespace
// by kubernetes.
in.Pipe(yaml.FieldSetter{
Name: "namespace",
StringValue: newnamespace,
})
func checkEqual(k, a, b string) error {
if a != b {
return fmt.Errorf(
"node-referrerOriginal '%s' mismatch '%s' != '%s'",
k, a, b)
}
return nil
}
func (f Filter) confirmNodeMatchesReferrer(node *yaml.RNode) error {
meta, err := node.GetMeta()
if err != nil {
return err
}
gvk := f.Referrer.GetGvk()
if err = checkEqual(
"APIVersion", meta.APIVersion, gvk.ApiVersion()); err != nil {
return err
}
if err = checkEqual(
"Kind", meta.Kind, gvk.Kind); err != nil {
return err
}
if err = checkEqual(
"Name", meta.Name, f.Referrer.GetName()); err != nil {
return err
}
if err = checkEqual(
"Namespace", meta.Namespace, f.Referrer.GetNamespace()); err != nil {
return err
}
return nil
}

View File

@@ -1,3 +1,6 @@
// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package nameref
import (
@@ -5,24 +8,23 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"sigs.k8s.io/kustomize/api/k8sdeps/kunstruct"
"sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/api/provider"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/resource"
filtertest_test "sigs.k8s.io/kustomize/api/testutils/filtertest"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/resid"
)
func TestNamerefFilter(t *testing.T) {
testCases := map[string]struct {
input string
candidates string
expected string
filter Filter
originalNames []string
referrerOriginal string
candidates string
referrerFinal string
filter Filter
originalNames []string
}{
"simple scalar": {
input: `
referrerOriginal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -41,8 +43,8 @@ kind: NotSecret
metadata:
name: newName2
`,
originalNames: []string{"oldName", ""},
expected: `
originalNames: []string{"oldName", "newName2"},
referrerFinal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -51,8 +53,8 @@ ref:
name: newName
`,
filter: Filter{
FieldSpec: types.FieldSpec{Path: "ref/name"},
Target: resid.Gvk{
NameFieldToUpdate: types.FieldSpec{Path: "ref/name"},
ReferralTarget: resid.Gvk{
Group: "apps",
Version: "v1",
Kind: "Secret",
@@ -60,7 +62,7 @@ ref:
},
},
"sequence": {
input: `
referrerOriginal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -80,8 +82,8 @@ kind: NotSecret
metadata:
name: newName2
`,
originalNames: []string{"oldName1", ""},
expected: `
originalNames: []string{"oldName1", "newName2"},
referrerFinal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -91,8 +93,8 @@ seq:
- oldName2
`,
filter: Filter{
FieldSpec: types.FieldSpec{Path: "seq"},
Target: resid.Gvk{
NameFieldToUpdate: types.FieldSpec{Path: "seq"},
ReferralTarget: resid.Gvk{
Group: "apps",
Version: "v1",
Kind: "Secret",
@@ -100,7 +102,7 @@ seq:
},
},
"mapping": {
input: `
referrerOriginal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -119,8 +121,8 @@ kind: NotSecret
metadata:
name: newName2
`,
originalNames: []string{"oldName", ""},
expected: `
originalNames: []string{"oldName", "newName2"},
referrerFinal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -129,8 +131,8 @@ map:
name: newName
`,
filter: Filter{
FieldSpec: types.FieldSpec{Path: "map"},
Target: resid.Gvk{
NameFieldToUpdate: types.FieldSpec{Path: "map"},
ReferralTarget: resid.Gvk{
Group: "apps",
Version: "v1",
Kind: "Secret",
@@ -138,40 +140,47 @@ map:
},
},
"mapping with namespace": {
input: `
referrerOriginal: `
apiVersion: apps/v1
kind: Deployment
metadata:
name: dep
namespace: someNs
map:
name: oldName
namespace: oldNs
namespace: someNs
`,
candidates: `
apiVersion: apps/v1
kind: Secret
metadata:
name: newName
namespace: oldNs
namespace: someNs
---
apiVersion: apps/v1
kind: NotSecret
metadata:
name: newName2
---
apiVersion: apps/v1
kind: Secret
metadata:
name: thirdName
`,
originalNames: []string{"oldName", ""},
expected: `
originalNames: []string{"oldName", "oldName", "oldName"},
referrerFinal: `
apiVersion: apps/v1
kind: Deployment
metadata:
name: dep
namespace: someNs
map:
name: newName
namespace: oldNs
namespace: someNs
`,
filter: Filter{
FieldSpec: types.FieldSpec{Path: "map"},
Target: resid.Gvk{
NameFieldToUpdate: types.FieldSpec{Path: "map"},
ReferralTarget: resid.Gvk{
Group: "apps",
Version: "v1",
Kind: "Secret",
@@ -179,7 +188,7 @@ map:
},
},
"null value": {
input: `
referrerOriginal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -198,8 +207,8 @@ kind: NotSecret
metadata:
name: newName2
`,
originalNames: []string{"oldName", ""},
expected: `
originalNames: []string{"oldName", "newName2"},
referrerFinal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -208,8 +217,8 @@ map:
name: null
`,
filter: Filter{
FieldSpec: types.FieldSpec{Path: "map"},
Target: resid.Gvk{
NameFieldToUpdate: types.FieldSpec{Path: "map"},
ReferralTarget: resid.Gvk{
Group: "apps",
Version: "v1",
Kind: "Secret",
@@ -220,14 +229,14 @@ map:
for tn, tc := range testCases {
t.Run(tn, func(t *testing.T) {
factory := resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())
referrer, err := factory.FromBytes([]byte(tc.input))
factory := provider.NewDefaultDepProvider().GetResourceFactory()
referrer, err := factory.FromBytes([]byte(tc.referrerOriginal))
if err != nil {
t.Fatal(err)
}
tc.filter.Referrer = referrer
resMapFactory := resmap.NewFactory(factory, nil)
resMapFactory := resmap.NewFactory(factory)
candidatesRes, err := factory.SliceFromBytesWithNames(
tc.originalNames, []byte(tc.candidates))
if err != nil {
@@ -237,10 +246,10 @@ map:
candidates := resMapFactory.FromResourceSlice(candidatesRes)
tc.filter.ReferralCandidates = candidates
result := filtertest_test.RunFilter(t, tc.referrerOriginal, tc.filter)
if !assert.Equal(t,
strings.TrimSpace(tc.expected),
strings.TrimSpace(
filtertest_test.RunFilter(t, tc.input, tc.filter))) {
strings.TrimSpace(tc.referrerFinal),
strings.TrimSpace(result)) {
t.FailNow()
}
})
@@ -249,14 +258,14 @@ map:
func TestNamerefFilterUnhappy(t *testing.T) {
testCases := map[string]struct {
input string
candidates string
expected string
filter Filter
originalNames []string
referrerOriginal string
candidates string
referrerFinal string
filter Filter
originalNames []string
}{
"multiple match": {
input: `
referrerOriginal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -276,10 +285,10 @@ metadata:
name: newName2
`,
originalNames: []string{"oldName", "oldName"},
expected: "",
referrerFinal: "",
filter: Filter{
FieldSpec: types.FieldSpec{Path: "ref/name"},
Target: resid.Gvk{
NameFieldToUpdate: types.FieldSpec{Path: "ref/name"},
ReferralTarget: resid.Gvk{
Group: "apps",
Version: "v1",
Kind: "Secret",
@@ -287,7 +296,7 @@ metadata:
},
},
"no name": {
input: `
referrerOriginal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -307,10 +316,10 @@ metadata:
name: newName2
`,
originalNames: []string{"oldName", "oldName"},
expected: "",
referrerFinal: "",
filter: Filter{
FieldSpec: types.FieldSpec{Path: "ref"},
Target: resid.Gvk{
NameFieldToUpdate: types.FieldSpec{Path: "ref"},
ReferralTarget: resid.Gvk{
Group: "apps",
Version: "v1",
Kind: "Secret",
@@ -321,14 +330,14 @@ metadata:
for tn, tc := range testCases {
t.Run(tn, func(t *testing.T) {
factory := resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())
referrer, err := factory.FromBytes([]byte(tc.input))
factory := provider.NewDefaultDepProvider().GetResourceFactory()
referrer, err := factory.FromBytes([]byte(tc.referrerOriginal))
if err != nil {
t.Fatal(err)
}
tc.filter.Referrer = referrer
resMapFactory := resmap.NewFactory(factory, nil)
resMapFactory := resmap.NewFactory(factory)
candidatesRes, err := factory.SliceFromBytesWithNames(
tc.originalNames, []byte(tc.candidates))
if err != nil {
@@ -338,11 +347,11 @@ metadata:
candidates := resMapFactory.FromResourceSlice(candidatesRes)
tc.filter.ReferralCandidates = candidates
_, err = filtertest_test.RunFilterE(t, tc.input, tc.filter)
_, err = filtertest_test.RunFilterE(t, tc.referrerOriginal, tc.filter)
if err == nil {
t.Fatalf("expect an error")
}
if tc.expected != "" && !assert.EqualError(t, err, tc.expected) {
if tc.referrerFinal != "" && !assert.EqualError(t, err, tc.referrerFinal) {
t.FailNow()
}
})
@@ -351,19 +360,19 @@ metadata:
func TestCandidatesWithDifferentPrefixSuffix(t *testing.T) {
testCases := map[string]struct {
input string
candidates string
expected string
filter Filter
originalNames []string
prefix []string
suffix []string
inputPrefix string
inputSuffix string
err bool
referrerOriginal string
candidates string
referrerFinal string
filter Filter
originalNames []string
prefix []string
suffix []string
inputPrefix string
inputSuffix string
err bool
}{
"prefix match": {
input: `
referrerOriginal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -387,7 +396,7 @@ metadata:
suffix: []string{"", "suffix2"},
inputPrefix: "prefix1",
inputSuffix: "",
expected: `
referrerFinal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -396,8 +405,8 @@ ref:
name: newName
`,
filter: Filter{
FieldSpec: types.FieldSpec{Path: "ref/name"},
Target: resid.Gvk{
NameFieldToUpdate: types.FieldSpec{Path: "ref/name"},
ReferralTarget: resid.Gvk{
Group: "apps",
Version: "v1",
Kind: "Secret",
@@ -406,7 +415,7 @@ ref:
err: false,
},
"suffix match": {
input: `
referrerOriginal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -430,7 +439,7 @@ metadata:
suffix: []string{"suffix1", "suffix2"},
inputPrefix: "",
inputSuffix: "suffix1",
expected: `
referrerFinal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -439,8 +448,8 @@ ref:
name: newName
`,
filter: Filter{
FieldSpec: types.FieldSpec{Path: "ref/name"},
Target: resid.Gvk{
NameFieldToUpdate: types.FieldSpec{Path: "ref/name"},
ReferralTarget: resid.Gvk{
Group: "apps",
Version: "v1",
Kind: "Secret",
@@ -449,7 +458,7 @@ ref:
err: false,
},
"prefix suffix both match": {
input: `
referrerOriginal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -473,7 +482,7 @@ metadata:
suffix: []string{"suffix1", "suffix2"},
inputPrefix: "prefix1",
inputSuffix: "suffix1",
expected: `
referrerFinal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -482,8 +491,8 @@ ref:
name: newName
`,
filter: Filter{
FieldSpec: types.FieldSpec{Path: "ref/name"},
Target: resid.Gvk{
NameFieldToUpdate: types.FieldSpec{Path: "ref/name"},
ReferralTarget: resid.Gvk{
Group: "apps",
Version: "v1",
Kind: "Secret",
@@ -492,7 +501,7 @@ ref:
err: false,
},
"multiple match: both": {
input: `
referrerOriginal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -516,10 +525,10 @@ metadata:
suffix: []string{"suffix", "suffix"},
inputPrefix: "prefix",
inputSuffix: "suffix",
expected: "",
referrerFinal: "",
filter: Filter{
FieldSpec: types.FieldSpec{Path: "ref/name"},
Target: resid.Gvk{
NameFieldToUpdate: types.FieldSpec{Path: "ref/name"},
ReferralTarget: resid.Gvk{
Group: "apps",
Version: "v1",
Kind: "Secret",
@@ -528,7 +537,7 @@ metadata:
err: true,
},
"multiple match: only prefix": {
input: `
referrerOriginal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -552,10 +561,10 @@ metadata:
suffix: []string{"", ""},
inputPrefix: "prefix",
inputSuffix: "",
expected: "",
referrerFinal: "",
filter: Filter{
FieldSpec: types.FieldSpec{Path: "ref/name"},
Target: resid.Gvk{
NameFieldToUpdate: types.FieldSpec{Path: "ref/name"},
ReferralTarget: resid.Gvk{
Group: "apps",
Version: "v1",
Kind: "Secret",
@@ -564,7 +573,7 @@ metadata:
err: true,
},
"multiple match: only suffix": {
input: `
referrerOriginal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -588,10 +597,10 @@ metadata:
suffix: []string{"suffix", "suffix"},
inputPrefix: "",
inputSuffix: "suffix",
expected: "",
referrerFinal: "",
filter: Filter{
FieldSpec: types.FieldSpec{Path: "ref/name"},
Target: resid.Gvk{
NameFieldToUpdate: types.FieldSpec{Path: "ref/name"},
ReferralTarget: resid.Gvk{
Group: "apps",
Version: "v1",
Kind: "Secret",
@@ -600,7 +609,7 @@ metadata:
err: true,
},
"no match: neither match": {
input: `
referrerOriginal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -624,7 +633,7 @@ metadata:
suffix: []string{"suffix1", "suffix2"},
inputPrefix: "prefix",
inputSuffix: "suffix",
expected: `
referrerFinal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -633,8 +642,8 @@ ref:
name: oldName
`,
filter: Filter{
FieldSpec: types.FieldSpec{Path: "ref/name"},
Target: resid.Gvk{
NameFieldToUpdate: types.FieldSpec{Path: "ref/name"},
ReferralTarget: resid.Gvk{
Group: "apps",
Version: "v1",
Kind: "Secret",
@@ -643,7 +652,7 @@ ref:
err: false,
},
"no match: prefix doesn't match": {
input: `
referrerOriginal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -667,7 +676,7 @@ metadata:
suffix: []string{"suffix", "suffix"},
inputPrefix: "prefix",
inputSuffix: "suffix",
expected: `
referrerFinal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -676,8 +685,8 @@ ref:
name: oldName
`,
filter: Filter{
FieldSpec: types.FieldSpec{Path: "ref/name"},
Target: resid.Gvk{
NameFieldToUpdate: types.FieldSpec{Path: "ref/name"},
ReferralTarget: resid.Gvk{
Group: "apps",
Version: "v1",
Kind: "Secret",
@@ -686,7 +695,7 @@ ref:
err: false,
},
"no match: suffix doesn't match": {
input: `
referrerOriginal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -710,7 +719,7 @@ metadata:
suffix: []string{"suffix1", "suffix2"},
inputPrefix: "prefix",
inputSuffix: "suffix",
expected: `
referrerFinal: `
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -719,8 +728,8 @@ ref:
name: oldName
`,
filter: Filter{
FieldSpec: types.FieldSpec{Path: "ref/name"},
Target: resid.Gvk{
NameFieldToUpdate: types.FieldSpec{Path: "ref/name"},
ReferralTarget: resid.Gvk{
Group: "apps",
Version: "v1",
Kind: "Secret",
@@ -732,8 +741,8 @@ ref:
for tn, tc := range testCases {
t.Run(tn, func(t *testing.T) {
factory := resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())
referrer, err := factory.FromBytes([]byte(tc.input))
factory := provider.NewDefaultDepProvider().GetResourceFactory()
referrer, err := factory.FromBytes([]byte(tc.referrerOriginal))
if err != nil {
t.Fatal(err)
}
@@ -745,7 +754,7 @@ ref:
}
tc.filter.Referrer = referrer
resMapFactory := resmap.NewFactory(factory, nil)
resMapFactory := resmap.NewFactory(factory)
candidatesRes, err := factory.SliceFromBytesWithNames(
tc.originalNames, []byte(tc.candidates))
if err != nil {
@@ -765,13 +774,15 @@ ref:
if !tc.err {
if !assert.Equal(t,
strings.TrimSpace(tc.expected),
strings.TrimSpace(tc.referrerFinal),
strings.TrimSpace(
filtertest_test.RunFilter(t, tc.input, tc.filter))) {
filtertest_test.RunFilter(
t, tc.referrerOriginal, tc.filter))) {
t.FailNow()
}
} else {
_, err := filtertest_test.RunFilterE(t, tc.input, tc.filter)
_, err := filtertest_test.RunFilterE(
t, tc.referrerOriginal, tc.filter)
if err == nil {
t.Fatalf("an error is expected")
}

View File

@@ -1,3 +1,6 @@
// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package nameref
import (

View File

@@ -1,3 +1,6 @@
// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package nameref
import (

View File

@@ -4,11 +4,11 @@
package namespace
import (
"sigs.k8s.io/kustomize/api/filters/fieldspec"
"sigs.k8s.io/kustomize/api/filters/filtersutil"
"sigs.k8s.io/kustomize/api/filters/fsslice"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/resid"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
@@ -18,9 +18,17 @@ type Filter struct {
// FsSlice contains the FieldSpecs to locate the namespace field
FsSlice types.FsSlice `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
trackableSetter filtersutil.TrackableSetter
}
var _ kio.Filter = Filter{}
var _ kio.TrackableFilter = &Filter{}
// WithMutationTracker registers a callback which will be invoked each time a field is mutated
func (ns *Filter) WithMutationTracker(callback func(key, value, tag string, node *yaml.RNode)) {
ns.trackableSetter.WithMutationTracker(callback)
}
func (ns Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
return kio.FilterAll(yaml.FilterFunc(ns.run)).Filter(nodes)
@@ -44,7 +52,7 @@ func (ns Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
// transformations based on data -- :)
err := node.PipeE(fsslice.Filter{
FsSlice: ns.FsSlice,
SetValue: filtersutil.SetScalar(ns.Namespace),
SetValue: ns.trackableSetter.SetEntry("", ns.Namespace, yaml.NodeTagString),
CreateKind: yaml.ScalarNode, // Namespace is a ScalarNode
CreateTag: yaml.NodeTagString,
})
@@ -54,16 +62,11 @@ func (ns Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
// hacks applies the namespace transforms that are hardcoded rather
// than specified through FieldSpecs.
func (ns Filter) hacks(obj *yaml.RNode) error {
meta, err := obj.GetMeta()
if err != nil {
gvk := resid.GvkFromNode(obj)
if err := ns.metaNamespaceHack(obj, gvk); err != nil {
return err
}
if err := ns.metaNamespaceHack(obj, meta); err != nil {
return err
}
return ns.roleBindingHack(obj, meta)
return ns.roleBindingHack(obj, gvk)
}
// metaNamespaceHack is a hack for implementing the namespace transform
@@ -74,16 +77,15 @@ func (ns Filter) hacks(obj *yaml.RNode) error {
// This hack should be updated to allow individual resources to specify
// if they are cluster scoped through either an annotation on the resources,
// or through inlined OpenAPI on the resource as a YAML comment.
func (ns Filter) metaNamespaceHack(obj *yaml.RNode, meta yaml.ResourceMeta) error {
gvk := fieldspec.GetGVK(meta)
if !gvk.IsNamespaceableKind() {
func (ns Filter) metaNamespaceHack(obj *yaml.RNode, gvk resid.Gvk) error {
if gvk.IsClusterScoped() {
return nil
}
f := fsslice.Filter{
FsSlice: []types.FieldSpec{
{Path: types.MetadataNamespacePath, CreateIfNotPresent: true},
},
SetValue: filtersutil.SetScalar(ns.Namespace),
SetValue: ns.trackableSetter.SetEntry("", ns.Namespace, yaml.NodeTagString),
CreateKind: yaml.ScalarNode, // Namespace is a ScalarNode
}
_, err := f.Filter(obj)
@@ -104,8 +106,8 @@ func (ns Filter) metaNamespaceHack(obj *yaml.RNode, meta yaml.ResourceMeta) erro
// ...
// - name: "something-else" # this will not have the namespace set
// ...
func (ns Filter) roleBindingHack(obj *yaml.RNode, meta yaml.ResourceMeta) error {
if meta.Kind != roleBindingKind && meta.Kind != clusterRoleBindingKind {
func (ns Filter) roleBindingHack(obj *yaml.RNode, gvk resid.Gvk) error {
if gvk.Kind != roleBindingKind && gvk.Kind != clusterRoleBindingKind {
return nil
}
@@ -118,7 +120,6 @@ func (ns Filter) roleBindingHack(obj *yaml.RNode, meta yaml.ResourceMeta) error
// add the namespace to each "subject" with name: default
err = obj.VisitElements(func(o *yaml.RNode) error {
// copied from kunstruct based kustomize NamespaceTransformer plugin
// The only case we need to force the namespace
// if for the "service account". "default" is
// kind of hardcoded here for right now.
@@ -130,11 +131,14 @@ func (ns Filter) roleBindingHack(obj *yaml.RNode, meta yaml.ResourceMeta) error
}
// set the namespace for the default account
v := yaml.NewScalarRNode(ns.Namespace)
return o.PipeE(
node, err := o.Pipe(
yaml.LookupCreate(yaml.ScalarNode, "namespace"),
yaml.FieldSetter{Value: v},
)
if err != nil {
return err
}
return ns.trackableSetter.SetEntry("", ns.Namespace, yaml.NodeTagString)(node)
})
return err

View File

@@ -12,8 +12,11 @@ import (
"sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
filtertest_test "sigs.k8s.io/kustomize/api/testutils/filtertest"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
var mutationTrackerStub = filtertest_test.MutationTrackerStub{}
var tests = []TestCase{
{
name: "add",
@@ -283,29 +286,134 @@ a:
},
},
},
{
name: "mutation tracker",
input: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
---
apiVersion: example.com/v1
kind: RoleBinding
subjects:
- name: default
`,
expected: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
namespace: bar
a:
b:
c: bar
---
apiVersion: example.com/v1
kind: RoleBinding
subjects:
- name: default
namespace: bar
metadata:
namespace: bar
a:
b:
c: bar
`,
filter: namespace.Filter{Namespace: "bar"},
fsslice: []types.FieldSpec{
{
Path: "a/b/c",
CreateIfNotPresent: true,
},
},
mutationTracker: mutationTrackerStub.MutationTracker,
expectedSetValueArgs: []filtertest_test.SetValueArg{
{
Value: "bar",
Tag: "!!str",
NodePath: []string{"metadata", "namespace"},
},
{
Value: "bar",
Tag: "!!str",
NodePath: []string{"a", "b", "c"},
},
{
Value: "bar",
Tag: "!!str",
NodePath: []string{"metadata", "namespace"},
},
{
Value: "bar",
Tag: "!!str",
NodePath: []string{"namespace"},
},
{
Value: "bar",
Tag: "!!str",
NodePath: []string{"a", "b", "c"},
},
},
},
{
name: "numeric",
input: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance
`,
expected: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
namespace: "01234"
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance
namespace: "01234"
`,
filter: namespace.Filter{Namespace: "01234"},
},
}
type TestCase struct {
name string
input string
expected string
filter namespace.Filter
fsslice types.FsSlice
name string
input string
expected string
filter namespace.Filter
fsslice types.FsSlice
mutationTracker func(key, value, tag string, node *yaml.RNode)
expectedSetValueArgs []filtertest_test.SetValueArg
}
var config = builtinconfig.MakeDefaultConfig()
func TestNamespace_Filter(t *testing.T) {
for i := range tests {
mutationTrackerStub.Reset()
test := tests[i]
test.filter.WithMutationTracker(test.mutationTracker)
t.Run(test.name, func(t *testing.T) {
test.filter.FsSlice = append(config.NameSpace, test.fsslice...)
test.filter.FsSlice = append(config.NameSpace, test.fsslice...) //nolint:gocritic
if !assert.Equal(t,
strings.TrimSpace(test.expected),
strings.TrimSpace(
filtertest_test.RunFilter(t, test.input, test.filter))) {
t.FailNow()
}
assert.Equal(t, test.expectedSetValueArgs, mutationTrackerStub.SetValueArgs())
})
}
}

View File

@@ -15,6 +15,7 @@ type Filter struct {
var _ kio.Filter = Filter{}
// Filter does a strategic merge patch, which can delete nodes.
func (pf Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
var result []*yaml.RNode
for i := range nodes {
@@ -27,7 +28,9 @@ func (pf Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
if err != nil {
return nil, err
}
result = append(result, r)
if r != nil {
result = append(result, r)
}
}
return result, nil
}

View File

@@ -1,3 +1,6 @@
// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package patchstrategicmerge
import (
@@ -15,6 +18,101 @@ func TestFilter(t *testing.T) {
patch *yaml.RNode
expected string
}{
"simple": {
input: `apiVersion: v1
kind: Deployment
metadata:
name: clown
spec:
numReplicas: 1
`,
patch: yaml.MustParse(`apiVersion: v1
kind: Deployment
metadata:
name: clown
spec:
numReplicas: 999
`),
expected: `apiVersion: v1
kind: Deployment
metadata:
name: clown
spec:
numReplicas: 999
`,
},
"nullMapEntry1": {
input: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: my-foo
spec:
bar:
B:
C: Z
`,
patch: yaml.MustParse(`
apiVersion: example.com/v1
kind: Foo
metadata:
name: my-foo
spec:
bar:
C: Z
D: W
baz:
hello: world
`),
expected: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: my-foo
spec:
bar:
C: Z
D: W
baz:
hello: world
`,
},
"nullMapEntry2": {
input: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: my-foo
spec:
bar:
C: Z
D: W
baz:
hello: world
`,
patch: yaml.MustParse(`
apiVersion: example.com/v1
kind: Foo
metadata:
name: my-foo
spec:
bar:
B:
C: Z
`),
expected: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: my-foo
spec:
bar:
C: Z
D: W
baz:
hello: world
`,
},
"simple patch": {
input: `
apiVersion: apps/v1
@@ -370,6 +468,270 @@ spec:
image: test2
- name: test
image: test
`,
},
"list map keys - add a port, no names": {
input: `
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deployment
spec:
template:
spec:
containers:
- image: test-image
name: test-deployment
ports:
- containerPort: 8080
protocol: TCP
`,
patch: yaml.MustParse(`
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deployment
spec:
template:
spec:
containers:
- image: test-image
name: test-deployment
ports:
- containerPort: 8080
protocol: UDP
- containerPort: 80
protocol: UDP
`),
expected: `
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deployment
spec:
template:
spec:
containers:
- image: test-image
name: test-deployment
ports:
- containerPort: 8080
protocol: UDP
- containerPort: 80
protocol: UDP
- containerPort: 8080
protocol: TCP
`,
},
"list map keys - add name to port": {
input: `
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deployment
spec:
template:
spec:
containers:
- image: test-image
name: test-deployment
ports:
- containerPort: 8080
protocol: UDP
- containerPort: 8080
protocol: TCP
`,
patch: yaml.MustParse(`
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deployment
spec:
template:
spec:
containers:
- image: test-image
name: test-deployment
ports:
- containerPort: 8080
protocol: UDP
name: UDP-name-patch
`),
expected: `
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deployment
spec:
template:
spec:
containers:
- image: test-image
name: test-deployment
ports:
- containerPort: 8080
protocol: UDP
name: UDP-name-patch
- containerPort: 8080
protocol: TCP
`,
},
"list map keys - replace port name": {
input: `
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deployment
spec:
template:
spec:
containers:
- image: test-image
name: test-deployment
ports:
- containerPort: 8080
protocol: UDP
name: UDP-name-original
- containerPort: 8080
protocol: TCP
name: TCP-name-original
`,
patch: yaml.MustParse(`
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deployment
spec:
template:
spec:
containers:
- image: test-image
name: test-deployment
ports:
- containerPort: 8080
protocol: UDP
name: UDP-name-patch
`),
expected: `
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deployment
spec:
template:
spec:
containers:
- image: test-image
name: test-deployment
ports:
- containerPort: 8080
protocol: UDP
name: UDP-name-patch
- containerPort: 8080
protocol: TCP
name: TCP-name-original
`,
},
"list map keys - add a port, no protocol": {
input: `
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deployment
spec:
template:
spec:
containers:
- image: test-image
name: test-deployment
ports:
- containerPort: 8080
`,
patch: yaml.MustParse(`
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deployment
spec:
template:
spec:
containers:
- image: test-image
name: test-deployment
ports:
- containerPort: 80
`),
expected: `
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deployment
spec:
template:
spec:
containers:
- image: test-image
name: test-deployment
ports:
- containerPort: 80
- containerPort: 8080
`,
},
// Test for issue #3513
// Currently broken; when one port has only containerPort, the output
// should not merge containerPort 8301 together
// This occurs because when protocol is missing on the first port,
// the merge code uses [containerPort] as the merge key rather than
// [containerPort, protocol]
"list map keys - protocol only present on some ports": {
input: `
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deployment
spec:
template:
spec:
containers:
- name: consul
image: "dashicorp/consul:1.9.1"
ports:
- containerPort: 8500
name: http
- containerPort: 8301
protocol: "TCP"
- containerPort: 8301
protocol: "UDP"
`,
patch: yaml.MustParse(`
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deployment
labels:
test: label
`),
expected: `
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-deployment
labels:
test: label
spec:
template:
spec:
containers:
- name: consul
image: "dashicorp/consul:1.9.1"
ports:
- containerPort: 8500
name: http
- containerPort: 8301
protocol: "TCP"
- containerPort: 8301
protocol: "UDP"
`,
},
}

View File

@@ -0,0 +1,6 @@
// Copyright 2020 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// Package prefix contains a kio.Filter implementation of the kustomize
// PrefixTransformer.
package prefix

View File

@@ -0,0 +1,47 @@
// Copyright 2020 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package prefix_test
import (
"bytes"
"log"
"os"
"sigs.k8s.io/kustomize/api/filters/prefix"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/kio"
)
func ExampleFilter() {
err := kio.Pipeline{
Inputs: []kio.Reader{&kio.ByteReader{Reader: bytes.NewBufferString(`
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance
`)}},
Filters: []kio.Filter{prefix.Filter{
Prefix: "baz-", FieldSpec: types.FieldSpec{Path: "metadata/name"}}},
Outputs: []kio.Writer{kio.ByteWriter{Writer: os.Stdout}},
}.Execute()
if err != nil {
log.Fatal(err)
}
// Output:
// apiVersion: example.com/v1
// kind: Foo
// metadata:
// name: baz-instance
// ---
// apiVersion: example.com/v1
// kind: Bar
// metadata:
// name: baz-instance
}

View File

@@ -0,0 +1,50 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package prefix
import (
"fmt"
"sigs.k8s.io/kustomize/api/filters/fieldspec"
"sigs.k8s.io/kustomize/api/filters/filtersutil"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
// Filter applies resource name prefix's using the fieldSpecs
type Filter struct {
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
FieldSpec types.FieldSpec `json:"fieldSpec,omitempty" yaml:"fieldSpec,omitempty"`
trackableSetter filtersutil.TrackableSetter
}
var _ kio.Filter = Filter{}
var _ kio.TrackableFilter = &Filter{}
// WithMutationTracker registers a callback which will be invoked each time a field is mutated
func (f *Filter) WithMutationTracker(callback func(key, value, tag string, node *yaml.RNode)) {
f.trackableSetter.WithMutationTracker(callback)
}
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
return kio.FilterAll(yaml.FilterFunc(f.run)).Filter(nodes)
}
func (f Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
err := node.PipeE(fieldspec.Filter{
FieldSpec: f.FieldSpec,
SetValue: f.evaluateField,
CreateKind: yaml.ScalarNode, // Name is a ScalarNode
CreateTag: yaml.NodeTagString,
})
return node, err
}
func (f Filter) evaluateField(node *yaml.RNode) error {
return f.trackableSetter.SetScalar(fmt.Sprintf(
"%s%s", f.Prefix, node.YNode().Value))(node)
}

View File

@@ -0,0 +1,154 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package prefix_test
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"sigs.k8s.io/kustomize/api/filters/prefix"
filtertest_test "sigs.k8s.io/kustomize/api/testutils/filtertest"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
var mutationTrackerStub = filtertest_test.MutationTrackerStub{}
var tests = map[string]TestCase{
"prefix": {
input: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance
`,
expected: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: foo-instance
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: foo-instance
`,
filter: prefix.Filter{
Prefix: "foo-",
FieldSpec: types.FieldSpec{Path: "metadata/name"},
},
},
"data-fieldspecs": {
input: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
a:
b:
c: d
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance
a:
b:
c: d
`,
expected: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
a:
b:
c: foo-d
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance
a:
b:
c: foo-d
`,
filter: prefix.Filter{
Prefix: "foo-",
FieldSpec: types.FieldSpec{Path: "a/b/c"},
},
},
"mutation tracker": {
input: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance
`,
expected: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: foo-instance
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: foo-instance
`,
filter: prefix.Filter{
Prefix: "foo-",
FieldSpec: types.FieldSpec{Path: "metadata/name"},
},
mutationTracker: mutationTrackerStub.MutationTracker,
expectedSetValueArgs: []filtertest_test.SetValueArg{
{
Value: "foo-instance",
NodePath: []string{"metadata", "name"},
},
{
Value: "foo-instance",
NodePath: []string{"metadata", "name"},
},
},
},
}
type TestCase struct {
input string
expected string
filter prefix.Filter
mutationTracker func(key, value, tag string, node *yaml.RNode)
expectedSetValueArgs []filtertest_test.SetValueArg
}
func TestFilter(t *testing.T) {
for name := range tests {
mutationTrackerStub.Reset()
test := tests[name]
test.filter.WithMutationTracker(test.mutationTracker)
t.Run(name, func(t *testing.T) {
if !assert.Equal(t,
strings.TrimSpace(test.expected),
strings.TrimSpace(
filtertest_test.RunFilter(t, test.input, test.filter))) {
t.FailNow()
}
assert.Equal(t, test.expectedSetValueArgs, mutationTrackerStub.SetValueArgs())
})
}
}

View File

@@ -1,6 +0,0 @@
// Copyright 2020 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// Package prefixsuffix contains a kio.Filter implementation of the kustomize
// PrefixSuffixTransformer.
package prefixsuffix

View File

@@ -1,47 +0,0 @@
// Copyright 2020 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package prefixsuffix_test
import (
"bytes"
"log"
"os"
"sigs.k8s.io/kustomize/api/filters/prefixsuffix"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/kio"
)
func ExampleFilter() {
err := kio.Pipeline{
Inputs: []kio.Reader{&kio.ByteReader{Reader: bytes.NewBufferString(`
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance
`)}},
Filters: []kio.Filter{prefixsuffix.Filter{
Prefix: "baz-", FieldSpec: types.FieldSpec{Path: "metadata/name"}}},
Outputs: []kio.Writer{kio.ByteWriter{Writer: os.Stdout}},
}.Execute()
if err != nil {
log.Fatal(err)
}
// Output:
// apiVersion: example.com/v1
// kind: Foo
// metadata:
// name: baz-instance
// ---
// apiVersion: example.com/v1
// kind: Bar
// metadata:
// name: baz-instance
}

View File

@@ -1,43 +0,0 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package prefixsuffix
import (
"fmt"
"sigs.k8s.io/kustomize/api/filters/fieldspec"
"sigs.k8s.io/kustomize/api/filters/filtersutil"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
// Filter applies resource name prefix's and suffix's using the fieldSpecs
type Filter struct {
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
Suffix string `json:"suffix,omitempty" yaml:"suffix,omitempty"`
FieldSpec types.FieldSpec `json:"fieldSpec,omitempty" yaml:"fieldSpec,omitempty"`
}
var _ kio.Filter = Filter{}
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
return kio.FilterAll(yaml.FilterFunc(f.run)).Filter(nodes)
}
func (f Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
err := node.PipeE(fieldspec.Filter{
FieldSpec: f.FieldSpec,
SetValue: f.evaluateField,
CreateKind: yaml.ScalarNode, // Name is a ScalarNode
CreateTag: yaml.NodeTagString,
})
return node, err
}
func (f Filter) evaluateField(node *yaml.RNode) error {
return filtersutil.SetScalar(fmt.Sprintf(
"%s%s%s", f.Prefix, node.YNode().Value, f.Suffix))(node)
}

View File

@@ -1,158 +0,0 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package prefixsuffix_test
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"sigs.k8s.io/kustomize/api/filters/prefixsuffix"
filtertest_test "sigs.k8s.io/kustomize/api/testutils/filtertest"
"sigs.k8s.io/kustomize/api/types"
)
var tests = map[string]TestCase{
"prefix": {
input: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance
`,
expected: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: foo-instance
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: foo-instance
`,
filter: prefixsuffix.Filter{Prefix: "foo-"},
fs: types.FieldSpec{Path: "metadata/name"},
},
"suffix": {
input: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance
`,
expected: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance-foo
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance-foo
`,
filter: prefixsuffix.Filter{Suffix: "-foo"},
fs: types.FieldSpec{Path: "metadata/name"},
},
"prefix-suffix": {
input: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance
`,
expected: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: bar-instance-foo
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: bar-instance-foo
`,
filter: prefixsuffix.Filter{Prefix: "bar-", Suffix: "-foo"},
fs: types.FieldSpec{Path: "metadata/name"},
},
"data-fieldspecs": {
input: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
a:
b:
c: d
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance
a:
b:
c: d
`,
expected: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
a:
b:
c: foo-d
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance
a:
b:
c: foo-d
`,
filter: prefixsuffix.Filter{Prefix: "foo-"},
fs: types.FieldSpec{Path: "a/b/c"},
},
}
type TestCase struct {
input string
expected string
filter prefixsuffix.Filter
fs types.FieldSpec
}
func TestFilter(t *testing.T) {
for name := range tests {
test := tests[name]
t.Run(name, func(t *testing.T) {
test.filter.FieldSpec = test.fs
if !assert.Equal(t,
strings.TrimSpace(test.expected),
strings.TrimSpace(
filtertest_test.RunFilter(t, test.input, test.filter))) {
t.FailNow()
}
})
}
}

View File

@@ -1,3 +1,6 @@
// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// Package refvar contains a kio.Filter implementation of the kustomize
// refvar transformer.
// refvar transformer (find and replace $(FOO) style variables in strings).
package refvar

View File

@@ -0,0 +1,147 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package refvar
import (
"fmt"
"log"
"strings"
)
const (
operator = '$'
referenceOpener = '('
referenceCloser = ')'
)
// syntaxWrap returns the input string wrapped by the expansion syntax.
func syntaxWrap(input string) string {
var sb strings.Builder
sb.WriteByte(operator)
sb.WriteByte(referenceOpener)
sb.WriteString(input)
sb.WriteByte(referenceCloser)
return sb.String()
}
// MappingFunc maps a string to anything.
type MappingFunc func(string) interface{}
// MakePrimitiveReplacer returns a MappingFunc that uses a map to do
// replacements, and a histogram to count map hits.
//
// Func behavior:
//
// If the input key is NOT found in the map, the key is wrapped up as
// as a variable declaration string and returned, e.g. key FOO becomes $(FOO).
// This string is presumably put back where it was found, and might get replaced
// later.
//
// If the key is found in the map, the value is returned if it is a primitive
// type (string, bool, number), and the hit is counted.
//
// If it's not a primitive type (e.g. a map, struct, func, etc.) then this
// function doesn't know what to do with it and it returns the key wrapped up
// again as if it had not been replaced. This should probably be an error.
func MakePrimitiveReplacer(
counts map[string]int, someMap map[string]interface{}) MappingFunc {
return func(key string) interface{} {
if value, ok := someMap[key]; ok {
switch typedV := value.(type) {
case string, int, int32, int64, float32, float64, bool:
counts[key]++
return typedV
default:
// If the value is some complicated type (e.g. a map or struct),
// this function doesn't know how to jam it into a string,
// so just pretend it was a cache miss.
// Likely this should be an error instead of a silent failure,
// since the programmer passed an impossible value.
log.Printf(
"MakePrimitiveReplacer: bad replacement type=%T val=%v",
typedV, typedV)
return syntaxWrap(key)
}
}
// If unable to return the mapped variable, return it
// as it was found, and a later mapping might be able to
// replace it.
return syntaxWrap(key)
}
}
// DoReplacements replaces variable references in the input string
// using the mapping function.
func DoReplacements(input string, mapping MappingFunc) interface{} {
var buf strings.Builder
checkpoint := 0
for cursor := 0; cursor < len(input); cursor++ {
if input[cursor] == operator && cursor+1 < len(input) {
// Copy the portion of the input string since the last
// checkpoint into the buffer
buf.WriteString(input[checkpoint:cursor])
// Attempt to read the variable name as defined by the
// syntax from the input string
read, isVar, advance := tryReadVariableName(input[cursor+1:])
if isVar {
// We were able to read a variable name correctly;
// apply the mapping to the variable name and copy the
// bytes into the buffer
mapped := mapping(read)
if input == syntaxWrap(read) {
// Preserve the type of variable
return mapped
}
// Variable is used in a middle of a string
buf.WriteString(fmt.Sprintf("%v", mapped))
} else {
// Not a variable name; copy the read bytes into the buffer
buf.WriteString(read)
}
// Advance the cursor in the input string to account for
// bytes consumed to read the variable name expression
cursor += advance
// Advance the checkpoint in the input string
checkpoint = cursor + 1
}
}
// Return the buffer and any remaining unwritten bytes in the
// input string.
return buf.String() + input[checkpoint:]
}
// tryReadVariableName attempts to read a variable name from the input
// string and returns the content read from the input, whether that content
// represents a variable name to perform mapping on, and the number of bytes
// consumed in the input string.
//
// The input string is assumed not to contain the initial operator.
func tryReadVariableName(input string) (string, bool, int) {
switch input[0] {
case operator:
// Escaped operator; return it.
return input[0:1], false, 1
case referenceOpener:
// Scan to expression closer
for i := 1; i < len(input); i++ {
if input[i] == referenceCloser {
return input[1:i], true, i + 1
}
}
// Incomplete reference; return it.
return string(operator) + string(referenceOpener), false, 1
default:
// Not the beginning of an expression, ie, an operator
// that doesn't begin an expression. Return the operator
// and the first rune in the string.
return string(operator) + string(input[0]), false, 1
}
}

View File

@@ -1,13 +1,14 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package expansion_test
package refvar_test
import (
"fmt"
"testing"
. "sigs.k8s.io/kustomize/api/internal/accumulator/expansion"
"github.com/stretchr/testify/assert"
. "sigs.k8s.io/kustomize/api/filters/refvar"
)
type expected struct {
@@ -15,6 +16,48 @@ type expected struct {
edited string
}
func TestPrimitiveReplacer(t *testing.T) {
varCounts := make(map[string]int)
f := MakePrimitiveReplacer(
varCounts,
map[string]interface{}{
"FOO": "bar",
"ZOO": "$(FOO)-1",
"BLU": "$(ZOO)-2",
"EIGHT": 8,
"PI": 3.14159,
"ZINT": "$(INT)",
"BOOL": "true",
"HUGENUMBER": int64(9223372036854775807),
"CRAZYMAP": map[string]int{"crazy": 200},
"ZBOOL": "$(BOOL)",
})
assert.Equal(t, "$()", f(""))
assert.Equal(t, "$( )", f(" "))
assert.Equal(t, "$(florida)", f("florida"))
assert.Equal(t, "$(0)", f("0"))
assert.Equal(t, "bar", f("FOO"))
assert.Equal(t, "bar", f("FOO"))
assert.Equal(t, "bar", f("FOO"))
assert.Equal(t, 8, f("EIGHT"))
assert.Equal(t, 8, f("EIGHT"))
assert.Equal(t, 3.14159, f("PI"))
assert.Equal(t, "true", f("BOOL"))
assert.Equal(t, int64(9223372036854775807), f("HUGENUMBER"))
assert.Equal(t, "$(FOO)-1", f("ZOO"))
assert.Equal(t, "$(CRAZYMAP)", f("CRAZYMAP"))
assert.Equal(t,
map[string]int{
"FOO": 3,
"EIGHT": 2,
"BOOL": 1,
"PI": 1,
"ZOO": 1,
"HUGENUMBER": 1,
},
varCounts)
}
func TestMapReference(t *testing.T) {
type env struct {
Name string
@@ -51,7 +94,7 @@ func TestMapReference(t *testing.T) {
},
}
declaredEnv := map[string]interface{}{
varMap := map[string]interface{}{
"FOO": "bar",
"ZOO": "$(FOO)-1",
"BLU": "$(ZOO)-2",
@@ -61,11 +104,11 @@ func TestMapReference(t *testing.T) {
"ZBOOL": "$(BOOL)",
}
counts := make(map[string]int)
mapping := MappingFuncFor(counts, declaredEnv)
varCounts := make(map[string]int)
for _, env := range envs {
declaredEnv[env.Name] = Expand(fmt.Sprintf("%v", env.Value), mapping)
varMap[env.Name] = DoReplacements(
fmt.Sprintf("%v", env.Value),
MakePrimitiveReplacer(varCounts, varMap))
}
expectedEnv := map[string]expected{
@@ -79,45 +122,20 @@ func TestMapReference(t *testing.T) {
}
for k, v := range expectedEnv {
if e, a := v, declaredEnv[k]; e.edited != a || e.count != counts[k] {
if e, a := v, varMap[k]; e.edited != a || e.count != varCounts[k] {
t.Errorf("Expected %v count=%d, got %v count=%d",
e.edited, e.count, a, counts[k])
e.edited, e.count, a, varCounts[k])
} else {
delete(declaredEnv, k)
delete(varMap, k)
}
}
if len(declaredEnv) != 0 {
t.Errorf("Unexpected keys in declared env: %v", declaredEnv)
if len(varMap) != 0 {
t.Errorf("Unexpected keys in declared env: %v", varMap)
}
}
func TestMapping(t *testing.T) {
context := map[string]interface{}{
"VAR_A": "A",
"VAR_B": "B",
"VAR_C": "C",
"VAR_REF": "$(VAR_A)",
"VAR_EMPTY": "",
}
doExpansionTest(t, context)
}
func TestMappingDual(t *testing.T) {
context := map[string]interface{}{
"VAR_A": "A",
"VAR_EMPTY": "",
}
context2 := map[string]interface{}{
"VAR_B": "B",
"VAR_C": "C",
"VAR_REF": "$(VAR_A)",
}
doExpansionTest(t, context, context2)
}
func doExpansionTest(t *testing.T, context ...map[string]interface{}) {
cases := []struct {
name string
input string
@@ -333,11 +351,17 @@ func doExpansionTest(t *testing.T, context ...map[string]interface{}) {
expected: "\n",
},
}
for _, tc := range cases {
counts := make(map[string]int)
mapping := MappingFuncFor(counts, context...)
expanded := Expand(fmt.Sprintf("%v", tc.input), mapping)
expanded := DoReplacements(
fmt.Sprintf("%v", tc.input),
MakePrimitiveReplacer(counts, map[string]interface{}{
"VAR_A": "A",
"VAR_B": "B",
"VAR_C": "C",
"VAR_REF": "$(VAR_A)",
"VAR_EMPTY": "",
}))
if e, a := tc.expected, expanded; e != a {
t.Errorf("%v: expected %q, got %q", tc.name, e, a)
}
@@ -347,8 +371,7 @@ func doExpansionTest(t *testing.T, context ...map[string]interface{}) {
}
if len(tc.counts) > 0 {
for k, expectedCount := range tc.counts {
c, ok := counts[k]
if ok {
if c, ok := counts[k]; ok {
if c != expectedCount {
t.Errorf(
"%v: k=%s, expected count %d, got %d",

View File

@@ -1,3 +1,6 @@
// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package refvar
import (
@@ -8,15 +11,13 @@ import (
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/yaml"
expansion2 "sigs.k8s.io/kustomize/api/internal/accumulator/expansion"
)
// Filter updates $(VAR) style variables with values.
// The fieldSpecs are the places to look for occurrences of $(VAR).
type Filter struct {
MappingFunc func(string) interface{} `json:"mappingFunc,omitempty" yaml:"mappingFunc,omitempty"`
FieldSpec types.FieldSpec `json:"fieldSpec,omitempty" yaml:"fieldSpec,omitempty"`
MappingFunc MappingFunc `json:"mappingFunc,omitempty" yaml:"mappingFunc,omitempty"`
FieldSpec types.FieldSpec `json:"fieldSpec,omitempty" yaml:"fieldSpec,omitempty"`
}
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
@@ -49,12 +50,21 @@ func (f Filter) set(node *yaml.RNode) error {
func updateNodeValue(node *yaml.Node, newValue interface{}) {
switch newValue := newValue.(type) {
case int:
node.Value = strconv.FormatInt(int64(newValue), 10)
node.Tag = yaml.NodeTagInt
case int32:
node.Value = strconv.FormatInt(int64(newValue), 10)
node.Tag = yaml.NodeTagInt
case int64:
node.Value = strconv.FormatInt(newValue, 10)
node.Tag = yaml.NodeTagInt
case bool:
node.SetString(strconv.FormatBool(newValue))
node.Tag = yaml.NodeTagBool
case float32:
node.SetString(strconv.FormatFloat(float64(newValue), 'f', -1, 32))
node.Tag = yaml.NodeTagFloat
case float64:
node.SetString(strconv.FormatFloat(newValue, 'f', -1, 64))
node.Tag = yaml.NodeTagFloat
@@ -69,7 +79,7 @@ func (f Filter) setScalar(node *yaml.RNode) error {
if !yaml.IsYNodeString(node.YNode()) {
return nil
}
v := expansion2.Expand(node.YNode().Value, f.MappingFunc)
v := DoReplacements(node.YNode().Value, f.MappingFunc)
updateNodeValue(node.YNode(), v)
return nil
}
@@ -78,12 +88,14 @@ func (f Filter) setMap(node *yaml.RNode) error {
contents := node.YNode().Content
for i := 0; i < len(contents); i += 2 {
if !yaml.IsYNodeString(contents[i]) {
return fmt.Errorf("invalid map key: %s, type: %s", contents[i].Value, contents[i].Tag)
return fmt.Errorf(
"invalid map key: value='%s', tag='%s'",
contents[i].Value, contents[i].Tag)
}
if !yaml.IsYNodeString(contents[i+1]) {
continue
}
newValue := expansion2.Expand(contents[i+1].Value, f.MappingFunc)
newValue := DoReplacements(contents[i+1].Value, f.MappingFunc)
updateNodeValue(contents[i+1], newValue)
}
return nil
@@ -94,7 +106,7 @@ func (f Filter) setSeq(node *yaml.RNode) error {
if !yaml.IsYNodeString(item) {
return fmt.Errorf("invalid value type expect a string")
}
newValue := expansion2.Expand(item.Value, f.MappingFunc)
newValue := DoReplacements(item.Value, f.MappingFunc)
updateNodeValue(item, newValue)
}
return nil

View File

@@ -1,19 +1,25 @@
package refvar
// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package refvar_test
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
expansion2 "sigs.k8s.io/kustomize/api/internal/accumulator/expansion"
. "sigs.k8s.io/kustomize/api/filters/refvar"
filtertest_test "sigs.k8s.io/kustomize/api/testutils/filtertest"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
func TestFilter(t *testing.T) {
replacementCounts := make(map[string]int)
var makeMf = func(theMap map[string]interface{}) MappingFunc {
ignored := make(map[string]int)
return MakePrimitiveReplacer(ignored, theMap)
}
func TestFilter(t *testing.T) {
testCases := map[string]struct {
input string
expected string
@@ -35,7 +41,7 @@ metadata:
spec:
replicas: 5`,
filter: Filter{
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
MappingFunc: makeMf(map[string]interface{}{
"VAR": int64(5),
}),
FieldSpec: types.FieldSpec{Path: "spec/replicas"},
@@ -57,7 +63,7 @@ metadata:
spec:
replicas: 1`,
filter: Filter{
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
MappingFunc: makeMf(map[string]interface{}{
"VAR": int64(5),
}),
FieldSpec: types.FieldSpec{Path: "spec/replicas"},
@@ -79,7 +85,7 @@ metadata:
spec:
replicas: 1`,
filter: Filter{
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
MappingFunc: makeMf(map[string]interface{}{
"VAR": int64(5),
}),
FieldSpec: types.FieldSpec{Path: "a/b/c"},
@@ -111,7 +117,7 @@ data:
- false
- 1.23`,
filter: Filter{
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
MappingFunc: makeMf(map[string]interface{}{
"FOO": "foo",
"BAR": "bar",
"BOOL": false,
@@ -142,7 +148,7 @@ data:
BAZ: $(BAZ)
PLUS: foo+bar`,
filter: Filter{
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
MappingFunc: makeMf(map[string]interface{}{
"FOO": "foo",
"BAR": "bar",
}),
@@ -181,7 +187,7 @@ data:
SLICE:
- $(FOO)`,
filter: Filter{
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
MappingFunc: makeMf(map[string]interface{}{
"FOO": "foo",
"BAR": "bar",
}),
@@ -204,8 +210,10 @@ metadata:
data:
FOO: null`,
filter: Filter{
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{}),
FieldSpec: types.FieldSpec{Path: "data/FOO"},
MappingFunc: makeMf(map[string]interface{}{
// no replacements!
}),
FieldSpec: types.FieldSpec{Path: "data/FOO"},
},
},
}
@@ -223,8 +231,6 @@ data:
}
func TestFilterUnhappy(t *testing.T) {
replacementCounts := make(map[string]int)
testCases := map[string]struct {
input string
expectedError string
@@ -239,18 +245,9 @@ metadata:
data:
slice:
- false`,
expectedError: `obj 'apiVersion: apps/v1
kind: Deployment
metadata:
name: dep
annotations:
config.kubernetes.io/index: '0'
data:
slice:
- false
' at path 'data/slice': invalid value type expect a string`,
expectedError: `considering field 'data/slice' of object Deployment.v1.apps/dep.[noNs]: invalid value type expect a string`,
filter: Filter{
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
MappingFunc: makeMf(map[string]interface{}{
"VAR": int64(5),
}),
FieldSpec: types.FieldSpec{Path: "data/slice"},
@@ -264,17 +261,9 @@ metadata:
name: dep
data:
1: str`,
expectedError: `obj 'apiVersion: apps/v1
kind: Deployment
metadata:
name: dep
annotations:
config.kubernetes.io/index: '0'
data:
1: str
' at path 'data': invalid map key: 1, type: ` + yaml.NodeTagInt,
expectedError: `considering field 'data' of object Deployment.v1.apps/dep.[noNs]: invalid map key: value='1', tag='` + yaml.NodeTagInt + `'`,
filter: Filter{
MappingFunc: expansion2.MappingFuncFor(replacementCounts, map[string]interface{}{
MappingFunc: makeMf(map[string]interface{}{
"VAR": int64(5),
}),
FieldSpec: types.FieldSpec{Path: "data"},

View File

@@ -0,0 +1,7 @@
// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// Package replacement contains a kio.Filter implementation of the kustomize
// replacement transformer (accepts sources and looks for targets to replace
// their values with values from the sources).
package replacement

View File

@@ -0,0 +1,68 @@
// Copyright 2021 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package replacement
import (
"bytes"
"log"
"os"
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
func ExampleFilter() {
f := Filter{}
err := yaml.Unmarshal([]byte(`
replacements:
- source:
kind: Foo2
fieldPath: spec.replicas
targets:
- select:
kind: Foo1
fieldPaths:
- spec.replicas`), &f)
if err != nil {
log.Fatal(err)
}
err = kio.Pipeline{
Inputs: []kio.Reader{&kio.ByteReader{Reader: bytes.NewBufferString(`
apiVersion: example.com/v1
kind: Foo1
metadata:
name: instance
spec:
replicas: 3
---
apiVersion: example.com/v1
kind: Foo2
metadata:
name: instance
spec:
replicas: 99
`)}},
Filters: []kio.Filter{f},
Outputs: []kio.Writer{kio.ByteWriter{Writer: os.Stdout}},
}.Execute()
if err != nil {
log.Fatal(err)
}
// Output:
// apiVersion: example.com/v1
// kind: Foo1
// metadata:
// name: instance
// spec:
// replicas: 99
// ---
// apiVersion: example.com/v1
// kind: Foo2
// metadata:
// name: instance
// spec:
// replicas: 99
}

View File

@@ -0,0 +1,256 @@
// Copyright 2021 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package replacement
import (
"errors"
"fmt"
"strings"
"sigs.k8s.io/kustomize/api/internal/utils"
"sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/resid"
kyaml_utils "sigs.k8s.io/kustomize/kyaml/utils"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
type Filter struct {
Replacements []types.Replacement `json:"replacements,omitempty" yaml:"replacements,omitempty"`
}
// 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 {
return nil, fmt.Errorf("replacements must specify a source and at least one target")
}
value, err := getReplacement(nodes, &f.Replacements[i])
if err != nil {
return nil, err
}
nodes, err = applyReplacement(nodes, value, r.Targets)
if err != nil {
return nil, err
}
}
return nodes, nil
}
func applyReplacement(nodes []*yaml.RNode, value *yaml.RNode, targets []*types.TargetSelector) ([]*yaml.RNode, error) {
for _, t := range targets {
if t.Select == nil {
return nil, fmt.Errorf("target must specify resources to select")
}
if len(t.FieldPaths) == 0 {
t.FieldPaths = []string{types.DefaultReplacementFieldPath}
}
for _, n := range nodes {
ids, err := utils.MakeResIds(n)
if err != nil {
return nil, err
}
// filter targets by label and annotation selectors
selectByAnnoAndLabel, err := selectByAnnoAndLabel(n, t)
if err != nil {
return nil, err
}
if !selectByAnnoAndLabel {
continue
}
// filter targets by matching resource IDs
for i, id := range ids {
if id.IsSelectedBy(t.Select.ResId) && !rejectId(t.Reject, &ids[i]) {
err := applyToNode(n, value, t)
if err != nil {
return nil, err
}
break
}
}
}
}
return nodes, nil
}
func selectByAnnoAndLabel(n *yaml.RNode, t *types.TargetSelector) (bool, error) {
if matchesSelect, err := matchesAnnoAndLabelSelector(n, t.Select); !matchesSelect || err != nil {
return false, err
}
for _, reject := range t.Reject {
if reject.AnnotationSelector == "" && reject.LabelSelector == "" {
continue
}
if m, err := matchesAnnoAndLabelSelector(n, reject); m || err != nil {
return false, err
}
}
return true, nil
}
func matchesAnnoAndLabelSelector(n *yaml.RNode, selector *types.Selector) (bool, error) {
r := resource.Resource{RNode: *n}
annoMatch, err := r.MatchesAnnotationSelector(selector.AnnotationSelector)
if err != nil {
return false, err
}
labelMatch, err := r.MatchesLabelSelector(selector.LabelSelector)
if err != nil {
return false, err
}
return annoMatch && labelMatch, nil
}
func rejectId(rejects []*types.Selector, id *resid.ResId) bool {
for _, r := range rejects {
if !r.ResId.IsEmpty() && id.IsSelectedBy(r.ResId) {
return true
}
}
return false
}
func applyToNode(node *yaml.RNode, value *yaml.RNode, target *types.TargetSelector) error {
for _, fp := range target.FieldPaths {
fieldPath := kyaml_utils.SmarterPathSplitter(fp, ".")
var t *yaml.RNode
var err error
if target.Options != nil && target.Options.Create {
// create option is not supported in a wildcard matching.
// Because, PathMatcher is not supported create option.
// So, if create option is set, we fallback to PathGetter.
for _, f := range fieldPath {
if f == "*" {
return errors.New("cannot support create option in a multi-value target") //nolint:goerr113
}
}
t, err = node.Pipe(yaml.LookupCreate(value.YNode().Kind, fieldPath...))
} else {
t, err = node.Pipe(&yaml.PathMatcher{Path: fieldPath})
}
if err != nil {
return err
}
if t != nil {
if err = applyToOneNode(target.Options, t, value); err != nil {
return err
}
}
}
return nil
}
func applyToOneNode(options *types.FieldOptions, t *yaml.RNode, value *yaml.RNode) error {
if len(t.YNode().Content) == 0 {
if err := setTargetValue(options, t, value); err != nil {
return err
}
return nil
}
for _, scalarNode := range t.YNode().Content {
rn := yaml.NewRNode(scalarNode)
if err := setTargetValue(options, rn, value); err != nil {
return err
}
}
return nil
}
func setTargetValue(options *types.FieldOptions, t *yaml.RNode, value *yaml.RNode) error {
value = value.Copy()
if options != nil && options.Delimiter != "" {
if t.YNode().Kind != yaml.ScalarNode {
return fmt.Errorf("delimiter option can only be used with scalar nodes")
}
tv := strings.Split(t.YNode().Value, options.Delimiter)
v := yaml.GetValue(value)
// TODO: Add a way to remove an element
switch {
case options.Index < 0: // prefix
tv = append([]string{v}, tv...)
case options.Index >= len(tv): // suffix
tv = append(tv, v)
default: // replace an element
tv[options.Index] = v
}
value.YNode().Value = strings.Join(tv, options.Delimiter)
}
if t.YNode().Kind == yaml.ScalarNode {
// For scalar, only copy the value (leave any type intact to auto-convert int->string or string->int)
t.YNode().Value = value.YNode().Value
} else {
t.SetYNode(value.YNode())
}
return nil
}
func getReplacement(nodes []*yaml.RNode, r *types.Replacement) (*yaml.RNode, error) {
source, err := selectSourceNode(nodes, r.Source)
if err != nil {
return nil, err
}
if r.Source.FieldPath == "" {
r.Source.FieldPath = types.DefaultReplacementFieldPath
}
fieldPath := kyaml_utils.SmarterPathSplitter(r.Source.FieldPath, ".")
rn, err := source.Pipe(yaml.Lookup(fieldPath...))
if err != nil {
return nil, err
}
if rn.IsNilOrEmpty() {
return nil, fmt.Errorf("fieldPath `%s` is missing for replacement source %s", r.Source.FieldPath, r.Source.ResId)
}
return getRefinedValue(r.Source.Options, rn)
}
func getRefinedValue(options *types.FieldOptions, rn *yaml.RNode) (*yaml.RNode, error) {
if options == nil || options.Delimiter == "" {
return rn, nil
}
if rn.YNode().Kind != yaml.ScalarNode {
return nil, fmt.Errorf("delimiter option can only be used with scalar nodes")
}
value := strings.Split(yaml.GetValue(rn), options.Delimiter)
if options.Index >= len(value) || options.Index < 0 {
return nil, fmt.Errorf("options.index %d is out of bounds for value %s", options.Index, yaml.GetValue(rn))
}
n := rn.Copy()
n.YNode().Value = value[options.Index]
return n, nil
}
// selectSourceNode finds the node that matches the selector, returning
// an error if multiple or none are found
func selectSourceNode(nodes []*yaml.RNode, selector *types.SourceSelector) (*yaml.RNode, error) {
var matches []*yaml.RNode
for _, n := range nodes {
ids, err := utils.MakeResIds(n)
if err != nil {
return nil, err
}
for _, id := range ids {
if id.IsSelectedBy(selector.ResId) {
if len(matches) > 0 {
return nil, fmt.Errorf(
"multiple matches for selector %s", selector)
}
matches = append(matches, n)
break
}
}
}
if len(matches) == 0 {
return nil, fmt.Errorf("nothing selected by %s", selector)
}
return matches[0], nil
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,6 @@
// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package replicacount
import (

View File

@@ -1,3 +1,6 @@
// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package replicacount
import (
@@ -14,9 +17,17 @@ import (
type Filter struct {
Replica types.Replica `json:"replica,omitempty" yaml:"replica,omitempty"`
FieldSpec types.FieldSpec `json:"fieldSpec,omitempty" yaml:"fieldSpec,omitempty"`
trackableSetter filtersutil.TrackableSetter
}
var _ kio.Filter = Filter{}
var _ kio.TrackableFilter = &Filter{}
// WithMutationTracker registers a callback which will be invoked each time a field is mutated
func (rc *Filter) WithMutationTracker(callback func(key, value, tag string, node *yaml.RNode)) {
rc.trackableSetter.WithMutationTracker(callback)
}
func (rc Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
return kio.FilterAll(yaml.FilterFunc(rc.run)).Filter(nodes)
@@ -33,5 +44,5 @@ func (rc Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
}
func (rc Filter) set(node *yaml.RNode) error {
return filtersutil.SetScalar(strconv.FormatInt(rc.Replica.Count, 10))(node)
return rc.trackableSetter.SetEntry("", strconv.FormatInt(rc.Replica.Count, 10), yaml.NodeTagInt)(node)
}

View File

@@ -1,3 +1,6 @@
// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package replicacount
import (
@@ -7,14 +10,17 @@ import (
"github.com/stretchr/testify/assert"
filtertest_test "sigs.k8s.io/kustomize/api/testutils/filtertest"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
func TestFilter(t *testing.T) {
mutationTrackerStub := filtertest_test.MutationTrackerStub{}
testCases := map[string]struct {
input string
expected string
filter Filter
input string
expected string
filter Filter
mutationTracker func(key, value, tag string, node *yaml.RNode)
expectedSetValueArgs []filtertest_test.SetValueArg
}{
"update field": {
input: `
@@ -161,9 +167,44 @@ spec:
FieldSpec: types.FieldSpec{Path: "spec/template/replicas"},
},
},
"mutation tracker": {
input: `
apiVersion: apps/v1
kind: Deployment
metadata:
name: dep
spec:
replicas: 5
`,
expected: `
apiVersion: apps/v1
kind: Deployment
metadata:
name: dep
spec:
replicas: 42
`,
filter: Filter{
Replica: types.Replica{
Name: "dep",
Count: 42,
},
FieldSpec: types.FieldSpec{Path: "spec/replicas"},
},
mutationTracker: mutationTrackerStub.MutationTracker,
expectedSetValueArgs: []filtertest_test.SetValueArg{
{
Value: "42",
Tag: "!!int",
NodePath: []string{"spec", "replicas"},
},
},
},
}
for tn, tc := range testCases {
mutationTrackerStub.Reset()
tc.filter.WithMutationTracker(tc.mutationTracker)
t.Run(tn, func(t *testing.T) {
if !assert.Equal(t,
strings.TrimSpace(tc.expected),
@@ -171,6 +212,7 @@ spec:
filtertest_test.RunFilter(t, tc.input, tc.filter))) {
t.FailNow()
}
assert.Equal(t, tc.expectedSetValueArgs, mutationTrackerStub.SetValueArgs())
})
}
}

View File

@@ -0,0 +1,6 @@
// Copyright 2021 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// Package suffix contains a kio.Filter implementation of the kustomize
// SuffixTransformer.
package suffix

View File

@@ -0,0 +1,47 @@
// Copyright 2021 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package suffix_test
import (
"bytes"
"log"
"os"
"sigs.k8s.io/kustomize/api/filters/suffix"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/kio"
)
func ExampleFilter() {
err := kio.Pipeline{
Inputs: []kio.Reader{&kio.ByteReader{Reader: bytes.NewBufferString(`
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance
`)}},
Filters: []kio.Filter{suffix.Filter{
Suffix: "-baz", FieldSpec: types.FieldSpec{Path: "metadata/name"}}},
Outputs: []kio.Writer{kio.ByteWriter{Writer: os.Stdout}},
}.Execute()
if err != nil {
log.Fatal(err)
}
// Output:
// apiVersion: example.com/v1
// kind: Foo
// metadata:
// name: instance-baz
// ---
// apiVersion: example.com/v1
// kind: Bar
// metadata:
// name: instance-baz
}

View File

@@ -0,0 +1,50 @@
// Copyright 2021 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package suffix
import (
"fmt"
"sigs.k8s.io/kustomize/api/filters/fieldspec"
"sigs.k8s.io/kustomize/api/filters/filtersutil"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
// Filter applies resource name suffix's using the fieldSpecs
type Filter struct {
Suffix string `json:"suffix,omitempty" yaml:"suffix,omitempty"`
FieldSpec types.FieldSpec `json:"fieldSpec,omitempty" yaml:"fieldSpec,omitempty"`
trackableSetter filtersutil.TrackableSetter
}
var _ kio.Filter = Filter{}
var _ kio.TrackableFilter = &Filter{}
// WithMutationTracker registers a callback which will be invoked each time a field is mutated
func (f *Filter) WithMutationTracker(callback func(key, value, tag string, node *yaml.RNode)) {
f.trackableSetter.WithMutationTracker(callback)
}
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
return kio.FilterAll(yaml.FilterFunc(f.run)).Filter(nodes)
}
func (f Filter) run(node *yaml.RNode) (*yaml.RNode, error) {
err := node.PipeE(fieldspec.Filter{
FieldSpec: f.FieldSpec,
SetValue: f.evaluateField,
CreateKind: yaml.ScalarNode, // Name is a ScalarNode
CreateTag: yaml.NodeTagString,
})
return node, err
}
func (f Filter) evaluateField(node *yaml.RNode) error {
return f.trackableSetter.SetScalar(fmt.Sprintf(
"%s%s", node.YNode().Value, f.Suffix))(node)
}

View File

@@ -0,0 +1,154 @@
// Copyright 2021 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package suffix_test
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
"sigs.k8s.io/kustomize/api/filters/suffix"
filtertest_test "sigs.k8s.io/kustomize/api/testutils/filtertest"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
var mutationTrackerStub = filtertest_test.MutationTrackerStub{}
var tests = map[string]TestCase{
"suffix": {
input: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance
`,
expected: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance-foo
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance-foo
`,
filter: suffix.Filter{
Suffix: "-foo",
FieldSpec: types.FieldSpec{Path: "metadata/name"},
},
},
"data-fieldspecs": {
input: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
a:
b:
c: d
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance
a:
b:
c: d
`,
expected: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
a:
b:
c: d-foo
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance
a:
b:
c: d-foo
`,
filter: suffix.Filter{
Suffix: "-foo",
FieldSpec: types.FieldSpec{Path: "a/b/c"},
},
},
"mutation tracker": {
input: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance
`,
expected: `
apiVersion: example.com/v1
kind: Foo
metadata:
name: instance-foo
---
apiVersion: example.com/v1
kind: Bar
metadata:
name: instance-foo
`,
filter: suffix.Filter{
Suffix: "-foo",
FieldSpec: types.FieldSpec{Path: "metadata/name"},
},
mutationTracker: mutationTrackerStub.MutationTracker,
expectedSetValueArgs: []filtertest_test.SetValueArg{
{
Value: "instance-foo",
NodePath: []string{"metadata", "name"},
},
{
Value: "instance-foo",
NodePath: []string{"metadata", "name"},
},
},
},
}
type TestCase struct {
input string
expected string
filter suffix.Filter
mutationTracker func(key, value, tag string, node *yaml.RNode)
expectedSetValueArgs []filtertest_test.SetValueArg
}
func TestFilter(t *testing.T) {
for name := range tests {
mutationTrackerStub.Reset()
test := tests[name]
test.filter.WithMutationTracker(test.mutationTracker)
t.Run(name, func(t *testing.T) {
if !assert.Equal(t,
strings.TrimSpace(test.expected),
strings.TrimSpace(
filtertest_test.RunFilter(t, test.input, test.filter))) {
t.FailNow()
}
assert.Equal(t, test.expectedSetValueArgs, mutationTrackerStub.SetValueArgs())
})
}
}

View File

@@ -6,7 +6,7 @@ package valueadd
import (
"strings"
"sigs.k8s.io/kustomize/api/filesys"
"sigs.k8s.io/kustomize/kyaml/filesys"
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
@@ -98,7 +98,17 @@ var _ kio.Filter = Filter{}
func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
_, err := kio.FilterAll(yaml.FilterFunc(
func(node *yaml.RNode) (*yaml.RNode, error) {
fields := strings.Split(f.FieldPath, "/")
var fields []string
// if there is forward slash '/' in the field name, a back slash '\'
// will be used to escape it.
for _, f := range strings.Split(f.FieldPath, "/") {
if len(fields) > 0 && strings.HasSuffix(fields[len(fields)-1], "\\") {
concatField := strings.TrimSuffix(fields[len(fields)-1], "\\") + "/" + f
fields = append(fields[:len(fields)-1], concatField)
} else {
fields = append(fields, f)
}
}
// TODO: support SequenceNode.
// Presumably here one could look for array indices (digits) at
// the end of the field path (as described in IETF RFC 6902 JSON),

View File

@@ -94,6 +94,20 @@ spec:
FilePathPosition: 2,
},
},
"backSlash": {
input: `
kind: SomeKind
`,
expectedOutput: `
kind: SomeKind
spec:
resourceRef/external: valueAdded
`,
filter: Filter{
Value: "valueAdded",
FieldPath: "spec/resourceRef\\/external",
},
},
}
for tn, tc := range testCases {

View File

@@ -1,22 +1,16 @@
module sigs.k8s.io/kustomize/api
go 1.14
go 1.16
require (
github.com/evanphx/json-patch v4.5.0+incompatible
github.com/go-openapi/spec v0.19.5
github.com/golangci/golangci-lint v1.21.0
github.com/evanphx/json-patch v4.11.0+incompatible
github.com/go-errors/errors v1.0.1
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/pkg/errors v0.8.1
github.com/stretchr/testify v1.4.0
github.com/yujunz/go-getter v1.4.1-lite
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e
gopkg.in/yaml.v2 v2.3.0
gopkg.in/yaml.v3 v3.0.0-20200121175148-a6ecf24a6d71
k8s.io/api v0.17.0
k8s.io/apimachinery v0.17.0
k8s.io/client-go v0.17.0
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a
sigs.k8s.io/kustomize/kyaml v0.9.3
github.com/imdario/mergo v0.3.5
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/kube-openapi v0.0.0-20220401212409-b28bf2818661
sigs.k8s.io/kustomize/kyaml v0.13.7
sigs.k8s.io/yaml v1.2.0
)

File diff suppressed because it is too large Load Diff

View File

@@ -20,12 +20,12 @@ func SortArrayAndComputeHash(s []string) (string, error) {
if err != nil {
return "", err
}
return Encode(Hash(string(data)))
return encode(hex256(string(data)))
}
// Copied from https://github.com/kubernetes/kubernetes
// /blob/master/pkg/kubectl/util/hash/hash.go
func Encode(hex string) (string, error) {
func encode(hex string) (string, error) {
if len(hex) < 10 {
return "", fmt.Errorf(
"input length must be at least 10")
@@ -48,23 +48,18 @@ func Encode(hex string) (string, error) {
return string(enc), nil
}
// Hash returns the hex form of the sha256 of the argument.
func Hash(data string) string {
// hex256 returns the hex form of the sha256 of the argument.
func hex256(data string) string {
return fmt.Sprintf("%x", sha256.Sum256([]byte(data)))
}
// HashRNode returns the hash value of input RNode
func HashRNode(node *yaml.RNode) (string, error) {
// get node kind
kindNode, err := node.Pipe(yaml.FieldMatcher{Name: "kind"})
if err != nil {
return "", err
}
kind := kindNode.YNode().Value
// Hasher computes the hash of an RNode.
type Hasher struct{}
// calculate hash for different kinds
encoded := ""
switch kind {
// Hash returns a hash of the argument.
func (h *Hasher) Hash(node *yaml.RNode) (r string, err error) {
var encoded string
switch node.GetKind() {
case "ConfigMap":
encoded, err = encodeConfigMap(node)
case "Secret":
@@ -77,10 +72,11 @@ func HashRNode(node *yaml.RNode) (string, error) {
if err != nil {
return "", err
}
return Encode(Hash(encoded))
return encode(hex256(encoded))
}
func getNodeValues(node *yaml.RNode, paths []string) (map[string]interface{}, error) {
func getNodeValues(
node *yaml.RNode, paths []string) (map[string]interface{}, error) {
values := make(map[string]interface{})
for _, p := range paths {
vn, err := node.Pipe(yaml.Lookup(p))
@@ -117,8 +113,11 @@ func encodeConfigMap(node *yaml.RNode) (string, error) {
if err != nil {
return "", err
}
m := map[string]interface{}{"kind": "ConfigMap", "name": values["metadata/name"],
"data": values["data"]}
m := map[string]interface{}{
"kind": "ConfigMap",
"name": values["metadata/name"],
"data": values["data"],
}
if _, ok := values["binaryData"].(map[string]interface{}); ok {
m["binaryData"] = values["binaryData"]
}

View File

@@ -32,10 +32,10 @@ func TestSortArrayAndComputeHash(t *testing.T) {
}
}
func TestHash(t *testing.T) {
func Test_hex256(t *testing.T) {
// hash the empty string to be sure that sha256 is being used
expect := "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
sum := Hash("")
sum := hex256("")
if expect != sum {
t.Errorf("expected hash %q but got %q", expect, sum)
}
@@ -56,7 +56,7 @@ kind: ConfigMap`, "6ct58987ht", ""},
{"one key", `
apiVersion: v1
kind: ConfigMap
data:
data:
one: ""`, "9g67k2htb6", ""},
// three keys (tests sorting order)
{"three keys", `
@@ -93,17 +93,17 @@ data:
binaryData:
two: ""`, "698h7c7t9m", ""},
}
h := &Hasher{}
for _, c := range cases {
node, err := yaml.Parse(c.cmYaml)
if err != nil {
t.Fatal(err)
}
h, err := HashRNode(node)
hashed, err := h.Hash(node)
if SkipRest(t, c.desc, err, c.err) {
continue
}
if c.hash != h {
if c.hash != hashed {
t.Errorf("case %q, expect hash %q but got %q", c.desc, c.hash, h)
}
}
@@ -154,35 +154,34 @@ type: my-type
data:
one: ""`, "74bd68bm66", ""},
}
h := &Hasher{}
for _, c := range cases {
node, err := yaml.Parse(c.secretYaml)
if err != nil {
t.Fatal(err)
}
h, err := HashRNode(node)
hashed, err := h.Hash(node)
if SkipRest(t, c.desc, err, c.err) {
continue
}
if c.hash != h {
if c.hash != hashed {
t.Errorf("case %q, expect hash %q but got %q", c.desc, c.hash, h)
}
}
}
func TestUnstructuredHash(t *testing.T) {
cases := []struct {
desc string
unstructured string
hash string
err string
func TestBasicHash(t *testing.T) {
cases := map[string]struct {
res string
hash string
err string
}{
{"minimal", `
"minimal": {`
apiVersion: test/v1
kind: TestResource
metadata:
name: my-resource`, "244782mkb7", ""},
{"with spec", `
"with spec": {`
apiVersion: test/v1
kind: TestResource
metadata:
@@ -191,19 +190,22 @@ spec:
foo: 1
bar: abc`, "59m2mdccg4", ""},
}
for _, c := range cases {
node, err := yaml.Parse(c.unstructured)
if err != nil {
t.Fatal(err)
}
h, err := HashRNode(node)
if SkipRest(t, c.desc, err, c.err) {
continue
}
if c.hash != h {
t.Errorf("case %q, expect hash %q but got %q", c.desc, c.hash, h)
}
h := &Hasher{}
for n := range cases {
c := cases[n]
t.Run(n, func(t *testing.T) {
node, err := yaml.Parse(c.res)
if err != nil {
t.Fatal(err)
}
hashed, err := h.Hash(node)
if SkipRest(t, n, err, c.err) {
return
}
if c.hash != hashed {
t.Errorf("case %q, expect hash %q but got %q", n, c.hash, h)
}
})
}
}
@@ -222,7 +224,7 @@ kind: ConfigMap`, `{"data":"","kind":"ConfigMap","name":""}`, ""},
{"one key", `
apiVersion: v1
kind: ConfigMap
data:
data:
one: ""`, `{"data":{"one":""},"kind":"ConfigMap","name":""}`, ""},
// three keys (tests sorting order)
{"three keys", `
@@ -334,10 +336,12 @@ data:
}
}
// SkipRest returns true if there was a non-nil error or if we expected an error that didn't happen,
// and logs the appropriate error on the test object.
// The return value indicates whether we should skip the rest of the test case due to the error result.
// SkipRest returns true if there was a non-nil error or if we expected an
// error that didn't happen, and logs the appropriate error on the test object.
// The return value indicates whether we should skip the rest of the test case
// due to the error result.
func SkipRest(t *testing.T, desc string, err error, contains string) bool {
t.Helper()
if err != nil {
if len(contains) == 0 {
t.Errorf("case %q, expect nil error but got %q", desc, err.Error())

View File

@@ -5,8 +5,8 @@
package ifc
import (
"sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/yaml"
)
// Validator provides functions to validate annotations and labels
@@ -38,84 +38,10 @@ type Loader interface {
Cleanup() error
}
// Kunstructured represents a Kubernetes Resource Model object.
type Kunstructured interface {
// Several uses.
Copy() Kunstructured
// Used by Resource.Replace, which in turn is used in many places, e.g.
// - resource.Resource.Merge
// - resWrangler.appendReplaceOrMerge (AbsorbAll)
// - api.internal.k8sdeps.transformer.patch.conflictdetector
GetAnnotations() map[string]string
// Used by ResAccumulator and ReplacementTransformer.
GetFieldValue(string) (interface{}, error)
// Used by Resource.OrgId
GetGvk() resid.Gvk
// Used by resource.Factory.SliceFromBytes
GetKind() string
// Used by Resource.Replace
GetLabels() map[string]string
// Used by Resource.CurId and resource factory.
GetName() string
// Used by special case code in
// ResMap.SubsetThatCouldBeReferencedByResource
GetSlice(path string) ([]interface{}, error)
// GetString returns the value of a string field.
// Used by Resource.GetNamespace
GetString(string) (string, error)
// Several uses.
Map() map[string]interface{}
// Used by Resource.AsYAML and Resource.String
MarshalJSON() ([]byte, error)
// Used by resWrangler.Select
MatchesAnnotationSelector(selector string) (bool, error)
// Used by resWrangler.Select
MatchesLabelSelector(selector string) (bool, error)
// Used by Resource.Replace.
SetAnnotations(map[string]string)
// Used by PatchStrategicMergeTransformer.
SetGvk(resid.Gvk)
// Used by Resource.Replace and used to remove "validated by" labels.
SetLabels(map[string]string)
// Used by Resource.Replace.
SetName(string)
// Used by Resource.Replace.
SetNamespace(string)
// Needed, for now, by kyaml/filtersutil.ApplyToJSON.
UnmarshalJSON([]byte) error
}
// KunstructuredFactory makes instances of Kunstructured.
type KunstructuredFactory interface {
SliceFromBytes([]byte) ([]Kunstructured, error)
FromMap(m map[string]interface{}) Kunstructured
Hasher() KunstructuredHasher
MakeConfigMap(kvLdr KvLoader, args *types.ConfigMapArgs) (Kunstructured, error)
MakeSecret(kvLdr KvLoader, args *types.SecretArgs) (Kunstructured, error)
}
// KunstructuredHasher returns a hash of the argument
// KustHasher returns a hash of the argument
// or an error.
type KunstructuredHasher interface {
Hash(Kunstructured) (string, error)
type KustHasher interface {
Hash(*yaml.RNode) (string, error)
}
// See core.v1.SecretTypeOpaque

View File

@@ -14,37 +14,53 @@ func IsImageMatched(s, t string) bool {
// Tag values are limited to [a-zA-Z0-9_.{}-].
// Some tools like Bazel rules_k8s allow tag patterns with {} characters.
// More info: https://github.com/bazelbuild/rules_k8s/pull/423
pattern, _ := regexp.Compile("^" + t + "(@sha256)?(:[a-zA-Z0-9_.{}-]*)?$")
pattern, _ := regexp.Compile("^" + t + "(:[a-zA-Z0-9_.{}-]*)?(@sha256:[a-zA-Z0-9_.{}-]*)?$")
return pattern.MatchString(s)
}
// Split separates and returns the name and tag parts
// from the image string using either colon `:` or at `@` separators.
// Note that the returned tag keeps its separator.
func Split(imageName string) (name string, tag string) {
// image reference pattern: [[host[:port]/]component/]component[:tag][@digest]
func Split(imageName string) (name string, tag string, digest string) {
// check if image name contains a domain
// if domain is present, ignore domain and check for `:`
ic := -1
if slashIndex := strings.Index(imageName, "/"); slashIndex < 0 {
ic = strings.LastIndex(imageName, ":")
searchName := imageName
slashIndex := strings.Index(imageName, "/")
if slashIndex > 0 {
searchName = imageName[slashIndex:]
} else {
lastIc := strings.LastIndex(imageName[slashIndex:], ":")
// set ic only if `:` is present
if lastIc > 0 {
ic = slashIndex + lastIc
}
}
ia := strings.LastIndex(imageName, "@")
if ic < 0 && ia < 0 {
return imageName, ""
slashIndex = 0
}
i := ic
if ia > 0 {
i = ia
id := strings.Index(searchName, "@")
ic := strings.Index(searchName, ":")
// no tag or digest
if ic < 0 && id < 0 {
return imageName, "", ""
}
name = imageName[:i]
tag = imageName[i:]
return
// digest only
if id >= 0 && (id < ic || ic < 0) {
id += slashIndex
name = imageName[:id]
digest = strings.TrimPrefix(imageName[id:], "@")
return name, "", digest
}
// tag and digest
if id >= 0 && ic >= 0 {
id += slashIndex
ic += slashIndex
name = imageName[:ic]
tag = strings.TrimPrefix(imageName[ic:id], ":")
digest = strings.TrimPrefix(imageName[id:], "@")
return name, tag, digest
}
// tag only
ic += slashIndex
name = imageName[:ic]
tag = strings.TrimPrefix(imageName[ic:], ":")
return name, tag, ""
}

View File

@@ -23,11 +23,23 @@ func TestIsImageMatched(t *testing.T) {
isMatched: true,
},
{
testName: "name is match",
testName: "name is match with tag",
value: "nginx:12345",
name: "nginx",
isMatched: true,
},
{
testName: "name is match with digest",
value: "nginx@sha256:xyz",
name: "nginx",
isMatched: true,
},
{
testName: "name is match with tag and digest",
value: "nginx:12345@sha256:xyz",
name: "nginx",
isMatched: true,
},
{
testName: "name is not a match",
value: "apache:12345",
@@ -49,32 +61,65 @@ func TestSplit(t *testing.T) {
value string
name string
tag string
digest string
}{
{
testName: "no tag",
value: "nginx",
name: "nginx",
tag: "",
digest: "",
},
{
testName: "with tag",
value: "nginx:1.2.3",
name: "nginx",
tag: ":1.2.3",
tag: "1.2.3",
digest: "",
},
{
testName: "with digest",
value: "nginx@12345",
value: "nginx@sha256:12345",
name: "nginx",
tag: "@12345",
tag: "",
digest: "sha256:12345",
},
{
testName: "with tag and digest",
value: "nginx:1.2.3@sha256:12345",
name: "nginx",
tag: "1.2.3",
digest: "sha256:12345",
},
{
testName: "with domain",
value: "docker.io/nginx:1.2.3",
name: "docker.io/nginx",
tag: "1.2.3",
digest: "",
},
{
testName: "with domain and port",
value: "foo.com:443/nginx:1.2.3",
name: "foo.com:443/nginx",
tag: "1.2.3",
digest: "",
},
{
testName: "with domain, port, tag and digest",
value: "foo.com:443/nginx:1.2.3@sha256:12345",
name: "foo.com:443/nginx",
tag: "1.2.3",
digest: "sha256:12345",
},
}
for _, tc := range testCases {
t.Run(tc.testName, func(t *testing.T) {
name, tag := Split(tc.value)
name, tag, digest := Split(tc.value)
assert.Equal(t, tc.name, name)
assert.Equal(t, tc.tag, tag)
assert.Equal(t, tc.digest, digest)
})
}
}

View File

@@ -1,121 +0,0 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// Package expansion provides functions find and replace $(FOO) style variables in strings.
package expansion
import (
"bytes"
"fmt"
)
const (
operator = '$'
referenceOpener = '('
referenceCloser = ')'
)
// syntaxWrap returns the input string wrapped by the expansion syntax.
func syntaxWrap(input string) string {
return string(operator) + string(referenceOpener) + input + string(referenceCloser)
}
// MappingFuncFor returns a mapping function for use with Expand that
// implements the expansion semantics defined in the expansion spec; it
// returns the input string wrapped in the expansion syntax if no mapping
// for the input is found.
func MappingFuncFor(
counts map[string]int,
context ...map[string]interface{}) func(string) interface{} {
return func(input string) interface{} {
for _, vars := range context {
val, ok := vars[input]
if ok {
counts[input]++
switch typedV := val.(type) {
case string, int64, float64, bool:
return typedV
default:
return syntaxWrap(input)
}
}
}
return syntaxWrap(input)
}
}
// Expand replaces variable references in the input string according to
// the expansion spec using the given mapping function to resolve the
// values of variables.
func Expand(input string, mapping func(string) interface{}) interface{} {
var buf bytes.Buffer
checkpoint := 0
for cursor := 0; cursor < len(input); cursor++ {
if input[cursor] == operator && cursor+1 < len(input) {
// Copy the portion of the input string since the last
// checkpoint into the buffer
buf.WriteString(input[checkpoint:cursor])
// Attempt to read the variable name as defined by the
// syntax from the input string
read, isVar, advance := tryReadVariableName(input[cursor+1:])
if isVar {
// We were able to read a variable name correctly;
// apply the mapping to the variable name and copy the
// bytes into the buffer
mapped := mapping(read)
if input == syntaxWrap(read) {
// Preserve the type of variable
return mapped
}
// Variable is used in a middle of a string
buf.WriteString(fmt.Sprintf("%v", mapped))
} else {
// Not a variable name; copy the read bytes into the buffer
buf.WriteString(read)
}
// Advance the cursor in the input string to account for
// bytes consumed to read the variable name expression
cursor += advance
// Advance the checkpoint in the input string
checkpoint = cursor + 1
}
}
// Return the buffer and any remaining unwritten bytes in the
// input string.
return buf.String() + input[checkpoint:]
}
// tryReadVariableName attempts to read a variable name from the input
// string and returns the content read from the input, whether that content
// represents a variable name to perform mapping on, and the number of bytes
// consumed in the input string.
//
// The input string is assumed not to contain the initial operator.
func tryReadVariableName(input string) (string, bool, int) {
switch input[0] {
case operator:
// Escaped operator; return it.
return input[0:1], false, 1
case referenceOpener:
// Scan to expression closer
for i := 1; i < len(input); i++ {
if input[i] == referenceCloser {
return input[1:i], true, i + 1
}
}
// Incomplete reference; return it.
return string(operator) + string(referenceOpener), false, 1
default:
// Not the beginning of an expression, ie, an operator
// that doesn't begin an expression. Return the operator
// and the first rune in the string.
return string(operator) + string(input[0]), false, 1
}
}

View File

@@ -7,19 +7,26 @@ import (
"encoding/json"
"strings"
"github.com/go-openapi/spec"
"github.com/pkg/errors"
"k8s.io/kube-openapi/pkg/common"
"sigs.k8s.io/kustomize/api/filesys"
"k8s.io/kube-openapi/pkg/validation/spec"
"sigs.k8s.io/kustomize/api/ifc"
"sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
"sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/filesys"
"sigs.k8s.io/kustomize/kyaml/resid"
"sigs.k8s.io/yaml"
)
type myProperties map[string]spec.Schema
type nameToApiMap map[string]common.OpenAPIDefinition
// OpenAPIDefinition describes single type.
// Normally these definitions are auto-generated using gen-openapi.
// Same as in k8s.io / kube-openapi / pkg / common.
type OpenAPIDefinition struct {
Schema spec.Schema
Dependencies []string
}
type myProperties = map[string]spec.Schema
type nameToApiMap map[string]OpenAPIDefinition
// LoadConfigFromCRDs parse CRD schemas from paths into a TransformerConfig
func LoadConfigFromCRDs(
@@ -162,7 +169,7 @@ func loadCrdIntoConfig(
err = theConfig.AddNamereferenceFieldSpec(
builtinconfig.NameBackReferences{
Gvk: resid.Gvk{Kind: kind, Version: version},
FieldSpecs: []types.FieldSpec{
Referrers: []types.FieldSpec{
makeFs(theGvk, append(path, propName, nameKey))},
})
if err != nil {
@@ -171,9 +178,12 @@ func loadCrdIntoConfig(
}
}
if property.Ref.GetURL() != nil {
loadCrdIntoConfig(
err = loadCrdIntoConfig(
theConfig, theGvk, theMap,
property.Ref.String(), append(path, propName))
if err != nil {
return
}
}
}
return nil

View File

@@ -7,13 +7,13 @@ import (
"reflect"
"testing"
"sigs.k8s.io/kustomize/api/filesys"
"sigs.k8s.io/kustomize/api/loader"
"github.com/stretchr/testify/require"
. "sigs.k8s.io/kustomize/api/internal/accumulator"
"sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
"sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/api/loader"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/filesys"
"sigs.k8s.io/kustomize/kyaml/resid"
)
// This defines two CRD's: Bee and MyKind.
@@ -140,21 +140,19 @@ func TestLoadCRDs(t *testing.T) {
nbrs := []builtinconfig.NameBackReferences{
{
Gvk: resid.Gvk{Kind: "Secret", Version: "v1"},
FieldSpecs: []types.FieldSpec{
Referrers: []types.FieldSpec{
{
CreateIfNotPresent: false,
Gvk: resid.Gvk{Kind: "MyKind"},
Path: "spec/secretRef/name",
Gvk: resid.Gvk{Kind: "MyKind"},
Path: "spec/secretRef/name",
},
},
},
{
Gvk: resid.Gvk{Kind: "Bee", Version: "v1beta1"},
FieldSpecs: []types.FieldSpec{
Referrers: []types.FieldSpec{
{
CreateIfNotPresent: false,
Gvk: resid.Gvk{Kind: "MyKind"},
Path: "spec/beeRef/name",
Gvk: resid.Gvk{Kind: "MyKind"},
Path: "spec/beeRef/name",
},
},
},
@@ -165,16 +163,13 @@ func TestLoadCRDs(t *testing.T) {
}
fSys := filesys.MakeFsInMemory()
fSys.WriteFile("/testpath/crd.json", []byte(crdContent))
err := fSys.WriteFile("/testpath/crd.json", []byte(crdContent))
require.NoError(t, err)
ldr, err := loader.NewLoader(loader.RestrictionRootOnly, "/testpath", fSys)
if err != nil {
t.Fatalf("unexpected error:%v", err)
}
require.NoError(t, err)
actualTc, err := LoadConfigFromCRDs(ldr, []string{"crd.json"})
if err != nil {
t.Fatalf("unexpected error:%v", err)
}
require.NoError(t, err)
if !reflect.DeepEqual(actualTc, expectedTc) {
t.Fatalf("expected\n %v\n but got\n %v\n", expectedTc, actualTc)
}

View File

@@ -4,23 +4,30 @@
package accumulator
import (
"fmt"
"log"
"sigs.k8s.io/kustomize/api/filters/nameref"
"sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/kyaml/filtersutil"
"sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/kyaml/resid"
)
type nameReferenceTransformer struct {
backRefs []builtinconfig.NameBackReferences
}
const doDebug = false
var _ resmap.Transformer = &nameReferenceTransformer{}
type filterMap map[*resource.Resource][]nameref.Filter
// newNameReferenceTransformer constructs a nameReferenceTransformer
// with a given slice of NameBackReferences.
func newNameReferenceTransformer(br []builtinconfig.NameBackReferences) resmap.Transformer {
func newNameReferenceTransformer(
br []builtinconfig.NameBackReferences) resmap.Transformer {
if br == nil {
log.Fatal("backrefs not expected to be nil")
}
@@ -33,13 +40,64 @@ func newNameReferenceTransformer(br []builtinconfig.NameBackReferences) resmap.T
//
// For example, a HorizontalPodAutoscaler (HPA)
// necessarily refers to a Deployment, the thing that
// the HPA scales. The Deployment name might change
// (e.g. prefix added), and the reference in the HPA
// has to be fixed.
// an HPA scales. In this case:
//
// In the outer loop over the ResMap below, say we
// encounter a specific HPA. Then, in scanning backrefs,
// we encounter an entry like
// - the HPA instance is the Referrer,
// - the Deployment instance is the ReferralTarget.
//
// If the Deployment's name changes, e.g. a prefix is added,
// then the HPA's reference to the Deployment must be fixed.
//
func (t *nameReferenceTransformer) Transform(m resmap.ResMap) error {
fMap := t.determineFilters(m.Resources())
debug(fMap)
for r, fList := range fMap {
c, err := m.SubsetThatCouldBeReferencedByResource(r)
if err != nil {
return err
}
for _, f := range fList {
f.Referrer = r
f.ReferralCandidates = c
if err := f.Referrer.ApplyFilter(f); err != nil {
return err
}
}
}
return nil
}
func debug(fMap filterMap) {
if !doDebug {
return
}
fmt.Printf("filterMap has %d entries:\n", len(fMap))
rCount := 0
for r, fList := range fMap {
yml, _ := r.AsYAML()
rCount++
fmt.Printf(`
---- %3d. possible referrer -------------
%s
---------`, rCount, string(yml),
)
for i, f := range fList {
fmt.Printf(`
%3d/%3d update: %s
from: %s
`, rCount, i+1, f.NameFieldToUpdate.Path, f.ReferralTarget,
)
}
}
}
// Produce a map from referrer resources that might need to be fixed
// to filters that might fix them. The keys to this map are potential
// referrers, so won't include resources like ConfigMap or Secret.
//
// In the inner loop over the resources below, say we
// encounter an HPA instance. Then, in scanning the set
// of all known backrefs, we encounter an entry like
//
// - kind: Deployment
// fieldSpecs:
@@ -48,54 +106,59 @@ func newNameReferenceTransformer(br []builtinconfig.NameBackReferences) resmap.T
//
// This entry says that an HPA, via its
// 'spec/scaleTargetRef/name' field, may refer to a
// Deployment. This match to HPA means we may need to
// modify the value in its 'spec/scaleTargetRef/name'
// field, by searching for the thing it refers to,
// and getting its new name.
// Deployment.
//
// As a filter, and search optimization, we compute a
// subset of all resources that the HPA could refer to,
// by excluding objects from other namespaces, and
// excluding objects that don't have the same prefix-
// suffix mods as the HPA.
//
// We look in this subset for all Deployment objects
// with a resId that has a Name matching the field value
// present in the HPA. If no match do nothing; if more
// than one match, it's an error.
//
// We overwrite the HPA name field with the value found
// in the Deployment's name field (the name in the raw
// object - the modified name - not the unmodified name
// in the Deployment's resId).
//
// This process assumes that the name stored in a ResId
// (the ResMap key) isn't modified by name transformers.
// Name transformers should only modify the name in the
// body of the resource object (the value in the ResMap).
//
func (o *nameReferenceTransformer) Transform(m resmap.ResMap) error {
// TODO: Too much looping, here and in transitive calls.
for _, referrer := range m.Resources() {
var candidates resmap.ResMap
for _, target := range o.backRefs {
for _, fSpec := range target.FieldSpecs {
if referrer.OrgId().IsSelected(&fSpec.Gvk) {
if candidates == nil {
candidates = m.SubsetThatCouldBeReferencedByResource(referrer)
}
err := filtersutil.ApplyToJSON(nameref.Filter{
FieldSpec: fSpec,
Referrer: referrer,
Target: target.Gvk,
ReferralCandidates: candidates,
}, referrer)
if err != nil {
return err
// This means that a filter will need to hunt for the right Deployment,
// obtain it's new name, and write that name into the HPA's
// 'spec/scaleTargetRef/name' field. Return a filter that can do that.
func (t *nameReferenceTransformer) determineFilters(
resources []*resource.Resource) (fMap filterMap) {
// We cache the resource OrgId values because they don't change and otherwise are very visible in a memory pprof
resourceOrgIds := make([]resid.ResId, len(resources))
for i, resource := range resources {
resourceOrgIds[i] = resource.OrgId()
}
fMap = make(filterMap)
for _, backReference := range t.backRefs {
for _, referrerSpec := range backReference.Referrers {
for i, res := range resources {
if resourceOrgIds[i].IsSelected(&referrerSpec.Gvk) {
// If this is true, the res might be a referrer, and if
// so, the name reference it holds might need an update.
if resHasField(res, referrerSpec.Path) {
// Optimization - the referrer has the field
// that might need updating.
fMap[res] = append(fMap[res], nameref.Filter{
// Name field to write in the Referrer.
// If the path specified here isn't found in
// the Referrer, nothing happens (no error,
// no field creation).
NameFieldToUpdate: referrerSpec,
// Specification of object class to read from.
// Always read from metadata/name field.
ReferralTarget: backReference.Gvk,
})
}
}
}
}
}
return nil
return fMap
}
// TODO: check res for field existence here to avoid extra work.
// res.GetFieldValue, which uses yaml.Lookup under the hood, doesn't know
// how to parse fieldspec-style paths that make no distinction
// between maps and sequences. This means it cannot lookup commonly
// used "indeterminate" paths like
// spec/containers/env/valueFrom/configMapKeyRef/name
// ('containers' is a list, not a map).
// However, the fieldspec filter does know how to handle this;
// extract that code and call it here?
func resHasField(res *resource.Resource, path string) bool {
return true
// fld := strings.Join(utils.PathSplitter(path), ".")
// _, e := res.GetFieldValue(fld)
// return e == nil
}

View File

@@ -8,17 +8,16 @@ import (
"testing"
"sigs.k8s.io/kustomize/api/internal/plugins/builtinconfig"
"sigs.k8s.io/kustomize/api/k8sdeps/kunstruct"
"sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/api/provider"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/resource"
resmaptest_test "sigs.k8s.io/kustomize/api/testutils/resmaptest"
"sigs.k8s.io/kustomize/kyaml/resid"
)
const notEqualErrFmt = "expected (self) doesn't match actual (other): %v"
func TestNameReferenceHappyRun(t *testing.T) {
rf := resource.NewFactory(
kunstruct.NewKunstructuredFactoryImpl())
m := resmaptest_test.NewRmBuilder(t, rf).AddWithName(
m := resmaptest_test.NewRmBuilderDefault(t).AddWithName(
"cm1",
map[string]interface{}{
"apiVersion": "v1",
@@ -220,6 +219,7 @@ func TestNameReferenceHappyRun(t *testing.T) {
"secret1",
"secret1",
"secret2",
"cm1",
},
},
},
@@ -261,7 +261,8 @@ func TestNameReferenceHappyRun(t *testing.T) {
},
}).ResMap()
expected := resmaptest_test.NewSeededRmBuilder(t, rf, m.ShallowCopy()).ReplaceResource(
expected := resmaptest_test.NewSeededRmBuilderDefault(
t, m.ShallowCopy()).ReplaceResource(
map[string]interface{}{
"group": "apps",
"apiVersion": "v1",
@@ -422,6 +423,7 @@ func TestNameReferenceHappyRun(t *testing.T) {
"someprefix-secret1-somehash",
"someprefix-secret1-somehash",
"secret2",
"someprefix-cm1-somehash",
},
},
},
@@ -470,19 +472,17 @@ func TestNameReferenceHappyRun(t *testing.T) {
}
if err = expected.ErrorIfNotEqualLists(m); err != nil {
t.Fatalf("actual doesn't match expected: %v", err)
t.Fatalf(notEqualErrFmt, err)
}
}
func TestNameReferenceUnhappyRun(t *testing.T) {
rf := resource.NewFactory(
kunstruct.NewKunstructuredFactoryImpl())
tests := []struct {
resMap resmap.ResMap
expectedErr string
}{
{
resMap: resmaptest_test.NewRmBuilder(t, rf).Add(
resMap: resmaptest_test.NewRmBuilderDefault(t).Add(
map[string]interface{}{
"apiVersion": "rbac.authorization.k8s.io/v1",
"kind": "ClusterRole",
@@ -502,7 +502,7 @@ func TestNameReferenceUnhappyRun(t *testing.T) {
}).ResMap(),
expectedErr: "is expected to be"},
{
resMap: resmaptest_test.NewRmBuilder(t, rf).Add(
resMap: resmaptest_test.NewRmBuilderDefault(t).Add(
map[string]interface{}{
"apiVersion": "rbac.authorization.k8s.io/v1",
"kind": "ClusterRole",
@@ -520,7 +520,10 @@ func TestNameReferenceUnhappyRun(t *testing.T) {
},
},
}).ResMap(),
expectedErr: "cannot find field 'name' in node"},
expectedErr: `updating name reference in 'rules/resourceNames' field of 'ClusterRole.v1.rbac.authorization.k8s.io/cr.[noNs]': ` +
`considering field 'rules/resourceNames' of object ClusterRole.v1.rbac.authorization.k8s.io/cr.[noNs]: visit traversal on ` +
`path: [resourceNames]: path config error; no 'name' field in node`,
},
}
nrt := newNameReferenceTransformer(builtinconfig.MakeDefaultConfig().NameReference)
@@ -531,15 +534,14 @@ func TestNameReferenceUnhappyRun(t *testing.T) {
}
if !strings.Contains(err.Error(), test.expectedErr) {
t.Fatalf("Incorrect error.\nExpected: %s, but got %v",
t.Fatalf("Incorrect error.\nExpected:\n %s\nGot:\n%v",
test.expectedErr, err)
}
}
}
func TestNameReferencePersistentVolumeHappyRun(t *testing.T) {
rf := resource.NewFactory(
kunstruct.NewKunstructuredFactoryImpl())
rf := provider.NewDefaultDepProvider().GetResourceFactory()
v1 := rf.FromMapWithName(
"volume1",
@@ -590,7 +592,7 @@ func TestNameReferencePersistentVolumeHappyRun(t *testing.T) {
v2.AppendRefBy(c2.CurId())
if err := m1.ErrorIfNotEqualLists(m2); err != nil {
t.Fatalf("actual doesn't match expected: %v", err)
t.Fatalf(notEqualErrFmt, err)
}
}
@@ -664,9 +666,7 @@ const (
// object with the same original names (uniquename) in different namespaces
// and with different current Id.
func TestNameReferenceNamespace(t *testing.T) {
rf := resource.NewFactory(
kunstruct.NewKunstructuredFactoryImpl())
m := resmaptest_test.NewRmBuilder(t, rf).
m := resmaptest_test.NewRmBuilderDefault(t).
// Add ConfigMap with the same org name in noNs, "ns1" and "ns2" namespaces
AddWithName(orgname, map[string]interface{}{
"apiVersion": "v1",
@@ -715,7 +715,7 @@ func TestNameReferenceNamespace(t *testing.T) {
AddWithNsAndName(ns1, orgname, deploymentMap(ns1, prefixedname, orgname, orgname)).
AddWithNsAndName(ns2, orgname, deploymentMap(ns2, suffixedname, orgname, orgname)).ResMap()
expected := resmaptest_test.NewSeededRmBuilder(t, rf, m.ShallowCopy()).
expected := resmaptest_test.NewSeededRmBuilderDefault(t, m.ShallowCopy()).
ReplaceResource(deploymentMap(defaultNs, modifiedname, modifiedname, modifiedname)).
ReplaceResource(deploymentMap(ns1, prefixedname, prefixedname, prefixedname)).
ReplaceResource(deploymentMap(ns2, suffixedname, suffixedname, suffixedname)).ResMap()
@@ -726,8 +726,9 @@ func TestNameReferenceNamespace(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
m.RemoveBuildAnnotations()
if err = expected.ErrorIfNotEqualLists(m); err != nil {
t.Fatalf("actual doesn't match expected: %v", err)
t.Fatalf(notEqualErrFmt, err)
}
}
@@ -735,9 +736,7 @@ func TestNameReferenceNamespace(t *testing.T) {
// object with the same original names (uniquename) in different namespaces
// and with different current Id.
func TestNameReferenceClusterWide(t *testing.T) {
rf := resource.NewFactory(
kunstruct.NewKunstructuredFactoryImpl())
m := resmaptest_test.NewRmBuilder(t, rf).
m := resmaptest_test.NewRmBuilderDefault(t).
// Add ServiceAccount with the same org name in noNs, "ns1" and "ns2" namespaces
AddWithName(orgname, map[string]interface{}{
"apiVersion": "v1",
@@ -816,7 +815,7 @@ func TestNameReferenceClusterWide(t *testing.T) {
},
}}).ResMap()
expected := resmaptest_test.NewSeededRmBuilder(t, rf, m.ShallowCopy()).
expected := resmaptest_test.NewSeededRmBuilderDefault(t, m.ShallowCopy()).
ReplaceResource(
map[string]interface{}{
"apiVersion": "rbac.authorization.k8s.io/v1",
@@ -877,9 +876,9 @@ func TestNameReferenceClusterWide(t *testing.T) {
}).ResMap()
clusterRoleId := resid.NewResId(
resid.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRole"}, modifiedname)
resid.NewGvk("rbac.authorization.k8s.io", "v1", "ClusterRole"), modifiedname)
clusterRoleBindingId := resid.NewResId(
resid.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBinding"}, modifiedname)
resid.NewGvk("rbac.authorization.k8s.io", "v1", "ClusterRoleBinding"), modifiedname)
clusterRole, _ := expected.GetByCurrentId(clusterRoleId)
clusterRole.AppendRefBy(clusterRoleBindingId)
@@ -889,8 +888,11 @@ func TestNameReferenceClusterWide(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
expected.RemoveBuildAnnotations()
m.RemoveBuildAnnotations()
if err = expected.ErrorIfNotEqualLists(m); err != nil {
t.Fatalf("actual doesn't match expected: %v", err)
t.Fatalf(notEqualErrFmt, err)
}
}
@@ -898,9 +900,7 @@ func TestNameReferenceClusterWide(t *testing.T) {
// object with the same original names (uniquename) in different namespaces
// and with different current Id.
func TestNameReferenceNamespaceTransformation(t *testing.T) {
rf := resource.NewFactory(
kunstruct.NewKunstructuredFactoryImpl())
m := resmaptest_test.NewRmBuilder(t, rf).
m := resmaptest_test.NewRmBuilderDefault(t).
AddWithNsAndName(ns4, orgname, map[string]interface{}{
"apiVersion": "v1",
"kind": "Secret",
@@ -964,7 +964,7 @@ func TestNameReferenceNamespaceTransformation(t *testing.T) {
},
}}).ResMap()
expected := resmaptest_test.NewSeededRmBuilder(t, rf, m.ShallowCopy()).
expected := resmaptest_test.NewSeededRmBuilderDefault(t, m.ShallowCopy()).
ReplaceResource(
map[string]interface{}{
"apiVersion": "rbac.authorization.k8s.io/v1",
@@ -1005,9 +1005,11 @@ func TestNameReferenceNamespaceTransformation(t *testing.T) {
}).ResMap()
clusterRoleId := resid.NewResId(
resid.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRole"}, modifiedname)
resid.NewGvk("rbac.authorization.k8s.io", "v1", "ClusterRole"),
modifiedname)
clusterRoleBindingId := resid.NewResId(
resid.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBinding"}, modifiedname)
resid.NewGvk("rbac.authorization.k8s.io", "v1", "ClusterRoleBinding"),
modifiedname)
clusterRole, _ := expected.GetByCurrentId(clusterRoleId)
clusterRole.AppendRefBy(clusterRoleBindingId)
@@ -1017,8 +1019,9 @@ func TestNameReferenceNamespaceTransformation(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
m.RemoveBuildAnnotations()
if err = expected.ErrorIfNotEqualLists(m); err != nil {
t.Fatalf("actual doesn't match expected: %v", err)
t.Fatalf(notEqualErrFmt, err)
}
}
@@ -1026,9 +1029,7 @@ func TestNameReferenceNamespaceTransformation(t *testing.T) {
// It validates the change done is IsSameFuzzyNamespace which
// uses the IsNsEquals method instead of the simple == operator.
func TestNameReferenceCandidateSelection(t *testing.T) {
rf := resource.NewFactory(
kunstruct.NewKunstructuredFactoryImpl())
m := resmaptest_test.NewRmBuilder(t, rf).
m := resmaptest_test.NewRmBuilderDefault(t).
AddWithName("cm1", map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
@@ -1045,7 +1046,7 @@ func TestNameReferenceCandidateSelection(t *testing.T) {
AddWithName("deploy1", deploymentMap("", "p1-deploy1", "cm1", "secret1")).
ResMap()
expected := resmaptest_test.NewSeededRmBuilder(t, rf, m.ShallowCopy()).
expected := resmaptest_test.NewSeededRmBuilderDefault(t, m.ShallowCopy()).
ReplaceResource(deploymentMap("", "p1-deploy1", "p1-cm1-hash", "p1-secret1-hash")).
ResMap()
@@ -1055,7 +1056,8 @@ func TestNameReferenceCandidateSelection(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
m.RemoveBuildAnnotations()
if err = expected.ErrorIfNotEqualLists(m); err != nil {
t.Fatalf("actual doesn't match expected: %v", err)
t.Fatalf(notEqualErrFmt, err)
}
}

View File

@@ -4,19 +4,15 @@
package accumulator
import (
expansion2 "sigs.k8s.io/kustomize/api/internal/accumulator/expansion"
"sigs.k8s.io/kustomize/api/filters/refvar"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/filtersutil"
)
type refVarTransformer struct {
varMap map[string]interface{}
replacementCounts map[string]int
fieldSpecs []types.FieldSpec
mappingFunc func(string) interface{}
}
// newRefVarTransformer returns a new refVarTransformer
@@ -35,8 +31,7 @@ func newRefVarTransformer(
func (rv *refVarTransformer) UnusedVars() []string {
var unused []string
for k := range rv.varMap {
_, ok := rv.replacementCounts[k]
if !ok {
if _, ok := rv.replacementCounts[k]; !ok {
unused = append(unused, k)
}
}
@@ -46,14 +41,13 @@ func (rv *refVarTransformer) UnusedVars() []string {
// Transform replaces $(VAR) style variables with values.
func (rv *refVarTransformer) Transform(m resmap.ResMap) error {
rv.replacementCounts = make(map[string]int)
rv.mappingFunc = expansion2.MappingFuncFor(
rv.replacementCounts, rv.varMap)
mf := refvar.MakePrimitiveReplacer(rv.replacementCounts, rv.varMap)
for _, res := range m.Resources() {
for _, fieldSpec := range rv.fieldSpecs {
err := filtersutil.ApplyToJSON(refvar.Filter{
MappingFunc: rv.mappingFunc,
err := res.ApplyFilter(refvar.Filter{
MappingFunc: mf,
FieldSpec: fieldSpec,
}, res)
})
if err != nil {
return err
}

View File

@@ -7,12 +7,10 @@ import (
"reflect"
"testing"
"sigs.k8s.io/kustomize/api/k8sdeps/kunstruct"
"sigs.k8s.io/kustomize/api/resid"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/resource"
resmaptest_test "sigs.k8s.io/kustomize/api/testutils/resmaptest"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kyaml/resid"
)
func TestRefVarTransformer(t *testing.T) {
@@ -25,14 +23,12 @@ func TestRefVarTransformer(t *testing.T) {
res resmap.ResMap
unused []string
}
testCases := []struct {
description string
given given
expected expected
errMessage string
testCases := map[string]struct {
given given
expected expected
errMessage string
}{
{
description: "var replacement in map[string]",
"var replacement in map[string]": {
given: given{
varMap: map[string]interface{}{
"FOO": "replacementForFoo",
@@ -46,8 +42,7 @@ func TestRefVarTransformer(t *testing.T) {
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/interface"},
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/num"},
},
res: resmaptest_test.NewRmBuilder(
t, resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())).
res: resmaptest_test.NewRmBuilderDefault(t).
Add(map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
@@ -77,8 +72,7 @@ func TestRefVarTransformer(t *testing.T) {
}}).ResMap(),
},
expected: expected{
res: resmaptest_test.NewRmBuilder(
t, resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())).
res: resmaptest_test.NewRmBuilderDefault(t).
Add(map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
@@ -109,15 +103,13 @@ func TestRefVarTransformer(t *testing.T) {
unused: []string{"BAR"},
},
},
{
description: "var replacement panic in map[string]",
"var replacement panic in map[string]": {
given: given{
varMap: map[string]interface{}{},
fs: []types.FieldSpec{
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/slice"},
},
res: resmaptest_test.NewRmBuilder(
t, resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())).
res: resmaptest_test.NewRmBuilderDefault(t).
Add(map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
@@ -128,18 +120,15 @@ func TestRefVarTransformer(t *testing.T) {
"slice": []interface{}{5}, // noticeably *not* a []string
}}).ResMap(),
},
errMessage: `obj '{"apiVersion": "v1", "data": {"slice": [5]}, "kind": "ConfigMap", "metadata": {"name": "cm1"}}
' at path 'data/slice': invalid value type expect a string`,
errMessage: `considering field 'data/slice' of object ConfigMap.v1.[noGrp]/cm1.[noNs]: invalid value type expect a string`,
},
{
description: "var replacement in nil",
"var replacement in nil": {
given: given{
varMap: map[string]interface{}{},
fs: []types.FieldSpec{
{Gvk: resid.Gvk{Version: "v1", Kind: "ConfigMap"}, Path: "data/nil"},
},
res: resmaptest_test.NewRmBuilder(
t, resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())).
res: resmaptest_test.NewRmBuilderDefault(t).
Add(map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
@@ -151,8 +140,7 @@ func TestRefVarTransformer(t *testing.T) {
}}).ResMap(),
},
expected: expected{
res: resmaptest_test.NewRmBuilder(
t, resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())).
res: resmaptest_test.NewRmBuilderDefault(t).
Add(map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMap",
@@ -166,20 +154,18 @@ func TestRefVarTransformer(t *testing.T) {
},
}
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
// arrange
for tn, tc := range testCases {
t.Run(tn, func(t *testing.T) {
tr := newRefVarTransformer(tc.given.varMap, tc.given.fs)
// act
err := tr.Transform(tc.given.res)
// assert
if tc.errMessage != "" {
if err == nil {
t.Fatalf("missing expected error %v", tc.errMessage)
} else if err.Error() != tc.errMessage {
t.Fatalf("actual error doesn't match expected error: \nACTUAL: %v\nEXPECTED: %v", err.Error(), tc.errMessage)
t.Fatalf(`actual error doesn't match expected error:
ACTUAL: %v
EXPECTED: %v`,
err.Error(), tc.errMessage)
}
} else {
if err != nil {
@@ -189,7 +175,13 @@ func TestRefVarTransformer(t *testing.T) {
a, e := tc.given.res, tc.expected.res
if !reflect.DeepEqual(a, e) {
err = e.ErrorIfNotEqualLists(a)
t.Fatalf("actual doesn't match expected: \nACTUAL:\n%v\nEXPECTED:\n%v\nERR: %v", a, e, err)
t.Fatalf(`actual doesn't match expected:
ACTUAL:
%v
EXPECTED:
%v
ERR: %v`,
a, e, err)
}
}
})

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