@@ -27,7 +27,7 @@ import (
27
27
28
28
"github.com/stretchr/testify/assert"
29
29
"github.com/stretchr/testify/require"
30
- "k8s.io/api/core/v1"
30
+ v1 "k8s.io/api/core/v1"
31
31
"k8s.io/apimachinery/pkg/api/resource"
32
32
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
33
33
"k8s.io/apimachinery/pkg/util/sets"
@@ -946,6 +946,45 @@ func TestDevicePreStartContainer(t *testing.T) {
946
946
as .Equal (len (runContainerOpts .Envs ), len (expectedResp .Envs ))
947
947
}
948
948
949
+ func TestResetExtendedResource (t * testing.T ) {
950
+ as := assert .New (t )
951
+ tmpDir , err := ioutil .TempDir ("" , "checkpoint" )
952
+ as .Nil (err )
953
+ ckm , err := checkpointmanager .NewCheckpointManager (tmpDir )
954
+ as .Nil (err )
955
+ testManager := & ManagerImpl {
956
+ endpoints : make (map [string ]endpointInfo ),
957
+ healthyDevices : make (map [string ]sets.String ),
958
+ unhealthyDevices : make (map [string ]sets.String ),
959
+ allocatedDevices : make (map [string ]sets.String ),
960
+ podDevices : make (podDevices ),
961
+ checkpointManager : ckm ,
962
+ }
963
+
964
+ extendedResourceName := "domain.com/resource"
965
+ testManager .podDevices .insert ("pod" , "con" , extendedResourceName ,
966
+ constructDevices ([]string {"dev1" }),
967
+ constructAllocResp (map [string ]string {"/dev/dev1" : "/dev/dev1" },
968
+ map [string ]string {"/home/lib1" : "/usr/lib1" }, map [string ]string {}))
969
+
970
+ testManager .healthyDevices [extendedResourceName ] = sets .NewString ()
971
+ testManager .healthyDevices [extendedResourceName ].Insert ("dev1" )
972
+ // checkpoint is present, indicating node hasn't been recreated
973
+ err = testManager .writeCheckpoint ()
974
+ as .Nil (err )
975
+
976
+ as .False (testManager .ShouldResetExtendedResourceCapacity ())
977
+
978
+ // checkpoint is absent, representing node recreation
979
+ ckpts , err := ckm .ListCheckpoints ()
980
+ as .Nil (err )
981
+ for _ , ckpt := range ckpts {
982
+ err = ckm .RemoveCheckpoint (ckpt )
983
+ as .Nil (err )
984
+ }
985
+ as .True (testManager .ShouldResetExtendedResourceCapacity ())
986
+ }
987
+
949
988
func allocateStubFunc () func (devs []string ) (* pluginapi.AllocateResponse , error ) {
950
989
return func (devs []string ) (* pluginapi.AllocateResponse , error ) {
951
990
resp := new (pluginapi.ContainerAllocateResponse )
0 commit comments