Skip to content

Support for case when pod has sidecar containers #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pkg/topology/transport/podexec/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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
Expand Down