Skip to content

Commit f80228b

Browse files
committed
put TODO for agw
Signed-off-by: omar <[email protected]>
1 parent ba7ba13 commit f80228b

File tree

4 files changed

+137
-2
lines changed

4 files changed

+137
-2
lines changed

pkg/kgateway/deployer/agentgateway_parameters.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,8 @@ func (g *agentgatewayParametersHelmValuesGenerator) applyGatewayParametersToHelm
479479
}
480480

481481
svcConfig := gwp.Spec.Kube.GetService()
482-
vals.Gateway.Service = deployer.GetServiceValues(svcConfig)
482+
// TODO: extract loadBalancerIP from Gateway.spec.addresses if service type is LoadBalancer
483+
vals.Gateway.Service = deployer.GetServiceValues(svcConfig, nil)
483484

484485
svcAccountConfig := gwp.Spec.Kube.GetServiceAccount()
485486
vals.Gateway.ServiceAccount = deployer.GetServiceAccountValues(svcAccountConfig)

pkg/kgateway/deployer/gateway_parameters.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ func extractLoadBalancerIP(gw *gwv1.Gateway) *string {
361361
}
362362

363363
if len(gw.Spec.Addresses) > 1 {
364-
slog.Warn("multiple IP addresses found in Gateway.spec.addresses, using first valid one",
364+
slog.Warn("multiple addresses found in Gateway.spec.addresses, using first valid IP address",
365365
"gateway", fmt.Sprintf("%s/%s", gw.Namespace, gw.Name),
366366
"count", len(gw.Spec.Addresses),
367367
)

pkg/kgateway/deployer/gateway_parameters_test.go

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,3 +332,133 @@ func newCommonCols(t test.Failer, initObjs ...client.Object) *collections.Common
332332
gateways.Gateways.WaitUntilSynced(ctx.Done())
333333
return commonCols
334334
}
335+
336+
func TestExtractLoadBalancerIP(t *testing.T) {
337+
tests := []struct {
338+
name string
339+
addresses []gwv1.GatewaySpecAddress
340+
want *string
341+
}{
342+
{
343+
name: "single valid IPv4 address",
344+
addresses: []gwv1.GatewaySpecAddress{
345+
{Type: ptr.To(gwv1.IPAddressType), Value: "203.0.113.10"},
346+
},
347+
want: ptr.To("203.0.113.10"),
348+
},
349+
{
350+
name: "single valid IPv6 address",
351+
addresses: []gwv1.GatewaySpecAddress{
352+
{Type: ptr.To(gwv1.IPAddressType), Value: "2001:db8::1"},
353+
},
354+
want: ptr.To("2001:db8::1"),
355+
},
356+
{
357+
name: "nil address type defaults to IPAddressType",
358+
addresses: []gwv1.GatewaySpecAddress{
359+
{Type: nil, Value: "192.0.2.1"},
360+
},
361+
want: ptr.To("192.0.2.1"),
362+
},
363+
{
364+
name: "empty addresses array",
365+
addresses: []gwv1.GatewaySpecAddress{},
366+
want: nil,
367+
},
368+
{
369+
name: "multiple valid IP addresses uses first one",
370+
addresses: []gwv1.GatewaySpecAddress{
371+
{Type: ptr.To(gwv1.IPAddressType), Value: "203.0.113.10"},
372+
{Type: ptr.To(gwv1.IPAddressType), Value: "203.0.113.11"},
373+
},
374+
want: ptr.To("203.0.113.10"),
375+
},
376+
{
377+
name: "multiple IP addresses with invalid format skips invalid and uses first valid",
378+
addresses: []gwv1.GatewaySpecAddress{
379+
{Type: ptr.To(gwv1.IPAddressType), Value: "invalid-ip"},
380+
{Type: ptr.To(gwv1.IPAddressType), Value: "203.0.113.10"},
381+
},
382+
want: ptr.To("203.0.113.10"),
383+
},
384+
{
385+
name: "mixed address types uses first IP address",
386+
addresses: []gwv1.GatewaySpecAddress{
387+
{Type: ptr.To(gwv1.HostnameAddressType), Value: "example.com"},
388+
{Type: ptr.To(gwv1.IPAddressType), Value: "203.0.113.10"},
389+
},
390+
want: ptr.To("203.0.113.10"),
391+
},
392+
{
393+
name: "all hostname addresses returns nil",
394+
addresses: []gwv1.GatewaySpecAddress{
395+
{Type: ptr.To(gwv1.HostnameAddressType), Value: "example.com"},
396+
{Type: ptr.To(gwv1.HostnameAddressType), Value: "test.example.com"},
397+
},
398+
want: nil,
399+
},
400+
{
401+
name: "all invalid IP addresses returns nil",
402+
addresses: []gwv1.GatewaySpecAddress{
403+
{Type: ptr.To(gwv1.IPAddressType), Value: "not-an-ip"},
404+
{Type: ptr.To(gwv1.IPAddressType), Value: "256.256.256.256"},
405+
},
406+
want: nil,
407+
},
408+
{
409+
name: "nil type with invalid IP skips and continues",
410+
addresses: []gwv1.GatewaySpecAddress{
411+
{Type: nil, Value: "invalid"},
412+
{Type: nil, Value: "203.0.113.10"},
413+
},
414+
want: ptr.To("203.0.113.10"),
415+
},
416+
{
417+
name: "IPv4 and IPv6 mixed uses first valid",
418+
addresses: []gwv1.GatewaySpecAddress{
419+
{Type: ptr.To(gwv1.IPAddressType), Value: "203.0.113.10"},
420+
{Type: ptr.To(gwv1.IPAddressType), Value: "2001:db8::1"},
421+
},
422+
want: ptr.To("203.0.113.10"),
423+
},
424+
{
425+
name: "IPv6 first in multiple addresses",
426+
addresses: []gwv1.GatewaySpecAddress{
427+
{Type: ptr.To(gwv1.IPAddressType), Value: "2001:db8::1"},
428+
{Type: ptr.To(gwv1.IPAddressType), Value: "203.0.113.10"},
429+
},
430+
want: ptr.To("2001:db8::1"),
431+
},
432+
{
433+
name: "hostname before IP address skips hostname",
434+
addresses: []gwv1.GatewaySpecAddress{
435+
{Type: ptr.To(gwv1.HostnameAddressType), Value: "example.com"},
436+
{Type: ptr.To(gwv1.IPAddressType), Value: "203.0.113.10"},
437+
{Type: ptr.To(gwv1.IPAddressType), Value: "203.0.113.11"},
438+
},
439+
want: ptr.To("203.0.113.10"),
440+
},
441+
}
442+
443+
for _, tt := range tests {
444+
t.Run(tt.name, func(t *testing.T) {
445+
gw := &gwv1.Gateway{
446+
ObjectMeta: metav1.ObjectMeta{
447+
Name: "test-gateway",
448+
Namespace: "default",
449+
},
450+
Spec: gwv1.GatewaySpec{
451+
Addresses: tt.addresses,
452+
},
453+
}
454+
455+
got := extractLoadBalancerIP(gw)
456+
if tt.want == nil {
457+
assert.Nil(t, got, "expected nil but got %v", got)
458+
} else {
459+
assert.NotNil(t, got, "expected non-nil result")
460+
assert.Equal(t, *tt.want, *got, "IP address mismatch")
461+
}
462+
})
463+
}
464+
}

test/deployer/internal_helm_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ wIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQBtestcertdata
135135
Name: "envoy-infrastructure",
136136
InputFile: "envoy-infrastructure",
137137
},
138+
{
139+
Name: "gateway with static IP address",
140+
InputFile: "loadbalancer-static-ip",
141+
},
138142
{
139143
Name: "agentgateway-params-primary",
140144
InputFile: "agentgateway-params-primary",

0 commit comments

Comments
 (0)