client

package
v0.76.0-devel Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: Apache-2.0 Imports: 50 Imported by: 0

Documentation

Overview

Package client contains the definitions of the different clients that can be used in a test.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AgentSelectorAnyPod

func AgentSelectorAnyPod(agentType kubernetes.KubernetesObjRefOutput) metav1.ListOptions

AgentSelectorAnyPod creates a selector for any pod that runs the agent of the given type. For example, you can pass Agent.LinuxNodeAgent to select any pod that runs the node agent.

func DefaultWindowsAgentInstallPath

func DefaultWindowsAgentInstallPath(host *Host) string

DefaultWindowsAgentInstallPath returns a reasonable default for the AgentInstallPath.

If the Agent is installed, the installPath is read from the registry. If the registry key is not found, returns the default install path.

func NewDockerAgentClient

func NewDockerAgentClient(context common.Context, dockerAgentOutput agent.DockerAgentOutput, options ...agentclientparams.Option) (agentclient.Agent, error)

NewDockerAgentClient creates an Agent client for a Docker install

func NewHostAgentClient

func NewHostAgentClient(context common.Context, hostOutput remote.HostOutput, waitForAgentReady bool) (agentclient.Agent, error)

NewHostAgentClient creates an Agent client for host install

func NewHostAgentClientWithParams

func NewHostAgentClientWithParams(context common.Context, hostOutput remote.HostOutput, options ...agentclientparams.Option) (agentclient.Agent, error)

NewHostAgentClientWithParams creates an Agent client for host install with custom parameters

func NewK8sAgentClient

func NewK8sAgentClient(context common.Context, podSelector metav1.ListOptions, clusterClient *KubernetesClient, options ...agentclientparams.Option) (agentclient.Agent, error)

NewK8sAgentClient creates an Agent client for a Kubernetes install, passing the ListOptions to select the pod that runs the agent. There are some helper functions to create common selectors, such as AgentSelectorAnyPod that will select any pod that runs the agent.

Types

type Docker

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

A Docker client that is connected to an docker.Deamon.

func NewDocker

func NewDocker(t *testing.T, dockerOutput docker.ManagerOutput) (*Docker, error)

NewDocker creates a new instance of Docker NOTE: docker+ssh does not support password protected SSH keys.

func (*Docker) DownloadFile

func (docker *Docker) DownloadFile(containerName, containerPath, localPath string) error

DownloadFile downloads a file or directory from the container to the local filesystem.

func (*Docker) ExecuteCommand

func (docker *Docker) ExecuteCommand(containerName string, commands ...string) string

ExecuteCommand executes a command on containerName and returns the output.

func (*Docker) ExecuteCommandStdoutStdErr

func (docker *Docker) ExecuteCommandStdoutStdErr(containerName string, commands ...string) (stdout string, stderr string, err error)

ExecuteCommandStdoutStdErr executes a command on containerName and returns the output, the error output and an error.

func (*Docker) ExecuteCommandWithErr

func (docker *Docker) ExecuteCommandWithErr(containerName string, commands ...string) (string, error)

ExecuteCommandWithErr executes a command on containerName and returns the output and an error.

func (*Docker) ListContainers

func (docker *Docker) ListContainers() ([]string, error)

ListContainers returns a list of container names.

type EC2Metadata

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

EC2Metadata contains a pointer to a VM and its AWS token

func NewEC2Metadata

func NewEC2Metadata(t *testing.T, h *Host, osFamily os.Family) *EC2Metadata

NewEC2Metadata creates a new EC2Metadata given an EC2 [VM]

func (*EC2Metadata) Get

func (m *EC2Metadata) Get(name string) string

Get returns EC2 instance name

type EnvVar

type EnvVar map[string]string

EnvVar alias to map representing env variables

type ExecuteOption

type ExecuteOption func(*ExecuteParams) error

ExecuteOption alias to a functional option changing a given Params instance

func WithEnvVariables

func WithEnvVariables(env EnvVar) ExecuteOption

WithEnvVariables allows to set env variable for the command that will be executed

type ExecuteParams

type ExecuteParams struct {
	EnvVariables EnvVar
}

ExecuteParams contains parameters for VM.Execute commands

type Host

type Host struct {
	HostArtifactClient
	// contains filtered or unexported fields
}

A Host client that is connected to an ssh.Client.

func NewHost

func NewHost(context common.Context, hostOutput remote.HostOutput) (*Host, error)

NewHost creates a new ssh client to connect to a remote host with reconnect retry logic

func (*Host) AppendFile

func (h *Host) AppendFile(os, path string, content []byte) (int64, error)

AppendFile append content to the file and returns the number of bytes appened and error if any

func (*Host) CopyFile

func (h *Host) CopyFile(src string, dst string)

CopyFile creates a sftp session and copy a single file to the remote host through SSH

func (*Host) CopyFileFromFS

func (h *Host) CopyFileFromFS(fs fs.FS, src, dst string)

CopyFileFromFS creates a sftp session and copy a single embedded file to the remote host through SSH

func (*Host) CopyFolder

func (h *Host) CopyFolder(srcFolder string, dstFolder string) error

CopyFolder create a sftp session and copy a folder to remote host through SSH

func (*Host) DialPort

func (h *Host) DialPort(port uint16) (net.Conn, error)

