mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-27 16:17:34 +00:00
Fix: apply-component bug (#2292)
* Fix: apply-component bug * Feat: uniform apply-component input/output format
This commit is contained in:
@@ -18,8 +18,7 @@ package application
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/oam-dev/kubevela/pkg/controller/core.oam.dev/v1alpha2/application/assemble"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
@@ -29,6 +28,7 @@ import (
|
||||
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
||||
"github.com/oam-dev/kubevela/apis/types"
|
||||
"github.com/oam-dev/kubevela/pkg/appfile"
|
||||
"github.com/oam-dev/kubevela/pkg/controller/core.oam.dev/v1alpha2/application/assemble"
|
||||
"github.com/oam-dev/kubevela/pkg/cue/model/value"
|
||||
"github.com/oam-dev/kubevela/pkg/cue/packages"
|
||||
"github.com/oam-dev/kubevela/pkg/oam/discoverymapper"
|
||||
@@ -98,19 +98,26 @@ func convertStepProperties(step *v1beta1.WorkflowStep, app *v1beta1.Application)
|
||||
if err := json.Unmarshal(js, &o); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, c := range app.Spec.Components {
|
||||
step.Inputs = c.Inputs
|
||||
step.Outputs = c.Outputs
|
||||
c.Inputs = nil
|
||||
c.Outputs = nil
|
||||
if c.Name == o.Component {
|
||||
step.Inputs = append(step.Inputs, c.Inputs...)
|
||||
for index := range step.Inputs {
|
||||
parameterKey := strings.TrimSpace(step.Inputs[index].ParameterKey)
|
||||
if !strings.HasPrefix(parameterKey, "properties") {
|
||||
parameterKey = "properties." + parameterKey
|
||||
}
|
||||
step.Inputs[index].ParameterKey = parameterKey
|
||||
}
|
||||
step.Outputs = append(step.Outputs, c.Outputs...)
|
||||
c.Inputs = nil
|
||||
c.Outputs = nil
|
||||
step.Properties = util.Object2RawExtension(c)
|
||||
return nil
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
return errors.Errorf("component %s not found", o.Component)
|
||||
}
|
||||
|
||||
func (h *AppHandler) applyComponentFunc(appParser *appfile.Parser, appRev *v1beta1.ApplicationRevision, af *appfile.Appfile, cli client.Client) oamProvider.ComponentApply {
|
||||
|
||||
@@ -477,11 +477,25 @@ var _ = Describe("Test Workflow", func() {
|
||||
updateApp := &oamcore.Application{}
|
||||
Expect(k8sClient.Get(ctx, appKey, updateApp)).Should(BeNil())
|
||||
Expect(updateApp.Status.Phase).Should(BeEquivalentTo(common.ApplicationRunning))
|
||||
updateApp.Spec.Components[0].Properties = runtime.RawExtension{Raw: []byte(`{}`)}
|
||||
updateApp.Spec.Workflow = &oamcore.Workflow{
|
||||
Steps: []oamcore.WorkflowStep{{
|
||||
Name: "test-web2",
|
||||
Type: "apply-component",
|
||||
Properties: runtime.RawExtension{Raw: []byte(`{"component":"myweb2"}`)},
|
||||
Outputs: common.StepOutputs{
|
||||
{Name: "image", ValueFrom: "output.spec.template.spec.containers[0].image"},
|
||||
},
|
||||
}, {
|
||||
Name: "test-web1",
|
||||
Type: "apply-component",
|
||||
Properties: runtime.RawExtension{Raw: []byte(`{"component":"myweb1"}`)},
|
||||
Inputs: common.StepInputs{
|
||||
{
|
||||
From: "image",
|
||||
ParameterKey: "image",
|
||||
},
|
||||
},
|
||||
}},
|
||||
}
|
||||
Expect(k8sClient.Update(context.Background(), updateApp)).Should(BeNil())
|
||||
|
||||
Reference in New Issue
Block a user