From 63c05e0f323a8b10a1b191c1b68d5978cdb7fc09 Mon Sep 17 00:00:00 2001 From: Guangning E Date: Fri, 15 Nov 2024 13:25:35 +0800 Subject: [PATCH 1/3] Fixed delete resouce --- cloud/resource_pulsar_cluster.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/cloud/resource_pulsar_cluster.go b/cloud/resource_pulsar_cluster.go index bb6d20c..6be2e3c 100644 --- a/cloud/resource_pulsar_cluster.go +++ b/cloud/resource_pulsar_cluster.go @@ -18,6 +18,7 @@ import ( "context" "fmt" "github.com/hashicorp/terraform-plugin-log/tflog" + "k8s.io/apimachinery/pkg/api/errors" "strings" "time" @@ -676,7 +677,7 @@ func resourcePulsarClusterUpdate(ctx context.Context, d *schema.ResourceData, me } // Delay 10 seconds to wait for api server start reconcile. time.Sleep(10 * time.Second) - err = retry.RetryContext(ctx, 20*time.Minute, func() *retry.RetryError { + err = retry.RetryContext(ctx, 2*time.Minute, func() *retry.RetryError { dia := resourcePulsarClusterRead(ctx, d, meta) if dia.HasError() { return retry.NonRetryableError(fmt.Errorf("ERROR_RETRY_READ_PULSAR_CLUSTER: %s", dia[0].Summary)) @@ -710,6 +711,23 @@ func resourcePulsarClusterDelete(ctx context.Context, d *schema.ResourceData, me if err != nil { return diag.FromErr(fmt.Errorf("ERROR_DELETE_PULSAR_CLUSTER: %w", err)) } + err = retry.RetryContext(ctx, 20*time.Minute, func() *retry.RetryError { + _, err = clientSet.CloudV1alpha1().PulsarClusters(namespace).Get(ctx, name, metav1.GetOptions{}) + if err != nil { + if statusErr, ok := err.(*errors.StatusError); ok && errors.IsNotFound(statusErr) { + return nil + } + return retry.NonRetryableError(err) + } + + e := fmt.Errorf("pulsarcluster (%s) still exists", d.Id()) + return retry.RetryableError(e) + }) + if err != nil { + return diag.FromErr(fmt.Errorf("ERROR_RETRY_READ_PULSAR_CLUSTER: %w", err)) + } + + d.SetId("") return nil } From 3cca5d5a0afa583b2443763f2c975d66db61f12e Mon Sep 17 00:00:00 2001 From: Guangning E Date: Fri, 15 Nov 2024 13:26:47 +0800 Subject: [PATCH 2/3] Fixed timeout --- cloud/resource_pulsar_cluster.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud/resource_pulsar_cluster.go b/cloud/resource_pulsar_cluster.go index 6be2e3c..77be318 100644 --- a/cloud/resource_pulsar_cluster.go +++ b/cloud/resource_pulsar_cluster.go @@ -677,7 +677,7 @@ func resourcePulsarClusterUpdate(ctx context.Context, d *schema.ResourceData, me } // Delay 10 seconds to wait for api server start reconcile. time.Sleep(10 * time.Second) - err = retry.RetryContext(ctx, 2*time.Minute, func() *retry.RetryError { + err = retry.RetryContext(ctx, 20*time.Minute, func() *retry.RetryError { dia := resourcePulsarClusterRead(ctx, d, meta) if dia.HasError() { return retry.NonRetryableError(fmt.Errorf("ERROR_RETRY_READ_PULSAR_CLUSTER: %s", dia[0].Summary)) From 8b704888d5f2c930556f678a2d3f428b139370aa Mon Sep 17 00:00:00 2001 From: Guangning E Date: Mon, 2 Dec 2024 12:29:37 +0800 Subject: [PATCH 3/3] Fixed timeout --- cloud/resource_pulsar_cluster.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cloud/resource_pulsar_cluster.go b/cloud/resource_pulsar_cluster.go index 4486873..d33020f 100644 --- a/cloud/resource_pulsar_cluster.go +++ b/cloud/resource_pulsar_cluster.go @@ -464,7 +464,7 @@ func resourcePulsarClusterCreate(ctx context.Context, d *schema.ResourceData, me return resourcePulsarClusterRead(ctx, d, meta) } } - err = retry.RetryContext(ctx, 20*time.Minute, func() *retry.RetryError { + err = retry.RetryContext(ctx, d.Timeout(schema.TimeoutCreate), func() *retry.RetryError { dia := resourcePulsarClusterRead(ctx, d, meta) if dia.HasError() { return retry.NonRetryableError(fmt.Errorf("ERROR_RETRY_READ_PULSAR_CLUSTER: %s", dia[0].Summary)) @@ -684,7 +684,7 @@ func resourcePulsarClusterUpdate(ctx context.Context, d *schema.ResourceData, me } // Delay 10 seconds to wait for api server start reconcile. time.Sleep(10 * time.Second) - err = retry.RetryContext(ctx, 20*time.Minute, func() *retry.RetryError { + err = retry.RetryContext(ctx, d.Timeout(schema.TimeoutUpdate), func() *retry.RetryError { dia := resourcePulsarClusterRead(ctx, d, meta) if dia.HasError() { return retry.NonRetryableError(fmt.Errorf("ERROR_RETRY_READ_PULSAR_CLUSTER: %s", dia[0].Summary))