DialPort creates a connection from the remote host to its `port`.

func (*Host) EnsureFileIsReadable

func (h *Host) EnsureFileIsReadable(path string) error

EnsureFileIsReadable add readable rights to a remote file

func (Host) Execute

func (h Host) Execute(command string, options ...ExecuteOption) (string, error)

Execute executes a command and returns an error if any.

func (*Host) FileExists

func (h *Host) FileExists(path string) (bool, error)

FileExists create a sftp session to and returns true if the file exists and is a regular file

func (*Host) FindFiles

func (h *Host) FindFiles(name string) ([]string, error)

FindFiles returns a list of files with a given name

func (*Host) GetAgentConfigFolder

func (h *Host) GetAgentConfigFolder() (string, error)

GetAgentConfigFolder returns the agent config folder path for the host

func (*Host) GetFile

func (h *Host) GetFile(src string, dst string) error

GetFile create a sftp session and copy a single file from the remote host through SSH

func (*Host) GetFolder

func (h *Host) GetFolder(srcFolder string, dstFolder string) error

GetFolder create a sftp session and copy a folder from the remote host through SSH

func (*Host) GetLogsFolder

func (h *Host) GetLogsFolder() (string, error)

GetLogsFolder returns the logs folder path for the host

func (*Host) GetTmpFolder

func (h *Host) GetTmpFolder() (string, error)

GetTmpFolder returns the temporary folder path for the host

func (*Host) HTTPTransport

func (h *Host) HTTPTransport() http.RoundTripper

HTTPTransport returns an http.RoundTripper which dials the remote host. This transport can only reach the host.

func (*Host) JoinPath

func (h *Host) JoinPath(path ...string) string

JoinPath joins the path elements with the correct separator for the host

func (*Host) Lstat

func (h *Host) Lstat(path string) (fs.FileInfo, error)

Lstat returns a FileInfo structure describing path. if path is a symbolic link, the FileInfo structure describes the symbolic link.

func (*Host) MkdirAll

func (h *Host) MkdirAll(path string) error

MkdirAll creates the specified directory along with any necessary parents. If the path is already a directory, does nothing and returns nil. Otherwise returns an error if any.

func (Host) MustExecute

func (h Host) MustExecute(command string, options ...ExecuteOption) string

MustExecute executes a command and requires no error.

func (*Host) NewHTTPClient

func (h *Host) NewHTTPClient() *http.Client

NewHTTPClient returns an *http.Client which dials the remote host. This client can only reach the host.

func (*Host) ReadDir

func (h *Host) ReadDir(path string) ([]fs.DirEntry, error)

ReadDir returns list of directory entries in path

func (*Host) ReadFile

func (h *Host) ReadFile(path string) ([]byte, error)

ReadFile reads the content of the file, return bytes read and error if any

func (*Host) ReadFilePrivileged

func (h *Host) ReadFilePrivileged(path string) ([]byte, error)

ReadFilePrivileged reads the content of the file with a privileged user, return bytes read and error if any

func (Host) Reconnect

func (h Host) Reconnect() error

Reconnect closes the current ssh client and creates a new one, with retries.

func (*Host) Remove

func (h *Host) Remove(path string) error

Remove removes the specified file or directory. Returns an error if file or directory does not exist, or if the directory is not empty.

func (*Host) RemoveAll

func (h *Host) RemoveAll(path string) error

RemoveAll recursively removes all files/folders in the specified directory. Returns an error if the directory does not exist.

func (Host) Start

func (h Host) Start(command string, options ...ExecuteOption) (*ssh.Session, io.WriteCloser, io.Reader, error)

Start a command and returns session, and an error if any.

func (*Host) WriteFile

func (h *Host) WriteFile(path string, content []byte) (int64, error)

WriteFile write content to the file and returns the number of bytes written and error if any

type HostArtifactClient

type HostArtifactClient interface {
	Get(path string, destPath string) error
}

HostArtifactClient is a client that can get files from the artifact bucket to the remote host

type KubernetesClient

type KubernetesClient struct {
	K8sConfig *rest.Config
	K8sClient kubeClient.Interface
}

KubernetesClient is a wrapper around the k8s client library and provides convenience methods for interacting with a k8s cluster

func NewKubernetesClient

func NewKubernetesClient(config *rest.Config) (*KubernetesClient, error)

NewKubernetesClient creates a new KubernetesClient

func (*KubernetesClient) DownloadFromPod

func (k *KubernetesClient) DownloadFromPod(namespace, podName, container, srcPath, destPath string) error

DownloadFromPod downloads a folder from a pod to a local destination

func (*KubernetesClient) PodExec

func (k *KubernetesClient) PodExec(namespace, pod, container string, cmd []string, podOptions ...PodExecOption) (stdout, stderr string, err error)

PodExec execs into a given namespace/pod and returns the output for the given command

type PodExecOption

type PodExecOption func(*corev1.PodExecOptions)

PodExecOption is a function that can be used to modify the PodExecOptions

Directories

Path Synopsis
Package agentclient provides an interface to run Agent commands.
Package agentclient provides an interface to run Agent commands.
Package agentclientparams implements function parameters for [e2e.Agent]
Package agentclientparams implements function parameters for [e2e.Agent]

Jump to

Keyboard shortcuts

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