github.com/kubewharf/katalyst-core@v0.5.3/pkg/agent/resourcemanager/fetcher/checkpoint/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 checkpoint 18 19 import ( 20 "encoding/json" 21 22 "k8s.io/kubernetes/pkg/kubelet/checkpointmanager" 23 "k8s.io/kubernetes/pkg/kubelet/checkpointmanager/checksum" 24 25 "github.com/kubewharf/katalyst-api/pkg/protocol/reporterplugin/v1alpha1" 26 ) 27 28 type ReporterManagerCheckpoint interface { 29 checkpointmanager.Checkpoint 30 GetData() map[string]*v1alpha1.GetReportContentResponse 31 } 32 33 // Data holds checkpoint data and its checksum 34 type Data struct { 35 Data map[string]*v1alpha1.GetReportContentResponse 36 Checksum checksum.Checksum 37 } 38 39 // New returns an instance of Checkpoint 40 func New(reportResponses map[string]*v1alpha1.GetReportContentResponse) ReporterManagerCheckpoint { 41 return &Data{ 42 Data: reportResponses, 43 } 44 } 45 46 func (d *Data) MarshalCheckpoint() ([]byte, error) { 47 d.Checksum = checksum.New(d.Data) 48 return json.Marshal(*d) 49 } 50 51 func (d *Data) UnmarshalCheckpoint(blob []byte) error { 52 return json.Unmarshal(blob, d) 53 } 54 55 func (d *Data) VerifyChecksum() error { 56 return d.Checksum.Verify(d.Data) 57 } 58 59 func (d *Data) GetData() map[string]*v1alpha1.GetReportContentResponse { 60 return d.Data 61 }