common

package
v0.0.0-...-b96ae8a Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Controller name
	ControllerName = "controller"

	// Finalizer names
	SandboxFinalizer  = "sandbox.llmsafespace.dev/finalizer"
	WarmPoolFinalizer = "warmpool.llmsafespace.dev/finalizer"
	WarmPodFinalizer  = "warmpod.llmsafespace.dev/finalizer"

	// Annotation keys
	AnnotationCreatedBy    = "llmsafespace.dev/created-by"
	AnnotationWarmPodID    = "llmsafespace.dev/warm-pod-id"
	AnnotationSandboxID    = "llmsafespace.dev/sandbox-id"
	AnnotationPoolName     = "llmsafespace.dev/pool-name"
	AnnotationRecyclable   = "llmsafespace.dev/recyclable"
	AnnotationRecycleCount = "llmsafespace.dev/recycle-count"
	AnnotationLastRecycled = "llmsafespace.dev/last-recycled"
	AnnotationLastSandbox  = "llmsafespace.dev/last-sandbox"

	// Label keys
	LabelApp       = "app"
	LabelComponent = "component"
	LabelSandboxID = "sandbox-id"
	LabelPoolName  = "pool-name"
	LabelWarmPodID = "warm-pod-id"
	LabelRuntime   = "runtime"
	LabelStatus    = "status"

	// Component values
	ComponentSandbox  = "sandbox"
	ComponentWarmPool = "warmpool"
	ComponentWarmPod  = "warmpod"

	// Condition types
	ConditionReady       = "Ready"
	ConditionPodCreated  = "PodCreated"
	ConditionPodRunning  = "PodRunning"
	ConditionPoolReady   = "PoolReady"
	ConditionScalingUp   = "ScalingUp"
	ConditionScalingDown = "ScalingDown"

	// Condition reasons
	ReasonPodCreated        = "PodCreated"
	ReasonPodCreationFailed = "PodCreationFailed"
	ReasonPodRunning        = "PodRunning"
	ReasonPodNotRunning     = "PodNotRunning"
	ReasonPoolReady         = "PoolReady"
	ReasonPoolNotReady      = "PoolNotReady"
	ReasonScalingUp         = "ScalingUp"
	ReasonScalingDown       = "ScalingDown"

	// Phase values for Sandbox
	SandboxPhasePending     = "Pending"
	SandboxPhaseCreating    = "Creating"
	SandboxPhaseRunning     = "Running"
	SandboxPhaseTerminating = "Terminating"
	SandboxPhaseTerminated  = "Terminated"
	SandboxPhaseFailed      = "Failed"

	// Phase values for WarmPod
	WarmPodPhasePending     = "Pending"
	WarmPodPhaseReady       = "Ready"
	WarmPodPhaseAssigned    = "Assigned"
	WarmPodPhaseTerminating = "Terminating"
)

Controller-related constants

Variables

View Source
var (
	// SandboxesCreated tracks the number of sandboxes created
	SandboxesCreated = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "llmsafespace_sandboxes_created_total",
			Help: "Number of sandboxes created",
		},
		[]string{"runtime", "security_level"},
	)

	// SandboxesDeleted tracks the number of sandboxes deleted
	SandboxesDeleted = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "llmsafespace_sandboxes_deleted_total",
			Help: "Number of sandboxes deleted",
		},
		[]string{"runtime", "security_level"},
	)

	// SandboxesRunning tracks the number of sandboxes currently running
	SandboxesRunning = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "llmsafespace_sandboxes_running",
			Help: "Number of sandboxes currently running",
		},
		[]string{"runtime", "security_level"},
	)

	// SandboxCreationDuration tracks the time taken to create a sandbox
	SandboxCreationDuration = prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "llmsafespace_sandbox_creation_duration_seconds",
			Help:    "Time taken to create a sandbox",
			Buckets: prometheus.ExponentialBuckets(0.1, 2, 10),
		},
		[]string{"runtime", "security_level", "warm_pool_used"},
	)

	// WarmPodsAvailable tracks the number of warm pods available
	WarmPodsAvailable = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "llmsafespace_warm_pods_available",
			Help: "Number of warm pods available",
		},
		[]string{"runtime", "pool"},
	)

	// WarmPodsAssigned tracks the number of warm pods assigned
	WarmPodsAssigned = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "llmsafespace_warm_pods_assigned",
			Help: "Number of warm pods assigned",
		},
		[]string{"runtime", "pool"},
	)

	// WarmPoolHitRatio tracks the ratio of sandbox creations that used a warm pod
	WarmPoolHitRatio = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "llmsafespace_warm_pool_hit_ratio",
			Help: "Ratio of sandbox creations that used a warm pod",
		},
		[]string{"runtime", "pool"},
	)

	// WarmPodRecycleCount tracks the number of times warm pods have been recycled
	WarmPodRecycleCount = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "llmsafespace_warm_pod_recycle_count_total",
			Help: "Number of times warm pods have been recycled",
		},
		[]string{"runtime", "pool"},
	)

	// WarmPodTTLExceededCount tracks the number of warm pods that exceeded their TTL
	WarmPodTTLExceededCount = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "llmsafespace_warm_pod_ttl_exceeded_total",
			Help: "Number of warm pods that exceeded their TTL",
		},
		[]string{"runtime", "pool"},
	)
)

Functions

func AddFinalizer

func AddFinalizer(obj client.Object, finalizer string) bool

AddFinalizer adds a finalizer to an object if it doesn't already exist

func ConvertFromMetaV1Condition

func ConvertFromMetaV1Condition(condition metav1.Condition) resources.SandboxCondition

ConvertFromMetaV1Condition converts a metav1.Condition to SandboxCondition

func ConvertFromMetaV1ConditionArray

func ConvertFromMetaV1ConditionArray(conditions []metav1.Condition) []resources.SandboxCondition

ConvertFromMetaV1ConditionArray converts an array of metav1.Condition to SandboxCondition

func ConvertFromMetaV1ToWarmPoolCondition

func ConvertFromMetaV1ToWarmPoolCondition(condition metav1.Condition) resources.WarmPoolCondition

ConvertFromMetaV1ToWarmPoolCondition converts a metav1.Condition to WarmPoolCondition

func ConvertFromMetaV1ToWarmPoolConditionArray

func ConvertFromMetaV1ToWarmPoolConditionArray(conditions []metav1.Condition) []resources.WarmPoolCondition

ConvertFromMetaV1ToWarmPoolConditionArray converts an array of metav1.Condition to WarmPoolCondition

func ConvertToMetaV1Condition

func ConvertToMetaV1Condition(condition resources.SandboxCondition) metav1.Condition

ConvertToMetaV1Condition converts a SandboxCondition to metav1.Condition

func ConvertToMetaV1ConditionArray

func ConvertToMetaV1ConditionArray(conditions []resources.SandboxCondition) []metav1.Condition

ConvertToMetaV1ConditionArray converts an array of SandboxCondition to metav1.Condition

func ConvertWarmPoolToMetaV1Condition

func ConvertWarmPoolToMetaV1Condition(condition resources.WarmPoolCondition) metav1.Condition

ConvertWarmPoolToMetaV1Condition converts a WarmPoolCondition to metav1.Condition

func ConvertWarmPoolToMetaV1ConditionArray

func ConvertWarmPoolToMetaV1ConditionArray(conditions []resources.WarmPoolCondition) []metav1.Condition

ConvertWarmPoolToMetaV1ConditionArray converts an array of WarmPoolCondition to metav1.Condition

func FindCondition

func FindCondition(conditions []metav1.Condition, conditionType string) *metav1.Condition

FindCondition finds a condition by type in the provided slice

func FindWarmPodForSandbox

func FindWarmPodForSandbox(ctx context.Context, c client.Client, sandbox *resources.Sandbox) (*resources.WarmPod, error)

FindWarmPodForSandbox finds an available warm pod for a sandbox

func GenerateRandomString

func GenerateRandomString(length int) string

GenerateRandomString generates a random string of the specified length

func IsConditionTrue

func IsConditionTrue(conditions []metav1.Condition, conditionType string) bool

IsConditionTrue checks if a condition with the given type exists and has status True

func IsPodReady

func IsPodReady(pod *corev1.Pod) bool

IsPodReady checks if a pod is ready

func RemoveFinalizer

func RemoveFinalizer(obj client.Object, finalizer string) bool

RemoveFinalizer removes a finalizer from an object if it exists

func SetCondition

func SetCondition(conditions *[]metav1.Condition, conditionType string, status metav1.ConditionStatus, reason, message string)

SetCondition updates or creates a condition in the provided slice

func SetSandboxCondition

func SetSandboxCondition(conditions *[]resources.SandboxCondition, conditionType string, status string, reason, message string)

SetSandboxCondition sets a condition on a Sandbox resource

func SetWarmPoolCondition

func SetWarmPoolCondition(conditions *[]resources.WarmPoolCondition, conditionType string, status string, reason, message string)

SetWarmPoolCondition sets a condition on a WarmPool resource

func SetupLeaderElection

func SetupLeaderElection(cfg *LeaderElectionConfig, kubeClient kubernetes.Interface, runFunc func(context.Context)) error

SetupLeaderElection configures and starts leader election

Types

type LeaderElectionConfig

type LeaderElectionConfig struct {
	// LeaseDuration is the duration that non-leader candidates will
	// wait to force acquire leadership
	LeaseDuration time.Duration
	// RenewDeadline is the duration that the acting master will retry
	// refreshing leadership before giving up
	RenewDeadline time.Duration
	// RetryPeriod is the duration the LeaderElector clients should wait
	// between tries of actions
	RetryPeriod time.Duration
	// Namespace is the namespace where the lock resource exists
	Namespace string
	// Name is the name of the lock resource
	Name string
}

LeaderElectionConfig contains configuration for leader election

type NetworkPolicyManager

type NetworkPolicyManager struct {
	Client client.Client
	Scheme *runtime.Scheme
}

NetworkPolicyManager handles network policy creation and management

func NewNetworkPolicyManager

func NewNetworkPolicyManager(client client.Client, scheme *runtime.Scheme) *NetworkPolicyManager

NewNetworkPolicyManager creates a new NetworkPolicyManager

func (*NetworkPolicyManager) CreateDefaultDenyPolicy

func (n *NetworkPolicyManager) CreateDefaultDenyPolicy(ctx context.Context, sandbox *resources.Sandbox) error

CreateDefaultDenyPolicy creates a default deny policy for a sandbox

func (*NetworkPolicyManager) CreateEgressPolicies

func (n *NetworkPolicyManager) CreateEgressPolicies(ctx context.Context, sandbox *resources.Sandbox) error

CreateEgressPolicies creates egress policies for a sandbox

func (*NetworkPolicyManager) DeleteNetworkPolicies

func (n *NetworkPolicyManager) DeleteNetworkPolicies(ctx context.Context, sandbox *resources.Sandbox) error

DeleteNetworkPolicies deletes all network policies for a sandbox

type PodManager

type PodManager struct {
	Client client.Client
	Scheme *runtime.Scheme
}

PodManager handles pod creation and management

func NewPodManager

func NewPodManager(client client.Client, scheme *runtime.Scheme) *PodManager

NewPodManager creates a new PodManager

func (*PodManager) CreateSandboxPod

func (p *PodManager) CreateSandboxPod(ctx context.Context, sandbox *resources.Sandbox) (*corev1.Pod, error)

CreateSandboxPod creates a new pod for a sandbox

func (*PodManager) CreateWarmPodPod

func (p *PodManager) CreateWarmPodPod(ctx context.Context, warmPod *resources.WarmPod, warmPool *resources.WarmPool) (*corev1.Pod, error)

CreateWarmPodPod creates a new pod for a warm pod

func (*PodManager) RecyclePod

func (p *PodManager) RecyclePod(ctx context.Context, pod *corev1.Pod) error

RecyclePod recycles a pod for reuse

type ServiceManager

type ServiceManager struct {
	Client client.Client
	Scheme *runtime.Scheme
}

ServiceManager handles service creation and management

func NewServiceManager

func NewServiceManager(client client.Client, scheme *runtime.Scheme) *ServiceManager

NewServiceManager creates a new ServiceManager

func (*ServiceManager) CreateSandboxService

func (s *ServiceManager) CreateSandboxService(ctx context.Context, sandbox *resources.Sandbox, podName string) (*corev1.Service, error)

CreateSandboxService creates a new service for a sandbox

func (*ServiceManager) DeleteService

func (s *ServiceManager) DeleteService(ctx context.Context, namespace, name string) error

DeleteService deletes a service

Jump to

Keyboard shortcuts

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