Prevent env deletion if any function exists (#2343)
* Added force deletion flag for env
This commit is contained in:
@@ -72,7 +72,7 @@ func Commands() *cobra.Command {
|
|||||||
}
|
}
|
||||||
wrapper.SetFlags(deleteCmd, flag.FlagSet{
|
wrapper.SetFlags(deleteCmd, flag.FlagSet{
|
||||||
Required: []flag.Flag{flag.EnvName},
|
Required: []flag.Flag{flag.EnvName},
|
||||||
Optional: []flag.Flag{flag.NamespaceEnvironment, flag.IgnoreNotFound},
|
Optional: []flag.Flag{flag.NamespaceEnvironment, flag.IgnoreNotFound, flag.EnvForce},
|
||||||
})
|
})
|
||||||
|
|
||||||
listCmd := &cobra.Command{
|
listCmd := &cobra.Command{
|
||||||
|
|||||||
@@ -42,6 +42,20 @@ func (opts *DeleteSubCommand) do(input cli.Input) error {
|
|||||||
Namespace: input.String(flagkey.NamespaceEnvironment),
|
Namespace: input.String(flagkey.NamespaceEnvironment),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !input.Bool(flagkey.EnvForce) {
|
||||||
|
fns, err := opts.Client().V1().Function().List(metav1.NamespaceAll)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "Error getting functions wrt environment.")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, fn := range fns {
|
||||||
|
if fn.Spec.Environment.Name == m.Name &&
|
||||||
|
fn.Spec.Environment.Namespace == m.Namespace {
|
||||||
|
return errors.New("Environment is used by atleast one function.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err := opts.Client().V1().Environment().Delete(m)
|
err := opts.Client().V1().Environment().Delete(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if input.Bool(flagkey.IgnoreNotFound) && util.IsNotFound(err) {
|
if input.Bool(flagkey.IgnoreNotFound) && util.IsNotFound(err) {
|
||||||
@@ -51,5 +65,6 @@ func (opts *DeleteSubCommand) do(input cli.Input) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("environment '%v' deleted\n", m.Name)
|
fmt.Printf("environment '%v' deleted\n", m.Name)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -180,6 +180,7 @@ var (
|
|||||||
EnvVersion = Flag{Type: Int, Name: flagkey.EnvVersion, Usage: "Environment API version (1 means v1 interface)", DefaultValue: 1}
|
EnvVersion = Flag{Type: Int, Name: flagkey.EnvVersion, Usage: "Environment API version (1 means v1 interface)", DefaultValue: 1}
|
||||||
EnvImagePullSecret = Flag{Type: String, Name: flagkey.EnvImagePullSecret, Usage: "Secret for Kubernetes to pull an image from a private registry"}
|
EnvImagePullSecret = Flag{Type: String, Name: flagkey.EnvImagePullSecret, Usage: "Secret for Kubernetes to pull an image from a private registry"}
|
||||||
EnvExecutorType = Flag{Type: String, Name: flagkey.EnvExecutorType, Usage: "Executor type of pod in environment; one of 'poolmgr', 'newdeploy', 'container'"}
|
EnvExecutorType = Flag{Type: String, Name: flagkey.EnvExecutorType, Usage: "Executor type of pod in environment; one of 'poolmgr', 'newdeploy', 'container'"}
|
||||||
|
EnvForce = Flag{Type: Bool, Name: flagkey.EnvForce, Short: "f", Usage: "Force delete env even if one or more functions exist", DefaultValue: false}
|
||||||
|
|
||||||
KwName = Flag{Type: String, Name: flagkey.KwName, Usage: "Watch name"}
|
KwName = Flag{Type: String, Name: flagkey.KwName, Usage: "Watch name"}
|
||||||
KwFnName = Flag{Type: String, Name: flagkey.KwFnName, Usage: "Function name"}
|
KwFnName = Flag{Type: String, Name: flagkey.KwFnName, Usage: "Function name"}
|
||||||
|
|||||||
@@ -130,6 +130,7 @@ const (
|
|||||||
EnvVersion = "version"
|
EnvVersion = "version"
|
||||||
EnvImagePullSecret = "imagepullsecret"
|
EnvImagePullSecret = "imagepullsecret"
|
||||||
EnvExecutorType = "executortype"
|
EnvExecutorType = "executortype"
|
||||||
|
EnvForce = force
|
||||||
|
|
||||||
KwName = resourceName
|
KwName = resourceName
|
||||||
KwFnName = "function"
|
KwFnName = "function"
|
||||||
|
|||||||
Reference in New Issue
Block a user