Skip to content

Commit

Permalink
Merge HTTPRoute conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
kate-osborn committed Nov 3, 2023
1 parent c0c586b commit 6851dd9
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 5 deletions.
13 changes: 12 additions & 1 deletion internal/framework/status/httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@ import (

// prepareHTTPRouteStatus prepares the status for an HTTPRoute resource.
func prepareHTTPRouteStatus(
oldStatus v1beta1.HTTPRouteStatus,
status HTTPRouteStatus,
gatewayCtlrName string,
transitionTime metav1.Time,
) v1beta1.HTTPRouteStatus {
parents := make([]v1beta1.RouteParentStatus, 0, len(status.ParentStatuses))
// maxParents is the max number of parent statuses which is the sum of all new parent statuses and all old parent
// statuses.
maxParents := len(status.ParentStatuses) + len(oldStatus.Parents)
parents := make([]v1beta1.RouteParentStatus, 0, maxParents)

// keep all the parent statuses that belong to other controllers
for _, os := range oldStatus.Parents {
if string(os.ControllerName) != gatewayCtlrName {
parents = append(parents, os)
}
}

for _, ps := range status.ParentStatuses {
// reassign the iteration variable inside the loop to fix implicit memory aliasing
Expand Down
63 changes: 62 additions & 1 deletion internal/framework/status/httproute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,70 @@ func TestPrepareHTTPRouteStatus(t *testing.T) {
gatewayCtlrName := "test.example.com"
transitionTime := metav1.NewTime(time.Now())

oldStatus := v1beta1.HTTPRouteStatus{
RouteStatus: v1beta1.RouteStatus{
Parents: []v1beta1.RouteParentStatus{
{
ParentRef: v1beta1.ParentReference{
Namespace: helpers.GetPointer(v1beta1.Namespace(gwNsName1.Namespace)),
Name: v1beta1.ObjectName(gwNsName1.Name),
SectionName: helpers.GetPointer[v1beta1.SectionName]("http"),
},
ControllerName: v1beta1.GatewayController(gatewayCtlrName),
Conditions: CreateExpectedAPIConditions("Old", 1, transitionTime),
},
{
ParentRef: v1beta1.ParentReference{
Namespace: helpers.GetPointer(v1beta1.Namespace(gwNsName1.Namespace)),
Name: v1beta1.ObjectName(gwNsName1.Name),
SectionName: helpers.GetPointer[v1beta1.SectionName]("http"),
},
ControllerName: v1beta1.GatewayController("not-our-controller"),
Conditions: CreateExpectedAPIConditions("Test", 1, transitionTime),
},
{
ParentRef: v1beta1.ParentReference{
Namespace: helpers.GetPointer(v1beta1.Namespace(gwNsName2.Namespace)),
Name: v1beta1.ObjectName(gwNsName2.Name),
SectionName: nil,
},
ControllerName: v1beta1.GatewayController(gatewayCtlrName),
Conditions: CreateExpectedAPIConditions("Old", 1, transitionTime),
},
{
ParentRef: v1beta1.ParentReference{
Namespace: helpers.GetPointer(v1beta1.Namespace(gwNsName2.Namespace)),
Name: v1beta1.ObjectName(gwNsName2.Name),
SectionName: nil,
},
ControllerName: v1beta1.GatewayController("not-our-controller"),
Conditions: CreateExpectedAPIConditions("Test", 1, transitionTime),
},
},
},
}

expected := v1beta1.HTTPRouteStatus{
RouteStatus: v1beta1.RouteStatus{
Parents: []v1beta1.RouteParentStatus{
{
ParentRef: v1beta1.ParentReference{
Namespace: helpers.GetPointer(v1beta1.Namespace(gwNsName1.Namespace)),
Name: v1beta1.ObjectName(gwNsName1.Name),
SectionName: helpers.GetPointer[v1beta1.SectionName]("http"),
},
ControllerName: v1beta1.GatewayController("not-our-controller"),
Conditions: CreateExpectedAPIConditions("Test", 1, transitionTime),
},
{
ParentRef: v1beta1.ParentReference{
Namespace: helpers.GetPointer(v1beta1.Namespace(gwNsName2.Namespace)),
Name: v1beta1.ObjectName(gwNsName2.Name),
SectionName: nil,
},
ControllerName: v1beta1.GatewayController("not-our-controller"),
Conditions: CreateExpectedAPIConditions("Test", 1, transitionTime),
},
{
ParentRef: v1beta1.ParentReference{
Namespace: helpers.GetPointer(v1beta1.Namespace(gwNsName1.Namespace)),
Expand All @@ -62,6 +123,6 @@ func TestPrepareHTTPRouteStatus(t *testing.T) {

g := NewWithT(t)

result := prepareHTTPRouteStatus(status, gatewayCtlrName, transitionTime)
result := prepareHTTPRouteStatus(oldStatus, status, gatewayCtlrName, transitionTime)
g.Expect(helpers.Diff(expected, result)).To(BeEmpty())
}
1 change: 1 addition & 0 deletions internal/framework/status/setters.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func newHTTPRouteStatusSetter(gatewayCtlrName string, clock Clock, rs HTTPRouteS
return func(object client.Object) bool {
hr := object.(*v1beta1.HTTPRoute)
status := prepareHTTPRouteStatus(
hr.Status,
rs,
gatewayCtlrName,
clock.Now(),
Expand Down
3 changes: 0 additions & 3 deletions internal/framework/status/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ func NewUpdater(cfg UpdaterConfig) *UpdaterImpl {
}

func (upd *UpdaterImpl) Update(ctx context.Context, status Status) {
// FIXME(pleshakov) Merge the new Conditions in the status with the existing Conditions
// https://github.com/nginxinc/nginx-gateway-fabric/issues/558

defer upd.lock.Unlock()
upd.lock.Lock()

Expand Down

0 comments on commit 6851dd9

Please sign in to comment.