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

Fix Namespace delete validation #7068

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions service/frontend/operator_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ func (h *OperatorHandlerImpl) DeleteNamespace(
ConcurrentDeleteExecutionsActivities: h.config.DeleteNamespaceConcurrentDeleteExecutionsActivities(),
},
NamespaceDeleteDelay: namespaceDeleteDelay,
CurrentClusterName: h.clusterMetadata.GetCurrentClusterName(),
}

sdkClient := h.sdkClientFactory.GetSystemClient()
Expand Down
15 changes: 12 additions & 3 deletions service/worker/deletenamespace/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ package deletenamespace

import (
"fmt"
"slices"
"strings"
"time"

Expand Down Expand Up @@ -56,6 +57,8 @@ type (
// Default is 0, means, namespace will be deleted immediately.
NamespaceDeleteDelay time.Duration

CurrentClusterName string

DeleteExecutionsConfig deleteexecutions.DeleteExecutionsConfig
}

Expand Down Expand Up @@ -104,7 +107,13 @@ func validateParams(params *DeleteNamespaceWorkflowParams) error {
return nil
}

func validateNamespace(ctx workflow.Context, nsID namespace.ID, nsName namespace.Name, nsClusters []string) error {
func validateNamespace(
ctx workflow.Context,
nsID namespace.ID,
nsName namespace.Name,
currentClusterName string,
nsClusters []string,
) error {

if nsName == primitives.SystemLocalNamespace || nsID == primitives.SystemNamespaceID {
return errors.NewFailedPrecondition("unable to delete system namespace", nil)
Expand All @@ -116,7 +125,7 @@ func validateNamespace(ctx workflow.Context, nsID namespace.ID, nsName namespace
// - If namespace is active in the current cluster, then it technically can be deleted (and
// in this case it will be deleted from this cluster only because delete operation is not replicated),
// but this is confusing for the users, as they might expect that namespace is deleted from all clusters.
if len(nsClusters) > 1 {
if len(nsClusters) > 1 && slices.Contains(nsClusters, currentClusterName) {
return errors.NewFailedPrecondition(fmt.Sprintf("namespace %s is replicated in several clusters [%s]: remove all other cluster and retry", nsName, strings.Join(nsClusters, ",")), nil)
}

Expand Down Expand Up @@ -170,7 +179,7 @@ func DeleteNamespaceWorkflow(ctx workflow.Context, params DeleteNamespaceWorkflo
params.NamespaceID = namespaceInfo.NamespaceID

// Step 1.1. Validate namespace.
if err = validateNamespace(ctx, params.NamespaceID, params.Namespace, namespaceInfo.Clusters); err != nil {
if err = validateNamespace(ctx, params.NamespaceID, params.Namespace, params.CurrentClusterName, namespaceInfo.Clusters); err != nil {
return result, err
}

Expand Down
Loading