common

package
v0.0.0-...-b80f625 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 22 Imported by: 2

Documentation

Overview

Package common contains utility functions which are commonly used across packages and modules

Index

Constants

View Source
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
)
View Source
const (
	TimeFormUTC string = "2006-01-02T15:04:05.000000Z"
)

Time Format

Variables

View Source
var ContainerRuntimeSocketKeys = []string{"docker", "containerd", "cri-o"}

ContainerRuntimeSocketKeys contains FIFO ordered keys of container runtimes

View Source
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 Clone

func Clone(src, dst interface{}) error

Clone Function

func ContainsElement

func ContainsElement(slice interface{}, element interface{}) bool

ContainsElement Function

func CopyFile

func CopyFile(src, dst string) error

CopyFile Function

func GetCRISocket

func GetCRISocket(ContainerRuntime string) string

GetCRISocket Function

func GetCommandOutputWithErr

func GetCommandOutputWithErr(cmd string, args []string) (string, error)

GetCommandOutputWithErr Function

func GetCommandOutputWithoutErr

func GetCommandOutputWithoutErr(cmd string, args []string) string

GetCommandOutputWithoutErr Function

func GetControllingPodOwner

func GetControllingPodOwner(ownerRefs []metav1.OwnerReference) *metav1.OwnerReference

GetControllingPodOwner Function returns the pod's Controlling OnwerReference

func GetDateTimeFromTimestamp

func GetDateTimeFromTimestamp(timestamp float64) string

GetDateTimeFromTimestamp Function

func GetDateTimeNow

func GetDateTimeNow() (int64, string)

GetDateTimeNow Function

func GetExternalIPAddr

func GetExternalIPAddr() string

GetExternalIPAddr Function

func GetExternalInterface

func GetExternalInterface() string

GetExternalInterface Function

func GetIPAddr

func GetIPAddr(ifname string) string

GetIPAddr Function

func GetLabelsFromString

func GetLabelsFromString(labelString string) (map[string]string, []string)

func GetMapRoot

func GetMapRoot() string

GetMapRoot function returns the current mapRoot path

func GetSHA256ofImage

func GetSHA256ofImage(s string) string

GetSHA256ofImage of the image

func GetUptimeTimestamp

func GetUptimeTimestamp() float64

GetUptimeTimestamp Function

func HandleGRPCErrors

func HandleGRPCErrors(err error) error

handle gRPC errors

func IsInK8sCluster

func IsInK8sCluster() bool

IsInK8sCluster Function

func IsK8sEnv

func IsK8sEnv() bool

IsK8sEnv Function

func IsK8sLocal

func IsK8sLocal() bool

IsK8sLocal Function

func MatchIdentities

func MatchIdentities(identities []string, superIdentities []string) bool

MatchIdentities Function

func MatchesRegex

func MatchesRegex(key, element string, array []string) bool

MatchesRegex function

func ObjCommaCanBeExpanded

func ObjCommaCanBeExpanded(objptr interface{}) bool

ObjCommaCanBeExpanded Function

func ObjCommaExpand

func ObjCommaExpand(v reflect.Value) []string

ObjCommaExpand Function

func ObjCommaExpandFirstDupOthers

func ObjCommaExpandFirstDupOthers(objptr interface{})

ObjCommaExpandFirstDupOthers Function

func ParseURL

func ParseURL(address string) (string, string, error)

ParseURL with/without scheme and return host, port or error

func RemoveStringElement

func RemoveStringElement(slice []string, size int) []string

RemoveStringElement function

func RunCommandAndWaitWithErr

func RunCommandAndWaitWithErr(cmd string, args []string) error

RunCommandAndWaitWithErr Function

func WriteToFile

func WriteToFile(val interface{}, destFile string) error

WriteToFile writes given string to file as JSON

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL