kmesh support restart by reload old bpf map and prog#475
kmesh support restart by reload old bpf map and prog#475kmesh-bot merged 8 commits intokmesh-net:mainfrom
Conversation
daemon/manager/manager.go
Outdated
| defer cniInstaller.Stop() | ||
|
|
||
| setupCloseHandler() | ||
| *configs.Status = setupCloseHandler() |
There was a problem hiding this comment.
Assign an int to a pointer?
There was a problem hiding this comment.
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.
you can change status from pointer to int
There was a problem hiding this comment.
I add a KmeshStartStatus in bpf
daemon/manager/manager.go
Outdated
|
|
||
| setupCloseHandler() | ||
| *configs.Status = setupCloseHandler() | ||
| log.Printf("bpfLoader.Restart %v", *configs.Status) |
There was a problem hiding this comment.
| log.Printf("bpfLoader.Restart %v", *configs.Status) | |
| log.Printf("Kmesh Restart %d", *configs.Status) |
pkg/bpf/bpf.go
Outdated
|
|
||
| "kmesh.net/kmesh/daemon/options" | ||
| "kmesh.net/kmesh/pkg/logger" | ||
| pkgversion "kmesh.net/kmesh/pkg/version" |
There was a problem hiding this comment.
Why not use version directly?
| pkgversion "kmesh.net/kmesh/pkg/version" | |
| "kmesh.net/kmesh/pkg/version" |
pkg/bpf/bpf.go
Outdated
|
|
||
| obj *BpfKmesh | ||
| workloadObj *BpfKmeshWorkload | ||
| Status *int |
There was a problem hiding this comment.
| 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.
| 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.
| * 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.
| 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 |
hzxuzhonghu
left a comment
There was a problem hiding this comment.
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.
| echo "kmesh close" | |
| echo "kmesh exit" |
daemon/manager/manager.go
Outdated
| defer cniInstaller.Stop() | ||
|
|
||
| setupCloseHandler() | ||
| *configs.Status = setupCloseHandler() |
There was a problem hiding this comment.
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.
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.
Yoiu can remove the duplicate path construct within NewVersionMap
There was a problem hiding this comment.
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.
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.
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
| } | ||
|
|
||
| func setupCloseHandler() { | ||
| func setupCloseHandler() int { |
There was a problem hiding this comment.
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.
it doesn‘t matter, i can move func GetDaemonset out
daemon/manager/manager.go
Outdated
|
|
||
| log.Warn("exiting...") | ||
|
|
||
| if bpf.GetDaemonset() { |
There was a problem hiding this comment.
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.
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.
sorry, forget
now in bpfLoader.Stop
pkg/bpf/bpf_restart.go
Outdated
| NewStart = iota | ||
| Restart | ||
| Update | ||
| Reload |
There was a problem hiding this comment.
These constants also defined in pkg/version, can they be defined in one place?
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
| verbs: ["get", "update", "patch", "list", "watch"] | ||
| - apiGroups: ["apps"] | ||
| resources: ["daemonsets"] | ||
| verbs: ["list", "get"] |
There was a problem hiding this comment.
to align with above, i think you donot need list permission
pkg/bpf/bpf.go
Outdated
| return &BpfLoader{ | ||
| config: config, | ||
| config: config, | ||
| StatusMap: NewVersionMap(config), |
|
|
||
| const ( | ||
| NewStart = iota | ||
| Restart |
pkg/bpf/bpf_restart.go
Outdated
| @@ -0,0 +1,100 @@ | |||
| /* | |||
| * Copyright 2024 The Kmesh Authors. | |||
pkg/bpf/bpf_restart.go
Outdated
| } | ||
|
|
||
| func CleanupBpfMap() { | ||
| err := syscall.Unmount("/mnt/kmesh_cgroup2", 0) |
pkg/bpf/bpf_restart.go
Outdated
| if GetDaemonset() { | ||
| SetKmeshStartStatus(Restart) | ||
| } else { | ||
| SetKmeshStartStatus(NewStart) |
There was a problem hiding this comment.
Not sure i understand the intention here, since it is closing
There was a problem hiding this comment.
i will check the name
pkg/bpf/bpf_restart.go
Outdated
| kmeshStartStatus = Status | ||
| } | ||
|
|
||
| func GetDaemonset() bool { |
There was a problem hiding this comment.
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.
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 |
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.
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.
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.
This can be changed, we can get it by
podNamespace := env.Register("POD_NAMESPACE", "", "").Get()
| // 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.
we may define a
type StartType uint8
and
const (
Normal StartType = iota
pkg/bpf/bpf_restart.go
Outdated
| kmeshStatus = Status | ||
| } | ||
|
|
||
| func InferRestartStatus() bool { |
pkg/bpf/bpf_restart.go
Outdated
| kmeshStatus = Status | ||
| } | ||
|
|
||
| func InferRestartStatus() bool { |
There was a problem hiding this comment.
and use small cased functionname to keep it private
pkg/bpf/bpf.go
Outdated
| } | ||
| } | ||
|
|
||
| func GetMap(m *ebpf.Map, key uint32) [16]byte { |
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.
| 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.
| 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.
If L222 returns err, wouldn't m.Pin panic?
There was a problem hiding this comment.
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.
Restart, no Update now, there is currently no Update scenario
Signed-off-by: let-bit <glfhmzmy@126.com>
| var log = logger.NewLoggerField("pkg/bpf") | ||
|
|
||
| var ( | ||
| hash = fnv.New32a() |
pkg/bpf/bpf.go
Outdated
| m := recoverVersionMap(config, versionPath) | ||
| if m != nil { | ||
| SetStartStatus(m) | ||
| CompareOldGitVersion(m) |
There was a problem hiding this comment.
The function name does not reflect the functionality.
pkg/bpf/bpf_restart.go
Outdated
| } | ||
|
|
||
| func SetKmeshStatus(Status int) { | ||
| func SetKmeshStatus(Status StartType) { |
pkg/bpf/bpf_restart.go
Outdated
| var kmeshStatus StartType | ||
|
|
||
| func GetKmeshStatus() int { | ||
| func GetKmeshStatus() StartType { |
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 DetailsNeeds 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?: