github.com/kubewharf/katalyst-core@v0.5.3/pkg/agent/orm/checkpoint.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 orm 18 19 import ( 20 "fmt" 21 "path/filepath" 22 23 "k8s.io/klog/v2" 24 "k8s.io/kubernetes/pkg/kubelet/checkpointmanager/errors" 25 26 "github.com/kubewharf/katalyst-core/pkg/agent/orm/checkpoint" 27 "github.com/kubewharf/katalyst-core/pkg/agent/orm/endpoint" 28 "github.com/kubewharf/katalyst-core/pkg/consts" 29 ) 30 31 func (m *ManagerImpl) checkpointFile() string { 32 return filepath.Join(m.socketdir, consts.KubeletQoSResourceManagerCheckpoint) 33 } 34 35 func (m *ManagerImpl) writeCheckpoint() error { 36 data := checkpoint.New(m.podResources.toCheckpointData()) 37 err := m.checkpointManager.CreateCheckpoint(consts.KubeletQoSResourceManagerCheckpoint, data) 38 if err != nil { 39 err = fmt.Errorf("[ORM] failed to write checkpoint file %q: %v", consts.KubeletQoSResourceManagerCheckpoint, err) 40 klog.Warning(err) 41 return err 42 } 43 return nil 44 } 45 46 func (m *ManagerImpl) readCheckpoint() error { 47 resEntries := make([]checkpoint.PodResourcesEntry, 0) 48 cp := checkpoint.New(resEntries) 49 err := m.checkpointManager.GetCheckpoint(consts.KubeletQoSResourceManagerCheckpoint, cp) 50 if err != nil { 51 if err == errors.ErrCheckpointNotFound { 52 klog.Warningf("[ORM] Failed to retrieve checkpoint for %q: %v", consts.KubeletQoSResourceManagerCheckpoint, err) 53 return nil 54 } 55 return err 56 } 57 58 podResources := cp.GetData() 59 klog.V(5).Infof("[ORM] read checkpoint %v", podResources) 60 m.podResources.fromCheckpointData(podResources) 61 62 m.mutex.Lock() 63 64 allocatedResourceNames := m.podResources.allAllocatedResourceNames() 65 66 for _, allocatedResourceName := range allocatedResourceNames.UnsortedList() { 67 m.endpoints[allocatedResourceName] = endpoint.EndpointInfo{E: endpoint.NewStoppedEndpointImpl(allocatedResourceName), Opts: nil} 68 } 69 70 m.mutex.Unlock() 71 72 return nil 73 }