From 5fcc2ad9f7aa8dbeab17e62ac38d6815fdc1b96d Mon Sep 17 00:00:00 2001 From: Zheng Xi Zhou Date: Fri, 27 Aug 2021 18:45:05 +0800 Subject: [PATCH] Fix: fix `EOF` event when describing an application (#2134) Fixed the issue: When component properties don't meet the parameter of the ComponentDefinition, it will hit 'EOF' event Co-authored-by: Jian.Li <74582607+leejanee@users.noreply.github.com> Fix #2132 --- pkg/cue/model/instance.go | 7 ++++--- pkg/cue/model/instance_test.go | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/pkg/cue/model/instance.go b/pkg/cue/model/instance.go index bf1f5d5c3..b4cc51eca 100644 --- a/pkg/cue/model/instance.go +++ b/pkg/cue/model/instance.go @@ -26,6 +26,7 @@ import ( "cuelang.org/go/cue/format" "github.com/pkg/errors" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/klog/v2" "github.com/oam-dev/kubevela/pkg/cue/model/sets" ) @@ -67,7 +68,7 @@ func (inst *instance) Compile() ([]byte, error) { } // compiled object should be final and concrete value if err := it.Value().Validate(cue.Concrete(true), cue.Final()); err != nil { - return nil, it.Err + return nil, err } return it.Value().MarshalJSON() } @@ -77,14 +78,14 @@ func (inst *instance) Compile() ([]byte, error) { func (inst *instance) Unstructured() (*unstructured.Unstructured, error) { jsonv, err := inst.Compile() if err != nil { - return nil, err + klog.ErrorS(err, "failed to have the workload/trait unstructured", "Definition", inst.String()) + return nil, errors.Wrap(err, "failed to have the workload/trait unstructured") } o := &unstructured.Unstructured{} if err := o.UnmarshalJSON(jsonv); err != nil { return nil, err } return o, nil - } // Unify implement unity operations between instances diff --git a/pkg/cue/model/instance_test.go b/pkg/cue/model/instance_test.go index 728ffa3d7..18b8f746e 100644 --- a/pkg/cue/model/instance_test.go +++ b/pkg/cue/model/instance_test.go @@ -196,7 +196,7 @@ metadata: name: parameter.name `, } _, err = ins.Unstructured() - assert.Equal(t, err.Error(), fmt.Sprintf(`metadata.name: reference "%s" not found`, velacue.ParameterTag)) + assert.Equal(t, err.Error(), fmt.Sprintf(`failed to have the workload/trait unstructured: metadata.name: reference "%s" not found`, velacue.ParameterTag)) ins = &instance{ v: ` apiVersion: "apps/v1" @@ -215,4 +215,20 @@ metadata: name: "abc" }, }, }) + + ins = &instance{ + v: ` +apiVersion: "source.toolkit.fluxcd.io/v1beta1" +metadata: { + name: "grafana" +} +kind: "HelmRepository" +spec: { + url: string + interval: *"5m" | string +}`, + } + o, err := ins.Unstructured() + assert.Nil(t, o) + assert.NotNil(t, err) }