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 netns info expired on sidecar mode #308

Merged
merged 1 commit into from
Jul 17, 2024
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
17 changes: 10 additions & 7 deletions pkg/exporter/nettop/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ func initDefaultEntity(sidecarMode bool) error {
}
ent := []*Entity{defaultEntity}
entities.Store(&ent)
addEntityToCache(defaultEntity, false)
}
addEntityToCache(defaultEntity, false, true)

return nil
}
Expand Down Expand Up @@ -283,15 +283,19 @@ func cachePodsWithTimeout(timeout time.Duration) error {
}
}

func addEntityToCache(e *Entity, ignoreHostPod bool) {
func addEntityToCache(e *Entity, ignoreHostPod, noExpiration bool) {
BSWANG marked this conversation as resolved.
Show resolved Hide resolved
expirationTime := 3 * cacheUpdateInterval
if noExpiration {
expirationTime = cache.NoExpiration
}
if !(ignoreHostPod && e.IsHostNetwork()) {
nsCache.Set(fmt.Sprintf("%d", e.inum), e, 3*cacheUpdateInterval)
nsCache.Set(fmt.Sprintf("%d", e.inum), e, expirationTime)
}
for _, ip := range e.ipList {
ipCache.Set(ip, e, 3*cacheUpdateInterval)
ipCache.Set(ip, e, expirationTime)
}
for _, pid := range e.pids {
pidCache.Set(fmt.Sprintf("%d", pid), e, 3*cacheUpdateInterval)
pidCache.Set(fmt.Sprintf("%d", pid), e, expirationTime)
}
}

Expand Down Expand Up @@ -333,7 +337,6 @@ func cacheNetTopology(ctx context.Context) error {

var newEntities []*Entity
newEntities = append(newEntities, defaultEntity)
addEntityToCache(defaultEntity, false)

sandboxList, err := criClient.ListPodSandbox(&v1.PodSandboxFilter{
State: &v1.PodSandboxStateValue{
Expand Down Expand Up @@ -420,7 +423,7 @@ func cacheNetTopology(ctx context.Context) error {
}

newEntities = append(newEntities, e)
addEntityToCache(e, true)
addEntityToCache(e, true, false)
}

entities.Store(&newEntities)
Expand Down
2 changes: 1 addition & 1 deletion pkg/exporter/nettop/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func GetEntityByNetns(nsinum int) (*Entity, error) {
if found {
return v.(*Entity), nil
}
return nil, fmt.Errorf("entify for netns %d not found", nsinum)
return nil, fmt.Errorf("entity for netns %d not found", nsinum)
}

func GetHostNetworkEntity() (*Entity, error) {
Expand Down
Loading