Skip to content
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

Fix the pod info with persistent IP in the map is deleted incorrectly #374

Merged
merged 6 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
-

### Bug fixes
-
- Fix the bug where the pod metadata with persistent IP in the map is deleted incorrectly due to the deleting mechanism with a delay. ([#374](https://github.com/KindlingProject/kindling/pull/374))
-
-
- Fix the bug that cpuEvent cache size continuously increases even if trace profiling is not enabled.([#362](https://github.com/CloudDectective-Harmonycloud/kindling/pull/362))
Expand Down
1 change: 1 addition & 0 deletions collector/pkg/metadata/kubernetes/k8scache.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type K8sContainerInfo struct {
}

type K8sPodInfo struct {
UID string
Ip string
PodName string
Ports []int32
Expand Down
21 changes: 18 additions & 3 deletions collector/pkg/metadata/kubernetes/pod_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type deleteRequest struct {
}

type deletedPodInfo struct {
uid string
name string
namespace string
containerIds []string
Expand Down Expand Up @@ -65,18 +66,32 @@ func deletePodInfo(podInfo *deletedPodInfo) {
}
if len(podInfo.containerIds) != 0 {
for i := 0; i < len(podInfo.containerIds); i++ {
// Assume that container id can't be reused in a few seconds
MetaDataCache.DeleteByContainerId(podInfo.containerIds[i])
}
}
if podInfo.ip != "" && len(podInfo.ports) != 0 {
for _, port := range podInfo.ports {
// Assume that PodIP:Port can't be reused in a few seconds
MetaDataCache.DeleteContainerByIpPort(podInfo.ip, uint32(port))
containerInfo, ok := MetaDataCache.GetContainerByIpPort(podInfo.ip, uint32(port))
if !ok {
continue
}
// PodIP:Port can be reused in a few seconds, so we check its UID
if containerInfo.RefPodInfo.UID == podInfo.uid {
MetaDataCache.DeleteContainerByIpPort(podInfo.ip, uint32(port))
}
}
}
if podInfo.hostIp != "" && len(podInfo.hostPorts) != 0 {
for _, port := range podInfo.hostPorts {
MetaDataCache.DeleteContainerByHostIpPort(podInfo.hostIp, uint32(port))
containerInfo, ok := MetaDataCache.GetContainerByHostIpPort(podInfo.hostIp, uint32(port))
if !ok {
continue
}
// PodIP:Port can be reused in a few seconds, so we check its UID
if containerInfo.RefPodInfo.UID == podInfo.uid {
MetaDataCache.DeleteContainerByHostIpPort(podInfo.hostIp, uint32(port))
}
}
}
}
6 changes: 5 additions & 1 deletion collector/pkg/metadata/kubernetes/pod_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"sync"
"time"

"github.com/Kindling-project/kindling/collector/pkg/compare"
corev1 "k8s.io/api/core/v1"
_ "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/runtime"
Expand All @@ -16,6 +15,8 @@ import (
"k8s.io/client-go/tools/cache"
_ "k8s.io/client-go/tools/clientcmd"
_ "k8s.io/client-go/util/homedir"

"github.com/Kindling-project/kindling/collector/pkg/compare"
)

type podMap struct {
Expand Down Expand Up @@ -141,6 +142,7 @@ func onAdd(obj interface{}) {
}

var cachePodInfo = &K8sPodInfo{
UID: string(pod.UID),
Ip: pod.Status.PodIP,
Namespace: pod.Namespace,
PodName: pod.Name,
Expand Down Expand Up @@ -251,6 +253,7 @@ func OnUpdate(objOld interface{}, objNew interface{}) {

// Delay delete the pod using the difference between the old pod and the new one
deletedPodInfo := &deletedPodInfo{
uid: string(oldPod.UID),
name: "",
namespace: oldPod.Namespace,
containerIds: nil,
Expand Down Expand Up @@ -322,6 +325,7 @@ func OnUpdate(objOld interface{}, objNew interface{}) {
func onDelete(obj interface{}) {
pod := obj.(*corev1.Pod)
podInfo := &deletedPodInfo{
uid: string(pod.UID),
name: pod.Name,
namespace: pod.Namespace,
containerIds: make([]string, 0),
Expand Down
Loading