Documentation
¶
Overview ¶
Copyright 2020-2026 Project Capsule Authors SPDX-License-Identifier: Apache-2.0
Index ¶
- func EnforceBodiesFromNamespaceRules(bodies []*api.NamespaceRuleBodyNamespace) []*api.NamespaceRuleEnforceBody
- func FilterEnforcementConditions(ctx context.Context, evaluator *ConditionEvaluator, object any, ...) ([]*rules.NamespaceRuleEnforceBody, error)
- func FilterNamespaceEnforcementConditions(ctx context.Context, evaluator *ConditionEvaluator, object any, ...) ([]*rules.NamespaceRuleBodyNamespace, error)
- func FilterNamespaceRulesByAudience(ctx context.Context, c client.Client, cfg configuration.Configuration, ...) ([]*rules.NamespaceRuleBodyNamespace, error)
- func ValidateRuleStatusBody(mapper k8smeta.RESTMapper, bodies []*rules.NamespaceRuleBodyNamespace, ...) error
- func WorkloadEnforcement(bodies []*rules.NamespaceRuleEnforceBody, gvk schema.GroupVersionKind) []*rules.NamespaceRuleEnforceBody
- type ConditionCompiler
- type ConditionEvaluator
- type Decision
- type DecisionError
- type Evaluation
- type Match
- type Set
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnforceBodiesFromNamespaceRules ¶
func EnforceBodiesFromNamespaceRules( bodies []*api.NamespaceRuleBodyNamespace, ) []*api.NamespaceRuleEnforceBody
func FilterEnforcementConditions ¶ added in v0.15.0
func FilterEnforcementConditions( ctx context.Context, evaluator *ConditionEvaluator, object any, bodies []*rules.NamespaceRuleEnforceBody, applies func(*rules.NamespaceRuleEnforceBody) bool, ) ([]*rules.NamespaceRuleEnforceBody, error)
FilterEnforcementConditions filters the applicable enforcement rules. It preserves rule order and cache-owned bodies, with no allocation when ungated.
func FilterNamespaceEnforcementConditions ¶ added in v0.15.0
func FilterNamespaceEnforcementConditions( ctx context.Context, evaluator *ConditionEvaluator, object any, bodies []*rules.NamespaceRuleBodyNamespace, applies func(*rules.NamespaceRuleEnforceBody) bool, ) ([]*rules.NamespaceRuleBodyNamespace, error)
FilterNamespaceEnforcementConditions gates enforcement-derived mutations while retaining independent mutate entries. It copies only bodies whose gate is false.
func FilterNamespaceRulesByAudience ¶ added in v0.13.10
func FilterNamespaceRulesByAudience( ctx context.Context, c client.Client, cfg configuration.Configuration, tnt *capsulev1beta2.Tenant, req admission.Request, bodies []*rules.NamespaceRuleBodyNamespace, ) ([]*rules.NamespaceRuleBodyNamespace, error)
func ValidateRuleStatusBody ¶
func ValidateRuleStatusBody( mapper k8smeta.RESTMapper, bodies []*rules.NamespaceRuleBodyNamespace, compilers ...ConditionCompiler, ) error
func WorkloadEnforcement ¶ added in v0.15.0
func WorkloadEnforcement(bodies []*rules.NamespaceRuleEnforceBody, gvk schema.GroupVersionKind) []*rules.NamespaceRuleEnforceBody
WorkloadEnforcement selects property policies for the admitted kind. It preserves order and never changes rules owned by the cache. The ordinary Pod-only path returns the input without copying it.
Types ¶
type ConditionCompiler ¶ added in v0.15.0
type ConditionCompiler interface {
GetOrCompileCondition(expression string, mode environment.Type) (*celruntime.CompiledExpression, error)
}
ConditionCompiler is backed by the controller's shared CEL cache.
type ConditionEvaluator ¶ added in v0.15.0
type ConditionEvaluator struct {
// contains filtered or unexported fields
}
ConditionEvaluator owns request-local metadata, never evaluation results.
func NewConditionEvaluator ¶ added in v0.15.0
func NewConditionEvaluator(compiler ConditionCompiler, request admissionv1.AdmissionRequest) *ConditionEvaluator
func (*ConditionEvaluator) Matches ¶ added in v0.15.0
func (e *ConditionEvaluator) Matches(ctx context.Context, object any, conditions []rules.AdmissionCondition) (bool, error)
Matches evaluates a block against its current object. A false condition takes precedence over errors, independently of condition order. A nil object uses the full admission request object, for callers that decode only metadata.
func (*ConditionEvaluator) ResetObject ¶ added in v0.15.0
func (e *ConditionEvaluator) ResetObject()
ResetObject invalidates only the current request's object view after mutation.
func (*ConditionEvaluator) WithVolume ¶ added in v0.15.0
func (e *ConditionEvaluator) WithVolume(volume *corev1.PersistentVolume) *ConditionEvaluator
WithVolume attaches the already-read PV without performing any API I/O. Conversion is deferred until a condition needs evaluation.
type Decision ¶
type Decision struct {
SetName string
EventReason string
Action api.ActionType
Value Value
MatchedValue any
// MatchedRule is the human-readable rule description returned by Set.RuleDescription.
MatchedRule string
// MatchDetail is the human-readable detail returned by Match.Detail.
MatchDetail string
Message string
}
type DecisionError ¶
type DecisionError struct {
Decision *Decision
}
func (*DecisionError) Error ¶
func (e *DecisionError) Error() string
type Evaluation ¶
type Evaluation struct {
// Final is the last matching allow/deny decision.
Final *Decision
// Blocking is set when the final result blocks admission.
Blocking *Decision
// Audits contains all matching audit decisions.
Audits []*Decision
}
func EvaluateEnforce ¶
func EvaluateEnforce[R any, T any]( obj T, enforceBodies []*api.NamespaceRuleEnforceBody, set Set[R, T], ) (*Evaluation, error)
func (*Evaluation) Append ¶
func (e *Evaluation) Append(other *Evaluation)
func (*Evaluation) BlockingError ¶
func (e *Evaluation) BlockingError() error
type Set ¶
type Set[R any, O any] struct { Name string EventReason string Values func(O) []Value // EvaluateEmptyValues includes empty strings in matching. By default they // represent unset resource fields and are skipped. Metadata keys can be // present with an empty value and must opt in to evaluation. EvaluateEmptyValues bool // Rules extracts rules when extraction cannot fail. Rules func(*api.NamespaceRuleEnforceBody) []R // RulesWithError extracts rules that require runtime parsing or matching. // When set, it takes precedence over Rules. RulesWithError func(*api.NamespaceRuleEnforceBody) ([]R, error) Matches func(R, Value) (Match, error) // Message can fully override the default message. // Prefer leaving this nil unless a rule requires very specific wording. Message func(api.ActionType, Value, any) string // RuleDescription returns a human-readable representation of one rule. // It is used only for admission/audit messages. RuleDescription func(R) string // AllowedDescription optionally overrides the "Allowed values" label. // Example: "Allowed CIDRs", "Allowed ranges", "Allowed hostnames". AllowedDescription string }