github.com/kubewharf/katalyst-core@v0.5.3/pkg/agent/qrm-plugins/cpu/dynamicpolicy/state/state_test.go (about)

     1  /*
     2  Copyright 2022 The Katalyst Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package state
    18  
    19  import (
    20  	"fmt"
    21  	"io/ioutil"
    22  	"os"
    23  	"strings"
    24  	"testing"
    25  
    26  	pluginapi "k8s.io/kubelet/pkg/apis/resourceplugin/v1alpha1"
    27  	"k8s.io/kubernetes/pkg/kubelet/checkpointmanager"
    28  	testutil "k8s.io/kubernetes/pkg/kubelet/cm/cpumanager/state/testing"
    29  
    30  	"github.com/stretchr/testify/assert"
    31  	"github.com/stretchr/testify/require"
    32  
    33  	"github.com/kubewharf/katalyst-api/pkg/consts"
    34  	"github.com/kubewharf/katalyst-core/pkg/util/machine"
    35  )
    36  
    37  const (
    38  	cpuPluginStateFileName = "cpu_plugin_state"
    39  	policyName             = "dynamic"
    40  )
    41  
    42  // assertStateEqual marks provided test as failed if provided states differ
    43  func assertStateEqual(t *testing.T, restoredState, expectedState State) {
    44  	as := require.New(t)
    45  
    46  	expectedMachineState := expectedState.GetMachineState()
    47  	restoredMachineState := restoredState.GetMachineState()
    48  	as.Equalf(expectedMachineState, restoredMachineState, "machineState mismatches")
    49  
    50  	expectedPodEntries := expectedState.GetPodEntries()
    51  	restoredPodEntries := restoredState.GetPodEntries()
    52  	as.Equalf(expectedPodEntries, restoredPodEntries, "podEntries mismatch")
    53  }
    54  
    55  func TestNewCheckpointState(t *testing.T) {
    56  	t.Parallel()
    57  
    58  	testName := "test"
    59  	cpuTopology, _ := machine.GenerateDummyCPUTopology(16, 2, 4)
    60  
    61  	testCases := []struct {
    62  		description       string
    63  		checkpointContent string
    64  		expectedError     string
    65  		expectedState     *cpuPluginState
    66  	}{
    67  		{
    68  			"Restore non-existing checkpoint",
    69  			"",
    70  			"",
    71  			&cpuPluginState{
    72  				podEntries:     make(PodEntries),
    73  				machineState:   GetDefaultMachineState(cpuTopology),
    74  				socketTopology: cpuTopology.GetSocketTopology(),
    75  				cpuTopology:    cpuTopology,
    76  			},
    77  		},
    78  		{
    79  			"Restore valid checkpoint",
    80  			`{
    81  	"policyName": "dynamic",
    82  	"machineState": {
    83  		"0": {
    84  			"default_cpuset": "0-1,8-9",
    85  			"allocated_cpuset": "",
    86  			"pod_entries": {
    87  				"2432d068-c5a0-46ba-a7bd-b69d9bd16961": {
    88  					"test": {
    89  						"pod_uid": "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
    90  						"pod_namespace": "test",
    91  						"pod_name": "test",
    92  						"container_name": "test",
    93  						"container_type": "MAIN",
    94  						"owner_pool_name": "reclaim",
    95  						"allocation_result": "8",
    96  						"original_allocation_result": "8",
    97  						"topology_aware_assignments": {
    98  							"0": "8"
    99  						},
   100  						"original_topology_aware_assignments": {
   101  							"0": "8"
   102  						},
   103  						"init_timestamp": "",
   104  						"labels": {
   105  							"katalyst.kubewharf.io/qos_level": "reclaimed_cores"
   106  						},
   107  						"annotations": {
   108  							"katalyst.kubewharf.io/qos_level": "reclaimed_cores"
   109  						},
   110  						"qosLevel": "reclaimed_cores",
   111  						"request_quantity": 2
   112  					}
   113  				},
   114  				"373d08e4-7a6b-4293-aaaf-b135ff8123bf": {
   115  					"test": {
   116  						"pod_uid": "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
   117  						"pod_namespace": "test",
   118  						"pod_name": "test",
   119  						"container_name": "test",
   120  						"container_type": "MAIN",
   121  						"owner_pool_name": "share",
   122  						"allocation_result": "1,9",
   123  						"original_allocation_result": "1,9",
   124  						"topology_aware_assignments": {
   125  							"0": "1,9"
   126  						},
   127  						"original_topology_aware_assignments": {
   128  							"0": "1,9"
   129  						},
   130  						"init_timestamp": "",
   131  						"labels": {
   132  							"katalyst.kubewharf.io/qos_level": "shared_cores"
   133  						},
   134  						"annotations": {
   135  							"katalyst.kubewharf.io/qos_level": "shared_cores"
   136  						},
   137  						"qosLevel": "shared_cores",
   138  						"request_quantity": 2
   139  					}
   140  				},
   141  				"ec6e2f30-c78a-4bc4-9576-c916db5281a3": {
   142  					"test": {
   143  						"pod_uid": "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
   144  						"pod_namespace": "test",
   145  						"pod_name": "test",
   146  						"container_name": "test",
   147  						"container_type": "MAIN",
   148  						"owner_pool_name": "share",
   149  						"allocation_result": "1,9",
   150  						"original_allocation_result": "1,9",
   151  						"topology_aware_assignments": {
   152  							"0": "1,9"
   153  						},
   154  						"original_topology_aware_assignments": {
   155  							"0": "1,9"
   156  						},
   157  						"init_timestamp": "",
   158  						"labels": {
   159  							"katalyst.kubewharf.io/qos_level": "shared_cores"
   160  						},
   161  						"annotations": {
   162  							"katalyst.kubewharf.io/qos_level": "shared_cores"
   163  						},
   164  						"qosLevel": "shared_cores",
   165  						"request_quantity": 2
   166  					}
   167  				}
   168  			}
   169  		},
   170  		"1": {
   171  			"default_cpuset": "2-3,10-11",
   172  			"allocated_cpuset": "",
   173  			"pod_entries": {
   174  				"2432d068-c5a0-46ba-a7bd-b69d9bd16961": {
   175  					"test": {
   176  						"pod_uid": "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
   177  						"pod_namespace": "test",
   178  						"pod_name": "test",
   179  						"container_name": "test",
   180  						"container_type": "MAIN",
   181  						"owner_pool_name": "reclaim",
   182  						"allocation_result": "10",
   183  						"original_allocation_result": "10",
   184  						"topology_aware_assignments": {
   185  							"1": "10"
   186  						},
   187  						"original_topology_aware_assignments": {
   188  							"1": "10"
   189  						},
   190  						"init_timestamp": "",
   191  						"labels": {
   192  							"katalyst.kubewharf.io/qos_level": "reclaimed_cores"
   193  						},
   194  						"annotations": {
   195  							"katalyst.kubewharf.io/qos_level": "reclaimed_cores"
   196  						},
   197  						"qosLevel": "reclaimed_cores",
   198  						"request_quantity": 2
   199  					}
   200  				},
   201  				"373d08e4-7a6b-4293-aaaf-b135ff8123bf": {
   202  					"test": {
   203  						"pod_uid": "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
   204  						"pod_namespace": "test",
   205  						"pod_name": "test",
   206  						"container_name": "test",
   207  						"container_type": "MAIN",
   208  						"owner_pool_name": "share",
   209  						"allocation_result": "3,11",
   210  						"original_allocation_result": "3,11",
   211  						"topology_aware_assignments": {
   212  							"1": "3,11"
   213  						},
   214  						"original_topology_aware_assignments": {
   215  							"1": "3,11"
   216  						},
   217  						"init_timestamp": "",
   218  						"labels": {
   219  							"katalyst.kubewharf.io/qos_level": "shared_cores"
   220  						},
   221  						"annotations": {
   222  							"katalyst.kubewharf.io/qos_level": "shared_cores"
   223  						},
   224  						"qosLevel": "shared_cores",
   225  						"request_quantity": 2
   226  					}
   227  				},
   228  				"ec6e2f30-c78a-4bc4-9576-c916db5281a3": {
   229  					"test": {
   230  						"pod_uid": "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
   231  						"pod_namespace": "test",
   232  						"pod_name": "test",
   233  						"container_name": "test",
   234  						"container_type": "MAIN",
   235  						"owner_pool_name": "share",
   236  						"allocation_result": "3,11",
   237  						"original_allocation_result": "3,11",
   238  						"topology_aware_assignments": {
   239  							"1": "3,11"
   240  						},
   241  						"original_topology_aware_assignments": {
   242  							"1": "3,11"
   243  						},
   244  						"init_timestamp": "",
   245  						"labels": {
   246  							"katalyst.kubewharf.io/qos_level": "shared_cores"
   247  						},
   248  						"annotations": {
   249  							"katalyst.kubewharf.io/qos_level": "shared_cores"
   250  						},
   251  						"qosLevel": "shared_cores",
   252  						"request_quantity": 2
   253  					}
   254  				}
   255  			}
   256  		},
   257  		"2": {
   258  			"default_cpuset": "4-5,12-13",
   259  			"allocated_cpuset": "",
   260  			"pod_entries": {
   261  				"2432d068-c5a0-46ba-a7bd-b69d9bd16961": {
   262  					"test": {
   263  						"pod_uid": "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
   264  						"pod_namespace": "test",
   265  						"pod_name": "test",
   266  						"container_name": "test",
   267  						"container_type": "MAIN",
   268  						"owner_pool_name": "reclaim",
   269  						"allocation_result": "5,13",
   270  						"original_allocation_result": "5,13",
   271  						"topology_aware_assignments": {
   272  							"2": "5,13"
   273  						},
   274  						"original_topology_aware_assignments": {
   275  							"2": "5,13"
   276  						},
   277  						"init_timestamp": "",
   278  						"labels": {
   279  							"katalyst.kubewharf.io/qos_level": "reclaimed_cores"
   280  						},
   281  						"annotations": {
   282  							"katalyst.kubewharf.io/qos_level": "reclaimed_cores"
   283  						},
   284  						"qosLevel": "reclaimed_cores",
   285  						"request_quantity": 2
   286  					}
   287  				},
   288  				"373d08e4-7a6b-4293-aaaf-b135ff8123bf": {
   289  					"test": {
   290  						"pod_uid": "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
   291  						"pod_namespace": "test",
   292  						"pod_name": "test",
   293  						"container_name": "test",
   294  						"container_type": "MAIN",
   295  						"owner_pool_name": "share",
   296  						"allocation_result": "4,12",
   297  						"original_allocation_result": "4,12",
   298  						"topology_aware_assignments": {
   299  							"2": "4,12"
   300  						},
   301  						"original_topology_aware_assignments": {
   302  							"2": "4,12"
   303  						},
   304  						"init_timestamp": "",
   305  						"labels": {
   306  							"katalyst.kubewharf.io/qos_level": "shared_cores"
   307  						},
   308  						"annotations": {
   309  							"katalyst.kubewharf.io/qos_level": "shared_cores"
   310  						},
   311  						"qosLevel": "shared_cores",
   312  						"request_quantity": 2
   313  					}
   314  				},
   315  				"ec6e2f30-c78a-4bc4-9576-c916db5281a3": {
   316  					"test": {
   317  						"pod_uid": "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
   318  						"pod_namespace": "test",
   319  						"pod_name": "test",
   320  						"container_name": "test",
   321  						"container_type": "MAIN",
   322  						"owner_pool_name": "share",
   323  						"allocation_result": "4,12",
   324  						"original_allocation_result": "4,12",
   325  						"topology_aware_assignments": {
   326  							"2": "4,12"
   327  						},
   328  						"original_topology_aware_assignments": {
   329  							"2": "4,12"
   330  						},
   331  						"init_timestamp": "",
   332  						"labels": {
   333  							"katalyst.kubewharf.io/qos_level": "shared_cores"
   334  						},
   335  						"annotations": {
   336  							"katalyst.kubewharf.io/qos_level": "shared_cores"
   337  						},
   338  						"qosLevel": "shared_cores",
   339  						"request_quantity": 2
   340  					}
   341  				}
   342  			}
   343  		},
   344  		"3": {
   345  			"default_cpuset": "6-7,14-15",
   346  			"allocated_cpuset": "",
   347  			"pod_entries": {
   348  				"2432d068-c5a0-46ba-a7bd-b69d9bd16961": {
   349  					"test": {
   350  						"pod_uid": "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
   351  						"pod_namespace": "test",
   352  						"pod_name": "test",
   353  						"container_name": "test",
   354  						"container_type": "MAIN",
   355  						"owner_pool_name": "reclaim",
   356  						"allocation_result": "6-7,14-15",
   357  						"original_allocation_result": "6-7,14-15",
   358  						"topology_aware_assignments": {
   359  							"3": "6-7,14-15"
   360  						},
   361  						"original_topology_aware_assignments": {
   362  							"3": "6-7,14-15"
   363  						},
   364  						"init_timestamp": "",
   365  						"labels": {
   366  							"katalyst.kubewharf.io/qos_level": "reclaimed_cores"
   367  						},
   368  						"annotations": {
   369  							"katalyst.kubewharf.io/qos_level": "reclaimed_cores"
   370  						},
   371  						"qosLevel": "reclaimed_cores",
   372  						"request_quantity": 2
   373  					}
   374  				}
   375  			}
   376  		}
   377  	},
   378  	"pod_entries": {
   379  		"2432d068-c5a0-46ba-a7bd-b69d9bd16961": {
   380  			"test": {
   381  				"pod_uid": "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
   382  				"pod_namespace": "test",
   383  				"pod_name": "test",
   384  				"container_name": "test",
   385  				"container_type": "MAIN",
   386  				"owner_pool_name": "reclaim",
   387  				"allocation_result": "5-8,10,13-15",
   388  				"original_allocation_result": "5-8,10,13-15",
   389  				"topology_aware_assignments": {
   390  					"0": "8",
   391  					"1": "10",
   392  					"2": "5,13",
   393  					"3": "6-7,14-15"
   394  				},
   395  				"original_topology_aware_assignments": {
   396  					"0": "8",
   397  					"1": "10",
   398  					"2": "5,13",
   399  					"3": "6-7,14-15"
   400  				},
   401  				"init_timestamp": "",
   402  				"labels": {
   403  					"katalyst.kubewharf.io/qos_level": "reclaimed_cores"
   404  				},
   405  				"annotations": {
   406  					"katalyst.kubewharf.io/qos_level": "reclaimed_cores"
   407  				},
   408  				"qosLevel": "reclaimed_cores",
   409  				"request_quantity": 2
   410  			}
   411  		},
   412  		"373d08e4-7a6b-4293-aaaf-b135ff8123bf": {
   413  			"test": {
   414  				"pod_uid": "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
   415  				"pod_namespace": "test",
   416  				"pod_name": "test",
   417  				"container_name": "test",
   418  				"container_type": "MAIN",
   419  				"owner_pool_name": "share",
   420  				"allocation_result": "1,3-4,9,11-12",
   421  				"original_allocation_result": "1,3-4,9,11-12",
   422  				"topology_aware_assignments": {
   423  					"0": "1,9",
   424  					"1": "3,11",
   425  					"2": "4,12"
   426  				},
   427  				"original_topology_aware_assignments": {
   428  					"0": "1,9",
   429  					"1": "3,11",
   430  					"2": "4,12"
   431  				},
   432  				"init_timestamp": "",
   433  				"labels": {
   434  					"katalyst.kubewharf.io/qos_level": "shared_cores"
   435  				},
   436  				"annotations": {
   437  					"katalyst.kubewharf.io/qos_level": "shared_cores"
   438  				},
   439  				"qosLevel": "shared_cores",
   440  				"request_quantity": 2
   441  			}
   442  		},
   443  		"ec6e2f30-c78a-4bc4-9576-c916db5281a3": {
   444  			"test": {
   445  				"pod_uid": "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
   446  				"pod_namespace": "test",
   447  				"pod_name": "test",
   448  				"container_name": "test",
   449  				"container_type": "MAIN",
   450  				"owner_pool_name": "share",
   451  				"allocation_result": "1,3-4,9,11-12",
   452  				"original_allocation_result": "1,3-4,9,11-12",
   453  				"topology_aware_assignments": {
   454  					"0": "1,9",
   455  					"1": "3,11",
   456  					"2": "4,12"
   457  				},
   458  				"original_topology_aware_assignments": {
   459  					"0": "1,9",
   460  					"1": "3,11",
   461  					"2": "4,12"
   462  				},
   463  				"init_timestamp": "",
   464  				"labels": {
   465  					"katalyst.kubewharf.io/qos_level": "shared_cores"
   466  				},
   467  				"annotations": {
   468  					"katalyst.kubewharf.io/qos_level": "shared_cores"
   469  				},
   470  				"qosLevel": "shared_cores",
   471  				"request_quantity": 2
   472  			}
   473  		},
   474  		"reclaim": {
   475  			"": {
   476  				"pod_uid": "reclaim",
   477  				"owner_pool_name": "reclaim",
   478  				"allocation_result": "5-8,10,13-15",
   479  				"original_allocation_result": "5-8,10,13-15",
   480  				"topology_aware_assignments": {
   481  					"0": "8",
   482  					"1": "10",
   483  					"2": "5,13",
   484  					"3": "6-7,14-15"
   485  				},
   486  				"original_topology_aware_assignments": {
   487  					"0": "8",
   488  					"1": "10",
   489  					"2": "5,13",
   490  					"3": "6-7,14-15"
   491  				},
   492  				"init_timestamp": "",
   493  				"labels": null,
   494  				"annotations": null,
   495  				"qosLevel": ""
   496  			}
   497  		},
   498  		"share": {
   499  			"": {
   500  				"pod_uid": "share",
   501  				"owner_pool_name": "share",
   502  				"allocation_result": "1,3-4,9,11-12",
   503  				"original_allocation_result": "1,3-4,9,11-12",
   504  				"topology_aware_assignments": {
   505  					"0": "1,9",
   506  					"1": "3,11",
   507  					"2": "4,12"
   508  				},
   509  				"original_topology_aware_assignments": {
   510  					"0": "1,9",
   511  					"1": "3,11",
   512  					"2": "4,12"
   513  				},
   514  				"init_timestamp": "",
   515  				"labels": null,
   516  				"annotations": null,
   517  				"qosLevel": ""
   518  			}
   519  		}
   520  	},
   521  	"checksum": 1743112210
   522  }`,
   523  			"",
   524  			&cpuPluginState{
   525  				podEntries: PodEntries{
   526  					"373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{
   527  						testName: &AllocationInfo{
   528  							PodUid:                   "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
   529  							PodNamespace:             testName,
   530  							PodName:                  testName,
   531  							ContainerName:            testName,
   532  							ContainerType:            pluginapi.ContainerType_MAIN.String(),
   533  							ContainerIndex:           0,
   534  							RampUp:                   false,
   535  							OwnerPoolName:            PoolNameShare,
   536  							AllocationResult:         machine.MustParse("1,3-4,9,11-12"),
   537  							OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"),
   538  							TopologyAwareAssignments: map[int]machine.CPUSet{
   539  								0: machine.NewCPUSet(1, 9),
   540  								1: machine.NewCPUSet(3, 11),
   541  								2: machine.NewCPUSet(4, 12),
   542  							},
   543  							OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   544  								0: machine.NewCPUSet(1, 9),
   545  								1: machine.NewCPUSet(3, 11),
   546  								2: machine.NewCPUSet(4, 12),
   547  							},
   548  							Labels: map[string]string{
   549  								consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   550  							},
   551  							Annotations: map[string]string{
   552  								consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   553  							},
   554  							QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
   555  							RequestQuantity: 2,
   556  						},
   557  					},
   558  					"ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{
   559  						testName: &AllocationInfo{
   560  							PodUid:                   "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
   561  							PodNamespace:             testName,
   562  							PodName:                  testName,
   563  							ContainerName:            testName,
   564  							ContainerType:            pluginapi.ContainerType_MAIN.String(),
   565  							ContainerIndex:           0,
   566  							RampUp:                   false,
   567  							OwnerPoolName:            PoolNameShare,
   568  							AllocationResult:         machine.MustParse("1,3-4,9,11-12"),
   569  							OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"),
   570  							TopologyAwareAssignments: map[int]machine.CPUSet{
   571  								0: machine.NewCPUSet(1, 9),
   572  								1: machine.NewCPUSet(3, 11),
   573  								2: machine.NewCPUSet(4, 12),
   574  							},
   575  							OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   576  								0: machine.NewCPUSet(1, 9),
   577  								1: machine.NewCPUSet(3, 11),
   578  								2: machine.NewCPUSet(4, 12),
   579  							},
   580  							Labels: map[string]string{
   581  								consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   582  							},
   583  							Annotations: map[string]string{
   584  								consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   585  							},
   586  							QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
   587  							RequestQuantity: 2,
   588  						},
   589  					},
   590  					"2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{
   591  						testName: &AllocationInfo{
   592  							PodUid:                   "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
   593  							PodNamespace:             testName,
   594  							PodName:                  testName,
   595  							ContainerName:            testName,
   596  							ContainerType:            pluginapi.ContainerType_MAIN.String(),
   597  							ContainerIndex:           0,
   598  							RampUp:                   false,
   599  							OwnerPoolName:            PoolNameReclaim,
   600  							AllocationResult:         machine.MustParse("5-8,10,13-15"),
   601  							OriginalAllocationResult: machine.MustParse("5-8,10,13-15"),
   602  							TopologyAwareAssignments: map[int]machine.CPUSet{
   603  								0: machine.NewCPUSet(8),
   604  								1: machine.NewCPUSet(10),
   605  								2: machine.NewCPUSet(5, 13),
   606  								3: machine.NewCPUSet(6, 7, 14, 15),
   607  							},
   608  							OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   609  								0: machine.NewCPUSet(8),
   610  								1: machine.NewCPUSet(10),
   611  								2: machine.NewCPUSet(5, 13),
   612  								3: machine.NewCPUSet(6, 7, 14, 15),
   613  							},
   614  							Labels: map[string]string{
   615  								consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
   616  							},
   617  							Annotations: map[string]string{
   618  								consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
   619  							},
   620  							QoSLevel:        consts.PodAnnotationQoSLevelReclaimedCores,
   621  							RequestQuantity: 2,
   622  						},
   623  					},
   624  					PoolNameReclaim: ContainerEntries{
   625  						"": &AllocationInfo{
   626  							PodUid:                   PoolNameReclaim,
   627  							OwnerPoolName:            PoolNameReclaim,
   628  							AllocationResult:         machine.MustParse("5-8,10,13-15"),
   629  							OriginalAllocationResult: machine.MustParse("5-8,10,13-15"),
   630  							TopologyAwareAssignments: map[int]machine.CPUSet{
   631  								0: machine.NewCPUSet(8),
   632  								1: machine.NewCPUSet(10),
   633  								2: machine.NewCPUSet(5, 13),
   634  								3: machine.NewCPUSet(6, 7, 14, 15),
   635  							},
   636  							OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   637  								0: machine.NewCPUSet(8),
   638  								1: machine.NewCPUSet(10),
   639  								2: machine.NewCPUSet(5, 13),
   640  								3: machine.NewCPUSet(6, 7, 14, 15),
   641  							},
   642  						},
   643  					},
   644  					PoolNameShare: ContainerEntries{
   645  						"": &AllocationInfo{
   646  							PodUid:                   PoolNameShare,
   647  							OwnerPoolName:            PoolNameShare,
   648  							AllocationResult:         machine.MustParse("1,3-4,9,11-12"),
   649  							OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"),
   650  							TopologyAwareAssignments: map[int]machine.CPUSet{
   651  								0: machine.NewCPUSet(1, 9),
   652  								1: machine.NewCPUSet(3, 11),
   653  								2: machine.NewCPUSet(4, 12),
   654  							},
   655  							OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   656  								0: machine.NewCPUSet(1, 9),
   657  								1: machine.NewCPUSet(3, 11),
   658  								2: machine.NewCPUSet(4, 12),
   659  							},
   660  						},
   661  					},
   662  				},
   663  				machineState: NUMANodeMap{
   664  					0: &NUMANodeState{
   665  						DefaultCPUSet:   cpuTopology.CPUDetails.CPUsInNUMANodes(0).Clone(),
   666  						AllocatedCPUSet: machine.NewCPUSet(),
   667  						PodEntries: PodEntries{
   668  							"373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{
   669  								testName: &AllocationInfo{
   670  									PodUid:                   "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
   671  									PodNamespace:             testName,
   672  									PodName:                  testName,
   673  									ContainerName:            testName,
   674  									ContainerType:            pluginapi.ContainerType_MAIN.String(),
   675  									ContainerIndex:           0,
   676  									RampUp:                   false,
   677  									OwnerPoolName:            PoolNameShare,
   678  									AllocationResult:         machine.NewCPUSet(1, 9),
   679  									OriginalAllocationResult: machine.NewCPUSet(1, 9),
   680  									TopologyAwareAssignments: map[int]machine.CPUSet{
   681  										0: machine.NewCPUSet(1, 9),
   682  									},
   683  									OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   684  										0: machine.NewCPUSet(1, 9),
   685  									},
   686  									Labels: map[string]string{
   687  										consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   688  									},
   689  									Annotations: map[string]string{
   690  										consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   691  									},
   692  									QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
   693  									RequestQuantity: 2,
   694  								},
   695  							},
   696  							"ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{
   697  								testName: &AllocationInfo{
   698  									PodUid:                   "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
   699  									PodNamespace:             testName,
   700  									PodName:                  testName,
   701  									ContainerName:            testName,
   702  									ContainerType:            pluginapi.ContainerType_MAIN.String(),
   703  									ContainerIndex:           0,
   704  									RampUp:                   false,
   705  									OwnerPoolName:            PoolNameShare,
   706  									AllocationResult:         machine.NewCPUSet(1, 9),
   707  									OriginalAllocationResult: machine.NewCPUSet(1, 9),
   708  									TopologyAwareAssignments: map[int]machine.CPUSet{
   709  										0: machine.NewCPUSet(1, 9),
   710  									},
   711  									OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   712  										0: machine.NewCPUSet(1, 9),
   713  									},
   714  									Labels: map[string]string{
   715  										consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   716  									},
   717  									Annotations: map[string]string{
   718  										consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   719  									},
   720  									QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
   721  									RequestQuantity: 2,
   722  								},
   723  							},
   724  							"2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{
   725  								testName: &AllocationInfo{
   726  									PodUid:                   "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
   727  									PodNamespace:             testName,
   728  									PodName:                  testName,
   729  									ContainerName:            testName,
   730  									ContainerType:            pluginapi.ContainerType_MAIN.String(),
   731  									ContainerIndex:           0,
   732  									RampUp:                   false,
   733  									OwnerPoolName:            PoolNameReclaim,
   734  									AllocationResult:         machine.MustParse("8"),
   735  									OriginalAllocationResult: machine.MustParse("8"),
   736  									TopologyAwareAssignments: map[int]machine.CPUSet{
   737  										0: machine.NewCPUSet(8),
   738  									},
   739  									OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   740  										0: machine.NewCPUSet(8),
   741  									},
   742  									Labels: map[string]string{
   743  										consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
   744  									},
   745  									Annotations: map[string]string{
   746  										consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
   747  									},
   748  									QoSLevel:        consts.PodAnnotationQoSLevelReclaimedCores,
   749  									RequestQuantity: 2,
   750  								},
   751  							},
   752  						},
   753  					},
   754  					1: &NUMANodeState{
   755  						DefaultCPUSet:   cpuTopology.CPUDetails.CPUsInNUMANodes(1).Clone(),
   756  						AllocatedCPUSet: machine.NewCPUSet(),
   757  						PodEntries: PodEntries{
   758  							"373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{
   759  								testName: &AllocationInfo{
   760  									PodUid:                   "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
   761  									PodNamespace:             testName,
   762  									PodName:                  testName,
   763  									ContainerName:            testName,
   764  									ContainerType:            pluginapi.ContainerType_MAIN.String(),
   765  									ContainerIndex:           0,
   766  									RampUp:                   false,
   767  									OwnerPoolName:            PoolNameShare,
   768  									AllocationResult:         machine.MustParse("3,11"),
   769  									OriginalAllocationResult: machine.MustParse("3,11"),
   770  									TopologyAwareAssignments: map[int]machine.CPUSet{
   771  										1: machine.NewCPUSet(3, 11),
   772  									},
   773  									OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   774  										1: machine.NewCPUSet(3, 11),
   775  									},
   776  									Labels: map[string]string{
   777  										consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   778  									},
   779  									Annotations: map[string]string{
   780  										consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   781  									},
   782  									QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
   783  									RequestQuantity: 2,
   784  								},
   785  							},
   786  							"ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{
   787  								testName: &AllocationInfo{
   788  									PodUid:                   "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
   789  									PodNamespace:             testName,
   790  									PodName:                  testName,
   791  									ContainerName:            testName,
   792  									ContainerType:            pluginapi.ContainerType_MAIN.String(),
   793  									ContainerIndex:           0,
   794  									RampUp:                   false,
   795  									OwnerPoolName:            PoolNameShare,
   796  									AllocationResult:         machine.MustParse("3,11"),
   797  									OriginalAllocationResult: machine.MustParse("3,11"),
   798  									TopologyAwareAssignments: map[int]machine.CPUSet{
   799  										1: machine.NewCPUSet(3, 11),
   800  									},
   801  									OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   802  										1: machine.NewCPUSet(3, 11),
   803  									},
   804  									Labels: map[string]string{
   805  										consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   806  									},
   807  									Annotations: map[string]string{
   808  										consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   809  									},
   810  									QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
   811  									RequestQuantity: 2,
   812  								},
   813  							},
   814  							"2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{
   815  								testName: &AllocationInfo{
   816  									PodUid:                   "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
   817  									PodNamespace:             testName,
   818  									PodName:                  testName,
   819  									ContainerName:            testName,
   820  									ContainerType:            pluginapi.ContainerType_MAIN.String(),
   821  									ContainerIndex:           0,
   822  									RampUp:                   false,
   823  									OwnerPoolName:            PoolNameReclaim,
   824  									AllocationResult:         machine.MustParse("10"),
   825  									OriginalAllocationResult: machine.MustParse("10"),
   826  									TopologyAwareAssignments: map[int]machine.CPUSet{
   827  										1: machine.NewCPUSet(10),
   828  									},
   829  									OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   830  										1: machine.NewCPUSet(10),
   831  									},
   832  									Labels: map[string]string{
   833  										consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
   834  									},
   835  									Annotations: map[string]string{
   836  										consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
   837  									},
   838  									QoSLevel:        consts.PodAnnotationQoSLevelReclaimedCores,
   839  									RequestQuantity: 2,
   840  								},
   841  							},
   842  						},
   843  					},
   844  					2: &NUMANodeState{
   845  						DefaultCPUSet:   cpuTopology.CPUDetails.CPUsInNUMANodes(2).Clone(),
   846  						AllocatedCPUSet: machine.NewCPUSet(),
   847  						PodEntries: PodEntries{
   848  							"373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{
   849  								testName: &AllocationInfo{
   850  									PodUid:                   "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
   851  									PodNamespace:             testName,
   852  									PodName:                  testName,
   853  									ContainerName:            testName,
   854  									ContainerType:            pluginapi.ContainerType_MAIN.String(),
   855  									ContainerIndex:           0,
   856  									RampUp:                   false,
   857  									OwnerPoolName:            PoolNameShare,
   858  									AllocationResult:         machine.MustParse("4,12"),
   859  									OriginalAllocationResult: machine.MustParse("4,12"),
   860  									TopologyAwareAssignments: map[int]machine.CPUSet{
   861  										2: machine.NewCPUSet(4, 12),
   862  									},
   863  									OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   864  										2: machine.NewCPUSet(4, 12),
   865  									},
   866  									Labels: map[string]string{
   867  										consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   868  									},
   869  									Annotations: map[string]string{
   870  										consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   871  									},
   872  									QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
   873  									RequestQuantity: 2,
   874  								},
   875  							},
   876  							"ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{
   877  								testName: &AllocationInfo{
   878  									PodUid:                   "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
   879  									PodNamespace:             testName,
   880  									PodName:                  testName,
   881  									ContainerName:            testName,
   882  									ContainerType:            pluginapi.ContainerType_MAIN.String(),
   883  									ContainerIndex:           0,
   884  									RampUp:                   false,
   885  									OwnerPoolName:            PoolNameShare,
   886  									AllocationResult:         machine.MustParse("4,12"),
   887  									OriginalAllocationResult: machine.MustParse("4,12"),
   888  									TopologyAwareAssignments: map[int]machine.CPUSet{
   889  										2: machine.NewCPUSet(4, 12),
   890  									},
   891  									OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   892  										2: machine.NewCPUSet(4, 12),
   893  									},
   894  									Labels: map[string]string{
   895  										consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   896  									},
   897  									Annotations: map[string]string{
   898  										consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
   899  									},
   900  									QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
   901  									RequestQuantity: 2,
   902  								},
   903  							},
   904  							"2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{
   905  								testName: &AllocationInfo{
   906  									PodUid:                   "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
   907  									PodNamespace:             testName,
   908  									PodName:                  testName,
   909  									ContainerName:            testName,
   910  									ContainerType:            pluginapi.ContainerType_MAIN.String(),
   911  									ContainerIndex:           0,
   912  									RampUp:                   false,
   913  									OwnerPoolName:            PoolNameReclaim,
   914  									AllocationResult:         machine.MustParse("5,13"),
   915  									OriginalAllocationResult: machine.MustParse("5,13"),
   916  									TopologyAwareAssignments: map[int]machine.CPUSet{
   917  										2: machine.NewCPUSet(5, 13),
   918  									},
   919  									OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   920  										2: machine.NewCPUSet(5, 13),
   921  									},
   922  									Labels: map[string]string{
   923  										consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
   924  									},
   925  									Annotations: map[string]string{
   926  										consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
   927  									},
   928  									QoSLevel:        consts.PodAnnotationQoSLevelReclaimedCores,
   929  									RequestQuantity: 2,
   930  								},
   931  							},
   932  						},
   933  					},
   934  					3: &NUMANodeState{
   935  						DefaultCPUSet:   cpuTopology.CPUDetails.CPUsInNUMANodes(3).Clone(),
   936  						AllocatedCPUSet: machine.NewCPUSet(),
   937  						PodEntries: PodEntries{
   938  							"2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{
   939  								testName: &AllocationInfo{
   940  									PodUid:                   "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
   941  									PodNamespace:             testName,
   942  									PodName:                  testName,
   943  									ContainerName:            testName,
   944  									ContainerType:            pluginapi.ContainerType_MAIN.String(),
   945  									ContainerIndex:           0,
   946  									RampUp:                   false,
   947  									OwnerPoolName:            PoolNameReclaim,
   948  									AllocationResult:         machine.MustParse("6,7,14,15"),
   949  									OriginalAllocationResult: machine.MustParse("6,7,14,15"),
   950  									TopologyAwareAssignments: map[int]machine.CPUSet{
   951  										3: machine.NewCPUSet(6, 7, 14, 15),
   952  									},
   953  									OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
   954  										3: machine.NewCPUSet(6, 7, 14, 15),
   955  									},
   956  									Labels: map[string]string{
   957  										consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
   958  									},
   959  									Annotations: map[string]string{
   960  										consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
   961  									},
   962  									QoSLevel:        consts.PodAnnotationQoSLevelReclaimedCores,
   963  									RequestQuantity: 2,
   964  								},
   965  							},
   966  						},
   967  					},
   968  				},
   969  			},
   970  		},
   971  		{
   972  			"Restore checkpoint with invalid checksum",
   973  			`{
   974  	"policyName": "dynamic",
   975  	"machineState": {
   976  		"0": {
   977  			"default_cpuset": "0-1,8-9",
   978  			"allocated_cpuset": "",
   979  			"pod_entries": {
   980  				"2432d068-c5a0-46ba-a7bd-b69d9bd16961": {
   981  					"test": {
   982  						"pod_uid": "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
   983  						"pod_namespace": "test",
   984  						"pod_name": "test",
   985  						"container_name": "test",
   986  						"container_type": "MAIN",
   987  						"owner_pool_name": "reclaim",
   988  						"allocation_result": "8",
   989  						"original_allocation_result": "8",
   990  						"topology_aware_assignments": {
   991  							"0": "8"
   992  						},
   993  						"original_topology_aware_assignments": {
   994  							"0": "8"
   995  						},
   996  						"init_timestamp": "",
   997  						"labels": {
   998  							"katalyst.kubewharf.io/qos_level": "reclaimed_cores"
   999  						},
  1000  						"annotations": {
  1001  							"katalyst.kubewharf.io/qos_level": "reclaimed_cores"
  1002  						},
  1003  						"qosLevel": "reclaimed_cores",
  1004  						"request_quantity": 2
  1005  					}
  1006  				},
  1007  				"373d08e4-7a6b-4293-aaaf-b135ff8123bf": {
  1008  					"test": {
  1009  						"pod_uid": "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
  1010  						"pod_namespace": "test",
  1011  						"pod_name": "test",
  1012  						"container_name": "test",
  1013  						"container_type": "MAIN",
  1014  						"owner_pool_name": "share",
  1015  						"allocation_result": "1,9",
  1016  						"original_allocation_result": "1,9",
  1017  						"topology_aware_assignments": {
  1018  							"0": "1,9"
  1019  						},
  1020  						"original_topology_aware_assignments": {
  1021  							"0": "1,9"
  1022  						},
  1023  						"init_timestamp": "",
  1024  						"labels": {
  1025  							"katalyst.kubewharf.io/qos_level": "shared_cores"
  1026  						},
  1027  						"annotations": {
  1028  							"katalyst.kubewharf.io/qos_level": "shared_cores"
  1029  						},
  1030  						"qosLevel": "shared_cores",
  1031  						"request_quantity": 2
  1032  					}
  1033  				},
  1034  				"ec6e2f30-c78a-4bc4-9576-c916db5281a3": {
  1035  					"test": {
  1036  						"pod_uid": "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
  1037  						"pod_namespace": "test",
  1038  						"pod_name": "test",
  1039  						"container_name": "test",
  1040  						"container_type": "MAIN",
  1041  						"owner_pool_name": "share",
  1042  						"allocation_result": "1,9",
  1043  						"original_allocation_result": "1,9",
  1044  						"topology_aware_assignments": {
  1045  							"0": "1,9"
  1046  						},
  1047  						"original_topology_aware_assignments": {
  1048  							"0": "1,9"
  1049  						},
  1050  						"init_timestamp": "",
  1051  						"labels": {
  1052  							"katalyst.kubewharf.io/qos_level": "shared_cores"
  1053  						},
  1054  						"annotations": {
  1055  							"katalyst.kubewharf.io/qos_level": "shared_cores"
  1056  						},
  1057  						"qosLevel": "shared_cores",
  1058  						"request_quantity": 2
  1059  					}
  1060  				}
  1061  			}
  1062  		},
  1063  		"1": {
  1064  			"default_cpuset": "2-3,10-11",
  1065  			"allocated_cpuset": "",
  1066  			"pod_entries": {
  1067  				"2432d068-c5a0-46ba-a7bd-b69d9bd16961": {
  1068  					"test": {
  1069  						"pod_uid": "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
  1070  						"pod_namespace": "test",
  1071  						"pod_name": "test",
  1072  						"container_name": "test",
  1073  						"container_type": "MAIN",
  1074  						"owner_pool_name": "reclaim",
  1075  						"allocation_result": "10",
  1076  						"original_allocation_result": "10",
  1077  						"topology_aware_assignments": {
  1078  							"1": "10"
  1079  						},
  1080  						"original_topology_aware_assignments": {
  1081  							"1": "10"
  1082  						},
  1083  						"init_timestamp": "",
  1084  						"labels": {
  1085  							"katalyst.kubewharf.io/qos_level": "reclaimed_cores"
  1086  						},
  1087  						"annotations": {
  1088  							"katalyst.kubewharf.io/qos_level": "reclaimed_cores"
  1089  						},
  1090  						"qosLevel": "reclaimed_cores",
  1091  						"request_quantity": 2
  1092  					}
  1093  				},
  1094  				"373d08e4-7a6b-4293-aaaf-b135ff8123bf": {
  1095  					"test": {
  1096  						"pod_uid": "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
  1097  						"pod_namespace": "test",
  1098  						"pod_name": "test",
  1099  						"container_name": "test",
  1100  						"container_type": "MAIN",
  1101  						"owner_pool_name": "share",
  1102  						"allocation_result": "3,11",
  1103  						"original_allocation_result": "3,11",
  1104  						"topology_aware_assignments": {
  1105  							"1": "3,11"
  1106  						},
  1107  						"original_topology_aware_assignments": {
  1108  							"1": "3,11"
  1109  						},
  1110  						"init_timestamp": "",
  1111  						"labels": {
  1112  							"katalyst.kubewharf.io/qos_level": "shared_cores"
  1113  						},
  1114  						"annotations": {
  1115  							"katalyst.kubewharf.io/qos_level": "shared_cores"
  1116  						},
  1117  						"qosLevel": "shared_cores",
  1118  						"request_quantity": 2
  1119  					}
  1120  				},
  1121  				"ec6e2f30-c78a-4bc4-9576-c916db5281a3": {
  1122  					"test": {
  1123  						"pod_uid": "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
  1124  						"pod_namespace": "test",
  1125  						"pod_name": "test",
  1126  						"container_name": "test",
  1127  						"container_type": "MAIN",
  1128  						"owner_pool_name": "share",
  1129  						"allocation_result": "3,11",
  1130  						"original_allocation_result": "3,11",
  1131  						"topology_aware_assignments": {
  1132  							"1": "3,11"
  1133  						},
  1134  						"original_topology_aware_assignments": {
  1135  							"1": "3,11"
  1136  						},
  1137  						"init_timestamp": "",
  1138  						"labels": {
  1139  							"katalyst.kubewharf.io/qos_level": "shared_cores"
  1140  						},
  1141  						"annotations": {
  1142  							"katalyst.kubewharf.io/qos_level": "shared_cores"
  1143  						},
  1144  						"qosLevel": "shared_cores",
  1145  						"request_quantity": 2
  1146  					}
  1147  				}
  1148  			}
  1149  		},
  1150  		"2": {
  1151  			"default_cpuset": "4-5,12-13",
  1152  			"allocated_cpuset": "",
  1153  			"pod_entries": {
  1154  				"2432d068-c5a0-46ba-a7bd-b69d9bd16961": {
  1155  					"test": {
  1156  						"pod_uid": "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
  1157  						"pod_namespace": "test",
  1158  						"pod_name": "test",
  1159  						"container_name": "test",
  1160  						"container_type": "MAIN",
  1161  						"owner_pool_name": "reclaim",
  1162  						"allocation_result": "5,13",
  1163  						"original_allocation_result": "5,13",
  1164  						"topology_aware_assignments": {
  1165  							"2": "5,13"
  1166  						},
  1167  						"original_topology_aware_assignments": {
  1168  							"2": "5,13"
  1169  						},
  1170  						"init_timestamp": "",
  1171  						"labels": {
  1172  							"katalyst.kubewharf.io/qos_level": "reclaimed_cores"
  1173  						},
  1174  						"annotations": {
  1175  							"katalyst.kubewharf.io/qos_level": "reclaimed_cores"
  1176  						},
  1177  						"qosLevel": "reclaimed_cores",
  1178  						"request_quantity": 2
  1179  					}
  1180  				},
  1181  				"373d08e4-7a6b-4293-aaaf-b135ff8123bf": {
  1182  					"test": {
  1183  						"pod_uid": "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
  1184  						"pod_namespace": "test",
  1185  						"pod_name": "test",
  1186  						"container_name": "test",
  1187  						"container_type": "MAIN",
  1188  						"owner_pool_name": "share",
  1189  						"allocation_result": "4,12",
  1190  						"original_allocation_result": "4,12",
  1191  						"topology_aware_assignments": {
  1192  							"2": "4,12"
  1193  						},
  1194  						"original_topology_aware_assignments": {
  1195  							"2": "4,12"
  1196  						},
  1197  						"init_timestamp": "",
  1198  						"labels": {
  1199  							"katalyst.kubewharf.io/qos_level": "shared_cores"
  1200  						},
  1201  						"annotations": {
  1202  							"katalyst.kubewharf.io/qos_level": "shared_cores"
  1203  						},
  1204  						"qosLevel": "shared_cores",
  1205  						"request_quantity": 2
  1206  					}
  1207  				},
  1208  				"ec6e2f30-c78a-4bc4-9576-c916db5281a3": {
  1209  					"test": {
  1210  						"pod_uid": "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
  1211  						"pod_namespace": "test",
  1212  						"pod_name": "test",
  1213  						"container_name": "test",
  1214  						"container_type": "MAIN",
  1215  						"owner_pool_name": "share",
  1216  						"allocation_result": "4,12",
  1217  						"original_allocation_result": "4,12",
  1218  						"topology_aware_assignments": {
  1219  							"2": "4,12"
  1220  						},
  1221  						"original_topology_aware_assignments": {
  1222  							"2": "4,12"
  1223  						},
  1224  						"init_timestamp": "",
  1225  						"labels": {
  1226  							"katalyst.kubewharf.io/qos_level": "shared_cores"
  1227  						},
  1228  						"annotations": {
  1229  							"katalyst.kubewharf.io/qos_level": "shared_cores"
  1230  						},
  1231  						"qosLevel": "shared_cores",
  1232  						"request_quantity": 2
  1233  					}
  1234  				}
  1235  			}
  1236  		},
  1237  		"3": {
  1238  			"default_cpuset": "6-7,14-15",
  1239  			"allocated_cpuset": "",
  1240  			"pod_entries": {
  1241  				"2432d068-c5a0-46ba-a7bd-b69d9bd16961": {
  1242  					"test": {
  1243  						"pod_uid": "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
  1244  						"pod_namespace": "test",
  1245  						"pod_name": "test",
  1246  						"container_name": "test",
  1247  						"container_type": "MAIN",
  1248  						"owner_pool_name": "reclaim",
  1249  						"allocation_result": "6-7,14-15",
  1250  						"original_allocation_result": "6-7,14-15",
  1251  						"topology_aware_assignments": {
  1252  							"3": "6-7,14-15"
  1253  						},
  1254  						"original_topology_aware_assignments": {
  1255  							"3": "6-7,14-15"
  1256  						},
  1257  						"init_timestamp": "",
  1258  						"labels": {
  1259  							"katalyst.kubewharf.io/qos_level": "reclaimed_cores"
  1260  						},
  1261  						"annotations": {
  1262  							"katalyst.kubewharf.io/qos_level": "reclaimed_cores"
  1263  						},
  1264  						"qosLevel": "reclaimed_cores",
  1265  						"request_quantity": 2
  1266  					}
  1267  				}
  1268  			}
  1269  		}
  1270  	},
  1271  	"pod_entries": {
  1272  		"2432d068-c5a0-46ba-a7bd-b69d9bd16961": {
  1273  			"test": {
  1274  				"pod_uid": "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
  1275  				"pod_namespace": "test",
  1276  				"pod_name": "test",
  1277  				"container_name": "test",
  1278  				"container_type": "MAIN",
  1279  				"owner_pool_name": "reclaim",
  1280  				"allocation_result": "5-8,10,13-15",
  1281  				"original_allocation_result": "5-8,10,13-15",
  1282  				"topology_aware_assignments": {
  1283  					"0": "8",
  1284  					"1": "10",
  1285  					"2": "5,13",
  1286  					"3": "6-7,14-15"
  1287  				},
  1288  				"original_topology_aware_assignments": {
  1289  					"0": "8",
  1290  					"1": "10",
  1291  					"2": "5,13",
  1292  					"3": "6-7,14-15"
  1293  				},
  1294  				"init_timestamp": "",
  1295  				"labels": {
  1296  					"katalyst.kubewharf.io/qos_level": "reclaimed_cores"
  1297  				},
  1298  				"annotations": {
  1299  					"katalyst.kubewharf.io/qos_level": "reclaimed_cores"
  1300  				},
  1301  				"qosLevel": "reclaimed_cores",
  1302  				"request_quantity": 2
  1303  			}
  1304  		},
  1305  		"373d08e4-7a6b-4293-aaaf-b135ff8123bf": {
  1306  			"test": {
  1307  				"pod_uid": "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
  1308  				"pod_namespace": "test",
  1309  				"pod_name": "test",
  1310  				"container_name": "test",
  1311  				"container_type": "MAIN",
  1312  				"owner_pool_name": "share",
  1313  				"allocation_result": "1,3-4,9,11-12",
  1314  				"original_allocation_result": "1,3-4,9,11-12",
  1315  				"topology_aware_assignments": {
  1316  					"0": "1,9",
  1317  					"1": "3,11",
  1318  					"2": "4,12"
  1319  				},
  1320  				"original_topology_aware_assignments": {
  1321  					"0": "1,9",
  1322  					"1": "3,11",
  1323  					"2": "4,12"
  1324  				},
  1325  				"init_timestamp": "",
  1326  				"labels": {
  1327  					"katalyst.kubewharf.io/qos_level": "shared_cores"
  1328  				},
  1329  				"annotations": {
  1330  					"katalyst.kubewharf.io/qos_level": "shared_cores"
  1331  				},
  1332  				"qosLevel": "shared_cores",
  1333  				"request_quantity": 2
  1334  			}
  1335  		},
  1336  		"ec6e2f30-c78a-4bc4-9576-c916db5281a3": {
  1337  			"test": {
  1338  				"pod_uid": "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
  1339  				"pod_namespace": "test",
  1340  				"pod_name": "test",
  1341  				"container_name": "test",
  1342  				"container_type": "MAIN",
  1343  				"owner_pool_name": "share",
  1344  				"allocation_result": "1,3-4,9,11-12",
  1345  				"original_allocation_result": "1,3-4,9,11-12",
  1346  				"topology_aware_assignments": {
  1347  					"0": "1,9",
  1348  					"1": "3,11",
  1349  					"2": "4,12"
  1350  				},
  1351  				"original_topology_aware_assignments": {
  1352  					"0": "1,9",
  1353  					"1": "3,11",
  1354  					"2": "4,12"
  1355  				},
  1356  				"init_timestamp": "",
  1357  				"labels": {
  1358  					"katalyst.kubewharf.io/qos_level": "shared_cores"
  1359  				},
  1360  				"annotations": {
  1361  					"katalyst.kubewharf.io/qos_level": "shared_cores"
  1362  				},
  1363  				"qosLevel": "shared_cores",
  1364  				"request_quantity": 2
  1365  			}
  1366  		},
  1367  		"reclaim": {
  1368  			"": {
  1369  				"pod_uid": "reclaim",
  1370  				"owner_pool_name": "reclaim",
  1371  				"allocation_result": "5-8,10,13-15",
  1372  				"original_allocation_result": "5-8,10,13-15",
  1373  				"topology_aware_assignments": {
  1374  					"0": "8",
  1375  					"1": "10",
  1376  					"2": "5,13",
  1377  					"3": "6-7,14-15"
  1378  				},
  1379  				"original_topology_aware_assignments": {
  1380  					"0": "8",
  1381  					"1": "10",
  1382  					"2": "5,13",
  1383  					"3": "6-7,14-15"
  1384  				},
  1385  				"init_timestamp": "",
  1386  				"labels": null,
  1387  				"annotations": null,
  1388  				"qosLevel": ""
  1389  			}
  1390  		},
  1391  		"share": {
  1392  			"": {
  1393  				"pod_uid": "share",
  1394  				"owner_pool_name": "share",
  1395  				"allocation_result": "1,3-4,9,11-12",
  1396  				"original_allocation_result": "1,3-4,9,11-12",
  1397  				"topology_aware_assignments": {
  1398  					"0": "1,9",
  1399  					"1": "3,11",
  1400  					"2": "4,12"
  1401  				},
  1402  				"original_topology_aware_assignments": {
  1403  					"0": "1,9",
  1404  					"1": "3,11",
  1405  					"2": "4,12"
  1406  				},
  1407  				"init_timestamp": "",
  1408  				"labels": null,
  1409  				"annotations": null,
  1410  				"qosLevel": ""
  1411  			}
  1412  		}
  1413  	},
  1414  	"checksum": 2840585175
  1415  }`,
  1416  			"checkpoint is corrupted",
  1417  			&cpuPluginState{},
  1418  		},
  1419  		{
  1420  			"Restore checkpoint with invalid JSON",
  1421  			`{`,
  1422  			"unexpected end of JSON input",
  1423  			&cpuPluginState{},
  1424  		},
  1425  	}
  1426  
  1427  	// create temp dir
  1428  	testingDir, err := ioutil.TempDir("", "TestNewCheckpointState")
  1429  	if err != nil {
  1430  		t.Fatal(err)
  1431  	}
  1432  	defer os.RemoveAll(testingDir)
  1433  
  1434  	// create checkpoint manager for testing
  1435  	cpm, err := checkpointmanager.NewCheckpointManager(testingDir)
  1436  	assert.NoError(t, err, "could not create testing checkpoint manager")
  1437  
  1438  	for _, tc := range testCases {
  1439  		// ensure there is no previous checkpoint
  1440  		require.NoError(t, cpm.RemoveCheckpoint(cpuPluginStateFileName), "could not remove testing checkpoint")
  1441  
  1442  		// prepare checkpoint for testing
  1443  		if strings.TrimSpace(tc.checkpointContent) != "" {
  1444  			checkpoint := &testutil.MockCheckpoint{Content: tc.checkpointContent}
  1445  			require.NoError(t, cpm.CreateCheckpoint(cpuPluginStateFileName, checkpoint), "could not create testing checkpoint")
  1446  		}
  1447  
  1448  		restoredState, err := NewCheckpointState(testingDir, cpuPluginStateFileName, policyName, cpuTopology, false)
  1449  		if strings.TrimSpace(tc.expectedError) != "" {
  1450  			require.Error(t, err)
  1451  			require.Contains(t, err.Error(), "could not restore state from checkpoint:")
  1452  			require.Contains(t, err.Error(), tc.expectedError)
  1453  
  1454  			// test skip corruption
  1455  			if strings.Contains(err.Error(), "checkpoint is corrupted") {
  1456  				_, err = NewCheckpointState(testingDir, cpuPluginStateFileName, policyName, cpuTopology, true)
  1457  				require.Nil(t, err)
  1458  			}
  1459  		} else {
  1460  			require.NoError(t, err, "unexpected error while creating checkpointState")
  1461  			// compare state after restoration with the one expected
  1462  			assertStateEqual(t, restoredState, tc.expectedState)
  1463  		}
  1464  	}
  1465  }
  1466  
  1467  func TestClearState(t *testing.T) {
  1468  	t.Parallel()
  1469  
  1470  	as := require.New(t)
  1471  
  1472  	testName := "test"
  1473  	cpuTopology, err := machine.GenerateDummyCPUTopology(16, 2, 4)
  1474  	as.Nil(err)
  1475  
  1476  	testCases := []struct {
  1477  		description  string
  1478  		cpuTopology  *machine.CPUTopology
  1479  		podEntries   PodEntries
  1480  		machineState NUMANodeMap
  1481  	}{
  1482  		{
  1483  			description: "valid state cleaning",
  1484  			cpuTopology: cpuTopology,
  1485  			podEntries: PodEntries{
  1486  				"373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{
  1487  					testName: &AllocationInfo{
  1488  						PodUid:                   "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
  1489  						PodNamespace:             testName,
  1490  						PodName:                  testName,
  1491  						ContainerName:            testName,
  1492  						ContainerType:            pluginapi.ContainerType_MAIN.String(),
  1493  						ContainerIndex:           0,
  1494  						RampUp:                   false,
  1495  						OwnerPoolName:            PoolNameShare,
  1496  						AllocationResult:         machine.MustParse("1,3-4,9,11-12"),
  1497  						OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"),
  1498  						TopologyAwareAssignments: map[int]machine.CPUSet{
  1499  							0: machine.NewCPUSet(1, 9),
  1500  							1: machine.NewCPUSet(3, 11),
  1501  							2: machine.NewCPUSet(4, 12),
  1502  						},
  1503  						OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  1504  							0: machine.NewCPUSet(1, 9),
  1505  							1: machine.NewCPUSet(3, 11),
  1506  							2: machine.NewCPUSet(4, 12),
  1507  						},
  1508  						Labels: map[string]string{
  1509  							consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  1510  						},
  1511  						Annotations: map[string]string{
  1512  							consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  1513  						},
  1514  						QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
  1515  						RequestQuantity: 2,
  1516  					},
  1517  				},
  1518  				"ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{
  1519  					testName: &AllocationInfo{
  1520  						PodUid:                   "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
  1521  						PodNamespace:             testName,
  1522  						PodName:                  testName,
  1523  						ContainerName:            testName,
  1524  						ContainerType:            pluginapi.ContainerType_MAIN.String(),
  1525  						ContainerIndex:           0,
  1526  						RampUp:                   false,
  1527  						OwnerPoolName:            PoolNameShare,
  1528  						AllocationResult:         machine.MustParse("1,3-4,9,11-12"),
  1529  						OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"),
  1530  						TopologyAwareAssignments: map[int]machine.CPUSet{
  1531  							0: machine.NewCPUSet(1, 9),
  1532  							1: machine.NewCPUSet(3, 11),
  1533  							2: machine.NewCPUSet(4, 12),
  1534  						},
  1535  						OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  1536  							0: machine.NewCPUSet(1, 9),
  1537  							1: machine.NewCPUSet(3, 11),
  1538  							2: machine.NewCPUSet(4, 12),
  1539  						},
  1540  						Labels: map[string]string{
  1541  							consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  1542  						},
  1543  						Annotations: map[string]string{
  1544  							consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  1545  						},
  1546  						QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
  1547  						RequestQuantity: 2,
  1548  					},
  1549  				},
  1550  				"2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{
  1551  					testName: &AllocationInfo{
  1552  						PodUid:                   "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
  1553  						PodNamespace:             testName,
  1554  						PodName:                  testName,
  1555  						ContainerName:            testName,
  1556  						ContainerType:            pluginapi.ContainerType_MAIN.String(),
  1557  						ContainerIndex:           0,
  1558  						RampUp:                   false,
  1559  						OwnerPoolName:            PoolNameReclaim,
  1560  						AllocationResult:         machine.MustParse("5-8,10,13-15"),
  1561  						OriginalAllocationResult: machine.MustParse("5-8,10,13-15"),
  1562  						TopologyAwareAssignments: map[int]machine.CPUSet{
  1563  							0: machine.NewCPUSet(8),
  1564  							1: machine.NewCPUSet(10),
  1565  							2: machine.NewCPUSet(5, 13),
  1566  							3: machine.NewCPUSet(6, 7, 14, 15),
  1567  						},
  1568  						OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  1569  							0: machine.NewCPUSet(8),
  1570  							1: machine.NewCPUSet(10),
  1571  							2: machine.NewCPUSet(5, 13),
  1572  							3: machine.NewCPUSet(6, 7, 14, 15),
  1573  						},
  1574  						Labels: map[string]string{
  1575  							consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
  1576  						},
  1577  						Annotations: map[string]string{
  1578  							consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
  1579  						},
  1580  						QoSLevel:        consts.PodAnnotationQoSLevelReclaimedCores,
  1581  						RequestQuantity: 2,
  1582  					},
  1583  				},
  1584  				PoolNameReclaim: ContainerEntries{
  1585  					"": &AllocationInfo{
  1586  						PodUid:                   PoolNameReclaim,
  1587  						OwnerPoolName:            PoolNameReclaim,
  1588  						AllocationResult:         machine.MustParse("5-8,10,13-15"),
  1589  						OriginalAllocationResult: machine.MustParse("5-8,10,13-15"),
  1590  						TopologyAwareAssignments: map[int]machine.CPUSet{
  1591  							0: machine.NewCPUSet(8),
  1592  							1: machine.NewCPUSet(10),
  1593  							2: machine.NewCPUSet(5, 13),
  1594  							3: machine.NewCPUSet(6, 7, 14, 15),
  1595  						},
  1596  						OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  1597  							0: machine.NewCPUSet(8),
  1598  							1: machine.NewCPUSet(10),
  1599  							2: machine.NewCPUSet(5, 13),
  1600  							3: machine.NewCPUSet(6, 7, 14, 15),
  1601  						},
  1602  					},
  1603  				},
  1604  				PoolNameShare: ContainerEntries{
  1605  					"": &AllocationInfo{
  1606  						PodUid:                   PoolNameShare,
  1607  						OwnerPoolName:            PoolNameShare,
  1608  						AllocationResult:         machine.MustParse("1,3-4,9,11-12"),
  1609  						OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"),
  1610  						TopologyAwareAssignments: map[int]machine.CPUSet{
  1611  							0: machine.NewCPUSet(1, 9),
  1612  							1: machine.NewCPUSet(3, 11),
  1613  							2: machine.NewCPUSet(4, 12),
  1614  						},
  1615  						OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  1616  							0: machine.NewCPUSet(1, 9),
  1617  							1: machine.NewCPUSet(3, 11),
  1618  							2: machine.NewCPUSet(4, 12),
  1619  						},
  1620  					},
  1621  				},
  1622  			},
  1623  			machineState: NUMANodeMap{
  1624  				0: &NUMANodeState{
  1625  					DefaultCPUSet:   cpuTopology.CPUDetails.CPUsInNUMANodes(0).Clone(),
  1626  					AllocatedCPUSet: machine.NewCPUSet(),
  1627  					PodEntries: PodEntries{
  1628  						"373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{
  1629  							testName: &AllocationInfo{
  1630  								PodUid:                   "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
  1631  								PodNamespace:             testName,
  1632  								PodName:                  testName,
  1633  								ContainerName:            testName,
  1634  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
  1635  								ContainerIndex:           0,
  1636  								RampUp:                   false,
  1637  								OwnerPoolName:            PoolNameShare,
  1638  								AllocationResult:         machine.NewCPUSet(1, 9),
  1639  								OriginalAllocationResult: machine.NewCPUSet(1, 9),
  1640  								TopologyAwareAssignments: map[int]machine.CPUSet{
  1641  									0: machine.NewCPUSet(1, 9),
  1642  								},
  1643  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  1644  									0: machine.NewCPUSet(1, 9),
  1645  								},
  1646  								Labels: map[string]string{
  1647  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  1648  								},
  1649  								Annotations: map[string]string{
  1650  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  1651  								},
  1652  								QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
  1653  								RequestQuantity: 2,
  1654  							},
  1655  						},
  1656  						"ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{
  1657  							testName: &AllocationInfo{
  1658  								PodUid:                   "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
  1659  								PodNamespace:             testName,
  1660  								PodName:                  testName,
  1661  								ContainerName:            testName,
  1662  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
  1663  								ContainerIndex:           0,
  1664  								RampUp:                   false,
  1665  								OwnerPoolName:            PoolNameShare,
  1666  								AllocationResult:         machine.NewCPUSet(1, 9),
  1667  								OriginalAllocationResult: machine.NewCPUSet(1, 9),
  1668  								TopologyAwareAssignments: map[int]machine.CPUSet{
  1669  									0: machine.NewCPUSet(1, 9),
  1670  								},
  1671  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  1672  									0: machine.NewCPUSet(1, 9),
  1673  								},
  1674  								Labels: map[string]string{
  1675  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  1676  								},
  1677  								Annotations: map[string]string{
  1678  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  1679  								},
  1680  								QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
  1681  								RequestQuantity: 2,
  1682  							},
  1683  						},
  1684  						"2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{
  1685  							testName: &AllocationInfo{
  1686  								PodUid:                   "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
  1687  								PodNamespace:             testName,
  1688  								PodName:                  testName,
  1689  								ContainerName:            testName,
  1690  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
  1691  								ContainerIndex:           0,
  1692  								RampUp:                   false,
  1693  								OwnerPoolName:            PoolNameReclaim,
  1694  								AllocationResult:         machine.MustParse("8"),
  1695  								OriginalAllocationResult: machine.MustParse("8"),
  1696  								TopologyAwareAssignments: map[int]machine.CPUSet{
  1697  									0: machine.NewCPUSet(8),
  1698  								},
  1699  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  1700  									0: machine.NewCPUSet(8),
  1701  								},
  1702  								Labels: map[string]string{
  1703  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
  1704  								},
  1705  								Annotations: map[string]string{
  1706  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
  1707  								},
  1708  								QoSLevel:        consts.PodAnnotationQoSLevelReclaimedCores,
  1709  								RequestQuantity: 2,
  1710  							},
  1711  						},
  1712  					},
  1713  				},
  1714  				1: &NUMANodeState{
  1715  					DefaultCPUSet:   cpuTopology.CPUDetails.CPUsInNUMANodes(1).Clone(),
  1716  					AllocatedCPUSet: machine.NewCPUSet(),
  1717  					PodEntries: PodEntries{
  1718  						"373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{
  1719  							testName: &AllocationInfo{
  1720  								PodUid:                   "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
  1721  								PodNamespace:             testName,
  1722  								PodName:                  testName,
  1723  								ContainerName:            testName,
  1724  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
  1725  								ContainerIndex:           0,
  1726  								RampUp:                   false,
  1727  								OwnerPoolName:            PoolNameShare,
  1728  								AllocationResult:         machine.MustParse("3,11"),
  1729  								OriginalAllocationResult: machine.MustParse("3,11"),
  1730  								TopologyAwareAssignments: map[int]machine.CPUSet{
  1731  									1: machine.NewCPUSet(3, 11),
  1732  								},
  1733  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  1734  									1: machine.NewCPUSet(3, 11),
  1735  								},
  1736  								Labels: map[string]string{
  1737  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  1738  								},
  1739  								Annotations: map[string]string{
  1740  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  1741  								},
  1742  								QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
  1743  								RequestQuantity: 2,
  1744  							},
  1745  						},
  1746  						"ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{
  1747  							testName: &AllocationInfo{
  1748  								PodUid:                   "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
  1749  								PodNamespace:             testName,
  1750  								PodName:                  testName,
  1751  								ContainerName:            testName,
  1752  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
  1753  								ContainerIndex:           0,
  1754  								RampUp:                   false,
  1755  								OwnerPoolName:            PoolNameShare,
  1756  								AllocationResult:         machine.MustParse("3,11"),
  1757  								OriginalAllocationResult: machine.MustParse("3,11"),
  1758  								TopologyAwareAssignments: map[int]machine.CPUSet{
  1759  									1: machine.NewCPUSet(3, 11),
  1760  								},
  1761  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  1762  									1: machine.NewCPUSet(3, 11),
  1763  								},
  1764  								Labels: map[string]string{
  1765  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  1766  								},
  1767  								Annotations: map[string]string{
  1768  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  1769  								},
  1770  								QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
  1771  								RequestQuantity: 2,
  1772  							},
  1773  						},
  1774  						"2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{
  1775  							testName: &AllocationInfo{
  1776  								PodUid:                   "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
  1777  								PodNamespace:             testName,
  1778  								PodName:                  testName,
  1779  								ContainerName:            testName,
  1780  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
  1781  								ContainerIndex:           0,
  1782  								RampUp:                   false,
  1783  								OwnerPoolName:            PoolNameReclaim,
  1784  								AllocationResult:         machine.MustParse("10"),
  1785  								OriginalAllocationResult: machine.MustParse("10"),
  1786  								TopologyAwareAssignments: map[int]machine.CPUSet{
  1787  									1: machine.NewCPUSet(10),
  1788  								},
  1789  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  1790  									1: machine.NewCPUSet(10),
  1791  								},
  1792  								Labels: map[string]string{
  1793  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
  1794  								},
  1795  								Annotations: map[string]string{
  1796  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
  1797  								},
  1798  								QoSLevel:        consts.PodAnnotationQoSLevelReclaimedCores,
  1799  								RequestQuantity: 2,
  1800  							},
  1801  						},
  1802  					},
  1803  				},
  1804  				2: &NUMANodeState{
  1805  					DefaultCPUSet:   cpuTopology.CPUDetails.CPUsInNUMANodes(2).Clone(),
  1806  					AllocatedCPUSet: machine.NewCPUSet(),
  1807  					PodEntries: PodEntries{
  1808  						"373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{
  1809  							testName: &AllocationInfo{
  1810  								PodUid:                   "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
  1811  								PodNamespace:             testName,
  1812  								PodName:                  testName,
  1813  								ContainerName:            testName,
  1814  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
  1815  								ContainerIndex:           0,
  1816  								RampUp:                   false,
  1817  								OwnerPoolName:            PoolNameShare,
  1818  								AllocationResult:         machine.MustParse("4,12"),
  1819  								OriginalAllocationResult: machine.MustParse("4,12"),
  1820  								TopologyAwareAssignments: map[int]machine.CPUSet{
  1821  									2: machine.NewCPUSet(4, 12),
  1822  								},
  1823  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  1824  									2: machine.NewCPUSet(4, 12),
  1825  								},
  1826  								Labels: map[string]string{
  1827  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  1828  								},
  1829  								Annotations: map[string]string{
  1830  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  1831  								},
  1832  								QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
  1833  								RequestQuantity: 2,
  1834  							},
  1835  						},
  1836  						"ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{
  1837  							testName: &AllocationInfo{
  1838  								PodUid:                   "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
  1839  								PodNamespace:             testName,
  1840  								PodName:                  testName,
  1841  								ContainerName:            testName,
  1842  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
  1843  								ContainerIndex:           0,
  1844  								RampUp:                   false,
  1845  								OwnerPoolName:            PoolNameShare,
  1846  								AllocationResult:         machine.MustParse("4,12"),
  1847  								OriginalAllocationResult: machine.MustParse("4,12"),
  1848  								TopologyAwareAssignments: map[int]machine.CPUSet{
  1849  									2: machine.NewCPUSet(4, 12),
  1850  								},
  1851  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  1852  									2: machine.NewCPUSet(4, 12),
  1853  								},
  1854  								Labels: map[string]string{
  1855  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  1856  								},
  1857  								Annotations: map[string]string{
  1858  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  1859  								},
  1860  								QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
  1861  								RequestQuantity: 2,
  1862  							},
  1863  						},
  1864  						"2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{
  1865  							testName: &AllocationInfo{
  1866  								PodUid:                   "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
  1867  								PodNamespace:             testName,
  1868  								PodName:                  testName,
  1869  								ContainerName:            testName,
  1870  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
  1871  								ContainerIndex:           0,
  1872  								RampUp:                   false,
  1873  								OwnerPoolName:            PoolNameReclaim,
  1874  								AllocationResult:         machine.MustParse("5,13"),
  1875  								OriginalAllocationResult: machine.MustParse("5,13"),
  1876  								TopologyAwareAssignments: map[int]machine.CPUSet{
  1877  									2: machine.NewCPUSet(5, 13),
  1878  								},
  1879  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  1880  									2: machine.NewCPUSet(5, 13),
  1881  								},
  1882  								Labels: map[string]string{
  1883  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
  1884  								},
  1885  								Annotations: map[string]string{
  1886  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
  1887  								},
  1888  								QoSLevel:        consts.PodAnnotationQoSLevelReclaimedCores,
  1889  								RequestQuantity: 2,
  1890  							},
  1891  						},
  1892  					},
  1893  				},
  1894  				3: &NUMANodeState{
  1895  					DefaultCPUSet:   cpuTopology.CPUDetails.CPUsInNUMANodes(3).Clone(),
  1896  					AllocatedCPUSet: machine.NewCPUSet(),
  1897  					PodEntries: PodEntries{
  1898  						"2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{
  1899  							testName: &AllocationInfo{
  1900  								PodUid:                   "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
  1901  								PodNamespace:             testName,
  1902  								PodName:                  testName,
  1903  								ContainerName:            testName,
  1904  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
  1905  								ContainerIndex:           0,
  1906  								RampUp:                   false,
  1907  								OwnerPoolName:            PoolNameReclaim,
  1908  								AllocationResult:         machine.MustParse("6,7,14,15"),
  1909  								OriginalAllocationResult: machine.MustParse("6,7,14,15"),
  1910  								TopologyAwareAssignments: map[int]machine.CPUSet{
  1911  									3: machine.NewCPUSet(6, 7, 14, 15),
  1912  								},
  1913  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  1914  									3: machine.NewCPUSet(6, 7, 14, 15),
  1915  								},
  1916  								Labels: map[string]string{
  1917  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
  1918  								},
  1919  								Annotations: map[string]string{
  1920  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
  1921  								},
  1922  								QoSLevel:        consts.PodAnnotationQoSLevelReclaimedCores,
  1923  								RequestQuantity: 2,
  1924  							},
  1925  						},
  1926  					},
  1927  				},
  1928  			},
  1929  		},
  1930  	}
  1931  
  1932  	for i, tc := range testCases {
  1933  		i, tc := i, tc
  1934  		t.Run(tc.description, func(t *testing.T) {
  1935  			t.Parallel()
  1936  
  1937  			// create temp dir
  1938  			testingDir, err := ioutil.TempDir("", fmt.Sprintf("dynamic_policy_state_test_%d", i))
  1939  			if err != nil {
  1940  				t.Fatal(err)
  1941  			}
  1942  			defer os.RemoveAll(testingDir)
  1943  
  1944  			state1, err := NewCheckpointState(testingDir, cpuPluginStateFileName, policyName, tc.cpuTopology, false)
  1945  			as.Nil(err)
  1946  
  1947  			state1.ClearState()
  1948  
  1949  			state1.SetMachineState(tc.machineState)
  1950  			state1.SetPodEntries(tc.podEntries)
  1951  
  1952  			state2, err := NewCheckpointState(testingDir, cpuPluginStateFileName, policyName, tc.cpuTopology, false)
  1953  			as.Nil(err)
  1954  			assertStateEqual(t, state2, state1)
  1955  		})
  1956  	}
  1957  }
  1958  
  1959  func TestCheckpointStateHelpers(t *testing.T) {
  1960  	t.Parallel()
  1961  
  1962  	as := require.New(t)
  1963  
  1964  	testName := "test"
  1965  
  1966  	cpuTopology, err := machine.GenerateDummyCPUTopology(16, 2, 4)
  1967  	as.Nil(err)
  1968  
  1969  	testCases := []struct {
  1970  		description  string
  1971  		cpuTopology  *machine.CPUTopology
  1972  		podEntries   PodEntries
  1973  		machineState NUMANodeMap
  1974  	}{
  1975  		{
  1976  			description: "valid state cleaning",
  1977  			cpuTopology: cpuTopology,
  1978  			podEntries: PodEntries{
  1979  				"373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{
  1980  					testName: &AllocationInfo{
  1981  						PodUid:                   "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
  1982  						PodNamespace:             testName,
  1983  						PodName:                  testName,
  1984  						ContainerName:            testName,
  1985  						ContainerType:            pluginapi.ContainerType_MAIN.String(),
  1986  						ContainerIndex:           0,
  1987  						RampUp:                   false,
  1988  						OwnerPoolName:            PoolNameShare,
  1989  						AllocationResult:         machine.MustParse("1,3-4,9,11-12"),
  1990  						OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"),
  1991  						TopologyAwareAssignments: map[int]machine.CPUSet{
  1992  							0: machine.NewCPUSet(1, 9),
  1993  							1: machine.NewCPUSet(3, 11),
  1994  							2: machine.NewCPUSet(4, 12),
  1995  						},
  1996  						OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  1997  							0: machine.NewCPUSet(1, 9),
  1998  							1: machine.NewCPUSet(3, 11),
  1999  							2: machine.NewCPUSet(4, 12),
  2000  						},
  2001  						Labels: map[string]string{
  2002  							consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  2003  						},
  2004  						Annotations: map[string]string{
  2005  							consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  2006  						},
  2007  						QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
  2008  						RequestQuantity: 2,
  2009  					},
  2010  				},
  2011  				"ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{
  2012  					testName: &AllocationInfo{
  2013  						PodUid:                   "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
  2014  						PodNamespace:             testName,
  2015  						PodName:                  testName,
  2016  						ContainerName:            testName,
  2017  						ContainerType:            pluginapi.ContainerType_MAIN.String(),
  2018  						ContainerIndex:           0,
  2019  						RampUp:                   false,
  2020  						OwnerPoolName:            PoolNameShare,
  2021  						AllocationResult:         machine.MustParse("1,3-4,9,11-12"),
  2022  						OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"),
  2023  						TopologyAwareAssignments: map[int]machine.CPUSet{
  2024  							0: machine.NewCPUSet(1, 9),
  2025  							1: machine.NewCPUSet(3, 11),
  2026  							2: machine.NewCPUSet(4, 12),
  2027  						},
  2028  						OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  2029  							0: machine.NewCPUSet(1, 9),
  2030  							1: machine.NewCPUSet(3, 11),
  2031  							2: machine.NewCPUSet(4, 12),
  2032  						},
  2033  						Labels: map[string]string{
  2034  							consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  2035  						},
  2036  						Annotations: map[string]string{
  2037  							consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  2038  						},
  2039  						QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
  2040  						RequestQuantity: 2,
  2041  					},
  2042  				},
  2043  				"2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{
  2044  					testName: &AllocationInfo{
  2045  						PodUid:                   "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
  2046  						PodNamespace:             testName,
  2047  						PodName:                  testName,
  2048  						ContainerName:            testName,
  2049  						ContainerType:            pluginapi.ContainerType_MAIN.String(),
  2050  						ContainerIndex:           0,
  2051  						RampUp:                   false,
  2052  						OwnerPoolName:            PoolNameReclaim,
  2053  						AllocationResult:         machine.MustParse("5-8,10,13-15"),
  2054  						OriginalAllocationResult: machine.MustParse("5-8,10,13-15"),
  2055  						TopologyAwareAssignments: map[int]machine.CPUSet{
  2056  							0: machine.NewCPUSet(8),
  2057  							1: machine.NewCPUSet(10),
  2058  							2: machine.NewCPUSet(5, 13),
  2059  							3: machine.NewCPUSet(6, 7, 14, 15),
  2060  						},
  2061  						OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  2062  							0: machine.NewCPUSet(8),
  2063  							1: machine.NewCPUSet(10),
  2064  							2: machine.NewCPUSet(5, 13),
  2065  							3: machine.NewCPUSet(6, 7, 14, 15),
  2066  						},
  2067  						Labels: map[string]string{
  2068  							consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
  2069  						},
  2070  						Annotations: map[string]string{
  2071  							consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
  2072  						},
  2073  						QoSLevel:        consts.PodAnnotationQoSLevelReclaimedCores,
  2074  						RequestQuantity: 2,
  2075  					},
  2076  				},
  2077  				PoolNameReclaim: ContainerEntries{
  2078  					"": &AllocationInfo{
  2079  						PodUid:                   PoolNameReclaim,
  2080  						OwnerPoolName:            PoolNameReclaim,
  2081  						AllocationResult:         machine.MustParse("5-8,10,13-15"),
  2082  						OriginalAllocationResult: machine.MustParse("5-8,10,13-15"),
  2083  						TopologyAwareAssignments: map[int]machine.CPUSet{
  2084  							0: machine.NewCPUSet(8),
  2085  							1: machine.NewCPUSet(10),
  2086  							2: machine.NewCPUSet(5, 13),
  2087  							3: machine.NewCPUSet(6, 7, 14, 15),
  2088  						},
  2089  						OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  2090  							0: machine.NewCPUSet(8),
  2091  							1: machine.NewCPUSet(10),
  2092  							2: machine.NewCPUSet(5, 13),
  2093  							3: machine.NewCPUSet(6, 7, 14, 15),
  2094  						},
  2095  					},
  2096  				},
  2097  				PoolNameShare: ContainerEntries{
  2098  					"": &AllocationInfo{
  2099  						PodUid:                   PoolNameShare,
  2100  						OwnerPoolName:            PoolNameShare,
  2101  						AllocationResult:         machine.MustParse("1,3-4,9,11-12"),
  2102  						OriginalAllocationResult: machine.MustParse("1,3-4,9,11-12"),
  2103  						TopologyAwareAssignments: map[int]machine.CPUSet{
  2104  							0: machine.NewCPUSet(1, 9),
  2105  							1: machine.NewCPUSet(3, 11),
  2106  							2: machine.NewCPUSet(4, 12),
  2107  						},
  2108  						OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  2109  							0: machine.NewCPUSet(1, 9),
  2110  							1: machine.NewCPUSet(3, 11),
  2111  							2: machine.NewCPUSet(4, 12),
  2112  						},
  2113  					},
  2114  				},
  2115  			},
  2116  			machineState: NUMANodeMap{
  2117  				0: &NUMANodeState{
  2118  					DefaultCPUSet:   cpuTopology.CPUDetails.CPUsInNUMANodes(0).Clone(),
  2119  					AllocatedCPUSet: machine.NewCPUSet(),
  2120  					PodEntries: PodEntries{
  2121  						"373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{
  2122  							testName: &AllocationInfo{
  2123  								PodUid:                   "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
  2124  								PodNamespace:             testName,
  2125  								PodName:                  testName,
  2126  								ContainerName:            testName,
  2127  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
  2128  								ContainerIndex:           0,
  2129  								RampUp:                   false,
  2130  								OwnerPoolName:            PoolNameShare,
  2131  								AllocationResult:         machine.NewCPUSet(1, 9),
  2132  								OriginalAllocationResult: machine.NewCPUSet(1, 9),
  2133  								TopologyAwareAssignments: map[int]machine.CPUSet{
  2134  									0: machine.NewCPUSet(1, 9),
  2135  								},
  2136  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  2137  									0: machine.NewCPUSet(1, 9),
  2138  								},
  2139  								Labels: map[string]string{
  2140  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  2141  								},
  2142  								Annotations: map[string]string{
  2143  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  2144  								},
  2145  								QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
  2146  								RequestQuantity: 2,
  2147  							},
  2148  						},
  2149  						"ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{
  2150  							testName: &AllocationInfo{
  2151  								PodUid:                   "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
  2152  								PodNamespace:             testName,
  2153  								PodName:                  testName,
  2154  								ContainerName:            testName,
  2155  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
  2156  								ContainerIndex:           0,
  2157  								RampUp:                   false,
  2158  								OwnerPoolName:            PoolNameShare,
  2159  								AllocationResult:         machine.NewCPUSet(1, 9),
  2160  								OriginalAllocationResult: machine.NewCPUSet(1, 9),
  2161  								TopologyAwareAssignments: map[int]machine.CPUSet{
  2162  									0: machine.NewCPUSet(1, 9),
  2163  								},
  2164  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  2165  									0: machine.NewCPUSet(1, 9),
  2166  								},
  2167  								Labels: map[string]string{
  2168  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  2169  								},
  2170  								Annotations: map[string]string{
  2171  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  2172  								},
  2173  								QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
  2174  								RequestQuantity: 2,
  2175  							},
  2176  						},
  2177  						"2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{
  2178  							testName: &AllocationInfo{
  2179  								PodUid:                   "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
  2180  								PodNamespace:             testName,
  2181  								PodName:                  testName,
  2182  								ContainerName:            testName,
  2183  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
  2184  								ContainerIndex:           0,
  2185  								RampUp:                   false,
  2186  								OwnerPoolName:            PoolNameReclaim,
  2187  								AllocationResult:         machine.MustParse("8"),
  2188  								OriginalAllocationResult: machine.MustParse("8"),
  2189  								TopologyAwareAssignments: map[int]machine.CPUSet{
  2190  									0: machine.NewCPUSet(8),
  2191  								},
  2192  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  2193  									0: machine.NewCPUSet(8),
  2194  								},
  2195  								Labels: map[string]string{
  2196  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
  2197  								},
  2198  								Annotations: map[string]string{
  2199  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
  2200  								},
  2201  								QoSLevel:        consts.PodAnnotationQoSLevelReclaimedCores,
  2202  								RequestQuantity: 2,
  2203  							},
  2204  						},
  2205  					},
  2206  				},
  2207  				1: &NUMANodeState{
  2208  					DefaultCPUSet:   cpuTopology.CPUDetails.CPUsInNUMANodes(1).Clone(),
  2209  					AllocatedCPUSet: machine.NewCPUSet(),
  2210  					PodEntries: PodEntries{
  2211  						"373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{
  2212  							testName: &AllocationInfo{
  2213  								PodUid:                   "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
  2214  								PodNamespace:             testName,
  2215  								PodName:                  testName,
  2216  								ContainerName:            testName,
  2217  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
  2218  								ContainerIndex:           0,
  2219  								RampUp:                   false,
  2220  								OwnerPoolName:            PoolNameShare,
  2221  								AllocationResult:         machine.MustParse("3,11"),
  2222  								OriginalAllocationResult: machine.MustParse("3,11"),
  2223  								TopologyAwareAssignments: map[int]machine.CPUSet{
  2224  									1: machine.NewCPUSet(3, 11),
  2225  								},
  2226  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  2227  									1: machine.NewCPUSet(3, 11),
  2228  								},
  2229  								Labels: map[string]string{
  2230  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  2231  								},
  2232  								Annotations: map[string]string{
  2233  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  2234  								},
  2235  								QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
  2236  								RequestQuantity: 2,
  2237  							},
  2238  						},
  2239  						"ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{
  2240  							testName: &AllocationInfo{
  2241  								PodUid:                   "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
  2242  								PodNamespace:             testName,
  2243  								PodName:                  testName,
  2244  								ContainerName:            testName,
  2245  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
  2246  								ContainerIndex:           0,
  2247  								RampUp:                   false,
  2248  								OwnerPoolName:            PoolNameShare,
  2249  								AllocationResult:         machine.MustParse("3,11"),
  2250  								OriginalAllocationResult: machine.MustParse("3,11"),
  2251  								TopologyAwareAssignments: map[int]machine.CPUSet{
  2252  									1: machine.NewCPUSet(3, 11),
  2253  								},
  2254  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  2255  									1: machine.NewCPUSet(3, 11),
  2256  								},
  2257  								Labels: map[string]string{
  2258  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  2259  								},
  2260  								Annotations: map[string]string{
  2261  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  2262  								},
  2263  								QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
  2264  								RequestQuantity: 2,
  2265  							},
  2266  						},
  2267  						"2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{
  2268  							testName: &AllocationInfo{
  2269  								PodUid:                   "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
  2270  								PodNamespace:             testName,
  2271  								PodName:                  testName,
  2272  								ContainerName:            testName,
  2273  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
  2274  								ContainerIndex:           0,
  2275  								RampUp:                   false,
  2276  								OwnerPoolName:            PoolNameReclaim,
  2277  								AllocationResult:         machine.MustParse("10"),
  2278  								OriginalAllocationResult: machine.MustParse("10"),
  2279  								TopologyAwareAssignments: map[int]machine.CPUSet{
  2280  									1: machine.NewCPUSet(10),
  2281  								},
  2282  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  2283  									1: machine.NewCPUSet(10),
  2284  								},
  2285  								Labels: map[string]string{
  2286  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
  2287  								},
  2288  								Annotations: map[string]string{
  2289  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
  2290  								},
  2291  								QoSLevel:        consts.PodAnnotationQoSLevelReclaimedCores,
  2292  								RequestQuantity: 2,
  2293  							},
  2294  						},
  2295  					},
  2296  				},
  2297  				2: &NUMANodeState{
  2298  					DefaultCPUSet:   cpuTopology.CPUDetails.CPUsInNUMANodes(2).Clone(),
  2299  					AllocatedCPUSet: machine.NewCPUSet(),
  2300  					PodEntries: PodEntries{
  2301  						"373d08e4-7a6b-4293-aaaf-b135ff8123bf": ContainerEntries{
  2302  							testName: &AllocationInfo{
  2303  								PodUid:                   "373d08e4-7a6b-4293-aaaf-b135ff8123bf",
  2304  								PodNamespace:             testName,
  2305  								PodName:                  testName,
  2306  								ContainerName:            testName,
  2307  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
  2308  								ContainerIndex:           0,
  2309  								RampUp:                   false,
  2310  								OwnerPoolName:            PoolNameShare,
  2311  								AllocationResult:         machine.MustParse("4,12"),
  2312  								OriginalAllocationResult: machine.MustParse("4,12"),
  2313  								TopologyAwareAssignments: map[int]machine.CPUSet{
  2314  									2: machine.NewCPUSet(4, 12),
  2315  								},
  2316  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  2317  									2: machine.NewCPUSet(4, 12),
  2318  								},
  2319  								Labels: map[string]string{
  2320  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  2321  								},
  2322  								Annotations: map[string]string{
  2323  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  2324  								},
  2325  								QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
  2326  								RequestQuantity: 2,
  2327  							},
  2328  						},
  2329  						"ec6e2f30-c78a-4bc4-9576-c916db5281a3": ContainerEntries{
  2330  							testName: &AllocationInfo{
  2331  								PodUid:                   "ec6e2f30-c78a-4bc4-9576-c916db5281a3",
  2332  								PodNamespace:             testName,
  2333  								PodName:                  testName,
  2334  								ContainerName:            testName,
  2335  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
  2336  								ContainerIndex:           0,
  2337  								RampUp:                   false,
  2338  								OwnerPoolName:            PoolNameShare,
  2339  								AllocationResult:         machine.MustParse("4,12"),
  2340  								OriginalAllocationResult: machine.MustParse("4,12"),
  2341  								TopologyAwareAssignments: map[int]machine.CPUSet{
  2342  									2: machine.NewCPUSet(4, 12),
  2343  								},
  2344  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  2345  									2: machine.NewCPUSet(4, 12),
  2346  								},
  2347  								Labels: map[string]string{
  2348  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  2349  								},
  2350  								Annotations: map[string]string{
  2351  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
  2352  								},
  2353  								QoSLevel:        consts.PodAnnotationQoSLevelSharedCores,
  2354  								RequestQuantity: 2,
  2355  							},
  2356  						},
  2357  						"2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{
  2358  							testName: &AllocationInfo{
  2359  								PodUid:                   "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
  2360  								PodNamespace:             testName,
  2361  								PodName:                  testName,
  2362  								ContainerName:            testName,
  2363  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
  2364  								ContainerIndex:           0,
  2365  								RampUp:                   false,
  2366  								OwnerPoolName:            PoolNameReclaim,
  2367  								AllocationResult:         machine.MustParse("5,13"),
  2368  								OriginalAllocationResult: machine.MustParse("5,13"),
  2369  								TopologyAwareAssignments: map[int]machine.CPUSet{
  2370  									2: machine.NewCPUSet(5, 13),
  2371  								},
  2372  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  2373  									2: machine.NewCPUSet(5, 13),
  2374  								},
  2375  								Labels: map[string]string{
  2376  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
  2377  								},
  2378  								Annotations: map[string]string{
  2379  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
  2380  								},
  2381  								QoSLevel:        consts.PodAnnotationQoSLevelReclaimedCores,
  2382  								RequestQuantity: 2,
  2383  							},
  2384  						},
  2385  					},
  2386  				},
  2387  				3: &NUMANodeState{
  2388  					DefaultCPUSet:   cpuTopology.CPUDetails.CPUsInNUMANodes(3).Clone(),
  2389  					AllocatedCPUSet: machine.NewCPUSet(),
  2390  					PodEntries: PodEntries{
  2391  						"2432d068-c5a0-46ba-a7bd-b69d9bd16961": ContainerEntries{
  2392  							testName: &AllocationInfo{
  2393  								PodUid:                   "2432d068-c5a0-46ba-a7bd-b69d9bd16961",
  2394  								PodNamespace:             testName,
  2395  								PodName:                  testName,
  2396  								ContainerName:            testName,
  2397  								ContainerType:            pluginapi.ContainerType_MAIN.String(),
  2398  								ContainerIndex:           0,
  2399  								RampUp:                   false,
  2400  								OwnerPoolName:            PoolNameReclaim,
  2401  								AllocationResult:         machine.MustParse("6,7,14,15"),
  2402  								OriginalAllocationResult: machine.MustParse("6,7,14,15"),
  2403  								TopologyAwareAssignments: map[int]machine.CPUSet{
  2404  									3: machine.NewCPUSet(6, 7, 14, 15),
  2405  								},
  2406  								OriginalTopologyAwareAssignments: map[int]machine.CPUSet{
  2407  									3: machine.NewCPUSet(6, 7, 14, 15),
  2408  								},
  2409  								Labels: map[string]string{
  2410  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
  2411  								},
  2412  								Annotations: map[string]string{
  2413  									consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
  2414  								},
  2415  								QoSLevel:        consts.PodAnnotationQoSLevelReclaimedCores,
  2416  								RequestQuantity: 2,
  2417  							},
  2418  						},
  2419  					},
  2420  				},
  2421  			},
  2422  		},
  2423  	}
  2424  
  2425  	// create temp dir
  2426  	testingDir, err := ioutil.TempDir("", "dynamic_policy_state_test")
  2427  	if err != nil {
  2428  		t.Fatal(err)
  2429  	}
  2430  	defer os.RemoveAll(testingDir)
  2431  
  2432  	for _, tc := range testCases {
  2433  		tc := tc
  2434  		t.Run(tc.description, func(t *testing.T) {
  2435  			t.Parallel()
  2436  
  2437  			state, err := NewCheckpointState(testingDir, cpuPluginStateFileName, policyName, tc.cpuTopology, false)
  2438  			as.Nil(err)
  2439  
  2440  			state.ClearState()
  2441  
  2442  			state.SetMachineState(tc.machineState)
  2443  			as.Equalf(tc.machineState, state.GetMachineState(), "failed in test case: %s", tc.description)
  2444  
  2445  			state.SetPodEntries(tc.podEntries)
  2446  			as.Equalf(tc.podEntries, state.GetPodEntries(), "failed in test case: %s", tc.description)
  2447  
  2448  			state.ClearState()
  2449  
  2450  			as.NotEqualf(tc.podEntries, state.GetPodEntries(), "failed in test case: %s", tc.description)
  2451  			for podUID, containerEntries := range tc.podEntries {
  2452  				for containerName, allocationInfo := range containerEntries {
  2453  					state.SetAllocationInfo(podUID, containerName, allocationInfo)
  2454  				}
  2455  			}
  2456  			as.Equalf(tc.podEntries, state.GetPodEntries(), "failed in test case: %s", tc.description)
  2457  		})
  2458  	}
  2459  }
  2460  
  2461  func TestGetDefaultMachineState(t *testing.T) {
  2462  	t.Parallel()
  2463  
  2464  	as := require.New(t)
  2465  
  2466  	cpuTopology, err := machine.GenerateDummyCPUTopology(16, 2, 4)
  2467  	as.Nil(err)
  2468  
  2469  	testCases := []struct {
  2470  		description          string
  2471  		cpuTopology          *machine.CPUTopology
  2472  		expectedMachineState NUMANodeMap
  2473  	}{
  2474  		{
  2475  			description: "nil cpuTopology",
  2476  		},
  2477  		{
  2478  			description: "non-nil cpuTopology",
  2479  			cpuTopology: cpuTopology,
  2480  			expectedMachineState: NUMANodeMap{
  2481  				0: &NUMANodeState{
  2482  					DefaultCPUSet:   machine.NewCPUSet(0, 1, 8, 9),
  2483  					AllocatedCPUSet: machine.NewCPUSet(),
  2484  					PodEntries:      make(PodEntries),
  2485  				},
  2486  				1: &NUMANodeState{
  2487  					DefaultCPUSet:   machine.NewCPUSet(2, 3, 10, 11),
  2488  					AllocatedCPUSet: machine.NewCPUSet(),
  2489  					PodEntries:      make(PodEntries),
  2490  				},
  2491  				2: &NUMANodeState{
  2492  					DefaultCPUSet:   machine.NewCPUSet(4, 5, 12, 13),
  2493  					AllocatedCPUSet: machine.NewCPUSet(),
  2494  					PodEntries:      make(PodEntries),
  2495  				},
  2496  				3: &NUMANodeState{
  2497  					DefaultCPUSet:   machine.NewCPUSet(6, 7, 14, 15),
  2498  					AllocatedCPUSet: machine.NewCPUSet(),
  2499  					PodEntries:      make(PodEntries),
  2500  				},
  2501  			},
  2502  		},
  2503  	}
  2504  
  2505  	for _, tc := range testCases {
  2506  		actualMachineState := GetDefaultMachineState(tc.cpuTopology)
  2507  		as.Equalf(actualMachineState, tc.expectedMachineState, "failed in test case: %s", tc.description)
  2508  	}
  2509  }
  2510  
  2511  func TestGetSocketTopology(t *testing.T) {
  2512  	t.Parallel()
  2513  
  2514  	as := require.New(t)
  2515  
  2516  	cpuTopology, err := machine.GenerateDummyCPUTopology(16, 2, 4)
  2517  	as.Nil(err)
  2518  
  2519  	testCases := []struct {
  2520  		description            string
  2521  		cpuTopology            *machine.CPUTopology
  2522  		expectedSocketTopology map[int]string
  2523  	}{
  2524  		{
  2525  			description: "nil cpuTopology",
  2526  		},
  2527  		{
  2528  			description: "non-nil cpuTopology",
  2529  			cpuTopology: cpuTopology,
  2530  			expectedSocketTopology: map[int]string{
  2531  				0: "0-1",
  2532  				1: "2-3",
  2533  			},
  2534  		},
  2535  	}
  2536  
  2537  	for _, tc := range testCases {
  2538  		actualSocketToplogy := tc.cpuTopology.GetSocketTopology()
  2539  		as.Equalf(tc.expectedSocketTopology, actualSocketToplogy, "failed in test case: %s", tc.description)
  2540  	}
  2541  }