controller

package
v0.0.0-...-fabb9d9 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package controller is the Kubernetes side of the reference issuer: it turns CapacityGrant resources into signed grants and grant Pods. For every CapacityGrant it creates the Pod (fiberd as PID 1, with the readiness gate), mints a JWT addressed to that Pod with the resource's uid as the grant uid, projects it into the Pod through a Secret, renews it at half-life, and mirrors the Pod's placement and readiness gate into the resource's status. The key lives in a Secret; the public half is served as a JWKS beside the OIDC discovery document.

It polls rather than watches: a list every few seconds is the same shape as the homes' grant delivery, needs no resourceVersion bookkeeping, and is more than fast enough for the number of grants a cluster holds.

Index

Constants

View Source
const (
	// GrantsMount is where the projected grant lands in fiberd.
	GrantsMount = "/var/run/fiberd/grants"
	// GrantsFile is the key in the grant Secret and the file's name.
	GrantsFile = "grant.jwt"
)
View Source
const (
	Group      = "fiberd.io"
	Version    = "v1alpha1"
	APIVersion = Group + "/" + Version
	Kind       = "CapacityGrant"
	Resource   = "capacitygrants"
	// GrantLabel marks the Pod and Secret of a CapacityGrant.
	GrantLabel = "fiberd.io/grant"
	// ReadyCondition is the Pod readiness gate fiberd sets.
	ReadyCondition = "fiberd.io/zygote-ready"
)

The CapacityGrant custom resource, fiberd.io/v1alpha1. Its spec is the CapacityGrant of the protocol plus how to build the grant Pod; its status is what the controller learned. The CRD manifest in kind/manifests/10-crd.yaml is the schema of these types.

Variables

This section is empty.

Functions

func EnsureKey

func EnsureKey(ctx context.Context, client *kube.Client, ns, name string) (*jose.JSONWebKey, error)

EnsureKey loads the issuer's private key from a Secret in ns, creating a fresh EdDSA key there when the Secret does not exist.

func ParseBytes

func ParseBytes(s string) (uint64, error)

ParseBytes reads a byte count with an optional Ki/Mi/Gi (or K/M/G) suffix; empty is zero.

func PodName

func PodName(cg *CapacityGrant) string

PodName is the grant Pod's name for a CapacityGrant.

func SecretName

func SecretName(cg *CapacityGrant) string

SecretName is the grant Secret's name for a CapacityGrant.

Types

type Capabilities

type Capabilities struct {
	Add  []string `json:"add,omitempty"`
	Drop []string `json:"drop,omitempty"`
}

type CapacityGrant

type CapacityGrant struct {
	APIVersion string          `json:"apiVersion"`
	Kind       string          `json:"kind"`
	Metadata   kube.ObjectMeta `json:"metadata"`
	Spec       Spec            `json:"spec"`
	Status     Status          `json:"status,omitempty"`
}

type CapacityGrantList

type CapacityGrantList struct {
	Items []CapacityGrant `json:"items"`
}

CapacityGrantList is what a list returns.

type Container

type Container struct {
	Name            string            `json:"name"`
	Image           string            `json:"image"`
	Command         []string          `json:"command,omitempty"`
	Args            []string          `json:"args"`
	Env             []EnvVar          `json:"env,omitempty"`
	Ports           []ContainerPort   `json:"ports,omitempty"`
	Resources       json.RawMessage   `json:"resources,omitempty"`
	SecurityContext *SecurityContext  `json:"securityContext,omitempty"`
	VolumeMounts    []VolumeMount     `json:"volumeMounts"`
	ReadinessProbe  *Probe            `json:"readinessProbe,omitempty"`
	StartupProbe    *Probe            `json:"startupProbe,omitempty"`
	LivenessProbe   *Probe            `json:"livenessProbe,omitempty"`
	Labels          map[string]string `json:"-"`
}

type ContainerPort

type ContainerPort struct {
	Name          string `json:"name"`
	ContainerPort int    `json:"containerPort"`
}

type Controller

type Controller struct {
	Client *kube.Client
	Issuer *grant.Issuer
	// Poll is the reconcile cadence (default 2s).
	Poll time.Duration
	// Now is for tests.
	Now func() time.Time
}

func (*Controller) Reconcile

func (c *Controller) Reconcile(ctx context.Context) error

Reconcile is one pass over every CapacityGrant in the cluster.

func (*Controller) Run

func (c *Controller) Run(ctx context.Context)

Run reconciles until ctx ends.

type EmptyDirVolume

type EmptyDirVolume struct {
	Medium string `json:"medium,omitempty"`
}

type EnvSource

type EnvSource struct {
	FieldRef *struct {
		FieldPath string `json:"fieldPath"`
	} `json:"fieldRef,omitempty"`
}

type EnvVar

type EnvVar struct {
	Name      string     `json:"name"`
	Value     string     `json:"value,omitempty"`
	ValueFrom *EnvSource `json:"valueFrom,omitempty"`
}

type ExecAction

type ExecAction struct {
	Command []string `json:"command"`
}

type Pod

type Pod struct {
	APIVersion string          `json:"apiVersion"`
	Kind       string          `json:"kind"`
	Metadata   kube.ObjectMeta `json:"metadata"`
	Spec       PodSpecObject   `json:"spec"`
	Status     struct {
		Phase      string           `json:"phase,omitempty"`
		PodIP      string           `json:"podIP,omitempty"`
		Conditions []kube.Condition `json:"conditions,omitempty"`
	} `json:"status,omitempty"`
}

func BuildPod

func BuildPod(cg *CapacityGrant, issuerURL string, lease time.Duration) *Pod

BuildPod is the Pod spec for a CapacityGrant: fiberd-k8s as PID 1, the projected grant volume, the readiness gate, the cgroup and criu privileges, the block ceiling as the container's limits.

type PodSpec

type PodSpec struct {
	// Image carries fiberd, the template and (for FIBER_CHECKPOINT) criu.
	Image   string `json:"image"`
	Runtime string `json:"runtime,omitempty"` // proc (default), runc, gvisor, hyperlight
	// Args are appended to fiberd's flags (-template ..., -parity ...).
	Args []string `json:"args,omitempty"`
	// Resources is the container's resources: its limits are the block
	// ceiling the kubelet enforces on the Pod's cgroup.
	Resources          json.RawMessage `json:"resources,omitempty"`
	ServiceAccountName string          `json:"serviceAccountName,omitempty"`
	// ResourceClaims are the Pod's DRA claims (its device channel).
	ResourceClaims json.RawMessage `json:"resourceClaims,omitempty"`
	// Devices are what the claim exposes, as the engine expects them.
	Devices []string `json:"devices,omitempty"`
	// EndpointFamily is inet4 (default) or inet6: which Pod IP fibers
	// are served on.
	EndpointFamily string            `json:"endpointFamily,omitempty"`
	NodeSelector   map[string]string `json:"nodeSelector,omitempty"`
	NodeName       string            `json:"nodeName,omitempty"`
	// Privileged runs fiberd privileged. When unset, the proc runtime gets
	// only the capabilities in caps.Proc and no seccomp filter, because criu
	// cannot dump from under one. Every other runtime runs privileged, a
	// known gap, even though caps.Runc measures what runc needs.
	Privileged *bool `json:"privileged,omitempty"`
	// UnsafeAdmin enables fiberd's test-only admin controls. It needs
	// an image whose fiberd is built with -tags fiberd_testhooks.
	UnsafeAdmin bool              `json:"unsafeAdmin,omitempty"`
	Labels      map[string]string `json:"labels,omitempty"`
	Annotations map[string]string `json:"annotations,omitempty"`
}

PodSpec is how the grant Pod is built.

type PodSpecObject

