mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
support binaryData merge
This commit is contained in:
@@ -49,6 +49,9 @@ type Kunstructured interface {
|
||||
// GetData returns a top-level "data" field, as in a ConfigMap.
|
||||
GetDataMap() map[string]string
|
||||
|
||||
// GetData returns a top-level "binaryData" field, as in a ConfigMap.
|
||||
GetBinaryDataMap() map[string]string
|
||||
|
||||
// Used by ResAccumulator and ReplacementTransformer.
|
||||
GetFieldValue(string) (interface{}, error)
|
||||
|
||||
@@ -90,6 +93,8 @@ type Kunstructured interface {
|
||||
// SetDataMap sets a top-level "data" field, as in a ConfigMap.
|
||||
SetDataMap(map[string]string)
|
||||
|
||||
// SetDataMap sets a top-level "binaryData" field, as in a ConfigMap.
|
||||
SetBinaryDataMap(map[string]string)
|
||||
// Used by PatchStrategicMergeTransformer.
|
||||
SetGvk(resid.Gvk)
|
||||
|
||||
|
||||
@@ -170,6 +170,16 @@ func (wn *WNode) SetDataMap(m map[string]string) {
|
||||
wn.node.SetDataMap(m)
|
||||
}
|
||||
|
||||
// GetBinaryDataMap implements ifc.Kunstructured.
|
||||
func (wn *WNode) GetBinaryDataMap() map[string]string {
|
||||
return wn.node.GetBinaryDataMap()
|
||||
}
|
||||
|
||||
// SetBinaryDataMap implements ifc.Kunstructured.
|
||||
func (wn *WNode) SetBinaryDataMap(m map[string]string) {
|
||||
wn.node.SetBinaryDataMap(m)
|
||||
}
|
||||
|
||||
// GetKind implements ifc.Kunstructured.
|
||||
func (wn *WNode) GetKind() string {
|
||||
return wn.demandMetaData("GetKind").Kind
|
||||
|
||||
@@ -345,6 +345,55 @@ metadata:
|
||||
`)
|
||||
}
|
||||
|
||||
var binaryHello = []byte{
|
||||
0xff, // non-utf8
|
||||
0x68, // h
|
||||
0x65, // e
|
||||
0x6c, // l
|
||||
0x6c, // l
|
||||
0x6f, // o
|
||||
}
|
||||
|
||||
func manyHellos(count int) (result []byte) {
|
||||
for i := 0; i < count; i++ {
|
||||
result = append(result, binaryHello...)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func TestGeneratorOverlaysBinaryData(t *testing.T) {
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
th.WriteF("/app/base/data.bin", string(manyHellos(30)))
|
||||
th.WriteK("/app/base", `
|
||||
namePrefix: p1-
|
||||
configMapGenerator:
|
||||
- name: com1
|
||||
behavior: create
|
||||
files:
|
||||
- data.bin
|
||||
`)
|
||||
th.WriteK("/app/overlay", `
|
||||
resources:
|
||||
- ../base
|
||||
configMapGenerator:
|
||||
- name: com1
|
||||
behavior: merge
|
||||
`)
|
||||
m := th.Run("/app/overlay", th.MakeDefaultOptions())
|
||||
th.AssertActualEqualsExpected(m, `
|
||||
apiVersion: v1
|
||||
binaryData:
|
||||
data.bin: |
|
||||
/2hlbGxv/2hlbGxv/2hlbGxv/2hlbGxv/2hlbGxv/2hlbGxv/2hlbGxv/2hlbGxv/2hlbG
|
||||
xv/2hlbGxv/2hlbGxv/2hlbGxv/2hlbGxv/2hlbGxv/2hlbGxv/2hlbGxv/2hlbGxv/2hl
|
||||
bGxv/2hlbGxv/2hlbGxv/2hlbGxv/2hlbGxv/2hlbGxv/2hlbGxv/2hlbGxv/2hlbGxv/2
|
||||
hlbGxv/2hlbGxv/2hlbGxv/2hlbGxv
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: p1-com1-96gmmt6gt5
|
||||
`)
|
||||
}
|
||||
|
||||
func TestGeneratorOverlays(t *testing.T) {
|
||||
th := kusttest_test.MakeHarness(t)
|
||||
th.WriteK("/app/base1", `
|
||||
|
||||
@@ -489,6 +489,7 @@ func (m *resWrangler) appendReplaceOrMerge(res *resource.Resource) error {
|
||||
case types.BehaviorMerge:
|
||||
res.CopyMergeMetaDataFieldsFrom(old)
|
||||
res.MergeDataMapFrom(old)
|
||||
res.MergeBinaryDataMapFrom(old)
|
||||
default:
|
||||
return fmt.Errorf(
|
||||
"id %#v exists; behavior must be merge or replace", id)
|
||||
|
||||
@@ -70,6 +70,10 @@ func (r *Resource) GetDataMap() map[string]string {
|
||||
return r.kunStr.GetDataMap()
|
||||
}
|
||||
|
||||
func (r *Resource) GetBinaryDataMap() map[string]string {
|
||||
return r.kunStr.GetBinaryDataMap()
|
||||
}
|
||||
|
||||
func (r *Resource) GetGvk() resid.Gvk {
|
||||
return r.kunStr.GetGvk()
|
||||
}
|
||||
@@ -127,6 +131,10 @@ func (r *Resource) SetDataMap(m map[string]string) {
|
||||
r.kunStr.SetDataMap(m)
|
||||
}
|
||||
|
||||
func (r *Resource) SetBinaryDataMap(m map[string]string) {
|
||||
r.kunStr.SetBinaryDataMap(m)
|
||||
}
|
||||
|
||||
func (r *Resource) SetGvk(gvk resid.Gvk) {
|
||||
r.kunStr.SetGvk(gvk)
|
||||
}
|
||||
@@ -196,6 +204,10 @@ func (r *Resource) MergeDataMapFrom(o *Resource) {
|
||||
r.SetDataMap(mergeStringMaps(o.GetDataMap(), r.GetDataMap()))
|
||||
}
|
||||
|
||||
func (r *Resource) MergeBinaryDataMapFrom(o *Resource) {
|
||||
r.SetBinaryDataMap(mergeStringMaps(o.GetBinaryDataMap(), r.GetBinaryDataMap()))
|
||||
}
|
||||
|
||||
func (r *Resource) ErrIfNotEquals(o *Resource) error {
|
||||
meYaml, err := r.AsYAML()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user