add functions for binaryData

This commit is contained in:
Donny Xia
2021-02-11 13:33:16 -08:00
parent dbbe340b4f
commit dd72ea1e6a
2 changed files with 42 additions and 0 deletions

View File

@@ -35,6 +35,20 @@ func (rn *RNode) LoadMapIntoConfigMapData(m map[string]string) error {
return nil
}
func (rn *RNode) LoadMapIntoConfigMapBinaryData(m map[string]string) error {
for _, k := range SortedMapKeys(m) {
_, vrN := makeConfigMapValueRNode(m[k])
// we know this is binary data
fldName := BinaryDataField
if _, err := rn.Pipe(
LookupCreate(MappingNode, fldName),
SetField(k, vrN)); err != nil {
return err
}
}
return nil
}
func makeConfigMapValueRNode(s string) (field string, rN *RNode) {
yN := &Node{Kind: ScalarNode}
yN.Tag = NodeTagString

View File

@@ -434,6 +434,19 @@ func (rn *RNode) GetDataMap() map[string]string {
return result
}
func (rn *RNode) GetBinaryDataMap() map[string]string {
n, err := rn.Pipe(Lookup(BinaryDataField))
if err != nil {
return nil
}
result := map[string]string{}
_ = n.VisitFields(func(node *MapNode) error {
result[GetValue(node.Key)] = GetValue(node.Value)
return nil
})
return result
}
func (rn *RNode) SetDataMap(m map[string]string) {
if rn == nil {
log.Fatal("cannot set data map on nil Rnode")
@@ -449,6 +462,21 @@ func (rn *RNode) SetDataMap(m map[string]string) {
}
}
func (rn *RNode) SetBinaryDataMap(m map[string]string) {
if rn == nil {
log.Fatal("cannot set binaryData map on nil Rnode")
}
if err := rn.PipeE(Clear(BinaryDataField)); err != nil {
log.Fatal(err)
}
if len(m) == 0 {
return
}
if err := rn.LoadMapIntoConfigMapBinaryData(m); err != nil {
log.Fatal(err)
}
}
// AppendToFieldPath appends a field name to the FieldPath.
func (rn *RNode) AppendToFieldPath(parts ...string) {
rn.fieldPath = append(rn.fieldPath, parts...)