mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-27 16:17:34 +00:00
Fix: optimize skip reconcile and expose error if the traits patch an invalid workload like terraform (#5334)
Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com> Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com>
This commit is contained in:
@@ -254,7 +254,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
|
||||
}
|
||||
}
|
||||
case workflowv1alpha1.WorkflowStateSkipped:
|
||||
return ctrl.Result{}, nil
|
||||
return r.result(nil).requeue(executor.GetBackoffWaitTime()).ret()
|
||||
default:
|
||||
}
|
||||
|
||||
|
||||
@@ -351,13 +351,16 @@ func (td *traitDef) Complete(ctx process.Context, abstractTemplate string, param
|
||||
|
||||
patcher := val.LookupPath(value.FieldPath(PatchFieldName))
|
||||
base, auxiliaries := ctx.Output()
|
||||
if base != nil && patcher.Exists() {
|
||||
if patcher.Exists() {
|
||||
if base == nil {
|
||||
return fmt.Errorf("patch trait %s into an invalid workload", td.name)
|
||||
}
|
||||
if err := base.Unify(patcher, sets.CreateUnifyOptionsForPatcher(patcher)...); err != nil {
|
||||
return errors.WithMessagef(err, "invalid patch trait %s into workload", td.name)
|
||||
}
|
||||
}
|
||||
outputsPatcher := val.LookupPath(value.FieldPath(PatchOutputsFieldName))
|
||||
if base != nil && outputsPatcher.Exists() {
|
||||
if outputsPatcher.Exists() {
|
||||
for _, auxiliary := range auxiliaries {
|
||||
target := outputsPatcher.LookupPath(value.FieldPath(auxiliary.Name))
|
||||
if !target.Exists() {
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
|
||||
"github.com/kubevela/workflow/pkg/cue/packages"
|
||||
wfprocess "github.com/kubevela/workflow/pkg/cue/process"
|
||||
|
||||
"github.com/oam-dev/kubevela/apis/types"
|
||||
"github.com/oam-dev/kubevela/pkg/cue/process"
|
||||
@@ -1534,3 +1535,34 @@ func TestTraitPatchSingleOutput(t *testing.T) {
|
||||
r.True(ok)
|
||||
r.Equal("val", val)
|
||||
}
|
||||
|
||||
func TestTraitCompleteErrorCases(t *testing.T) {
|
||||
cases := map[string]struct {
|
||||
ctx wfprocess.Context
|
||||
traitName string
|
||||
template string
|
||||
params map[string]interface{}
|
||||
err string
|
||||
}{
|
||||
"patch trait": {
|
||||
ctx: process.NewContext(process.ContextData{}),
|
||||
template: `
|
||||
patch: {
|
||||
// +patchKey=name
|
||||
spec: template: spec: containers: [parameter]
|
||||
}
|
||||
parameter: {
|
||||
name: string
|
||||
image: string
|
||||
command?: [...string]
|
||||
}`,
|
||||
err: "patch trait patch trait into an invalid workload",
|
||||
},
|
||||
}
|
||||
for k, v := range cases {
|
||||
td := NewTraitAbstractEngine(k, &packages.PackageDiscover{})
|
||||
err := td.Complete(v.ctx, v.template, v.params)
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), v.err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user