Files
fission-src/pkg/fission-cli/cmd/environment/delete.go
T
neha_guptaandGitHub facd14de90 mprove warning/verbose messages around namespace in Fission CLI (#2572)
Removed extra warning message while creating HTTP trigger, and updated some verbose logs to show info related to the namespace.
2022-10-17 17:52:34 +05:30

79 lines
2.1 KiB
Go

/*
Copyright 2019 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 environment
import (
"fmt"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/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 DeleteSubCommand struct {
cmd.CommandActioner
}
func Delete(input cli.Input) error {
return (&DeleteSubCommand{}).do(input)
}
func (opts *DeleteSubCommand) do(input cli.Input) (err error) {
_, currentContextNS, err := util.GetResourceNamespace(input, flagkey.NamespaceEnvironment)
if err != nil {
return errors.Wrap(err, "error creating environment")
}
console.Verbose(2, "Searching for resource in %s Namespace", currentContextNS)
m := &metav1.ObjectMeta{
Name: input.String(flagkey.EnvName),
Namespace: currentContextNS,
}
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) {
return nil
}
return errors.Wrap(err, "error deleting environment")
}
fmt.Printf("environment '%v' deleted\n", m.Name)
return nil
}