@@ -19,8 +19,6 @@ package controllers
1919import (
2020 "context"
2121 "fmt"
22- "time"
23-
2422 "github.com/golang/glog"
2523 "github.com/pkg/errors"
2624
@@ -258,21 +256,15 @@ func (r *GatewayReconciler) cleanupGatewayResources(ctx context.Context, gw *gat
258256
259257func (r * GatewayReconciler ) updateGatewayStatus (ctx context.Context , serviceNetworkStatus * latticestore.ServiceNetwork , gw * gateway_api.Gateway ) error {
260258
261- glog .V (6 ).Infof ("updateGatewayStatus: updating last transition time \n " )
262259 gwOld := gw .DeepCopy ()
263260
264- if len (gw .Status .Conditions ) <= 1 {
265- condition := metav1.Condition {}
266- gw .Status .Conditions = append (gw .Status .Conditions , condition )
267- }
268-
269- gw .Status .Conditions [1 ].LastTransitionTime = metav1 .NewTime (time .Now ())
270- gw .Status .Conditions [1 ].Status = "True"
271- gw .Status .Conditions [1 ].Message = fmt .Sprintf ("aws-gateway-arn: %s" , serviceNetworkStatus .ARN )
272- gw .Status .Conditions [1 ].Reason = "Reconciled"
273- gw .Status .Conditions [1 ].ObservedGeneration = gw .Generation
274- gw .Status .Conditions [0 ].ObservedGeneration = gw .Generation // update the accept
275- gw .Status .Conditions [1 ].Type = string (gateway_api .GatewayConditionProgrammed )
261+ gw .Status .Conditions = updateCondition (gw .Status .Conditions , metav1.Condition {
262+ Type : string (gateway_api .GatewayConditionProgrammed ),
263+ Status : metav1 .ConditionTrue ,
264+ ObservedGeneration : gw .Generation ,
265+ Reason : string (gateway_api .GatewayReasonProgrammed ),
266+ Message : fmt .Sprintf ("aws-gateway-arn: %s" , serviceNetworkStatus .ARN ),
267+ })
276268
277269 // TODO following is causing crash on some platform, see https://t.corp.amazon.com/b7c9ea6c-5168-4616-b718-c1bdf78dbdf1/communication
278270 //gw.Annotations["gateway.networking.k8s.io/aws-gateway-id"] = serviceNetworkStatus.ID
@@ -289,20 +281,25 @@ func (r *GatewayReconciler) updateGatewayAcceptStatus(ctx context.Context, gw *g
289281
290282 gwOld := gw .DeepCopy ()
291283
292- glog .V (6 ).Infof ("updateGatewayStatus: updating last transition time \n " )
293- if gw .Status .Conditions [0 ].LastTransitionTime == eventhandlers .ZeroTransitionTime {
294- gw .Status .Conditions [0 ].LastTransitionTime = metav1 .NewTime (time .Now ())
295- }
284+ var cond metav1.Condition
296285 if accepted {
297- gw .Status .Conditions [0 ].Status = "True"
298- gw .Status .Conditions [0 ].Reason = "Accepted"
286+ cond = metav1.Condition {
287+ Type : string (gateway_api .GatewayConditionAccepted ),
288+ ObservedGeneration : gw .Generation ,
289+ Message : config .LatticeGatewayControllerName ,
290+ Status : metav1 .ConditionTrue ,
291+ Reason : string (gateway_api .GatewayReasonAccepted ),
292+ }
299293 } else {
300- gw .Status .Conditions [0 ].Status = "False"
301- gw .Status .Conditions [0 ].Reason = "Invalid"
294+ cond = metav1.Condition {
295+ Type : string (gateway_api .GatewayConditionAccepted ),
296+ ObservedGeneration : gw .Generation ,
297+ Message : config .LatticeGatewayControllerName ,
298+ Status : metav1 .ConditionFalse ,
299+ Reason : string (gateway_api .GatewayReasonInvalid ),
300+ }
302301 }
303- gw .Status .Conditions [0 ].Message = config .LatticeGatewayControllerName
304- gw .Status .Conditions [0 ].ObservedGeneration = gw .Generation
305- gw .Status .Conditions [0 ].Type = string (gateway_api .GatewayConditionAccepted )
302+ gw .Status .Conditions = updateCondition (gw .Status .Conditions , cond )
306303
307304 if err := r .Client .Status ().Patch (ctx , gw , client .MergeFrom (gwOld )); err != nil {
308305 glog .V (2 ).Infof ("Failed to Patch acceptance status, err %v gw %v" , err , gw )
@@ -312,27 +309,6 @@ func (r *GatewayReconciler) updateGatewayAcceptStatus(ctx context.Context, gw *g
312309 return nil
313310}
314311
315- func (r * GatewayReconciler ) updateBadStatus (ctx context.Context , message string , gw * gateway_api.Gateway ) error {
316-
317- gwOld := gw .DeepCopy ()
318-
319- glog .V (6 ).Infof ("updateGatewayStatus: updating last transition time \n " )
320- if gw .Status .Conditions [0 ].LastTransitionTime == eventhandlers .ZeroTransitionTime {
321- gw .Status .Conditions [0 ].LastTransitionTime = metav1 .NewTime (time .Now ())
322- }
323-
324- gw .Status .Conditions [0 ].Status = "False"
325- gw .Status .Conditions [0 ].Message = message
326- gw .Status .Conditions [0 ].Reason = "NoReconcile"
327- gw .Status .Conditions [0 ].Type = "NotAccepted"
328-
329- if err := r .Client .Status ().Patch (ctx , gw , client .MergeFrom (gwOld )); err != nil {
330- return errors .Wrapf (err , "failed to update gateway status" )
331- }
332-
333- return nil
334- }
335-
336312func UpdateHTTPRouteListenerStatus (ctx context.Context , k8sclient client.Client , httproute * gateway_api.HTTPRoute ) error {
337313 gw := & gateway_api.Gateway {}
338314
@@ -391,8 +367,6 @@ func UpdateGWListenerStatus(ctx context.Context, k8sclient client.Client, gw *ga
391367
392368 glog .V (6 ).Infof ("Before update, the snapshot of listeners %v \n " , gw .Status .Listeners )
393369
394- gw .Status .Listeners = make ([]gateway_api.ListenerStatus , 0 )
395-
396370 httpRouteList := & gateway_api.HTTPRouteList {}
397371
398372 k8sclient .List (context .TODO (), httpRouteList )
@@ -441,7 +415,7 @@ func UpdateGWListenerStatus(ctx context.Context, k8sclient client.Client, gw *ga
441415 Status : metav1 .ConditionFalse ,
442416 Reason : string (gateway_api .ListenerReasonInvalidRouteKinds ),
443417 ObservedGeneration : gw .Generation ,
444- LastTransitionTime : metav1 .NewTime ( time . Now () ),
418+ LastTransitionTime : metav1 .Now (),
445419 }
446420 listenerStatus .SupportedKinds = supportedkind
447421 listenerStatus .Conditions = append (listenerStatus .Conditions , condition )
@@ -451,12 +425,11 @@ func UpdateGWListenerStatus(ctx context.Context, k8sclient client.Client, gw *ga
451425 hasValidListener = true
452426
453427 condition := metav1.Condition {
454- Type : "Accepted" ,
455- Status : "True" ,
456- Reason : "Accepted" ,
428+ Type : string ( gateway_api . ListenerConditionAccepted ) ,
429+ Status : metav1 . ConditionTrue ,
430+ Reason : string ( gateway_api . ListenerReasonAccepted ) ,
457431 ObservedGeneration : gw .Generation ,
458- // TODO need to use previous one
459- LastTransitionTime : metav1 .NewTime (time .Now ()),
432+ LastTransitionTime : metav1 .Now (),
460433 }
461434
462435 for _ , httpRoute := range httpRouteList .Items {
@@ -499,8 +472,20 @@ func UpdateGWListenerStatus(ctx context.Context, k8sclient client.Client, gw *ga
499472 listenerStatus .Conditions = append (listenerStatus .Conditions , condition )
500473
501474 }
502- gw .Status .Listeners = append (gw .Status .Listeners , listenerStatus )
503475
476+ found := false
477+ for i , oldStatus := range gw .Status .Listeners {
478+ if oldStatus .Name == listenerStatus .Name {
479+ gw .Status .Listeners [i ].AttachedRoutes = listenerStatus .AttachedRoutes
480+ gw .Status .Listeners [i ].SupportedKinds = listenerStatus .SupportedKinds
481+ // Only have one condition in the logic
482+ gw .Status .Listeners [i ].Conditions = updateCondition (gw .Status .Listeners [i ].Conditions , listenerStatus .Conditions [0 ])
483+ found = true
484+ }
485+ }
486+ if ! found {
487+ gw .Status .Listeners = append (gw .Status .Listeners , listenerStatus )
488+ }
504489 }
505490
506491 glog .V (6 ).Infof ("After update, the snapshot of listener status %v" , gw .Status .Listeners )
0 commit comments