Prevent env deletion if any function exists (#2343)
* Added force deletion flag for env
This commit is contained in:
@@ -42,6 +42,20 @@ func (opts *DeleteSubCommand) do(input cli.Input) error {
|
||||
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)
|
||||
if err != nil {
|
||||
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)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user