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:
@@ -71,7 +71,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{
|
||||
|
||||
@@ -61,7 +61,11 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
mqtName = id.String()
|
||||
}
|
||||
fnName := input.String(flagkey.MqtFnName)
|
||||
fnNamespace := input.String(flagkey.NamespaceFunction)
|
||||
|
||||
userProvidedNS, fnNamespace, err := util.GetResourceNamespace(input, flagkey.NamespaceFunction)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in deleting function ")
|
||||
}
|
||||
|
||||
mqtKind := input.String(flagkey.MqtKind)
|
||||
|
||||
@@ -94,7 +98,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
contentType = "application/json"
|
||||
}
|
||||
|
||||
err := checkMQTopicAvailability(mqType, mqtKind, topic, respTopic)
|
||||
err = checkMQTopicAvailability(mqType, mqtKind, topic, respTopic)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -136,7 +140,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 {
|
||||
@@ -153,11 +157,19 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
}
|
||||
}
|
||||
|
||||
opts.trigger = &fv1.MessageQueueTrigger{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
m := metav1.ObjectMeta{
|
||||
Name: mqtName,
|
||||
Namespace: fnNamespace,
|
||||
}
|
||||
|
||||
if input.Bool(flagkey.SpecSave) || input.Bool(flagkey.SpecDry) {
|
||||
m = metav1.ObjectMeta{
|
||||
Name: mqtName,
|
||||
Namespace: fnNamespace,
|
||||
},
|
||||
Namespace: userProvidedNS,
|
||||
}
|
||||
}
|
||||
opts.trigger = &fv1.MessageQueueTrigger{
|
||||
ObjectMeta: m,
|
||||
Spec: fv1.MessageQueueTriggerSpec{
|
||||
FunctionReference: fv1.FunctionReference{
|
||||
Type: fv1.FunctionReferenceTypeFunctionName,
|
||||
|
||||
@@ -45,10 +45,16 @@ 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) {
|
||||
|
||||
_, namespace, err := util.GetResourceNamespace(input, flagkey.NamespaceTrigger)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in deleting function ")
|
||||
}
|
||||
|
||||
opts.metadata = &metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.MqtName),
|
||||
Namespace: input.String(flagkey.NamespaceTrigger),
|
||||
Namespace: namespace,
|
||||
}
|
||||
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 {
|
||||
@@ -45,24 +47,33 @@ 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 in deleting function ")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (opts *ListSubCommand) run(input cli.Input) error {
|
||||
mqts, err := opts.Client().V1().MessageQueueTrigger().List(input.String(flagkey.MqtMQType), opts.namespace)
|
||||
func (opts *ListSubCommand) run(input cli.Input) (err error) {
|
||||
|
||||
var mqts []v1.MessageQueueTrigger
|
||||
if input.Bool(flagkey.AllNamespaces) {
|
||||
mqts, err = opts.Client().V1().MessageQueueTrigger().List(input.String(flagkey.MqtMQType), "")
|
||||
} else {
|
||||
mqts, err = opts.Client().V1().MessageQueueTrigger().List(input.String(flagkey.MqtMQType), opts.namespace)
|
||||
}
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error listing message queue triggers")
|
||||
}
|
||||
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
|
||||
|
||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\n",
|
||||
"NAME", "FUNCTION_NAME", "MESSAGE_QUEUE_TYPE", "TOPIC", "RESPONSE_TOPIC", "ERROR_TOPIC", "MAX_RETRIES", "PUB_MSG_CONTENT_TYPE")
|
||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\n",
|
||||
"NAME", "FUNCTION_NAME", "MESSAGE_QUEUE_TYPE", "TOPIC", "RESPONSE_TOPIC", "ERROR_TOPIC", "MAX_RETRIES", "PUB_MSG_CONTENT_TYPE", "NAMESPACE")
|
||||
for _, mqt := range mqts {
|
||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\n",
|
||||
mqt.ObjectMeta.Name, mqt.Spec.FunctionReference.Name, mqt.Spec.MessageQueueType, mqt.Spec.Topic, mqt.Spec.ResponseTopic, mqt.Spec.ErrorTopic, mqt.Spec.MaxRetries, mqt.Spec.ContentType)
|
||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\n",
|
||||
mqt.ObjectMeta.Name, mqt.Spec.FunctionReference.Name, mqt.Spec.MessageQueueType, mqt.Spec.Topic, mqt.Spec.ResponseTopic, mqt.Spec.ErrorTopic, mqt.Spec.MaxRetries, mqt.Spec.ContentType, mqt.ObjectMeta.Namespace)
|
||||
}
|
||||
w.Flush()
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ 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"
|
||||
)
|
||||
@@ -46,10 +47,15 @@ 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) {
|
||||
_, namespace, err := util.GetResourceNamespace(input, flagkey.NamespaceTrigger)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error in deleting function ")
|
||||
}
|
||||
|
||||
mqt, err := opts.Client().V1().MessageQueueTrigger().Get(&metav1.ObjectMeta{
|
||||
Name: input.String(flagkey.MqtName),
|
||||
Namespace: input.String(flagkey.NamespaceTrigger),
|
||||
Namespace: namespace,
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting message queue trigger")
|
||||
@@ -93,6 +99,12 @@ func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
updated = true
|
||||
}
|
||||
if len(fnName) > 0 {
|
||||
functionList := []string{fnName}
|
||||
err := util.CheckFunctionExistence(opts.Client(), functionList, namespace)
|
||||
if err != nil {
|
||||
console.Warn(err.Error())
|
||||
}
|
||||
|
||||
mqt.Spec.FunctionReference.Name = fnName
|
||||
updated = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user