use unix command style and refactor to new design

This commit is contained in:
天元
2020-08-24 17:55:36 +08:00
parent 9efb1f60c7
commit 40da5a1961
46 changed files with 398 additions and 388 deletions

View File

@@ -22,45 +22,45 @@ mv bin/vela /usr/local/bin
#### env
```
$ vela env:init test --namespace test
$ vela env init test --namespace test
Create env succeed, current env is test
$ vela env test
NAME NAMESPACE
test test
$ vela env
$ vela env ls
NAME NAMESPACE
default default
test test
$ vela env:sw default
$ vela env sw default
Switch env succeed, current env is default
$ vela env:delete test
$ vela env delete test
test deleted
$ vela env:delete default
$ vela env delete default
Error: you can't delete current using default
```
#### workload run
```shell script
$ vela containerized:run app123 -p 80 --image nginx:1.9.4
$ vela comp run app123 -p 80 --image nginx:1.9.4
Creating AppConfig app123
SUCCEED
```
#### app
```
$ vela app:ls
$ vela app ls
NAME WORKLOAD TRAITS STATUS CREATED-TIME
app123 ContainerizedWorkload app123-manualscaler-trait False 2020-08-05 20:19:03 +0800 CST
poc08032042 ContainerizedWorkload True 2020-08-03 20:43:02 +0800 CST
poc1039 ContainerizedWorkload poc1039-manualscaler-trait False 2020-08-02 10:39:54 +0800 CST
$ vela app:status app123
$ vela app status app123
status: "False"
trait:
- apiVersion: core.oam.dev/v1alpha2
@@ -82,7 +82,7 @@ workload:
name: ""
$ vela app:delete app123
$ vela app delete app123
Deleting AppConfig "app123"
DELETE SUCCEED
```

View File

