edselwang
edselwang

Reputation: 57

kubernetes Client-go kubectl rollout example

Could anyone get me a example about how to use

kubectl rollout pause xxx

kubectl rollout update xxx

in client-go? I can't find any example about it. Thank you~

Upvotes: 1

Views: 2763

Answers (2)

Yoonga
Yoonga

Reputation: 31

maybe .

data := fmt.Sprintf(`{"spec":{"template":{"metadata":{"annotations":{"kubectl.kubernetes.io/restartedAt":"%s"}}}}}`, time.Now().String())
    resultDeployment, err = p.Client.AppsV1().Deployments(p.Namespace).Patch(context.Background(), deployment.Name, types.StrategicMergePatchType, []byte(data), metav1.PatchOptions{FieldManager: "kubectl-rollout"})

you can use kubectl with --v=6 to see the logs, for example kubectl get pods --v=6, and build a request use go-client.

Upvotes: 3

Crou
Crou

Reputation: 11418

As we can read in the Kubernetes docs Pausing and Resuming a Deployment.

You can pause a Deployment before triggering one or more updates and then resume it. This allows you to apply multiple fixes in between pausing and resuming without triggering unnecessary rollouts.

Updating a Deployment using Go-Client is easy because you are just updating the fields that you want to change, and once done commit them. So as long as you don't push the changes to the cluster you can still add new updates.

Here is a article on How to write Kubernetes custom controllers in Go and another one about Updating and rolling back a deployment.

Upvotes: 0

Related Questions