Something went wrong. Try again.
A Kubernetes operator that runs Claude Code sessions on long-horizon work
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201// Package v1alpha1 holds the resources of the API group simmer.foo,// version v1alpha1, as Go types: the Account, Allowance, Signal,// McpServer, and Stop that a cluster owner declares once for the// cluster, the Mandate that delegates a responsibility, the Duty that// it owes, the Session that the operator// starts under a Mandate, the Hold that keeps a Duty's events from// starting Sessions, and the Console where a person works.//// The types are written by hand, the way liken's operators write// theirs. The operator speaks to the API server through liken's// kubernetes module, so a generated client and k8s.io/apimachinery would// add a large dependency tree for a few structs. ObjectMeta and// Condition copy only the fields that the operator reads or writes, and// keep the wire format of metav1.ObjectMeta and metav1.Condition.//// The CRDs in deploy/crds are written by hand too, and they are the// schema that the API server enforces. The tests here hold each type to// its CRD, field by field, so the two cannot drift apart.package v1alpha1
import ( "time"
"github.com/liken-sh/liken/kubernetes/conditions")
const ( // Group is the API group of every kind in this package. Group = "simmer.foo" // Version is the one version that the CRDs serve. Version = "v1alpha1" // APIVersion is the value of apiVersion in every object. APIVersion = Group + "/" + Version // Category is the category of every kind, so `kubectl get simmer -A` // lists them all. Category = "simmer")
// The labels that the operator puts on the objects it creates.const ( // LabelMandate names the Mandate that a Session, a Job, or a // ClusterRoleBinding belongs to. LabelMandate = Group + "/mandate" // LabelMandateNamespace names the Mandate's namespace on a // ClusterRoleBinding. A ClusterRoleBinding cannot have a namespaced // owner, so the operator finds and deletes it by these two labels. LabelMandateNamespace = Group + "/mandate-namespace" // LabelSession names the Session that a Job and its pod run a turn // of. The data plane accepts a request only from a pod with this // label. LabelSession = Group + "/session" // LabelTurn numbers the turn that a Job and its pod run, from 1. The // data plane takes and acknowledges a turn's events under it. LabelTurn = Group + "/turn" // LabelDuty names the Duty that a Session runs, or that a // ServiceAccount, a binding, or a CronJob belongs to. LabelDuty = Group + "/duty" // LabelProbe names the Account that a probe Job and its pod read. // The data plane accepts an Account's usage reading only from a pod // with this label, in the operator's namespace. LabelProbe = Group + "/probe" // LabelHook names the hook that a Job and its pod run: before or // after. The operator sets it after it merges the hook's template, // so a template cannot drop it. The data plane lets a pod with this // label read its hook's context and nothing else. LabelHook = Group + "/hook" // LabelSchedule names the Duty whose schedule a CronJob, its Jobs, // and their pods run. The data plane // lets a pod with this label start only that duty. LabelSchedule = Group + "/schedule" // LabelConsole names the Console that a ServiceAccount, a binding, a // home volume, a Deployment, or a pod belongs to. LabelConsole = Group + "/console" // LabelConsoleNamespace names the Console's namespace on a // ClusterRoleBinding, which cannot have a namespaced owner. LabelConsoleNamespace = Group + "/console-namespace")
// ObjectMeta is the part of an object's metadata that the operator// uses. The namespace is empty for a cluster-scoped kind. Labels,// annotations, and owner references are here so that an object the// operator reads and writes back keeps them.type ObjectMeta struct { Name string `json:"name,omitempty"` GenerateName string `json:"generateName,omitempty"` Namespace string `json:"namespace,omitempty"` UID string `json:"uid,omitempty"` ResourceVersion string `json:"resourceVersion,omitempty"` Generation int64 `json:"generation,omitempty"` CreationTimestamp *time.Time `json:"creationTimestamp,omitempty"` DeletionTimestamp *time.Time `json:"deletionTimestamp,omitempty"` Finalizers []string `json:"finalizers,omitempty"` Labels map[string]string `json:"labels,omitempty"` Annotations map[string]string `json:"annotations,omitempty"` OwnerReferences []OwnerReference `json:"ownerReferences,omitempty"`}
// OwnerReference has the shape of metav1.OwnerReference. A Session// names its Mandate here, so Kubernetes deletes the Session when the// Mandate goes.type OwnerReference struct { APIVersion string `json:"apiVersion"` Kind string `json:"kind"` Name string `json:"name"` UID string `json:"uid"` Controller *bool `json:"controller,omitempty"` BlockOwnerDeletion *bool `json:"blockOwnerDeletion,omitempty"`}
// Meta is the part of the metadata that a watch's store reads. It is// the same interface literal as liken's memo.Meta, so the types answer// that interface.type Meta = interface { GetNamespace() string GetName() string GetResourceVersion() string}
func (m *ObjectMeta) GetName() string { return m.Name }func (m *ObjectMeta) GetNamespace() string { return m.Namespace }func (m *ObjectMeta) GetResourceVersion() string { return m.ResourceVersion }
// ListMeta is the metadata of a list. Its resourceVersion is the// version that a watch starts from.type ListMeta struct { ResourceVersion string `json:"resourceVersion,omitempty"`}
// Object is one resource of a kind: the metadata, the spec that a// person writes, and the status that the operator writes. Each kind in// this package is an alias of Object with its own spec and status, so// every kind has the same envelope and the same methods.type Object[Spec, Status any] struct { APIVersion string `json:"apiVersion,omitempty"` Kind string `json:"kind,omitempty"` Metadata ObjectMeta `json:"metadata"` Spec Spec `json:"spec"` Status Status `json:"status,omitzero"`}
// GetObjectMeta answers the metadata, for the watch's store and the// memo of the operator's own writes.func (o *Object[Spec, Status]) GetObjectMeta() Meta { return &o.Metadata }
// List is the answer to a list request for one kind.type List[T any] struct { Metadata ListMeta `json:"metadata"` Items []T `json:"items"`}
// Condition has the shape of metav1.Condition, so `kubectl describe`// and `kubectl wait --for=condition=Ready` read it the way they read a// Pod's conditions. It is liken's shared condition type, so liken's// setter keeps its lastTransitionTime and its events package posts an// Event for each transition.type Condition = conditions.Condition
// ConditionStatus is a condition's verdict: True, False, or Unknown.type ConditionStatus = conditions.Status
const ( ConditionTrue = conditions.True ConditionFalse = conditions.False ConditionUnknown = conditions.Unknown)
// SecretKeyRef names one key of one Secret. The kinds that hold one// are cluster-scoped, so the reference names the namespace too.type SecretKeyRef struct { Namespace string `json:"namespace"` Name string `json:"name"` Key string `json:"key"`}
// Kind names one resource of the group: its kind, the plural that its// URL uses, and whether its objects live in a namespace.type Kind struct { Name string Plural string Namespaced bool}
var ( AccountKind = Kind{"Account", "accounts", false} AllowanceKind = Kind{"Allowance", "allowances", false} SignalKind = Kind{"Signal", "signals", false} McpServerKind = Kind{"McpServer", "mcpservers", false} StopKind = Kind{"Stop", "stops", false} MandateKind = Kind{"Mandate", "mandates", true} SessionKind = Kind{"Session", "sessions", true} ConsoleKind = Kind{"Console", "consoles", true} DutyKind = Kind{"Duty", "duties", true} HoldKind = Kind{"Hold", "holds", true})
// Kinds lists every kind of the group.var Kinds = []Kind{ AccountKind, AllowanceKind, SignalKind, McpServerKind, StopKind, MandateKind, SessionKind, ConsoleKind, DutyKind, HoldKind,}