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

Delete Pod specific VF resource cache from Podwatch controller, when a Pod gets deleted. #4285

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
13 changes: 13 additions & 0 deletions pkg/agent/secondarynetwork/podwatch/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,20 @@ func (pc *PodController) buildVFDeviceIDListPerPod(podName, podNamespace string)
vfDeviceIDInfoCache = append(vfDeviceIDInfoCache, initSriovVfDeviceID)
}
pc.vfDeviceIDUsageMap.Store(podKey, vfDeviceIDInfoCache)
klog.V(2).InfoS("Pod specific SRIOV VF cache created", "Key", podKey)
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 SRIOV 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 +301,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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question - could we pass key argument of handleRemovePod() to deleteVFDeviceIDListPerPod()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, key from the function argument can be used as well.

}
}
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")

})
}