Update DRAManager checkpoint to store a map for CDIDevices

The key of the map is the KubeletPluginName where the CDIDevices originate.

Signed-off-by: Kevin Klues <kklues@nvidia.com>
This commit is contained in:
Kevin Klues 2023-03-10 19:44:33 +00:00
parent 273a8ffad1
commit fd7370b84d
2 changed files with 11 additions and 7 deletions

View File

@ -51,9 +51,9 @@ type ClaimInfoState struct {
// PodUIDs is a set of pod UIDs that reference a resource // PodUIDs is a set of pod UIDs that reference a resource
PodUIDs sets.Set[string] PodUIDs sets.Set[string]
// CDIDevices is a list of CDI devices returned by the // CDIDevices is a map of KubeletPluginName --> CDI devices returned by the
// GRPC API call NodePrepareResource // GRPC API call NodePrepareResource
CDIDevices []string CDIDevices map[string][]string
} }
type stateCheckpoint struct { type stateCheckpoint struct {

View File

@ -50,7 +50,7 @@ func TestCheckpointGetOrCreate(t *testing.T) {
}, },
{ {
"Restore valid checkpoint", "Restore valid checkpoint",
`{"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":["example.com/example=cdi-example"]}],"checksum":2242470059}`, `{"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}`,
"", "",
[]ClaimInfoState{{ []ClaimInfoState{{
DriverName: "test-driver.cdi.k8s.io", DriverName: "test-driver.cdi.k8s.io",
@ -58,13 +58,15 @@ func TestCheckpointGetOrCreate(t *testing.T) {
ClaimName: "example", ClaimName: "example",
Namespace: "default", Namespace: "default",
PodUIDs: sets.New("139cdb46-f989-4f17-9561-ca10cfb509a6"), PodUIDs: sets.New("139cdb46-f989-4f17-9561-ca10cfb509a6"),
CDIDevices: []string{"example.com/example=cdi-example"}, CDIDevices: map[string][]string{
"test-driver.cdi.k8s.io": {"example.com/example=cdi-example"},
},
}, },
}, },
}, },
{ {
"Restore checkpoint with invalid checksum", "Restore checkpoint with 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":["example.com/example=cdi-example"]}],"checksum":2242470060}`, `{"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}`,
"checkpoint is corrupted", "checkpoint is corrupted",
[]ClaimInfoState{}, []ClaimInfoState{},
}, },
@ -123,10 +125,12 @@ func TestCheckpointStateStore(t *testing.T) {
ClaimName: "example", ClaimName: "example",
Namespace: "default", Namespace: "default",
PodUIDs: sets.New("139cdb46-f989-4f17-9561-ca10cfb509a6"), PodUIDs: sets.New("139cdb46-f989-4f17-9561-ca10cfb509a6"),
CDIDevices: []string{"example.com/example=cdi-example"}, CDIDevices: map[string][]string{
"test-driver.cdi.k8s.io": {"example.com/example=cdi-example"},
},
} }
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":["example.com/example=cdi-example"]}],"checksum":2242470059}` 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}`
// create temp dir // create temp dir
testingDir, err := os.MkdirTemp("", "dramanager_state_test") testingDir, err := os.MkdirTemp("", "dramanager_state_test")