-
Notifications
You must be signed in to change notification settings - Fork 91
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
kmesh support restart by reload old bpf map and prog #475
Conversation
daemon/manager/manager.go
Outdated
@@ -101,17 +101,23 @@ func Execute(configs *options.BootstrapConfigs) error { | |||
log.Info("command Start cni successful") | |||
defer cniInstaller.Stop() | |||
|
|||
setupCloseHandler() | |||
*configs.Status = setupCloseHandler() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assign an int to a pointer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I want the data in configs.Status and configs.BpfConfig.Status to be the same at the same time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can change status from pointer to int
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add a KmeshStartStatus in bpf
daemon/manager/manager.go
Outdated
@@ -101,17 +101,23 @@ func Execute(configs *options.BootstrapConfigs) error { | |||
log.Info("command Start cni successful") | |||
defer cniInstaller.Stop() | |||
|
|||
setupCloseHandler() | |||
*configs.Status = setupCloseHandler() | |||
log.Printf("bpfLoader.Restart %v", *configs.Status) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.Printf("bpfLoader.Restart %v", *configs.Status) | |
log.Printf("Kmesh Restart %d", *configs.Status) |
pkg/bpf/bpf.go
Outdated
@@ -30,6 +30,7 @@ import ( | |||
|
|||
"kmesh.net/kmesh/daemon/options" | |||
"kmesh.net/kmesh/pkg/logger" | |||
pkgversion "kmesh.net/kmesh/pkg/version" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use version directly?
pkgversion "kmesh.net/kmesh/pkg/version" | |
"kmesh.net/kmesh/pkg/version" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/bpf/bpf.go
Outdated
@@ -49,11 +50,15 @@ type BpfLoader struct { | |||
|
|||
obj *BpfKmesh | |||
workloadObj *BpfKmeshWorkload | |||
Status *int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Status *int | |
Status int |
pkg/bpf/bpf_kmesh_workload.go
Outdated
} | ||
|
||
if err := sc.Link.Pin(sc.Info.BpfFsPath + "sockconn_prog"); err != nil { | ||
log.Printf("file exit %v", sc.Info.BpfFsPath+"sockconn_prog") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.Printf("file exit %v", sc.Info.BpfFsPath+"sockconn_prog") | |
log.Printf("file exited %s", sc.Info.BpfFsPath+"sockconn_prog") |
pkg/bpf/bpf_restart.go
Outdated
@@ -0,0 +1,57 @@ | |||
/* | |||
* Copyright 2023 The Kmesh Authors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Copyright 2023 The Kmesh Authors. | |
* Copyright 2024 The Kmesh Authors. |
pkg/version/version.go
Outdated
|
||
err = m.Pin(versionPath + "kmesh_version") | ||
if err != nil { | ||
log.Errorf("kmesh_version failed to pin: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.Errorf("kmesh_version failed to pin: %v", err) | |
log.Errorf("kmesh_version pin failed: %v", err) |
@lec-bit Can you fix and prevent force pushing? So it will be firendly to reviewers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we make version map as a global config used by kmesh, in future we could expand it.
In addition, can we store it in the files instead of bpf map, which seems unnecessary.
umount -t cgroup2 /mnt/kmesh_cgroup2/ | ||
rm -rf /mnt/kmesh_cgroup2 | ||
rm -rf /sys/fs/bpf/bpf_kmesh | ||
echo "kmesh close" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo "kmesh close" | |
echo "kmesh exit" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
daemon/manager/manager.go
Outdated
@@ -101,17 +101,23 @@ func Execute(configs *options.BootstrapConfigs) error { | |||
log.Info("command Start cni successful") | |||
defer cniInstaller.Stop() | |||
|
|||
setupCloseHandler() | |||
*configs.Status = setupCloseHandler() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can change status from pointer to int
pkg/bpf/bpf_restart.go
Outdated
log.Printf("daemonset err:%v", err) | ||
return false | ||
} | ||
return true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not right, you should check the kmesh name.
pkg/version/version.go
Outdated
if config.AdsEnabled() { | ||
versionPath = config.BpfFsPath + "/bpf_kmesh/map/kmesh_version" | ||
} else if config.WdsEnabled() { | ||
versionPath = config.BpfFsPath + "/bpf_kmesh_workload/map/kmesh_version" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yoiu can remove the duplicate path construct within NewVersionMap
pkg/version/version.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move the logic of map operation out to bpf loader of bpf.go
pkg/version/version.go
Outdated
NewStart = iota | ||
Restart | ||
Update | ||
Reload |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does reload mean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mean we need to reload bpf map, it is restart
pkg/version/version.go
Outdated
const ( | ||
NewStart = iota | ||
Restart | ||
Update |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and update means what?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the future update scenario, if the two gitversions are different after the kmesh is restarted, it indicates that the update scenario is used and the previous configuration is not load.
daemon/manager/manager.go
Outdated
return nil | ||
} | ||
|
||
func setupCloseHandler() { | ||
func setupCloseHandler() int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function seems to be used to handle os signal and it's weired to get status
and return here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn‘t matter, i can move func GetDaemonset out
daemon/manager/manager.go
Outdated
ch := make(chan os.Signal, 1) | ||
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGHUP, syscall.SIGABRT, syscall.SIGTSTP) | ||
|
||
<-ch | ||
|
||
log.Warn("exiting...") | ||
|
||
if bpf.GetDaemonset() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why if we get Kmesh daemonset object, we could make sure it's restart?
When Kmesh is create for the first time, it always creates the Kmesh DaemonSet object first and then creates the Kmesh pods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, always creates the Kmesh DaemonSet object first and then creates the Kmesh pods.
and by end, there is some confusion,
although the current I can judge if restart by daemonset in bpfLoader.Stop, there is still a lack of theoretical basis
pkg/bpf/bpf_restart.go
Outdated
return true | ||
} | ||
|
||
func cleanupMountPath() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is not used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, forget
now in bpfLoader.Stop
pkg/bpf/bpf_restart.go
Outdated
NewStart = iota | ||
Restart | ||
Update | ||
Reload |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These constants also defined in pkg/version
, can they be defined in one place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved
Codecov ReportAttention: Patch coverage is
... and 5 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
@lec-bit ping me when it is ready |
5b9a91a
to
e72518c
Compare
@hzxuzhonghu I have added test cases and fully verified this part of the function, and it can be merged now. |
Will take a look later |
deploy/yaml/clusterrole.yaml
Outdated
@@ -8,3 +8,6 @@ rules: | |||
- apiGroups: [""] | |||
resources: ["pods","services","namespaces"] | |||
verbs: ["get", "update", "patch", "list", "watch"] | |||
- apiGroups: ["apps"] | |||
resources: ["daemonsets"] | |||
verbs: ["list", "get"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to align with above, i think you donot need list permission
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, i will delete
pkg/bpf/bpf.go
Outdated
} | ||
|
||
func NewBpfLoader(config *options.BpfConfig) *BpfLoader { | ||
return &BpfLoader{ | ||
config: config, | ||
config: config, | ||
StatusMap: NewVersionMap(config), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StatusMap or VersionMap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, VersionMap
|
||
const ( | ||
NewStart = iota | ||
Restart |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add some comments
pkg/bpf/bpf_restart.go
Outdated
@@ -0,0 +1,100 @@ | |||
/* | |||
* Copyright 2024 The Kmesh Authors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove year
pkg/bpf/bpf_restart.go
Outdated
} | ||
|
||
func CleanupBpfMap() { | ||
err := syscall.Unmount("/mnt/kmesh_cgroup2", 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prevent hardcoding
pkg/bpf/bpf_restart.go
Outdated
if GetDaemonset() { | ||
SetKmeshStartStatus(Restart) | ||
} else { | ||
SetKmeshStartStatus(NewStart) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure i understand the intention here, since it is closing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i will check the name
pkg/bpf/bpf_restart.go
Outdated
kmeshStartStatus = Status | ||
} | ||
|
||
func GetDaemonset() bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be more clear, we can move this implement detail into a function InferRestartStatus
pkg/bpf/bpf_restart.go
Outdated
|
||
var kmeshStartStatus int | ||
|
||
func GetKmeshStartStatus() int { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confusing with GetStartStatus
Signed-off-by: lec-bit <glfhmzmy@126.com>
Signed-off-by: let-bit <glfhmzmy@126.com>
Signed-off-by: let-bit <glfhmzmy@126.com>
Signed-off-by: let-bit <glfhmzmy@126.com>
Signed-off-by: let-bit <glfhmzmy@126.com>
pkg/bpf/bpf_restart.go
Outdated
// Normal: a normal new start | ||
// Restart: reusing the previous kmesh configuration | ||
// Update: upgrading kmesh and reusing part of previous kmesh configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better add some indents
pkg/bpf/bpf_restart.go
Outdated
// Restart: reusing the previous kmesh configuration | ||
// Update: upgrading kmesh and reusing part of previous kmesh configuration | ||
// Close: | ||
// Normal: normal close |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clean up all the bpf progs and maps
Signed-off-by: let-bit <glfhmzmy@126.com>
pkg/bpf/bpf_restart.go
Outdated
return kmeshStatus | ||
} | ||
|
||
func SetKmeshStatus(Status int) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove it, i get confused by it with SetStartStatus
pkg/bpf/bpf_restart.go
Outdated
|
||
const ( | ||
daemonSetName = "kmesh" | ||
namespace = "kmesh-system" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be changed, we can get it by
podNamespace := env.Register("POD_NAMESPACE", "", "").Get()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
// Normal: normal close | ||
// Restart: not clean kmesh configuration, for next launch | ||
// Update: not clean part of kmesh configuration, for next launch | ||
const ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we may define a
type StartType uint8
and
const (
Normal StartType = iota
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
pkg/bpf/bpf_restart.go
Outdated
kmeshStatus = Status | ||
} | ||
|
||
func InferRestartStatus() bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make it return StartType
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
pkg/bpf/bpf_restart.go
Outdated
kmeshStatus = Status | ||
} | ||
|
||
func InferRestartStatus() bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and use small cased functionname to keep it private
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
pkg/bpf/bpf.go
Outdated
} | ||
} | ||
|
||
func GetMap(m *ebpf.Map, key uint32) [16]byte { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getOldVersionFromMap
pkg/bpf/bpf.go
Outdated
|
||
versionMap, err := ebpf.LoadPinnedMap(versionPath+"kmesh_version", opts) | ||
if err != nil { | ||
log.Debugf("kmesh version map LoadPinnedMap failed: %v, Start normal", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.Debugf("kmesh version map LoadPinnedMap failed: %v, Start normal", err) | |
log.Debugf("kmesh version map loadfailed: %v, start normally", err) |
pkg/bpf/bpf.go
Outdated
return valueBytes | ||
} | ||
|
||
func RecoverVersionMap(config *options.BpfConfig, versionPath string) *ebpf.Map { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func RecoverVersionMap(config *options.BpfConfig, versionPath string) *ebpf.Map { | |
func recoverVersionMap(config *options.BpfConfig, versionPath string) *ebpf.Map { |
pkg/bpf/bpf.go
Outdated
return nil | ||
} | ||
|
||
err = m.Pin(filepath.Join(versionPath + "kmesh_version")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If L222 returns err, wouldn't m.Pin panic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes,will Panic;
I will add an error handling, generally no error will be returned here unless there are insufficient resources
} | ||
|
||
// Test Kmesh Restart Normal | ||
func runTestRestart(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a update case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restart, no Update now, there is currently no Update scenario
Signed-off-by: let-bit <glfhmzmy@126.com>
@@ -38,6 +39,10 @@ import ( | |||
|
|||
var log = logger.NewLoggerField("pkg/bpf") | |||
|
|||
var ( | |||
hash = fnv.New32a() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to the function
pkg/bpf/bpf.go
Outdated
if m != nil { | ||
SetStartStatus(m) | ||
CompareOldGitVersion(m) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function name does not reflect the functionality.
pkg/bpf/bpf_restart.go
Outdated
return kmeshStatus | ||
} | ||
|
||
func SetKmeshStatus(Status int) { | ||
func SetKmeshStatus(Status StartType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SetStartType
pkg/bpf/bpf_restart.go
Outdated
|
||
func GetKmeshStatus() int { | ||
func GetKmeshStatus() StartType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetStartType
Signed-off-by: let-bit <glfhmzmy@126.com>
/lgtm /approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hzxuzhonghu The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind feature
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: