mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-27 16:17:34 +00:00
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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user