Skip to content

Commit

Permalink
fixes 'kfctl delete fails when no platform or minikube is specified' (k…
Browse files Browse the repository at this point in the history
…ubeflow#2810)

* call package manager, then platform in delete. Allow ksonnet to delete k8s

* fix logic around deletion of ALL and PLATFORM

* compilation error

* convert to KfError on error returns

* update on code comments, make sure all errors are returned as KfError
  • Loading branch information
kkasravi authored and lluunn committed Mar 28, 2019
1 parent 32c43db commit 1cf2eaf
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
32 changes: 28 additions & 4 deletions bootstrap/pkg/kfapp/coordinator/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"github.com/ghodss/yaml"
gogetter "github.com/hashicorp/go-getter"
kfapis "github.com/kubeflow/kubeflow/bootstrap/pkg/apis"
kftypes "github.com/kubeflow/kubeflow/bootstrap/pkg/apis/apps"
kfdefs "github.com/kubeflow/kubeflow/bootstrap/pkg/apis/apps/kfdef/v1alpha1"
"github.com/kubeflow/kubeflow/bootstrap/pkg/kfapp/gcp"
Expand Down Expand Up @@ -453,14 +454,37 @@ func (kfapp *coordinator) Delete(resources kftypes.ResourceEnum) error {

switch resources {
case kftypes.ALL:
// if we're deleting ALL, any problems with deleting k8s will abort and not delete the platform
if err := k8s(); err != nil {
return &kfapis.KfError{
Code: int(kfapis.INTERNAL_ERROR),
Message: fmt.Sprintf("error while deleting k8 resources, aborting deleting the platform. Error %v", err),
}
}
if err := platform(); err != nil {
return err
return &kfapis.KfError{
Code: int(kfapis.INTERNAL_ERROR),
Message: fmt.Sprintf("error while deleting platform resources. Error %v", err),
}
}
return k8s()
case kftypes.PLATFORM:
return platform()
// deleting the PLATFORM means deleting the cluster. We remove k8s first in order free up any cloud vendor
// resources. Deleting k8 resources is a best effort and partial delete or failure should not
// prevent PLATFORM (cluster) deletion
_ = k8s()
if err := platform(); err != nil {
return &kfapis.KfError{
Code: int(kfapis.INTERNAL_ERROR),
Message: fmt.Sprintf("error while deleting platform resources. Error %v", err),
}
}
case kftypes.K8S:
return k8s()
if err := k8s(); err != nil {
return &kfapis.KfError{
Code: int(kfapis.INTERNAL_ERROR),
Message: fmt.Sprintf("error while deleting k8 resources, aborting deleting the platform. Error %v", err),
}
}
}
return nil
}
Expand Down
42 changes: 42 additions & 0 deletions bootstrap/pkg/kfapp/ksonnet/ksonnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,48 @@ func (ksApp *ksApp) deleteGlobalResources(config *rest.Config) error {
}

func (ksApp *ksApp) Delete(resources kftypes.ResourceEnum) error {
config := kftypes.GetConfig()
err := ksApp.deleteGlobalResources(config)
if err != nil {
log.Errorf("there was a problem deleting global resources: %v", err)
}
envSetErr := ksApp.envSet(ksApp.KsEnvName, config.Host)
if envSetErr != nil {
return fmt.Errorf("couldn't create ksonnet env %v Error: %v", ksApp.KsEnvName, envSetErr)
}
clientConfig := kftypes.GetKubeConfig()
components := []string{"application", "metacontroller"}
err = actions.RunDelete(map[string]interface{}{
actions.OptionApp: ksApp.KApp,
actions.OptionClientConfig: &client.Config{
Overrides: &clientcmd.ConfigOverrides{},
Config: clientcmd.NewDefaultClientConfig(*clientConfig, &clientcmd.ConfigOverrides{}),
},
actions.OptionEnvName: ksApp.KsEnvName,
actions.OptionComponentNames: components,
actions.OptionGracePeriod: int64(10),
})
if err != nil {
log.Infof("there was a problem deleting %v: %v", components, err)
}
namespace := ksApp.ObjectMeta.Namespace
log.Infof("deleting namespace: %v", namespace)
clientset := kftypes.GetClientset(config)
ns, nsMissingErr := clientset.CoreV1().Namespaces().Get(namespace, metav1.GetOptions{})
if nsMissingErr == nil {
nsErr := clientset.CoreV1().Namespaces().Delete(ns.Name, metav1.NewDeleteOptions(int64(100)))
if nsErr != nil {
return fmt.Errorf("couldn't delete namespace %v Error: %v", namespace, nsErr)
}
}
name := "meta-controller-cluster-role-binding"
crb, crbErr := clientset.RbacV1().ClusterRoleBindings().Get(name, metav1.GetOptions{})
if crbErr == nil {
crbDeleteErr := clientset.RbacV1().ClusterRoleBindings().Delete(crb.Name, metav1.NewDeleteOptions(int64(5)))
if crbDeleteErr != nil {
return fmt.Errorf("couldn't delete clusterrolebinding %v Error: %v", name, crbDeleteErr)
}
}
return nil
}

Expand Down

0 comments on commit 1cf2eaf

Please sign in to comment.