Skip to content

Commit

Permalink
fix(flink): poll application deployment deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
byashimov committed Feb 22, 2024
1 parent 5fb3fdf commit ef33a0a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 53 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ nav_order: 1
- Fix `aiven_organization_user_group` resource - `description` field is required
- Use golang 1.22
- Output explicitly `termination_protection = true -> false` when service property is removed
- Fix `aiven_flink_application_deployment` deletion

## [4.13.3] - 2024-01-29

Expand Down
20 changes: 0 additions & 20 deletions internal/plugin/util/wait.go

This file was deleted.

53 changes: 20 additions & 33 deletions internal/sdkprovider/service/flink/flink_application_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/aiven/aiven-go-client/v2"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"

Expand Down Expand Up @@ -135,42 +134,30 @@ func resourceFlinkApplicationDeploymentDelete(
return diag.Errorf("cannot read Flink Application Deployment resource ID: %v", err)
}

_, err = client.FlinkApplicationDeployments.Cancel(ctx, project, serviceName, applicationID, deploymentID)
if err != nil {
return diag.Errorf("error cancelling Flink Application Deployment: %v", err)
}

//goland:noinspection GoDeprecation
conf := &retry.StateChangeConf{
Pending: []string{
"CANCELLING",
},
Target: []string{
"CANCELED",
},
Refresh: func() (interface{}, string, error) {
r, err := client.FlinkApplicationDeployments.Get(ctx, project, serviceName, applicationID, deploymentID)
if err != nil {
return nil, "", err
// Flink Application Deployment has a quite complicated state machine
// https://api.aiven.io/doc/#tag/Service:_Flink/operation/ServiceFlinkDeleteApplicationDeployment
// Retries until succeeds or exceeds the timeout
for {
select {
case <-ctx.Done():
// The context itself already comes with delete timeout
return diag.Errorf("can't delete Flink Application Deployment %q: %s", ctx.Err())

Check failure on line 144 in internal/sdkprovider/service/flink/flink_application_deployment.go

View workflow job for this annotation

GitHub Actions / go_test

github.com/hashicorp/terraform-plugin-sdk/v2/diag.Errorf format %s reads arg #2, but call has 1 arg

Check failure on line 144 in internal/sdkprovider/service/flink/flink_application_deployment.go

View workflow job for this annotation

GitHub Actions / make_lint

printf: github.com/hashicorp/terraform-plugin-sdk/v2/diag.Errorf format %s reads arg #2, but call has 1 arg (govet)

Check failure on line 144 in internal/sdkprovider/service/flink/flink_application_deployment.go

View workflow job for this annotation

GitHub Actions / go_test

github.com/hashicorp/terraform-plugin-sdk/v2/diag.Errorf format %s reads arg #2, but call has 1 arg

Check failure on line 144 in internal/sdkprovider/service/flink/flink_application_deployment.go

View workflow job for this annotation

GitHub Actions / make_lint

printf: github.com/hashicorp/terraform-plugin-sdk/v2/diag.Errorf format %s reads arg #2, but call has 1 arg (govet)
case <-time.After(time.Second):
_, err := client.FlinkApplicationDeployments.Get(ctx, project, serviceName, applicationID, deploymentID)
if aiven.IsNotFound(err) {
return nil
}
return r, r.Status, nil
},
Delay: 1 * time.Second,
Timeout: d.Timeout(schema.TimeoutDelete),
MinTimeout: 1 * time.Second,
}

_, err = conf.WaitForStateContext(ctx)
if err != nil {
return diag.Errorf("error waiting for Flink Application Deployment to become canceled: %s", err)
}
// Must be canceled before deleted
_, err = client.FlinkApplicationDeployments.Cancel(ctx, project, serviceName, applicationID, deploymentID)
if err == nil {
continue
}

_, err = client.FlinkApplicationDeployments.Delete(ctx, project, serviceName, applicationID, deploymentID)
if err != nil {
return diag.Errorf("error deleting Flink Application Deployment: %v", err)
// Completely ignores all errors, until it gets 404 on GET request
_, _ = client.FlinkApplicationDeployments.Delete(ctx, project, serviceName, applicationID, deploymentID)
}
}

return nil
}

// resourceFlinkApplicationDeploymentRead reads an existing Flink Application Deployment resource.
Expand Down

0 comments on commit ef33a0a

Please sign in to comment.