Skip to content

Commit

Permalink
Merge pull request kubeedge#5804 from luomengY/fix_edged_start
Browse files Browse the repository at this point in the history
Optimize the syncPod startup time for edge nodes.
  • Loading branch information
kubeedge-bot authored Aug 19, 2024
2 parents cf8ca4d + 2e51443 commit 5b696a2
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions edge/pkg/edged/edged.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"context"
"encoding/json"
"fmt"
"net/http"
"os"
"reflect"
"strconv"
Expand Down Expand Up @@ -148,9 +149,8 @@ func (e *edged) Start() {
}
}()

// block until kubelet is ready to sync pods
startWaiter := time.NewTimer(10 * time.Second)
defer startWaiter.Stop()
kubeletReadyChan := make(chan struct{}, 1)
go kubeletHealthCheck(e.KubeletServer.ReadOnlyPort, kubeletReadyChan)

select {
case <-beehiveContext.Done():
Expand All @@ -159,7 +159,7 @@ func (e *edged) Start() {
case err := <-kubeletErrChan:
klog.Errorf("Failed to start edged, err: %v", err)
return
case <-startWaiter.C:
case <-kubeletReadyChan:
klog.Info("Start sync pod")
}

Expand Down Expand Up @@ -491,3 +491,29 @@ func (e *edged) controllerUnpublishVolume(content []byte) (interface{}, error) {
func filterPodByNodeName(pod *v1.Pod, nodeName string) bool {
return pod.Spec.NodeName == nodeName
}

func kubeletHealthCheck(port int32, kubeletReadyChan chan struct{}) {
url := fmt.Sprintf("http://localhost:%d/healthz/syncloop", port)
for {
resp, err := http.Get(url)
if err != nil {
klog.Warningf("failed to get kubelet healthz syncloop, err: %v", err)
time.Sleep(50 * time.Millisecond)
continue
}

statusCode := resp.StatusCode
err = resp.Body.Close()
if err != nil {
klog.Errorf("failed to close response's body with err:%v", err)
}

if statusCode != http.StatusOK {
klog.Warningf("internal error and status code: %d", resp.StatusCode)
} else {
kubeletReadyChan <- struct{}{}
break
}
time.Sleep(50 * time.Millisecond)
}
}

0 comments on commit 5b696a2

Please sign in to comment.