...
1
16
17 package kuberuntime
18
19 import (
20 "sort"
21
22 utilfeature "k8s.io/apiserver/pkg/util/feature"
23 runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
24 "k8s.io/kubernetes/pkg/features"
25 kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
26 )
27
28
29
30 func toKubeContainerImageSpec(image *runtimeapi.Image) kubecontainer.ImageSpec {
31 var annotations []kubecontainer.Annotation
32
33 if image.Spec != nil && len(image.Spec.Annotations) > 0 {
34 annotationKeys := make([]string, 0, len(image.Spec.Annotations))
35 for k := range image.Spec.Annotations {
36 annotationKeys = append(annotationKeys, k)
37 }
38 sort.Strings(annotationKeys)
39 for _, k := range annotationKeys {
40 annotations = append(annotations, kubecontainer.Annotation{
41 Name: k,
42 Value: image.Spec.Annotations[k],
43 })
44 }
45 }
46
47 spec := kubecontainer.ImageSpec{
48 Image: image.Id,
49 Annotations: annotations,
50 }
51
52 if utilfeature.DefaultFeatureGate.Enabled(features.RuntimeClassInImageCriAPI) {
53 runtimeHandler := ""
54 if image.Spec != nil {
55 runtimeHandler = image.Spec.RuntimeHandler
56 }
57 spec.RuntimeHandler = runtimeHandler
58 }
59
60 return spec
61 }
62
63 func toRuntimeAPIImageSpec(imageSpec kubecontainer.ImageSpec) *runtimeapi.ImageSpec {
64 var annotations = make(map[string]string)
65 if imageSpec.Annotations != nil {
66 for _, a := range imageSpec.Annotations {
67 annotations[a.Name] = a.Value
68 }
69 }
70
71 spec := runtimeapi.ImageSpec{
72 Image: imageSpec.Image,
73 Annotations: annotations,
74 }
75
76 if utilfeature.DefaultFeatureGate.Enabled(features.RuntimeClassInImageCriAPI) {
77 spec.RuntimeHandler = imageSpec.RuntimeHandler
78 }
79
80 return &spec
81 }
82
View as plain text