MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / CommandInContainer

Function CommandInContainer

tests/utils/exec/exec.go:49–70  ·  view source on GitHub ↗

CommandInContainer executes commands in a given instance pod, in the postgres container

(
	ctx context.Context,
	crudClient client.Client,
	kubeInterface kubernetes.Interface,
	restConfig *rest.Config,
	container ContainerLocator,
	timeout *time.Duration,
	command ...string,
)

Source from the content-addressed store, hash-verified

47// CommandInContainer executes commands in a given instance pod, in the
48// postgres container
49func CommandInContainer(
50 ctx context.Context,
51 crudClient client.Client,
52 kubeInterface kubernetes.Interface,
53 restConfig *rest.Config,
54 container ContainerLocator,
55 timeout *time.Duration,
56 command ...string,
57) (string, string, error) {
58 wrapErr := func(err error) error {
59 return fmt.Errorf("while executing command in pod '%s/%s': %w",
60 container.Namespace, container.PodName, err)
61 }
62 pod, err := pods.Get(ctx, crudClient, container.Namespace, container.PodName)
63 if err != nil {
64 return "", "", wrapErr(err)
65 }
66 if !pkgutils.IsPodReady(*pod) {
67 return "", "", fmt.Errorf("pod not ready. Namespace: %v, Name: %v", pod.Namespace, pod.Name)
68 }
69 return Command(ctx, kubeInterface, restConfig, *pod, container.ContainerName, timeout, command...)
70}
71
72// PodLocator contains the necessary data to find a pod
73type PodLocator struct {

Callers 1

CommandInInstancePodFunction · 0.85

Calls 2

GetFunction · 0.92
CommandFunction · 0.70

Tested by

no test coverage detected