How to scale multiple deployments and wait for rollout in parallel

4/12/2019

I want to scale deployment(s) with the kubernetes go client and wait until rollout is finished successfully. I already created working solution but was wondering if i miss any edge cases or can improve it.

My first very simple solution:

for _, deployment := range deploymentList.Items {
  deployment.Spec.Replicas = int32Ptr(1)
  _, err := deploymentsClient.Update(&deployment)
  if err != nil {
    panic(err)
  }
}

for {
  deploymentList, err = deploymentsClient.List(opts)
  if err != nil {
    panic(fmt.Errorf("List deployments failed: %v", err))
  }
  # checks if DeploymentAvailable and Status is "True"
  if available(deploymentList) {
    fmt.Println("Rolled out")
    break
  }
  fmt.Println("Not rolled out")
  time.Sleep(5 * time.Second)
}

This works but I don't like the idea of polling.

The second solution is inspired by kubectl rollout status. I adjusted the code to my needs and it's working. But I'm not sure how to do it for multiple deployments in parallel (do something with channels?).

-- rabenhorst
kubernetes-go-client

1 Answer

10/26/2019

You could subscribe or watch for changes on your Deployment using an Informer in client-go.

This is a bit more complex code, but as you say, it is a solution if you don't want to do polling.

Here are a few examples:

-- Jonas
Source: StackOverflow