allow vela CLI to specify NS

This commit is contained in:
qiaozp
2021-06-21 16:38:56 +08:00
parent 8c864f33b9
commit 33f27362d9
2 changed files with 7 additions and 10 deletions

View File

@@ -45,10 +45,12 @@ type DryRunCmdOptions struct {
cmdutil.IOStreams
ApplicationFile string
DefinitionFile string
NameSpace string
}
// NewDryRunCommand creates `dry-run` command
func NewDryRunCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
var namespace string
o := &DryRunCmdOptions{IOStreams: ioStreams}
cmd := &cobra.Command{
Use: "dry-run",
@@ -60,11 +62,7 @@ func NewDryRunCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Command
return c.SetConfig()
},
RunE: func(cmd *cobra.Command, args []string) error {
velaEnv, err := GetEnv(cmd)
if err != nil {
return err
}
buff, err := DryRunApplication(o, c, velaEnv.Namespace)
buff, err := DryRunApplication(o, c, namespace)
if err != nil {
return err
}
@@ -75,6 +73,7 @@ func NewDryRunCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Command
cmd.Flags().StringVarP(&o.ApplicationFile, "file", "f", "./app.yaml", "application file name")
cmd.Flags().StringVarP(&o.DefinitionFile, "definition", "d", "", "specify a definition file or directory, it will only be used in dry-run rather than applied to K8s cluster")
cmd.Flags().StringVarP(&namespace, "namespace", "n", "default", "specify namespace of the definition file, by default is default namespace")
cmd.SetOut(ioStreams.Out)
return cmd
}

View File

@@ -42,6 +42,7 @@ type LiveDiffCmdOptions struct {
// NewLiveDiffCommand creates `live-diff` command
func NewLiveDiffCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Command {
var namespace string
o := &LiveDiffCmdOptions{
DryRunCmdOptions: DryRunCmdOptions{
IOStreams: ioStreams,
@@ -56,11 +57,7 @@ func NewLiveDiffCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Comma
return c.SetConfig()
},
RunE: func(cmd *cobra.Command, args []string) error {
velaEnv, err := GetEnv(cmd)
if err != nil {
return err
}
buff, err := LiveDiffApplication(o, c, velaEnv.Namespace)
buff, err := LiveDiffApplication(o, c, namespace)
if err != nil {
return err
}
@@ -73,6 +70,7 @@ func NewLiveDiffCommand(c common.Args, ioStreams cmdutil.IOStreams) *cobra.Comma
cmd.Flags().StringVarP(&o.DefinitionFile, "definition", "d", "", "specify a file or directory containing capability definitions, they will only be used in dry-run rather than applied to K8s cluster")
cmd.Flags().StringVarP(&o.Revision, "Revision", "r", "", "specify an application Revision name, by default, it will compare with the latest Revision")
cmd.Flags().IntVarP(&o.Context, "context", "c", -1, "output number lines of context around changes, by default show all unchanged lines")
cmd.Flags().StringVarP(&namespace, "namespace", "n", "default", "specify namespace of the application to be compared, by default is default namespace")
cmd.SetOut(ioStreams.Out)
return cmd
}