Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve deleteUnreachable workflow #2489

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Unreleased

- Improve deleteUnreachable workflow for unreachable clusters (https://github.com/pulumi/pulumi-kubernetes/pull/2489)

## 3.30.1 (June 29, 2023)

- Add experimental helmChart support to kustomize.Directory (https://github.com/pulumi/pulumi-kubernetes/pull/2471)
Expand Down
31 changes: 20 additions & 11 deletions provider/pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1953,18 +1953,18 @@ func (k *kubeProvider) Read(ctx context.Context, req *pulumirpc.ReadRequest) (*p

// If the cluster is unreachable, return an error unless the user has opted in to mark the resources to be deleted
if k.clusterUnreachable {
_ = k.host.Log(ctx, diag.Warning, urn, fmt.Sprintf(
"configured Kubernetes cluster is unreachable: %s", k.clusterUnreachableReason))
if k.deleteUnreachable {
_ = k.host.Log(ctx, diag.Warning, urn, fmt.Sprintf(
"configured Kubernetes cluster is unreachable and configuration is specified to ensure that "+
"the resources are deleted: %s", k.clusterUnreachableReason))
_ = k.host.Log(ctx, diag.Info, urn, fmt.Sprintf(
"configured Kubernetes cluster is unreachable and the `deleteUnreachable` option is enabled. "+
"Deleting the unreachable resource from Pulumi state"))
return deleteResponse, nil
}

_ = k.host.Log(ctx, diag.Warning, urn, fmt.Sprintf(
"configured Kubernetes cluster is unreachable: %s", k.clusterUnreachableReason))
return nil, fmt.Errorf("failed to read resource state due to unreachable cluster. " +
"If the cluster has been deleted, you can edit the pulumi state to remove this resource or retry " +
"with the PULUMI_K8S_DELETE_UNREACHABLE environment variable set to true.")
return nil, fmt.Errorf("failed to read resource state due to unreachable cluster. If the cluster was " +
"deleted, you can remove this resource from Pulumi state by rerunning the operation with the " +
"PULUMI_K8S_DELETE_UNREACHABLE environment variable set to \"true\"")
}

if isHelmRelease(urn) {
Expand Down Expand Up @@ -2459,9 +2459,18 @@ func (k *kubeProvider) Delete(ctx context.Context, req *pulumirpc.DeleteRequest)
}

if k.clusterUnreachable {
return nil, fmt.Errorf("configured Kubernetes cluster is unreachable: %s\n"+
"If the cluster has been deleted, you can edit the pulumi state to remove this resource",
k.clusterUnreachableReason)
_ = k.host.Log(ctx, diag.Warning, urn, fmt.Sprintf(
"configured Kubernetes cluster is unreachable: %s", k.clusterUnreachableReason))
if k.deleteUnreachable {
_ = k.host.Log(ctx, diag.Info, urn, fmt.Sprintf(
"configured Kubernetes cluster is unreachable and the `deleteUnreachable` option is enabled. "+
"Deleting the unreachable resource from Pulumi state"))
return &pbempty.Empty{}, nil
}

return nil, fmt.Errorf("configured Kubernetes cluster is unreachable. If the cluster was deleted, " +
"you can remove this resource from Pulumi state by rerunning the operation with the " +
"PULUMI_K8S_DELETE_UNREACHABLE environment variable set to \"true\"")
}

initialAPIVersion, err := initialAPIVersion(oldState, &unstructured.Unstructured{})
Expand Down
Loading