...
1 package oci
2
3 import (
4 "fmt"
5
6 "github.com/Microsoft/hcsshim/pkg/annotations"
7 )
8
9
10
11 type KubernetesContainerType string
12
13 const (
14
15
16 KubernetesContainerTypeNone KubernetesContainerType = ""
17
18
19 KubernetesContainerTypeContainer KubernetesContainerType = "container"
20
21
22 KubernetesContainerTypeSandbox KubernetesContainerType = "sandbox"
23 )
24
25
26
27
28 func GetSandboxTypeAndID(specAnnotations map[string]string) (KubernetesContainerType, string, error) {
29 var ct KubernetesContainerType
30 if t, ok := specAnnotations[annotations.KubernetesContainerType]; ok {
31 switch t {
32 case string(KubernetesContainerTypeContainer):
33 ct = KubernetesContainerTypeContainer
34 case string(KubernetesContainerTypeSandbox):
35 ct = KubernetesContainerTypeSandbox
36 default:
37 return KubernetesContainerTypeNone, "", fmt.Errorf("invalid '%s': '%s'", annotations.KubernetesContainerType, t)
38 }
39 }
40
41 id := specAnnotations[annotations.KubernetesSandboxID]
42
43 switch ct {
44 case KubernetesContainerTypeContainer, KubernetesContainerTypeSandbox:
45 if id == "" {
46 return KubernetesContainerTypeNone, "", fmt.Errorf("cannot specify '%s' without '%s'", annotations.KubernetesContainerType, annotations.KubernetesSandboxID)
47 }
48 default:
49 if id != "" {
50 return KubernetesContainerTypeNone, "", fmt.Errorf("cannot specify '%s' without '%s'", annotations.KubernetesSandboxID, annotations.KubernetesContainerType)
51 }
52 }
53 return ct, id, nil
54 }
55
56
57
58
59
60 func SandboxAnnotationsPassThrough(podAnnots, containerAnnots map[string]string, vals ...string) {
61 if podAnnots == nil || containerAnnots == nil {
62 return
63 }
64 for _, val := range vals {
65 if v, ok := podAnnots[val]; ok {
66 containerAnnots[val] = v
67 }
68 }
69 }
70
View as plain text