Wait for deployment replicas == 0

This commit is contained in:
danielgormly
2019-08-26 15:00:34 +10:00
parent abbde42209
commit b74736516e
3 changed files with 11 additions and 7 deletions
+9 -5
View File
@@ -1,7 +1,6 @@
package main
import (
"fmt"
"log"
"strings"
@@ -15,11 +14,11 @@ import (
func CreateOrUpdateDeployment(clientset *kubernetes.Clientset, namespace string, deployment *appv1.Deployment) error {
deploymentExists, err := deploymentExists(clientset, namespace, deployment.Name)
if deploymentExists {
log.Printf("📦 Found existing deployment. Updating.")
log.Printf("📦 Found existing deployment '%s'. Updating.", deployment.Name)
_, err = clientset.AppsV1().Deployments(namespace).Update(deployment)
return err
}
log.Printf("📦 Creating new deployment.")
log.Printf("📦 Creating new deployment '%s'. Updating.", deployment.Name)
_, err = clientset.AppsV1().Deployments(namespace).Create(deployment)
return err
}
@@ -48,13 +47,18 @@ func waitUntilDeploymentSettled(clientset *kubernetes.Clientset, namespace strin
watcher, error := clientset.AppsV1().Deployments(namespace).Watch(watchOptions)
liveDeployment, error := clientset.AppsV1().Deployments(namespace).Get(name, meta.GetOptions{})
log.Printf("📦 Unavailable replicas: %d", liveDeployment.Status.UnavailableReplicas)
log.Printf("📦 %s", liveDeployment)
if liveDeployment.Status.UnavailableReplicas == 0 {
return "ready", error
return "📦 Updated", error
}
i := 0
for {
event := <-watcher.ResultChan()
fmt.Printf("%s\n\n", event.Object)
deployment := event.Object.(*appv1.Deployment)
if liveDeployment.Status.UnavailableReplicas == 0 {
return "📦 Updated", error
}
log.Printf("📦 Unavailable replicas: %d", deployment.Status.UnavailableReplicas)
i++
}
return "failed", error
+1 -1
View File
@@ -89,7 +89,7 @@ func (p Plugin) Exec() error {
return err
}
// Watch for successful update
log.Print("📦 Waiting for succesful update")
log.Print("📦 Watching deployment until no unavailable replicas.")
state, watchErr := waitUntilDeploymentSettled(clientset, p.KubeConfig.Namespace, o.ObjectMeta.Name, 120)
log.Printf("%s", state)
return watchErr
+1 -1
View File
@@ -14,7 +14,7 @@ spec:
spec:
containers:
- name: nginx
image: nginx:alpine
image: nginx
ports:
- containerPort: 80
imagePullSecrets: