evaluator

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MockUserInfo

func MockUserInfo(username string, groups []string) user.Info

MockUserInfo creates a simple user.Info for testing.

func NewAuthorizerValue

func NewAuthorizerValue(auth authorizer.Authorizer, userInfo user.Info) ref.Val

NewAuthorizerValue creates a CEL authorizer value using Kubernetes' library function. This wraps a Kubernetes authorizer for use in CEL expressions.

Types

type AuthorizationMockConfig added in v0.1.1

type AuthorizationMockConfig struct {
	Group       string `json:"group,omitempty"`
	Resource    string `json:"resource"`
	Subresource string `json:"subresource,omitempty"`
	Namespace   string `json:"namespace,omitempty"`
	Verb        string `json:"verb"`
	Decision    string `json:"decision"` // "allow" or "deny"
}

AuthorizationMockConfig represents a mocked authorization decision configuration.

type EvaluationResult

type EvaluationResult struct {
	Allowed          bool
	Message          string
	Warnings         []string
	PatchType        *admissionv1.PatchType
	PatchedObject    *unstructured.Unstructured // The object after applying mutations
	AuditAnnotations map[string]string
}

EvaluationResult contains the result of evaluating a policy.

type Evaluator

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

Evaluator evaluates admission policies using CEL expressions.

func New

func New() (*Evaluator, error)

New creates a new Evaluator with a CEL environment configured for Kubernetes admission policies.

func (*Evaluator) EvaluateMutating

EvaluateMutating evaluates a MutatingAdmissionPolicy against an admission request.

func (*Evaluator) EvaluateTest

EvaluateTest evaluates a policy against a test case and returns whether it passed.

func (*Evaluator) EvaluateValidating

EvaluateValidating evaluates a ValidatingAdmissionPolicy against an admission request.

type MockAuthorizer

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

MockAuthorizer is a simple mock authorizer for testing.

func NewMockAuthorizer

func NewMockAuthorizer() *MockAuthorizer

NewMockAuthorizer creates a new mock authorizer.

func NewMockAuthorizerFromConfig added in v0.1.1

func NewMockAuthorizerFromConfig(configs []AuthorizationMockConfig) *MockAuthorizer

NewMockAuthorizerFromConfig creates a mock authorizer from a list of configs.

func (*MockAuthorizer) Add added in v0.1.1

Add adds a decision to the mock authorizer.

func (*MockAuthorizer) Allow

func (m *MockAuthorizer) Allow(group, resource, subresource, namespace, verb string)

Allow configures the mock to allow a specific request.

func (*MockAuthorizer) Authorize

Authorize implements the authorizer.Authorizer interface.

func (*MockAuthorizer) Deny

func (m *MockAuthorizer) Deny(group, resource, subresource, namespace, verb string)

Deny configures the mock to deny a specific request.

type TestCase

type TestCase interface {
	GetRequest() *admissionv1.AdmissionRequest
	GetObject() *unstructured.Unstructured
	GetOldObject() *unstructured.Unstructured
	GetParams() *unstructured.Unstructured
	GetNamespaceObj() *unstructured.Unstructured
	GetUserInfo() user.Info
	GetExpectAllowed() bool
	GetExpectMessage() string
	GetExpectWarnings() []string
	GetExpectAuditAnnotations() map[string]string
	GetExpectedObject() *unstructured.Unstructured
	GetError() error
	GetAuthorizer() []AuthorizationMockConfig
}

TestCase represents a test case with inputs and expected outcomes. This is a subset of the loader.TestCase interface that evaluator needs.

type TestExpectation

type TestExpectation struct {
	Allowed          bool
	Message          string
	Object           *unstructured.Unstructured
	Warnings         []string
	AuditAnnotations map[string]string
}

TestExpectation contains what the test expects to happen.

type TestOutcome

type TestOutcome struct {
	Allowed          bool
	Message          string
	Object           *unstructured.Unstructured
	Warnings         []string
	AuditAnnotations map[string]string
	EvaluationErr    error
}

TestOutcome contains what actually happened during evaluation.

type TestResult

type TestResult struct {
	Passed        bool
	Expected      TestExpectation
	Actual        TestOutcome
	Message       string // Failure explanation or diff
	PatchedObject *unstructured.Unstructured
}

TestResult contains the result of evaluating a test case.

Jump to

Keyboard shortcuts

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