mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 00:52:55 +00:00
Add RNode.Set/GetDataMap to ease configmap generation.
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -417,6 +418,34 @@ func (rn *RNode) SetMapField(value *RNode, path ...string) error {
|
||||
)
|
||||
}
|
||||
|
||||
func (rn *RNode) GetDataMap() map[string]string {
|
||||
n, err := rn.Pipe(Lookup(DataField))
|
||||
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")
|
||||
}
|
||||
if len(m) == 0 {
|
||||
if err := rn.PipeE(Clear(DataField)); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
if err := rn.SetMapField(NewMapRNode(&m), DataField); 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...)
|
||||
|
||||
Reference in New Issue
Block a user