Skip to content

Commit f76e38f

Browse files
authored
Remove error condition on httproute when nginx reload fails (#3936) (#3938)
Problem: When nginx reload fails, all routes are marked invalid Solution: Remove adding GatewayNotProgrammed condition to routes since the error should only be reflected on Gateway Listener conditions
1 parent c68b52a commit f76e38f

File tree

5 files changed

+31
-155
lines changed

5 files changed

+31
-155
lines changed

internal/controller/handler.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ func (h *eventHandlerImpl) updateStatuses(ctx context.Context, gr *graph.Graph,
337337
gr.L4Routes,
338338
gr.Routes,
339339
transitionTime,
340-
gw.LatestReloadResult,
341340
h.cfg.gatewayCtlrName,
342341
)
343342

internal/controller/state/conditions/conditions.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ const (
4949
// as another route.
5050
RouteReasonHostnameConflict v1.RouteConditionReason = "HostnameConflict"
5151

52-
// RouteReasonGatewayNotProgrammed is used when the associated Gateway is not programmed.
53-
// Used with Accepted (false).
54-
RouteReasonGatewayNotProgrammed v1.RouteConditionReason = "GatewayNotProgrammed"
55-
5652
// RouteReasonUnsupportedConfiguration is used when the associated Gateway does not support the Route.
5753
// Used with Accepted (false).
5854
RouteReasonUnsupportedConfiguration v1.RouteConditionReason = "UnsupportedConfiguration"
@@ -472,17 +468,6 @@ func NewRouteUnsupportedConfiguration(msg string) Condition {
472468
}
473469
}
474470

475-
// NewRouteGatewayNotProgrammed returns a Condition that indicates that the Gateway it references is not programmed,
476-
// which does not guarantee that the Route has been configured.
477-
func NewRouteGatewayNotProgrammed(msg string) Condition {
478-
return Condition{
479-
Type: string(v1.RouteConditionAccepted),
480-
Status: metav1.ConditionFalse,
481-
Reason: string(RouteReasonGatewayNotProgrammed),
482-
Message: msg,
483-
}
484-
}
485-
486471
// NewRouteInvalidIPFamily returns a Condition that indicates that the Service associated with the Route
487472
// is not configured with the same IP family as the NGINX server.
488473
func NewRouteInvalidIPFamily(msg string) Condition {

internal/controller/status/prepare_requests.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ func PrepareRouteRequests(
2222
l4routes map[graph.L4RouteKey]*graph.L4Route,
2323
routes map[graph.RouteKey]*graph.L7Route,
2424
transitionTime metav1.Time,
25-
nginxReloadRes graph.NginxReloadResult,
2625
gatewayCtlrName string,
2726
) []UpdateRequest {
2827
reqs := make([]UpdateRequest, 0, len(routes))
@@ -32,7 +31,6 @@ func PrepareRouteRequests(
3231
gatewayCtlrName,
3332
r.ParentRefs,
3433
r.Conditions,
35-
nginxReloadRes,
3634
transitionTime,
3735
r.Source.GetGeneration(),
3836
)
@@ -55,7 +53,6 @@ func PrepareRouteRequests(
5553
gatewayCtlrName,
5654
r.ParentRefs,
5755
r.Conditions,
58-
nginxReloadRes,
5956
transitionTime,
6057
r.Source.GetGeneration(),
6158
)
@@ -134,7 +131,6 @@ func prepareRouteStatus(
134131
gatewayCtlrName string,
135132
parentRefs []graph.ParentRef,
136133
conds []conditions.Condition,
137-
nginxReloadRes graph.NginxReloadResult,
138134
transitionTime metav1.Time,
139135
srcGeneration int64,
140136
) v1.RouteStatus {
@@ -163,13 +159,6 @@ func prepareRouteStatus(
163159
allConds = append(allConds, ref.Attachment.FailedConditions...)
164160
}
165161

166-
if nginxReloadRes.Error != nil {
167-
allConds = append(
168-
allConds,
169-
conditions.NewRouteGatewayNotProgrammed(conditions.RouteMessageFailedNginxReload),
170-
)
171-
}
172-
173162
conds := conditions.DeduplicateConditions(allConds)
174163
apiConds := conditions.ConvertConditions(conds, srcGeneration, transitionTime)
175164

internal/controller/status/prepare_requests_test.go

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,6 @@ func TestBuildHTTPRouteStatuses(t *testing.T) {
432432
map[graph.L4RouteKey]*graph.L4Route{},
433433
routes,
434434
transitionTime,
435-
graph.NginxReloadResult{},
436435
gatewayCtlrName,
437436
)
438437

@@ -511,7 +510,6 @@ func TestBuildGRPCRouteStatuses(t *testing.T) {
511510
map[graph.L4RouteKey]*graph.L4Route{},
512511
routes,
513512
transitionTime,
514-
graph.NginxReloadResult{},
515513
gatewayCtlrName,
516514
)
517515

@@ -588,7 +586,6 @@ func TestBuildTLSRouteStatuses(t *testing.T) {
588586
routes,
589587
map[graph.RouteKey]*graph.L7Route{},
590588
transitionTime,
591-
graph.NginxReloadResult{},
592589
gatewayCtlrName,
593590
)
594591

@@ -605,108 +602,6 @@ func TestBuildTLSRouteStatuses(t *testing.T) {
605602
}
606603
}
607604

608-
func TestBuildRouteStatusesNginxErr(t *testing.T) {
609-
t.Parallel()
610-
const gatewayCtlrName = "controller"
611-
612-
hr1 := &v1.HTTPRoute{
613-
ObjectMeta: metav1.ObjectMeta{
614-
Namespace: "test",
615-
Name: "hr-valid",
616-
Generation: 3,
617-
},
618-
Spec: v1.HTTPRouteSpec{
619-
CommonRouteSpec: commonRouteSpecValid,
620-
},
621-
}
622-
623-
routeKey := graph.CreateRouteKey(hr1)
624-
625-
gwNsName := types.NamespacedName{Namespace: "test", Name: "gateway"}
626-
627-
routes := map[graph.RouteKey]*graph.L7Route{
628-
routeKey: {
629-
Valid: true,
630-
RouteType: graph.RouteTypeHTTP,
631-
Source: hr1,
632-
ParentRefs: []graph.ParentRef{
633-
{
634-
Idx: 0,
635-
Gateway: &graph.ParentRefGateway{NamespacedName: gwNsName},
636-
Attachment: &graph.ParentRefAttachmentStatus{
637-
Attached: true,
638-
},
639-
SectionName: commonRouteSpecValid.ParentRefs[0].SectionName,
640-
},
641-
},
642-
},
643-
}
644-
645-
transitionTime := helpers.PrepareTimeForFakeClient(metav1.Now())
646-
647-
expectedStatus := v1.HTTPRouteStatus{
648-
RouteStatus: v1.RouteStatus{
649-
Parents: []v1.RouteParentStatus{
650-
{
651-
ParentRef: v1.ParentReference{
652-
Namespace: helpers.GetPointer(v1.Namespace(gwNsName.Namespace)),
653-
Name: v1.ObjectName(gwNsName.Name),
654-
SectionName: helpers.GetPointer[v1.SectionName]("listener-80-1"),
655-
},
656-
ControllerName: gatewayCtlrName,
657-
Conditions: []metav1.Condition{
658-
{
659-
Type: string(v1.RouteConditionResolvedRefs),
660-
Status: metav1.ConditionTrue,
661-
ObservedGeneration: 3,
662-
LastTransitionTime: transitionTime,
663-
Reason: string(v1.RouteReasonResolvedRefs),
664-
Message: "All references are resolved",
665-
},
666-
{
667-
Type: string(v1.RouteConditionAccepted),
668-
Status: metav1.ConditionFalse,
669-
ObservedGeneration: 3,
670-
LastTransitionTime: transitionTime,
671-
Reason: string(conditions.RouteReasonGatewayNotProgrammed),
672-
Message: conditions.RouteMessageFailedNginxReload,
673-
},
674-
},
675-
},
676-
},
677-
},
678-
}
679-
680-
g := NewWithT(t)
681-
682-
k8sClient := createK8sClientFor(&v1.HTTPRoute{})
683-
684-
for _, r := range routes {
685-
err := k8sClient.Create(context.Background(), r.Source)
686-
g.Expect(err).ToNot(HaveOccurred())
687-
}
688-
689-
updater := NewUpdater(k8sClient, logr.Discard())
690-
691-
reqs := PrepareRouteRequests(
692-
map[graph.L4RouteKey]*graph.L4Route{},
693-
routes,
694-
transitionTime,
695-
graph.NginxReloadResult{Error: errors.New("test error")},
696-
gatewayCtlrName,
697-
)
698-
699-
g.Expect(reqs).To(HaveLen(1))
700-
701-
updater.Update(context.Background(), reqs...)
702-
703-
var hr v1.HTTPRoute
704-
705-
err := k8sClient.Get(context.Background(), routeKey.NamespacedName, &hr)
706-
g.Expect(err).ToNot(HaveOccurred())
707-
g.Expect(helpers.Diff(expectedStatus, hr.Status)).To(BeEmpty())
708-
}
709-
710605
func TestBuildGatewayClassStatuses(t *testing.T) {
711606
t.Parallel()
712607
transitionTime := helpers.PrepareTimeForFakeClient(metav1.Now())

tests/suite/snippets_filter_test.go

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
v1 "sigs.k8s.io/gateway-api/apis/v1"
1515

1616
ngfAPI "github.com/nginx/nginx-gateway-fabric/v2/apis/v1alpha1"
17-
"github.com/nginx/nginx-gateway-fabric/v2/internal/controller/state/conditions"
1817
"github.com/nginx/nginx-gateway-fabric/v2/tests/framework"
1918
)
2019

@@ -28,7 +27,8 @@ var _ = Describe("SnippetsFilter", Ordered, Label("functional", "snippets-filter
2827

2928
namespace = "snippets-filter"
3029

31-
nginxPodName string
30+
nginxPodName string
31+
gatewayNsName = types.NamespacedName{Name: "gateway", Namespace: namespace}
3232
)
3333

3434
BeforeAll(func() {
@@ -230,9 +230,8 @@ var _ = Describe("SnippetsFilter", Ordered, Label("functional", "snippets-filter
230230

231231
Expect(resourceManager.ApplyFromFiles(files, namespace)).To(Succeed())
232232

233-
nsname := types.NamespacedName{Name: "tea", Namespace: namespace}
234-
Eventually(checkHTTPRouteToHaveGatewayNotProgrammedCond).
235-
WithArguments(nsname).
233+
Eventually(checkGatewayToHaveGatewayNotProgrammedCond).
234+
WithArguments(gatewayNsName).
236235
WithTimeout(timeoutConfig.GetStatusTimeout).
237236
WithPolling(500 * time.Millisecond).
238237
Should(Succeed())
@@ -245,9 +244,8 @@ var _ = Describe("SnippetsFilter", Ordered, Label("functional", "snippets-filter
245244

246245
Expect(resourceManager.ApplyFromFiles(files, namespace)).To(Succeed())
247246

248-
nsname := types.NamespacedName{Name: "soda", Namespace: namespace}
249-
Eventually(checkHTTPRouteToHaveGatewayNotProgrammedCond).
250-
WithArguments(nsname).
247+
Eventually(checkGatewayToHaveGatewayNotProgrammedCond).
248+
WithArguments(gatewayNsName).
251249
WithTimeout(timeoutConfig.GetStatusTimeout).
252250
WithPolling(500 * time.Millisecond).
253251
Should(Succeed())
@@ -257,42 +255,52 @@ var _ = Describe("SnippetsFilter", Ordered, Label("functional", "snippets-filter
257255
})
258256
})
259257

260-
func checkHTTPRouteToHaveGatewayNotProgrammedCond(httpRouteNsName types.NamespacedName) error {
258+
func checkGatewayToHaveGatewayNotProgrammedCond(gatewayNsName types.NamespacedName) error {
261259
ctx, cancel := context.WithTimeout(context.Background(), timeoutConfig.GetTimeout)
262260
defer cancel()
263261

264262
GinkgoWriter.Printf(
265-
"Checking for HTTPRoute %q to have the condition Accepted/True/GatewayNotProgrammed\n",
266-
httpRouteNsName,
263+
"Checking for Gateway %q to have the condition Programmed/False/Invalid \n",
264+
gatewayNsName,
267265
)
268266

269-
var hr v1.HTTPRoute
267+
var gw v1.Gateway
270268
var err error
271269

272-
if err = k8sClient.Get(ctx, httpRouteNsName, &hr); err != nil {
270+
if err = k8sClient.Get(ctx, gatewayNsName, &gw); err != nil {
273271
return err
274272
}
275273

276-
if len(hr.Status.Parents) != 1 {
277-
return fmt.Errorf("httproute has %d parent statuses, expected 1", len(hr.Status.Parents))
274+
gwStatus := gw.Status
275+
if gwStatus.Conditions == nil {
276+
nilConditionErr := fmt.Errorf("expected gateway conditions to not be nil")
277+
GinkgoWriter.Printf("ERROR: %v\n", nilConditionErr)
278+
279+
return nilConditionErr
278280
}
279281

280-
parent := hr.Status.Parents[0]
281-
if parent.Conditions == nil {
282-
return fmt.Errorf("expected parent conditions to not be nil")
282+
for i := range gwStatus.Conditions {
283+
GinkgoWriter.Printf("Gateway condition %d: Type=%s, Status=%s, Reason=%s\n",
284+
i, gwStatus.Conditions[i].Type, gwStatus.Conditions[i].Status, gwStatus.Conditions[i].Reason)
283285
}
284286

285-
cond := parent.Conditions[1]
286-
if cond.Type != string(v1.GatewayConditionAccepted) {
287-
return fmt.Errorf("expected condition type to be Accepted, got %s", cond.Type)
287+
cond := gwStatus.Conditions[1]
288+
if cond.Type != string(v1.GatewayConditionProgrammed) {
289+
wrongTypeErr := fmt.Errorf("expected condition type to be Programmed, got %s", cond.Type)
290+
GinkgoWriter.Printf("ERROR: %v\n", wrongTypeErr)
291+
292+
return wrongTypeErr
288293
}
289294

290295
if cond.Status != metav1.ConditionFalse {
291296
return fmt.Errorf("expected condition status to be False, got %s", cond.Status)
292297
}
293298

294-
if cond.Reason != string(conditions.RouteReasonGatewayNotProgrammed) {
295-
return fmt.Errorf("expected condition reason to be GatewayNotProgrammed, got %s", cond.Reason)
299+
if cond.Reason != string(v1.GatewayReasonInvalid) {
300+
wrongReasonErr := fmt.Errorf("expected condition reason to be GatewayReasonInvalid, got %s", cond.Reason)
301+
GinkgoWriter.Printf("ERROR: %v\n", wrongReasonErr)
302+
303+
return wrongReasonErr
296304
}
297305

298306
return nil

0 commit comments

Comments
 (0)