Skip to content

Commit

Permalink
fix: review
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetanars committed Apr 3, 2023
1 parent 10c60c2 commit 9c0557f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
2 changes: 1 addition & 1 deletion internal/provider/alb/pool_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func processHealthMonitors(poolHealthMonitors []govcdtypes.NsxtAlbPoolHealthMoni
}

func processPersistenceProfile(poolPersistenceProfile *govcdtypes.NsxtAlbPoolPersistenceProfile) persistenceProfile {
if poolPersistenceProfile != nil {
if poolPersistenceProfile == nil {
return persistenceProfile{}
}

Expand Down
27 changes: 9 additions & 18 deletions internal/provider/alb/pool_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,8 @@ func (r *albPoolResource) Create(ctx context.Context, req resource.CreateRequest
resp.Diagnostics.AddError("Unable to get Edge Gateway", err.Error())
return
}
resp.Diagnostics.Append(edgeGW.Lock(ctx)...)
if resp.Diagnostics.HasError() {
return
}
defer resp.Diagnostics.Append(edgeGW.Unlock(ctx)...)
edgeGW.Lock(ctx)
defer edgeGW.Unlock(ctx)

// Create ALB Pool
createdAlbPool, err := r.client.Vmware.CreateNsxtAlbPool(albPoolConfig)
Expand Down Expand Up @@ -197,10 +194,10 @@ func (r *albPoolResource) Read(ctx context.Context, req resource.ReadRequest, re
}

// Set health monitors.
healtMonitors := processHealthMonitors(albPool.NsxtAlbPool.HealthMonitors)
healthMonitors := processHealthMonitors(albPool.NsxtAlbPool.HealthMonitors)

if len(healtMonitors) > 0 {
plan.HealthMonitors, diags = types.SetValueFrom(ctx, types.StringType, healtMonitors)
if len(healthMonitors) > 0 {
plan.HealthMonitors, diags = types.SetValueFrom(ctx, types.StringType, healthMonitors)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
Expand Down Expand Up @@ -258,11 +255,8 @@ func (r *albPoolResource) Update(ctx context.Context, req resource.UpdateRequest
resp.Diagnostics.AddError("Unable to get Edge Gateway", err.Error())
return
}
resp.Diagnostics.Append(edgeGW.Lock(ctx)...)
if resp.Diagnostics.HasError() {
return
}
defer resp.Diagnostics.Append(edgeGW.Unlock(ctx)...)
edgeGW.Lock(ctx)
defer edgeGW.Unlock(ctx)

// Update ALB Pool.
_, err = albPool.Update(albPoolConfig)
Expand Down Expand Up @@ -297,11 +291,8 @@ func (r *albPoolResource) Delete(ctx context.Context, req resource.DeleteRequest
resp.Diagnostics.AddError("Unable to get Edge Gateway", err.Error())
return
}
resp.Diagnostics.Append(edgeGW.Lock(ctx)...)
if resp.Diagnostics.HasError() {
return
}
defer resp.Diagnostics.Append(edgeGW.Unlock(ctx)...)
edgeGW.Lock(ctx)
defer edgeGW.Unlock(ctx)

// Get albPool
albPool, err := r.GetAlbPool()
Expand Down
7 changes: 2 additions & 5 deletions internal/provider/common/edgegw/edgegw.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/vmware/go-vcloud-director/v2/govcd"

"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"

"github.com/orange-cloudavenue/terraform-provider-cloudavenue/internal/client"
Expand Down Expand Up @@ -67,13 +66,11 @@ func (e EdgeGateway) GetID() string {
}

// Lock locks the Edge Gateway.
func (e EdgeGateway) Lock(ctx context.Context) (d diag.Diagnostics) {
func (e EdgeGateway) Lock(ctx context.Context) {
gwMutexKV.KvLock(ctx, e.GetID())
return
}

// Unlock unlocks the Edge Gateway.
func (e EdgeGateway) Unlock(ctx context.Context) (d diag.Diagnostics) {
func (e EdgeGateway) Unlock(ctx context.Context) {
gwMutexKV.KvUnlock(ctx, e.GetID())
return
}

0 comments on commit 9c0557f

Please sign in to comment.