From 9c0557f2846402dce016a81a2c2711da7c271620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Ars?= <29622411+gaetanars@users.noreply.github.com> Date: Mon, 3 Apr 2023 18:04:21 +0200 Subject: [PATCH] fix: review --- internal/provider/alb/pool_common.go | 2 +- internal/provider/alb/pool_resource.go | 27 ++++++++--------------- internal/provider/common/edgegw/edgegw.go | 7 ++---- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/internal/provider/alb/pool_common.go b/internal/provider/alb/pool_common.go index 16dd2203..2daef1dd 100644 --- a/internal/provider/alb/pool_common.go +++ b/internal/provider/alb/pool_common.go @@ -40,7 +40,7 @@ func processHealthMonitors(poolHealthMonitors []govcdtypes.NsxtAlbPoolHealthMoni } func processPersistenceProfile(poolPersistenceProfile *govcdtypes.NsxtAlbPoolPersistenceProfile) persistenceProfile { - if poolPersistenceProfile != nil { + if poolPersistenceProfile == nil { return persistenceProfile{} } diff --git a/internal/provider/alb/pool_resource.go b/internal/provider/alb/pool_resource.go index 36551bc1..5256372e 100644 --- a/internal/provider/alb/pool_resource.go +++ b/internal/provider/alb/pool_resource.go @@ -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) @@ -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 @@ -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) @@ -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() diff --git a/internal/provider/common/edgegw/edgegw.go b/internal/provider/common/edgegw/edgegw.go index cb0bcfe6..24ba5b01 100644 --- a/internal/provider/common/edgegw/edgegw.go +++ b/internal/provider/common/edgegw/edgegw.go @@ -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" @@ -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 }