Skip to content

Commit

Permalink
Merge pull request #105 from uselagoon/fix-scale
Browse files Browse the repository at this point in the history
fix: possible race condition with new unidle functionality
  • Loading branch information
smlx authored Sep 6, 2022
2 parents 9a8fdbd + 4ab22d1 commit 01f7d5b
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions internal/k8s/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,15 @@ func (c *Client) ensureScaled(ctx context.Context, namespace, deployment string)
if err != nil {
return fmt.Errorf("couldn't get deployment scale: %v", err)
}
// exit early if no change required
if s.Spec.Replicas > 0 {
return nil
}
// scale up the deployment
sc := *s
sc.Spec.Replicas = 1
_, err = c.clientset.AppsV1().Deployments(namespace).
UpdateScale(ctx, deployment, &sc, metav1.UpdateOptions{})
if err != nil {
return fmt.Errorf("couldn't scale deployment: %v", err)
// scale up the deployment if required
if s.Spec.Replicas == 0 {
sc := *s
sc.Spec.Replicas = 1
_, err = c.clientset.AppsV1().Deployments(namespace).
UpdateScale(ctx, deployment, &sc, metav1.UpdateOptions{})
if err != nil {
return fmt.Errorf("couldn't scale deployment: %v", err)
}
}
// wait for a pod to start running
return wait.PollImmediateWithContext(ctx, time.Second, timeout,
Expand Down

0 comments on commit 01f7d5b

Please sign in to comment.