Skip to content

Commit dcc2213

Browse files
committed
pass conformance test
1 parent fc3cddf commit dcc2213

File tree

4 files changed

+84
-10
lines changed

4 files changed

+84
-10
lines changed

internal/controller/gateway_controller.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
9898
tctx := &translator.TranslateContext{
9999
Secrets: make(map[types.NamespacedName]*corev1.Secret),
100100
}
101-
if err := r.processListenerConfig(tctx, gateway.Spec.Listeners, ns); err != nil {
101+
if err := r.processListenerConfig(tctx, gateway, ns); err != nil {
102102
acceptStatus = status{
103103
status: false,
104104
msg: err.Error(),
@@ -220,8 +220,9 @@ func (r *GatewayReconciler) listGatewaysForHTTPRoute(_ context.Context, obj clie
220220
return recs
221221
}
222222

223-
func (r *GatewayReconciler) processListenerConfig(tctx *translator.TranslateContext, listeners []gatewayv1.Listener, ns string) error {
223+
func (r *GatewayReconciler) processListenerConfig(tctx *translator.TranslateContext, gateway *gatewayv1.Gateway, ns string) error {
224224
var terror error
225+
listeners := gateway.Spec.Listeners
225226
for _, listener := range listeners {
226227
if listener.TLS == nil || listener.TLS.CertificateRefs == nil {
227228
continue
@@ -237,13 +238,14 @@ func (r *GatewayReconciler) processListenerConfig(tctx *translator.TranslateCont
237238
Name: string(ref.Name),
238239
}, &secret); err != nil {
239240
log.Error(err, "failed to get secret", "namespace", ns, "name", string(ref.Name))
241+
SetGatewayListenerConditionProgrammed(gateway, string(listener.Name), false, err.Error())
242+
SetGatewayListenerConditionResolvedRefs(gateway, string(listener.Name), false, err.Error())
240243
terror = err
241244
break
242245
}
243246
log.Info("Setting secret for listener", "listener", listener.Name, "secret", secret.Name, " namespace", ns)
244247
tctx.Secrets[types.NamespacedName{Namespace: ns, Name: string(ref.Name)}] = &secret
245248
}
246-
247249
}
248250
}
249251
return terror

internal/controller/utils.go

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ func setGatewayCondition(gw *gatewayv1.Gateway, newCondition metav1.Condition) {
4343
gw.Status.Conditions = MergeCondition(gw.Status.Conditions, newCondition)
4444
}
4545

46+
func setListenerCondition(gw *gatewayv1.Gateway, listenerName string, newCondition metav1.Condition) {
47+
for i, listener := range gw.Status.Listeners {
48+
if listener.Name == gatewayv1.SectionName(listenerName) {
49+
gw.Status.Listeners[i].Conditions = MergeCondition(listener.Conditions, newCondition)
50+
return
51+
}
52+
}
53+
}
54+
4655
func reconcileGatewaysMatchGatewayClass(gatewayClass client.Object, gateways []gatewayv1.Gateway) (recs []reconcile.Request) {
4756
for _, gateway := range gateways {
4857
if string(gateway.Spec.GatewayClassName) == gatewayClass.GetName() {
@@ -91,6 +100,72 @@ func SetGatewayConditionAccepted(gw *gatewayv1.Gateway, status bool, message str
91100
return
92101
}
93102

103+
func SetGatewayListenerConditionAccepted(gw *gatewayv1.Gateway, listenerName string, status bool, message string) (ok bool) {
104+
conditionStatus := metav1.ConditionTrue
105+
if !status {
106+
conditionStatus = metav1.ConditionFalse
107+
}
108+
109+
condition := metav1.Condition{
110+
Type: string(gatewayv1.ListenerConditionAccepted),
111+
Status: conditionStatus,
112+
Reason: string(gatewayv1.ListenerConditionAccepted),
113+
ObservedGeneration: gw.GetGeneration(),
114+
Message: message,
115+
LastTransitionTime: metav1.Now(),
116+
}
117+
118+
if !IsConditionPresentAndEqual(gw.Status.Conditions, condition) {
119+
setListenerCondition(gw, listenerName, condition)
120+
ok = true
121+
}
122+
return
123+
}
124+
125+
func SetGatewayListenerConditionProgrammed(gw *gatewayv1.Gateway, listenerName string, status bool, message string) (ok bool) {
126+
conditionStatus := metav1.ConditionTrue
127+
if !status {
128+
conditionStatus = metav1.ConditionFalse
129+
}
130+
131+
condition := metav1.Condition{
132+
Type: string(gatewayv1.ListenerConditionProgrammed),
133+
Status: conditionStatus,
134+
Reason: string(gatewayv1.ListenerReasonProgrammed),
135+
ObservedGeneration: gw.GetGeneration(),
136+
Message: message,
137+
LastTransitionTime: metav1.Now(),
138+
}
139+
140+
if !IsConditionPresentAndEqual(gw.Status.Conditions, condition) {
141+
setListenerCondition(gw, listenerName, condition)
142+
ok = true
143+
}
144+
return
145+
}
146+
147+
func SetGatewayListenerConditionResolvedRefs(gw *gatewayv1.Gateway, listenerName string, status bool, message string) (ok bool) {
148+
conditionStatus := metav1.ConditionTrue
149+
if !status {
150+
conditionStatus = metav1.ConditionFalse
151+
}
152+
153+
condition := metav1.Condition{
154+
Type: string(gatewayv1.ListenerConditionResolvedRefs),
155+
Status: conditionStatus,
156+
Reason: string(gatewayv1.ListenerReasonResolvedRefs),
157+
ObservedGeneration: gw.GetGeneration(),
158+
Message: message,
159+
LastTransitionTime: metav1.Now(),
160+
}
161+
162+
if !IsConditionPresentAndEqual(gw.Status.Conditions, condition) {
163+
setListenerCondition(gw, listenerName, condition)
164+
ok = true
165+
}
166+
return
167+
}
168+
94169
func SetGatewayConditionProgrammed(gw *gatewayv1.Gateway, status bool, message string) (ok bool) {
95170
conditionStatus := metav1.ConditionTrue
96171
if !status {
@@ -288,21 +363,17 @@ func checkRouteAcceptedByListener(
288363
return false, gatewayv1.RouteReasonNoMatchingParent, nil
289364
}
290365
}
291-
292366
if parentRef.Port != nil {
293367
if *parentRef.Port != listener.Port {
294368
return false, gatewayv1.RouteReasonNoMatchingParent, nil
295369
}
296370
}
297-
298371
if !routeMatchesListenerType(route, listener) {
299372
return false, gatewayv1.RouteReasonNoMatchingParent, nil
300373
}
301-
302374
if !routeHostnamesIntersectsWithListenerHostname(route, listener) {
303375
return false, gatewayv1.RouteReasonNoMatchingListenerHostname, nil
304376
}
305-
306377
if ok, err := routeMatchesListenerAllowedRoutes(ctx, mgrc, route, listener.AllowedRoutes, gateway.Namespace, parentRef.Namespace); err != nil {
307378
return false, gatewayv1.RouteReasonNotAllowedByListeners, fmt.Errorf("failed matching listener %s to a route %s for gateway %s: %w",
308379
listener.Name, route.GetName(), gateway.Name, err,
@@ -480,7 +551,6 @@ func getAttachedRoutesForListener(ctx context.Context, mgrc client.Client, gatew
480551
if err := mgrc.List(ctx, &httpRouteList); err != nil {
481552
return 0, err
482553
}
483-
484554
var attachedRoutes int32
485555
for _, route := range httpRouteList.Items {
486556
route := route
@@ -534,7 +604,6 @@ func getListenerStatus(
534604
if err != nil {
535605
return nil, err
536606
}
537-
538607
var (
539608
reasonResolvedRef = string(gatewayv1.ListenerReasonResolvedRefs)
540609
statusResolvedRef = metav1.ConditionTrue

internal/controlplane/translator/gateway.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ func (t *Translator) translateSecret(tctx *TranslateContext, listener gatewayv1.
5151
}
5252
name := listener.TLS.CertificateRefs[0].Name
5353
secret := tctx.Secrets[types.NamespacedName{Namespace: ns, Name: string(ref.Name)}]
54+
if secret == nil {
55+
log.Error("secret not found", "namespace", ns, "name", name)
56+
return nil, fmt.Errorf("secret not found for %s/%s", ns, name)
57+
}
5458
if secret.Data == nil {
5559
log.Error("secret data is nil", "secret", secret)
5660
return nil, fmt.Errorf("no secret data found for %s/%s", ns, name)

test/conformance/conformance_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ var skippedTestsForSSL = []string{
2727
var skippedTestsForTraditionalRoutes = []string{
2828
// TODO: Support ReferenceGrant resource
2929
tests.HTTPRouteInvalidReferenceGrant.ShortName,
30-
tests.GatewayWithAttachedRoutes.ShortName,
3130
tests.HTTPRoutePartiallyInvalidViaInvalidReferenceGrant.ShortName,
3231
tests.HTTPRouteReferenceGrant.ShortName,
3332
tests.GatewayInvalidTLSConfiguration.ShortName,

0 commit comments

Comments
 (0)