policy

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: Apache-2.0 Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package policy implements the ADR-018 ClusterCreationPolicy resolution algorithm as a pure function set. Callers (butler-server, butler-controller) supply the candidate policies and the resolution context; the package returns the effective rule per option type.

No Kubernetes client calls live in this package. Listing policies happens at callers. Per ADR-018 Decision section 6.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadField

func ReadField(tc *butlerv1alpha1.TenantCluster, providerType butlerv1alpha1.ProviderType, ot butlerv1alpha1.OptionType) (value string, path string, supported bool)

ReadField extracts the option value from a TenantCluster spec for a given (provider type, option type) pair. The returned path string is the dotted field path used in admission rejection messages, e.g. `spec.infrastructureOverride.nutanix.imageUUID`.

Supported is false when the provider does not expose the option type (for example a policy targeting `cluster` against a Harvester provider). Callers should treat unsupported pairs as no-ops; the policy webhook accepts the policy because the same policy may target multiple providers where the option type is meaningful.

ReadField is the only per-provider code path the resolver touches. New providers add a switch case here; the resolver does not branch on provider type anywhere else.

func Resolve

Resolve runs the ADR-018 section 6 algorithm and returns the effective rule per option type for the given context.

Specificity wins: a teamAndEnvironment-scoped rule for an option type shadows any team or platformWide rule for the same option type. Modes do not stack across tiers. Option types with no matching rule do not appear in the result.

Resolve assumes that intra-tier conflicts (two policies in the same tier defining a rule for the same option type for the same context) have already been rejected at policy admission time. If the caller passes a conflicting set, Resolve picks the first rule it encounters per option type within that tier. Callers should treat such inputs as misconfigured admission.

func ResolveWithSources

ResolveWithSources is the same as Resolve but also returns the name of the policy that contributed each effective rule. Used at admission time so rejection messages can name the policy.

func ValidateAgainstRule

func ValidateAgainstRule(tc *butlerv1alpha1.TenantCluster, providerType butlerv1alpha1.ProviderType, ot butlerv1alpha1.OptionType, rule butlerv1alpha1.OptionRule, policyName string) (ok bool, fieldPath string, message string)

ValidateAgainstRule checks a single TenantCluster spec field against a resolved policy rule. Returns (ok, message). When ok is false, message is the human-readable rejection text suitable for admission errors. For modes that do not enforce (default, recommended), ValidateAgainstRule always returns ok=true.

Types

type ResolutionContext

type ResolutionContext struct {
	// TeamName is the team owning the TenantCluster. Empty means the
	// request has no team context; only PlatformWide policies match.
	TeamName string

	// EnvironmentName is the team environment. Empty means no environment
	// is selected; only PlatformWide and Team scope policies match.
	EnvironmentName string

	// ProviderType is the underlying provider for the cluster. A policy
	// without TargetProviders matches every provider; a policy with a
	// non-empty TargetProviders matches only when the type appears in
	// the list.
	ProviderType butlerv1alpha1.ProviderType
}

ResolutionContext is the tuple under which a set of ClusterCreationPolicy resources is resolved. For list-time resolution (butler-server) the fields come from the operator's session. For admission-time resolution (butler-controller) they come from the TenantCluster being validated.

Jump to

Keyboard shortcuts

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