Added ignorenotfound flag for all resources' deletion (#2293)

Treat \"resource not found\" as a successful delete if ignorenotfound flag passed while deletion of Fission resource.
This commit is contained in:
Ankit Chawla
2022-01-06 17:30:05 +05:30
committed by GitHub
parent f54bd6a703
commit b27043518f
19 changed files with 69 additions and 8 deletions
+1 -1
View File
@@ -65,7 +65,7 @@ func Commands() *cobra.Command {
}
wrapper.SetFlags(deleteCmd, flag.FlagSet{
Required: []flag.Flag{flag.CanaryName},
Optional: []flag.Flag{flag.NamespaceCanary},
Optional: []flag.Flag{flag.NamespaceCanary, flag.IgnoreNotFound},
})
listCmd := &cobra.Command{
@@ -25,6 +25,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 DeleteSubCommand struct {
@@ -43,6 +44,9 @@ func (opts *DeleteSubCommand) run(input cli.Input) error {
err := opts.Client().V1().CanaryConfig().Delete(m)
if err != nil {
if input.Bool(flagkey.IgnoreNotFound) && util.IsNotFound(err) {
return nil
}
return errors.Wrap(err, "error deleting canary config")
}
+1 -1
View File
@@ -72,7 +72,7 @@ func Commands() *cobra.Command {
}
wrapper.SetFlags(deleteCmd, flag.FlagSet{
Required: []flag.Flag{flag.EnvName},
Optional: []flag.Flag{flag.NamespaceEnvironment},
Optional: []flag.Flag{flag.NamespaceEnvironment, flag.IgnoreNotFound},
})
listCmd := &cobra.Command{
@@ -25,6 +25,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 DeleteSubCommand struct {
@@ -43,6 +44,9 @@ func (opts *DeleteSubCommand) do(input cli.Input) error {
err := opts.Client().V1().Environment().Delete(m)
if err != nil {
if input.Bool(flagkey.IgnoreNotFound) && util.IsNotFound(err) {
return nil
}
return errors.Wrap(err, "error deleting environment")
}
+1 -1
View File
@@ -110,7 +110,7 @@ func Commands() *cobra.Command {
}
wrapper.SetFlags(deleteCmd, flag.FlagSet{
Required: []flag.Flag{flag.FnName},
Optional: []flag.Flag{flag.NamespaceFunction},
Optional: []flag.Flag{flag.NamespaceFunction, flag.IgnoreNotFound},
})
listCmd := &cobra.Command{
+4
View File
@@ -25,6 +25,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 DeleteSubCommand struct {
@@ -43,6 +44,9 @@ func (opts *DeleteSubCommand) do(input cli.Input) error {
err := opts.Client().V1().Function().Delete(m)
if err != nil {
if input.Bool(flagkey.IgnoreNotFound) && util.IsNotFound(err) {
return nil
}
return errors.Wrap(err, fmt.Sprintf("delete function '%v'", m.Name))
}
+1 -1
View File
@@ -68,7 +68,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Delete),
}
wrapper.SetFlags(deleteCmd, flag.FlagSet{
Optional: []flag.Flag{flag.HtName, flag.HtFnFilter, flag.NamespaceTrigger},
Optional: []flag.Flag{flag.HtName, flag.HtFnFilter, flag.NamespaceTrigger, flag.IgnoreNotFound},
})
listCmd := &cobra.Command{
@@ -26,6 +26,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"
"github.com/fission/fission/pkg/utils"
)
@@ -94,6 +95,9 @@ func (opts *DeleteSubCommand) run(input cli.Input) error {
}
if errs.ErrorOrNil() != nil {
if input.Bool(flagkey.IgnoreNotFound) && util.IsNotFound(err) {
return nil
}
return errors.Wrap(errs.ErrorOrNil(), "error deleting trigger(s)")
}
+1 -1
View File
@@ -44,7 +44,7 @@ func Commands() *cobra.Command {
}
wrapper.SetFlags(deleteCmd, flag.FlagSet{
Required: []flag.Flag{flag.KwFnName},
Optional: []flag.Flag{flag.NamespaceTrigger},
Optional: []flag.Flag{flag.NamespaceTrigger, flag.IgnoreNotFound},
})
listCmd := &cobra.Command{
+4
View File
@@ -25,6 +25,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 DeleteSubCommand struct {
@@ -57,6 +58,9 @@ func (opts *DeleteSubCommand) run(input cli.Input) error {
Namespace: opts.namespace,
})
if err != nil {
if input.Bool(flagkey.IgnoreNotFound) && util.IsNotFound(err) {
return nil
}
return errors.Wrap(err, "error deleting kubewatch")
}
+1 -1
View File
@@ -60,7 +60,7 @@ func Commands() *cobra.Command {
}
wrapper.SetFlags(deleteCmd, flag.FlagSet{
Required: []flag.Flag{flag.MqtName},
Optional: []flag.Flag{flag.NamespaceTrigger},
Optional: []flag.Flag{flag.NamespaceTrigger, flag.IgnoreNotFound},
})
listCmd := &cobra.Command{
+4
View File
@@ -25,6 +25,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 DeleteSubCommand struct {
@@ -55,6 +56,9 @@ func (opts *DeleteSubCommand) complete(input cli.Input) error {
func (opts *DeleteSubCommand) run(input cli.Input) error {
err := opts.Client().V1().MessageQueueTrigger().Delete(opts.metadata)
if err != nil {
if input.Bool(flagkey.IgnoreNotFound) && util.IsNotFound(err) {
return nil
}
return errors.Wrap(err, "error deleting message queue trigger")
}
+1 -1
View File
@@ -74,7 +74,7 @@ func Commands() *cobra.Command {
RunE: wrapper.Wrapper(Delete),
}
wrapper.SetFlags(deleteCmd, flag.FlagSet{
Optional: []flag.Flag{flag.PkgName, flag.PkgForce, flag.PkgOrphan, flag.NamespacePackage},
Optional: []flag.Flag{flag.PkgName, flag.PkgForce, flag.PkgOrphan, flag.NamespacePackage, flag.IgnoreNotFound},
})
listCmd := &cobra.Command{
+4
View File
@@ -26,6 +26,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 DeleteSubCommand struct {
@@ -68,6 +69,9 @@ func (opts *DeleteSubCommand) run(input cli.Input) error {
Name: opts.name,
})
if err != nil {
if input.Bool(flagkey.IgnoreNotFound) && util.IsNotFound(err) {
return nil
}
return errors.Wrap(err, "find package")
}
+1 -1
View File
@@ -53,7 +53,7 @@ func Commands() *cobra.Command {
}
wrapper.SetFlags(deleteCmd, flag.FlagSet{
Required: []flag.Flag{flag.TtName},
Optional: []flag.Flag{flag.NamespaceTrigger},
Optional: []flag.Flag{flag.NamespaceTrigger, flag.IgnoreNotFound},
})
listCmd := &cobra.Command{
@@ -25,6 +25,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 DeleteSubCommand struct {
@@ -43,6 +44,9 @@ func (opts *DeleteSubCommand) do(input cli.Input) error {
err := opts.Client().V1().TimeTrigger().Delete(m)
if err != nil {
if input.Bool(flagkey.IgnoreNotFound) && util.IsNotFound(err) {
return nil
}
return errors.Wrap(err, "error deleting trigger")
}
+2
View File
@@ -76,6 +76,8 @@ var (
KubeContext = Flag{Type: String, Name: flagkey.KubeContext, Usage: "Kubernetes context to be used for the execution of Fission commands", DefaultValue: ""}
IgnoreNotFound = Flag{Type: Bool, Name: flagkey.IgnoreNotFound, Usage: "Treat \"resource not found\" as a successful delete.", DefaultValue: false}
Labels = Flag{Type: String, Name: flagkey.Labels, Usage: "Comma separated labels to apply to the function. E.g. --labels=\"environment=dev,application=analytics\""}
Annotation = Flag{Type: StringSlice, Name: flagkey.Annotation, Usage: "Annotation to apply to the function. To mention multiple annotations --annotation=\"abc.com/team=dev\" --annotation=\"foo=bar\""}
+2
View File
@@ -29,6 +29,8 @@ const (
Labels = "labels"
Annotation = "annotation"
IgnoreNotFound = "ignorenotfound"
NamespaceFunction = "fnNamespace"
NamespaceEnvironment = "envNamespace"
NamespacePackage = "pkgNamespace"
+25
View File
@@ -0,0 +1,25 @@
/*
Copyright 2021 The Fission Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package util
import (
"strings"
)
func IsNotFound(err error) bool {
return strings.HasSuffix(strings.TrimSpace(err.Error()), "not found")
}