github.com/inspektor-gadget/inspektor-gadget@v0.28.1/pkg/gadget-collection/gadgets/helpers.go (about) 1 // Copyright 2019-2021 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 gadgets 16 17 import ( 18 k8sTypes "k8s.io/apimachinery/pkg/types" 19 20 gadgetv1alpha1 "github.com/inspektor-gadget/inspektor-gadget/pkg/apis/gadget/v1alpha1" 21 containercollection "github.com/inspektor-gadget/inspektor-gadget/pkg/container-collection" 22 "github.com/inspektor-gadget/inspektor-gadget/pkg/types" 23 ) 24 25 func TraceName(namespace, name string) string { 26 return "trace_" + namespace + "_" + name 27 } 28 29 func TraceNameFromNamespacedName(n k8sTypes.NamespacedName) string { 30 return TraceName(n.Namespace, n.Name) 31 } 32 33 func ContainerSelectorFromContainerFilter(f *gadgetv1alpha1.ContainerFilter) *containercollection.ContainerSelector { 34 if f == nil { 35 return &containercollection.ContainerSelector{} 36 } 37 labels := map[string]string{} 38 for k, v := range f.Labels { 39 labels[k] = v 40 } 41 return &containercollection.ContainerSelector{ 42 K8s: containercollection.K8sSelector{ 43 BasicK8sMetadata: types.BasicK8sMetadata{ 44 Namespace: f.Namespace, 45 PodName: f.Podname, 46 ContainerName: f.ContainerName, 47 PodLabels: labels, 48 }, 49 }, 50 } 51 }