github.com/inspektor-gadget/inspektor-gadget@v0.28.1/pkg/container-utils/oci-annotations/resolver_containerd.go (about) 1 // Copyright 2022 The Inspektor Gadget authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package ociannotations 16 17 import "github.com/inspektor-gadget/inspektor-gadget/pkg/types" 18 19 const ( 20 // containerd container annotations to get container information 21 // https://github.com/containerd/containerd/blob/main/pkg/cri/annotations/annotations.go 22 // 23 // Pod UID annotation added in: 24 // * containerd v1.7.0 via https://github.com/containerd/containerd/pull/7697 25 // * containerd v1.6.11 via https://github.com/containerd/containerd/pull/7735 26 containerdPodNameAnnotation = "io.kubernetes.cri.sandbox-name" 27 containerdPodNamespaceAnnotation = "io.kubernetes.cri.sandbox-namespace" 28 containerdPodUIDAnnotation = "io.kubernetes.cri.sandbox-uid" 29 containerdContainerNameAnnotation = "io.kubernetes.cri.container-name" 30 containerdContainerTypeAnnotation = "io.kubernetes.cri.container-type" 31 containerdContainerImageName = "io.kubernetes.cri.image-name" 32 containerdPodSandboxId = "io.kubernetes.cri.sandbox-id" 33 ) 34 35 type containerdResolver struct{} 36 37 func (containerdResolver) ContainerName(annotations map[string]string) string { 38 return annotations[containerdContainerNameAnnotation] 39 } 40 41 func (containerdResolver) ContainerType(annotations map[string]string) string { 42 return annotations[containerdContainerTypeAnnotation] 43 } 44 45 func (containerdResolver) ContainerImageName(annotations map[string]string) string { 46 return annotations[containerdContainerImageName] 47 } 48 49 func (containerdResolver) PodName(annotations map[string]string) string { 50 return annotations[containerdPodNameAnnotation] 51 } 52 53 func (containerdResolver) PodUID(annotations map[string]string) string { 54 return annotations[containerdPodUIDAnnotation] 55 } 56 57 func (containerdResolver) PodNamespace(annotations map[string]string) string { 58 return annotations[containerdPodNamespaceAnnotation] 59 } 60 61 func (containerdResolver) PodSandboxId(annotations map[string]string) string { 62 return annotations[containerdPodSandboxId] 63 } 64 65 func (containerdResolver) Runtime() types.RuntimeName { 66 return types.RuntimeNameContainerd 67 }