github.com/gocrane/crane@v0.11.0/pkg/utils/ref.go (about) 1 package utils 2 3 import ( 4 "strings" 5 6 v1 "k8s.io/api/core/v1" 7 "k8s.io/apimachinery/pkg/types" 8 ) 9 10 const ( 11 CgroupKubePods = "kubepods" 12 CgroupPodPrefix = "pod" 13 ) 14 15 func GetNodeRef(nodeName string) *v1.ObjectReference { 16 return &v1.ObjectReference{ 17 Kind: "Node", 18 Name: nodeName, 19 UID: types.UID(nodeName), 20 Namespace: "", 21 } 22 } 23 24 func GetContainerIdFromKey(key string) string { 25 subPaths := strings.Split(key, "/") 26 27 if len(subPaths) > 0 { 28 // if the latest sub path is pod-xxx-xxx, we regard as it pod path 29 // if not we used the latest sub path as the containerId 30 if strings.HasPrefix(subPaths[len(subPaths)-1], CgroupPodPrefix) { 31 return "" 32 } else { 33 return subPaths[len(subPaths)-1] 34 } 35 } 36 37 return "" 38 }