@@ -6,22 +6,25 @@ import (
66
77	"github.com/go-logr/logr" 
88	"github.com/nginxinc/nginx-gateway-kubernetes/internal/state" 
9+ 	"github.com/nginxinc/nginx-gateway-kubernetes/internal/status" 
910	"sigs.k8s.io/gateway-api/apis/v1alpha2" 
1011)
1112
1213// EventLoop is the main event loop of the Gateway. 
1314type  EventLoop  struct  {
14- 	conf     state.Configuration 
15- 	eventCh  <- chan  interface {}
16- 	logger   logr.Logger 
15+ 	conf           state.Configuration 
16+ 	eventCh        <- chan  interface {}
17+ 	logger         logr.Logger 
18+ 	statusUpdater  status.Updater 
1719}
1820
1921// NewEventLoop creates a new EventLoop. 
20- func  NewEventLoop (conf  state.Configuration , eventCh  <- chan  interface {}, logger  logr.Logger ) * EventLoop  {
22+ func  NewEventLoop (conf  state.Configuration , eventCh  <- chan  interface {}, statusUpdater  status. Updater ,  logger  logr.Logger ) * EventLoop  {
2123	return  & EventLoop {
22- 		conf :    conf ,
23- 		eventCh : eventCh ,
24- 		logger :  logger .WithName ("eventLoop" ),
24+ 		conf :          conf ,
25+ 		eventCh :       eventCh ,
26+ 		statusUpdater : statusUpdater ,
27+ 		logger :        logger .WithName ("eventLoop" ),
2528	}
2629}
2730
@@ -35,7 +38,7 @@ func (el *EventLoop) Start(ctx context.Context) error {
3538		case  <- ctx .Done ():
3639			return  nil 
3740		case  e  :=  <- el .eventCh :
38- 			err  :=  el .handleEvent (e )
41+ 			err  :=  el .handleEvent (ctx ,  e )
3942			if  err  !=  nil  {
4043				return  err 
4144			}
@@ -44,7 +47,7 @@ func (el *EventLoop) Start(ctx context.Context) error {
4447}
4548
4649// TO-DO: think about how to avoid using an interface{} here 
47- func  (el  * EventLoop ) handleEvent (event  interface {}) error  {
50+ func  (el  * EventLoop ) handleEvent (ctx  context. Context ,  event  interface {}) error  {
4851	var  changes  []state.Change 
4952	var  updates  []state.StatusUpdate 
5053	var  err  error 
@@ -55,15 +58,15 @@ func (el *EventLoop) handleEvent(event interface{}) error {
5558	case  * DeleteEvent :
5659		changes , updates , err  =  el .propagateDelete (e )
5760	default :
61+ 		// TO-DO: panic 
5862		return  fmt .Errorf ("unknown event type %T" , e )
5963	}
6064
6165	if  err  !=  nil  {
6266		return  err 
6367	}
6468
65- 	el .processChangesAndStatusUpdates (changes , updates )
66- 
69+ 	el .processChangesAndStatusUpdates (ctx , changes , updates )
6770	return  nil 
6871}
6972
@@ -87,7 +90,7 @@ func (el *EventLoop) propagateDelete(e *DeleteEvent) ([]state.Change, []state.St
8790	return  nil , nil , fmt .Errorf ("unknown resource type %T" , e .Type )
8891}
8992
90- func  (el  * EventLoop ) processChangesAndStatusUpdates (changes  []state.Change , updates  []state.StatusUpdate ) {
93+ func  (el  * EventLoop ) processChangesAndStatusUpdates (ctx  context. Context ,  changes  []state.Change , updates  []state.StatusUpdate ) {
9194	for  _ , c  :=  range  changes  {
9295		el .logger .Info ("Processing a change" ,
9396			"host" , c .Host .Value )
@@ -96,13 +99,5 @@ func (el *EventLoop) processChangesAndStatusUpdates(changes []state.Change, upda
9699		fmt .Printf ("%+v\n " , c )
97100	}
98101
99- 	for  _ , u  :=  range  updates  {
100- 		// TO-DO: in the next iteration, the update will include the namespace/name of the resource instead of 
101- 		// runtime.Object, so it will be easy to get the resource namespace/name and include it in the log output 
102- 		el .logger .Info ("Processing a status update" ,
103- 			"gvk" , u .Object .GetObjectKind ().GroupVersionKind ().String ())
104- 
105- 		// TO-DO: This code is temporary. We will remove it once we have a component that updates statuses. 
106- 		fmt .Printf ("%+v\n " , u )
107- 	}
102+ 	el .statusUpdater .ProcessStatusUpdates (ctx , updates )
108103}
0 commit comments