Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Copy wait utilities from Kubernetes to reduce code bloat
Browse files Browse the repository at this point in the history
  • Loading branch information
bboreham committed Jul 29, 2020
1 parent 6bc656d commit 48b6315
Show file tree
Hide file tree
Showing 2 changed files with 386 additions and 6 deletions.
11 changes: 5 additions & 6 deletions net/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/coreos/go-iptables/iptables"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
utilwait "k8s.io/apimachinery/pkg/util/wait"
)

// AddChainWithRules creates a chain and appends given rules to it.
Expand Down Expand Up @@ -152,7 +151,7 @@ func MonitorForIptablesFlush(log *logrus.Logger, canary string, tables []string,
}, stopCh)

// Poll until stopCh is closed or iptables is flushed
err = utilwait.PollUntil(interval, func() (bool, error) {
err = PollUntil(interval, func() (bool, error) {
if exists, err := chainExists(ipt, tables[0], canary); exists {
return false, nil
} else if isResourceError(err) {
Expand All @@ -163,7 +162,7 @@ func MonitorForIptablesFlush(log *logrus.Logger, canary string, tables []string,

// Wait for the other canaries to be deleted too before returning
// so we don't start reloading too soon.
err := utilwait.PollImmediate(iptablesFlushPollTime, iptablesFlushTimeout, func() (bool, error) {
err := PollImmediate(iptablesFlushPollTime, iptablesFlushTimeout, func() (bool, error) {
for i := 1; i < len(tables); i++ {
if exists, err := chainExists(ipt, tables[i], canary); exists || isResourceError(err) {
return false, nil
Expand Down Expand Up @@ -209,7 +208,7 @@ func isResourceError(err error) bool {
//
// PollImmediateUntil runs the 'condition' before waiting for the interval.
// 'condition' will always be invoked at least once.
func PollImmediateUntil(interval time.Duration, condition utilwait.ConditionFunc, stopCh <-chan struct{}) error {
func PollImmediateUntil(interval time.Duration, condition ConditionFunc, stopCh <-chan struct{}) error {
done, err := condition()
if err != nil {
return err
Expand All @@ -219,8 +218,8 @@ func PollImmediateUntil(interval time.Duration, condition utilwait.ConditionFunc
}
select {
case <-stopCh:
return utilwait.ErrWaitTimeout
return ErrWaitTimeout
default:
return utilwait.PollUntil(interval, condition, stopCh)
return PollUntil(interval, condition, stopCh)
}
}
Loading

0 comments on commit 48b6315

Please sign in to comment.