github.com/inspektor-gadget/inspektor-gadget@v0.28.1/pkg/container-collection/interface.go (about)

     1  // Copyright 2019-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 containercollection
    16  
    17  import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    18  
    19  // ContainerResolver offers primitives to look up running containers with
    20  // various criteria, and to subscribe to container creation and termination.
    21  type ContainerResolver interface {
    22  	// LookupMntnsByContainer returns the mount namespace inode of the container
    23  	// specified in arguments or zero if not found
    24  	LookupMntnsByContainer(namespace, pod, container string) uint64
    25  
    26  	// LookupContainerByMntns returns a container by its mount namespace
    27  	// inode id. If not found nil is returned.
    28  	LookupContainerByMntns(mntnsid uint64) *Container
    29  
    30  	// LookupContainersByNetns returns a slice of containers that run in a given
    31  	// network namespace. Or an empty slice if there are no containers running
    32  	// in that network namespace.
    33  	LookupContainersByNetns(netnsid uint64) []*Container
    34  
    35  	// LookupMntnsByPod returns the mount namespace inodes of all containers
    36  	// belonging to the pod specified in arguments, indexed by the name of the
    37  	// containers or an empty map if not found
    38  	LookupMntnsByPod(namespace, pod string) map[string]uint64
    39  
    40  	// LookupPIDByContainer returns the PID of the container
    41  	// specified in arguments or zero if not found
    42  	LookupPIDByContainer(namespace, pod, container string) uint32
    43  
    44  	// LookupPIDByPod returns the PID of all containers belonging to
    45  	// the pod specified in arguments, indexed by the name of the
    46  	// containers or an empty map if not found
    47  	LookupPIDByPod(namespace, pod string) map[string]uint32
    48  
    49  	// LookupOwnerReferenceByMntns returns a pointer to the owner reference of the
    50  	// container identified by the mount namespace, or nil if not found
    51  	LookupOwnerReferenceByMntns(mntns uint64) *metav1.OwnerReference
    52  
    53  	// GetContainersBySelector returns a slice of containers that match
    54  	// the selector or an empty slice if there are not matches
    55  	GetContainersBySelector(containerSelector *ContainerSelector) []*Container
    56  
    57  	// Subscribe returns the list of existing containers and registers a
    58  	// callback for notifications about additions and deletions of
    59  	// containers
    60  	Subscribe(key interface{}, s ContainerSelector, f FuncNotify) []*Container
    61  
    62  	// Unsubscribe undoes a previous call to Subscribe
    63  	Unsubscribe(key interface{})
    64  }