Documentation
¶
Overview ¶
Package kubernetes is our main interface on top of the Kubernetes API Currently, we directly control Pods. Alternatively we may opt for the Kubernetes Job abstraction if it provides enough low-level access today
Index ¶
- func CopyFileFromPod(ctx context.Context, podName string, containerName string, sourcePath string, ...) error
- func CopyFileToPod(ctx context.Context, podName string, containerName string, sourcePath string, ...) error
- func CreatePod(ctx context.Context, pod *apiv1.Pod) (*apiv1.Pod, error)
- func DeletePod(ctx context.Context, podName string) error
- func ExecBashInContainer(ctx context.Context, nameSpace, podName, containerName, cmd string) (string, string, error)
- func ExecCommandInContainer(ctx context.Context, nameSpace, podName, containerName string, cmd ...string) (string, string, error)
- func ExecShellInContainer(ctx context.Context, nameSpace, podName, containerName, cmd string) (string, string, error)
- func ExecShellInContainerWithEnvVars(ctx context.Context, namespace string, podName string, containerName string, ...) (string, string, error)
- func ExecWithOptions(options ExecOptions) (string, string, error)
- func Init(ctx context.Context) error
- func PodExists(ctx context.Context, podName string) (bool, error)
- func WatchErrors() <-chan error
- type ExecOptions
- type PodWatcher
- type RunningPodSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyFileFromPod ¶
func CopyFileFromPod(ctx context.Context, podName string, containerName string, sourcePath string, destPath string, keepFile bool) error
CopyFileFromPod is a function that copies a file from a specified Pod and container to the local filesystem. Parameters:
- podName: A string containing the name of the Pod from which the file should be copied.
- containerName: A string containing the name of the container from which the file should be copied.
- sourcePath: A string containing the path to the file in the Pod that should be copied.
- destPath: A string containing the path to the destination file on the local filesystem.
- keepFile: A boolean value indicating whether the file should be kept in the Pod after copying.
Returns:
- An error if there were any issues encountered during the file copy process.
func CopyFileToPod ¶
func CopyFileToPod(ctx context.Context, podName string, containerName string, sourcePath string, destPath string) error
CopyFileToPod is a function that copies a file to a specified Pod and container from the local filesystem. Parameters:
- podName: A string containing the name of the Pod to which the file should be copied.
- containerName: A string containing the name of the container to which the file should be copied.
- sourcePath: A string containing the path to the source file on the local filesystem.
- destPath: A string containing the path to the destination file in the Pod.
Returns:
- An error if there were any issues encountered during the file copy process.
func CreatePod ¶
CreatePod is a function that takes a pointer to a Kubernetes Pod object as input. It uses the Kubernetes client to create the new Pod, and returns the new Pod object along with any errors encountered during the creation process.
Parameters:
- pod: A pointer to the Kubernetes Pod object that needs to be created.
Returns:
- A pointer to the new Kubernetes Pod object that was created by the function.
- An error if there were any issues encountered during the creation process.
func DeletePod ¶
DeletePod is a function that takes a string containing the name of a Pod as input. It deletes the specified Pod from the Kubernetes cluster using the Kubernetes client.
Parameters:
- podName: A string containing the name of the Pod that needs to be deleted.
Returns:
- An error if there were any issues encountered during the Pod deletion process.
func ExecBashInContainer ¶
func ExecBashInContainer(ctx context.Context, nameSpace, podName, containerName, cmd string) (string, string, error)
ExecShellInContainer is a function that launches a command in the specified container using sh. It takes the namespace, pod name, container name, and command as input parameters and returns the stdout and stderr outputs of the command. This function is used in the main function.
Parameters:
- nameSpace: A string containing the name of the namespace in which the pod is running.
- podName: A string containing the name of the pod in which the container is running.
- containerName: A string containing the name of the container in which the command is to be executed.
- cmd: A string containing the command to be executed using sh.
Returns:
- stdout: A string containing the standard output of the executed command.
- stderr: A string containing the standard error output of the executed command.
func ExecCommandInContainer ¶
func ExecCommandInContainer(ctx context.Context, nameSpace, podName, containerName string, cmd ...string) (string, string, error)
ExecCommandInContainerWithFullOutput is a function that executes a command in a specified container and returns the stdout, stderr, and error using the Kubernetes client. It uses the ExecWithOptions function to execute the command at the API level. The function takes the namespace, pod name, container name, and command as input parameters.
Parameters:
- nameSpace: A string representing the namespace of the pod.
- podName: A string representing the name of the pod.
- containerName: A string representing the name of the container.
- cmd: A variadic parameter of strings representing the command to be executed in the container.
Returns:
- stdout: A string containing the standard output of the executed command.
- stderr: A string containing the standard error output of the executed command.
- error: An error object indicating any errors encountered while executing the command.
func ExecShellInContainer ¶
func ExecShellInContainer(ctx context.Context, nameSpace, podName, containerName, cmd string) (string, string, error)
ExecShellInContainer is a function that launches a command in the specified container using sh. It takes the namespace, pod name, container name, and command as input parameters and returns the stdout and stderr outputs of the command. This function is used in the main function.
Parameters:
- nameSpace: A string containing the name of the namespace in which the pod is running.
- podName: A string containing the name of the pod in which the container is running.
- containerName: A string containing the name of the container in which the command is to be executed.
- cmd: A string containing the command to be executed using sh.
Returns:
- stdout: A string containing the standard output of the executed command.
- stderr: A string containing the standard error output of the executed command.
func ExecWithOptions ¶
func ExecWithOptions(options ExecOptions) (string, string, error)
ExecWithOptions is a function that executes a command in a specified container using the Kubernetes API. The function takes an ExecOptions struct as input, which includes the name of the Pod and Container to execute the command in, the command to execute, and additional options such as whether to capture stdout and stderr, whether to preserve whitespace in output, and whether to use a TTY.
Parameters:
- options: an ExecOptions struct containing the necessary information to execute the command.
Returns:
- stdout: a string containing the standard output of the command execution.
- stderr: a string containing the standard error of the command execution.
- err: an error object that indicates whether an error occurred while executing the command.
func PodExists ¶
PodExists checks if a Pod with the specified name exists in the cluster using the Kubernetes client. If the Pod exists, the function returns true. If the Pod does not exist, the function returns false.
Parameters:
- podName: A string containing the name of the Pod whose existence needs to be checked.
Returns:
- A boolean value indicating whether the specified Pod exists or not.
- An error if there were any issues encountered during the existence check process.
func WatchErrors ¶
func WatchErrors() <-chan error
WatchErrors returns asynchronous pod watcher failures.
Types ¶
type ExecOptions ¶
type PodWatcher ¶
type PodWatcher struct {
// contains filtered or unexported fields
}
func NewPodWatcher ¶
func NewPodWatcher(podsClient v1.PodInterface) PodWatcher
func (*PodWatcher) WaitForPodReady ¶
WaitForPodReady blocks until the pod is in the running phase and all the containers are ready.
First it adds the pod with a corresponding channel to the eventsChans map for PodWatcher. Then it waits for updates from the PodWatcher for the desired phase to be reached.
type RunningPodSpec ¶
type RunningPodSpec struct {
PodName string
ContainerImage string
ContainerName string
PodIP string
}
func CreateReadyPod ¶
CreateReadyPod is a function that creates a Kubernetes Pod and waits for the Pod to be ready using the PodWatcher. The function returns a PodSpec containing the relevant specifications of the created Pod.
Parameters:
- pod: A pointer to the Kubernetes Pod object that needs to be created.
Returns:
- A PodSpec struct containing the specifications of the created Pod.
- An error if there were any issues encountered during the Pod creation process.
func SetPodSpec ¶
func SetPodSpec(pod *apiv1.Pod) RunningPodSpec
SetPodSpec is a helper function that returns a structured object that contains some of the relevant specifications of the given Kubernetes Pod. It extracts the Pod's name, container imag, container name, and Pod IP from the provided Pod variable, and organizes them into a flat struct of type RunningPodSpec.
Parameters:
- pod: A pointer to the Kubernetes Pod whose specifications are to be extracted.
Returns:
- A PodSpec object containing the specifications of the given Pod.