Skip to content

Commit

Permalink
Upon a CNF Pod delete, clear Pod VF cache at secondary network's podw…
Browse files Browse the repository at this point in the history
…atch controller

Signed-off-by: Arunkumar Velayutham <arunkumar.velayutham@intel.com>
  • Loading branch information
arunvelayutham committed Oct 25, 2022
1 parent ac70351 commit 5ae73fa
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/agent/secondarynetwork/podwatch/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@ func (pc *PodController) buildVFDeviceIDListPerPod(podName, podNamespace string)
return vfDeviceIDInfoCache, nil
}

func (pc *PodController) deleteVFDeviceIDListPerPod(podName, podNamespace string) {
podKey := podNamespace + "/" + podName
_, cacheFound := pc.vfDeviceIDUsageMap.Load(podKey)
if cacheFound {
pc.vfDeviceIDUsageMap.Delete(podKey)
klog.V(2).InfoS("Pod specific VF Cache cleared", "Key", podKey)
}
return
}

func (pc *PodController) assignUnusedSriovVFDeviceIDPerPod(podName, podNamespace, interfaceName string) (string, error) {
var cache []podSriovVFDeviceIDInfo
cache, err := pc.buildVFDeviceIDListPerPod(podName, podNamespace)
Expand Down Expand Up @@ -290,6 +300,8 @@ func (pc *PodController) handleRemovePod(key string) error {
} else {
// Delete cache entry from podCNIInfo.
pc.podCache.DeleteCNIConfigInfo(containerInfo)
// Delete Pod specific VF cache (if one exists)
pc.deleteVFDeviceIDListPerPod(containerInfo.PodName, containerInfo.PodNameSpace)
}
}
return nil
Expand Down
19 changes: 19 additions & 0 deletions pkg/agent/secondarynetwork/podwatch/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,4 +510,23 @@ func TestPodControllerAddPod(t *testing.T) {
// we don't expect an error here, no requeueing
assert.NoError(t, podController.handleAddUpdatePod(pod))
})

t.Run("Error when adding VF deviceID cache per Pod", func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
network := testNetwork(networkName)
podController, _, _ := newPodController(ctrl)
podController.podCache.AddCNIConfigInfo(cniConfig)
_, err := podController.kubeClient.CoreV1().Pods(testNamespace).Create(context.Background(), pod, metav1.CreateOptions{})
require.NoError(t, err, "error when creating test Pod")
_, err = podController.netAttachDefClient.NetworkAttachmentDefinitions(testNamespace).Create(context.Background(), network, metav1.CreateOptions{})
require.NoError(t, err, "error when creating test NetworkAttachmentDefinition")

_, err = podController.assignUnusedSriovVFDeviceIDPerPod(podName, testNamespace, interfaceName)
require.NoError(t, err, "error while assigning unused VfDevice ID")

podController.deleteVFDeviceIDListPerPod(podName, testNamespace)
require.NoError(t, err, "error deleting cache")

})
}

0 comments on commit 5ae73fa

Please sign in to comment.