Skip to content

Commit

Permalink
chore(kubernetes): WaitForKubernetesNodeGroupState method to wait f…
Browse files Browse the repository at this point in the history
…irst (#274)
  • Loading branch information
villevsv-upcloud authored Oct 25, 2023
1 parent b64f2f0 commit 68885c4
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions upcloud/service/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,16 @@ func (s *Service) WaitForKubernetesNodeGroupState(ctx context.Context, r *reques

for {
attempts++
time.Sleep(sleepDuration)

ng, err := s.GetKubernetesNodeGroup(ctx, &request.GetKubernetesNodeGroupRequest{
ClusterUUID: r.ClusterUUID,
Name: r.Name,
})
if err != nil {
// Ignore first two 404 responses to avoid errors caused by possible false NOT_FOUND responses right after cluster has been created.
// Ignore first two 404 responses to avoid errors caused by possible false NOT_FOUND responses right after cluster or node group has been created.
var ucErr *upcloud.Problem
if errors.As(err, &ucErr) && ucErr.Status == http.StatusNotFound && attempts < 3 {
log.Printf("ERROR: %+v", err)
} else {
if !(errors.As(err, &ucErr) && ucErr.Status == http.StatusNotFound) || attempts >= 3 {
return nil, err
}
}
Expand All @@ -136,8 +135,6 @@ func (s *Service) WaitForKubernetesNodeGroupState(ctx context.Context, r *reques
return &ng.KubernetesNodeGroup, nil
}

time.Sleep(sleepDuration)

if time.Duration(attempts)*sleepDuration >= r.Timeout {
return nil, fmt.Errorf("timeout reached while waiting for Kubernetes node group to enter state \"%s\"", r.DesiredState)
}
Expand Down

0 comments on commit 68885c4

Please sign in to comment.