mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-17 17:52:12 +00:00
More control over bytereadwriter options
- Override wrapping - Override function config
This commit is contained in:
@@ -43,6 +43,7 @@ type ByteReadWriter struct {
|
|||||||
|
|
||||||
Results *yaml.RNode
|
Results *yaml.RNode
|
||||||
|
|
||||||
|
NoWrap bool
|
||||||
WrappingAPIVersion string
|
WrappingAPIVersion string
|
||||||
WrappingKind string
|
WrappingKind string
|
||||||
}
|
}
|
||||||
@@ -53,10 +54,15 @@ func (rw *ByteReadWriter) Read() ([]*yaml.RNode, error) {
|
|||||||
OmitReaderAnnotations: rw.OmitReaderAnnotations,
|
OmitReaderAnnotations: rw.OmitReaderAnnotations,
|
||||||
}
|
}
|
||||||
val, err := b.Read()
|
val, err := b.Read()
|
||||||
rw.FunctionConfig = b.FunctionConfig
|
if rw.FunctionConfig == nil {
|
||||||
|
rw.FunctionConfig = b.FunctionConfig
|
||||||
|
}
|
||||||
rw.Results = b.Results
|
rw.Results = b.Results
|
||||||
rw.WrappingAPIVersion = b.WrappingAPIVersion
|
|
||||||
rw.WrappingKind = b.WrappingKind
|
if !rw.NoWrap {
|
||||||
|
rw.WrappingAPIVersion = b.WrappingAPIVersion
|
||||||
|
rw.WrappingKind = b.WrappingKind
|
||||||
|
}
|
||||||
return val, errors.Wrap(err)
|
return val, errors.Wrap(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestByteReadWriter(t *testing.T) {
|
func TestByteReadWriter(t *testing.T) {
|
||||||
@@ -226,6 +227,68 @@ metadata:
|
|||||||
`,
|
`,
|
||||||
instance: kio.ByteReadWriter{KeepReaderAnnotations: true},
|
instance: kio.ByteReadWriter{KeepReaderAnnotations: true},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "manual_override_wrap",
|
||||||
|
input: `
|
||||||
|
apiVersion: config.kubernetes.io/v1alpha1
|
||||||
|
kind: ResourceList
|
||||||
|
items:
|
||||||
|
- kind: Deployment
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
- kind: Service
|
||||||
|
spec:
|
||||||
|
selectors:
|
||||||
|
foo: bar
|
||||||
|
functionConfig:
|
||||||
|
a: b # something
|
||||||
|
`,
|
||||||
|
expectedOutput: `
|
||||||
|
kind: Deployment
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
---
|
||||||
|
kind: Service
|
||||||
|
spec:
|
||||||
|
selectors:
|
||||||
|
foo: bar
|
||||||
|
`,
|
||||||
|
instance: kio.ByteReadWriter{NoWrap: true},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "manual_override_function_config",
|
||||||
|
input: `
|
||||||
|
apiVersion: config.kubernetes.io/v1alpha1
|
||||||
|
kind: ResourceList
|
||||||
|
items:
|
||||||
|
- kind: Deployment
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
- kind: Service
|
||||||
|
spec:
|
||||||
|
selectors:
|
||||||
|
foo: bar
|
||||||
|
functionConfig:
|
||||||
|
a: b # something
|
||||||
|
`,
|
||||||
|
expectedOutput: `
|
||||||
|
apiVersion: config.kubernetes.io/v1alpha1
|
||||||
|
kind: ResourceList
|
||||||
|
items:
|
||||||
|
- kind: Deployment
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
- kind: Service
|
||||||
|
spec:
|
||||||
|
selectors:
|
||||||
|
foo: bar
|
||||||
|
functionConfig:
|
||||||
|
c: d
|
||||||
|
`,
|
||||||
|
instance: kio.ByteReadWriter{FunctionConfig: yaml.MustParse(`c: d`)},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range testCases {
|
for i := range testCases {
|
||||||
|
|||||||
Reference in New Issue
Block a user