@@ -20,7 +20,7 @@ import (
"encoding/json"
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"cuelang.org/go/cue"
@@ -100,7 +100,7 @@ func ConvertTemplateJson2Object(in *runtime.RawExtension) (Capability, error) {
return t, err
}
func SetFlagBy(cmd *cobra.Command, v Parameter) {
func SetFlagBy(flags *pflag.FlagSet, v Parameter) {
switch v.Type {
case cue.IntKind:
var vv int64
@@ -114,11 +114,11 @@ func SetFlagBy(cmd *cobra.Command, v Parameter) {
case float64:
vv = int64(val)
}
cmd.Flags().Int64P(v.Name, v.Short, vv, v.Usage)
flags.Int64P(v.Name, v.Short, vv, v.Usage)
case cue.StringKind:
cmd.Flags().StringP(v.Name, v.Short, v.Default.(string), v.Usage)
flags.StringP(v.Name, v.Short, v.Default.(string), v.Usage)
case cue.BoolKind:
cmd.Flags().BoolP(v.Name, v.Short, v.Default.(bool), v.Usage)
flags.BoolP(v.Name, v.Short, v.Default.(bool), v.Usage)
case cue.NumberKind, cue.FloatKind:
var vv float64
switch val := v.Default.(type) {
@@ -131,9 +131,6 @@ func SetFlagBy(cmd *cobra.Command, v Parameter) {
case float64:
vv = val
}
cmd.Flags().Float64P(v.Name, v.Short, vv, v.Usage)
}
if v.Required && v.Name != "name" {
cmd.MarkFlagRequired(v.Name)
flags.Float64P(v.Name, v.Short, vv, v.Usage)
}
}

View File

@@ -100,26 +100,24 @@ func newCommand() *cobra.Command {
os.Exit(1)
}
// Getting Start
cmd.EnvCommandGroup(cmds, commandArgs, ioStream)
// Others
cmd.CapabilityCommandGroup(cmds, commandArgs, ioStream)
// System
cmd.SystemCommandGroup(cmds, commandArgs, ioStream)
cmds.AddCommand(
// Getting Start
cmd.NewEnvCommand(commandArgs, ioStream),
// Getting Start
NewVersionCommand(),
// Apps
cmd.NewAppsCommand(commandArgs, ioStream),
cmd.NewDeleteCommand(commandArgs, ioStream),
cmd.NewAppStatusCommand(commandArgs, ioStream),
cmd.NewAppShowCommand(commandArgs, ioStream),
cmd.NewRunCommand(commandArgs, ioStream),
// Workloads
cmd.AddCompCommands(commandArgs, ioStream),
// Capability Systems
cmd.CapabilityCommandGroup(commandArgs, ioStream),
// System
cmd.NewRefreshCommand(commandArgs, ioStream),
cmd.SystemCommandGroup(commandArgs, ioStream),
cmd.NewCompletionCommand(),
cmd.NewTraitsCommand(ioStream),
@@ -128,21 +126,12 @@ func newCommand() *cobra.Command {
cmd.NewDashboardCommand(commandArgs, ioStream),
)
// Workloads
if err = cmd.AddWorkloadCommands(cmds, commandArgs, ioStream); err != nil {
fmt.Println("Add workload commands from workloadDefinition err", err)
os.Exit(1)
}
// Traits
if err = cmd.AddTraitCommands(cmds, commandArgs, ioStream); err != nil {
fmt.Println("Add trait commands from traitDefinition err", err)
os.Exit(1)
}
if err = cmd.AddTraitDetachCommands(cmds, commandArgs, ioStream); err != nil {
fmt.Println("Add trait detach commands from traitDefinition err", err)
os.Exit(1)
}
// this is for mute klog
fset := flag.NewFlagSet("logs", flag.ContinueOnError)
klog.InitFlags(fset)

View File

@@ -19,31 +19,30 @@ vela [flags]
### SEE ALSO
* [vela app:delete](vela_app_delete.md) - Delete OAM Applications
* [vela app:ls](vela_app_ls.md) - List applications
* [vela app:run](vela_app_run.md) - Run a bundle of OAM Applications
* [vela app:show](vela_app_show.md) - get detail spec of your app
* [vela app:status](vela_app_status.md) - get status of an application
* [vela cap:add](vela_cap_add.md) - Add capability into cluster
* [vela cap:center:config](vela_cap_center_config.md) - Configure or add the capability center, default is local (built-in capabilities)
* [vela cap:center:sync](vela_cap_center_sync.md) - Sync capabilities from remote center, default to sync all centers
* [vela cap:ls](vela_cap_ls.md) - List all capabilities in center
* [vela cap:remove](vela_cap_remove.md) - Remove capability from cluster
* [vela app delete](vela_app_delete.md) - Delete OAM Applications
* [vela app ls](vela_app_ls.md) - List applications
* [vela app run](vela_app_run.md) - Run a bundle of OAM Applications
* [vela app show](vela_app_show.md) - get detail spec of your app
* [vela app status](vela_app_status.md) - get status of an application
* [vela cap add](vela_cap_add.md) - Add capability into cluster
* [vela cap center config](vela_cap_center_config.md) - Configure or add the capability center, default is local (built-in capabilities)
* [vela cap center sync](vela_cap_center_sync.md) - Sync capabilities from remote center, default to sync all centers
* [vela cap ls](vela_cap_ls.md) - List all capabilities in center
* [vela cap remove](vela_cap_remove.md) - Remove capability from cluster
* [vela completion](vela_completion.md) - Output shell completion code for the specified shell (bash or zsh)
* [vela containerized:run](vela_containerized_run.md) - Run containerized workloads
* [vela comp run](vela_comp_run.md) - Run containerized workloads
* [vela dashboard](vela_dashboard.md) - Setup API Server and launch Dashboard
* [vela deployment:run](vela_deployment_run.md) - Run deployment workloads
* [vela env](vela_env.md) - List environments
* [vela env:delete](vela_env_delete.md) - Delete environment
* [vela env:init](vela_env_init.md) - Create environments
* [vela env:sw](vela_env_sw.md) - Switch environments
* [vela env delete](vela_env_delete.md) - Delete environment
* [vela env init](vela_env_init.md) - Create environments
* [vela env sw](vela_env_sw.md) - Switch environments
* [vela rollout](vela_rollout.md) - Attach rollout trait to an app
* [vela rollout:detach](vela_rollout_detach.md) - Detach rollout trait from an app
* [vela scale](vela_scale.md) - Attach scale trait to an app
* [vela scale:detach](vela_scale_detach.md) - Detach scale trait from an app
* [vela system:info](vela_system_info.md) - show vela client and cluster version
* [vela system:init](vela_system_init.md) - Initialize vela on both client and server
* [vela system:update](vela_system_update.md) - Sync definition from cluster
* [vela system init](vela_system_init.md) - Initialize vela on both client and server
* [vela system update](vela_system_update.md) - Sync definition from cluster
* [vela traits](vela_traits.md) - List traits
* [vela version](vela_version.md) - Prints out build version information
* [vela workloads](vela_workloads.md) - List workloads

View File

@@ -1,4 +1,4 @@
## vela app:delete
## vela app delete
Delete OAM Applications
@@ -7,7 +7,7 @@ Delete OAM Applications
Delete OAM Applications
```
vela app:delete <APPLICATION_NAME>
vela app delete <APPLICATION_NAME>
```
### Examples
@@ -19,7 +19,7 @@ vela delete frontend
### Options
```
-h, --help help for app:delete
-h, --help help for app delete
```
### Options inherited from parent commands

View File

@@ -1,4 +1,4 @@
## vela app:ls
## vela app ls
List applications
@@ -7,20 +7,20 @@ List applications
List applications with workloads, traits, status and created time
```
vela app:ls
vela app ls
```
### Examples
```
vela app:ls
vela app ls
```
### Options
```
-a, --app string Application name
-h, --help help for app:ls
-h, --help help for app ls
```
### Options inherited from parent commands

View File

@@ -1,4 +1,4 @@
## vela app:run
## vela app run
Run a bundle of OAM Applications
@@ -7,7 +7,7 @@ Run a bundle of OAM Applications
Run a bundle of OAM Applications
```
vela app:run <APPLICATION_BUNDLE_NAME> [args]
vela app run <APPLICATION_BUNDLE_NAME> [args]
```
### Examples
@@ -20,7 +20,7 @@ vela run myAppBundle
```
-f, --file string launch application from provided appfile
-h, --help help for app:run
-h, --help help for app run
```
### Options inherited from parent commands

View File

@@ -1,4 +1,4 @@
## vela app:show
## vela app show
get detail spec of your app
@@ -7,19 +7,19 @@ get detail spec of your app
get detail spec of your app, including its workload and trait
```
vela app:show <APPLICATION-NAME> [flags]
vela app show <APPLICATION-NAME> [flags]
```
### Examples
```
vela app:show <APPLICATION-NAME>
vela app show <APPLICATION-NAME>
```
### Options
```
-h, --help help for app:show
-h, --help help for app show
```
### Options inherited from parent commands

View File

@@ -1,4 +1,4 @@
## vela app:status
## vela app status
get status of an application
@@ -7,19 +7,19 @@ get status of an application
get status of an application, including its workload and trait
```
vela app:status <APPLICATION-NAME> [flags]
vela app status <APPLICATION-NAME> [flags]
```
### Examples
```
vela app:status <APPLICATION-NAME>
vela app status <APPLICATION-NAME>
```
### Options
```
-h, --help help for app:status
-h, --help help for app status
```
### Options inherited from parent commands

View File

@@ -1,4 +1,4 @@
## vela cap:add
## vela cap add
Add capability into cluster
@@ -7,19 +7,19 @@ Add capability into cluster
Add capability into cluster
```
vela cap:add <center>/<name> [flags]
vela cap add <center>/<name> [flags]
```
### Examples
```
vela cap:add mycenter/route
vela cap add mycenter/route
```
### Options
```
-h, --help help for cap:add
-h, --help help for cap add
-t, --token string Github Repo token
```

View File

@@ -1,4 +1,4 @@
## vela cap:center:config
## vela cap center config
Configure or add the capability center, default is local (built-in capabilities)
@@ -7,19 +7,19 @@ Configure or add the capability center, default is local (built-in capabilities)
Configure or add the capability center, default is local (built-in capabilities)
```
vela cap:center:config <centerName> <centerUrl> [flags]
vela cap center config <centerName> <centerUrl> [flags]
```
### Examples
```
vela cap:center:config mycenter https://github.com/oam-dev/catalog/cap-center
vela cap center config mycenter https://github.com/oam-dev/catalog/cap-center
```
### Options
```
-h, --help help for cap:center:config
-h, --help help for cap center config
-t, --token string Github Repo token
```

View File

@@ -1,4 +1,4 @@
## vela cap:center:sync
## vela cap center sync
Sync capabilities from remote center, default to sync all centers
@@ -7,19 +7,19 @@ Sync capabilities from remote center, default to sync all centers
Sync capabilities from remote center, default to sync all centers
```
vela cap:center:sync [centerName] [flags]
vela cap center sync [centerName] [flags]
```
### Examples
```
vela cap:center:sync mycenter
vela cap center sync mycenter
```
### Options
```
-h, --help help for cap:center:sync
-h, --help help for cap center sync
```
### Options inherited from parent commands

View File

@@ -1,4 +1,4 @@
## vela cap:ls
## vela cap ls
List all capabilities in center
@@ -7,19 +7,19 @@ List all capabilities in center
List all capabilities in center
```
vela cap:ls [centerName] [flags]
vela cap ls [centerName] [flags]
```
### Examples
```
vela cap:ls
vela cap ls
```
### Options
```
-h, --help help for cap:ls
-h, --help help for cap ls
```
### Options inherited from parent commands

View File

@@ -1,4 +1,4 @@
## vela cap:remove
## vela cap remove
Remove capability from cluster
@@ -7,19 +7,19 @@ Remove capability from cluster
Remove capability from cluster
```
vela cap:remove <name> [flags]
vela cap remove <name> [flags]
```
### Examples
```
vela cap:remove route
vela cap remove route
```
### Options
```
-h, --help help for cap:remove
-h, --help help for cap remove
-t, --token string Github Repo token
```

View File

@@ -1,4 +1,4 @@
## vela containerized:run
## vela comp run
Run containerized workloads
@@ -7,20 +7,20 @@ Run containerized workloads
Run containerized workloads
```
vela containerized:run <appname> [args]
vela comp run -t <workloadType> <appname> [args]
```
### Examples
```
vela containerized:run frontend
vela comp run -t containerized frontend
```
### Options
```
-a, --app string create or add into an existing application group
-h, --help help for containerized:run
-h, --help help for comp run
-i, --image string specify app image
--name string
-p, --port int specify port for container (default 6379)

View File

@@ -1,40 +0,0 @@
## vela deployment:run
Run deployment workloads
### Synopsis
Run deployment workloads
```
vela deployment:run <appname> [args]
```
### Examples
```
vela deployment:run frontend
```
### Options
```
-a, --app string create or add into an existing application group
-h, --help help for deployment:run
--image string
--name string
--port int (default 8080)
-s, --staging only save changes locally without real update application
```
### Options inherited from parent commands
```
-e, --env string specify env name for application
```
### SEE ALSO
* [vela](vela.md) - ✈️ A Micro App Platform for Kubernetes.
###### Auto generated by spf13/cobra on 17-Aug-2020

View File

@@ -7,13 +7,13 @@ List environments
List all environments
```
vela env
vela env ls
```
### Examples
```
vela env [env-name]
vela env ls [env-name]
```
### Options

View File

@@ -1,4 +1,4 @@
## vela env:delete
## vela env delete
Delete environment
@@ -7,19 +7,19 @@ Delete environment
Delete environment
```
vela env:delete
vela env delete
```
### Examples
```
vela env:delete test
vela env delete test
```
### Options
```
-h, --help help for env:delete
-h, --help help for env delete
```
### Options inherited from parent commands

View File

@@ -1,4 +1,4 @@
## vela env:init
## vela env init
Create environments
@@ -7,19 +7,19 @@ Create environments
Create environment and switch to it
```
vela env:init <envName>
vela env init <envName>
```
### Examples
```
vela env:init test --namespace test
vela env init test --namespace test
```
### Options
```
-h, --help help for env:init
-h, --help help for env init
--namespace string specify K8s namespace for env (default "default")
```

View File

@@ -1,4 +1,4 @@
## vela env:sw
## vela env sw
Switch environments
@@ -7,19 +7,19 @@ Switch environments
switch to another environment
```
vela env:sw
vela env sw
```
### Examples
```
vela env:sw test
vela env sw test
```
### Options
```
-h, --help help for env:sw
-h, --help help for env sw
```
### Options inherited from parent commands

View File

@@ -1,4 +1,4 @@
## vela system:init
## vela system init
Initialize vela on both client and server
@@ -7,13 +7,13 @@ Initialize vela on both client and server
Install OAM runtime and vela builtin capabilities.
```
vela system:init [flags]
vela system init [flags]
```
### Options
```
-h, --help help for system:init
-h, --help help for system init
-v, --version string Override chart version
```

View File

@@ -1,4 +1,4 @@
## vela system:update
## vela system update
Sync definition from cluster
@@ -7,19 +7,19 @@ Sync definition from cluster
Refresh and sync definition files from cluster
```
vela system:update
vela system update
```
### Examples
```
vela system:update
vela system update
```
### Options
```
-h, --help help for system:update
-h, --help help for system update
```
### Options inherited from parent commands

View File

@@ -157,7 +157,7 @@ var _ = ginkgo.Describe("API Workload", func() {
gomega.Expect(err).NotTo(gomega.HaveOccurred())
var r apis.Response
err = json.Unmarshal(result, &r)
gomega.Expect(http.StatusOK).Should(gomega.Equal(r.Code))
gomega.Expect(http.StatusOK).Should(gomega.Equal(r.Code), string(result))
output := fmt.Sprintf("Creating App %s\nSUCCEED", workloadName)
gomega.Expect(r.Data.(string)).To(gomega.ContainSubstring(output))
})

View File

@@ -18,7 +18,7 @@ var _ = ginkgo.Describe("Application", func() {
e2e.EnvInitContext("env init", envName)
e2e.EnvShowContext("env show", envName)
e2e.EnvSwitchContext("env switch", envName)
e2e.WorkloadRunContext("run", fmt.Sprintf("vela %s:run %s -p 80 --image nginx:1.9.4",
e2e.WorkloadRunContext("run", fmt.Sprintf("vela comp run -t %s %s -p 80 --image nginx:1.9.4",
workloadType, applicationName))
e2e.ApplicationListContext("app ls", applicationName, "")
e2e.TraitManualScalerAttachContext("vela attach trait", traitAlias, applicationName)

View File

@@ -47,8 +47,8 @@ func AsyncExec(cli string) (*gexec.Session, error) {
func BeforeSuit() {
_, err := GetCliBinary()
gomega.Expect(err).NotTo(gomega.HaveOccurred())
Exec("vela system:init")
Exec("vela system init")
//Without this line, will hit issue like `<string>: Error: unknown command "scale" for "vela"`
Exec("vela system:update")
Exec("vela system update")
AsyncExec("vela dashboard &")
}

View File

@@ -20,7 +20,7 @@ var (
SystemInitContext = func(context string) bool {
return ginkgo.Context(context, func() {
ginkgo.It("Install OAM runtime and vela builtin capabilities.", func() {
output, err := Exec("vela system:init")
output, err := Exec("vela system init")
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(output).To(gomega.ContainSubstring("- Installing OAM Kubernetes Runtime"))
gomega.Expect(output).To(gomega.ContainSubstring("- Installing builtin capabilities"))
@@ -32,7 +32,7 @@ var (
SystemUpdateContext = func(context string) bool {
return ginkgo.Context(context, func() {
ginkgo.It("Synchronize workload/trait definitions from cluster", func() {
output, err := Exec("vela system:update")
output, err := Exec("vela system update")
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(output).To(gomega.ContainSubstring("workload definitions successfully synced"))
gomega.Expect(output).To(gomega.ContainSubstring("trait definitions successfully synced"))
@@ -44,7 +44,7 @@ var (
RefreshContext = func(context string) bool {
return ginkgo.Context(context, func() {
ginkgo.It("Sync commands from your Kubernetes cluster and locally cached them", func() {
output, err := Exec("vela system:update")
output, err := Exec("vela system update")
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(output).To(gomega.ContainSubstring("syncing workload definitions from cluster..."))
gomega.Expect(output).To(gomega.ContainSubstring("successfully synced"))
@@ -67,7 +67,7 @@ var (
EnvInitContext = func(context string, envName string) bool {
return ginkgo.Context(context, func() {
ginkgo.It("should print env initiation successful message", func() {
cli := fmt.Sprintf("vela env:init %s --namespace %s", envName, envName)
cli := fmt.Sprintf("vela env init %s --namespace %s", envName, envName)
output, err := Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedOutput := fmt.Sprintf("Create env succeed, current env is %s", envName)
@@ -79,7 +79,7 @@ var (
EnvShowContext = func(context string, envName string) bool {
return ginkgo.Context(context, func() {
ginkgo.It("should show detailed env message", func() {
cli := fmt.Sprintf("vela env %s", envName)
cli := fmt.Sprintf("vela env ls %s", envName)
output, err := Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(output).To(gomega.ContainSubstring("NAME"))
@@ -92,7 +92,7 @@ var (
EnvSwitchContext = func(context string, envName string) bool {
return ginkgo.Context(context, func() {
ginkgo.It("should show env switch message", func() {
cli := fmt.Sprintf("vela env:sw %s", envName)
cli := fmt.Sprintf("vela env sw %s", envName)
output, err := Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedOutput := fmt.Sprintf("Switch env succeed, current env is %s", envName)
@@ -104,7 +104,7 @@ var (
EnvDeleteContext = func(context string, envName string) bool {
return ginkgo.Context(context, func() {
ginkgo.It("should delete an env", func() {
cli := fmt.Sprintf("vela env:delete %s", envName)
cli := fmt.Sprintf("vela env delete %s", envName)
output, err := Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedOutput := fmt.Sprintf("%s deleted", envName)
@@ -115,7 +115,7 @@ var (
EnvDeleteCurrentUsingContext = func(context string, envName string) bool {
return ginkgo.Context(context, func() {
ginkgo.It("should delete all envs", func() {
cli := fmt.Sprintf("vela env:delete %s", envName)
cli := fmt.Sprintf("vela env delete %s", envName)
output, err := Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
expectedOutput := fmt.Sprintf("Error: you can't delete current using env %s", envName)
@@ -138,7 +138,7 @@ var (
WorkloadDeleteContext = func(context string, applicationName string) bool {
return ginkgo.Context(context, func() {
ginkgo.It("should print successful deletion information", func() {
cli := fmt.Sprintf("vela app:delete %s", applicationName)
cli := fmt.Sprintf("vela app delete %s", applicationName)
output, err := Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(output).To(gomega.ContainSubstring("DELETE SUCCEED"))
@@ -163,7 +163,7 @@ var (
ApplicationListContext = func(context string, applicationName string, traitAlias string) bool {
return ginkgo.Context("ls", func() {
ginkgo.It("should list all applications", func() {
output, err := Exec("vela app:ls")
output, err := Exec("vela app ls")
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(output).To(gomega.ContainSubstring("NAME"))
gomega.Expect(output).To(gomega.ContainSubstring(applicationName))
@@ -177,11 +177,11 @@ var (
ApplicationStatusContext = func(context string, applicationName string, workloadType string) bool {
return ginkgo.Context(context, func() {
ginkgo.It("should get status for the application", func() {
cli := fmt.Sprintf("vela app:status %s", applicationName)
cli := fmt.Sprintf("vela app status %s", applicationName)
output, err := Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(output).To(gomega.ContainSubstring(applicationName))
// TODO(zzxwill) need to check workloadType after app:status is refined
// TODO(zzxwill) need to check workloadType after app status is refined
//gomega.Expect(output).To(gomega.ContainSubstring(workloadType))
gomega.Expect(output).To(gomega.ContainSubstring("Workload"))
})
@@ -191,10 +191,10 @@ var (
ApplicationShowContext = func(context string, applicationName string, workloadType string) bool {
return ginkgo.Context(context, func() {
ginkgo.It("should show app information", func() {
cli := fmt.Sprintf("vela app:show %s", applicationName)
cli := fmt.Sprintf("vela app show %s", applicationName)
output, err := Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
// TODO(zzxwill) need to check workloadType after app:show is refined
// TODO(zzxwill) need to check workloadType after app show is refined
//gomega.Expect(output).To(gomega.ContainSubstring(workloadType))
gomega.Expect(output).To(gomega.ContainSubstring(applicationName))
})

2
e2e/env/env_test.go vendored
View File

@@ -20,7 +20,7 @@ var _ = ginkgo.Describe("Env", func() {
ginkgo.Context("env list", func() {
ginkgo.It("should list all envs", func() {
output, err := e2e.Exec("vela env")
output, err := e2e.Exec("vela env ls")
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(output).To(gomega.ContainSubstring("NAME"))
gomega.Expect(output).To(gomega.ContainSubstring("NAMESPACE"))

View File

@@ -11,7 +11,7 @@ import (
var _ = ginkgo.BeforeSuite(func() {
e2e.BeforeSuit()
})
}, 30)
func TestApplication(t *testing.T) {
gomega.RegisterFailHandler(ginkgo.Fail)

View File

@@ -17,7 +17,7 @@ var _ = ginkgo.Describe("Trait", func() {
e2e.RefreshContext("refresh")
e2e.EnvInitContext("env init", envName)
e2e.EnvSwitchContext("env switch", envName)
e2e.WorkloadRunContext("run", fmt.Sprintf("vela containerized:run %s -p 80 --image nginx:1.9.4", applicationName))
e2e.WorkloadRunContext("run", fmt.Sprintf("vela comp run -t containerized %s -p 80 --image nginx:1.9.4", applicationName))
e2e.TraitManualScalerAttachContext("vela attach trait", traitAlias, applicationName)

View File

@@ -18,11 +18,11 @@ var _ = ginkgo.Describe("Workload", func() {
e2e.RefreshContext("refresh")
e2e.EnvInitContext("env init", envName)
e2e.EnvSwitchContext("env switch", envName)
e2e.WorkloadRunContext("run", fmt.Sprintf("vela containerized:run %s -p 80 --image nginx:1.9.4", applicationName))
e2e.WorkloadRunContext("run", fmt.Sprintf("vela comp run -t containerized %s -p 80 --image nginx:1.9.4", applicationName))
ginkgo.Context("run without enough flags", func() {
ginkgo.It("should throw error message: some flags are NOT set", func() {
cli := fmt.Sprintf("vela containerized:run %s -p 80", notEnoughFlagsApplicationName)
cli := fmt.Sprintf("vela comp run -t containerized %s -p 80", notEnoughFlagsApplicationName)
output, err := e2e.Exec(cli)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
gomega.Expect(output).To(gomega.ContainSubstring("required flag(s) \"image\" not set"))

View File

@@ -64,7 +64,7 @@ func Load(envName, appName string) (*Application, error) {
return LoadFromFile(filepath.Join(appDir, appName+".yaml"))
}
func (app *Application) Save(envName, appName string) error {
func (app *Application) Save(envName string) error {
appDir, err := system.GetApplicationDir(envName)
if err != nil {
return fmt.Errorf("get app dir from env %s err %v", envName, err)
@@ -73,7 +73,7 @@ func (app *Application) Save(envName, appName string) error {
if err != nil {
return err
}
return ioutil.WriteFile(filepath.Join(appDir, appName+".yaml"), out, 0644)
return ioutil.WriteFile(filepath.Join(appDir, app.Name+".yaml"), out, 0644)
}
func (app *Application) Validate() error {

View File

@@ -33,23 +33,47 @@ import (
"github.com/spf13/cobra"
)
func CapabilityCommandGroup(parentCmd *cobra.Command, c types.Args, ioStream cmdutil.IOStreams) {
parentCmd.AddCommand(
NewCapCenterConfigCommand(ioStream),
func CapabilityCommandGroup(c types.Args, ioStream cmdutil.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "cap <command>",
Short: "Capability Management",
Long: "Capability Management with config, list, add, remove capabilities",
Annotations: map[string]string{
types.TagCommandType: types.TypeOthers,
},
}
cmd.AddCommand(
NewCenterCommand(c, ioStream),
NewCapListCommand(ioStream),
NewCapCenterSyncCommand(ioStream),
NewCapAddCommand(c, ioStream),
NewCapRemoveCommand(c, ioStream),
)
return cmd
}
func NewCenterCommand(c types.Args, ioStream cmdutil.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "center <command>",
Short: "Manage Capability Center",
Long: "Manage Capability Center with config, sync, list",
Annotations: map[string]string{
types.TagCommandType: types.TypeOthers,
},
}
cmd.AddCommand(
NewCapCenterConfigCommand(ioStream),
NewCapCenterSyncCommand(ioStream),
NewCapCenterListCommand(ioStream),
)
return cmd
}
func NewCapCenterConfigCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "cap:center:config <centerName> <centerUrl>",
Use: "config <centerName> <centerUrl>",
Short: "Configure or add the capability center, default is local (built-in capabilities)",
Long: "Configure or add the capability center, default is local (built-in capabilities)",
Example: `vela cap:center:config mycenter https://github.com/oam-dev/catalog/cap-center`,
Example: `vela cap center config mycenter https://github.com/oam-dev/catalog/cap-center`,
RunE: func(cmd *cobra.Command, args []string) error {
argsLength := len(args)
if argsLength < 2 {
@@ -99,10 +123,10 @@ func NewCapCenterConfigCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
func NewCapAddCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "cap:add <center>/<name>",
Use: "add <center>/<name>",
Short: "Add capability into cluster",
Long: "Add capability into cluster",
Example: `vela cap:add mycenter/route`,
Example: `vela cap add mycenter/route`,
RunE: func(cmd *cobra.Command, args []string) error {
argsLength := len(args)
if argsLength < 1 {
@@ -130,10 +154,10 @@ func NewCapAddCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command
func NewCapRemoveCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "cap:remove <name>",
Use: "remove <name>",
Short: "Remove capability from cluster",
Long: "Remove capability from cluster",
Example: `vela cap:remove route`,
Example: `vela cap remove route`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("you must specify <name> for capability you want to remove")
@@ -162,10 +186,10 @@ func NewCapRemoveCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Comma
func NewCapCenterSyncCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "cap:center:sync [centerName]",
Use: "sync [centerName]",
Short: "Sync capabilities from remote center, default to sync all centers",
Long: "Sync capabilities from remote center, default to sync all centers",
Example: `vela cap:center:sync mycenter`,
Example: `vela cap center sync mycenter`,
RunE: func(cmd *cobra.Command, args []string) error {
repos, err := plugins.LoadRepos()
if err != nil {
@@ -211,10 +235,10 @@ func NewCapCenterSyncCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
func NewCapListCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "cap:ls [centerName]",
Use: "ls [centerName]",
Short: "List all capabilities in center",
Long: "List all capabilities in center",
Example: `vela cap:ls`,
Example: `vela cap ls`,
RunE: func(cmd *cobra.Command, args []string) error {
var repoName string
if len(args) > 0 {
@@ -257,10 +281,10 @@ func NewCapListCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
func NewCapCenterListCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "cap:center:ls",
Use: "ls",
Short: "List all capability centers",
Long: "List all configured capability centers",
Example: `vela cap:center:ls`,
Example: `vela cap center ls`,
RunE: func(cmd *cobra.Command, args []string) error {
return ListCapCenters(args, ioStreams)
},
@@ -407,7 +431,7 @@ func GetSyncedCapabilities(repoName, addonName string) (types.Capability, error)
return t, nil
}
}
return types.Capability{}, fmt.Errorf("%s/%s not exist, try vela cap:center:sync %s to sync from remote", repoName, addonName, repoName)
return types.Capability{}, fmt.Errorf("%s/%s not exist, try vela cap center sync %s to sync from remote", repoName, addonName, repoName)
}
func ListCenterCapabilities(table *uitable.Table, repoDir string, ioStreams cmdutil.IOStreams) error {

View File

@@ -27,15 +27,14 @@ func newDeleteOptions(ioStreams cmdutil.IOStreams) *deleteOptions {
func newDeleteCommand() *cobra.Command {
return &cobra.Command{
Use: "app:delete <APPLICATION_NAME>",
Aliases: []string{"delete"},
Use: "delete <APPLICATION_NAME>",
DisableFlagsInUseLine: true,
Short: "Delete OAM Applications",
Long: "Delete OAM Applications",
Short: "Delete Applications",
Long: "Delete Applications",
Annotations: map[string]string{
types.TagCommandType: types.TypeApp,
},
Example: "vela delete frontend"}
Example: "vela app delete frontend"}
}
// NewDeleteCommand init new command

View File

@@ -16,37 +16,37 @@ import (
"github.com/spf13/cobra"
)
func EnvCommandGroup(parentCmd *cobra.Command, c types.Args, ioStream cmdutil.IOStreams) {
parentCmd.AddCommand(NewEnvInitCommand(c, ioStream),
NewEnvSwitchCommand(ioStream),
NewEnvDeleteCommand(ioStream),
NewEnvCommand(ioStream),
)
}
func NewEnvCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
ctx := context.Background()
func NewEnvCommand(c types.Args, ioStream cmdutil.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "env",
DisableFlagsInUseLine: true,
Short: "Manage application environments",
Long: "Manage application environments",
Annotations: map[string]string{
types.TagCommandType: types.TypeStart,
},
}
cmd.SetOut(ioStream.Out)
cmd.AddCommand(NewEnvListCommand(ioStream), NewEnvInitCommand(c, ioStream), NewEnvSwitchCommand(ioStream), NewEnvDeleteCommand(ioStream))
return cmd
}
func NewEnvListCommand(ioStream cmdutil.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "ls",
Aliases: []string{"list"},
DisableFlagsInUseLine: true,
Short: "List environments",
Long: "List all environments",
Example: `vela env [env-name]`,
Example: `vela env list [env-name]`,
RunE: func(cmd *cobra.Command, args []string) error {
return ListEnvs(ctx, args, ioStreams)
return ListEnvs(args, ioStream)
},
Annotations: map[string]string{
types.TagCommandType: types.TypeStart,
},
}
cmd.SetOut(ioStreams.Out)
cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
cmdutil.PrintUsageIntroduce(cmd, "Prepare environments for applications")
subcmds := []*cobra.Command{cmd, NewEnvInitCommand(types.Args{}, ioStreams), NewEnvSwitchCommand(ioStreams), NewEnvDeleteCommand(ioStreams)}
cmdutil.PrintUsage(cmd, subcmds)
cmdutil.PrintExample(cmd, subcmds)
cmdutil.PrintFlags(cmd, subcmds)
})
cmd.SetOut(ioStream.Out)
return cmd
}
@@ -54,11 +54,11 @@ func NewEnvInitCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command
var envArgs types.EnvMeta
ctx := context.Background()
cmd := &cobra.Command{
Use: "env:init <envName>",
Use: "init <envName>",
DisableFlagsInUseLine: true,
Short: "Create environments",
Long: "Create environment and switch to it",
Example: `vela env:init test --namespace test`,
Example: `vela env init test --namespace test`,
RunE: func(cmd *cobra.Command, args []string) error {
newClient, err := client.New(c.Config, client.Options{Scheme: c.Schema})
if err != nil {
@@ -78,11 +78,11 @@ func NewEnvInitCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command
func NewEnvDeleteCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
ctx := context.Background()
cmd := &cobra.Command{
Use: "env:delete",
Use: "delete",
DisableFlagsInUseLine: true,
Short: "Delete environment",
Long: "Delete environment",
Example: `vela env:delete test`,
Example: `vela env delete test`,
RunE: func(cmd *cobra.Command, args []string) error {
return DeleteEnv(ctx, args, ioStreams)
},
@@ -97,11 +97,12 @@ func NewEnvDeleteCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
func NewEnvSwitchCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
ctx := context.Background()
cmd := &cobra.Command{
Use: "env:sw",
Use: "switch",
Aliases: []string{"sw"},
DisableFlagsInUseLine: true,
Short: "Switch environments",
Long: "switch to another environment",
Example: `vela env:sw test`,
Example: `vela env switch test`,
RunE: func(cmd *cobra.Command, args []string) error {
return SwitchEnv(ctx, args, ioStreams)
},
@@ -113,7 +114,7 @@ func NewEnvSwitchCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
return cmd
}
func ListEnvs(ctx context.Context, args []string, ioStreams cmdutil.IOStreams) error {
func ListEnvs(args []string, ioStreams cmdutil.IOStreams) error {
table := uitable.New()
table.MaxColWidth = 60
table.AddRow("NAME", "CURRENT", "NAMESPACE")
@@ -134,7 +135,7 @@ func ListEnvs(ctx context.Context, args []string, ioStreams cmdutil.IOStreams) e
func DeleteEnv(ctx context.Context, args []string, ioStreams cmdutil.IOStreams) error {
if len(args) < 1 {
return fmt.Errorf("you must specify env name for vela env:delete command")
return fmt.Errorf("you must specify env name for vela env delete command")
}
envName := args[0]
msg, err := oam.DeleteEnv(envName)
@@ -146,7 +147,7 @@ func DeleteEnv(ctx context.Context, args []string, ioStreams cmdutil.IOStreams)
func CreateOrUpdateEnv(ctx context.Context, c client.Client, envArgs *types.EnvMeta, args []string, ioStreams cmdutil.IOStreams) error {
if len(args) < 1 {
return fmt.Errorf("you must specify env name for vela env:init command")
return fmt.Errorf("you must specify env name for vela env init command")
}
envName := args[0]
namespace := envArgs.Namespace

View File

@@ -63,11 +63,11 @@ func TestENV(t *testing.T) {
// List all env
var b bytes.Buffer
ioStream.Out = &b
err = ListEnvs(ctx, []string{}, ioStream)
err = ListEnvs([]string{}, ioStream)
assert.NoError(t, err)
assert.Equal(t, "NAME \tCURRENT\tNAMESPACE\ndefault\t \tdefault \nenv1 \t* \ttest1 \n", b.String())
b.Reset()
err = ListEnvs(ctx, []string{"env1"}, ioStream)
err = ListEnvs([]string{"env1"}, ioStream)
assert.NoError(t, err)
assert.Equal(t, "NAME\tCURRENT\tNAMESPACE\nenv1\t \ttest1 \n", b.String())
ioStream.Out = os.Stdout

View File

@@ -16,14 +16,33 @@ import (
var appName string
func NewAppsCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "app",
DisableFlagsInUseLine: true,
Short: "Manage applications",
Long: "Manage applications with ls, show, delete, run",
Example: `vela app <command>`,
Annotations: map[string]string{
types.TagCommandType: types.TypeApp,
},
}
cmd.AddCommand(NewAppsListCommand(c, ioStreams),
NewDeleteCommand(c, ioStreams),
NewAppStatusCommand(c, ioStreams),
NewAppShowCommand(c, ioStreams),
NewRunCommand(c, ioStreams))
return cmd
}
func NewAppsListCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
ctx := context.Background()
cmd := &cobra.Command{
Use: "app:ls",
Aliases: []string{"ls"},
Use: "ls",
DisableFlagsInUseLine: true,
Short: "List applications",
Long: "List applications with workloads, traits, status and created time",
Example: `vela app:ls`,
Example: `vela app ls`,
RunE: func(cmd *cobra.Command, args []string) error {
env, err := GetEnv(cmd)
if err != nil {
@@ -33,22 +52,21 @@ func NewAppsCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
if err != nil {
return err
}
printApplicationList(ctx, newClient, appName, env.Namespace)
printApplicationList(ctx, newClient, appName, env.Namespace, ioStreams)
return nil
},
Annotations: map[string]string{
types.TagCommandType: types.TypeApp,
},
}
cmd.PersistentFlags().StringVarP(&appName, "app", "a", "", "Application name")
cmd.Flags().StringVarP(&appName, "app", "a", "", "Application name")
return cmd
}
func printApplicationList(ctx context.Context, c client.Client, appName string, namespace string) {
func printApplicationList(ctx context.Context, c client.Client, appName string, namespace string, ioStreams cmdutil.IOStreams) {
applicationMetaList, err := oam.RetrieveApplicationsByName(ctx, c, appName, namespace)
if err != nil {
fmt.Printf("listing Trait DefinitionPath hit an issue: %s\n", err)
ioStreams.Infof("listing Trait DefinitionPath hit an issue: %s\n", err)
return
}
if applicationMetaList == nil {
@@ -62,6 +80,6 @@ func printApplicationList(ctx context.Context, c client.Client, appName string,
traitAlias := strings.Join(a.Traits, ",")
table.AddRow(a.Name, a.Workload, traitAlias, a.Status, a.CreatedTime)
}
fmt.Print(table.String())
ioStreams.Info(table.String())
}
}

View File

@@ -14,11 +14,11 @@ import (
func NewRefreshCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
ctx := context.Background()
cmd := &cobra.Command{
Use: "system:update",
Use: "update",
DisableFlagsInUseLine: true,
Short: "Sync definition from cluster",
Long: "Refresh and sync definition files from cluster",
Example: `vela system:update`,
Example: `vela system update`,
RunE: func(cmd *cobra.Command, args []string) error {
newClient, err := client.New(c.Config, client.Options{Scheme: c.Schema})
if err != nil {

View File

@@ -26,15 +26,14 @@ type appRunOptions struct {
func NewRunCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
o := &appRunOptions{IOStreams: ioStreams}
cmd := &cobra.Command{
Use: "app:run <APPLICATION_BUNDLE_NAME> [args]",
Aliases: []string{"run"},
Use: "run <APPLICATION_BUNDLE_NAME> [args]",
DisableFlagsInUseLine: true,
Short: "Run a bundle of OAM Applications",
Long: "Run a bundle of OAM Applications",
Annotations: map[string]string{
types.TagCommandType: types.TypeApp,
},
Example: "vela run myAppBundle",
Example: "vela app run myAppBundle",
RunE: func(cmd *cobra.Command, args []string) error {
newClient, err := client.New(c.Config, client.Options{Scheme: c.Schema})
o.client = newClient

View File

@@ -18,11 +18,10 @@ import (
func NewAppShowCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
ctx := context.Background()
cmd := &cobra.Command{
Use: "app:show <APPLICATION-NAME>",
Aliases: []string{"show"},
Use: "show <APPLICATION-NAME>",
Short: "get detail spec of your app",
Long: "get detail spec of your app, including its workload and trait",
Example: `vela app:show <APPLICATION-NAME>`,
Example: `vela app show <APPLICATION-NAME>`,
RunE: func(cmd *cobra.Command, args []string) error {
argsLength := len(args)
if argsLength == 0 {

View File

@@ -24,11 +24,10 @@ type ApplicationStatusMeta struct {
func NewAppStatusCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
ctx := context.Background()
cmd := &cobra.Command{
Use: "app:status <APPLICATION-NAME>",
Aliases: []string{"status"},
Use: "status <APPLICATION-NAME>",
Short: "get status of an application",
Long: "get status of an application, including its workload and trait",
Example: `vela app:status <APPLICATION-NAME>`,
Example: `vela status <APPLICATION-NAME>`,
RunE: func(cmd *cobra.Command, args []string) error {
argsLength := len(args)
if argsLength == 0 {

View File

@@ -77,17 +77,24 @@ var (
}
)
func SystemCommandGroup(parentCmd *cobra.Command, c types.Args, ioStream cmdutil.IOStreams) {
parentCmd.AddCommand(NewAdminInitCommand(c, ioStream),
NewAdminInfoCommand(ioStream),
)
func SystemCommandGroup(c types.Args, ioStream cmdutil.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "system",
Short: "system management utilities",
Long: "system management utilities",
Annotations: map[string]string{
types.TagCommandType: types.TypeSystem,
},
}
cmd.AddCommand(NewAdminInitCommand(c, ioStream), NewAdminInfoCommand(ioStream), NewRefreshCommand(c, ioStream))
return cmd
}
func NewAdminInfoCommand(ioStreams cmdutil.IOStreams) *cobra.Command {
i := &infoCmd{out: ioStreams.Out}
cmd := &cobra.Command{
Use: "system:info",
Use: "info",
Short: "show vela client and cluster version",
Long: "show vela client and cluster version",
RunE: func(cmd *cobra.Command, args []string) error {
@@ -116,7 +123,7 @@ func (i *infoCmd) run(ioStreams cmdutil.IOStreams) error {
func NewAdminInitCommand(c types.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
i := &initCmd{ioStreams: ioStreams}
cmd := &cobra.Command{
Use: "system:init",
Use: "init",
Short: "Initialize vela on both client and server",
Long: "Install OAM runtime and vela builtin capabilities.",
RunE: func(cmd *cobra.Command, args []string) error {
@@ -373,7 +380,7 @@ func GetOAMReleaseVersion() (string, error) {
return result.Chart.AppVersion(), nil
}
}
return "", errors.New("oam-kubernetes-runtime not found in your kubernetes cluster, try `vela system:init` to install.")
return "", errors.New("oam-kubernetes-runtime not found in your kubernetes cluster, try `vela system init` to install.")
}
func filterRepos(repos []*repo.Entry) []*repo.Entry {

View File

@@ -63,8 +63,16 @@ func AddTraitCommands(parentCmd *cobra.Command, c types.Args, ioStreams cmdutil.
if err != nil {
return err
}
if err := o.AddOrUpdateTrait(cmd, args); err != nil {
return err
detach, _ := cmd.Flags().GetBool(TraitDetach)
if detach {
if err := o.DetachTrait(cmd, args); err != nil {
return err
}
o.Detach = true
} else {
if err := o.AddOrUpdateTrait(cmd, args); err != nil {
return err
}
}
return o.Run(cmd, ctx)
},
@@ -74,10 +82,11 @@ func AddTraitCommands(parentCmd *cobra.Command, c types.Args, ioStreams cmdutil.
}
pluginCmd.SetOut(ioStreams.Out)
for _, v := range tmp.Parameters {
types.SetFlagBy(pluginCmd, v)
types.SetFlagBy(pluginCmd.Flags(), v)
}
pluginCmd.Flags().StringP(App, "a", "", "create or add into an existing application group")
pluginCmd.Flags().BoolP(Staging, "s", false, "only save changes locally without real update application")
pluginCmd.Flags().BoolP(TraitDetach, "", false, "detach trait from component")
parentCmd.AddCommand(pluginCmd)
}
@@ -130,54 +139,7 @@ func (o *commandOptions) AddOrUpdateTrait(cmd *cobra.Command, args []string) err
return err
}
o.app = app
return o.app.Save(o.Env.Name, o.appName)
}
func AddTraitDetachCommands(parentCmd *cobra.Command, c types.Args, ioStreams cmdutil.IOStreams) error {
templates, err := plugins.LoadInstalledCapabilityWithType(types.TypeTrait)
if err != nil {
return err
}
ctx := context.Background()
for _, tmp := range templates {
tmp := tmp
var name = tmp.Name
pluginCmd := &cobra.Command{
Use: name + ":detach <appname>",
DisableFlagsInUseLine: true,
Short: "Detach " + name + " trait from an app",
Long: "Detach " + name + " trait from an app",
Example: "vela " + name + ":detach frontend",
RunE: func(cmd *cobra.Command, args []string) error {
o := NewCommandOptions(ioStreams)
newClient, err := client.New(c.Config, client.Options{Scheme: c.Schema})
if err != nil {
return err
}
o.Env, err = GetEnv(cmd)
if err != nil {
return err
}
o.Client = newClient
if err := o.DetachTrait(cmd, args); err != nil {
return err
}
o.Template = tmp
o.Detach = true
return o.Run(cmd, ctx)
},
Annotations: map[string]string{
types.TagCommandType: types.TypeTraits,
},
}
pluginCmd.Flags().StringP(App, "a", "", "create or add into an existing application group")
pluginCmd.Flags().BoolP(Staging, "s", false, "only save changes locally without real update application")
pluginCmd.SetOut(ioStreams.Out)
parentCmd.AddCommand(pluginCmd)
}
return nil
return o.app.Save(o.Env.Name)
}
func (o *commandOptions) DetachTrait(cmd *cobra.Command, args []string) error {
@@ -193,7 +155,7 @@ func (o *commandOptions) DetachTrait(cmd *cobra.Command, args []string) error {
return err
}
o.app = app
return o.app.Save(o.Env.Name, o.appName)
return o.app.Save(o.Env.Name)
}
func (o *commandOptions) Run(cmd *cobra.Command, ctx context.Context) error {

View File

@@ -5,17 +5,21 @@ import (
"errors"
"github.com/cloud-native-application/rudrx/pkg/oam"
"github.com/cloud-native-application/rudrx/pkg/plugins"
"github.com/cloud-native-application/rudrx/api/types"
"github.com/cloud-native-application/rudrx/pkg/cmd/util"
"github.com/cloud-native-application/rudrx/pkg/plugins"
"github.com/spf13/cobra"
"sigs.k8s.io/controller-runtime/pkg/client"
)
const Staging = "staging"
const App = "app"
const (
Staging = "staging"
App = "app"
WorkloadType = "type"
TraitDetach = "detach"
)
type runOptions oam.RunOptions
@@ -23,69 +27,113 @@ func newRunOptions(ioStreams util.IOStreams) *runOptions {
return &runOptions{IOStreams: ioStreams}
}
func AddWorkloadCommands(parentCmd *cobra.Command, c types.Args, ioStreams util.IOStreams) error {
templates, err := plugins.LoadInstalledCapabilityWithType(types.TypeWorkload)
func AddCompCommands(c types.Args, ioStreams util.IOStreams) *cobra.Command {
compCommands := &cobra.Command{
Use: "comp <commands>",
DisableFlagsInUseLine: true,
Short: "Manage Components",
Long: "Manage Components",
Annotations: map[string]string{
types.TagCommandType: types.TypeWorkloads,
},
}
compCommands.AddCommand(NewCompRunCommands(c, ioStreams))
return compCommands
}
func NewCompRunCommands(c types.Args, ioStreams util.IOStreams) *cobra.Command {
runCmd := &cobra.Command{
Use: "run [args]",
DisableFlagsInUseLine: true,
// Dynamic flag parse in compeletion
DisableFlagParsing: true,
Short: "Init and Run workloads",
Long: "Init and Run workloads",
Example: "vela comp run -t <workload-type>",
RunE: func(cmd *cobra.Command, args []string) error {
o := newRunOptions(ioStreams)
newClient, err := client.New(c.Config, client.Options{Scheme: c.Schema})
if err != nil {
return err
}
o.KubeClient = newClient
o.Env, err = GetEnv(cmd)
if err != nil {
return err
}
if err := o.Complete(cmd, args, context.TODO()); err != nil {
return err
}
return o.Run(cmd)
},
Annotations: map[string]string{
types.TagCommandType: types.TypeWorkloads,
},
}
runCmd.SetOut(ioStreams.Out)
runCmd.Flags().StringP(App, "a", "", "create or add into an existing application group")
runCmd.Flags().BoolP(Staging, "s", false, "only save changes locally without real update application")
runCmd.Flags().StringP(WorkloadType, "t", "", "specify workload type for application")
return runCmd
}
func GetWorkloadNameFromArgs(args []string) (string, error) {
argsLength := len(args)
if argsLength < 1 {
return "", errors.New("must specify name for workload")
}
return args[0], nil
}
func (o *runOptions) Complete(cmd *cobra.Command, args []string, ctx context.Context) error {
flags := cmd.Flags()
flags.ParseErrorsWhitelist.UnknownFlags = true
// First parse, figure out which workloadType it is.
if err := flags.Parse(args); err != nil {
return err
}
workloadName, err := GetWorkloadNameFromArgs(flags.Args())
if err != nil {
return err
}
for _, tmp := range templates {
tmp := tmp
var name = tmp.Name
pluginCmd := &cobra.Command{
Use: name + ":run <appname> [args]",
DisableFlagsInUseLine: true,
Short: "Run " + name + " workloads",
Long: "Run " + name + " workloads",
Example: "vela " + name + ":run frontend",
RunE: func(cmd *cobra.Command, args []string) error {
o := newRunOptions(ioStreams)
o.WorkloadType = name
newClient, err := client.New(c.Config, client.Options{Scheme: c.Schema})
if err != nil {
return err
}
o.KubeClient = newClient
o.Env, err = GetEnv(cmd)
if err != nil {
return err
}
o.Template = tmp
if err := o.Complete(cmd, args, context.TODO()); err != nil {
return err
}
return o.Run(cmd)
},
Annotations: map[string]string{
types.TagCommandType: types.TypeWorkloads,
},
}
pluginCmd.SetOut(ioStreams.Out)
for _, v := range tmp.Parameters {
types.SetFlagBy(pluginCmd, v)
}
pluginCmd.Flags().StringP(App, "a", "", "create or add into an existing application group")
pluginCmd.Flags().BoolP(Staging, "s", false, "only save changes locally without real update application")
parentCmd.AddCommand(pluginCmd)
appGroup, err := flags.GetString(App)
if err != nil {
return err
}
return nil
}
func (o *runOptions) Complete(cmd *cobra.Command, args []string, ctx context.Context) error {
argsLength := len(args)
if argsLength < 1 {
return errors.New("must specify name for workload")
workloadType, err := flags.GetString(WorkloadType)
if err != nil {
return err
}
workloadName := args[0]
template := o.Template
appGroup := cmd.Flag(App).Value.String()
envName := o.Env.Name
// Dynamic load flags
template, err := plugins.LoadCapabilityByName(workloadType)
if err != nil {
return err
}
for _, v := range template.Parameters {
types.SetFlagBy(flags, v)
}
// Second parse, parse parameters of this workload.
if err = flags.Parse(args); err != nil {
return err
}
var flagSet = cmd.Flags()
app, err := oam.BaseComplete(envName, workloadName, appGroup, flagSet, template)
app, err := oam.BaseComplete(envName, workloadName, appGroup, flagSet, workloadType)
if err != nil {
return err
}
o.App = app
return err
}

View File

@@ -63,7 +63,7 @@ func CreateOrUpdateEnv(ctx context.Context, c client.Client, envName string, nam
if err = ioutil.WriteFile(curEnvPath, []byte(envName), 0644); err != nil {
return err, message
}
message = fmt.Sprintf("Create env succeed, current env is " + envName + " namespace is " + envArgs.Namespace + ", use --namespace=<namespace> to specify namespace with env:init")
message = fmt.Sprintf("Create env succeed, current env is " + envName + " namespace is " + envArgs.Namespace + ", use --namespace=<namespace> to specify namespace with env init")
return nil, message
}

View File

@@ -5,6 +5,8 @@ import (
"fmt"
"strconv"
"github.com/cloud-native-application/rudrx/pkg/plugins"
"github.com/spf13/pflag"
"github.com/cloud-native-application/rudrx/api/types"
@@ -16,9 +18,7 @@ import (
)
type RunOptions struct {
Template types.Capability
Env *types.EnvMeta
WorkloadType string
WorkloadName string
KubeClient client.Client
App *application.Application
@@ -27,7 +27,7 @@ type RunOptions struct {
util.IOStreams
}
func BaseComplete(envName string, workloadName string, appGroup string, flagSet *pflag.FlagSet, template types.Capability) (*application.Application, error) {
func LoadIfExist(envName string, workloadName string, appGroup string) (*application.Application, error) {
var appName string
if appGroup != "" {
appName = appGroup
@@ -43,10 +43,25 @@ func BaseComplete(envName string, workloadName string, appGroup string, flagSet
if app.Components == nil {
app.Components = make(map[string]map[string]interface{})
}
return app, nil
}
func BaseComplete(envName string, workloadName string, appGroup string, flagSet *pflag.FlagSet, workloadType string) (*application.Application, error) {
app, err := LoadIfExist(envName, workloadName, appGroup)
if err != nil {
return nil, err
}
tp, workloadData := app.GetWorkload(workloadName)
if tp == "" {
if workloadType == "" {
return nil, fmt.Errorf("must specify workload type for application %s", workloadName)
}
// Not exist
tp = template.Name
tp = workloadType
}
template, err := plugins.LoadCapabilityByName(tp)
if err != nil {
return nil, err
}
for _, v := range template.Parameters {
@@ -72,7 +87,7 @@ func BaseComplete(envName string, workloadName string, appGroup string, flagSet
if err = app.SetWorkload(workloadName, tp, workloadData); err != nil {
return app, err
}
return app, app.Save(envName, appName)
return app, app.Save(envName)
}
func BaseRun(staging bool, App *application.Application, kubeClient client.Client, Env *types.EnvMeta) (string, error) {

View File

@@ -25,14 +25,8 @@ func CreateWorkload(c *gin.Context) {
fs.String(f.Name, f.Value, "")
}
evnName := body.EnvName
var template types.Capability
template, err := plugins.LoadCapabilityByName(body.WorkloadType)
if err != nil {
util.HandleError(c, util.StatusInternalServerError, err.Error())
return
}
appObj, err := oam.BaseComplete(evnName, body.WorkloadName, body.AppGroup, fs, template)
appObj, err := oam.BaseComplete(evnName, body.WorkloadName, body.AppGroup, fs, body.WorkloadType)
if err != nil {
util.HandleError(c, util.StatusInternalServerError, err.Error())
return