Help us shape the future of Go! Take the 2026 Go Developer Survey

policy

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package policy compiles immutable selectors and templates shared by reconciliation and admission.

Index

Constants

View Source
const (
	ConditionBudget int64 = 100000
)

ConditionBudget bounds all evaluations in one admission request. Denials and warnings use separate budgets so a broken warning cannot exhaust denial work.

View Source
const ExecutionExtra = "addons.projectcapsule.dev/execution"

Variables

This section is empty.

Functions

func Context

func Context(target map[string]any, captured map[string]any, w schedule.Window, now time.Time) map[string]any

func Parse

func Parse(text string) (*template.Template, error)

func ProtectedNamespace

func ProtectedNamespace(namespace, controllerNamespace string) bool

ProtectedNamespace keeps the controller and Kubernetes recovery paths outside maintenance selection. Match the exclusions in both installation manifests.

func Render

func Render(t *template.Template, data map[string]any, limit int) (string, error)

Types

type CandidateSet

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

CandidateSet merges immutable exact and pattern indexes without allocating a result per request. Only pattern policies need checking beyond the exact GVR.

func (CandidateSet) All

func (c CandidateSet) All() iter.Seq[*Compiled]

func (CandidateSet) Empty

func (c CandidateSet) Empty() bool

type Compiled

type Compiled struct {
	Source          *api.ChangeWindow
	Engine          *schedule.Engine
	Namespaces      []labels.Selector
	Targets         map[string]Target
	Rules, Warnings []Message
}

func Compile

func Compile(obj *api.ChangeWindow, mapper meta.RESTMapper) (*Compiled, error)

func (*Compiled) SelectNamespace

func (c *Compiled) SelectNamespace(set labels.Set) bool

type Message

type Message struct {
	Name string

	Match       api.RequestMatch
	When        string
	Within      time.Duration
	Template    *template.Template
	NeedsTarget bool
	// contains filtered or unexported fields
}

func (Message) HasConditions

func (m Message) HasConditions() bool

func (Message) MatchConditions

func (m Message) MatchConditions(ctx context.Context, variables map[string]any, budget *int64) (bool, error)

MatchConditions follows AND semantics, including false taking precedence over an ordinary evaluation error. Request-budget exhaustion and cancellation abort evaluation.

func (Message) MatchesAudience

func (m Message) MatchesAudience(user authenticationv1.UserInfo) bool

type Store

type Store struct {
	Mapper meta.RESTMapper
	// contains filtered or unexported fields
}

Store publishes immutable compiled policies indexed by the parent GVR. Status updates do not recompile. Deletion retires all references; no request snapshots or authorization decisions are cached here.

func NewStore

func NewStore(mapper meta.RESTMapper) *Store

func (*Store) Candidates

func (s *Store) Candidates(gvr schema.GroupVersionResource) (CandidateSet, error)

Candidates returns a read-only snapshot; published slices are never modified.

func (*Store) Delete

func (s *Store) Delete(name string)

func (*Store) For

func (s *Store) For(obj *api.ChangeWindow) (*Compiled, error)

For returns the compiled snapshot for this exact generation, or compiles a transient value when reconciliation runs ahead of the informer callback.

func (*Store) Upsert

func (s *Store) Upsert(obj *api.ChangeWindow) error

type Target

type Target struct {
	Namespaced bool
	Spec       api.Target
	Selector   labels.Selector
	Resource   schema.GroupVersionResource
	Pattern    *capsuleruntime.VersionKind
}

func (Target) MatchesAPI

func (t Target) MatchesAPI(gvr schema.GroupVersionResource) bool

MatchesAPI filters before resolving a subresource's parent kind or namespace.

func (Target) MatchesKind

func (t Target) MatchesKind(gvr schema.GroupVersionResource, kind string) bool

Jump to

Keyboard shortcuts

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