allow accessing labels and annotations in vars

This commit is contained in:
Jingfang Liu
2018-11-13 15:56:06 -08:00
parent 38b7f42f9e
commit 51e9fec65d
2 changed files with 76 additions and 2 deletions

View File

@@ -20,7 +20,6 @@ package kunstruct
import (
"encoding/json"
"fmt"
"strings"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
@@ -80,8 +79,12 @@ func (fs *UnstructAdapter) SetMap(m map[string]interface{}) {
// GetFieldValue returns value at the given fieldpath.
func (fs *UnstructAdapter) GetFieldValue(path string) (string, error) {
fields, err := parseFields(path)
if err != nil {
return "", err
}
s, found, err := unstructured.NestedString(
fs.UnstructuredContent(), strings.Split(path, ".")...)
fs.UnstructuredContent(), fields...)
if found || err != nil {
return s, err
}