diff --git a/pkg/topology/transport/podexec/transport.go b/pkg/topology/transport/podexec/transport.go index 713c306..f23de5f 100644 --- a/pkg/topology/transport/podexec/transport.go +++ b/pkg/topology/transport/podexec/transport.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "time" + "fmt" "github.com/tarantool/tarantool-operator/pkg/topology/transport/podexec/cli" v1 "k8s.io/api/core/v1" @@ -16,6 +17,8 @@ const ( resource = "pods" subResource = "exec" defaultTimeout = 2 * time.Second + // use this pod annotation to set cartridge container name if pod has sidecars + cartridgeContainerNameAnnotation = "tarantool.io/cartridge-container-name" ) type PodExec struct { @@ -34,6 +37,17 @@ func (r *PodExec) Exec(ctx context.Context, pod *v1.Pod, res interface{}, lua st return err } + // if pod has more than 1 container use annotation to get cartridge container name + if len(pod.Spec.Containers) > 1 { + cartridgeContainerName, ok := pod.Annotations[cartridgeContainerNameAnnotation] + + if !ok { + return fmt.Errorf("pod %s contains more than one container. use pod annotation %s to set cartridge container name", pod.GetName(), cartridgeContainerNameAnnotation) + } + + r.ContainerName = cartridgeContainerName + } + stdout, err := r.execShellCommand(ctx, command, pod.GetName(), pod.GetNamespace()) if err != nil { return err