Skip to content

Commit

Permalink
Merge pull request #104 from lionelnicolas/bugfix/deployment-wait
Browse files Browse the repository at this point in the history
Fix race condition in deployment ready state detection
  • Loading branch information
omrikiei authored Apr 8, 2023
2 parents b74471d + fcf373f commit 2312c7a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 26 deletions.
25 changes: 0 additions & 25 deletions pkg/k8s/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,31 +103,6 @@ func getAllPods(namespace, kubeCtx *string) (*apiv1.PodList, error) {
return pods, nil
}

func waitForReady(name *string, ti time.Time, numPods int32, readyChan chan<- bool) {
go func() {
for {
print(".")
count := int32(0)
pods, err := podsClient.List(context.Background(), metav1.ListOptions{})
if err != nil {
log.Error(err)
os.Exit(1)
}
for _, p := range pods.Items {
if strings.HasPrefix(p.Name, *name) && p.CreationTimestamp.After(ti.Add(-time.Second)) && p.Status.Phase == apiv1.PodRunning {
count += 1
}
if count == numPods {
readyChan <- true
println()
return
}
}
time.Sleep(time.Millisecond * 300)
}
}()
}

func hasSidecar(podSpec apiv1.PodSpec, image string) bool {
for _, c := range podSpec.Containers {
if c.Image == image {
Expand Down
2 changes: 1 addition & 1 deletion pkg/k8s/exposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func ExposeAsService(namespace, name *string, tunnelPort int, scheme string, raw
}

log.Infof("Exposed service's cluster ip is: %s", newSvc.Spec.ClusterIP)
waitForReady(name, d.GetCreationTimestamp().Time, *deployment.Spec.Replicas, readyChan)
watchForReady(deployment, readyChan)
return nil
}

Expand Down

0 comments on commit 2312c7a

Please # to comment.