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:
neha_gupta
2022-10-11 13:23:47 +05:30
committed by GitHub
parent 0739aca920
commit b9513868ed
74 changed files with 1289 additions and 304 deletions
+1 -1
View File
@@ -55,7 +55,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(List),
}
wrapper.SetFlags(listCmd, flag.FlagSet{
Optional: []flag.Flag{flag.NamespaceTrigger},
Optional: []flag.Flag{flag.NamespaceTrigger, flag.AllNamespaces},
})
command := &cobra.Command{
+8 -4
View File
@@ -60,8 +60,12 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
watchName = id.String()
}
fnName := input.String(flagkey.KwFnName)
fnNamespace := input.String(flagkey.NamespaceFunction)
namespace := input.String(flagkey.KwNamespace)
_, namespace, err := util.GetResourceNamespace(input, flagkey.KwNamespace)
if err != nil {
return errors.Wrap(err, "error in listing function ")
}
objType := input.String(flagkey.KwObjType)
if input.Bool(flagkey.SpecSave) {
@@ -75,7 +79,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
exists, err := fr.ExistsInSpecs(fv1.Function{
ObjectMeta: metav1.ObjectMeta{
Name: fnName,
Namespace: fnNamespace,
Namespace: namespace,
},
})
if err != nil {
@@ -90,7 +94,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
opts.watcher = &fv1.KubernetesWatchTrigger{
ObjectMeta: metav1.ObjectMeta{
Name: watchName,
Namespace: fnNamespace,
Namespace: namespace,
},
Spec: fv1.KubernetesWatchTriggerSpec{
Namespace: namespace,
+5 -2
View File
@@ -46,9 +46,12 @@ func (opts *DeleteSubCommand) do(input cli.Input) error {
return opts.run(input)
}
func (opts *DeleteSubCommand) complete(input cli.Input) error {
func (opts *DeleteSubCommand) complete(input cli.Input) (err error) {
opts.name = input.String(flagkey.KwName)
opts.namespace = input.String(flagkey.NamespaceTrigger)
_, opts.namespace, err = util.GetResourceNamespace(input, flagkey.NamespaceTrigger)
if err != nil {
return errors.Wrap(err, "error in deleting kubewatch")
}
return nil
}
+14 -4
View File
@@ -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,21 @@ 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.NamespaceTrigger)
func (opts *ListSubCommand) complete(input cli.Input) (err error) {
_, opts.namespace, err = util.GetResourceNamespace(input, flagkey.NamespaceTrigger)
if err != nil {
return errors.Wrap(err, "error listing kubewatchers")
}
return nil
}
func (opts *ListSubCommand) run(input cli.Input) error {
ws, err := opts.Client().V1().KubeWatcher().List(opts.namespace)
func (opts *ListSubCommand) run(input cli.Input) (err error) {
var ws []v1.KubernetesWatchTrigger
if input.Bool(flagkey.AllNamespaces) {
ws, err = opts.Client().V1().KubeWatcher().List("")
} else {
ws, err = opts.Client().V1().KubeWatcher().List(opts.namespace)
}
if err != nil {
return errors.Wrap(err, "error listing kubewatchers")
}