namespacecleanup

package
v1.38.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package namespacecleanup runs the leader-side cascade that empties a namespace once it has been marked for deletion.

Deletion is split into a fast synchronous half and a slow asynchronous half. The DELETE handler flips the namespace to deleting and returns 202. This package then removes the contents on a periodic tick: DB users, then aliases, then classes, then the namespace entry itself. Aliases come before classes because an alias points at a class. Class deletion is the slow part, which is why it lives here rather than in the request path.

The split is driven by two concerns. First, class deletion can run long on large collections and would otherwise risk request timeouts. Second, a node can crash mid-delete at any time, so the cluster needs an after-the-fact cleanup path regardless; once that path exists, routing the bulk of the work through it is cheaper than duplicating the logic in the request handler.

Every step is a separate replicated command, so any failure is retried on the next tick. Because the coordinator's view of what still belongs to a namespace can lag behind the leader, the final entity removal is re-checked at apply time and rejected if anything still owns the namespace; the next tick retries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Coordinator

type Coordinator struct {
	// contains filtered or unexported fields
}

Coordinator runs one cleanup pass per Tick on the leader. isLeader is re-checked before every RAFT write so the old leader stops issuing writes once leadership moves.

func NewCoordinator

func NewCoordinator(
	nsLister namespaceLister,
	schema schemaLister,
	users userLister,
	raft raftExecutor,
	rbac RBACLister,
	isLeader func() bool,
	logger logrus.FieldLogger,
) *Coordinator

func (*Coordinator) Tick

func (c *Coordinator) Tick(ctx context.Context) error

Tick cleans up every namespace currently in the deleting state. A per-namespace error is logged and the loop moves on; a not-leader error stops the tick so the new leader can take over. A cancelled ctx (server shutdown) stops the tick cleanly between namespaces and mid cleanup; the next tick resumes the rest.

Returns an error if another Tick is already running.

type RBACLister added in v1.38.3

type RBACLister interface {
	NamespaceLocalRBAC(namespace string) (roles []string, subjects []rbac.NamespaceSubject, err error)
	GetRolesForUserOrGroup(user string, authMethod authentication.AuthType, isGroup bool) (map[string][]authorization.Policy, error)
}

RBACLister reads the roles and role assignments that belong to a namespace. Nil when RBAC is disabled (only possible on a non-namespace cluster, which has nothing to clean). Reads run on the leader; the deletes go through raftExecutor.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL