From cf69571199d047f2d4c5adf7287deca80adea90b Mon Sep 17 00:00:00 2001 From: yimgzz <48012999+yimgzz@users.noreply.github.com> Date: Fri, 21 Jun 2024 12:50:04 +0300 Subject: [PATCH 1/2] use annotation to detect cartridge container name if pod has sidecars --- pkg/topology/transport/podexec/transport.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/topology/transport/podexec/transport.go b/pkg/topology/transport/podexec/transport.go index 713c306..22ca379 100644 --- a/pkg/topology/transport/podexec/transport.go +++ b/pkg/topology/transport/podexec/transport.go @@ -16,6 +16,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 +36,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 From 036b67dbc8d85c9e0e5c894c686ce4a05d608703 Mon Sep 17 00:00:00 2001 From: yimgzz <48012999+yimgzz@users.noreply.github.com> Date: Fri, 21 Jun 2024 15:07:24 +0300 Subject: [PATCH 2/2] add fmt import --- pkg/topology/transport/podexec/transport.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/topology/transport/podexec/transport.go b/pkg/topology/transport/podexec/transport.go index 22ca379..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"