From 59555c6a62f407cd5834e7a44a20ae4a38a9d258 Mon Sep 17 00:00:00 2001 From: Ed Bartosh Date: Tue, 23 Jul 2024 23:01:51 +0300 Subject: [PATCH] DRA: move dra/checkpont/* to dra/state/* --- pkg/kubelet/cm/dra/claiminfo.go | 7 ++- .../dra/{checkpoint => state}/checkpoint.go | 12 ++--- .../dra/{checkpoint => state}/checkpointer.go | 3 +- .../checkpointer_test.go | 51 +++++++++---------- .../cm/dra/state/{types.go => state.go} | 6 --- 5 files changed, 34 insertions(+), 45 deletions(-) rename pkg/kubelet/cm/dra/{checkpoint => state}/checkpoint.go (87%) rename pkg/kubelet/cm/dra/{checkpoint => state}/checkpointer.go (97%) rename pkg/kubelet/cm/dra/{checkpoint => state}/checkpointer_test.go (92%) rename pkg/kubelet/cm/dra/state/{types.go => state.go} (93%) diff --git a/pkg/kubelet/cm/dra/claiminfo.go b/pkg/kubelet/cm/dra/claiminfo.go index 7f07b771c60..73c437b9ade 100644 --- a/pkg/kubelet/cm/dra/claiminfo.go +++ b/pkg/kubelet/cm/dra/claiminfo.go @@ -25,7 +25,6 @@ import ( resourceapi "k8s.io/api/resource/v1alpha3" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/kubernetes/pkg/kubelet/cm/dra/checkpoint" state "k8s.io/kubernetes/pkg/kubelet/cm/dra/state" kubecontainer "k8s.io/kubernetes/pkg/kubelet/container" ) @@ -41,7 +40,7 @@ type ClaimInfo struct { // claimInfoCache is a cache of processed resource claims keyed by namespace/claimname. type claimInfoCache struct { sync.RWMutex - state checkpoint.Checkpointer + state state.Checkpointer claimInfo map[string]*ClaimInfo } @@ -114,7 +113,7 @@ func (info *ClaimInfo) isPrepared() bool { // newClaimInfoCache creates a new claim info cache object, pre-populated from a checkpoint (if present). func newClaimInfoCache(stateDir, checkpointName string) (*claimInfoCache, error) { - checkpointer, err := checkpoint.NewCheckpointer(stateDir, checkpointName) + checkpointer, err := state.NewCheckpointer(stateDir, checkpointName) if err != nil { return nil, fmt.Errorf("could not initialize checkpoint manager, please drain node and remove dra state file, err: %+v", err) } @@ -198,7 +197,7 @@ func (cache *claimInfoCache) syncToCheckpoint() error { for _, infoClaim := range cache.claimInfo { claimInfoStateList = append(claimInfoStateList, infoClaim.ClaimInfoState) } - checkpoint, err := checkpoint.NewCheckpoint(claimInfoStateList) + checkpoint, err := state.NewCheckpoint(claimInfoStateList) if err != nil { return err } diff --git a/pkg/kubelet/cm/dra/checkpoint/checkpoint.go b/pkg/kubelet/cm/dra/state/checkpoint.go similarity index 87% rename from pkg/kubelet/cm/dra/checkpoint/checkpoint.go rename to pkg/kubelet/cm/dra/state/checkpoint.go index 3901caa08b8..c3976ff638c 100644 --- a/pkg/kubelet/cm/dra/checkpoint/checkpoint.go +++ b/pkg/kubelet/cm/dra/state/checkpoint.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package checkpoint +package state import ( "encoding/json" @@ -22,19 +22,17 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/kubernetes/pkg/kubelet/checkpointmanager/errors" - state "k8s.io/kubernetes/pkg/kubelet/cm/dra/state" ) const ( CheckpointAPIGroup = "checkpoint.dra.kubelet.k8s.io" CheckpointKind = "DRACheckpoint" - CheckpointAPIVersion = CheckpointAPIGroup + "/" + state.Version + CheckpointAPIVersion = CheckpointAPIGroup + "/" + Version ) // Checkpoint represents a structure to store DRA checkpoint data type Checkpoint struct { // Data is a JSON serialized checkpoint data - // See state.CheckpointData for the details Data string // Checksum is a checksum of Data Checksum uint32 @@ -42,11 +40,11 @@ type Checkpoint struct { type CheckpointData struct { metav1.TypeMeta - Entries state.ClaimInfoStateList + Entries ClaimInfoStateList } // NewCheckpoint creates a new checkpoint from a list of claim info states -func NewCheckpoint(data state.ClaimInfoStateList) (*Checkpoint, error) { +func NewCheckpoint(data ClaimInfoStateList) (*Checkpoint, error) { cpData := &CheckpointData{ TypeMeta: metav1.TypeMeta{ Kind: CheckpointKind, @@ -97,7 +95,7 @@ func (cp *Checkpoint) VerifyChecksum() error { } // GetEntries returns list of claim info states from checkpoint -func (cp *Checkpoint) GetEntries() (state.ClaimInfoStateList, error) { +func (cp *Checkpoint) GetEntries() (ClaimInfoStateList, error) { var cpData CheckpointData if err := json.Unmarshal([]byte(cp.Data), &cpData); err != nil { return nil, err diff --git a/pkg/kubelet/cm/dra/checkpoint/checkpointer.go b/pkg/kubelet/cm/dra/state/checkpointer.go similarity index 97% rename from pkg/kubelet/cm/dra/checkpoint/checkpointer.go rename to pkg/kubelet/cm/dra/state/checkpointer.go index 205430f5f39..bc1dc3fe54d 100644 --- a/pkg/kubelet/cm/dra/checkpoint/checkpointer.go +++ b/pkg/kubelet/cm/dra/state/checkpointer.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package checkpoint +package state import ( "errors" @@ -23,7 +23,6 @@ import ( "k8s.io/kubernetes/pkg/kubelet/checkpointmanager" checkpointerrors "k8s.io/kubernetes/pkg/kubelet/checkpointmanager/errors" - state "k8s.io/kubernetes/pkg/kubelet/cm/dra/state" ) type Checkpointer interface { diff --git a/pkg/kubelet/cm/dra/checkpoint/checkpointer_test.go b/pkg/kubelet/cm/dra/state/checkpointer_test.go similarity index 92% rename from pkg/kubelet/cm/dra/checkpoint/checkpointer_test.go rename to pkg/kubelet/cm/dra/state/checkpointer_test.go index b92df22baba..b3e4ae00816 100644 --- a/pkg/kubelet/cm/dra/checkpoint/checkpointer_test.go +++ b/pkg/kubelet/cm/dra/state/checkpointer_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package checkpoint +package state import ( "os" @@ -27,7 +27,6 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/kubernetes/pkg/kubelet/checkpointmanager" testutil "k8s.io/kubernetes/pkg/kubelet/cm/cpumanager/state/testing" - state "k8s.io/kubernetes/pkg/kubelet/cm/dra/state" ) const testingCheckpoint = "dramanager_checkpoint_test" @@ -39,7 +38,7 @@ func TestCheckpointGetOrCreate(t *testing.T) { description string checkpointContent string expectedError string - expectedClaimInfoStateList state.ClaimInfoStateList + expectedClaimInfoStateList ClaimInfoStateList }{ { description: "new-checkpoint", @@ -48,11 +47,11 @@ func TestCheckpointGetOrCreate(t *testing.T) { { description: "single-claim-info-state", checkpointContent: `{"Data":"{\"kind\":\"DRACheckpoint\",\"apiVersion\":\"checkpoint.dra.kubelet.k8s.io/v1\",\"Entries\":[{\"ClaimUID\":\"067798be-454e-4be4-9047-1aa06aea63f7\",\"ClaimName\":\"example\",\"Namespace\":\"default\",\"PodUIDs\":{\"139cdb46-f989-4f17-9561-ca10cfb509a6\":{}},\"DriverState\":{\"test-driver.cdi.k8s.io\":{\"Devices\":[{\"PoolName\":\"worker-1\",\"DeviceName\":\"dev-1\",\"RequestNames\":[\"test request\"],\"CDIDeviceIDs\":[\"example.com/example=cdi-example\"]}]}}}]}","Checksum":1597924435}`, - expectedClaimInfoStateList: state.ClaimInfoStateList{ + expectedClaimInfoStateList: ClaimInfoStateList{ { - DriverState: map[string]state.DriverState{ + DriverState: map[string]DriverState{ "test-driver.cdi.k8s.io": { - Devices: []state.Device{ + Devices: []Device{ { PoolName: "worker-1", DeviceName: "dev-1", @@ -72,11 +71,11 @@ func TestCheckpointGetOrCreate(t *testing.T) { { description: "claim-info-state-with-multiple-devices", checkpointContent: `{"Data":"{\"kind\":\"DRACheckpoint\",\"apiVersion\":\"checkpoint.dra.kubelet.k8s.io/v1\",\"Entries\":[{\"ClaimUID\":\"067798be-454e-4be4-9047-1aa06aea63f7\",\"ClaimName\":\"example\",\"Namespace\":\"default\",\"PodUIDs\":{\"139cdb46-f989-4f17-9561-ca10cfb509a6\":{}},\"DriverState\":{\"test-driver.cdi.k8s.io\":{\"Devices\":[{\"PoolName\":\"worker-1\",\"DeviceName\":\"dev-1\",\"RequestNames\":[\"test request\"],\"CDIDeviceIDs\":[\"example.com/example=cdi-example\"]},{\"PoolName\":\"worker-1\",\"DeviceName\":\"dev-2\",\"RequestNames\":[\"test request\"],\"CDIDeviceIDs\":[\"example.com/example=cdi-example\"]}]}}}]}","Checksum":1812303514}`, - expectedClaimInfoStateList: state.ClaimInfoStateList{ + expectedClaimInfoStateList: ClaimInfoStateList{ { - DriverState: map[string]state.DriverState{ + DriverState: map[string]DriverState{ "test-driver.cdi.k8s.io": { - Devices: []state.Device{ + Devices: []Device{ { PoolName: "worker-1", DeviceName: "dev-1", @@ -102,11 +101,11 @@ func TestCheckpointGetOrCreate(t *testing.T) { { description: "two-claim-info-states", checkpointContent: `{"Data":"{\"kind\":\"DRACheckpoint\",\"apiVersion\":\"checkpoint.dra.kubelet.k8s.io/v1\",\"Entries\":[{\"ClaimUID\":\"067798be-454e-4be4-9047-1aa06aea63f7\",\"ClaimName\":\"example-1\",\"Namespace\":\"default\",\"PodUIDs\":{\"139cdb46-f989-4f17-9561-ca10cfb509a6\":{}},\"DriverState\":{\"test-driver.cdi.k8s.io\":{\"Devices\":[{\"PoolName\":\"worker-1\",\"DeviceName\":\"dev-1\",\"RequestNames\":[\"test request\"],\"CDIDeviceIDs\":[\"example.com/example=cdi-example\"]}]}}},{\"ClaimUID\":\"4cf8db2d-06c0-7d70-1a51-e59b25b2c16c\",\"ClaimName\":\"example-2\",\"Namespace\":\"default\",\"PodUIDs\":{\"139cdb46-f989-4f17-9561-ca10cfb509a6\":{}},\"DriverState\":{\"test-driver.cdi.k8s.io\":{\"Devices\":[{\"PoolName\":\"worker-1\",\"DeviceName\":\"dev-2\",\"RequestNames\":null,\"CDIDeviceIDs\":null}]}}}]}","Checksum":3633532417}`, - expectedClaimInfoStateList: state.ClaimInfoStateList{ + expectedClaimInfoStateList: ClaimInfoStateList{ { - DriverState: map[string]state.DriverState{ + DriverState: map[string]DriverState{ "test-driver.cdi.k8s.io": { - Devices: []state.Device{ + Devices: []Device{ { PoolName: "worker-1", DeviceName: "dev-1", @@ -122,9 +121,9 @@ func TestCheckpointGetOrCreate(t *testing.T) { PodUIDs: sets.New("139cdb46-f989-4f17-9561-ca10cfb509a6"), }, { - DriverState: map[string]state.DriverState{ + DriverState: map[string]DriverState{ "test-driver.cdi.k8s.io": { - Devices: []state.Device{ + Devices: []Device{ { PoolName: "worker-1", DeviceName: "dev-2", @@ -197,16 +196,16 @@ func TestCheckpointGetOrCreate(t *testing.T) { func TestCheckpointStateStore(t *testing.T) { testCases := []struct { description string - claimInfoStateList state.ClaimInfoStateList + claimInfoStateList ClaimInfoStateList expectedCheckpointContent string }{ { description: "single-claim-info-state", - claimInfoStateList: state.ClaimInfoStateList{ + claimInfoStateList: ClaimInfoStateList{ { - DriverState: map[string]state.DriverState{ + DriverState: map[string]DriverState{ "test-driver.cdi.k8s.io": { - Devices: []state.Device{ + Devices: []Device{ { PoolName: "worker-1", DeviceName: "dev-1", @@ -226,11 +225,11 @@ func TestCheckpointStateStore(t *testing.T) { }, { description: "single-claim-info-state-with-multiple-devices", - claimInfoStateList: state.ClaimInfoStateList{ + claimInfoStateList: ClaimInfoStateList{ { - DriverState: map[string]state.DriverState{ + DriverState: map[string]DriverState{ "test-driver.cdi.k8s.io": { - Devices: []state.Device{ + Devices: []Device{ { PoolName: "worker-1", DeviceName: "dev-1", @@ -256,11 +255,11 @@ func TestCheckpointStateStore(t *testing.T) { }, { description: "two-claim-info-states", - claimInfoStateList: state.ClaimInfoStateList{ + claimInfoStateList: ClaimInfoStateList{ { - DriverState: map[string]state.DriverState{ + DriverState: map[string]DriverState{ "test-driver.cdi.k8s.io": { - Devices: []state.Device{ + Devices: []Device{ { PoolName: "worker-1", DeviceName: "dev-1", @@ -276,9 +275,9 @@ func TestCheckpointStateStore(t *testing.T) { PodUIDs: sets.New("139cdb46-f989-4f17-9561-ca10cfb509a6"), }, { - DriverState: map[string]state.DriverState{ + DriverState: map[string]DriverState{ "test-driver.cdi.k8s.io": { - Devices: []state.Device{ + Devices: []Device{ { PoolName: "worker-1", DeviceName: "dev-2", diff --git a/pkg/kubelet/cm/dra/state/types.go b/pkg/kubelet/cm/dra/state/state.go similarity index 93% rename from pkg/kubelet/cm/dra/state/types.go rename to pkg/kubelet/cm/dra/state/state.go index 24e417d97f9..17e0a5e1682 100644 --- a/pkg/kubelet/cm/dra/state/types.go +++ b/pkg/kubelet/cm/dra/state/state.go @@ -17,7 +17,6 @@ limitations under the License. package state import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/sets" ) @@ -28,11 +27,6 @@ const ( type ClaimInfoStateList []ClaimInfoState -type CheckpointData struct { - metav1.TypeMeta - Entries ClaimInfoStateList -} - // +k8s:deepcopy-gen=true type ClaimInfoState struct { // ClaimUID is the UID of a resource claim