Skip to content

Commit 8bdf40c

Browse files
committed
add TLS and UDP listener tests. Fix bugs that were found from the tests
1 parent 8c660cd commit 8bdf40c

25 files changed

+602
-309
lines changed

controllers/gateway/route_reconciler.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (d *routeReconcilerImpl) handleItemError(routeData routeutils.RouteData, er
7575
}
7676

7777
func (d *routeReconcilerImpl) handleRouteStatusUpdate(routeData routeutils.RouteData) error {
78-
d.logger.V(1).Info("Handling route status update", "route", routeData.RouteMetadata.RouteName)
78+
d.logger.Info("Handling route status update", "route", routeData)
7979
routeName := routeData.RouteMetadata.RouteName
8080
routeNamespace := routeData.RouteMetadata.RouteNamespace
8181
routeKind := routeData.RouteMetadata.RouteKind
@@ -106,6 +106,7 @@ func (d *routeReconcilerImpl) handleRouteStatusUpdate(routeData routeutils.Route
106106

107107
// compare it with original status, patch if different
108108
if !d.isRouteStatusIdentical(routeOld, route) {
109+
d.logger.Info("Patching route status!", "route", route)
109110
if err := d.k8sClient.Status().Patch(context.Background(), route, client.MergeFrom(routeOld)); err != nil {
110111
d.logger.Error(err, "Failed to patch route status")
111112
return err
@@ -321,6 +322,7 @@ func (d *routeReconcilerImpl) isRouteStatusIdentical(routeOld client.Object, rou
321322

322323
// compare if both have same parent number
323324
if len(routeOldStatus) != len(routeNewStatus) {
325+
d.logger.Info("Route status is not identical, parent number is different", "route", route)
324326
return false
325327
}
326328

@@ -348,11 +350,13 @@ func (d *routeReconcilerImpl) isRouteStatusIdentical(routeOld client.Object, rou
348350

349351
// Compare ControllerName
350352
if oldStatus.ControllerName != newStatus.ControllerName {
353+
d.logger.Info("Controller name dif")
351354
return false
352355
}
353356

354357
// Compare Conditions
355-
if !areConditionsEqual(oldStatus.Conditions, newStatus.Conditions) {
358+
if !areConditionsEqual(oldStatus.Conditions, newStatus.Conditions, d.logger) {
359+
d.logger.Info("conditions diff")
356360
return false
357361
}
358362
}
@@ -418,8 +422,9 @@ func getParentStatusKey(ref gwv1.ParentReference) string {
418422
}
419423

420424
// Helper function to compare conditions
421-
func areConditionsEqual(oldConditions, newConditions []metav1.Condition) bool {
425+
func areConditionsEqual(oldConditions, newConditions []metav1.Condition, logger logr.Logger) bool {
422426
if len(oldConditions) != len(newConditions) {
427+
logger.Info("cond size is diff")
423428
return false
424429
}
425430

@@ -431,6 +436,7 @@ func areConditionsEqual(oldConditions, newConditions []metav1.Condition) bool {
431436
for _, newCondition := range newConditions {
432437
oldCondition, exists := oldConditionMap[newCondition.Type]
433438
if !exists {
439+
logger.Info("cond not exist in old")
434440
return false
435441
}
436442

@@ -439,6 +445,7 @@ func areConditionsEqual(oldConditions, newConditions []metav1.Condition) bool {
439445
oldCondition.Status != newCondition.Status ||
440446
oldCondition.Reason != newCondition.Reason ||
441447
oldCondition.Message != newCondition.Message {
448+
logger.Info("cond param change")
442449
return false
443450
}
444451
}

pkg/gateway/model/model_build_listener.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func (l listenerBuilderImpl) buildL4ListenerSpec(ctx context.Context, stack core
157157
}
158158
backend := routeDescriptor.GetAttachedRules()[0].GetBackends()[0]
159159
targetGroup, tgErr := l.tgBuilder.buildTargetGroup(stack, gw, lbCfg, lb.Spec.IPAddressType, routeDescriptor, backend, securityGroups.backendSecurityGroupToken)
160+
l.logger.Info("Built this target group", "tg", targetGroup, "route", routeDescriptor.GetRouteNamespacedName())
160161
if tgErr != nil {
161162
return &elbv2model.ListenerSpec{}, tgErr
162163
}

pkg/gateway/model/model_build_target_group.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,9 @@ func (t *targetGroupBuilderImpl) buildTargetGroup(stack core.Stack,
100100
gw *gwv1.Gateway, lbConfig elbv2gw.LoadBalancerConfiguration, lbIPType elbv2model.IPAddressType, routeDescriptor routeutils.RouteDescriptor, backend routeutils.Backend, backendSGIDToken core.StringToken) (*elbv2model.TargetGroup, error) {
101101

102102
targetGroupProps := backend.ELBV2TargetGroupProps
103-
tgResID := t.buildTargetGroupResourceID(k8s.NamespacedName(gw), k8s.NamespacedName(backend.Service), routeDescriptor.GetRouteNamespacedName(), backend.ServicePort.TargetPort)
103+
tgResID := t.buildTargetGroupResourceID(k8s.NamespacedName(gw), k8s.NamespacedName(backend.Service), routeDescriptor.GetRouteNamespacedName(), routeDescriptor.GetRouteKind(), backend.ServicePort.TargetPort)
104104
if tg, exists := t.tgByResID[tgResID]; exists {
105+
fmt.Println("TG already exists. Returning cached version")
105106
return tg, nil
106107
}
107108

@@ -129,7 +130,7 @@ func (builder *targetGroupBuilderImpl) buildTargetGroupBindingSpec(gw *gwv1.Gate
129130
if targetType == elbv2api.TargetTypeInstance {
130131
targetPort = intstr.FromInt32(backend.ServicePort.NodePort)
131132
}
132-
tgbNetworking := builder.buildTargetGroupBindingNetworking(targetPort, *tgSpec.HealthCheckConfig.Port, *backend.ServicePort, backendSGIDToken)
133+
tgbNetworking := builder.buildTargetGroupBindingNetworking(targetPort, *tgSpec.HealthCheckConfig.Port, tgSpec.Protocol, backendSGIDToken)
133134

134135
multiClusterEnabled := builder.buildTargetGroupBindingMultiClusterFlag(tgProps)
135136

@@ -175,14 +176,14 @@ func (builder *targetGroupBuilderImpl) buildTargetGroupBindingSpec(gw *gwv1.Gate
175176
}
176177
}
177178

178-
func (builder *targetGroupBuilderImpl) buildTargetGroupBindingNetworking(targetPort intstr.IntOrString, healthCheckPort intstr.IntOrString, svcPort corev1.ServicePort, backendSGIDToken core.StringToken) *elbv2model.TargetGroupBindingNetworking {
179+
func (builder *targetGroupBuilderImpl) buildTargetGroupBindingNetworking(targetPort intstr.IntOrString, healthCheckPort intstr.IntOrString, tgProtocol elbv2model.Protocol, backendSGIDToken core.StringToken) *elbv2model.TargetGroupBindingNetworking {
179180
if backendSGIDToken == nil {
180181
return nil
181182
}
182183
protocolTCP := elbv2api.NetworkingProtocolTCP
183184
protocolUDP := elbv2api.NetworkingProtocolUDP
184185

185-
udpSupported := svcPort.Protocol == corev1.ProtocolUDP
186+
udpSupported := tgProtocol == elbv2model.ProtocolUDP || tgProtocol == elbv2model.ProtocolTCP_UDP
186187

187188
if builder.disableRestrictedSGRules {
188189
ports := []elbv2api.NetworkingPort{
@@ -282,7 +283,7 @@ func (builder *targetGroupBuilderImpl) buildTargetGroupSpec(gw *gwv1.Gateway, ro
282283
return elbv2model.TargetGroupSpec{}, err
283284
}
284285
tgPort := builder.buildTargetGroupPort(targetType, *backend.ServicePort)
285-
name := builder.buildTargetGroupName(targetGroupProps, k8s.NamespacedName(gw), route.GetRouteNamespacedName(), k8s.NamespacedName(backend.Service), tgPort, targetType, tgProtocol, tgProtocolVersion)
286+
name := builder.buildTargetGroupName(targetGroupProps, k8s.NamespacedName(gw), route.GetRouteNamespacedName(), route.GetRouteKind(), k8s.NamespacedName(backend.Service), tgPort, targetType, tgProtocol, tgProtocolVersion)
286287
return elbv2model.TargetGroupSpec{
287288
Name: name,
288289
TargetType: targetType,
@@ -300,7 +301,7 @@ var invalidTargetGroupNamePattern = regexp.MustCompile("[[:^alnum:]]")
300301

301302
// buildTargetGroupName will calculate the targetGroup's name.
302303
func (builder *targetGroupBuilderImpl) buildTargetGroupName(targetGroupProps *elbv2gw.TargetGroupProps,
303-
gwKey types.NamespacedName, routeKey types.NamespacedName, svcKey types.NamespacedName, tgPort int32,
304+
gwKey types.NamespacedName, routeKey types.NamespacedName, routeKind routeutils.RouteKind, svcKey types.NamespacedName, tgPort int32,
304305
targetType elbv2model.TargetType, tgProtocol elbv2model.Protocol, tgProtocolVersion *elbv2model.ProtocolVersion) string {
305306

306307
if targetGroupProps != nil && targetGroupProps.TargetGroupName != nil {
@@ -313,6 +314,7 @@ func (builder *targetGroupBuilderImpl) buildTargetGroupName(targetGroupProps *el
313314
_, _ = uuidHash.Write([]byte(gwKey.Name))
314315
_, _ = uuidHash.Write([]byte(routeKey.Namespace))
315316
_, _ = uuidHash.Write([]byte(routeKey.Name))
317+
_, _ = uuidHash.Write([]byte(routeKind))
316318
_, _ = uuidHash.Write([]byte(svcKey.Namespace))
317319
_, _ = uuidHash.Write([]byte(svcKey.Name))
318320
_, _ = uuidHash.Write([]byte(strconv.Itoa(int(tgPort))))
@@ -660,8 +662,8 @@ func (builder *targetGroupBuilderImpl) convertMapToAttributes(attributeMap map[s
660662
return convertedAttributes
661663
}
662664

663-
func (builder *targetGroupBuilderImpl) buildTargetGroupResourceID(gwKey types.NamespacedName, svcKey types.NamespacedName, routeKey types.NamespacedName, port intstr.IntOrString) string {
664-
return fmt.Sprintf("%s/%s:%s-%s:%s-%s:%s", gwKey.Namespace, gwKey.Name, routeKey.Namespace, routeKey.Name, svcKey.Namespace, svcKey.Name, port.String())
665+
func (builder *targetGroupBuilderImpl) buildTargetGroupResourceID(gwKey types.NamespacedName, svcKey types.NamespacedName, routeKey types.NamespacedName, routeKind routeutils.RouteKind, port intstr.IntOrString) string {
666+
return fmt.Sprintf("%s/%s:%s-%s:%s-%s-%s:%s", gwKey.Namespace, gwKey.Name, routeKey.Namespace, routeKey.Name, routeKind, svcKey.Namespace, svcKey.Name, port.String())
665667
}
666668

667669
func (builder *targetGroupBuilderImpl) buildTargetGroupBindingNodeSelector(tgProps *elbv2gw.TargetGroupProps, targetType elbv2model.TargetType) *metav1.LabelSelector {

0 commit comments

Comments
 (0)