diff --git a/pkg/appfile/appfile.go b/pkg/appfile/appfile.go index 6c474b4c5..943cac3e2 100644 --- a/pkg/appfile/appfile.go +++ b/pkg/appfile/appfile.go @@ -64,12 +64,12 @@ func (app *AppFile) BuildOAM(ns string, io cmdutil.IOStreams, tm template.Manage } // RenderOAM renders Appfile into AppConfig, Components. -func (app *AppFile) RenderOAM(ns string, io cmdutil.IOStreams, tm template.Manager, slience bool) ( +func (app *AppFile) RenderOAM(ns string, io cmdutil.IOStreams, tm template.Manager, silence bool) ( []*v1alpha2.Component, *v1alpha2.ApplicationConfiguration, []oam.Object, error) { - return app.buildOAM(ns, io, false, tm, slience) + return app.buildOAM(ns, io, false, tm, silence) } -func (app *AppFile) buildOAM(ns string, io cmdutil.IOStreams, buildImage bool, tm template.Manager, slience bool) ( +func (app *AppFile) buildOAM(ns string, io cmdutil.IOStreams, buildImage bool, tm template.Manager, silence bool) ( []*v1alpha2.Component, *v1alpha2.ApplicationConfiguration, []oam.Object, error) { appConfig := &v1alpha2.ApplicationConfiguration{ @@ -99,7 +99,7 @@ func (app *AppFile) buildOAM(ns string, io cmdutil.IOStreams, buildImage bool, t } } } - if !slience { + if !silence { io.Infof("\nRendering configs for service (%s)...\n", sname) } acComp, comp, err := svc.RenderService(tm, sname, ns, app.configGetter) diff --git a/pkg/application/app.go b/pkg/application/app.go index aea53e159..c858bc310 100644 --- a/pkg/application/app.go +++ b/pkg/application/app.go @@ -221,8 +221,8 @@ func (app *Application) GetTraitsByType(componentName, traitType string) (map[st } // TODO(wonderflow) add scope support here -func (app *Application) OAM(env *types.EnvMeta, io cmdutil.IOStreams, slience bool) ([]*v1alpha2.Component, *v1alpha2.ApplicationConfiguration, []oam.Object, error) { - comps, appConfig, scopes, err := app.RenderOAM(env.Namespace, io, app.tm, slience) +func (app *Application) OAM(env *types.EnvMeta, io cmdutil.IOStreams, silence bool) ([]*v1alpha2.Component, *v1alpha2.ApplicationConfiguration, []oam.Object, error) { + comps, appConfig, scopes, err := app.RenderOAM(env.Namespace, io, app.tm, silence) if err != nil { return nil, nil, nil, err } diff --git a/pkg/commands/ls.go b/pkg/commands/ls.go index 016757faf..1b4e15532 100644 --- a/pkg/commands/ls.go +++ b/pkg/commands/ls.go @@ -4,6 +4,8 @@ import ( "context" "strings" + "github.com/crossplane/oam-kubernetes-runtime/apis/core/v1alpha2" + gocmp "github.com/google/go-cmp/cmp" "github.com/gosuri/uitable" "github.com/spf13/cobra" @@ -70,13 +72,13 @@ func printComponentList(ctx context.Context, c client.Client, appName string, en } func mergeStagingComponents(deployed []apis.ComponentMeta, env *types.EnvMeta, ioStreams cmdutil.IOStreams) []apis.ComponentMeta { - apps, err := application.List(env.Name) + localApps, err := application.List(env.Name) if err != nil { ioStreams.Error("list application err", err) return deployed } var all []apis.ComponentMeta - for _, app := range apps { + for _, app := range localApps { comps, appConfig, _, err := app.OAM(env, ioStreams, true) if err != nil { ioStreams.Errorf("convert app %s err %v\n", app.Name, err) @@ -113,7 +115,11 @@ func mergeStagingComponents(deployed []apis.ComponentMeta, env *types.EnvMeta, i v.Traits[j] = t } aspec.Components[i] = v + if compMeta.AppConfig.Spec.Components[i].Traits == nil && len(v.Traits) == 0 { + compMeta.AppConfig.Spec.Components[i].Traits = make([]v1alpha2.ComponentTrait, 0) + } } + if !gocmp.Equal(compMeta.Component.Spec, *cspec) || !gocmp.Equal(compMeta.AppConfig.Spec, *aspec) { compMeta.Status = types.StatusStaging } diff --git a/pkg/controller/v1alpha1/routes/route_controller_test.go b/pkg/controller/v1alpha1/routes/route_controller_test.go index a1b9c610f..d08b83c55 100644 --- a/pkg/controller/v1alpha1/routes/route_controller_test.go +++ b/pkg/controller/v1alpha1/routes/route_controller_test.go @@ -5,6 +5,8 @@ import ( "errors" "time" + "github.com/crossplane/oam-kubernetes-runtime/pkg/oam" + "github.com/oam-dev/kubevela/api/v1alpha1" "github.com/crossplane/oam-kubernetes-runtime/apis/core/v1alpha2" @@ -134,7 +136,7 @@ var _ = Describe("Route Trait Integration Test", func() { "kind": "Route", "metadata": map[string]interface{}{ "labels": map[string]interface{}{ - "trait.oam.dev/type": "route", + oam.TraitTypeLabel: "route", }, }, "spec": map[string]interface{}{