Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix merge tag #1

Open
wants to merge 82 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
a23d598
WIP
RafaeLeal Jan 10, 2022
b2cdf1d
Fix merge corner cases
RafaeLeal Jan 11, 2022
3b5403a
Merge remote-tracking branch 'origin/master' into fix-merge-tag
RafaeLeal Jan 11, 2022
fa352cb
Add test for explicit !!merge tag
RafaeLeal Jan 11, 2022
7895a86
Fix tests
RafaeLeal Jan 11, 2022
2c80158
Cleanup
RafaeLeal Jan 11, 2022
5d6137a
Cleanup
RafaeLeal Jan 11, 2022
5c24ab3
Fix deanchoring lists
RafaeLeal Jan 11, 2022
20363a2
Add test case for keeping comments
RafaeLeal Jan 11, 2022
b063645
Revert "[fix] configMapGenerator: extra space in end of line gives "\…
natasha41575 Jan 12, 2022
6e82b21
Merge pull request #4385 from kubernetes-sigs/revert-4329-configMapIssue
k8s-ci-robot Jan 12, 2022
b73dfe7
Remove exclude statements
Neo2308 Jan 14, 2022
cec9298
Update owners file to reflect active contributors
KnVerey Jan 19, 2022
2554d69
deprecate enable-managedby-label flag in favor of a field
natasha41575 Jan 10, 2022
6e5d267
Merge pull request #4377 from natasha41575/managedBy
k8s-ci-robot Jan 20, 2022
2c23b96
set transformer annotation when the option is specified
natasha41575 Jan 7, 2022
9577d61
move origin to be an attribute of KustTarget
natasha41575 Jan 20, 2022
d711b27
Merge pull request #4373 from natasha41575/TransformerAnnotationsFull
k8s-ci-robot Jan 20, 2022
02cf540
Add MapEntrySetter and fix json marshalling after deanchoring
RafaeLeal Jan 20, 2022
e570dae
Keep duplicated keys
RafaeLeal Jan 20, 2022
7af5ce5
fix deprecated command on run-fns help docs
koba1t Jan 20, 2022
69e5228
Merge pull request #4411 from koba1t/fix_run-fns_command_help_message…
k8s-ci-robot Jan 21, 2022
3687250
Add TrackableFilter interface (#4410)
sdowell Jan 24, 2022
bf97d23
refactor: use SetScalar in imagetag filter
sdowell Jan 13, 2022
302cc86
implement TrackableFilter interface with imagetag
sdowell Jan 24, 2022
816e236
Add benchmark test for parsing openapi in protobuf format
Jan 19, 2022
c754ead
Merge pull request #4396 from mengqiy/oabench
k8s-ci-robot Jan 25, 2022
c65ef48
Merge pull request #4418 from sdowell/imagetag-trackable-filter
k8s-ci-robot Jan 25, 2022
9abf5fc
fix: set FieldPath for SequenceNode elements
sdowell Jan 26, 2022
bcebad1
new command `kustomize edit add buildmetadata` (#4413)
natasha41575 Jan 26, 2022
d62cc6d
Merge pull request #4426 from KnVerey/update-maintainers
k8s-ci-robot Jan 27, 2022
a5b6101
Merge pull request #4425 from sdowell/fieldspec-sequencenode-fieldpath
k8s-ci-robot Jan 27, 2022
e316037
test: add testutil for mutation tracker
sdowell Jan 28, 2022
51b767b
feat: implement TrackableFilter for namespace
sdowell Jan 28, 2022
90493ec
feat: implement TrackableFilter for prefix
sdowell Jan 28, 2022
851b3fc
feat: implement TrackableFilter for replicacount
sdowell Jan 28, 2022
ba55d95
feat: implement TrackableFilter for suffix
sdowell Jan 28, 2022
cfd9278
Merge pull request #4431 from sdowell/implement-trackable-filters
k8s-ci-robot Feb 1, 2022
f5b2b75
fix test-unit-kustomize-api
natasha41575 Feb 1, 2022
f0c0d93
Merge pull request #4437 from natasha41575/fixMake
k8s-ci-robot Feb 1, 2022
91ff4ee
Pin to kyaml v0.13.2
natasha41575 Feb 1, 2022
3c1e695
Update year in all the addlicense targets
KnVerey Feb 1, 2022
98fce99
Commit missing go.sum updates
KnVerey Feb 1, 2022
2b3d9dd
Merge pull request #4438 from natasha41575/pinToKyaml
natasha41575 Feb 1, 2022
7bc5115
Add missing header
KnVerey Feb 1, 2022
fb76868
Merge pull request #4439 from KnVerey/update-year
natasha41575 Feb 1, 2022
939545a
Pin to cmd/config v0.10.3
natasha41575 Feb 1, 2022
d46bb0a
Merge pull request #4440 from natasha41575/pinToCmdConfig
natasha41575 Feb 1, 2022
f38648d
Pin to api v0.11.0
natasha41575 Feb 2, 2022
6759176
Merge pull request #4441 from natasha41575/pinToApi
natasha41575 Feb 2, 2022
78e8d43
Back to development mode; unpin the modules
natasha41575 Feb 2, 2022
836a721
Test examples against latest release
natasha41575 Feb 2, 2022
39349c4
Merge pull request #4442 from natasha41575/unpinEverything
natasha41575 Feb 2, 2022
01d7fae
Merge pull request #4443 from natasha41575/updateProwExamplesTarget
natasha41575 Feb 2, 2022
a86723c
Fix regression 4388
KnVerey Feb 2, 2022
fcfd30c
Merge pull request #4445 from KnVerey/ordering_regression_4388
k8s-ci-robot Feb 2, 2022
32e13bd
Pin to kyaml v0.13.3
natasha41575 Feb 2, 2022
6a7caf4
Update release instructions to check for blockers
KnVerey Feb 2, 2022
28b3e9f
Merge pull request #4446 from natasha41575/pinToKyaml
natasha41575 Feb 2, 2022
2f9617f
Pin to cmd/config v0.10.4
natasha41575 Feb 2, 2022
3006846
Merge pull request #4448 from natasha41575/pinToCmdConfig
natasha41575 Feb 2, 2022
30612cf
Merge pull request #4447 from KnVerey/update_release_instr
k8s-ci-robot Feb 2, 2022
d776304
Pin to api v0.11.1
natasha41575 Feb 2, 2022
746bd18
Merge pull request #4449 from natasha41575/pinToApi
natasha41575 Feb 2, 2022
3277ff9
Test examples against latest release
natasha41575 Feb 2, 2022
c3c7013
Merge pull request #4450 from natasha41575/updateProwExamplesTarget
natasha41575 Feb 2, 2022
6374d3d
Commit 2022 roadmap presented to SIG-CLI
KnVerey Feb 4, 2022
a5df6f7
Merge pull request #4387 from Neo2308/remove-exclude-statements
k8s-ci-robot Feb 7, 2022
14cb815
Merge pull request #4452 from KnVerey/2022-roadmap
k8s-ci-robot Feb 8, 2022
e91608b
Merge remote-tracking branch 'origin/master' into fix-merge-tag
RafaeLeal Feb 8, 2022
a5b526f
Move MergeTag definition to yaml alias
RafaeLeal Feb 8, 2022
a5720df
Remove go-spew from api
RafaeLeal Feb 8, 2022
e7b8c35
Add support for sequence nodes on merge tags
RafaeLeal Feb 8, 2022
3d55196
Add docstring to MapEntrySetter.Key
RafaeLeal Feb 8, 2022
a5750a6
Add docstring to MapEntrySetter struct
RafaeLeal Feb 24, 2022
60a4e82
Add tests to MapEntrySetter
RafaeLeal Feb 25, 2022
a9c4541
Fix duplicate merge key
RafaeLeal Mar 3, 2022
66f89d4
Revert whitespace changes on forked go-yaml
RafaeLeal Mar 3, 2022
44cd517
Remove AssocMapEntry function
RafaeLeal Mar 3, 2022
714a233
Refactoring merge order
RafaeLeal Mar 3, 2022
f760419
Return errors on VisitFields and PipeE
RafaeLeal Mar 23, 2022
78ae5c1
Add tests for each non-conforming map merges
RafaeLeal Mar 23, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ MYGOBIN = $(shell go env GOPATH)/bin
endif
export PATH := $(MYGOBIN):$(PATH)
MODULES := '"cmd/config" "api/" "kustomize/" "kyaml/"'
LATEST_V4_RELEASE=v4.4.1
LATEST_V4_RELEASE=v4.5.1

# Provide defaults for REPO_OWNER and REPO_NAME if not present.
# Typically these values would be provided by Prow.
Expand Down Expand Up @@ -224,8 +224,8 @@ generate-kustomize-api: $(MYGOBIN)/k8scopy

.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"; \
cd krusty; OPENAPI_TEST=true go test -run TestCustomOpenAPIFieldFromComponentWithOverlays
cd api; go test ./... -ldflags "-X sigs.k8s.io/kustomize/api/provenance.version=v444.333.222"
cd api/krusty; OPENAPI_TEST=true go test -run TestCustomOpenAPIFieldFromComponentWithOverlays

.PHONY: test-unit-kustomize-plugins
test-unit-kustomize-plugins:
Expand Down
11 changes: 5 additions & 6 deletions OWNERS_ALIASES
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
aliases:
kustomize-owners:
- knverey
- monopole
- pwittrock
- natasha41575
kustomize-approvers:
- justinsb
- knverey
- monopole
- natasha41575
- pwittrock
kustomize-reviewers:
- knverey
- monopole
- natasha41575
- yuwenma

kyaml-approvers:
- mengqiy
Expand All @@ -28,3 +24,6 @@ aliases:
emeritus-approvers:
- liujingfang1
- Shell32-Natsu
- justinsb
- monopole
- pwittrock
112 changes: 112 additions & 0 deletions ROADMAP.md
Original file line number Diff line number Diff line change
@@ -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](https://github.com/kubernetes-sigs/kustomize/blob/master/roadmap-2021.md#objective-improve-contributor-community)

[Objective: Improve end-user experience](https://github.com/kubernetes-sigs/kustomize/blob/master/roadmap-2021.md#objective-improve-end-user-experience)

[Objective: Improve extension experience](https://github.com/kubernetes-sigs/kustomize/blob/master/roadmap-2021.md#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 doesn’t 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 don’t 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)
19 changes: 6 additions & 13 deletions api/filters/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,15 @@ type Filter struct {
// FsSlice contains the FieldSpecs to locate the namespace field
FsSlice types.FsSlice

// SetEntryCallback is invoked each time an annotation is applied
// Example use cases:
// - Tracking all paths where annotations have been applied
SetEntryCallback func(key, value, tag string, node *yaml.RNode)
trackableSetter filtersutil.TrackableSetter
}

var _ kio.Filter = Filter{}
var _ kio.TrackableFilter = &Filter{}

func (f Filter) setEntry(key, value, tag string) filtersutil.SetFn {
baseSetEntryFunc := filtersutil.SetEntry(key, value, tag)
return func(node *yaml.RNode) error {
if f.SetEntryCallback != nil {
f.SetEntryCallback(key, value, tag, node)
}
return baseSetEntryFunc(node)
}
// 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) {
Expand All @@ -45,7 +38,7 @@ func (f Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
for _, k := range keys {
if err := node.PipeE(fsslice.Filter{
FsSlice: f.FsSlice,
SetValue: f.setEntry(
SetValue: f.trackableSetter.SetEntry(
k, f.Annotations[k], yaml.NodeTagString),
CreateKind: yaml.MappingNode, // Annotations are MappingNodes.
CreateTag: yaml.NodeTagMap,
Expand Down
31 changes: 8 additions & 23 deletions api/filters/annotations/annotations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,15 @@ import (

var annosFs = builtinconfig.MakeDefaultConfig().CommonAnnotations

type setEntryArg struct {
Key string
Value string
Tag string
NodePath []string
}

var setEntryArgs []setEntryArg

func setEntryCallbackStub(key, value, tag string, node *yaml.RNode) {
setEntryArgs = append(setEntryArgs, setEntryArg{
Key: key,
Value: value,
Tag: tag,
NodePath: node.FieldPath(),
})
}

func TestAnnotations_Filter(t *testing.T) {
mutationTrackStub := filtertest_test.MutationTrackerStub{}
testCases := map[string]struct {
input string
expectedOutput string
filter Filter
fsslice types.FsSlice
expectedSetEntryArgs []setEntryArg
setEntryCallback func(key, value, tag string, node *yaml.RNode)
expectedSetEntryArgs []filtertest_test.SetValueArg
}{
"add": {
input: `
Expand Down Expand Up @@ -259,15 +243,15 @@ spec:
"a": "a1",
"b": "b1",
},
SetEntryCallback: setEntryCallbackStub,
},
setEntryCallback: mutationTrackStub.MutationTracker,
fsslice: []types.FieldSpec{
{
Path: "spec/template/metadata/annotations",
CreateIfNotPresent: true,
},
},
expectedSetEntryArgs: []setEntryArg{
expectedSetEntryArgs: []filtertest_test.SetValueArg{
{
Key: "a",
Value: "a1",
Expand Down Expand Up @@ -297,16 +281,17 @@ spec:
}

for tn, tc := range testCases {
setEntryArgs = nil
mutationTrackStub.Reset()
t.Run(tn, func(t *testing.T) {
filter := tc.filter
filter.WithMutationTracker(tc.setEntryCallback)
filter.FsSlice = append(annosFs, tc.fsslice...)
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, setEntryArgs) {
if !assert.Equal(t, tc.expectedSetEntryArgs, mutationTrackStub.SetValueArgs()) {
t.FailNow()
}
})
Expand Down
2 changes: 2 additions & 0 deletions api/filters/fieldspec/fieldspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ func (fltr Filter) handleMap(obj *yaml.RNode) error {
// seq calls filter on all sequence elements
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
Expand Down
82 changes: 82 additions & 0 deletions api/filters/fieldspec/fieldspec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,3 +558,85 @@ a:
})
}
}

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