From 7f7a9dcac02fbfdc32bf53dd84f2c5b1b6079bc2 Mon Sep 17 00:00:00 2001 From: Jianbo Sun Date: Wed, 12 Jan 2022 17:43:08 +0800 Subject: [PATCH] Feat: vela up support read from stdin && refine CLI output && fix vela addon command (#3080) * Feat: vela up support read from stdin Signed-off-by: Jianbo Sun * Fix: addon name missed in output and fix test Signed-off-by: Jianbo Sun * Chore: refine CLI output Signed-off-by: Jianbo Sun Fix: add retry-on conflict on CLI Signed-off-by: Jianbo Sun --- e2e/addon/addon_test.go | 6 ++-- pkg/addon/addon.go | 32 ++++++++++------- references/cli/addon-registry.go | 32 ++++++++--------- references/cli/addon.go | 57 +++++++++++++++++-------------- references/cli/cli.go | 4 +-- references/cli/cluster.go | 15 ++++---- references/cli/components.go | 2 +- references/cli/cue_packages.go | 5 +-- references/cli/def.go | 22 ++++++------ references/cli/env.go | 4 +-- references/cli/help.go | 3 ++ references/cli/init.go | 2 +- references/cli/logs.go | 2 +- references/cli/portforward.go | 2 +- references/cli/show.go | 2 +- references/cli/status.go | 3 +- references/cli/system.go | 4 +-- references/cli/traits.go | 2 +- references/cli/workflow.go | 22 ++++++------ references/common/application.go | 4 +++ test/e2e-addon-test/addon_test.go | 4 +-- 21 files changed, 125 insertions(+), 104 deletions(-) diff --git a/e2e/addon/addon_test.go b/e2e/addon/addon_test.go index 1d59f5b3a..9ed82bb3c 100644 --- a/e2e/addon/addon_test.go +++ b/e2e/addon/addon_test.go @@ -47,13 +47,13 @@ var _ = Describe("Addon Test", func() { It("Enable addon test-addon", func() { output, err := e2e.Exec("vela addon enable test-addon") Expect(err).NotTo(HaveOccurred()) - Expect(output).To(ContainSubstring("Successfully enable addon")) + Expect(output).To(ContainSubstring("enabled Successfully.")) }) It("Upgrade addon test-addon", func() { output, err := e2e.Exec("vela addon upgrade test-addon") Expect(err).NotTo(HaveOccurred()) - Expect(output).To(ContainSubstring("Successfully enable addon")) + Expect(output).To(ContainSubstring("enabled Successfully.")) }) It("Disable addon test-addon", func() { @@ -68,7 +68,7 @@ var _ = Describe("Addon Test", func() { It("Enable addon with input", func() { output, err := e2e.LongTimeExec("vela addon enable test-addon example=redis", 300*time.Second) Expect(err).NotTo(HaveOccurred()) - Expect(output).To(ContainSubstring("Successfully enable addon")) + Expect(output).To(ContainSubstring("enabled Successfully.")) }) It("Disable addon test-addon", func() { diff --git a/pkg/addon/addon.go b/pkg/addon/addon.go index 6eb8859c9..373b2a6ec 100644 --- a/pkg/addon/addon.go +++ b/pkg/addon/addon.go @@ -42,6 +42,7 @@ import ( k8syaml "k8s.io/apimachinery/pkg/runtime/serializer/yaml" types2 "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/rest" + "k8s.io/client-go/util/retry" "k8s.io/klog/v2" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/yaml" @@ -1010,21 +1011,26 @@ func (h *Installer) continueOrRestartWorkflow() error { // this case means user add a new cluster and user want to restart workflow to dispatch addon resources to new cluster // re-apply app won't help app restart workflow case app.Status.Phase == common2.ApplicationRunning: - app.Status.Workflow = nil - - if err := h.cli.Status().Update(context.TODO(), app); err != nil { - return err - } - return nil - // this case means addon last installation meet some error and workflow has been suspend by app controller + // we can use retry on conflict here in CLI, because we want to update the status in this CLI operation. + return retry.RetryOnConflict(retry.DefaultBackoff, func() (err error) { + if err = h.cli.Get(h.ctx, client.ObjectKey{Namespace: app.Namespace, Name: app.Name}, app); err != nil { + return + } + app.Status.Workflow = nil + return h.cli.Status().Update(h.ctx, app) + }) + // this case means addon last installation meet some error and workflow has been suspended by app controller // re-apply app won't help app workflow continue case app.Status.Workflow != nil && app.Status.Workflow.Suspend: - mergePatch := client.MergeFrom(app.DeepCopy()) - app.Status.Workflow.Suspend = false - if err := h.cli.Status().Patch(h.ctx, app, mergePatch); err != nil { - return err - } - return nil + // we can use retry on conflict here in CLI, because we want to update the status in this CLI operation. + return retry.RetryOnConflict(retry.DefaultBackoff, func() (err error) { + if err = h.cli.Get(h.ctx, client.ObjectKey{Namespace: app.Namespace, Name: app.Name}, app); err != nil { + return + } + mergePatch := client.MergeFrom(app.DeepCopy()) + app.Status.Workflow.Suspend = false + return h.cli.Status().Patch(h.ctx, app, mergePatch) + }) } return nil } diff --git a/references/cli/addon-registry.go b/references/cli/addon-registry.go index 81aeaf31f..fcb1470a3 100644 --- a/references/cli/addon-registry.go +++ b/references/cli/addon-registry.go @@ -44,8 +44,8 @@ const ( func NewAddonRegistryCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Command { cmd := &cobra.Command{ Use: "registry", - Short: "Manage addon registry", - Long: "Manage addon registry", + Short: "Manage addon registry.", + Long: "Manage addon registry.", } cmd.AddCommand( NewAddAddonRegistryCommand(c, ioStreams), @@ -61,9 +61,9 @@ func NewAddonRegistryCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra. func NewAddAddonRegistryCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Command { cmd := &cobra.Command{ Use: "add", - Short: "Add an addon registry", - Long: "Add an addon registry", - Example: `"vela addon registry add my-repo --type OSS --endpoint=xxxxx --bucket=xxxx or vela addon registry add my-repo --type git --endpoint=xxxxx --path=xxxx --gitToken=xxx"`, + Short: "Add an addon registry.", + Long: "Add an addon registry.", + Example: `"vela addon registry add --type OSS --endpoint= --bucket= or vela addon registry add my-repo --type git --endpoint= --path= --gitToken="`, RunE: func(cmd *cobra.Command, args []string) error { registry, err := getRegistryFromArgs(cmd, args) if err != nil { @@ -83,9 +83,9 @@ func NewAddAddonRegistryCommand(c common.Args, ioStreams cmdutil.IOStreams) *cob func NewGetAddonRegistryCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Command { return &cobra.Command{ Use: "get", - Short: "Get an addon registry", - Long: "Get an addon registry", - Example: "vela addon registry get my-repo ", + Short: "Get an addon registry.", + Long: "Get an addon registry.", + Example: "vela addon registry get ", RunE: func(cmd *cobra.Command, args []string) error { if len(args) != 1 { return errors.New("must specify the registry name") @@ -104,8 +104,8 @@ func NewGetAddonRegistryCommand(c common.Args, ioStreams cmdutil.IOStreams) *cob func NewListAddonRegistryCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Command { return &cobra.Command{ Use: "list", - Short: "List addon registries", - Long: "List addon registries", + Short: "List addon registries.", + Long: "List addon registries.", Example: "vela addon registry list", RunE: func(cmd *cobra.Command, args []string) error { if err := listAddonRegistry(context.Background(), c); err != nil { @@ -120,9 +120,9 @@ func NewListAddonRegistryCommand(c common.Args, ioStreams cmdutil.IOStreams) *co func NewUpdateAddonRegistryCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Command { cmd := &cobra.Command{ Use: "update", - Short: "Update an addon registry", - Long: "Update an addon registry", - Example: "vela addon registry update my-repo --type OSS --endpoint=xxxxx --bucket=xxxx", + Short: "Update an addon registry.", + Long: "Update an addon registry.", + Example: "vela addon registry update --type OSS --endpoint= --bucket=", RunE: func(cmd *cobra.Command, args []string) error { registry, err := getRegistryFromArgs(cmd, args) if err != nil { @@ -144,7 +144,7 @@ func NewDeleteAddonRegistryCommand(c common.Args, ioStreams cmdutil.IOStreams) * Use: "delete", Short: "Delete an addon registry", Long: "Delete an addon registry", - Example: "vela addon registry delete my-repo ", + Example: "vela addon registry delete ", RunE: func(cmd *cobra.Command, args []string) error { if len(args) != 1 { return errors.New("must specify the registry name") @@ -261,8 +261,8 @@ func updateAddonRegistry(ctx context.Context, c common.Args, registry pkgaddon.R func parseArgsFromFlag(cmd *cobra.Command) { cmd.Flags().StringP(addonRegistryType, "", "", "specify the addon registry type") cmd.Flags().StringP(addonEndpoint, "", "", "specify the addon registry endpoint") - cmd.Flags().StringP(addonOssBucket, "", "", "specify the OSS bucket") - cmd.Flags().StringP(addonPath, "", "", "specify the repo path") + cmd.Flags().StringP(addonOssBucket, "", "", "specify the OSS bucket name") + cmd.Flags().StringP(addonPath, "", "", "specify the addon registry OSS path") cmd.Flags().StringP(addonGitToken, "", "", "specify the github repo token") } diff --git a/references/cli/addon.go b/references/cli/addon.go index 23d71f9f1..48cff95b8 100644 --- a/references/cli/addon.go +++ b/references/cli/addon.go @@ -113,7 +113,7 @@ func NewAddonEnableCommand(c common.Args, ioStream cmdutil.IOStreams) *cobra.Com cmd := &cobra.Command{ Use: "enable", Short: "enable an addon", - Long: "enable an addon in cluster", + Long: "enable an addon in cluster.", Example: "vela addon enable ", RunE: func(cmd *cobra.Command, args []string) error { @@ -133,45 +133,54 @@ func NewAddonEnableCommand(c common.Args, ioStream cmdutil.IOStreams) *cobra.Com return err } addonOrDir := args[0] - var name string + var name = addonOrDir if _, err := os.Stat(addonOrDir); err == nil { // args[0] is a local path install with local dir, use base dir name as addonName - name := filepath.Base(addonOrDir) + name = filepath.Base(addonOrDir) err = enableAddonByLocal(ctx, name, addonOrDir, k8sClient, config, addonArgs) if err != nil { return err } } else { - err = enableAddon(ctx, k8sClient, config, addonOrDir, addonArgs) + err = enableAddon(ctx, k8sClient, config, name, addonArgs) if err != nil { return err } } - fmt.Printf("Successfully enable addon:%s\n", name) - endpoints, _ := GetServiceEndpoints(ctx, k8sClient, pkgaddon.Convert2AppName(name), types.DefaultKubeVelaNS, c) - if len(endpoints) > 0 { - table := tablewriter.NewWriter(os.Stdout) - table.SetColWidth(100) - table.SetHeader([]string{"Cluster", "Ref(Kind/Namespace/Name)", "Endpoint"}) - for _, endpoint := range endpoints { - table.Append([]string{endpoint.Cluster, fmt.Sprintf("%s/%s/%s", endpoint.Ref.Kind, endpoint.Ref.Namespace, endpoint.Ref.Name), endpoint.String()}) - } - fmt.Printf("Please access the %s from the following endpoints:\n", name) - table.Render() - } + fmt.Printf("Addon: %s enabled Successfully.\n", name) + AdditionalEndpointPrinter(ctx, c, k8sClient, name) return nil }, } return cmd } +// AdditionalEndpointPrinter will print endpoints +func AdditionalEndpointPrinter(ctx context.Context, c common.Args, k8sClient client.Client, name string) { + endpoints, _ := GetServiceEndpoints(ctx, k8sClient, pkgaddon.Convert2AppName(name), types.DefaultKubeVelaNS, c) + if len(endpoints) > 0 { + table := tablewriter.NewWriter(os.Stdout) + table.SetColWidth(100) + table.SetHeader([]string{"Cluster", "Ref(Kind/Namespace/Name)", "Endpoint"}) + for _, endpoint := range endpoints { + table.Append([]string{endpoint.Cluster, fmt.Sprintf("%s/%s/%s", endpoint.Ref.Kind, endpoint.Ref.Namespace, endpoint.Ref.Name), endpoint.String()}) + } + fmt.Printf("Please access the %s from the following endpoints:\n", name) + table.Render() + return + } + if name == "velaux" { + fmt.Println(`Please use command: "vela port-forward -n vela-system addon-velaux 9082:80" and Select "Cluster: local | Namespace: vela-system | Component: velaux | Kind: Service" to check the dashboard.`) + } +} + // NewAddonUpgradeCommand create addon upgrade command func NewAddonUpgradeCommand(c common.Args, ioStream cmdutil.IOStreams) *cobra.Command { ctx := context.Background() cmd := &cobra.Command{ Use: "upgrade", Short: "upgrade an addon", - Long: "upgrade an addon in cluster", + Long: "upgrade an addon in cluster.", Example: "vela addon upgrade ", RunE: func(cmd *cobra.Command, args []string) error { if len(args) < 1 { @@ -213,10 +222,8 @@ func NewAddonUpgradeCommand(c common.Args, ioStream cmdutil.IOStreams) *cobra.Co } } - fmt.Printf("Successfully enable addon:%s\n", name) - if name == "velaux" { - fmt.Println(`Please use command: "vela port-forward -n vela-system addon-velaux 9082:80" and Select "Cluster: local | Namespace: vela-system | Component: velaux | Kind: Service" to check the dashboard`) - } + fmt.Printf("Addon: %s\n enabled Successfully.", name) + AdditionalEndpointPrinter(ctx, c, k8sClient, name) return nil }, } @@ -244,7 +251,7 @@ func NewAddonDisableCommand(c common.Args, ioStream cmdutil.IOStreams) *cobra.Co return &cobra.Command{ Use: "disable", Short: "disable an addon", - Long: "disable an addon in cluster", + Long: "disable an addon in cluster.", Example: "vela addon disable ", RunE: func(cmd *cobra.Command, args []string) error { if len(args) < 1 { @@ -269,8 +276,8 @@ func NewAddonDisableCommand(c common.Args, ioStream cmdutil.IOStreams) *cobra.Co func NewAddonStatusCommand(c common.Args, ioStream cmdutil.IOStreams) *cobra.Command { return &cobra.Command{ Use: "status", - Short: "get an addon's status", - Long: "get an addon's status from cluster", + Short: "get an addon's status.", + Long: "get an addon's status from cluster.", Example: "vela addon status ", RunE: func(cmd *cobra.Command, args []string) error { if len(args) < 1 { @@ -307,7 +314,7 @@ func enableAddon(ctx context.Context, k8sClient client.Client, config *rest.Conf } return nil } - return fmt.Errorf("addon: %s not found in registrys", name) + return fmt.Errorf("addon: %s not found in registries", name) } // enableAddonByLocal enable addon in local dir and return the addon name diff --git a/references/cli/cli.go b/references/cli/cli.go index d62cb903e..03d92ee22 100644 --- a/references/cli/cli.go +++ b/references/cli/cli.go @@ -124,8 +124,8 @@ func NewCommand() *cobra.Command { func NewVersionCommand() *cobra.Command { return &cobra.Command{ Use: "version", - Short: "Prints out build version information", - Long: "Prints out build version information.", + Short: "Prints vela build version information", + Long: "Prints vela build version information.", Run: func(cmd *cobra.Command, args []string) { fmt.Printf(`Version: %v GitRevision: %v diff --git a/references/cli/cluster.go b/references/cli/cluster.go index e3cda3d33..74b2aa2a7 100644 --- a/references/cli/cluster.go +++ b/references/cli/cluster.go @@ -110,7 +110,7 @@ func NewClusterListCommand(c *common.Args) *cobra.Command { Use: "list", Aliases: []string{"ls"}, Short: "list managed clusters", - Long: "list child clusters managed by KubeVela", + Long: "list worker clusters managed by KubeVela.", Args: cobra.ExactValidArgs(0), RunE: func(cmd *cobra.Command, args []string) error { table := newUITable().AddRow("CLUSTER", "TYPE", "ENDPOINT") @@ -154,8 +154,8 @@ func ensureVelaSystemNamespaceInstalled(c client.Client, clusterName string, cre func NewClusterJoinCommand(c *common.Args, ioStreams cmdutil.IOStreams) *cobra.Command { cmd := &cobra.Command{ Use: "join [KUBECONFIG]", - Short: "join managed cluster", - Long: "join managed cluster by kubeconfig", + Short: "join managed cluster.", + Long: "join managed cluster by kubeconfig.", Example: "# Join cluster declared in my-child-cluster.kubeconfig\n" + "> vela cluster join my-child-cluster.kubeconfig --name example-cluster", Args: cobra.ExactValidArgs(1), @@ -390,7 +390,8 @@ func registerClusterManagedByOCM(ioStreams cmdutil.IOStreams, hubConfig *rest.Co func NewClusterRenameCommand(c *common.Args) *cobra.Command { cmd := &cobra.Command{ Use: "rename [OLD_NAME] [NEW_NAME]", - Short: "rename managed cluster", + Short: "rename managed cluster.", + Long: "rename managed cluster.", Args: cobra.ExactValidArgs(2), RunE: func(cmd *cobra.Command, args []string) error { oldClusterName := args[0] @@ -432,7 +433,8 @@ func NewClusterRenameCommand(c *common.Args) *cobra.Command { func NewClusterDetachCommand(c *common.Args) *cobra.Command { cmd := &cobra.Command{ Use: "detach [CLUSTER_NAME]", - Short: "detach managed cluster", + Short: "detach managed cluster.", + Long: "detach managed cluster.", Args: cobra.ExactValidArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clusterName := args[0] @@ -510,7 +512,8 @@ func NewClusterDetachCommand(c *common.Args) *cobra.Command { func NewClusterProbeCommand(c *common.Args) *cobra.Command { cmd := &cobra.Command{ Use: "probe [CLUSTER_NAME]", - Short: "probe managed cluster", + Short: "health probe managed cluster.", + Long: "health probe managed cluster.", Args: cobra.ExactValidArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clusterName := args[0] diff --git a/references/cli/components.go b/references/cli/components.go index db33e3e80..bd8bef0a8 100644 --- a/references/cli/components.go +++ b/references/cli/components.go @@ -97,7 +97,7 @@ func NewCompGetCommand(c common2.Args, ioStreams cmdutil.IOStreams) *cobra.Comma cmd := &cobra.Command{ Use: "get ", Short: "get component from registry", - Long: "get component from registry", + Long: "get/download/install component from registry.", Example: "vela comp get ", RunE: func(cmd *cobra.Command, args []string) error { if len(args) < 1 { diff --git a/references/cli/cue_packages.go b/references/cli/cue_packages.go index ef15d9258..9c49a707a 100644 --- a/references/cli/cue_packages.go +++ b/references/cli/cue_packages.go @@ -23,7 +23,6 @@ import ( "github.com/gosuri/uitable" "github.com/spf13/cobra" - "github.com/oam-dev/kubevela/apis/types" "github.com/oam-dev/kubevela/pkg/utils/common" cmdutil "github.com/oam-dev/kubevela/pkg/utils/util" ) @@ -37,9 +36,7 @@ func NewCUEPackageCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Com Short: "List cue package", Long: "List CUE packages available.", Example: `vela cue-packages`, - Annotations: map[string]string{ - types.TagCommandType: types.TypeSystem, - }, + Annotations: map[string]string{}, RunE: func(cmd *cobra.Command, args []string) error { return printCUEPackageList(c, ioStreams) }, diff --git a/references/cli/def.go b/references/cli/def.go index 2a0b74749..e599afe66 100644 --- a/references/cli/def.go +++ b/references/cli/def.go @@ -449,8 +449,8 @@ func NewDefinitionGenDocCommand(c common.Args) *cobra.Command { func NewDefinitionListCommand(c common.Args) *cobra.Command { cmd := &cobra.Command{ Use: "list", - Short: "List definitions", - Long: "List definitions in kubernetes cluster", + Short: "List definitions.", + Long: "List definitions in kubernetes cluster.", Example: "# Command below will list all definitions in all namespaces\n" + "> vela def list\n" + "# Command below will list all definitions in the vela-system namespace\n" + @@ -499,8 +499,8 @@ func NewDefinitionListCommand(c common.Args) *cobra.Command { func NewDefinitionEditCommand(c common.Args) *cobra.Command { cmd := &cobra.Command{ Use: "edit NAME", - Short: "Edit definition", - Long: "Edit definition in kubernetes. If type and namespace are not specified, the command will automatically search all possible results.\n" + + Short: "Edit X-Definition.", + Long: "Edit X-Definition in kubernetes. If type and namespace are not specified, the command will automatically search all possible results.\n" + "By default, this command will use the vi editor and can be altered by setting EDITOR environment variable.", Example: "# Command below will edit the ComponentDefinition (and other definitions if exists) of webservice in kubernetes\n" + "> vela def edit webservice\n" + @@ -598,8 +598,8 @@ func prettyYAMLMarshal(obj map[string]interface{}) (string, error) { func NewDefinitionRenderCommand(c common.Args) *cobra.Command { cmd := &cobra.Command{ Use: "render DEFINITION.cue", - Short: "Render definition", - Long: "Render definition with cue format into kubernetes YAML format. Could be used to check whether the cue format definition is working as expected. If a directory is used as input, all cue definitions in the directory will be rendered.", + Short: "Render X-Definition.", + Long: "Render X-Definition with cue format into kubernetes YAML format. Could be used to check whether the cue format definition is working as expected. If a directory is used as input, all cue definitions in the directory will be rendered.", Example: "# Command below will render my-webservice.cue into YAML format and print it out.\n" + "> vela def render my-webservice.cue\n" + "# Command below will render my-webservice.cue and save it in my-webservice.yaml.\n" + @@ -705,8 +705,8 @@ func NewDefinitionRenderCommand(c common.Args) *cobra.Command { func NewDefinitionApplyCommand(c common.Args) *cobra.Command { cmd := &cobra.Command{ Use: "apply DEFINITION.cue", - Short: "Apply definition", - Long: "Apply definition from local storage to kubernetes cluster. It will apply file to vela-system namespace by default.", + Short: "Apply X-Definition.", + Long: "Apply X-Definition from local storage to kubernetes cluster. It will apply file to vela-system namespace by default.", Example: "# Command below will apply the local my-webservice.cue file to kubernetes vela-system namespace\n" + "> vela def apply my-webservice.cue\n" + "# Command below will apply the ./defs/my-trait.cue file to kubernetes default namespace\n" + @@ -787,8 +787,8 @@ func NewDefinitionApplyCommand(c common.Args) *cobra.Command { func NewDefinitionDelCommand(c common.Args) *cobra.Command { cmd := &cobra.Command{ Use: "del DEFINITION_NAME", - Short: "Delete definition", - Long: "Delete definition in kubernetes cluster.", + Short: "Delete X-Definition.", + Long: "Delete X-Definition in kubernetes cluster.", Example: "# Command below will delete TraitDefinition of annotations in default namespace\n" + "> vela def del annotations -t trait -n default", Args: cobra.ExactValidArgs(1), @@ -852,7 +852,7 @@ func NewDefinitionDelCommand(c common.Args) *cobra.Command { func NewDefinitionValidateCommand(c common.Args) *cobra.Command { cmd := &cobra.Command{ Use: "vet DEFINITION.cue", - Short: "Validate definition", + Short: "Validate X-Definition.", Long: "Validate definition file by checking whether it has the valid cue format with fields set correctly\n" + "* Currently, this command only checks the cue format. This function is still working in progress and we will support more functional validation mechanism in the future.", Example: "# Command below will validate the my-def.cue file.\n" + diff --git a/references/cli/env.go b/references/cli/env.go index e3ca4ee4e..e0c223c95 100644 --- a/references/cli/env.go +++ b/references/cli/env.go @@ -107,7 +107,7 @@ func NewEnvDeleteCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Comm cmd := &cobra.Command{ Use: "delete", DisableFlagsInUseLine: true, - Short: "Delete an environment", + Short: "Delete an environment.", Long: "Delete an environment.", Example: `vela env delete test`, RunE: func(cmd *cobra.Command, args []string) error { @@ -135,7 +135,7 @@ func NewEnvSetCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Command Use: "set", Aliases: []string{"sw"}, DisableFlagsInUseLine: true, - Short: "Set an environment", + Short: "Set an environment.", Long: "Set an environment as the default one for running vela applications.", Example: `vela env set test`, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/references/cli/help.go b/references/cli/help.go index b6c5aeffb..f914104f2 100644 --- a/references/cli/help.go +++ b/references/cli/help.go @@ -78,6 +78,9 @@ func PrintHelpByTag(cmd *cobra.Command, all []*cobra.Command, tag string) { table := newUITable() var pl PrintList for _, c := range all { + if c.Hidden || c.IsAdditionalHelpTopicCommand() { + continue + } if val, ok := c.Annotations[types.TagCommandType]; ok && val == tag { pl = append(pl, Printable{Order: c.Annotations[types.TagCommandOrder], use: c.Use, Long: c.Long}) } diff --git a/references/cli/init.go b/references/cli/init.go index 5f27aac2f..05b492dd9 100644 --- a/references/cli/init.go +++ b/references/cli/init.go @@ -61,7 +61,7 @@ func NewInitCommand(c common2.Args, order string, ioStreams cmdutil.IOStreams) * cmd := &cobra.Command{ Use: "init", DisableFlagsInUseLine: true, - Short: "Create scaffold for an application", + Short: "Create scaffold for an application.", Long: "Create scaffold for vela application.", Example: "vela init", RunE: func(cmd *cobra.Command, args []string) error { diff --git a/references/cli/logs.go b/references/cli/logs.go index d0ad74843..854123e38 100644 --- a/references/cli/logs.go +++ b/references/cli/logs.go @@ -45,7 +45,7 @@ func NewLogsCommand(c common.Args, order string, ioStreams util.IOStreams) *cobr largs := &Args{Args: c} cmd := &cobra.Command{ Use: "logs APP_NAME", - Short: "Tail logs for application in multicluster", + Short: "Tail logs for application.", Long: "Tail logs for vela application.", Args: cobra.ExactArgs(1), PreRunE: func(cmd *cobra.Command, args []string) error { diff --git a/references/cli/portforward.go b/references/cli/portforward.go index 293393802..d6ae8b994 100644 --- a/references/cli/portforward.go +++ b/references/cli/portforward.go @@ -84,7 +84,7 @@ func NewPortForwardCommand(c common.Args, order string, ioStreams util.IOStreams } cmd := &cobra.Command{ Use: "port-forward APP_NAME", - Short: "Forward local ports to container/service port of vela application", + Short: "Forward local ports to container/service port of vela application.", Long: "Forward local ports to container/service port of vela application.", Example: "port-forward APP_NAME [options] [LOCAL_PORT:]REMOTE_PORT [...[LOCAL_PORT_N:]REMOTE_PORT_N]", PersistentPreRunE: func(cmd *cobra.Command, args []string) error { diff --git a/references/cli/show.go b/references/cli/show.go index 286929ee2..8907a9e94 100644 --- a/references/cli/show.go +++ b/references/cli/show.go @@ -62,7 +62,7 @@ var webSite bool func NewCapabilityShowCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Command { cmd := &cobra.Command{ Use: "show", - Short: "Show the reference doc for a component type or trait", + Short: "Show the reference doc for a component type or trait.", Long: "Show the reference doc for component or trait types.", Example: `show webservice`, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/references/cli/status.go b/references/cli/status.go index 82e39517b..c93d49a29 100644 --- a/references/cli/status.go +++ b/references/cli/status.go @@ -74,6 +74,7 @@ const ( // Error msg used in `status` command const ( + // ErrNotLoadAppConfig display the error message load ErrNotLoadAppConfig = "cannot load the application" ) @@ -87,7 +88,7 @@ func NewAppStatusCommand(c common.Args, order string, ioStreams cmdutil.IOStream ctx := context.Background() cmd := &cobra.Command{ Use: "status APP_NAME", - Short: "Show status of an application", + Short: "Show status of an application.", Long: "Show status of vela application.", Example: `vela status APP_NAME`, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/references/cli/system.go b/references/cli/system.go index cf786d1f8..3b97b39a2 100644 --- a/references/cli/system.go +++ b/references/cli/system.go @@ -69,8 +69,8 @@ func NewAdminInfoCommand(ioStreams cmdutil.IOStreams) *cobra.Command { cmd := &cobra.Command{ Use: "info", - Short: "Show vela client and cluster chartPath", - Long: "Show vela client and cluster chartPath", + Short: "Show vela client and cluster chartPath.", + Long: "Show vela client and cluster chartPath.", RunE: func(cmd *cobra.Command, args []string) error { return i.run(ioStreams) }, diff --git a/references/cli/traits.go b/references/cli/traits.go index 39d9f350d..f5d16700e 100644 --- a/references/cli/traits.go +++ b/references/cli/traits.go @@ -50,7 +50,7 @@ func NewTraitCommand(c common2.Args, ioStreams cmdutil.IOStreams) *cobra.Command cmd := &cobra.Command{ Use: "trait", Aliases: []string{"traits"}, - Short: "List/get traits", + Short: "List/get traits.", Long: "List trait types installed and discover more in registry.", Example: `vela trait`, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/references/cli/workflow.go b/references/cli/workflow.go index 9b1e94285..645044598 100644 --- a/references/cli/workflow.go +++ b/references/cli/workflow.go @@ -35,7 +35,7 @@ import ( func NewWorkflowCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Command { cmd := &cobra.Command{ Use: "workflow", - Short: "Operate application delivery workflow", + Short: "Operate application delivery workflow.", Long: "Operate the Workflow during Application Delivery.", Annotations: map[string]string{ types.TagCommandType: types.TypeCD, @@ -55,8 +55,8 @@ func NewWorkflowCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Comma func NewWorkflowSuspendCommand(c common.Args, ioStream cmdutil.IOStreams) *cobra.Command { cmd := &cobra.Command{ Use: "suspend", - Short: "Suspend an application workflow", - Long: "Suspend an application workflow in cluster", + Short: "Suspend an application workflow.", + Long: "Suspend an application workflow in cluster.", Example: "vela workflow suspend ", RunE: func(cmd *cobra.Command, args []string) error { if len(args) < 1 { @@ -95,8 +95,8 @@ func NewWorkflowSuspendCommand(c common.Args, ioStream cmdutil.IOStreams) *cobra func NewWorkflowResumeCommand(c common.Args, ioStream cmdutil.IOStreams) *cobra.Command { cmd := &cobra.Command{ Use: "resume", - Short: "Resume a suspend application workflow", - Long: "Resume a suspend application workflow in cluster", + Short: "Resume a suspend application workflow.", + Long: "Resume a suspend application workflow in cluster.", Example: "vela workflow resume ", RunE: func(cmd *cobra.Command, args []string) error { if len(args) < 1 { @@ -143,8 +143,8 @@ func NewWorkflowResumeCommand(c common.Args, ioStream cmdutil.IOStreams) *cobra. func NewWorkflowTerminateCommand(c common.Args, ioStream cmdutil.IOStreams) *cobra.Command { cmd := &cobra.Command{ Use: "terminate", - Short: "Terminate an application workflow", - Long: "Terminate an application workflow in cluster", + Short: "Terminate an application workflow.", + Long: "Terminate an application workflow in cluster.", Example: "vela workflow terminate ", RunE: func(cmd *cobra.Command, args []string) error { if len(args) < 1 { @@ -183,8 +183,8 @@ func NewWorkflowTerminateCommand(c common.Args, ioStream cmdutil.IOStreams) *cob func NewWorkflowRestartCommand(c common.Args, ioStream cmdutil.IOStreams) *cobra.Command { cmd := &cobra.Command{ Use: "restart", - Short: "Restart an application workflow", - Long: "Restart an application workflow in cluster", + Short: "Restart an application workflow.", + Long: "Restart an application workflow in cluster.", Example: "vela workflow restart ", RunE: func(cmd *cobra.Command, args []string) error { if len(args) < 1 { @@ -224,8 +224,8 @@ func NewWorkflowRestartCommand(c common.Args, ioStream cmdutil.IOStreams) *cobra func NewWorkflowRollbackCommand(c common.Args, ioStream cmdutil.IOStreams) *cobra.Command { cmd := &cobra.Command{ Use: "rollback", - Short: "Rollback an application workflow to the latest revision", - Long: "Rollback an application workflow to the latest revision", + Short: "Rollback an application workflow to the latest revision.", + Long: "Rollback an application workflow to the latest revision.", Example: "vela workflow rollback ", RunE: func(cmd *cobra.Command, args []string) error { if len(args) < 1 { diff --git a/references/common/application.go b/references/common/application.go index 2b83261ed..c6cb5b5b8 100644 --- a/references/common/application.go +++ b/references/common/application.go @@ -21,6 +21,7 @@ import ( "context" j "encoding/json" "fmt" + "io/ioutil" "os" "path/filepath" "strings" @@ -250,6 +251,9 @@ func LoadAppFile(pathOrURL string) (*api.AppFile, error) { // ReadRemoteOrLocalPath will read a path remote or locally func ReadRemoteOrLocalPath(pathOrURL string) ([]byte, error) { + if pathOrURL == "-" { + return ioutil.ReadAll(os.Stdin) + } var body []byte var err error if strings.HasPrefix(pathOrURL, "https://") || strings.HasPrefix(pathOrURL, "http://") { diff --git a/test/e2e-addon-test/addon_test.go b/test/e2e-addon-test/addon_test.go index a22603c3d..7b26acb33 100644 --- a/test/e2e-addon-test/addon_test.go +++ b/test/e2e-addon-test/addon_test.go @@ -94,7 +94,7 @@ var _ = Describe("Addon tests", func() { fmt.Println("exit code error:", string(ee.Stderr)) } Expect(err).Should(BeNil()) - Expect(string(output)).Should(ContainSubstring("Successfully enable addon:")) + Expect(string(output)).Should(ContainSubstring("enabled Successfully")) By("Checking Provider") Eventually(func() error { @@ -130,6 +130,6 @@ var _ = Describe("Addon tests", func() { fmt.Println("exit code error:", string(ee.Stderr)) } Expect(err).Should(BeNil()) - Expect(string(output)).Should(ContainSubstring("Successfully enable addon:")) + Expect(string(output)).Should(ContainSubstring("enabled Successfully")) }) })