From e14f981cd4f54cda6a7878927c20f11228a3b2d1 Mon Sep 17 00:00:00 2001 From: Arko Dasgupta Date: Tue, 27 Sep 2022 11:25:45 -0700 Subject: [PATCH 1/2] merge gateway conditions before updating status Fixes: https://github.com/envoyproxy/gateway/issues/414 Signed-off-by: Arko Dasgupta --- internal/provider/kubernetes/gateway.go | 10 ++++++++-- internal/provider/kubernetes/httproute.go | 4 ++-- internal/status/conditions.go | 4 ++-- internal/status/conditions_test.go | 2 +- internal/status/gateway.go | 4 ++-- internal/status/gatewayclass.go | 2 +- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/internal/provider/kubernetes/gateway.go b/internal/provider/kubernetes/gateway.go index 6badb16302..f3b2e445b5 100644 --- a/internal/provider/kubernetes/gateway.go +++ b/internal/provider/kubernetes/gateway.go @@ -345,10 +345,16 @@ func (r *gatewayReconciler) subscribeAndUpdateStatus(ctx context.Context) { NamespacedName: key, Resource: new(gwapiv1b1.Gateway), Mutator: status.MutatorFunc(func(obj client.Object) client.Object { - if _, ok := obj.(*gwapiv1b1.Gateway); !ok { + g, ok := obj.(*gwapiv1b1.Gateway) + if !ok { panic(fmt.Sprintf("unsupported object type %T", obj)) } - return val.DeepCopy() + gCopy := g.DeepCopy() + gCopy.Status.Conditions = status.MergeConditions(gCopy.Status.Conditions, val.Status.Conditions...) + if len(val.Status.Listeners) > 0 { + gCopy.Status.Listeners = val.Status.Listeners + } + return gCopy }), }) } diff --git a/internal/provider/kubernetes/httproute.go b/internal/provider/kubernetes/httproute.go index faf49bfee7..92987bc096 100644 --- a/internal/provider/kubernetes/httproute.go +++ b/internal/provider/kubernetes/httproute.go @@ -281,7 +281,7 @@ func (r *httpRouteReconciler) subscribeAndUpdateStatus(ctx context.Context) { continue } key := update.Key - value := update.Value + val := update.Value r.statusUpdater.Send(status.Update{ NamespacedName: key, Resource: new(gwapiv1b1.HTTPRoute), @@ -289,7 +289,7 @@ func (r *httpRouteReconciler) subscribeAndUpdateStatus(ctx context.Context) { if _, ok := obj.(*gwapiv1b1.HTTPRoute); !ok { panic(fmt.Sprintf("unsupported object type %T", obj)) } - return value.DeepCopy() + return val }), }) } diff --git a/internal/status/conditions.go b/internal/status/conditions.go index 4a37d307d7..03dcffcc4a 100644 --- a/internal/status/conditions.go +++ b/internal/status/conditions.go @@ -76,9 +76,9 @@ func computeGatewayReadyCondition(gw *gwapiv1b1.Gateway, deployment *appsv1.Depl string(gwapiv1b1.GatewayReasonReady), message, time.Now(), gw.Generation) } -// mergeConditions adds or updates matching conditions, and updates the transition +// MergeConditions adds or updates matching conditions, and updates the transition // time if details of a condition have changed. Returns the updated condition array. -func mergeConditions(conditions []metav1.Condition, updates ...metav1.Condition) []metav1.Condition { +func MergeConditions(conditions []metav1.Condition, updates ...metav1.Condition) []metav1.Condition { var additions []metav1.Condition for i, update := range updates { add := true diff --git a/internal/status/conditions_test.go b/internal/status/conditions_test.go index 738990dbc9..6cc8a52cf9 100644 --- a/internal/status/conditions_test.go +++ b/internal/status/conditions_test.go @@ -228,7 +228,7 @@ func TestMergeConditions(t *testing.T) { fakeClock.SetTime(later) for _, tc := range testCases { - got := mergeConditions(tc.current, tc.updates...) + got := MergeConditions(tc.current, tc.updates...) if conditionChanged(tc.expected[0], got[0]) { assert.Equal(t, tc.expected, got, tc.name) } diff --git a/internal/status/gateway.go b/internal/status/gateway.go index a4dcb9e482..feb8ba7318 100644 --- a/internal/status/gateway.go +++ b/internal/status/gateway.go @@ -10,7 +10,7 @@ import ( // UpdateGatewayScheduledCondition updates the status condition for the provided Gateway based on the scheduled state. func UpdateGatewayStatusScheduledCondition(gw *gwapiv1b1.Gateway, scheduled bool) *gwapiv1b1.Gateway { - gw.Status.Conditions = mergeConditions(gw.Status.Conditions, computeGatewayScheduledCondition(gw, scheduled)) + gw.Status.Conditions = MergeConditions(gw.Status.Conditions, computeGatewayScheduledCondition(gw, scheduled)) return gw } @@ -55,5 +55,5 @@ func UpdateGatewayStatusReadyCondition(gw *gwapiv1b1.Gateway, svc *corev1.Servic gw.Status.Addresses = gwAddrs } // Update the ready condition. - gw.Status.Conditions = mergeConditions(gw.Status.Conditions, computeGatewayReadyCondition(gw, deployment)) + gw.Status.Conditions = MergeConditions(gw.Status.Conditions, computeGatewayReadyCondition(gw, deployment)) } diff --git a/internal/status/gatewayclass.go b/internal/status/gatewayclass.go index 8ac203eee9..41581b2290 100644 --- a/internal/status/gatewayclass.go +++ b/internal/status/gatewayclass.go @@ -10,6 +10,6 @@ import ( // SetGatewayClassAccepted inserts or updates the Accepted condition // for the provided GatewayClass. func SetGatewayClassAccepted(gc *gwapiv1b1.GatewayClass, accepted bool) *gwapiv1b1.GatewayClass { - gc.Status.Conditions = mergeConditions(gc.Status.Conditions, computeGatewayClassAcceptedCondition(gc, accepted)) + gc.Status.Conditions = MergeConditions(gc.Status.Conditions, computeGatewayClassAcceptedCondition(gc, accepted)) return gc } From 85a61ab49c1e0bf943f89209c5baf8220e8563ad Mon Sep 17 00:00:00 2001 From: Arko Dasgupta Date: Tue, 27 Sep 2022 12:34:39 -0700 Subject: [PATCH 2/2] copy addresses Signed-off-by: Arko Dasgupta --- internal/provider/kubernetes/gateway.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/provider/kubernetes/gateway.go b/internal/provider/kubernetes/gateway.go index f3b2e445b5..8980395f3f 100644 --- a/internal/provider/kubernetes/gateway.go +++ b/internal/provider/kubernetes/gateway.go @@ -351,9 +351,8 @@ func (r *gatewayReconciler) subscribeAndUpdateStatus(ctx context.Context) { } gCopy := g.DeepCopy() gCopy.Status.Conditions = status.MergeConditions(gCopy.Status.Conditions, val.Status.Conditions...) - if len(val.Status.Listeners) > 0 { - gCopy.Status.Listeners = val.Status.Listeners - } + gCopy.Status.Addresses = val.Status.Addresses + gCopy.Status.Listeners = val.Status.Listeners return gCopy }), })