Add ClassName to chekpoint state and in-memory cache
Signed-off-by: Moshe Levi <moshele@nvidia.com>
This commit is contained in:
parent
71d6e4d53c
commit
9c57613912
@ -134,7 +134,6 @@ func TestListPodResourcesV1alpha1(t *testing.T) {
|
|||||||
mockDevicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(tc.devices).AnyTimes()
|
mockDevicesProvider.EXPECT().GetDevices(string(podUID), containerName).Return(tc.devices).AnyTimes()
|
||||||
mockDevicesProvider.EXPECT().UpdateAllocatedDevices().Return().AnyTimes()
|
mockDevicesProvider.EXPECT().UpdateAllocatedDevices().Return().AnyTimes()
|
||||||
|
|
||||||
|
|
||||||
providers := PodResourcesProviders{
|
providers := PodResourcesProviders{
|
||||||
Pods: mockPodsProvider,
|
Pods: mockPodsProvider,
|
||||||
Devices: mockDevicesProvider,
|
Devices: mockDevicesProvider,
|
||||||
|
@ -57,9 +57,10 @@ type claimInfoCache struct {
|
|||||||
claimInfo map[string]*claimInfo
|
claimInfo map[string]*claimInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func newClaimInfo(driverName string, claimUID types.UID, claimName, namespace string, podUIDs sets.Set[string]) *claimInfo {
|
func newClaimInfo(driverName, className string, claimUID types.UID, claimName, namespace string, podUIDs sets.Set[string]) *claimInfo {
|
||||||
claimInfoState := state.ClaimInfoState{
|
claimInfoState := state.ClaimInfoState{
|
||||||
DriverName: driverName,
|
DriverName: driverName,
|
||||||
|
ClassName: className,
|
||||||
ClaimUID: claimUID,
|
ClaimUID: claimUID,
|
||||||
ClaimName: claimName,
|
ClaimName: claimName,
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
@ -110,6 +111,7 @@ func newClaimInfoCache(stateDir, checkpointName string) (*claimInfoCache, error)
|
|||||||
for _, entry := range curState {
|
for _, entry := range curState {
|
||||||
info := newClaimInfo(
|
info := newClaimInfo(
|
||||||
entry.DriverName,
|
entry.DriverName,
|
||||||
|
entry.ClassName,
|
||||||
entry.ClaimUID,
|
entry.ClaimUID,
|
||||||
entry.ClaimName,
|
entry.ClaimName,
|
||||||
entry.Namespace,
|
entry.Namespace,
|
||||||
|
@ -122,6 +122,7 @@ func (m *ManagerImpl) PrepareResources(pod *v1.Pod) error {
|
|||||||
// Create a claimInfo object to store the relevant claim info.
|
// Create a claimInfo object to store the relevant claim info.
|
||||||
claimInfo := newClaimInfo(
|
claimInfo := newClaimInfo(
|
||||||
resourceClaim.Status.DriverName,
|
resourceClaim.Status.DriverName,
|
||||||
|
resourceClaim.Spec.ResourceClassName,
|
||||||
resourceClaim.UID,
|
resourceClaim.UID,
|
||||||
resourceClaim.Name,
|
resourceClaim.Name,
|
||||||
resourceClaim.Namespace,
|
resourceClaim.Namespace,
|
||||||
|
@ -39,6 +39,9 @@ type ClaimInfoState struct {
|
|||||||
// Name of the DRA driver
|
// Name of the DRA driver
|
||||||
DriverName string
|
DriverName string
|
||||||
|
|
||||||
|
// ClassName is a resource class of the claim
|
||||||
|
ClassName string
|
||||||
|
|
||||||
// ClaimUID is an UID of the resource claim
|
// ClaimUID is an UID of the resource claim
|
||||||
ClaimUID types.UID
|
ClaimUID types.UID
|
||||||
|
|
||||||
|
@ -50,11 +50,12 @@ func TestCheckpointGetOrCreate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Restore checkpoint - single claim",
|
"Restore checkpoint - single claim",
|
||||||
`{"version":"v1","entries":[{"DriverName":"test-driver.cdi.k8s.io","ClaimUID":"067798be-454e-4be4-9047-1aa06aea63f7","ClaimName":"example","Namespace":"default","PodUIDs":{"139cdb46-f989-4f17-9561-ca10cfb509a6":{}},"CDIDevices":{"test-driver.cdi.k8s.io":["example.com/example=cdi-example"]}}],"checksum":1988120167}`,
|
`{"version":"v1","entries":[{"DriverName":"test-driver.cdi.k8s.io","ClassName":"class-name","ClaimUID":"067798be-454e-4be4-9047-1aa06aea63f7","ClaimName":"example","Namespace":"default","PodUIDs":{"139cdb46-f989-4f17-9561-ca10cfb509a6":{}},"CDIDevices":{"test-driver.cdi.k8s.io":["example.com/example=cdi-example"]}}],"checksum":153446146}`,
|
||||||
"",
|
"",
|
||||||
[]ClaimInfoState{
|
[]ClaimInfoState{
|
||||||
{
|
{
|
||||||
DriverName: "test-driver.cdi.k8s.io",
|
DriverName: "test-driver.cdi.k8s.io",
|
||||||
|
ClassName: "class-name",
|
||||||
ClaimUID: "067798be-454e-4be4-9047-1aa06aea63f7",
|
ClaimUID: "067798be-454e-4be4-9047-1aa06aea63f7",
|
||||||
ClaimName: "example",
|
ClaimName: "example",
|
||||||
Namespace: "default",
|
Namespace: "default",
|
||||||
@ -67,11 +68,12 @@ func TestCheckpointGetOrCreate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Restore checkpoint - single claim - multiple devices",
|
"Restore checkpoint - single claim - multiple devices",
|
||||||
`{"version":"v1","entries":[{"DriverName":"meta-test-driver.cdi.k8s.io","ClaimUID":"067798be-454e-4be4-9047-1aa06aea63f7","ClaimName":"example","Namespace":"default","PodUIDs":{"139cdb46-f989-4f17-9561-ca10cfb509a6":{}},"CDIDevices":{"test-driver-1.cdi.k8s.io":["example-1.com/example-1=cdi-example-1"],"test-driver-2.cdi.k8s.io":["example-2.com/example-2=cdi-example-2"]}}],"checksum":2113538068}`,
|
`{"version":"v1","entries":[{"DriverName":"meta-test-driver.cdi.k8s.io","ClassName":"class-name","ClaimUID":"067798be-454e-4be4-9047-1aa06aea63f7","ClaimName":"example","Namespace":"default","PodUIDs":{"139cdb46-f989-4f17-9561-ca10cfb509a6":{}},"CDIDevices":{"test-driver-1.cdi.k8s.io":["example-1.com/example-1=cdi-example-1"],"test-driver-2.cdi.k8s.io":["example-2.com/example-2=cdi-example-2"]}}],"checksum":1363630443}`,
|
||||||
"",
|
"",
|
||||||
[]ClaimInfoState{
|
[]ClaimInfoState{
|
||||||
{
|
{
|
||||||
DriverName: "meta-test-driver.cdi.k8s.io",
|
DriverName: "meta-test-driver.cdi.k8s.io",
|
||||||
|
ClassName: "class-name",
|
||||||
ClaimUID: "067798be-454e-4be4-9047-1aa06aea63f7",
|
ClaimUID: "067798be-454e-4be4-9047-1aa06aea63f7",
|
||||||
ClaimName: "example",
|
ClaimName: "example",
|
||||||
Namespace: "default",
|
Namespace: "default",
|
||||||
@ -85,11 +87,12 @@ func TestCheckpointGetOrCreate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Restore checkpoint - multiple claims",
|
"Restore checkpoint - multiple claims",
|
||||||
`{"version":"v1","entries":[{"DriverName":"test-driver.cdi.k8s.io","ClaimUID":"067798be-454e-4be4-9047-1aa06aea63f7","ClaimName":"example-1","Namespace":"default","PodUIDs":{"139cdb46-f989-4f17-9561-ca10cfb509a6":{}},"CDIDevices":{"test-driver.cdi.k8s.io":["example.com/example=cdi-example-1"]}},{"DriverName":"test-driver.cdi.k8s.io","ClaimUID":"4cf8db2d-06c0-7d70-1a51-e59b25b2c16c","ClaimName":"example-2","Namespace":"default","PodUIDs":{"139cdb46-f989-4f17-9561-ca10cfb509a6":{}},"CDIDevices":{"test-driver.cdi.k8s.io":["example.com/example=cdi-example-2"]}}],"checksum":666680545}`,
|
`{"version":"v1","entries":[{"DriverName":"test-driver.cdi.k8s.io","ClassName":"class-name-1","ClaimUID":"067798be-454e-4be4-9047-1aa06aea63f7","ClaimName":"example-1","Namespace":"default","PodUIDs":{"139cdb46-f989-4f17-9561-ca10cfb509a6":{}},"CDIDevices":{"test-driver.cdi.k8s.io":["example.com/example=cdi-example-1"]}},{"DriverName":"test-driver.cdi.k8s.io","ClaimUID":"4cf8db2d-06c0-7d70-1a51-e59b25b2c16c","ClassName":"class-name-2","ClaimName":"example-2","Namespace":"default","PodUIDs":{"139cdb46-f989-4f17-9561-ca10cfb509a6":{}},"CDIDevices":{"test-driver.cdi.k8s.io":["example.com/example=cdi-example-2"]}}],"checksum":1978566460}`,
|
||||||
"",
|
"",
|
||||||
[]ClaimInfoState{
|
[]ClaimInfoState{
|
||||||
{
|
{
|
||||||
DriverName: "test-driver.cdi.k8s.io",
|
DriverName: "test-driver.cdi.k8s.io",
|
||||||
|
ClassName: "class-name-1",
|
||||||
ClaimUID: "067798be-454e-4be4-9047-1aa06aea63f7",
|
ClaimUID: "067798be-454e-4be4-9047-1aa06aea63f7",
|
||||||
ClaimName: "example-1",
|
ClaimName: "example-1",
|
||||||
Namespace: "default",
|
Namespace: "default",
|
||||||
@ -100,6 +103,7 @@ func TestCheckpointGetOrCreate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
DriverName: "test-driver.cdi.k8s.io",
|
DriverName: "test-driver.cdi.k8s.io",
|
||||||
|
ClassName: "class-name-2",
|
||||||
ClaimUID: "4cf8db2d-06c0-7d70-1a51-e59b25b2c16c",
|
ClaimUID: "4cf8db2d-06c0-7d70-1a51-e59b25b2c16c",
|
||||||
ClaimName: "example-2",
|
ClaimName: "example-2",
|
||||||
Namespace: "default",
|
Namespace: "default",
|
||||||
@ -112,7 +116,7 @@ func TestCheckpointGetOrCreate(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Restore checkpoint - invalid checksum",
|
"Restore checkpoint - invalid checksum",
|
||||||
`{"version":"v1","entries":[{"DriverName":"test-driver.cdi.k8s.io","ClaimUID":"067798be-454e-4be4-9047-1aa06aea63f7","ClaimName":"example","Namespace":"default","PodUIDs":{"139cdb46-f989-4f17-9561-ca10cfb509a6":{}},"CDIDevices":{"test-driver.cdi.k8s.io":["example.com/example=cdi-example"]}}],"checksum":1988120168}`,
|
`{"version":"v1","entries":[{"DriverName":"test-driver.cdi.k8s.io","ClassName":"class-name","ClaimUID":"067798be-454e-4be4-9047-1aa06aea63f7","ClaimName":"example","Namespace":"default","PodUIDs":{"139cdb46-f989-4f17-9561-ca10cfb509a6":{}},"CDIDevices":{"test-driver.cdi.k8s.io":["example.com/example=cdi-example"]}}],"checksum":1988120168}`,
|
||||||
"checkpoint is corrupted",
|
"checkpoint is corrupted",
|
||||||
[]ClaimInfoState{},
|
[]ClaimInfoState{},
|
||||||
},
|
},
|
||||||
@ -167,6 +171,7 @@ func TestCheckpointGetOrCreate(t *testing.T) {
|
|||||||
func TestCheckpointStateStore(t *testing.T) {
|
func TestCheckpointStateStore(t *testing.T) {
|
||||||
claimInfoState := ClaimInfoState{
|
claimInfoState := ClaimInfoState{
|
||||||
DriverName: "test-driver.cdi.k8s.io",
|
DriverName: "test-driver.cdi.k8s.io",
|
||||||
|
ClassName: "class-name",
|
||||||
ClaimUID: "067798be-454e-4be4-9047-1aa06aea63f7",
|
ClaimUID: "067798be-454e-4be4-9047-1aa06aea63f7",
|
||||||
ClaimName: "example",
|
ClaimName: "example",
|
||||||
Namespace: "default",
|
Namespace: "default",
|
||||||
@ -176,7 +181,7 @@ func TestCheckpointStateStore(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedCheckpoint := `{"version":"v1","entries":[{"DriverName":"test-driver.cdi.k8s.io","ClaimUID":"067798be-454e-4be4-9047-1aa06aea63f7","ClaimName":"example","Namespace":"default","PodUIDs":{"139cdb46-f989-4f17-9561-ca10cfb509a6":{}},"CDIDevices":{"test-driver.cdi.k8s.io":["example.com/example=cdi-example"]}}],"checksum":1988120167}`
|
expectedCheckpoint := `{"version":"v1","entries":[{"DriverName":"test-driver.cdi.k8s.io","ClassName":"class-name","ClaimUID":"067798be-454e-4be4-9047-1aa06aea63f7","ClaimName":"example","Namespace":"default","PodUIDs":{"139cdb46-f989-4f17-9561-ca10cfb509a6":{}},"CDIDevices":{"test-driver.cdi.k8s.io":["example.com/example=cdi-example"]}}],"checksum":153446146}`
|
||||||
|
|
||||||
// create temp dir
|
// create temp dir
|
||||||
testingDir, err := os.MkdirTemp("", "dramanager_state_test")
|
testingDir, err := os.MkdirTemp("", "dramanager_state_test")
|
||||||
|
Loading…
Reference in New Issue
Block a user