Skip to content

Commit da36f73

Browse files
committed
Add some context
1 parent 0c70f9b commit da36f73

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

internal/mode/static/handler.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ type eventHandlerImpl struct {
110110
// objectFilters contains all created objectFilters, with the key being a filterKey
111111
objectFilters map[filterKey]objectFilter
112112

113-
// latestReloadResult status.NginxReloadResult
114-
115113
cfg eventHandlerConfig
116114
lock sync.Mutex
117115

internal/mode/static/nginx/agent/agent.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,16 @@ func NewNginxUpdater(
6464
}
6565

6666
// UpdateConfig sends the nginx configuration to the agent.
67-
// Returns whether configuration was applied or not.
67+
// Returns whether the configuration was sent to any agents.
68+
//
69+
// The flow of events is as follows:
70+
// - Set the configuration files on the deployment.
71+
// - Broadcast the message containing file metadata to all pods (subscriptions) for the deployment.
72+
// - Agent receives a ConfigApplyRequest with the list of file metadata.
73+
// - Agent calls GetFile for each file in the list, which we send back to the agent.
74+
// - Agent updates nginx, and responds with a DataPlaneResponse.
75+
// - Subscriber responds back to the broadcaster to inform that the transaction is complete.
76+
// - If any errors occurred, they are set on the deployment for the handler to use in the status update.
6877
func (n *NginxUpdaterImpl) UpdateConfig(
6978
deployment *Deployment,
7079
files []File,
@@ -87,7 +96,7 @@ func (n *NginxUpdaterImpl) UpdateConfig(
8796

8897
// UpdateUpstreamServers sends an APIRequest to the agent to update upstream servers using the NGINX Plus API.
8998
// Only applicable when using NGINX Plus.
90-
// Returns whether configuration was applied or not.
99+
// Returns whether the configuration was sent to any agents.
91100
func (n *NginxUpdaterImpl) UpdateUpstreamServers(
92101
deployment *Deployment,
93102
conf dataplane.Configuration,

internal/mode/static/nginx/agent/broadcast/broadcast.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ type Broadcaster interface {
1919
CancelSubscription(string)
2020
}
2121

22+
// SubscriberChannels are the channels sent to the subscriber to listen and respond on.
23+
// The ID is used for map lookup to delete a subscriber when it's gone.
2224
type SubscriberChannels struct {
2325
ListenCh <-chan NginxAgentMessage
2426
ResponseCh chan<- struct{}
2527
ID string
2628
}
2729

30+
// storedChannels are the same channels used in the SubscriberChannels, but reverse direction.
31+
// These are used to store the channels for the broadcaster to send and listen on,
32+
// and can be looked up in the map using the same ID.
2833
type storedChannels struct {
2934
listenCh chan<- NginxAgentMessage
3035
responseCh <-chan struct{}

internal/mode/static/nginx/agent/command.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ func (cs *commandService) CreateConnection(
105105
}
106106

107107
// Subscribe is a decoupled communication mechanism between the data plane agent and control plane.
108+
// The series of events are as follows:
109+
// - Wait for the agent to register its nginx instance with the control plane.
110+
// - Grab the most recent deployment configuration for itself, and attempt to apply it.
111+
// - Subscribe to any future updates from the NginxUpdater and start a loop to listen for those updates.
112+
// If any connection or unrecoverable errors occur, return and agent should re-establish a subscription.
113+
// If errors occur with applying the config, log and put those errors into the status queue to be written
114+
// to the Gateway status.
108115
func (cs *commandService) Subscribe(in pb.CommandService_SubscribeServer) error {
109116
ctx := in.Context()
110117

@@ -238,6 +245,8 @@ func (cs *commandService) setInitialConfig(
238245
return connErr
239246
}
240247

248+
// TODO(sberman): without a delay, sometimes the following API request will fail because it doesn't
249+
// think the upstreams exist yet. Have to figure this one out.
241250
time.Sleep(1 * time.Second)
242251

243252
var upstreamErr error

internal/mode/static/nginx/agent/grpc/messenger/messenger.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import (
77
pb "github.com/nginx/agent/v3/api/grpc/mpi/v1"
88
)
99

10+
// Messenger is a wrapper around a gRPC stream with the nginx agent.
1011
type Messenger struct {
1112
incoming chan *pb.ManagementPlaneRequest
1213
outgoing chan *pb.DataPlaneResponse
1314
errorCh chan error
1415
server pb.CommandService_SubscribeServer
1516
}
1617

18+
// New returns a new Messenger instance.
1719
func New(server pb.CommandService_SubscribeServer) *Messenger {
1820
return &Messenger{
1921
incoming: make(chan *pb.ManagementPlaneRequest),
@@ -23,6 +25,7 @@ func New(server pb.CommandService_SubscribeServer) *Messenger {
2325
}
2426
}
2527

28+
// Run starts the Messenger to listen for any Send() or Recv() events over the stream.
2629
func (m *Messenger) Run(ctx context.Context) {
2730
go m.handleRecv(ctx)
2831
m.handleSend(ctx)

0 commit comments

Comments
 (0)