Skip to content

Commit

Permalink
Merge pull request #651 from hzxuzhonghu/fix-cni-uninstall
Browse files Browse the repository at this point in the history
Fix kmesh daemon graceful exit
  • Loading branch information
hzxuzhonghu authored Jul 30, 2024
2 parents 354bba4 + 68d7f31 commit e4143c2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
10 changes: 8 additions & 2 deletions build/docker/start_kmesh.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pid=$!

# pass SIGTERM to kmesh process
function stop_kmesh() {
echo "received SIGTERM, stopping kmesh"
kill $pid
}

Expand All @@ -40,9 +41,14 @@ function cleanup(){
rmmod kmesh
fi

echo "kmesh close"
echo "kmesh exit"
}

trap 'stop_kmesh' SIGTERM
wait # wait child process exit

# wait for kmesh process to exit, cannot use wait $pid here, because the script received SIGTERM, wait will return immediately
while kill -0 $pid 2>/dev/null; do
sleep 1
done

cleanup
8 changes: 4 additions & 4 deletions pkg/bpf/bpf_restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ func inferRestartStatus() StartType {
podName := strings.Split(env.Register("POD_NAME", "", "").Get(), "-")
daemonSetName := podName[0]
daemonSetNamespace := env.Register("POD_NAMESPACE", "", "").Get()
log.Infof("DaemonSet %s in namespace %s\n", daemonSetName, daemonSetNamespace)
log.Infof("trying to get daemonSet %s in namespace %s", daemonSetName, daemonSetNamespace)
daemonSet, err := clientset.AppsV1().DaemonSets(daemonSetNamespace).Get(context.TODO(), daemonSetName, metav1.GetOptions{})
if err == nil {
log.Debugf("Found DaemonSet %s in namespace %s\n", daemonSet.Name, daemonSet.Namespace)
log.Infof("found daemonSet %s in namespace %s", daemonSet.Name, daemonSet.Namespace)
return Restart
}
log.Infof("DaemonSet %s in namespace %s\n", daemonSet.Name, daemonSet.Namespace)
log.Infof("unable to find daemonSet %s in namespace %s: %v ", daemonSetName, daemonSetNamespace, err)
return Normal
}

Expand All @@ -90,7 +90,7 @@ func SetStartStatus(versionMap *ebpf.Map) {
hash.Write([]byte(version.Get().GitVersion))
GitVersion = hash.Sum32()
oldGitVersion := getOldVersionFromMap(versionMap, 0)
log.Debugf("oldGitVersion:%v\nGitVersion:%v", oldGitVersion, GitVersion)
log.Infof("oldGitVersion: %v newGitVersion: %v", oldGitVersion, GitVersion)
if GitVersion == oldGitVersion {
log.Infof("kmesh start with Restart, load bpf maps and prog from last")
SetStartType(Restart)
Expand Down
2 changes: 1 addition & 1 deletion pkg/status/status_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func (s *Server) setBpfLogLevel(w http.ResponseWriter, levelStr string) {
func (s *Server) StartServer() {
go func() {
err := s.server.ListenAndServe()
if err != nil {
if err != nil && err != http.ErrServerClosed {
log.Errorf("Failed to start status server: %v", err)
}
}()
Expand Down

0 comments on commit e4143c2

Please sign in to comment.