Documentation ¶
Overview ¶
Package common contains utility functions which are commonly used across packages and modules
Index ¶
- Constants
- Variables
- func CheckOrMountBPFFs(bpfRoot string)
- func Clone(src, dst interface{}) error
- func ContainsElement(slice interface{}, element interface{}) bool
- func CopyFile(src, dst string) error
- func GetBootTime() string
- func GetCRISocket(ContainerRuntime string) string
- func GetCommandOutputWithErr(cmd string, args []string) (string, error)
- func GetCommandOutputWithoutErr(cmd string, args []string) string
- func GetControllingPodOwner(ownerRefs []metav1.OwnerReference) *metav1.OwnerReference
- func GetDateTimeFromTimestamp(timestamp float64) string
- func GetDateTimeNow() (int64, string)
- func GetExternalIPAddr() string
- func GetExternalInterface() string
- func GetIPAddr(ifname string) string
- func GetLabelsFromString(labelString string) (map[string]string, []string)
- func GetMapRoot() string
- func GetSHA256ofImage(s string) string
- func GetUptimeTimestamp() float64
- func HandleGRPCErrors(err error) error
- func IsInK8sCluster() bool
- func IsK8sEnv() bool
- func IsK8sLocal() bool
- func MatchIdentities(identities []string, superIdentities []string) bool
- func MatchesRegex(key, element string, array []string) bool
- func ObjCommaCanBeExpanded(objptr interface{}) bool
- func ObjCommaExpand(v reflect.Value) []string
- func ObjCommaExpandFirstDupOthers(objptr interface{})
- func ParseURL(address string) (string, string, error)
- func RemoveStringElement(slice []string, size int) []string
- func RunCommandAndWaitWithErr(cmd string, args []string) error
- func WriteToFile(val interface{}, destFile string) error
Constants ¶
const ( // grpc default is 4MB // CRI i.e. containerd service can send msg extended upto 16MB // https://github.com/containerd/containerd/blob/main/defaults/defaults.go#L22-L25 DefaultMaxRecvMaxSize = 16 << 20 )
const (
TimeFormUTC string = "2006-01-02T15:04:05.000000Z"
)
Time Format
Variables ¶
var ContainerRuntimeSocketKeys = []string{"docker", "containerd", "cri-o"}
ContainerRuntimeSocketKeys contains FIFO ordered keys of container runtimes
var ContainerRuntimeSocketMap = map[string][]string{
"docker": {
"/var/run/docker.sock",
"/run/docker.sock",
},
"containerd": {
"/var/snap/microk8s/common/run/containerd.sock",
"/run/k3s/containerd/containerd.sock",
"/run/containerd/containerd.sock",
"/var/run/containerd/containerd.sock",
"/run/dockershim.sock",
},
"cri-o": {
"/var/run/crio/crio.sock",
"/run/crio/crio.sock",
},
}
ContainerRuntimeSocketMap Structure
Functions ¶
func CheckOrMountBPFFs ¶
func CheckOrMountBPFFs(bpfRoot string)
CheckOrMountBPFFs checks for the mounted BPF filesystem at either the standard or the user specified custom location.
- No custom location specified, check if BPFFS mounted at /sys/fs/bpf
- No - Mount BPFFS at /sys/fs/bpf
- Yes - We're done
- Yes but /sys/fs/bpf has a different fs mounted which implies that kubearmor is running inside a container and the host mount is an empty directory. So we mount BPFFS under /run/kubearmor/bpffs.
- Custom location specified, check if BPFFS is mounted there
- No - Mount it
- Yes - We're done
- Yes but the location has some different fs mounted, return an error
We also check and error if there have been multiple mounts at the same point. See - https://patchwork.kernel.org/project/netdevbpf/patch/20220223131833.51991-1-laoar.shao@gmail.com/
func ContainsElement ¶
func ContainsElement(slice interface{}, element interface{}) bool
ContainsElement Function
func GetBootTime ¶
func GetBootTime() string
get boot time credits: https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/util/boottime_util_linux.go
func GetCommandOutputWithErr ¶
GetCommandOutputWithErr Function
func GetCommandOutputWithoutErr ¶
GetCommandOutputWithoutErr Function
func GetControllingPodOwner ¶
func GetControllingPodOwner(ownerRefs []metav1.OwnerReference) *metav1.OwnerReference
GetControllingPodOwner Function returns the pod's Controlling OnwerReference
func GetDateTimeFromTimestamp ¶
GetDateTimeFromTimestamp Function
func GetLabelsFromString ¶
func MatchIdentities ¶
MatchIdentities Function
func MatchesRegex ¶
MatchesRegex function
func ObjCommaCanBeExpanded ¶
func ObjCommaCanBeExpanded(objptr interface{}) bool
ObjCommaCanBeExpanded Function
func ObjCommaExpandFirstDupOthers ¶
func ObjCommaExpandFirstDupOthers(objptr interface{})
ObjCommaExpandFirstDupOthers Function
func RemoveStringElement ¶
RemoveStringElement function
func RunCommandAndWaitWithErr ¶
RunCommandAndWaitWithErr Function
func WriteToFile ¶
WriteToFile writes given string to file as JSON
Types ¶
This section is empty.