add render-only to ini cmd and ignore route if domain is empty

This commit is contained in:
Hongchao Deng
2020-11-01 23:34:12 -08:00
parent e043e6b764
commit 7cfc80cd41
10 changed files with 43 additions and 15 deletions
+1
View File
@@ -139,6 +139,7 @@ core-uninstall: manifests
# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=charts/vela-core/crds
./hack/vela-templates/gen_definitions.sh
# Generate code
generate: controller-gen
-1
View File
@@ -1,4 +1,3 @@
version: "1.0-alpha.1"
name: lab3
services:
-1
View File
@@ -1,4 +1,3 @@
version: "1.0-alpha.1"
name: testapp
services:
+1 -2
View File
@@ -24,11 +24,10 @@ const DefaultAppfilePath = "./vela.yaml"
type AppFile struct {
Name string `json:"name"`
Version string `json:"version"`
CreateTime time.Time `json:"createTime,omitempty"`
UpdateTime time.Time `json:"updateTime,omitempty"`
Services map[string]Service `json:"services"`
Secrets map[string]string `json:"secrets"`
Secrets map[string]string `json:"secrets,omitempty"`
configGetter configGetter
}
+10 -5
View File
@@ -13,20 +13,25 @@ import (
cmdutil "github.com/oam-dev/kubevela/pkg/commands/util"
)
func (app *Application) Run(ctx context.Context, client client.Client, env *types.EnvMeta, io cmdutil.IOStreams) error {
func (app *Application) BuildRun(ctx context.Context, client client.Client, env *types.EnvMeta, io cmdutil.IOStreams) error {
components, appconfig, scopes, err := app.OAM(env, io, true)
if err != nil {
return err
}
for _, cmp := range components {
if err = CreateOrUpdateComponent(ctx, client, cmp); err != nil {
return app.Run(ctx, client, appconfig, components, scopes)
}
func (app *Application) Run(ctx context.Context, client client.Client,
ac *v1alpha2.ApplicationConfiguration, comps []*v1alpha2.Component, scopes []oam.Object) error {
for _, comp := range comps {
if err := CreateOrUpdateComponent(ctx, client, comp); err != nil {
return err
}
}
if err = CreateScopes(ctx, client, scopes); err != nil {
if err := CreateScopes(ctx, client, scopes); err != nil {
return err
}
return CreateOrUpdateAppConfig(ctx, client, appconfig)
return CreateOrUpdateAppConfig(ctx, client, ac)
}
func CreateOrUpdateComponent(ctx context.Context, client client.Client, comp *v1alpha2.Component) error {
+27 -2
View File
@@ -3,11 +3,13 @@ package commands
import (
"context"
"fmt"
"io/ioutil"
"strconv"
"cuelang.org/go/cue"
"github.com/AlecAivazis/survey/v2"
"github.com/fatih/color"
"github.com/ghodss/yaml"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -29,6 +31,7 @@ type appInitOptions struct {
appName string
workloadName string
workloadType string
renderOnly bool
}
// NewInitCommand init application
@@ -67,12 +70,30 @@ func NewInitCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
if err = o.Traits(); err != nil {
return err
}
_, err = oam.BaseRun(false, o.app, o.client, o.Env, ioStreams)
comps, appconfig, scopes, err := o.app.OAM(o.Env, ioStreams, true)
if err != nil {
return err
}
b, err := yaml.Marshal(o.app.AppFile)
if err != nil {
return err
}
err = ioutil.WriteFile("./vela.yaml", b, 0600)
if err != nil {
return err
}
o.IOStreams.Info("\nRendered and written deployment config to " + color.New(color.FgCyan).Sprint("vela.yaml"))
if o.renderOnly {
return nil
}
ctx := context.Background()
err = o.app.Run(ctx, o.client, appconfig, comps, scopes)
if err != nil {
return err
}
deployStatus, err := printTrackingDeployStatus(ctx, o.client, o.IOStreams, o.workloadName, o.appName, o.Env)
if err != nil {
return err
@@ -84,6 +105,7 @@ func NewInitCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
return printComponentStatus(context.Background(), o.client, o.IOStreams, o.workloadName, o.appName, o.Env)
},
}
cmd.Flags().BoolVar(&o.renderOnly, "render-only", false, "Rendering vela.yaml in current dir and do not deploy")
cmd.SetOut(ioStreams.Out)
return cmd
}
@@ -263,7 +285,10 @@ func (o *appInitOptions) Traits() error {
switch o.workloadType {
case "webservice":
//TODO(wonderflow) this should get from workload definition to know which trait should be suggestions
var suggestTraits = []string{"route"}
var suggestTraits = []string{}
if o.Env.Domain != "" {
suggestTraits = append(suggestTraits, "route")
}
for _, tr := range suggestTraits {
trait, err := GetCapabilityByName(tr, traits)
if err != nil {
+1 -1
View File
@@ -79,7 +79,7 @@ func (o *appRunOptions) LoadApp(cmd *cobra.Command, args []string) error {
func (o *appRunOptions) Run(io cmdutil.IOStreams) error {
o.Infof("Launching App Bundle \"%s\"\n", o.appName)
if err := o.app.Run(context.Background(), o.client, o.Env, io); err != nil {
if err := o.app.BuildRun(context.Background(), o.client, o.Env, io); err != nil {
return err
}
o.Info("SUCCEED")
+1 -1
View File
@@ -228,7 +228,7 @@ func (o *DeleteOptions) DeleteComponent(io cmdutil.IOStreams) (string, error) {
// Remove component from appConfig in k8s cluster
ctx := context.Background()
if err := app.Run(ctx, o.Client, o.Env, io); err != nil {
if err := app.BuildRun(ctx, o.Client, o.Env, io); err != nil {
return "", err
}
+1 -1
View File
@@ -234,7 +234,7 @@ func TraitOperationRun(ctx context.Context, c client.Client, env *types.EnvMeta,
if staging {
return "Staging saved", nil
}
err := appObj.Run(ctx, c, env, io)
err := appObj.BuildRun(ctx, c, env, io)
if err != nil {
return "", err
}
+1 -1
View File
@@ -112,7 +112,7 @@ func BaseRun(staging bool, app *application.Application, kubeClient client.Clien
if staging {
return "Staging saved", nil
}
if err := app.Run(context.Background(), kubeClient, Env, io); err != nil {
if err := app.BuildRun(context.Background(), kubeClient, Env, io); err != nil {
err = fmt.Errorf("create app err: %s", err)
return "", err
}