Use Kubernetes Client instead of Controller APIs from CLI (#2605)
Use the Kubernetes and Fission Client from CLI instead of Controller API. This removes port-forwarding for the controller across Fission CLI mostly. * Use configurable client in CLI * Move resource namespace under cmd client * use server to get fission version * get archive with URL Signed-off-by: Sanket Sudake <sanketsudake@gmail.com> Co-authored-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
co-authored by
Sanket Sudake
parent
261bf24974
commit
b71a36dc1c
@@ -20,13 +20,13 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/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 {
|
||||
@@ -39,40 +39,36 @@ func Delete(input cli.Input) error {
|
||||
|
||||
func (opts *DeleteSubCommand) do(input cli.Input) (err error) {
|
||||
|
||||
_, currentContextNS, err := util.GetResourceNamespace(input, flagkey.NamespaceEnvironment)
|
||||
_, currentContextNS, err := opts.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,
|
||||
}
|
||||
envName := input.String(flagkey.EnvName)
|
||||
|
||||
if !input.Bool(flagkey.EnvForce) {
|
||||
fns, err := opts.Client().V1().Function().List(metav1.NamespaceAll)
|
||||
fns, err := opts.Client().FissionClientSet.CoreV1().Functions(metav1.NamespaceAll).List(input.Context(), metav1.ListOptions{})
|
||||
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 {
|
||||
for _, fn := range fns.Items {
|
||||
if fn.Spec.Environment.Name == envName &&
|
||||
fn.Spec.Environment.Namespace == currentContextNS {
|
||||
return errors.New("Environment is used by at least one function.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err = opts.Client().V1().Environment().Delete(m)
|
||||
err = opts.Client().FissionClientSet.CoreV1().Environments(currentContextNS).Delete(input.Context(), envName, metav1.DeleteOptions{})
|
||||
if err != nil {
|
||||
if input.Bool(flagkey.IgnoreNotFound) && util.IsNotFound(err) {
|
||||
if input.Bool(flagkey.IgnoreNotFound) && kerrors.IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
return errors.Wrap(err, "error deleting environment")
|
||||
}
|
||||
|
||||
fmt.Printf("environment '%v' deleted\n", m.Name)
|
||||
fmt.Printf("environment '%s' deleted\n", envName)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user