mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-30 09:51:23 +00:00
Uniform unmarshal function
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
package target
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
@@ -60,7 +59,7 @@ func (kt *KustTarget) Load() error {
|
||||
return err
|
||||
}
|
||||
var k types.Kustomization
|
||||
err = unmarshal(content, &k)
|
||||
err = k.Unmarshal(content)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -104,16 +103,6 @@ func loadKustFile(ldr ifc.Loader) ([]byte, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func unmarshal(y []byte, o interface{}) error {
|
||||
j, err := yaml.YAMLToJSON(y)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dec := json.NewDecoder(bytes.NewReader(j))
|
||||
dec.DisallowUnknownFields()
|
||||
return dec.Decode(o)
|
||||
}
|
||||
|
||||
// MakeCustomizedResMap creates a fully customized ResMap
|
||||
// per the instructions contained in its kustomiztion instance.
|
||||
func (kt *KustTarget) MakeCustomizedResMap() (resmap.ResMap, error) {
|
||||
|
||||
@@ -3,6 +3,13 @@
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
const (
|
||||
KustomizationVersion = "kustomize.config.k8s.io/v1beta1"
|
||||
KustomizationKind = "Kustomization"
|
||||
@@ -165,3 +172,20 @@ func (k *Kustomization) EnforceFields() []string {
|
||||
}
|
||||
return errs
|
||||
}
|
||||
|
||||
// Unmarshal replace k with the content in YAML input y
|
||||
func (k *Kustomization) Unmarshal(y []byte) error {
|
||||
j, err := yaml.YAMLToJSON(y)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dec := json.NewDecoder(bytes.NewReader(j))
|
||||
dec.DisallowUnknownFields()
|
||||
var nk Kustomization
|
||||
err = dec.Decode(&nk)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*k = nk
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user