mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-09-15 12:18:57 +00:00
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
This commit is contained in:
committed by
GitHub
parent
fbfcb0479a
commit
7b0ec99d90
@@ -5,6 +5,7 @@ package command_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -66,6 +67,7 @@ ENTRYPOINT ["function"]
|
||||
func TestCommand_standalone(t *testing.T) {
|
||||
var config struct {
|
||||
A string `json:"a" yaml:"a"`
|
||||
B int `json:"b" yaml:"b"`
|
||||
}
|
||||
|
||||
fn := func(items []*yaml.RNode) ([]*yaml.RNode, error) {
|
||||
@@ -83,6 +85,10 @@ metadata:
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = items[i].PipeE(yaml.SetAnnotation("b", fmt.Sprintf("%v", config.B)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return items, nil
|
||||
@@ -99,6 +105,7 @@ metadata:
|
||||
func TestCommand_standalone_stdin(t *testing.T) {
|
||||
var config struct {
|
||||
A string `json:"a" yaml:"a"`
|
||||
B int `json:"b" yaml:"b"`
|
||||
}
|
||||
|
||||
p := &framework.SimpleProcessor{
|
||||
@@ -119,6 +126,10 @@ metadata:
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = items[i].PipeE(yaml.SetAnnotation("b", fmt.Sprintf("%v", config.B)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return items, nil
|
||||
@@ -150,7 +161,8 @@ metadata:
|
||||
namespace: default
|
||||
annotations:
|
||||
foo: bar1
|
||||
a: 'b'
|
||||
a: 'c'
|
||||
b: '1'
|
||||
spec:
|
||||
replicas: 1
|
||||
---
|
||||
@@ -161,6 +173,7 @@ metadata:
|
||||
namespace: default
|
||||
annotations:
|
||||
foo: bar2
|
||||
a: 'b'
|
||||
a: 'c'
|
||||
b: '1'
|
||||
`), strings.TrimSpace(out.String()))
|
||||
}
|
||||
|
||||
@@ -3,4 +3,5 @@
|
||||
|
||||
apiVersion: example.com/v1alpha1
|
||||
kind: Foo
|
||||
a: b
|
||||
a: c
|
||||
b: 1
|
||||
|
||||
@@ -8,7 +8,8 @@ metadata:
|
||||
namespace: default
|
||||
annotations:
|
||||
foo: bar2
|
||||
a: 'b'
|
||||
a: 'c'
|
||||
b: '1'
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
@@ -17,4 +18,5 @@ metadata:
|
||||
namespace: default
|
||||
annotations:
|
||||
foo: bar1
|
||||
a: 'b'
|
||||
a: 'c'
|
||||
b: '1'
|
||||
|
||||
@@ -479,7 +479,12 @@ func (s SetOpenAPI) Filter(object *yaml.RNode) (*yaml.RNode, error) {
|
||||
}
|
||||
|
||||
if s.IsSet {
|
||||
if err := def.PipeE(&yaml.FieldSetter{Name: "isSet", StringValue: "true"}); err != nil {
|
||||
n := &yaml.Node{
|
||||
Kind: yaml.ScalarNode,
|
||||
Value: "true",
|
||||
Tag: yaml.NodeTagBool,
|
||||
}
|
||||
if err := def.PipeE(&yaml.FieldSetter{Name: "isSet", Value: yaml.NewRNode(n)}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -685,6 +685,12 @@ func (s FieldSetter) Filter(rn *RNode) (*RNode, error) {
|
||||
s.Value = NewScalarRNode(s.StringValue)
|
||||
}
|
||||
|
||||
// need to set style for strings not recognized by yaml 1.1 to quoted if not previously set
|
||||
// TODO: fix in upstream yaml library so this can be handled with yaml SetString
|
||||
if s.Value.IsStringValue() && !s.OverrideStyle && s.Value.YNode().Style == 0 && IsYaml1_1NonString(s.Value.YNode()) {
|
||||
s.Value.YNode().Style = yaml.DoubleQuotedStyle
|
||||
}
|
||||
|
||||
if s.Name == "" {
|
||||
if err := ErrorIfInvalid(rn, yaml.ScalarNode); err != nil {
|
||||
return rn, err
|
||||
|
||||
@@ -248,6 +248,11 @@ func (rn *RNode) IsNilOrEmpty() bool {
|
||||
IsYNodeZero(rn.YNode())
|
||||
}
|
||||
|
||||
// IsStringValue is true if the RNode is not nil and is scalar string node
|
||||
func (rn *RNode) IsStringValue() bool {
|
||||
return !rn.IsNil() && IsYNodeString(rn.YNode())
|
||||
}
|
||||
|
||||
// GetMeta returns the ResourceMeta for an RNode
|
||||
func (rn *RNode) GetMeta() (ResourceMeta, error) {
|
||||
if IsMissingOrNull(rn) {
|
||||
|
||||
Reference in New Issue
Block a user