Skip to content

Commit 75d6760

Browse files
authored
fix: kubeconfig state will not be removed if the cluster does not exists anymore (#659)
* fix: kubeconfig state is not removed if the cluster no longer exists and kubeconfig can't be found (status code 404)
1 parent 7f52013 commit 75d6760

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

stackit/internal/services/ske/kubeconfig/resource.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ske
33
import (
44
"context"
55
"fmt"
6+
"net/http"
67
"strconv"
78
"strings"
89
"time"
@@ -23,6 +24,7 @@ import (
2324
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
2425
"github.com/hashicorp/terraform-plugin-framework/types"
2526
"github.com/stackitcloud/stackit-sdk-go/core/config"
27+
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
2628
"github.com/stackitcloud/stackit-sdk-go/core/utils"
2729
"github.com/stackitcloud/stackit-sdk-go/services/ske"
2830
)
@@ -259,6 +261,11 @@ func (r *kubeconfigResource) Read(ctx context.Context, req resource.ReadRequest,
259261

260262
cluster, err := r.client.GetClusterExecute(ctx, projectId, clusterName)
261263
if err != nil {
264+
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
265+
if ok && oapiErr.StatusCode == http.StatusNotFound {
266+
resp.State.RemoveResource(ctx)
267+
return
268+
}
262269
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading kubeconfig", fmt.Sprintf("Could not get cluster(%s): %v", clusterName, err))
263270
return
264271
}

0 commit comments

Comments
 (0)