criutils

package
v0.0.0-...-5c7ffcf Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupported = errors.New("unsupported")
	ErrDisabled    = errors.New("disabled")
)

Functions

func CopyFromContainer

func CopyFromContainer(ctx context.Context, i cri.Interface, c *cri.Container, srcPath, dstPath string) (string, error)

func CopyFromContainerByMount

func CopyFromContainerByMount(ctx context.Context, i cri.Interface, c *cri.Container, srcPath, dstPath string) error

func CopyFromContainerByTar

func CopyFromContainerByTar(ctx context.Context, i cri.Interface, c *cri.Container, srcPath, dstPath string) error

CopyFromContainerByTar copies file from container using tar

func CopyFromContainerToTempFile

func CopyFromContainerToTempFile(ctx context.Context, i cri.Interface, c *cri.Container, path string) (string, func() error, error)

CopyFromContainerToTempFile copies file from container to local tep file. It is the caller's responsibility to remove the file when it is no longer needed. See os.CreateTemp.

func CopySmallFileFromContainerToTempFile

func CopySmallFileFromContainerToTempFile(ctx context.Context, i cri.Interface, c *cri.Container, path string) (string, func() error, error)

CopySmallFileFromContainerToTempFile copies small file from container to temp file.

func CopyToContainer

func CopyToContainer(ctx context.Context, i cri.Interface, c *cri.Container, srcPath, dstPath string) (string, error)

func CopyToContainerByChunk

func CopyToContainerByChunk(ctx context.Context, i cri.Interface, c *cri.Container, srcPath, dstPath string) error

func CopyToContainerByMount

func CopyToContainerByMount(ctx context.Context, i cri.Interface, c *cri.Container, srcPath, dstPath string) (retErr error)

func CopyToContainerByTar

func CopyToContainerByTar(ctx context.Context, i cri.Interface, c *cri.Container, srcPath, dstPath string) (retErr error)

CopyToContainerByTar copies file to container using tar

func CountZombies

func CountZombies(i cri.Interface, ctx context.Context, c *cri.Container) (int, error)

func ExecChmod

func ExecChmod(ctx context.Context, i cri.Interface, c *cri.Container, path string, mode fs.FileMode) error

ExecChmod executes 'chmod' command inside container

func ExecCp

func ExecCp(ctx context.Context, i cri.Interface, c *cri.Container, srcPath, dstPath string) error

ExecCp executes 'cp' command inside container

func ExecMv

func ExecMv(ctx context.Context, i cri.Interface, c *cri.Container, srcPath, dstPath string) error

ExecMv executes 'mv' command inside container

func ExecRm

func ExecRm(ctx context.Context, i cri.Interface, c *cri.Container, path string) error

ExecRm executes 'rm' command inside container

func FindFirstPodByIp

func FindFirstPodByIp(i cri.Interface, ip string) *cri.Pod

func FindPodsByIp

func FindPodsByIp(i cri.Interface, ip string) []*cri.Pod

func GetContainerE

func GetContainerE(i cri.Interface, ns, pod, k8sContainerName string) (*cri.Container, error)

func GetMainBizContainerE

func GetMainBizContainerE(i cri.Interface, ns string, pod string) (*cri.Container, error)

GetMainBizContainerE get main biz container for pod

func Glob

func Glob(ctx context.Context, i cri.Interface, c *cri.Container, pattern string) ([]string, error)

Glob runs glob commands inside the container.

func HasCommand

func HasCommand(ctx context.Context, i cri.Interface, c *cri.Container, command string) error

HasCommand checks whether container has specified command

func Md5sum

func Md5sum(ctx context.Context, i cri.Interface, c *cri.Container, path string) (string, error)

Md5sum runs 'md5sum' inside the container and extracts the md5 string

func ReadContainerFile

func ReadContainerFile(ctx context.Context, i cri.Interface, c *cri.Container, path string) ([]byte, error)

ReadContainerFile copies file from container to local temp file, reads the file content, and then remove the temp file.

func ReadContainerFileUsingExecCat

func ReadContainerFileUsingExecCat(ctx context.Context, i cri.Interface, c *cri.Container, path string) ([]byte, error)

ReadContainerFileUsingExecCat reads container file using docker exec 'cat ...'

func SubContextTimeoutExec

func SubContextTimeoutExec(parent context.Context, timeout time.Duration, callback func(context.Context) (cri.ExecResult, error)) (cri.ExecResult, error)

func TcpProxy

func TcpProxy(ctx context.Context, i cri.Interface, c *cri.Container, addr string, dialTimeout time.Duration) (net.Conn, error)

TcpProxy

func TcpProxyByExec

func TcpProxyByExec(ctx context.Context, i cri.Interface, c *cri.Container, addr string) (net.Conn, error)

Types

type ProcessInfo

type ProcessInfo struct {
	User         string   `json:"user"`
	Name         string   `json:"name"`
	CmdlineSlice []string `json:"cmdlineSlice"`
	Tgid         int32    `json:"tgid"`
}

func GetProcessInfo

func GetProcessInfo(ctx context.Context, i cri.Interface, c *cri.Container, pid int) (*ProcessInfo, error)

GetProcessInfo returns process info of pid in target container

type StatefulHelper

type StatefulHelper interface {
	// 打开一个文件用于后续读操作, 要返回一个句柄, 并且对端(必须长期运行)必须要持有文件句柄不关闭
	FileOpen(c *cri.Container, path string) (interface{}, error)
	FileSeek(c *cri.Container, fd interface{}) (interface{}, error)
	FileRead(c *cri.Container, fd interface{}) (interface{}, error)
	FileRead2(c *cri.Container, fd interface{}, offset, limit int) (interface{}, error)
	FileStat(c *cri.Container, fd interface{}) (interface{}, error)
	FileClose(c *cri.Container, fd interface{}) (interface{}, error)
}

type StatelessHelper

type StatelessHelper interface {
	// 获取容器内部一个 pid 的信息
	GetProcessInfo(c *cri.Container, pid int) (*ProcessInfo, error)
	// 在容器内部做 glob
	Glob(c *cri.Container, pattern string) (interface{}, error)
	// 列出文件目录
	ListFiles(c *cri.Container, request *pb.ListFilesRequest) (*pb.ListFilesResponse, error)
}

Jump to

Keyboard shortcuts

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