github.com/inspektor-gadget/inspektor-gadget@v0.28.1/pkg/container-utils/oci-annotations/resolver_crio.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  	// cri-o container annotations to get container information
    21  	// https://github.com/containers/podman/blob/main/pkg/annotations/annotations.go
    22  	// https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/types/labels.go
    23  	crioContainerManagerAnnotation = "io.container.manager"
    24  	crioPodNameAnnotation          = "io.kubernetes.pod.name"
    25  	crioPodNamespaceAnnotation     = "io.kubernetes.pod.namespace"
    26  	crioPodUIDAnnotation           = "io.kubernetes.pod.uid"
    27  	crioContainerNameAnnotation    = "io.kubernetes.container.name"
    28  	crioContainerTypeAnnotation    = "io.kubernetes.cri-o.ContainerType"
    29  	crioContainerImageName         = "io.kubernetes.cri-o.ImageName"
    30  	crioPodSandboxId               = "io.kubernetes.cri-o.SandboxID"
    31  )
    32  
    33  type crioResolver struct{}
    34  
    35  func (crioResolver) ContainerName(annotations map[string]string) string {
    36  	return annotations[crioContainerNameAnnotation]
    37  }
    38  
    39  func (crioResolver) ContainerType(annotations map[string]string) string {
    40  	return annotations[crioContainerTypeAnnotation]
    41  }
    42  
    43  func (crioResolver) ContainerImageName(annotations map[string]string) string {
    44  	return annotations[crioContainerImageName]
    45  }
    46  
    47  func (crioResolver) PodName(annotations map[string]string) string {
    48  	return annotations[crioPodNameAnnotation]
    49  }
    50  
    51  func (crioResolver) PodUID(annotations map[string]string) string {
    52  	return annotations[crioPodUIDAnnotation]
    53  }
    54  
    55  func (crioResolver) PodNamespace(annotations map[string]string) string {
    56  	return annotations[crioPodNamespaceAnnotation]
    57  }
    58  
    59  func (crioResolver) PodSandboxId(annotations map[string]string) string {
    60  	return annotations[crioPodSandboxId]
    61  }
    62  
    63  func (crioResolver) Runtime() types.RuntimeName {
    64  	return types.RuntimeNameCrio
    65  }