mirror of https://github.com/kubernetes/kops.git
Merge pull request #16231 from hakman/cluster-deletion-configurable
Make cluster deletion configurable
This commit is contained in:
commit
dc829682bd
|
|
@ -20,6 +20,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
|
|
@ -44,6 +45,14 @@ type DeleteClusterOptions struct {
|
||||||
External bool
|
External bool
|
||||||
Unregister bool
|
Unregister bool
|
||||||
ClusterName string
|
ClusterName string
|
||||||
|
wait time.Duration
|
||||||
|
count int
|
||||||
|
interval time.Duration
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *DeleteClusterOptions) InitDefaults() {
|
||||||
|
o.count = 42
|
||||||
|
o.interval = 10 * time.Second
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -64,6 +73,7 @@ var (
|
||||||
|
|
||||||
func NewCmdDeleteCluster(f *util.Factory, out io.Writer) *cobra.Command {
|
func NewCmdDeleteCluster(f *util.Factory, out io.Writer) *cobra.Command {
|
||||||
options := &DeleteClusterOptions{}
|
options := &DeleteClusterOptions{}
|
||||||
|
options.InitDefaults()
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "cluster [CLUSTER]",
|
Use: "cluster [CLUSTER]",
|
||||||
|
|
@ -84,6 +94,10 @@ func NewCmdDeleteCluster(f *util.Factory, out io.Writer) *cobra.Command {
|
||||||
cmd.Flags().StringVar(&options.Region, "region", options.Region, "External cluster's cloud region")
|
cmd.Flags().StringVar(&options.Region, "region", options.Region, "External cluster's cloud region")
|
||||||
cmd.RegisterFlagCompletionFunc("region", completeRegion)
|
cmd.RegisterFlagCompletionFunc("region", completeRegion)
|
||||||
|
|
||||||
|
cmd.Flags().DurationVar(&options.wait, "wait", options.wait, "Amount of time to wait for the cluster resources to de deleted")
|
||||||
|
cmd.Flags().IntVar(&options.count, "count", options.count, "Number of consecutive failures to make progress deleting the cluster resources")
|
||||||
|
cmd.Flags().DurationVar(&options.interval, "interval", options.interval, "Time in duration to wait between deletion attempts")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -171,7 +185,7 @@ func RunDeleteCluster(ctx context.Context, f *util.Factory, out io.Writer, optio
|
||||||
|
|
||||||
fmt.Fprintf(out, "\n")
|
fmt.Fprintf(out, "\n")
|
||||||
|
|
||||||
err = resourceops.DeleteResources(cloud, clusterResources)
|
err = resourceops.DeleteResources(cloud, clusterResources, options.count, options.interval, options.wait)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,11 +24,14 @@ kops delete cluster [CLUSTER] [flags]
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
```
|
```
|
||||||
--external Delete an external cluster
|
--count int Number of consecutive failures to make progress deleting the cluster resources (default 42)
|
||||||
-h, --help help for cluster
|
--external Delete an external cluster
|
||||||
--region string External cluster's cloud region
|
-h, --help help for cluster
|
||||||
--unregister Don't delete cloud resources, just unregister the cluster
|
--interval duration Time in duration to wait between deletion attempts (default 10s)
|
||||||
-y, --yes Specify --yes to delete the cluster
|
--region string External cluster's cloud region
|
||||||
|
--unregister Don't delete cloud resources, just unregister the cluster
|
||||||
|
--wait duration Amount of time to wait for the cluster resources to de deleted
|
||||||
|
-y, --yes Specify --yes to delete the cluster
|
||||||
```
|
```
|
||||||
|
|
||||||
### Options inherited from parent commands
|
### Options inherited from parent commands
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// DeleteResources deletes the resources, as previously collected by ListResources
|
// DeleteResources deletes the resources, as previously collected by ListResources
|
||||||
func DeleteResources(cloud fi.Cloud, resourceMap map[string]*resources.Resource) error {
|
func DeleteResources(cloud fi.Cloud, resourceMap map[string]*resources.Resource, count int, interval, wait time.Duration) error {
|
||||||
depMap := make(map[string][]string)
|
depMap := make(map[string][]string)
|
||||||
|
|
||||||
done := make(map[string]*resources.Resource)
|
done := make(map[string]*resources.Resource)
|
||||||
|
|
@ -52,9 +52,12 @@ func DeleteResources(cloud fi.Cloud, resourceMap map[string]*resources.Resource)
|
||||||
klog.V(2).Infof("\t%s\t%v", k, v)
|
klog.V(2).Infof("\t%s\t%v", k, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timeout := time.Now().Add(wait)
|
||||||
iterationsWithNoProgress := 0
|
iterationsWithNoProgress := 0
|
||||||
for {
|
for {
|
||||||
// TODO: Some form of default ordering based on types?
|
if wait > 0 && time.Now().After(timeout) {
|
||||||
|
return fmt.Errorf("wait time exceeded during resources deletion")
|
||||||
|
}
|
||||||
|
|
||||||
failed := make(map[string]*resources.Resource)
|
failed := make(map[string]*resources.Resource)
|
||||||
|
|
||||||
|
|
@ -167,10 +170,10 @@ func DeleteResources(cloud fi.Cloud, resourceMap map[string]*resources.Resource)
|
||||||
}
|
}
|
||||||
|
|
||||||
iterationsWithNoProgress++
|
iterationsWithNoProgress++
|
||||||
if iterationsWithNoProgress > 42 {
|
if iterationsWithNoProgress > count && count != 0 {
|
||||||
return fmt.Errorf("not making progress deleting resources; giving up")
|
return fmt.Errorf("not making progress deleting resources; giving up")
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(10 * time.Second)
|
time.Sleep(interval)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue