Skip to content

Commit

Permalink
cloud-init secret: no wait on delete
Browse files Browse the repository at this point in the history
Don't wait for a state change when deleting a cloud-init secret. The
cloud-init secret is just a normal core/v1 Secret API object. These
don't have a state, they either exist or they don't but there is not any
intermediate state like the is with a VM or a Pod. As a consequence,
it's not necessary to wait for a state change when deleting a secret.

Signed-off-by: Moritz Röhrich <[email protected]>
  • Loading branch information
m-ildefons committed Jun 4, 2024
1 parent b14edf3 commit 346d0e0
Showing 1 changed file with 0 additions and 41 deletions.
41 changes: 0 additions & 41 deletions internal/provider/cloudinitsecret/resource_cloudinitsecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package cloudinitsecret
import (
"context"
"encoding/base64"
"errors"
"fmt"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -111,18 +109,6 @@ func resourceCloudInitSecretDelete(ctx context.Context, d *schema.ResourceData,
return diag.FromErr(err)
}

stateConf := &resource.StateChangeConf{
Pending: []string{constants.StateImageTerminating, constants.StateCommonActive},
Target: []string{constants.StateCommonRemoved},
Refresh: resourceCloudInitSecretRefresh(ctx, d, meta),
Timeout: d.Timeout(schema.TimeoutDelete),
Delay: 1 * time.Second,
MinTimeout: 3 * time.Second,
}
_, err = stateConf.WaitForStateContext(ctx)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
Expand Down Expand Up @@ -152,30 +138,3 @@ func resourceCloudInitSecretImport(d *schema.ResourceData, obj *corev1.Secret) e

return util.ResourceStatesSet(d, stateGetter)
}

func resourceCloudInitSecretRefresh(ctx context.Context, d *schema.ResourceData, meta interface{}) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
c := meta.(*client.Client)
namespace := d.Get(constants.FieldCommonNamespace).(string)
name := d.Get(constants.FieldCommonName).(string)

obj, err := c.KubeClient.CoreV1().Secrets(namespace).Get(ctx, name, metav1.GetOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
return obj, constants.StateCommonRemoved, nil
}
return obj, constants.StateCommonError, err
}

if err = resourceCloudInitSecretImport(d, obj); err != nil {
return obj, constants.StateCommonError, err
}

state := d.Get(constants.FieldCommonState).(string)
if state == constants.StateCommonFailed {
message := d.Get(constants.FieldCommonMessage).(string)
return obj, state, errors.New(message)
}
return obj, state, err
}
}

0 comments on commit 346d0e0

Please sign in to comment.