util

package
v0.0.0-...-a6dd246 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddDeviceFile

func AddDeviceFile(config *Config, deviceInfo api.DeviceInfo) error

func CheckResourcesInNode

func CheckResourcesInNode(node *v1.Node, request map[v1.ResourceName]resource.Quantity) bool

func CheckResourcesInSlice

func CheckResourcesInSlice(resources map[v1.ResourceName]resource.Quantity, slice, ignore []string) bool

func CopyMap

func CopyMap[K comparable, V any](src, dst map[K]V)

func DeleteSliceFunc

func DeleteSliceFunc[S ~[]E, E any](s S, filter func(E) bool) S

func GetContainerStatus

func GetContainerStatus(pod *v1.Pod, containerName string) (*v1.ContainerStatus, bool)

func GetDeviceFileVersion

func GetDeviceFileVersion(deviceFile string) (uint32, uint32, error)

func GetDeviceFileVersionV2

func GetDeviceFileVersionV2(deviceFile string) (uint32, uint32, devices.Type, error)

func GetK8sPodCGroupFullPath

func GetK8sPodCGroupFullPath(podCGroupPath string) string

func GetK8sPodCGroupPath

func GetK8sPodCGroupPath(pod *v1.Pod, container *api.Container,
	getFullPath func(string) string) (string, error)

func GetK8sPodDeviceCGroupFullPath

func GetK8sPodDeviceCGroupFullPath(podCGroupPath string) string

func IsSidecar

func IsSidecar(container v1.Container) bool

func KillRunningProcesses

func KillRunningProcesses(config *Config, processes []int) error

func LoadEmulator

func LoadEmulator(path string) (*devices.Emulator, error)

func LoopRetry

func LoopRetry(retryCount uint, interval time.Duration, conditionFunc wait.ConditionFunc) error

func NewDeviceSlavePod

func NewDeviceSlavePod(ownerPod *v1.Pod, limits map[v1.ResourceName]resource.Quantity, annotations, labels map[string]string) *v1.Pod

func NilCloser

func NilCloser() error

func PathIsNotExist

func PathIsNotExist(fullPath string) bool

func RemoveDeviceFile

func RemoveDeviceFile(config *Config, deviceInfo api.DeviceInfo) error

func SetDeviceRulesByCgroupv1

func SetDeviceRulesByCgroupv1(path string, r *configs.Resources) (func() error, error)

func SetDeviceRulesByCgroupv2

func SetDeviceRulesByCgroupv2(dirPath string, r *configs.Resources) (func() error, func() error, error)

func SystemdPathPrefixOfRuntime

func SystemdPathPrefixOfRuntime(runtimeName string) string

Types

type CgroupName

type CgroupName []string

func NewPodCgroupName

func NewPodCgroupName(pod *v1.Pod) CgroupName

func (CgroupName) ToCgroupfs

func (cgroupName CgroupName) ToCgroupfs() string

func (CgroupName) ToSystemd

func (cgroupName CgroupName) ToSystemd() string

cgroupName.ToSystemd converts the internal cgroup name to a systemd name. For example, the name {"kubepods", "burstable", "pod1234-abcd-5678-efgh"} becomes "/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod1234_abcd_5678_efgh.slice" This function always expands the systemd name into the cgroupfs form. If only the last part is needed, use path.Base(...) on it to discard the rest.

type Config

type Config struct {
	Cgroup              bool   // Enter cgroup namespace
	CgroupFile          string // Cgroup namespace location, default to /proc/PID/ns/cgroup
	FollowContext       bool   // Set SELinux security context
	GID                 int    // GID to use to execute given program
	IPC                 bool   // Enter IPC namespace
	IPCFile             string // IPC namespace location, default to /proc/PID/ns/ipc
	Mount               bool   // Enter mount namespace
	MountFile           string // Mount namespace location, default to /proc/PID/ns/mnt
	Net                 bool   // Enter network namespace
	NetFile             string // Network namespace location, default to /proc/PID/ns/net
	NoFork              bool   // Do not fork before executing the specified program
	PID                 bool   // Enter PID namespace
	PIDFile             string // PID namespace location, default to /proc/PID/ns/pid
	PreserveCredentials bool   // Preserve current UID/GID when entering namespaces
	RootDirectory       string // Set the root directory, default to target process root directory
	Target              int    // Target PID (required)
	UID                 int    // UID to use to execute given program
	User                bool   // Enter user namespace
	UserFile            string // User namespace location, default to /proc/PID/ns/user
	UTS                 bool   // Enter UTS namespace
	UTSFile             string // UTS namespace location, default to /proc/PID/ns/uts
	WorkingDirectory    string // Set the working directory, default to target process working directory
}

Config is the nsenter configuration used to generate nsenter command

func (*Config) Execute

func (c *Config) Execute(program string, args ...string) (string, string, error)

Execute executs the givne command with a default background context

func (*Config) ExecuteContext

func (c *Config) ExecuteContext(ctx context.Context, program string, args ...string) (string, string, error)

ExecuteContext the given program using the given nsenter configuration and given context and return stdout/stderr or an error if command has failed

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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