nsmgr

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NamespacePathFromProc

func NamespacePathFromProc(nsType NSType, pid int) string

NamespacePathFromProc returns the namespace path of type nsType for a given pid and type.

Types

type NS

type NS interface {
	nspkg.NetNS
}

NS is a wrapper for the containernetworking plugin's NetNS interface It exists because while NetNS is specifically called such, it is really a generic namespace, and can be used for other namespace types.

type NSType

type NSType string

NSType is a representation of available namespace types.

const (
	NETNS                NSType = "net"
	IPCNS                NSType = "ipc"
	UTSNS                NSType = "uts"
	USERNS               NSType = "user"
	PIDNS                NSType = "pid"
	ManagedNamespacesNum        = 5
)

type Namespace

type Namespace interface {
	// Path returns the bind mount path of the namespace.
	Path() string

	// Type returns the namespace type (net, ipc, user, pid or uts).
	Type() NSType

	// Remove ensures this namespace is closed and removed.
	Remove() error
}

Namespace provides a generic namespace interface.

func GetNamespace

func GetNamespace(nsPath string, nsType NSType) (Namespace, error)

GetNamespace takes a path and type, checks if it is a namespace, and if so returns an instance of the Namespace interface.

type NamespaceManager

type NamespaceManager struct {
	// contains filtered or unexported fields
}

NamespaceManager manages the server's namespaces. Specifically, it is an interface for how the server is creating namespaces, and can be requested to create namespaces for a pod.

func New

func New(namespacesDir, pinnsPath string) *NamespaceManager

New creates a new NamespaceManager.

func (*NamespaceManager) Initialize

func (mgr *NamespaceManager) Initialize() error

func (*NamespaceManager) NamespaceFromProcEntry

func (mgr *NamespaceManager) NamespaceFromProcEntry(pid int, nsType NSType) (_ Namespace, retErr error)

NamespaceFromProcEntry creates a new namespace object from a bind mount from a processes proc entry. The caller is responsible for cleaning up the namespace by calling Namespace.Remove(). This function is heavily based on containernetworking ns package found at: https://github.com/containernetworking/plugins/blob/5c3c17164270150467498a32c71436c7cd5501be/pkg/ns/ns.go#L140 Credit goes to the CNI authors.

func (*NamespaceManager) NewPodNamespaces

func (mgr *NamespaceManager) NewPodNamespaces(cfg *PodNamespacesConfig) ([]Namespace, error)

NewPodNamespaces creates new namespaces for a pod. It's responsible for running pinns and creating the Namespace objects. The caller is responsible for cleaning up the namespaces by calling Namespace.Remove().

type PodNamespaceConfig

type PodNamespaceConfig struct {
	Type NSType
	Host bool
	Path string
}

type PodNamespacesConfig

type PodNamespacesConfig struct {
	Namespaces []*PodNamespaceConfig
	IDMappings *idtools.IDMappings
	Sysctls    map[string]string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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