accessmanagement

package
v1.14.0-dev.1 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package accessmanagement works out what reconciling an AccessManagement does to the objects it distributes: which copies its rules want and which already distributed copies they no longer do. The controller acts on it, and admission uses the very same answer to check, before an update is accepted, that the copies it would remove can be removed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClusterTemplatesToRemove

func ClusterTemplatesToRemove(ctx context.Context, cl client.Client, systemNamespace string, accessMgmt *kcmv1.AccessManagement) ([]*kcmv1.ClusterTemplate, error)

ClusterTemplatesToRemove returns the ClusterTemplates reconciling accessMgmt would delete, as the cluster stands: managed copies its rules no longer distribute and that nothing else owns, leaving out the ones already being deleted. It is nil unless the controller still handles ClusterTemplates for accessMgmt at all, see TracksGroupKind.

func HasForeignOwnerReference

func HasForeignOwnerReference(refs []metav1.OwnerReference, accessMgmt *kcmv1.AccessManagement) bool

HasForeignOwnerReference reports whether refs carry any owner besides accessMgmt.

func IsAccessManagementOwnerReference

func IsAccessManagementOwnerReference(ref metav1.OwnerReference, accessMgmt *kcmv1.AccessManagement) bool

IsAccessManagementOwnerReference reports whether ref names accessMgmt, whatever its version or UID: a reference left by a since-recreated AccessManagement is still the controller's to drop.

func LabelSelector

func LabelSelector(selector *metav1.LabelSelector, stringSelector string) (labels.Selector, bool, error)

LabelSelector is the single helper behind both TargetNamespaces and ResourceRule selector matching: a non-empty stringSelector takes precedence, then a structured selector. The returned bool reports whether the resulting selector is non-empty (an empty selector, or no selector at all, conventionally means "match everything" for both use sites).

func NamespacedName

func NamespacedName(namespace, name string) string

NamespacedName returns the namespace/name key a copy is tracked under.

func ReferencedGroupKinds

func ReferencedGroupKinds(accessMgmt *kcmv1.AccessManagement) []schema.GroupKind

ReferencedGroupKinds returns the de-duplicated set of GroupKinds referenced across all of accessMgmt's AccessRules' EffectiveResources, in first-seen order.

func ResolveNames

func ResolveNames[T labeled](rule kcmv1.ResourceRule, system map[string]T) ([]string, error)

ResolveNames returns the object names in the system namespace selected by rule. Whether Names was set at all (rather than just non-empty) is what decides the branch taken: an explicitly-empty Names ([] rather than omitted) means "select nothing" and must not fall through to selector matching, or it would silently select every object of the Kind. A non-empty Names is used verbatim (even for names not found in system, so callers can still report a clear "not found" error and keep the target from being deleted-then-recreated on the next reconcile). Only when Names is nil is Selector/StringSelector matched against the system objects' labels — same convention as TargetNamespaces: no selector, or an empty one, matches every object of the Kind.

func TargetNamespaces

func TargetNamespaces(ctx context.Context, cl client.Client, systemNamespace string, targetNamespaces kcmv1.TargetNamespaces) ([]string, error)

TargetNamespaces resolves the namespaces a rule distributes into, always excluding systemNamespace: an object copied back into the namespace it was read from is either a no-op or a copy taking over the name of its own source.

func TracksGroupKind

func TracksGroupKind(accessMgmt *kcmv1.AccessManagement, gk schema.GroupKind) bool

TracksGroupKind reports whether the controller handles gk for accessMgmt: either a rule references it, or accessMgmt.Status.Resources still records it from a previous reconcile, which is how copies of a Kind dropped from every rule still get cleaned up.

Types

type Plan

type Plan[M metav1.Object] struct {
	// Desired holds the copies the rules distribute, de-duplicated, in rule order.
	Desired []Target
	// Remove holds the managed copies no rule distributes anymore and that nothing but the
	// AccessManagement owns: they are deleted.
	Remove []M
	// Release holds the managed copies no rule distributes anymore but that something else owns
	// too, such as a ClusterTemplate a ClusterTemplateChain also distributed into the same
	// namespace: they are still wanted there, so the AccessManagement only drops its own owner
	// reference.
	Release []M
}

Plan is what reconciling an AccessManagement does for a single Kind.

func PlanGroupKind

func PlanGroupKind[T labeled, M metav1.Object](rules []Rule, gk schema.GroupKind, system map[string]T, managed []M, accessMgmt *kcmv1.AccessManagement) (*Plan[M], error)

PlanGroupKind works out what reconciling accessMgmt does for gk. system holds the gk objects in the system namespace by name, the only source copies are ever made from; managed holds the managed copies of gk found outside it. Both the controller, acting on the whole plan, and admission, checking that what it removes can be removed, go through this.

type Rule

type Rule struct {
	Namespaces []string
	Resources  []kcmv1.ResourceRule
}

Rule is an AccessRule resolved against the cluster: the namespaces it distributes into and the resource rules selecting what it distributes there.

func ResolveRules

func ResolveRules(ctx context.Context, cl client.Client, systemNamespace string, accessRules []kcmv1.AccessRule) ([]Rule, error)

ResolveRules resolves every AccessRule against the cluster. EffectiveResources falls back to the deprecated one-field-per-Kind selectors when Resources is empty, for backward compatibility when the mutating webhook that normally migrates them on write is disabled/unavailable. When both are present, Resources wins outright.

type Target

type Target struct {
	Namespace string
	Name      string
}

Target is one copy the rules distribute: the object Name from the system namespace, into Namespace.

Jump to

Keyboard shortcuts

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