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
retain quotes in namespace transformer filter #4421
Changes from 14 commits
430f1fe
937f968
7f4227b
55823f6
be62ad9
5a1d545
5509834
4832510
7ca3615
246d070
c98a310
99e6c57
71570f8
ec36280
dc40cb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,7 +140,7 @@ metadata: | |
foo: 'bar' | ||
data: | ||
a: x | ||
b: y | ||
b: "y" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why does "y" get quoted? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this is because LoadMapIntoConfigMapData uses yaml.FieldSetter, so it will have the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I figured it's okay to change this test since this is an invalid config (I shared output in my comment in the linked issue #4386 showing issues with invalid yaml 1.1 values in config map data). Any data that should be quoted and isn't passed through FieldSetter.Filter won't be corrected. This won't fix #4472, idk if the env var gets passed through FieldSetter.Filter at all but the env var losing quotes in the example is not an invalid yaml 1.1 string and that config can be applied. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I see. I had to do some research because I'm not a yaml expert, but TIL that "y" is the equivalent of "true" in yaml 1.1. |
||
c: Hello World | ||
d: "true" | ||
`, | ||
|
@@ -181,7 +181,7 @@ metadata: | |
river: 'Missouri' | ||
data: | ||
a: x | ||
b: y | ||
b: "y" | ||
c: Hello World | ||
d: "true" | ||
immutable: true | ||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ import ( | |
"os" | ||
|
||
"sigs.k8s.io/kustomize/kyaml/fn/framework" | ||
"sigs.k8s.io/kustomize/kyaml/fn/framework/command" | ||
"sigs.k8s.io/kustomize/kyaml/kio" | ||
"sigs.k8s.io/kustomize/kyaml/yaml" | ||
) | ||
|
||
|
@@ -32,27 +34,29 @@ type Example struct { | |
|
||
func main() { | ||
functionConfig := &Example{} | ||
resourceList := &framework.ResourceList{FunctionConfig: functionConfig} | ||
|
||
cmd := framework.Command(resourceList, func() error { | ||
for i := range resourceList.Items { | ||
if err := resourceList.Items[i].PipeE(yaml.SetAnnotation("a-string-value", | ||
fn := func(items []*yaml.RNode) ([]*yaml.RNode, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't impact tests passing or not but I think having this updated helps rule out whether this is the source of a bug in the |
||
for i := range items { | ||
// set the annotation on each resource item | ||
if err := items[i].PipeE(yaml.SetAnnotation("a-string-value", | ||
functionConfig.Data.StringValue)); err != nil { | ||
return err | ||
return nil, err | ||
} | ||
|
||
if err := resourceList.Items[i].PipeE(yaml.SetAnnotation("a-int-value", | ||
if err := items[i].PipeE(yaml.SetAnnotation("a-int-value", | ||
fmt.Sprintf("%v", functionConfig.Data.IntValue))); err != nil { | ||
return err | ||
return nil, err | ||
} | ||
|
||
if err := resourceList.Items[i].PipeE(yaml.SetAnnotation("a-bool-value", | ||
if err := items[i].PipeE(yaml.SetAnnotation("a-bool-value", | ||
fmt.Sprintf("%v", functionConfig.Data.BoolValue))); err != nil { | ||
return err | ||
return nil, err | ||
} | ||
} | ||
return nil | ||
}) | ||
return items, nil | ||
} | ||
p := framework.SimpleProcessor{Filter: kio.FilterFunc(fn), Config: functionConfig} | ||
cmd := command.Build(p, command.StandaloneDisabled, false) | ||
natasha41575 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if err := cmd.Execute(); err != nil { | ||
os.Exit(1) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
|
||
apiVersion: example.com/v1alpha1 | ||
kind: Foo | ||
a: b | ||
a: c | ||
b: 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed changes to
SetScalar
and am usingSetEntry("", ns.Namespace, <tag>)
where a tag is needed, so as not to make any changes to public functions.I only added tag to namespace and replicacount filters to minimize changes but could add to other filters (suffix, prefix, etc.) if requested so they don't also remove quotes.
I'm resolving the outdated comments with @natasha41575 but would like to know if using SetEntry is fine in these cases, since that allows moving the addition of the double quotes style to the
FieldSetter
func in thekyaml
package, which should work whenever the scalar type tag is set on the rnode passed to it.The other problems mentioned in the issue I opened (configmap "true|false" values, a separate env variable issue #4472) are not resolved by this PR.