From dcff6f985450462a4ffbdc81d9207d2a6adbdfca Mon Sep 17 00:00:00 2001 From: Fabian Fulga Date: Mon, 2 Sep 2024 10:53:26 +0300 Subject: [PATCH] Add getProviderBaseParams function in basePoolManager --- runner/pool/pool.go | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/runner/pool/pool.go b/runner/pool/pool.go index 384bd517..4d317dd9 100644 --- a/runner/pool/pool.go +++ b/runner/pool/pool.go @@ -130,6 +130,16 @@ type basePoolManager struct { keyMux *keyMutex } +func (r *basePoolManager) getProviderBaseParams(pool params.Pool) common.ProviderBaseParams { + r.mux.Lock() + defer r.mux.Unlock() + + return common.ProviderBaseParams{ + PoolInfo: pool, + ControllerInfo: r.controllerInfo, + } +} + func (r *basePoolManager) HandleWorkflowJob(job params.WorkflowJob) error { if err := r.ValidateOwner(job); err != nil { return errors.Wrap(err, "validating owner") @@ -591,10 +601,7 @@ func (r *basePoolManager) cleanupOrphanedGithubRunners(runners []*github.Runner) "pool_id", pool.ID) listInstancesParams := common.ListInstancesParams{ ListInstancesV011: common.ListInstancesV011Params{ - ProviderBaseParams: common.ProviderBaseParams{ - PoolInfo: pool, - ControllerInfo: r.controllerInfo, - }, + ProviderBaseParams: r.getProviderBaseParams(pool), }, } poolInstances, err = provider.ListInstances(r.ctx, pool.ID, listInstancesParams) @@ -664,10 +671,7 @@ func (r *basePoolManager) cleanupOrphanedGithubRunners(runners []*github.Runner) startParams := common.StartParams{ StartV011: common.StartV011Params{ - ProviderBaseParams: common.ProviderBaseParams{ - PoolInfo: pool, - ControllerInfo: r.controllerInfo, - }, + ProviderBaseParams: r.getProviderBaseParams(pool), }, } if err := provider.Start(r.ctx, dbInstance.ProviderID, startParams); err != nil { @@ -888,10 +892,7 @@ func (r *basePoolManager) addInstanceToProvider(instance params.Instance) error if instanceIDToDelete != "" { deleteInstanceParams := common.DeleteInstanceParams{ DeleteInstanceV011: common.DeleteInstanceV011Params{ - ProviderBaseParams: common.ProviderBaseParams{ - PoolInfo: pool, - ControllerInfo: r.controllerInfo, - }, + ProviderBaseParams: r.getProviderBaseParams(pool), }, } if err := provider.DeleteInstance(r.ctx, instanceIDToDelete, deleteInstanceParams); err != nil { @@ -906,10 +907,7 @@ func (r *basePoolManager) addInstanceToProvider(instance params.Instance) error createInstanceParams := common.CreateInstanceParams{ CreateInstanceV011: common.CreateInstanceV011Params{ - ProviderBaseParams: common.ProviderBaseParams{ - PoolInfo: pool, - ControllerInfo: r.controllerInfo, - }, + ProviderBaseParams: r.getProviderBaseParams(pool), }, } providerInstance, err := provider.CreateInstance(r.ctx, bootstrapArgs, createInstanceParams) @@ -1350,10 +1348,7 @@ func (r *basePoolManager) deleteInstanceFromProvider(ctx context.Context, instan deleteInstanceParams := common.DeleteInstanceParams{ DeleteInstanceV011: common.DeleteInstanceV011Params{ - ProviderBaseParams: common.ProviderBaseParams{ - PoolInfo: pool, - ControllerInfo: r.controllerInfo, - }, + ProviderBaseParams: r.getProviderBaseParams(pool), }, } if err := provider.DeleteInstance(ctx, identifier, deleteInstanceParams); err != nil {