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

Fix DestroyWorkers not retrying operations #639

Merged
merged 1 commit into from
Aug 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
43 changes: 34 additions & 9 deletions pkg/installer/installation/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,49 @@ func Reset(s *state.State) error {
}

func destroyWorkers(s *state.State) error {
var lastErr error
s.Logger.Infoln("Destroying worker nodes…")

waitErr := wait.ExponentialBackoff(defaultRetryBackoff(3), func() (bool, error) {
err := kubeconfig.BuildKubernetesClientset(s)
return err == nil, errors.Wrap(err, "unable to build kubernetes clientset")
_ = wait.ExponentialBackoff(defaultRetryBackoff(3), func() (bool, error) {
lastErr = kubeconfig.BuildKubernetesClientset(s)
if lastErr != nil {
s.Logger.Warn("Unable to connect to the control plane API. Retrying…")
return false, nil
}
return true, nil

})
if waitErr != nil {
if lastErr != nil {
s.Logger.Warn("Unable to connect to the control plane API and destroy worker nodes")
s.Logger.Warn("You can skip destroying worker nodes and destroy them manually using `--destroy-workers=false`")
return waitErr
return errors.Wrap(lastErr, "unable to build kubernetes clientset")
}

waitErr = wait.ExponentialBackoff(defaultRetryBackoff(3), func() (bool, error) {
err := machinecontroller.DestroyWorkers(s)
return err == nil, errors.Wrap(err, "unable to delete all worker nodes")
_ = wait.ExponentialBackoff(defaultRetryBackoff(3), func() (bool, error) {
lastErr = machinecontroller.DestroyWorkers(s)
if lastErr != nil {
s.Logger.Warn("Unable to destroy worker nodes. Retrying…")
return false, nil
}
return true, nil
})
if lastErr != nil {
return errors.Wrap(lastErr, "unable to delete all worker nodes")
}

return waitErr
_ = wait.ExponentialBackoff(defaultRetryBackoff(3), func() (bool, error) {
lastErr = machinecontroller.WaitDestroy(s)
if lastErr != nil {
s.Logger.Warn("Waiting for all machines to be deleted…")
return false, nil
}
return true, nil
})
if lastErr != nil {
return errors.Wrap(lastErr, "error waiting for machines to be deleted")
}

return nil
}

func resetNode(s *state.State, _ *kubeoneapi.HostConfig, conn ssh.Connection) error {
Expand Down
8 changes: 7 additions & 1 deletion pkg/templates/machinecontroller/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,14 @@ func DestroyWorkers(s *state.State) error {
}
}

// Wait for all Machines to be deleted
return nil
}

// WaitDestroy waits for all Machines to be deleted
func WaitDestroy(s *state.State) error {
s.Logger.Info("Waiting for all machines to get deleted…")

bgCtx := context.Background()
return wait.Poll(5*time.Second, 5*time.Minute, func() (bool, error) {
list := &clusterv1alpha1.MachineList{}
if err := s.DynamicClient.List(bgCtx, dynclient.InNamespace(MachineControllerNamespace), list); err != nil {
Expand Down