Skip to content

Commit bad54ca

Browse files
committed
Simplify Synchronize loop and improve SetPodNetNs logging
1 parent 5285665 commit bad54ca

2 files changed

Lines changed: 10 additions & 13 deletions

File tree

pkg/driver/nri_hooks.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ func (np *NetworkDriver) Synchronize(_ context.Context, pods []*api.PodSandbox,
5656
ns, isLive := livePodNetNs[storedUID]
5757

5858
if isLive {
59-
if ns != "" {
60-
np.podConfigStore.SetPodNetNs(storedUID, ns)
61-
}
59+
np.podConfigStore.SetPodNetNs(storedUID, ns)
6260
} else {
6361
klog.Infof("Synchronize: pruning stale config for pod %s", storedUID)
6462
np.podConfigStore.DeletePod(storedUID)
@@ -370,18 +368,16 @@ func (np *NetworkDriver) stopPodSandbox(_ context.Context, pod *api.PodSandbox,
370368
// we workaround it using the local copy we have in the db to associate interfaces with Pods via
371369
// the network namespace id.
372370
storedNs, ok := np.podConfigStore.GetPodNetNs(types.UID(pod.GetUid()))
373-
if ok {
374-
if storedNs != "" {
375-
ns = storedNs
376-
} else {
377-
// Pod is not configured for DRAnet (host network or other driver)
378-
klog.Infof("StopPodSandbox pod %s/%s using host network ... skipping", pod.Namespace, pod.Name)
379-
return nil
380-
}
381-
} else {
371+
if !ok {
382372
klog.Warningf("StopPodSandbox: pod %s/%s (UID %s) not found in podConfigStore when fetching fallback NetNS", pod.Namespace, pod.Name, pod.Uid)
383373
return nil
384374
}
375+
if storedNs == "" {
376+
// Pod is not configured for DRAnet (host network or other driver)
377+
klog.Infof("StopPodSandbox pod %s/%s using host network ... skipping", pod.Namespace, pod.Name)
378+
return nil
379+
}
380+
ns = storedNs
385381
}
386382
needsRescan := false
387383
for deviceName, config := range podConfig.DeviceConfigs {

pkg/driver/pod_device_config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,10 @@ func (s *PodConfigStore) SetPodNetNs(podUID types.UID, netns string) {
274274

275275
podCfg, ok := s.configs[podUID]
276276
if !ok {
277-
klog.Warningf("SetPodNetNs: pod UID %s not found in store; skipping NetNS update", podUID)
277+
klog.Errorf("SetPodNetNs: pod UID %s not found in store; skipping NetNS update", podUID)
278278
return
279279
}
280+
klog.V(3).Infof("SetPodNetNs: setting NetNS for pod %s to %q", podUID, netns)
280281
podCfg.NetNS = netns
281282
s.configs[podUID] = podCfg
282283
}

0 commit comments

Comments
 (0)