Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes 'kfctl delete fails when no platform or minikube is specified' #2810

Merged
merged 5 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Add a comment explaining why we want to call K8s as part of platform deletion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

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