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:
@@ -64,7 +64,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},
|
||||
})
|
||||
|
||||
showCmd := &cobra.Command{
|
||||
|
||||
@@ -53,7 +53,7 @@ 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) {
|
||||
name := input.String(flagkey.TtName)
|
||||
if len(name) == 0 {
|
||||
id, err := uuid.NewV4()
|
||||
@@ -68,7 +68,10 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
return errors.New("Need a function name to create a trigger, use --function")
|
||||
}
|
||||
|
||||
fnNamespace := input.String(flagkey.NamespaceFunction)
|
||||
userProvidedNS, fnNamespace, err := util.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in deleting function ")
|
||||
}
|
||||
|
||||
cronSpec := input.String(flagkey.TtCron)
|
||||
if len(cronSpec) == 0 {
|
||||
@@ -86,7 +89,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
exists, err := fr.ExistsInSpecs(fv1.Function{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: fnName,
|
||||
Namespace: fnNamespace,
|
||||
Namespace: userProvidedNS,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -98,11 +101,20 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
}
|
||||
}
|
||||
|
||||
opts.trigger = &fv1.TimeTrigger{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
m := metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: fnNamespace,
|
||||
}
|
||||
|
||||
if input.Bool(flagkey.SpecSave) || input.Bool(flagkey.SpecDry) {
|
||||
m = metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Namespace: fnNamespace,
|
||||
},
|
||||
Namespace: userProvidedNS,
|
||||
}
|
||||
}
|
||||
|
||||
opts.trigger = &fv1.TimeTrigger{
|
||||
ObjectMeta: m,
|
||||
Spec: fv1.TimeTriggerSpec{
|
||||
Cron: cronSpec,
|
||||
FunctionReference: fv1.FunctionReference{
|
||||
|
||||
@@ -36,13 +36,18 @@ func Delete(input cli.Input) error {
|
||||
return (&DeleteSubCommand{}).do(input)
|
||||
}
|
||||
|
||||
func (opts *DeleteSubCommand) do(input cli.Input) error {
|
||||
func (opts *DeleteSubCommand) do(input cli.Input) (err error) {
|
||||
|
||||
_, namespace, err := util.GetResourceNamespace(input, flagkey.NamespaceTrigger)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in deleting function ")
|
||||
}
|
||||
m := &metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.TtName),
|
||||
Namespace: input.String(flagkey.NamespaceTrigger),
|
||||
Namespace: namespace,
|
||||
}
|
||||
|
||||
err := opts.Client().V1().TimeTrigger().Delete(m)
|
||||
err = opts.Client().V1().TimeTrigger().Delete(m)
|
||||
if err != nil {
|
||||
if input.Bool(flagkey.IgnoreNotFound) && util.IsNotFound(err) {
|
||||
return nil
|
||||
|
||||
@@ -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 {
|
||||
@@ -36,9 +38,19 @@ func List(input cli.Input) error {
|
||||
return (&ListSubCommand{}).do(input)
|
||||
}
|
||||
|
||||
func (opts *ListSubCommand) do(input cli.Input) error {
|
||||
ttNs := input.String(flagkey.NamespaceTrigger)
|
||||
tts, err := opts.Client().V1().TimeTrigger().List(ttNs)
|
||||
func (opts *ListSubCommand) do(input cli.Input) (err error) {
|
||||
_, ttNs, err := util.GetResourceNamespace(input, flagkey.NamespaceTrigger)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in deleting function ")
|
||||
}
|
||||
|
||||
var tts []v1.TimeTrigger
|
||||
if input.Bool(flagkey.AllNamespaces) {
|
||||
tts, err = opts.Client().V1().TimeTrigger().List("")
|
||||
} else {
|
||||
tts, err = opts.Client().V1().TimeTrigger().List(ttNs)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "list Time triggers")
|
||||
}
|
||||
|
||||
@@ -25,7 +25,9 @@ import (
|
||||
fv1 "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"
|
||||
"github.com/fission/fission/pkg/fission-cli/console"
|
||||
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
|
||||
"github.com/fission/fission/pkg/fission-cli/util"
|
||||
)
|
||||
|
||||
type UpdateSubCommand struct {
|
||||
@@ -46,9 +48,13 @@ func (opts *UpdateSubCommand) do(input cli.Input) error {
|
||||
}
|
||||
|
||||
func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
_, namespace, err := util.GetResourceNamespace(input, flagkey.NamespaceTrigger)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in deleting function ")
|
||||
}
|
||||
tt, err := opts.Client().V1().TimeTrigger().Get(&metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.TtName),
|
||||
Namespace: input.String(flagkey.NamespaceTrigger),
|
||||
Namespace: namespace,
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting time trigger")
|
||||
@@ -61,11 +67,13 @@ func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
updated = true
|
||||
}
|
||||
|
||||
// TODO : During update, function has to be in the same ns as the trigger object
|
||||
// but since we are not checking this for other triggers too, not sure if we need a check here.
|
||||
|
||||
fnName := input.String("function")
|
||||
if len(fnName) > 0 {
|
||||
functionList := []string{fnName}
|
||||
err := util.CheckFunctionExistence(opts.Client(), functionList, namespace)
|
||||
if err != nil {
|
||||
console.Warn(err.Error())
|
||||
}
|
||||
tt.Spec.FunctionReference.Name = fnName
|
||||
updated = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user