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,