add namespace param for fn and env (#2556)
This PR moves fission CLI as closer as possible to kubectl command behaviour. We have improved namespace handling behaviour across CLI. * add namespace param for fn and env * use common fn for ns check * update validation * default namespace for httpTrigger, env and package, config and triggers * use default ns * add namespace filter to spec * add forceNamespace flag * set current namespace * add default namespace in config * add namespace specific destroy * add all namespace in the list of resources * add namespace as global tag * use %s instead of %v * add test cases for namespace * use ns in get all functions
This commit is contained in:
@@ -76,7 +76,7 @@ func Commands() *cobra.Command {
|
||||
RunE: wrapper.Wrapper(List),
|
||||
}
|
||||
wrapper.SetFlags(listCmd, flag.FlagSet{
|
||||
Optional: []flag.Flag{flag.NamespaceCanary},
|
||||
Optional: []flag.Flag{flag.NamespaceCanary, flag.AllNamespaces},
|
||||
})
|
||||
|
||||
command := &cobra.Command{
|
||||
|
||||
@@ -47,20 +47,23 @@ func (opts *CreateSubCommand) do(input cli.Input) error {
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
func (opts *CreateSubCommand) complete(input cli.Input) (err error) {
|
||||
// canary configs can be created for functions in the same namespace
|
||||
|
||||
name := input.String(flagkey.CanaryName)
|
||||
ht := input.String(flagkey.CanaryHTTPTriggerName)
|
||||
newFunc := input.String(flagkey.CanaryNewFunc)
|
||||
oldFunc := input.String(flagkey.CanaryOldFunc)
|
||||
fnNs := input.String(flagkey.NamespaceFunction)
|
||||
_, fnNs, err := util.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in creating canaryconfig")
|
||||
}
|
||||
incrementStep := input.Int(flagkey.CanaryWeightIncrement)
|
||||
failureThreshold := input.Int(flagkey.CanaryFailureThreshold)
|
||||
incrementInterval := input.String(flagkey.CanaryIncrementInterval)
|
||||
|
||||
// check for time parsing
|
||||
_, err := time.ParseDuration(incrementInterval)
|
||||
_, err = time.ParseDuration(incrementInterval)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error parsing time duration")
|
||||
}
|
||||
|
||||
@@ -36,13 +36,17 @@ func Delete(input cli.Input) error {
|
||||
return (&DeleteSubCommand{}).run(input)
|
||||
}
|
||||
|
||||
func (opts *DeleteSubCommand) run(input cli.Input) error {
|
||||
func (opts *DeleteSubCommand) run(input cli.Input) (err error) {
|
||||
_, namespace, err := util.GetResourceNamespace(input, flagkey.NamespaceCanary)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in deleting canaryConfig ")
|
||||
}
|
||||
m := &metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.CanaryName),
|
||||
Namespace: input.String(flagkey.NamespaceCanary),
|
||||
Namespace: namespace,
|
||||
}
|
||||
|
||||
err := opts.Client().V1().CanaryConfig().Delete(m)
|
||||
err = opts.Client().V1().CanaryConfig().Delete(m)
|
||||
if err != nil {
|
||||
if input.Bool(flagkey.IgnoreNotFound) && util.IsNotFound(err) {
|
||||
return nil
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
type GetSubCommand struct {
|
||||
@@ -37,10 +38,16 @@ func Get(input cli.Input) error {
|
||||
return (&GetSubCommand{}).run(input)
|
||||
}
|
||||
|
||||
func (opts *GetSubCommand) run(input cli.Input) error {
|
||||
func (opts *GetSubCommand) run(input cli.Input) (err error) {
|
||||
|
||||
_, namespace, err := util.GetResourceNamespace(input, flagkey.NamespaceCanary)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting canary config")
|
||||
}
|
||||
|
||||
canaryCfg, err := opts.Client().V1().CanaryConfig().Get(&metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.CanaryName),
|
||||
Namespace: input.String(flagkey.NamespaceCanary),
|
||||
Namespace: namespace,
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting canary config")
|
||||
|
||||
@@ -23,9 +23,11 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
v1 "github.com/fission/fission/pkg/apis/core/v1"
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
type ListSubCommand struct {
|
||||
@@ -45,13 +47,22 @@ func (opts *ListSubCommand) do(input cli.Input) error {
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *ListSubCommand) complete(input cli.Input) error {
|
||||
opts.namespace = input.String(flagkey.NamespaceCanary)
|
||||
func (opts *ListSubCommand) complete(input cli.Input) (err error) {
|
||||
_, opts.namespace, err = util.GetResourceNamespace(input, flagkey.NamespaceCanary)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in listing canary config ")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (opts *ListSubCommand) run(input cli.Input) error {
|
||||
canaryCfgs, err := opts.Client().V1().CanaryConfig().List(opts.namespace)
|
||||
func (opts *ListSubCommand) run(input cli.Input) (err error) {
|
||||
|
||||
var canaryCfgs []v1.CanaryConfig
|
||||
if input.Bool(flagkey.AllNamespaces) {
|
||||
canaryCfgs, err = opts.Client().V1().CanaryConfig().List("")
|
||||
} else {
|
||||
canaryCfgs, err = opts.Client().V1().CanaryConfig().List(opts.namespace)
|
||||
}
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error listing canary config")
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
|
||||
"github.com/fission/fission/pkg/fission-cli/cmd"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
type UpdateSubCommand struct {
|
||||
@@ -46,16 +47,19 @@ func (opts *UpdateSubCommand) do(input cli.Input) error {
|
||||
return opts.run(input)
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
func (opts *UpdateSubCommand) complete(input cli.Input) (err error) {
|
||||
// get the current config
|
||||
name := input.String(flagkey.CanaryName)
|
||||
ns := input.String(flagkey.NamespaceCanary)
|
||||
_, ns, err := util.GetResourceNamespace(input, flagkey.NamespaceCanary)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error updating canary config")
|
||||
}
|
||||
incrementStep := input.Int(flagkey.CanaryWeightIncrement)
|
||||
failureThreshold := input.Int(flagkey.CanaryFailureThreshold)
|
||||
incrementInterval := input.String(flagkey.CanaryIncrementInterval)
|
||||
|
||||
// check for time parsing
|
||||
_, err := time.ParseDuration(incrementInterval)
|
||||
_, err = time.ParseDuration(incrementInterval)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error parsing time duration")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user