4141 subscribeClient mpi.CommandService_SubscribeClient
4242 agentConfig * config.Config
4343 isConnected * atomic.Bool
44+ clientUpdated * atomic.Bool
4445 subscribeChannel chan * mpi.ManagementPlaneRequest
4546 configApplyRequestQueue map [string ][]* mpi.ManagementPlaneRequest // key is the instance ID
4647 resource * mpi.Resource
@@ -58,10 +59,14 @@ func NewCommandService(
5859 isConnected := & atomic.Bool {}
5960 isConnected .Store (false )
6061
62+ clientUpdated := & atomic.Bool {}
63+ clientUpdated .Store (false )
64+
6165 commandService := & CommandService {
6266 commandServiceClient : commandServiceClient ,
6367 agentConfig : agentConfig ,
6468 isConnected : isConnected ,
69+ clientUpdated : clientUpdated ,
6570 subscribeChannel : subscribeChannel ,
6671 configApplyRequestQueue : make (map [string ][]* mpi.ManagementPlaneRequest ),
6772 resource : & mpi.Resource {},
@@ -210,6 +215,10 @@ func (cs *CommandService) CreateConnection(
210215 slog .InfoContext (ctx , "No Data Plane Instance found" )
211216 }
212217
218+ if cs .isConnected .Load () {
219+ return nil , errors .New ("command service already connected" )
220+ }
221+
213222 request := & mpi.CreateConnectionRequest {
214223 MessageMeta : & mpi.MessageMeta {
215224 MessageId : id .GenerateMessageID (),
@@ -228,7 +237,6 @@ func (cs *CommandService) CreateConnection(
228237 }
229238
230239 slog .DebugContext (ctx , "Sending create connection request" , "request" , request )
231-
232240 response , err := backoff .RetryWithData (
233241 cs .connectCallback (ctx , request ),
234242 backoffHelpers .Context (ctx , commonSettings ),
@@ -249,6 +257,17 @@ func (cs *CommandService) CreateConnection(
249257 return response , nil
250258}
251259
260+ func (cs * CommandService ) UpdateClient (client mpi.CommandServiceClient ) {
261+ cs .commandServiceClient = client
262+ cs .clientUpdated .Store (true )
263+ }
264+
265+ func (cs * CommandService ) Resource () * mpi.Resource {
266+ cs .resourceMutex .Lock ()
267+ defer cs .resourceMutex .Unlock ()
268+ return cs .resource
269+ }
270+
252271// Retry callback for sending a data plane response to the Management Plane.
253272func (cs * CommandService ) sendDataPlaneResponseCallback (
254273 ctx context.Context ,
0 commit comments