From a26a62d89b90e5e5477e9c7491b47ea33c3ae410 Mon Sep 17 00:00:00 2001 From: Saylor Berman Date: Mon, 1 Dec 2025 11:45:05 -0700 Subject: [PATCH] Fix empty pod owner name when connecting to agent Problem: Saw an issue where nginx failed to connect to the control plane due to an empty hostname and not being able to find the pod name. Solution: If ContainerInfo provided by agent is empty, fall back to HostInfo. This should cover all bases to ensure we get the hostname. --- internal/controller/nginx/agent/command.go | 3 +++ .../controller/nginx/agent/command_test.go | 26 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/internal/controller/nginx/agent/command.go b/internal/controller/nginx/agent/command.go index f3095f7398..2348d02e86 100644 --- a/internal/controller/nginx/agent/command.go +++ b/internal/controller/nginx/agent/command.go @@ -84,6 +84,9 @@ func (cs *commandService) CreateConnection( resource := req.GetResource() podName := resource.GetContainerInfo().GetHostname() + if podName == "" { + podName = resource.GetHostInfo().GetHostname() + } cs.logger.Info(fmt.Sprintf("Creating connection for nginx pod: %s", podName)) owner, _, err := cs.getPodOwner(podName) diff --git a/internal/controller/nginx/agent/command_test.go b/internal/controller/nginx/agent/command_test.go index 5acde66376..7b5830bcd8 100644 --- a/internal/controller/nginx/agent/command_test.go +++ b/internal/controller/nginx/agent/command_test.go @@ -163,6 +163,32 @@ func TestCreateConnection(t *testing.T) { }, }, }, + { + name: "uses regular hostname if container info not set", + ctx: createGrpcContext(), + request: &pb.CreateConnectionRequest{ + Resource: &pb.Resource{ + Info: &pb.Resource_HostInfo{ + HostInfo: &pb.HostInfo{ + Hostname: "nginx-pod", + }, + }, + Instances: []*pb.Instance{ + { + InstanceMeta: &pb.InstanceMeta{ + InstanceId: "nginx-id", + InstanceType: pb.InstanceMeta_INSTANCE_TYPE_NGINX, + }, + }, + }, + }, + }, + response: &pb.CreateConnectionResponse{ + Response: &pb.CommandResponse{ + Status: pb.CommandResponse_COMMAND_STATUS_OK, + }, + }, + }, { name: "request is nil", request: nil,