Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: for readiness check both the phase and ready status #277

Merged
merged 4 commits into from
Dec 8, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions go-chaos/internal/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,32 +121,33 @@ func (c K8Client) RestartPodWithGracePeriod(podName string, gracePeriodSec *int6
}

func (c K8Client) AwaitReadiness() error {
retries := 0
maxRetries := 300 // 5 * 60s
for {
if retries >= maxRetries {
return errors.New("Awaited readiness of pods in namespace %s, but timed out after 30s")
}
if retries > 0 {
time.Sleep(1 * time.Second)
}
return c.AwaitReadinessWithTimeout(5 * time.Minute)
}

brokersAreRunning, err := c.checkIfBrokersAreRunning()
if err != nil {
return err
}
func (c K8Client) AwaitReadinessWithTimeout(timeout time.Duration) error {
timedOut := time.After(timeout)
ticker := time.Tick(1 * time.Second)

gatewaysAreRunning, err := c.checkIfGatewaysAreRunning()
if err != nil {
return err
}
// Keep checking until we're timed out
for {
select {
case <-timedOut:
return errors.New(fmt.Sprintf("Awaited readiness of pods in namespace %v, but timed out after %v", c.GetCurrentNamespace(), timeout))
case <-ticker:
Comment on lines +134 to +136
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Yeah I thought also last week that we can write this better with channels thanks for improving this 🚀

brokersAreRunning, err := c.checkIfBrokersAreRunning()
if err != nil {
LogVerbose("Failed to check broker status. Will retry. %v", err)
}
gatewaysAreRunning, err := c.checkIfGatewaysAreRunning()
if err != nil {
LogVerbose("Failed to check gateway status. Will retry. %v", err)
}

if brokersAreRunning && gatewaysAreRunning {
break
if brokersAreRunning && gatewaysAreRunning {
return nil
}
}
retries++
}
return nil
}

func (c K8Client) checkIfBrokersAreRunning() (bool, error) {
Expand Down