exec

package
v1.7.3 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2021 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package exec embeds Rook's exec logic

Copyright 2016 The Rook Authors. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var (
	CephCommandsTimeout = 15 * time.Second
)

Functions

func ExitStatus added in v1.7.3

func ExitStatus(err error) (int, bool)

ExitStatus looks for the exec error code

func ExtractExitCode added in v1.7.3

func ExtractExitCode(err error) (int, error)

ExtractExitCode attempts to get the exit code from the error returned by an Executor function. This should also work for any errors returned by the golang os/exec package and "k8s.io/utils/exec"

Types

type CephCLIError added in v1.7.3

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

CephCLIError is Ceph CLI Error type

func (*CephCLIError) Error added in v1.7.3

func (e *CephCLIError) Error() string

type CommandExecutor

type CommandExecutor struct{}

CommandExecutor is the type of the Executor

func (*CommandExecutor) ExecuteCommand

func (c *CommandExecutor) ExecuteCommand(command string, arg ...string) error

ExecuteCommand starts a process and wait for its completion

func (*CommandExecutor) ExecuteCommandWithCombinedOutput added in v0.3.0

func (*CommandExecutor) ExecuteCommandWithCombinedOutput(command string, arg ...string) (string, error)

ExecuteCommandWithCombinedOutput executes a command with combined output

func (*CommandExecutor) ExecuteCommandWithEnv added in v1.7.3

func (*CommandExecutor) ExecuteCommandWithEnv(env []string, command string, arg ...string) error

ExecuteCommandWithEnv starts a process with env variables and wait for its completion

func (*CommandExecutor) ExecuteCommandWithOutput

func (*CommandExecutor) ExecuteCommandWithOutput(command string, arg ...string) (string, error)

ExecuteCommandWithOutput executes a command with output

func (*CommandExecutor) ExecuteCommandWithOutputFile added in v0.5.0

func (*CommandExecutor) ExecuteCommandWithOutputFile(command, outfileArg string, arg ...string) (string, error)

ExecuteCommandWithOutputFile executes a command with output on a file #nosec G307 Calling defer to close the file without checking the error return is not a risk for a simple file open and close

func (*CommandExecutor) ExecuteCommandWithOutputFileTimeout added in v1.1.0

func (*CommandExecutor) ExecuteCommandWithOutputFileTimeout(timeout time.Duration,
	command, outfileArg string, arg ...string) (string, error)

ExecuteCommandWithOutputFileTimeout Same as ExecuteCommandWithOutputFile but with a timeout limit. #nosec G307 Calling defer to close the file without checking the error return is not a risk for a simple file open and close

func (*CommandExecutor) ExecuteCommandWithTimeout added in v0.6.0

func (*CommandExecutor) ExecuteCommandWithTimeout(timeout time.Duration, command string, arg ...string) (string, error)

ExecuteCommandWithTimeout starts a process and wait for its completion with timeout.

type ExecOptions added in v1.7.3

type ExecOptions struct {
	Command       []string
	Namespace     string
	PodName       string
	ContainerName string
	Stdin         io.Reader
	CaptureStdout bool
	CaptureStderr bool
	// If false, whitespace in std{err,out} will be removed.
	PreserveWhitespace bool
}

ExecOptions passed to ExecWithOptions

type Executor

type Executor interface {
	ExecuteCommand(command string, arg ...string) error
	ExecuteCommandWithEnv(env []string, command string, arg ...string) error
	ExecuteCommandWithOutput(command string, arg ...string) (string, error)
	ExecuteCommandWithCombinedOutput(command string, arg ...string) (string, error)
	ExecuteCommandWithTimeout(timeout time.Duration, command string, arg ...string) (string, error)
}

Executor is the main interface for all the exec commands

type RemotePodCommandExecutor added in v1.7.3

type RemotePodCommandExecutor struct {
	ClientSet  kubernetes.Interface
	RestClient *rest.Config
}

RemotePodCommandExecutor is an exec.Executor that execs every command in a remote container This is especially useful when the CephCluster networking type is Multus and when the Operator pod does not have the right network annotations.

func (*RemotePodCommandExecutor) ExecCommandInContainerWithFullOutput added in v1.7.3

func (e *RemotePodCommandExecutor) ExecCommandInContainerWithFullOutput(appLabel, containerName, namespace string, cmd ...string) (string, string, error)

ExecCommandInContainerWithFullOutput executes a command in the specified container and return stdout, stderr and error

func (*RemotePodCommandExecutor) ExecCommandInContainerWithFullOutputWithTimeout added in v1.7.3

func (e *RemotePodCommandExecutor) ExecCommandInContainerWithFullOutputWithTimeout(appLabel, containerName, namespace string, cmd ...string) (string, string, error)

func (*RemotePodCommandExecutor) ExecWithOptions added in v1.7.3

func (e *RemotePodCommandExecutor) ExecWithOptions(options ExecOptions) (string, string, error)

ExecWithOptions executes a command in the specified container, returning stdout, stderr and error. `options` allowed for additional parameters to be passed.

type TranslateCommandExecutor added in v1.1.0

type TranslateCommandExecutor struct {

	// Executor is probably a exec.CommandExecutor that will run the translated commands
	Executor Executor

	// Translator translates every command before running it
	Translator func(command string, arg ...string) (string, []string)
}

TranslateCommandExecutor is an exec.Executor that translates every command before executing it This is useful to run the commands in a job with `kubectl run ...` when running the operator outside of Kubernetes and need to run tools that require running inside the cluster.

func (*TranslateCommandExecutor) ExecuteCommand added in v1.1.0

func (e *TranslateCommandExecutor) ExecuteCommand(command string, arg ...string) error

ExecuteCommand starts a process and wait for its completion

func (*TranslateCommandExecutor) ExecuteCommandWithCombinedOutput added in v1.1.0

func (e *TranslateCommandExecutor) ExecuteCommandWithCombinedOutput(command string, arg ...string) (string, error)

ExecuteCommandWithCombinedOutput starts a process and returns its stdout and stderr combined.

func (*TranslateCommandExecutor) ExecuteCommandWithEnv added in v1.7.3

func (e *TranslateCommandExecutor) ExecuteCommandWithEnv(env []string, command string, arg ...string) error

ExecuteCommandWithEnv starts a process with an env variable and wait for its completion

func (*TranslateCommandExecutor) ExecuteCommandWithOutput added in v1.1.0

func (e *TranslateCommandExecutor) ExecuteCommandWithOutput(command string, arg ...string) (string, error)

ExecuteCommandWithOutput starts a process and wait for its completion

func (*TranslateCommandExecutor) ExecuteCommandWithTimeout added in v1.1.0

func (e *TranslateCommandExecutor) ExecuteCommandWithTimeout(timeout time.Duration, command string, arg ...string) (string, error)

ExecuteCommandWithTimeout starts a process and wait for its completion with timeout.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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