diff --git a/pkg/resmgr/apis/expression.go b/pkg/resmgr/apis/expression.go index 1cfe0a0fd..859714489 100644 --- a/pkg/resmgr/apis/expression.go +++ b/pkg/resmgr/apis/expression.go @@ -250,12 +250,18 @@ func ResolveRef(subject Evaluable, spec string) (string, bool, error) { switch v := obj.(type) { case string: obj = v + ref = ref[1:] case map[string]string: + if len(ref) > 1 { + key = strings.Join(ref, "/") + log.Debug(" - using tailing ref %s as map key...", key) + } value, ok := v[key] if !ok { return "", false, nil } obj = value + ref = nil case error: return "", false, exprError("%s: failed to resolve %q: %v", subject, spec, v) default: @@ -265,9 +271,8 @@ func ResolveRef(subject Evaluable, spec string) (string, bool, error) { subject, spec, obj) } obj = e.Eval(key) + ref = ref[1:] } - - ref = ref[1:] } str, ok := obj.(string) diff --git a/pkg/resmgr/apis/expression_test.go b/pkg/resmgr/apis/expression_test.go index 52829c9c3..546906604 100644 --- a/pkg/resmgr/apis/expression_test.go +++ b/pkg/resmgr/apis/expression_test.go @@ -86,7 +86,12 @@ func TestResolveRefAndKeyValue(t *testing.T) { defer logger.Flush() pod := newEvaluable("P1", "pns", "pqos", - map[string]string{"l1": "plone", "l2": "pltwo", "l5": "plfive"}, nil, nil) + map[string]string{ + "l1": "plone", + "l2": "pltwo", + "l5": "plfive", + "io.test/label1": "io.test/value1", + }, nil, nil) tcases := []struct { name string @@ -100,7 +105,11 @@ func TestResolveRefAndKeyValue(t *testing.T) { { name: "test resolving references", subject: newEvaluable("C1", "cns", "cqos", - map[string]string{"l1": "clone", "l2": "cltwo", "l3": "clthree"}, + map[string]string{ + "l1": "clone", + "l2": "cltwo", + "l3": "clthree", + }, map[string]string{"t1": "ctone", "t2": "cttwo", "t3": "ctthree"}, pod), keys: []string{ "name", "namespace", "qosclass", @@ -111,34 +120,35 @@ func TestResolveRefAndKeyValue(t *testing.T) { "pod/labels/l3", "pod/labels/l4", "pod/labels/l5", + "pod/labels/io.test/label1", ":,-pod/qosclass,pod/namespace,pod/name,name", }, values: []string{ "C1", "cns", "cqos", "clone", "cltwo", "clthree", "", "ctone", "cttwo", "ctthree", "", - "plone", "pltwo", "", "", "plfive", + "plone", "pltwo", "", "", "plfive", "io.test/value1", "", }, keyvalues: []string{ "C1", "cns", "cqos", "clone", "cltwo", "clthree", "", "ctone", "cttwo", "ctthree", "", - "plone", "pltwo", "", "", "plfive", + "plone", "pltwo", "", "", "plfive", "io.test/value1", "pqos-pns-P1-C1", }, ok: []bool{ true, true, true, true, true, true, false, true, true, true, false, - true, true, false, false, true, + true, true, false, false, true, true, false, }, error: []bool{ false, false, false, false, false, false, false, false, false, false, false, - false, false, false, false, false, + false, false, false, false, false, false, true, }, },