Skip to content

Commit 698a369

Browse files
authored
Remove error condition on httproute when nginx reload fails (#3936)
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 8f774c1 commit 698a369

File tree

5 files changed

+24
-160
lines changed

5 files changed

+24
-160
lines changed

internal/controller/handler.go

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

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"
@@ -493,17 +489,6 @@ func NewRouteUnsupportedConfiguration(msg string) Condition {
493489
}
494490
}
495491

496-
// NewRouteGatewayNotProgrammed returns a Condition that indicates that the Gateway it references is not programmed,
497-
// which does not guarantee that the Route has been configured.
498-
func NewRouteGatewayNotProgrammed(msg string) Condition {
499-
return Condition{
500-
Type: string(v1.RouteConditionAccepted),
501-
Status: metav1.ConditionFalse,
502-
Reason: string(RouteReasonGatewayNotProgrammed),
503-
Message: msg,
504-
}
505-
}
506-
507492
// NewRouteInvalidIPFamily returns a Condition that indicates that the Service associated with the Route
508493
// is not configured with the same IP family as the NGINX server.
509494
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
@@ -28,7 +28,6 @@ func PrepareRouteRequests(
2828
l4routes map[graph.L4RouteKey]*graph.L4Route,
2929
routes map[graph.RouteKey]*graph.L7Route,
3030
transitionTime metav1.Time,
31-
nginxReloadRes graph.NginxReloadResult,
3231
gatewayCtlrName string,
3332
) []UpdateRequest {
3433
reqs := make([]UpdateRequest, 0, len(routes))
@@ -38,7 +37,6 @@ func PrepareRouteRequests(
3837
gatewayCtlrName,
3938
r.ParentRefs,
4039
r.Conditions,
41-
nginxReloadRes,
4240
transitionTime,
4341
r.Source.GetGeneration(),
4442
)
@@ -61,7 +59,6 @@ func PrepareRouteRequests(
6159
gatewayCtlrName,
6260
r.ParentRefs,
6361
r.Conditions,
64-
nginxReloadRes,
6562
transitionTime,
6663
r.Source.GetGeneration(),
6764
)
@@ -140,7 +137,6 @@ func prepareRouteStatus(
140137
gatewayCtlrName string,
141138
parentRefs []graph.ParentRef,
142139
conds []conditions.Condition,
143-
nginxReloadRes graph.NginxReloadResult,
144140
transitionTime metav1.Time,
145141
srcGeneration int64,
146142
) v1.RouteStatus {
@@ -169,13 +165,6 @@ func prepareRouteStatus(
169165
allConds = append(allConds, ref.Attachment.FailedConditions...)
170166
}
171167

172-
if nginxReloadRes.Error != nil {
173-
allConds = append(
174-
allConds,
175-
conditions.NewRouteGatewayNotProgrammed(conditions.RouteMessageFailedNginxReload),
176-
)
177-
}
178-
179168
conds := conditions.DeduplicateConditions(allConds)
180169
apiConds := conditions.ConvertConditions(conds, srcGeneration, transitionTime)
181170

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: 24 additions & 28 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() {
@@ -234,9 +234,8 @@ var _ = Describe("SnippetsFilter", Ordered, Label("functional", "snippets-filter
234234

235235
Expect(resourceManager.ApplyFromFiles(files, namespace)).To(Succeed())
236236

237-
nsname := types.NamespacedName{Name: "tea", Namespace: namespace}
238-
Eventually(checkHTTPRouteToHaveGatewayNotProgrammedCond).
239-
WithArguments(nsname).
237+
Eventually(checkGatewayToHaveGatewayNotProgrammedCond).
238+
WithArguments(gatewayNsName).
240239
WithTimeout(timeoutConfig.GetStatusTimeout).
241240
WithPolling(500 * time.Millisecond).
242241
Should(Succeed())
@@ -249,9 +248,8 @@ var _ = Describe("SnippetsFilter", Ordered, Label("functional", "snippets-filter
249248

250249
Expect(resourceManager.ApplyFromFiles(files, namespace)).To(Succeed())
251250

252-
nsname := types.NamespacedName{Name: "soda", Namespace: namespace}
253-
Eventually(checkHTTPRouteToHaveGatewayNotProgrammedCond).
254-
WithArguments(nsname).
251+
Eventually(checkGatewayToHaveGatewayNotProgrammedCond).
252+
WithArguments(gatewayNsName).
255253
WithTimeout(timeoutConfig.GetStatusTimeout).
256254
WithPolling(500 * time.Millisecond).
257255
Should(Succeed())
@@ -261,40 +259,38 @@ var _ = Describe("SnippetsFilter", Ordered, Label("functional", "snippets-filter
261259
})
262260
})
263261

264-
func checkHTTPRouteToHaveGatewayNotProgrammedCond(httpRouteNsName types.NamespacedName) error {
262+
func checkGatewayToHaveGatewayNotProgrammedCond(gatewayNsName types.NamespacedName) error {
265263
ctx, cancel := context.WithTimeout(context.Background(), timeoutConfig.GetTimeout)
266264
defer cancel()
267265

268266
GinkgoWriter.Printf(
269-
"Checking for HTTPRoute %q to have the condition Accepted/True/GatewayNotProgrammed\n",
270-
httpRouteNsName,
267+
"Checking for Gateway %q to have the condition Programmed/False/Invalid \n",
268+
gatewayNsName,
271269
)
272270

273-
var hr v1.HTTPRoute
271+
var gw v1.Gateway
274272
var err error
275273

276-
if err = resourceManager.Get(ctx, httpRouteNsName, &hr); err != nil {
274+
if err = resourceManager.Get(ctx, gatewayNsName, &gw); err != nil {
277275
return err
278276
}
279277

280-
if len(hr.Status.Parents) != 1 {
281-
tooManyParentStatusesErr := fmt.Errorf("httproute has %d parent statuses, expected 1", len(hr.Status.Parents))
282-
GinkgoWriter.Printf("ERROR: %v\n", tooManyParentStatusesErr)
283-
284-
return tooManyParentStatusesErr
285-
}
286-
287-
parent := hr.Status.Parents[0]
288-
if parent.Conditions == nil {
289-
nilConditionErr := fmt.Errorf("expected parent conditions to not be nil")
278+
gwStatus := gw.Status
279+
if gwStatus.Conditions == nil {
280+
nilConditionErr := fmt.Errorf("expected gateway conditions to not be nil")
290281
GinkgoWriter.Printf("ERROR: %v\n", nilConditionErr)
291282

292283
return nilConditionErr
293284
}
294285

295-
cond := parent.Conditions[1]
296-
if cond.Type != string(v1.GatewayConditionAccepted) {
297-
wrongTypeErr := fmt.Errorf("expected condition type to be Accepted, got %s", cond.Type)
286+
for i := range gwStatus.Conditions {
287+
GinkgoWriter.Printf("Gateway condition %d: Type=%s, Status=%s, Reason=%s\n",
288+
i, gwStatus.Conditions[i].Type, gwStatus.Conditions[i].Status, gwStatus.Conditions[i].Reason)
289+
}
290+
291+
cond := gwStatus.Conditions[1]
292+
if cond.Type != string(v1.GatewayConditionProgrammed) {
293+
wrongTypeErr := fmt.Errorf("expected condition type to be Programmed, got %s", cond.Type)
298294
GinkgoWriter.Printf("ERROR: %v\n", wrongTypeErr)
299295

300296
return wrongTypeErr
@@ -307,8 +303,8 @@ func checkHTTPRouteToHaveGatewayNotProgrammedCond(httpRouteNsName types.Namespac
307303
return wrongStatusErr
308304
}
309305

310-
if cond.Reason != string(conditions.RouteReasonGatewayNotProgrammed) {
311-
wrongReasonErr := fmt.Errorf("expected condition reason to be GatewayNotProgrammed, got %s", cond.Reason)
306+
if cond.Reason != string(v1.GatewayReasonInvalid) {
307+
wrongReasonErr := fmt.Errorf("expected condition reason to be GatewayReasonInvalid, got %s", cond.Reason)
312308
GinkgoWriter.Printf("ERROR: %v\n", wrongReasonErr)
313309

314310
return wrongReasonErr

0 commit comments

Comments
 (0)