Skip to content

Commit

Permalink
Checks k8s metadata for pod before removing IP from ipccahe
Browse files Browse the repository at this point in the history
This is to prevent removing ip cache when a Pod's IP is reused. We will
only remove ip cache entry if the k8s metadata associated with the IP is
"current", meaning tha the last time we update this entry, it is from
the same pod or CEP.

Signed-off-by: Weilong Cui <cuiwl@google.com>
  • Loading branch information
Weil0ng authored and ti-mo committed Aug 18, 2021
1 parent 83edea8 commit 63c0b29
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
18 changes: 12 additions & 6 deletions pkg/k8s/watchers/cilium_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,22 @@ func (k *K8sWatcher) endpointDeleted(endpoint *types.CiliumEndpoint) {
namedPortsChanged := false
for _, pair := range endpoint.Networking.Addressing {
if pair.IPV4 != "" {
portsChanged := ipcache.IPIdentityCache.Delete(pair.IPV4, source.CustomResource)
if portsChanged {
namedPortsChanged = true
k8sMeta := ipcache.IPIdentityCache.GetK8sMetadata(pair.IPV4)
if k8sMeta.Namespace == endpoint.Namespace && k8sMeta.PodName == endpoint.Name {
portsChanged := ipcache.IPIdentityCache.Delete(pair.IPV4, source.CustomResource)
if portsChanged {
namedPortsChanged = true
}
}
}

if pair.IPV6 != "" {
portsChanged := ipcache.IPIdentityCache.Delete(pair.IPV6, source.CustomResource)
if portsChanged {
namedPortsChanged = true
k8sMeta := ipcache.IPIdentityCache.GetK8sMetadata(pair.IPV6)
if k8sMeta.Namespace == endpoint.Namespace && k8sMeta.PodName == endpoint.Name {
portsChanged := ipcache.IPIdentityCache.Delete(pair.IPV6, source.CustomResource)
if portsChanged {
namedPortsChanged = true
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/k8s/watchers/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,10 @@ func (k *K8sWatcher) deletePodHostData(pod *slim_corev1.Pod) (bool, error) {
continue
}

ipcache.IPIdentityCache.Delete(podIP, source.Kubernetes)
k8sMeta := ipcache.IPIdentityCache.GetK8sMetadata(podIP)
if k8sMeta.Namespace == pod.Namespace && k8sMeta.PodName == pod.Name {
ipcache.IPIdentityCache.Delete(podIP, source.Kubernetes)
}
}

if len(errs) != 0 {
Expand Down

0 comments on commit 63c0b29

Please sign in to comment.