type PodSpecObject struct {
	ServiceAccountName string            `json:"serviceAccountName,omitempty"`
	RestartPolicy      string            `json:"restartPolicy"`
	ReadinessGates     []ReadinessGate   `json:"readinessGates"`
	NodeSelector       map[string]string `json:"nodeSelector,omitempty"`
	NodeName           string            `json:"nodeName,omitempty"`
	ResourceClaims     json.RawMessage   `json:"resourceClaims,omitempty"`
	Volumes            []Volume          `json:"volumes"`
	Containers         []Container       `json:"containers"`
}

type Probe

type Probe struct {
	Exec             *ExecAction      `json:"exec,omitempty"`
	TCPSocket        *TCPSocketAction `json:"tcpSocket,omitempty"`
	PeriodSeconds    int              `json:"periodSeconds,omitempty"`
	TimeoutSeconds   int              `json:"timeoutSeconds,omitempty"`
	FailureThreshold int              `json:"failureThreshold,omitempty"`
}

type ReadinessGate

type ReadinessGate struct {
	ConditionType string `json:"conditionType"`
}

type SeccompProfile

type SeccompProfile struct {
	Type string `json:"type"`
}

type SecretVolume

type SecretVolume struct {
	SecretName string `json:"secretName"`
	Optional   bool   `json:"optional"`
}

type SecurityContext

type SecurityContext struct {
	Privileged     bool            `json:"privileged"`
	Capabilities   *Capabilities   `json:"capabilities,omitempty"`
	SeccompProfile *SeccompProfile `json:"seccompProfile,omitempty"`
}

type Spec

type Spec struct {
	// Template is the digest of the zygote artifact (what fiberd's
	// -template maps).
	Template string `json:"template"`
	Fibers   struct {
		Max  int `json:"max"`
		Warm int `json:"warm,omitempty"`
	} `json:"fibers"`
	// WBudget is the per-fiber dirtied working set ceiling (32Mi).
	WBudget string `json:"wBudget,omitempty"`
	MinTier string `json:"minTier,omitempty"`
	// Isolation is UNTRUSTED or TRUSTED. UNTRUSTED is the default, and only
	// a gvisor or hyperlight Pod serves it, so the controller refuses it on
	// any other runtime. Any runtime serves TRUSTED, including proc and runc.
	Isolation string `json:"isolation,omitempty"`
	// Lease is how long each minted grant is valid; the controller renews
	// at half-life. Default 10m.
	Lease        string `json:"lease,omitempty"`
	Durability   string `json:"durability,omitempty"`
	SessionClass string `json:"sessionClass,omitempty"`
	DeviceBudget *struct {
		Bytes string `json:"bytes"`
		Class string `json:"class,omitempty"`
	} `json:"deviceBudget,omitempty"`
	Pod PodSpec `json:"pod"`
}

type Status

type Status struct {
	// GrantUID is the uid the minted grants carry (the resource's uid).
	GrantUID string `json:"grantUID,omitempty"`
	PodName  string `json:"podName,omitempty"`
	// Placed is set once the scheduler put the Pod on a node.
	Placed bool   `json:"placed"`
	Node   string `json:"node,omitempty"`
	// Ready mirrors the Pod's readiness gate: a template is warm.
	Ready bool `json:"ready"`
	// Endpoint is where callers reach fiberd (Pod IP and port).
	Endpoint  string `json:"endpoint,omitempty"`
	IssuedAt  string `json:"issuedAt,omitempty"`
	ExpiresAt string `json:"expiresAt,omitempty"`
	Message   string `json:"message,omitempty"`
}

type TCPSocketAction

type TCPSocketAction struct {
	Port int `json:"port"`
}

type Volume

type Volume struct {
	Name     string          `json:"name"`
	Secret   *SecretVolume   `json:"secret,omitempty"`
	EmptyDir *EmptyDirVolume `json:"emptyDir,omitempty"`
}

type VolumeMount

type VolumeMount struct {
	Name      string `json:"name"`
	MountPath string `json:"mountPath"`
	ReadOnly  bool   `json:"readOnly,omitempty"`
}

Jump to

Keyboard shortcuts

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