From 0dd82c83fde655a9815c759d234954d2c9556965 Mon Sep 17 00:00:00 2001 From: xuriwuyun Date: Wed, 22 Nov 2023 15:26:01 +0800 Subject: [PATCH] fix: get lorry container (#5897) --- lorry/client/client.go | 2 +- pkg/controllerutil/pod_utils.go | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lorry/client/client.go b/lorry/client/client.go index a444c921250..58de6381778 100644 --- a/lorry/client/client.go +++ b/lorry/client/client.go @@ -315,7 +315,7 @@ func NewHTTPClientWithChannelPod(pod *corev1.Pod, characterType string) (*Operat if ip == "" { return nil, fmt.Errorf("pod %v has no ip", pod.Name) } - container, err := intctrlutil.GetProbeContainerName(pod) + container, err := intctrlutil.GetLorryContainerName(pod) if err != nil { return nil, err } diff --git a/pkg/controllerutil/pod_utils.go b/pkg/controllerutil/pod_utils.go index 9446a89f230..0b6d9f4b342 100644 --- a/pkg/controllerutil/pod_utils.go +++ b/pkg/controllerutil/pod_utils.go @@ -371,15 +371,16 @@ func GuessLorryHTTPPort(pod *corev1.Pod) (int32, error) { return 0, fmt.Errorf("lorry port not found") } -// GetProbeContainerName gets the probe container from pod -func GetProbeContainerName(pod *corev1.Pod) (string, error) { - lorryImage := viper.GetString(constant.KBToolsImage) +// GetLorryContainerName gets the probe container from pod +func GetLorryContainerName(pod *corev1.Pod) (string, error) { for _, container := range pod.Spec.Containers { - if container.Image == lorryImage { - return container.Name, nil + for _, port := range container.Ports { + if port.Name == constant.LorryHTTPPortName { + return container.Name, nil + } } } - return "", fmt.Errorf("container %s not found", lorryImage) + return "", fmt.Errorf("lorry container not found") }