mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-09-19 00:11:09 +00:00
Adds a wait to account for the possiblity of a not ready unix socket
This commit is contained in:
@@ -22,9 +22,17 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
utilwait "k8s.io/apimachinery/pkg/util/wait"
|
||||
)
|
||||
|
||||
const (
|
||||
// APIReadyPollDuration specifies duration for API readiness check polling
|
||||
APIReadyPollDuration = 100 * time.Millisecond
|
||||
// APIReadyPollTimeout specifies timeout for API readiness check polling
|
||||
APIReadyPollTimeout = 60000 * time.Millisecond
|
||||
|
||||
// MultusCNIAPIEndpoint is an endpoint for multus CNI request (for multus-shim)
|
||||
MultusCNIAPIEndpoint = "/cni"
|
||||
// MultusDelegateAPIEndpoint is an endpoint for multus delegate request (for hotplug)
|
||||
@@ -88,3 +96,11 @@ func CreateDelegateRequest(cniCommand, cniContainerID, cniNetNS, cniIFName, podN
|
||||
InterfaceAttributes: interfaceAttributes,
|
||||
}
|
||||
}
|
||||
|
||||
// WaitUntilAPIReady checks API readiness
|
||||
func WaitUntilAPIReady(socketPath string) error {
|
||||
return utilwait.PollImmediate(APIReadyPollDuration, APIReadyPollTimeout, func() (bool, error) {
|
||||
_, err := DoCNI(GetAPIEndpoint(MultusHealthAPIEndpoint), nil, SocketPath(socketPath))
|
||||
return err == nil, nil
|
||||
})
|
||||
}
|
||||
|
@@ -24,6 +24,8 @@ import (
|
||||
cnitypes "github.com/containernetworking/cni/pkg/types"
|
||||
|
||||
"gopkg.in/k8snetworkplumbingwg/multus-cni.v4/pkg/logging"
|
||||
|
||||
utilwait "k8s.io/apimachinery/pkg/util/wait"
|
||||
)
|
||||
|
||||
// ShimNetConf for the SHIM cni config file written in json
|
||||
@@ -77,12 +79,21 @@ func postRequest(args *skel.CmdArgs) (*Response, string, error) {
|
||||
return nil, "", fmt.Errorf("invalid CNI configuration passed to multus-shim: %w", err)
|
||||
}
|
||||
|
||||
// check API readiness
|
||||
if err := WaitUntilAPIReady(multusShimConfig.MultusSocketDir); err != nil {
|
||||
return nil, multusShimConfig.CNIVersion, err
|
||||
}
|
||||
|
||||
cniRequest, err := newCNIRequest(args)
|
||||
if err != nil {
|
||||
return nil, multusShimConfig.CNIVersion, err
|
||||
}
|
||||
|
||||
body, err := DoCNI("http://dummy/cni", cniRequest, SocketPath(multusShimConfig.MultusSocketDir))
|
||||
var body []byte
|
||||
err = utilwait.PollImmediate(APIReadyPollDuration, APIReadyPollTimeout, func() (bool, error) {
|
||||
body, err = DoCNI("http://dummy/cni", cniRequest, SocketPath(multusShimConfig.MultusSocketDir))
|
||||
return err == nil, nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, multusShimConfig.CNIVersion, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user