k8s.io/kubernetes@v1.29.3/pkg/kubelet/cri/remote/utils.go (about) 1 /* 2 Copyright 2016 The Kubernetes 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 remote 18 19 import ( 20 "fmt" 21 22 runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1" 23 ) 24 25 // maxMsgSize use 16MB as the default message size limit. 26 // grpc library default is 4MB 27 const maxMsgSize = 1024 * 1024 * 16 28 29 // verifySandboxStatus verified whether all required fields are set in PodSandboxStatus. 30 func verifySandboxStatus(status *runtimeapi.PodSandboxStatus) error { 31 if status.Id == "" { 32 return fmt.Errorf("status.Id is not set") 33 } 34 35 if status.Metadata == nil { 36 return fmt.Errorf("status.Metadata is not set") 37 } 38 39 metadata := status.Metadata 40 if metadata.Name == "" || metadata.Namespace == "" || metadata.Uid == "" { 41 return fmt.Errorf("metadata.Name, metadata.Namespace or metadata.Uid is not in metadata %q", metadata) 42 } 43 44 if status.CreatedAt == 0 { 45 return fmt.Errorf("status.CreatedAt is not set") 46 } 47 48 return nil 49 } 50 51 // verifyContainerStatus verified whether all required fields are set in ContainerStatus. 52 func verifyContainerStatus(status *runtimeapi.ContainerStatus) error { 53 if status.Id == "" { 54 return fmt.Errorf("status.Id is not set") 55 } 56 57 if status.Metadata == nil { 58 return fmt.Errorf("status.Metadata is not set") 59 } 60 61 metadata := status.Metadata 62 if metadata.Name == "" { 63 return fmt.Errorf("metadata.Name is not in metadata %q", metadata) 64 } 65 66 if status.CreatedAt == 0 { 67 return fmt.Errorf("status.CreatedAt is not set") 68 } 69 70 if status.Image == nil || status.Image.Image == "" { 71 return fmt.Errorf("status.Image is not set") 72 } 73 74 if status.ImageRef == "" { 75 return fmt.Errorf("status.ImageRef is not set") 76 } 77 78 return nil 79 }