cmds

package
v1.11.2 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Find

func Find(slice []string, option string) (int, bool)

Find checks if a slice contains a string and at which position

func UpdateAdmintoolsCmd

func UpdateAdmintoolsCmd(passwd string, cmd ...string) []string

UpdateAdmintoolsCmd generates an admintools command appending the options we need

func UpdateVsqlCmd

func UpdateVsqlCmd(passwd string, cmd ...string) []string

UpdateVsqlCmd generates a vsql command appending the options we need

Types

type ClusterPodRunner

type ClusterPodRunner struct {
	Log        logr.Logger
	Cfg        *rest.Config
	SUPassword string
}

func MakeClusterPodRunner

func MakeClusterPodRunner(log logr.Logger, cfg *rest.Config, passwd string) *ClusterPodRunner

MakeClusterPodRunnerr will build a ClusterPodRunner object

func (*ClusterPodRunner) CopyToPod added in v1.1.0

func (c *ClusterPodRunner) CopyToPod(ctx context.Context, podName types.NamespacedName,
	contName string, sourceFile string, destFile string, executeCmd ...string) (stdout, stderr string, err error)

CopyToPod copies a file into a container's pod. Optionally, it can also run a command after the copy has finished.

func (*ClusterPodRunner) DumpAdmintoolsConf added in v1.11.2

func (c *ClusterPodRunner) DumpAdmintoolsConf(ctx context.Context, podName types.NamespacedName)

DumpAdmintoolsConf will log relenvant portions of the admintools.conf for debug purposes.

func (*ClusterPodRunner) ExecAdmintools

func (c *ClusterPodRunner) ExecAdmintools(ctx context.Context, podName types.NamespacedName,
	contName string, command ...string) (stdout, stderr string, err error)

ExecAdmintools appends options to the admintools command and calls ExecInPod

func (*ClusterPodRunner) ExecInPod

func (c *ClusterPodRunner) ExecInPod(ctx context.Context, podName types.NamespacedName,
	contName string, command ...string) (stdout, stderr string, err error)

ExecInPod executes arbitrary command inside of a pod and returns the output.

func (*ClusterPodRunner) ExecVSQL

func (c *ClusterPodRunner) ExecVSQL(ctx context.Context, podName types.NamespacedName,
	contName string, command ...string) (stdout, stderr string, err error)

ExecVSQL appends options to the vsql command and calls ExecInPod

type CmdHistory

type CmdHistory struct {
	Pod     types.NamespacedName
	Command []string
}

CmdHistory stores the command that was run and the pod it was run against.

type CmdResult

type CmdResult struct {
	Stdout string
	Stderr string
	Err    error
}

CmdResult stores the result of a single command.

type CmdResults

type CmdResults map[types.NamespacedName][]CmdResult

CmdResults stores the command result. The key is the pod name.

type FakePodRunner

type FakePodRunner struct {
	// The fake result of calls made.  This *must* be filled in prior to ExecInPod.
	Results CmdResults
	// The commands that were issue. The commands are in the same order that
	// commands were received. This is filled in by ExecInPod and can be inspected.
	Histories []CmdHistory
	// fake password
	SUPassword string
}

FakePodRunner is stub that we use in testing to take output from exec calls. The CmdResult are prepopulated results to commands. Each command given is for a specific pod. This allows us to build up the result for each successive exec call to that pod. This class also keeps track of the commands that were passed to ExecInPod. These can be inspected at the end of the test to verify assertions.

func (*FakePodRunner) CopyToPod added in v1.1.0

func (f *FakePodRunner) CopyToPod(ctx context.Context, podName types.NamespacedName,
	contName string, sourceFile string, destFile string, executeCmd ...string) (stdout, stderr string, err error)

CopyToPod will mimic a real copy file into a pod

func (*FakePodRunner) DumpAdmintoolsConf added in v1.11.2

func (f *FakePodRunner) DumpAdmintoolsConf(ctx context.Context, podName types.NamespacedName)

DumpAdmintoolsConf will log relenvant portions of the admintools.conf for debug purposes.

func (*FakePodRunner) ExecAdmintools

func (f *FakePodRunner) ExecAdmintools(ctx context.Context, podName types.NamespacedName,
	contName string, command ...string) (stdout, stderr string, err error)

ExecAdmintools calls ExecInPod

func (*FakePodRunner) ExecInPod

func (f *FakePodRunner) ExecInPod(ctx context.Context, podName types.NamespacedName,
	contName string, command ...string) (stdout, stderr string, err error)

ExecInPod is a test stub for a real exec call to a pod. It will return output as saved in the FakePodRunner struct. The command that is passed in are saved as a history that tests can later inspect.

func (*FakePodRunner) ExecVSQL

func (f *FakePodRunner) ExecVSQL(ctx context.Context, podName types.NamespacedName,
	contName string, command ...string) (stdout, stderr string, err error)

ExecVSQL calls ExecInPod

func (*FakePodRunner) FindCommands

func (f *FakePodRunner) FindCommands(partialCmd ...string) []CmdHistory

FindCommands will search through the command history for any command that contains the given partial command.

type PodRunner

type PodRunner interface {
	ExecInPod(ctx context.Context, podName types.NamespacedName, contName string, command ...string) (string, string, error)
	ExecVSQL(ctx context.Context, podName types.NamespacedName, contName string, command ...string) (string, string, error)
	ExecAdmintools(ctx context.Context, podName types.NamespacedName, contName string, command ...string) (string, string, error)
	CopyToPod(ctx context.Context, podName types.NamespacedName, contName string, sourceFile string,
		destFile string, executeCmd ...string) (stdout, stderr string, err error)
	DumpAdmintoolsConf(ctx context.Context, podName types.NamespacedName)
}

Jump to

Keyboard shortcuts

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