mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-09-24 02:49:17 +00:00
Merge pull request #1127 from s1061123/add-ready-check
This change introduces wait to generate config until API is ready
This commit is contained in:
@@ -25,6 +25,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||||
utilwait "k8s.io/apimachinery/pkg/util/wait"
|
utilwait "k8s.io/apimachinery/pkg/util/wait"
|
||||||
@@ -74,6 +75,12 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait until daemon ready
|
||||||
|
if waitUntilAPIReady(daemonConf.SocketDir) != nil {
|
||||||
|
logging.Panicf("failed to ready multus-daemon socket: %v", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
// Generate multus CNI config from current CNI config
|
// Generate multus CNI config from current CNI config
|
||||||
if multusConf.MultusConfigFile == "auto" {
|
if multusConf.MultusConfigFile == "auto" {
|
||||||
if multusConf.CNIVersion == "" {
|
if multusConf.CNIVersion == "" {
|
||||||
@@ -140,6 +147,16 @@ func main() {
|
|||||||
// never reached
|
// never reached
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func waitUntilAPIReady(socketPath string) error {
|
||||||
|
apiReadyPollDuration := 100 * time.Millisecond
|
||||||
|
apiReadyPollTimeout := 1000 * time.Millisecond
|
||||||
|
|
||||||
|
return utilwait.PollImmediate(apiReadyPollDuration, apiReadyPollTimeout, func() (bool, error) {
|
||||||
|
_, err := api.DoCNI(api.GetAPIEndpoint(api.MultusHealthAPIEndpoint), nil, api.SocketPath(socketPath))
|
||||||
|
return err == nil, nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func startMultusDaemon(daemonConfig *srv.ControllerNetConf, stopCh chan struct{}, done chan struct{}) error {
|
func startMultusDaemon(daemonConfig *srv.ControllerNetConf, stopCh chan struct{}, done chan struct{}) error {
|
||||||
if user, err := user.Current(); err != nil || user.Uid != "0" {
|
if user, err := user.Current(); err != nil || user.Uid != "0" {
|
||||||
return fmt.Errorf("failed to run multus-daemon with root: %v, now running in uid: %s", err, user.Uid)
|
return fmt.Errorf("failed to run multus-daemon with root: %v, now running in uid: %s", err, user.Uid)
|
||||||
|
@@ -225,7 +225,7 @@ func newCNIServer(rundir string, kubeClient *k8s.ClientInfo, exec invoke.Exec, s
|
|||||||
// handle for '/healthz'
|
// handle for '/healthz'
|
||||||
router.HandleFunc(api.MultusHealthAPIEndpoint, promhttp.InstrumentHandlerCounter(s.metrics.requestCounter.MustCurryWith(prometheus.Labels{"handler": api.MultusHealthAPIEndpoint}),
|
router.HandleFunc(api.MultusHealthAPIEndpoint, promhttp.InstrumentHandlerCounter(s.metrics.requestCounter.MustCurryWith(prometheus.Labels{"handler": api.MultusHealthAPIEndpoint}),
|
||||||
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != http.MethodGet {
|
if r.Method != http.MethodGet && r.Method != http.MethodPost {
|
||||||
http.Error(w, fmt.Sprintf("Method not allowed"), http.StatusMethodNotAllowed)
|
http.Error(w, fmt.Sprintf("Method not allowed"), http.StatusMethodNotAllowed)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user