Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge HTTPRoute conditions #1220

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading