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

🐛 tenancy/workspace-deletion: try harder with the admin client to delete the LogicalCluster #3119

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 pkg/reconciler/tenancy/workspace/workspace_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ func (c *Controller) reconcile(ctx context.Context, ws *tenancyv1alpha1.Workspac
deleteLogicalCluster: func(ctx context.Context, cluster logicalcluster.Path) error {
return c.kcpExternalClient.Cluster(cluster).CoreV1alpha1().LogicalClusters().Delete(ctx, corev1alpha1.LogicalClusterName, metav1.DeleteOptions{})
},
getShardByHash: getShardByName,
kcpLogicalClusterAdminClientFor: kcpDirectClientFor,
},
&schedulingReconciler{
generateClusterName: randomClusterName,
Expand Down
39 changes: 35 additions & 4 deletions pkg/reconciler/tenancy/workspace/workspace_reconcile_deletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import (
"context"
"fmt"

kcpclientset "github.com/kcp-dev/kcp/sdk/client/clientset/versioned/cluster"
"github.com/kcp-dev/logicalcluster/v3"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/util/sets"
Expand All @@ -33,6 +35,10 @@ import (
type deletionReconciler struct {
getLogicalCluster func(ctx context.Context, cluster logicalcluster.Path) (*corev1alpha1.LogicalCluster, error)
deleteLogicalCluster func(ctx context.Context, cluster logicalcluster.Path) error

getShardByHash func(hash string) (*corev1alpha1.Shard, error)

kcpLogicalClusterAdminClientFor func(shard *corev1alpha1.Shard) (kcpclientset.ClusterInterface, error)
}

func (r *deletionReconciler) reconcile(ctx context.Context, workspace *tenancyv1alpha1.Workspace) (reconcileStatus, error) {
Expand Down Expand Up @@ -62,10 +68,35 @@ func (r *deletionReconciler) reconcile(ctx context.Context, workspace *tenancyv1
clusterName = logicalcluster.Name(a)
}

logicalCluster, err := r.getLogicalCluster(ctx, clusterName.Path())
if err != nil && !apierrors.IsNotFound(err) {
return reconcileStatusStopAndRequeue, err
} else if apierrors.IsNotFound(err) {
logicalCluster, getErr := r.getLogicalCluster(ctx, clusterName.Path())
if getErr != nil && !apierrors.IsNotFound(getErr) {
// try again with a direct connection. It might be that the front-proxy
// does not know about the logical cluster. We don't want to leak, so
// try extra hard.
shardNameHash, hasShard := workspace.Annotations[WorkspaceShardHashAnnotationKey]
if !hasShard {
// nothing we can do beyond retrying
return reconcileStatusStopAndRequeue, getErr
}

shard, err := r.getShardByHash(shardNameHash)
if err != nil {
return reconcileStatusStopAndRequeue, err
}

logicalClusterAdminClient, err := r.kcpLogicalClusterAdminClientFor(shard)
if err != nil {
return reconcileStatusStopAndRequeue, err
}

logicalCluster, getErr = logicalClusterAdminClient.Cluster(clusterName.Path()).CoreV1alpha1().LogicalClusters().Get(ctx, corev1alpha1.LogicalClusterName, metav1.GetOptions{})
if getErr != nil && !apierrors.IsNotFound(getErr) {
return reconcileStatusStopAndRequeue, getErr
}

// fall-through
}
if apierrors.IsNotFound(getErr) {
finalizers := sets.New[string](workspace.Finalizers...)
if finalizers.Has(corev1alpha1.LogicalClusterFinalizer) {
logger.Info(fmt.Sprintf("Removing finalizer %s", corev1alpha1.LogicalClusterFinalizer))
Expand Down
Loading