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

Add retry mechanism to CNI interface discovery on kube-proxy handler #3121

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Changes from all commits
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
23 changes: 22 additions & 1 deletion pkg/routeagent_driver/handlers/kubeproxy/kp_packetfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package kubeproxy
import (
"net"
"os"
"time"

"github.com/pkg/errors"
"github.com/submariner-io/admiral/pkg/log"
Expand All @@ -31,6 +32,8 @@ import (
"github.com/submariner-io/submariner/pkg/packetfilter"
"github.com/submariner-io/submariner/pkg/vxlan"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/util/retry"
"k8s.io/utils/set"
logf "sigs.k8s.io/controller-runtime/pkg/log"
)
Expand Down Expand Up @@ -91,8 +94,16 @@ func (kp *SyncHandler) GetNetworkPlugins() []string {
return networkPlugins
}

var discoverCNIRetryConfig = wait.Backoff{
Cap: 1 * time.Minute,
Duration: 4 * time.Second,
Factor: 1.2,
Steps: 12,
}

func (kp *SyncHandler) Init() error {
var err error
var cniIface *cni.Interface

kp.hostname, err = os.Hostname()
if err != nil {
Expand All @@ -104,7 +115,17 @@ func (kp *SyncHandler) Init() error {
return errors.Wrapf(err, "Unable to find the default interface on host: %s", kp.hostname)
}

cniIface, err := cni.Discover(kp.localClusterCidr)
err = retry.OnError(discoverCNIRetryConfig, func(err error) bool {
logger.Infof("Waiting for CNI interface discovery: %s", err)
return true
}, func() error {
cniIface, err = cni.Discover(kp.localClusterCidr)
if err != nil {
return errors.Wrapf(err, "Error discovering the CNI interface")
}

return nil
})
if err == nil {
// Configure CNI Specific changes
kp.cniIface = cniIface
Expand Down
Loading