Skip to content

Commit

Permalink
call package manager, then platform in delete. Allow ksonnet to delet…
Browse files Browse the repository at this point in the history
…e k8s
  • Loading branch information
Kam D Kasravi committed Mar 27, 2019
1 parent 75f3d30 commit 068f530
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 44 deletions.
6 changes: 3 additions & 3 deletions bootstrap/pkg/kfapp/coordinator/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,11 @@ func (kfapp *coordinator) Delete(resources kftypes.ResourceEnum) error {

switch resources {
case kftypes.ALL:
if err := platform(); err != nil {
fallthrough
case kftypes.PLATFORM:
if err := k8s(); err != nil {
return err
}
return k8s()
case kftypes.PLATFORM:
return platform()
case kftypes.K8S:
return k8s()
Expand Down
80 changes: 39 additions & 41 deletions bootstrap/pkg/kfapp/ksonnet/ksonnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,48 +288,46 @@ func (ksApp *ksApp) deleteGlobalResources(config *rest.Config) error {
}

func (ksApp *ksApp) Delete(resources kftypes.ResourceEnum) error {
if ksApp.Spec.Platform != kftypes.GCP {
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)
}
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)
}
}
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 068f530

Please sign in to comment.