podexec

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCommandFailed is returned for command executions with an exit code > 0
	ErrCommandFailed = errors.New("command failed: ")
)

Functions

func DownloadFile

func DownloadFile(fs afero.Fs, file string, pod *v1.Pod, ctrName string, restCfg *rest.Config) error

DownloadFile fetches a file from a remote pod. It runs `tar cf - file` command and streams contents of the file via the stdout. Locally, the tar file is extracted into the passed afero filesystem where it is saved under the same path. Afero filesystem is used to allow the caller downloading and persisting of multiple files concurrently (afero filesystem is thread-safe).

func FileSize

func FileSize(file string, pod *v1.Pod, ctrName string, restCfg *rest.Config) (int64, error)

FileSize fetches the size of a file in a remote pod. It runs `stat -c %s file` command in the pod and parses the output.

func HasCommandFailed

func HasCommandFailed(err error) bool

HasCommandFailed returns true if PodExec command returned an exit code > 0

Types

type PodExec

type PodExec struct {
	RestCfg       *rest.Config
	PodName       string
	PodNamespace  string
	ContainerName string
	Args          []string
	In            io.Reader
	Out           io.Writer
	Err           io.Writer
	TTY           bool
}

PodExec defines a command that will be executed in a running Pod. RestCfg - The REST configuration for the cluster. PodName - The pod name on which to execute the command. PodNamespace - Namespace of the pod ContainerName - optional container to execute the command in. If empty, first container is taken Args - The command (and args) to execute. In - Command input stream. Out - Command output stream Err - Command error stream

func (*PodExec) Run

func (pe *PodExec) Run() error

Run executes a command in a pod. This is a distilled version of what `kubectl exec` (and also `kubectl cp`) doing under the hood: a POST request is made to the `exec` subresource of the v1/pods endpoint containing the pod information and the command. Here is a good article describing it in detail: https://erkanerol.github.io/post/how-kubectl-exec-works/

The result of the command execution is returned via passed PodExec.Out and PodExec.Err streams. Run calls the remotecommand executor, which executes the command in the remote pod, captures stdout and stderr, writes them to the provided Out and Err writers and then returns with an exit code. Note that when using SYNCHRONOUS io.Pipe for Out or Err streams Run call will not return until the streams are consumed. Here, Run has to be executed in a goroutine.

Jump to

Keyboard shortcuts

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