Skip to content

Commit b88de84

Browse files
authored
Fix empty pod owner name when connecting to agent (#4367)
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.
1 parent 2a64f38 commit b88de84

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

internal/controller/nginx/agent/command.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ func (cs *commandService) CreateConnection(
8484

8585
resource := req.GetResource()
8686
podName := resource.GetContainerInfo().GetHostname()
87+
if podName == "" {
88+
podName = resource.GetHostInfo().GetHostname()
89+
}
8790
cs.logger.Info(fmt.Sprintf("Creating connection for nginx pod: %s", podName))
8891

8992
owner, _, err := cs.getPodOwner(podName)

internal/controller/nginx/agent/command_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,32 @@ func TestCreateConnection(t *testing.T) {
163163
},
164164
},
165165
},
166+
{
167+
name: "uses regular hostname if container info not set",
168+
ctx: createGrpcContext(),
169+
request: &pb.CreateConnectionRequest{
170+
Resource: &pb.Resource{
171+
Info: &pb.Resource_HostInfo{
172+
HostInfo: &pb.HostInfo{
173+
Hostname: "nginx-pod",
174+
},
175+
},
176+
Instances: []*pb.Instance{
177+
{
178+
InstanceMeta: &pb.InstanceMeta{
179+
InstanceId: "nginx-id",
180+
InstanceType: pb.InstanceMeta_INSTANCE_TYPE_NGINX,
181+
},
182+
},
183+
},
184+
},
185+
},
186+
response: &pb.CreateConnectionResponse{
187+
Response: &pb.CommandResponse{
188+
Status: pb.CommandResponse_COMMAND_STATUS_OK,
189+
},
190+
},
191+
},
166192
{
167193
name: "request is nil",
168194
request: nil,

0 commit comments

Comments
 (0)