Skip to content

Commit e0d44c8

Browse files
authored
fix: handle missing NAD during pod deletion (#5929)
Allow pod cleanup when NetworkAttachmentDefinition is deleted before pod. Extract subnet info from pod annotations to release IPs and prevent subnet finalizer deadlock. Signed-off-by: DiMalovanyy <dmitrymalovanyy@gmail.com>
1 parent 9fcab65 commit e0d44c8

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

pkg/controller/pod.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,6 +1784,43 @@ func (c *Controller) getPodAttachmentNet(pod *v1.Pod) ([]*kubeovnNet, error) {
17841784
network, err := c.netAttachLister.NetworkAttachmentDefinitions(attach.Namespace).Get(attach.Name)
17851785
if err != nil {
17861786
klog.Errorf("failed to get net-attach-def %s, %v", attach.Name, err)
1787+
if k8serrors.IsNotFound(err) && ignoreSubnetNotExist {
1788+
// NAD deleted before pod, find subnet for cleanup
1789+
providerName := fmt.Sprintf("%s.%s.%s", attach.Name, attach.Namespace, util.OvnProvider)
1790+
subnetName := pod.Annotations[fmt.Sprintf(util.LogicalSwitchAnnotationTemplate, providerName)]
1791+
if subnetName == "" {
1792+
for _, subnet := range subnets {
1793+
if subnet.Spec.Provider == providerName {
1794+
subnetName = subnet.Name
1795+
break
1796+
}
1797+
}
1798+
}
1799+
1800+
if subnetName == "" {
1801+
klog.Errorf("deleting pod %s/%s net-attach-def %s not found and cannot determine subnet, gc will clean its ip cr", pod.Namespace, pod.Name, attach.Name)
1802+
continue
1803+
}
1804+
1805+
subnet, err := c.subnetsLister.Get(subnetName)
1806+
if err != nil {
1807+
klog.Errorf("failed to get subnet %s, %v", subnetName, err)
1808+
if k8serrors.IsNotFound(err) {
1809+
klog.Errorf("deleting pod %s/%s attach subnet %s already not exist, gc will clean its ip cr", pod.Namespace, pod.Name, subnetName)
1810+
continue
1811+
}
1812+
return nil, err
1813+
}
1814+
1815+
klog.Infof("pod %s/%s net-attach-def %s not found, using subnet %s for cleanup", pod.Namespace, pod.Name, attach.Name, subnetName)
1816+
result = append(result, &kubeovnNet{
1817+
Type: providerTypeIPAM,
1818+
ProviderName: providerName,
1819+
Subnet: subnet,
1820+
IsDefault: util.IsDefaultNet(pod.Annotations[util.DefaultNetworkAnnotation], attach),
1821+
})
1822+
continue
1823+
}
17871824
return nil, err
17881825
}
17891826

0 commit comments

Comments
 (0)