Skip to content

Commit 94b4f60

Browse files
committed
cleanup memo
1 parent 0cf2e26 commit 94b4f60

15 files changed

Lines changed: 54 additions & 353 deletions

apis/v1/cocoonhibernation_types.go

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,17 @@ import (
55
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
66
)
77

8-
// HibernationDesire is the requested target state for a pod's VM.
9-
//
108
// +kubebuilder:validation:Enum=Hibernate;Wake
9+
1110
type HibernationDesire string
1211

1312
const (
14-
// HibernationDesireHibernate asks vk-cocoon to snapshot the VM,
15-
// destroy it, and keep the backing pod alive.
1613
HibernationDesireHibernate HibernationDesire = "Hibernate"
17-
// HibernationDesireWake asks vk-cocoon to restore the VM from a
18-
// previously hibernated snapshot.
19-
HibernationDesireWake HibernationDesire = "Wake"
14+
HibernationDesireWake HibernationDesire = "Wake"
2015
)
2116

22-
// CocoonHibernationPhase is the high-level state reported in status.
23-
//
2417
// +kubebuilder:validation:Enum=Pending;Hibernating;Hibernated;Waking;Active;Failed
18+
2519
type CocoonHibernationPhase string
2620

2721
const (
@@ -33,32 +27,24 @@ const (
3327
CocoonHibernationPhaseFailed CocoonHibernationPhase = "Failed"
3428
)
3529

36-
// CocoonHibernationSpec is the desired state of a CocoonHibernation.
3730
type CocoonHibernationSpec struct {
38-
// PodRef points at the pod whose VM should be hibernated or woken.
3931
// +kubebuilder:validation:Required
4032
PodRef corev1.LocalObjectReference `json:"podRef"`
4133

42-
// Desire is the target state.
4334
// +kubebuilder:validation:Required
4435
Desire HibernationDesire `json:"desire"`
4536
}
4637

47-
// CocoonHibernationStatus is the observed state of a CocoonHibernation.
4838
type CocoonHibernationStatus struct {
49-
// ObservedGeneration is the .metadata.generation the controller last reconciled.
5039
// +optional
5140
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
5241

53-
// Phase reflects the lifecycle state.
5442
// +optional
5543
Phase CocoonHibernationPhase `json:"phase,omitempty"`
5644

57-
// VMName is the deterministic VM name resolved from the pod annotations.
5845
// +optional
5946
VMName string `json:"vmName,omitempty"`
6047

61-
// Conditions follow the standard Kubernetes condition pattern.
6248
// +optional
6349
// +patchMergeKey=type
6450
// +patchStrategy=merge
@@ -75,7 +61,6 @@ type CocoonHibernationStatus struct {
7561
// +kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase`
7662
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
7763

78-
// CocoonHibernation is the Schema for the cocoonhibernations API.
7964
type CocoonHibernation struct {
8065
metav1.TypeMeta `json:",inline"`
8166
metav1.ObjectMeta `json:"metadata,omitempty"`
@@ -86,7 +71,6 @@ type CocoonHibernation struct {
8671

8772
// +kubebuilder:object:root=true
8873

89-
// CocoonHibernationList is a list of CocoonHibernation.
9074
type CocoonHibernationList struct {
9175
metav1.TypeMeta `json:",inline"`
9276
metav1.ListMeta `json:"metadata,omitempty"`

apis/v1/cocoonset_types.go

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,149 +6,114 @@ import (
66
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
77
)
88

9-
// CocoonSetSpec is the desired state of a CocoonSet.
109
type CocoonSetSpec struct {
11-
// Suspend, when true, hibernates every managed pod.
1210
// +optional
1311
Suspend bool `json:"suspend,omitempty"`
1412

15-
// SnapshotPolicy controls when vk-cocoon snapshots VMs before destroying them.
1613
// +optional
1714
// +kubebuilder:default=always
1815
SnapshotPolicy SnapshotPolicy `json:"snapshotPolicy,omitempty"`
1916

20-
// NodePool selects the cocoon node pool that should host this CocoonSet.
21-
// vk-cocoon nodes are labeled with cocoonstack.io/pool=<name>.
2217
// +optional
2318
// +kubebuilder:default=default
2419
NodePool string `json:"nodePool,omitempty"`
2520

26-
// Agent describes the main agent VM and any sub-agent replicas.
2721
// +kubebuilder:validation:Required
2822
Agent AgentSpec `json:"agent"`
2923

30-
// Toolboxes are companion VMs scheduled alongside the agents.
3124
// +optional
3225
Toolboxes []ToolboxSpec `json:"toolboxes,omitempty"`
3326
}
3427

35-
// AgentSpec describes a CocoonSet's main agent and sub-agent replicas.
3628
type AgentSpec struct {
37-
// Replicas is the number of sub-agents to fork from the main agent.
38-
// The main agent is always created in addition to Replicas.
29+
// Replicas is the number of sub-agents; the main agent is always created in addition.
3930
// +optional
4031
// +kubebuilder:default=0
4132
// +kubebuilder:validation:Minimum=0
4233
Replicas int32 `json:"replicas,omitempty"`
4334

44-
// Image is the epoch reference or boot image URL.
4535
// +kubebuilder:validation:Required
4636
// +kubebuilder:validation:MinLength=1
4737
Image string `json:"image"`
4838

49-
// Mode controls how the VM is brought up.
5039
// +optional
5140
// +kubebuilder:default=clone
5241
Mode AgentMode `json:"mode,omitempty"`
5342

54-
// OS is the guest operating system.
5543
// +optional
5644
// +kubebuilder:default=linux
5745
OS OSType `json:"os,omitempty"`
5846

59-
// Network is the CNI conflist name to use; empty means cocoon default.
6047
// +optional
6148
Network string `json:"network,omitempty"`
6249

63-
// Storage is the COW disk size to allocate for each VM.
6450
// +optional
6551
Storage *resource.Quantity `json:"storage,omitempty"`
6652

67-
// Resources passes through CPU/memory hints to the underlying pod.
6853
// +optional
6954
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
7055

71-
// EnvFrom is forwarded to the agent container's envFrom field.
7256
// +optional
7357
EnvFrom []corev1.EnvFromSource `json:"envFrom,omitempty"`
7458

75-
// ServiceAccountName overrides the agent pod's serviceAccountName.
7659
// +optional
7760
ServiceAccountName string `json:"serviceAccountName,omitempty"`
7861
}
7962

80-
// ToolboxSpec describes a companion toolbox VM scheduled alongside agents.
8163
type ToolboxSpec struct {
82-
// Name is unique within the CocoonSet and must follow RFC 1123 label rules.
8364
// +kubebuilder:validation:Required
8465
// +kubebuilder:validation:MinLength=1
8566
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`
8667
Name string `json:"name"`
8768

88-
// OS is the guest operating system.
8969
// +optional
9070
// +kubebuilder:default=linux
9171
OS OSType `json:"os,omitempty"`
9272

93-
// Image is the epoch reference or boot image URL. Required for non-static modes.
9473
// +optional
9574
Image string `json:"image,omitempty"`
9675

97-
// Mode controls how the toolbox VM is brought up.
9876
// +optional
9977
// +kubebuilder:default=run
10078
Mode ToolboxMode `json:"mode,omitempty"`
10179

102-
// Storage is the COW disk size to allocate.
10380
// +optional
10481
Storage *resource.Quantity `json:"storage,omitempty"`
10582

106-
// StaticIP is the pre-assigned IP for static-mode toolboxes.
10783
// +optional
10884
StaticIP string `json:"staticIP,omitempty"`
10985

110-
// StaticVMID is the pre-assigned VM identifier for static-mode toolboxes.
11186
// +optional
11287
StaticVMID string `json:"staticVMID,omitempty"`
11388

114-
// VNCPort is the VNC port for graphical access (Windows, Android).
11589
// +optional
11690
// +kubebuilder:validation:Minimum=0
11791
// +kubebuilder:validation:Maximum=65535
11892
VNCPort int32 `json:"vncPort,omitempty"`
11993

120-
// Resources passes through CPU/memory hints to the underlying pod.
12194
// +optional
12295
Resources corev1.ResourceRequirements `json:"resources,omitempty"`
12396
}
12497

125-
// CocoonSetStatus is the observed state of a CocoonSet.
12698
type CocoonSetStatus struct {
127-
// ObservedGeneration is the .metadata.generation the controller last reconciled.
12899
// +optional
129100
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
130101

131-
// Phase is the high-level lifecycle phase.
132102
// +optional
133103
Phase CocoonSetPhase `json:"phase,omitempty"`
134104

135-
// ReadyAgents is the count of agent pods in the Running phase.
136105
// +optional
137106
ReadyAgents int32 `json:"readyAgents"`
138107

139-
// DesiredAgents is the total number of agents requested by spec (1 + Replicas).
140108
// +optional
141109
DesiredAgents int32 `json:"desiredAgents"`
142110

143-
// Agents reports per-agent runtime state.
144111
// +optional
145112
Agents []AgentStatus `json:"agents,omitempty"`
146113

147-
// Toolboxes reports per-toolbox runtime state.
148114
// +optional
149115
Toolboxes []ToolboxStatus `json:"toolboxes,omitempty"`
150116

151-
// Conditions follow the standard Kubernetes condition pattern.
152117
// +optional
153118
// +patchMergeKey=type
154119
// +patchStrategy=merge
@@ -157,9 +122,6 @@ type CocoonSetStatus struct {
157122
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
158123
}
159124

160-
// AgentStatus is the per-agent runtime state. Slot 0 is always the
161-
// main agent; ForkedFrom is set only for sub-agents and points at
162-
// the main VM they cloned from.
163125
type AgentStatus struct {
164126
Slot int32 `json:"slot"`
165127
Role string `json:"role"`
@@ -171,9 +133,6 @@ type AgentStatus struct {
171133
ForkedFrom string `json:"forkedFrom,omitempty"`
172134
}
173135

174-
// ToolboxStatus is the per-toolbox runtime state. ConnType is the
175-
// preferred kubectl-style connection protocol picked by
176-
// meta.ConnectionType (ssh / rdp / adb / vnc).
177136
type ToolboxStatus struct {
178137
Name string `json:"name"`
179138
PodName string `json:"podName,omitempty"`
@@ -193,7 +152,6 @@ type ToolboxStatus struct {
193152
// +kubebuilder:printcolumn:name="Desired",type=integer,JSONPath=`.status.desiredAgents`
194153
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
195154

196-
// CocoonSet is the Schema for the cocoonsets API.
197155
type CocoonSet struct {
198156
metav1.TypeMeta `json:",inline"`
199157
metav1.ObjectMeta `json:"metadata,omitempty"`
@@ -204,7 +162,6 @@ type CocoonSet struct {
204162

205163
// +kubebuilder:object:root=true
206164

207-
// CocoonSetList is a list of CocoonSet.
208165
type CocoonSetList struct {
209166
metav1.TypeMeta `json:",inline"`
210167
metav1.ListMeta `json:"metadata,omitempty"`

apis/v1/enums.go

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,46 @@
11
package v1
22

3-
// AgentMode controls how an agent VM is brought up.
4-
//
53
// +kubebuilder:validation:Enum=clone;run
4+
65
type AgentMode string
76

87
const (
9-
// AgentModeClone forks the VM from a snapshot in epoch.
108
AgentModeClone AgentMode = "clone"
11-
// AgentModeRun boots the VM cold from a cloud image.
12-
AgentModeRun AgentMode = "run"
9+
AgentModeRun AgentMode = "run"
1310
)
1411

15-
// IsValid reports whether m is one of the recognized AgentMode values.
1612
func (m AgentMode) IsValid() bool {
1713
return m == AgentModeClone || m == AgentModeRun
1814
}
1915

20-
// Default returns m when set, otherwise the canonical default
21-
// (AgentModeClone). Centralizing the fallback here keeps the
22-
// webhook, operator and vk-cocoon in lock-step.
16+
// Default returns m when set, otherwise AgentModeClone.
2317
func (m AgentMode) Default() AgentMode {
2418
if m == "" {
2519
return AgentModeClone
2620
}
2721
return m
2822
}
2923

30-
// ToolboxMode controls how a toolbox VM is brought up.
31-
//
3224
// +kubebuilder:validation:Enum=run;clone;static
3325
type ToolboxMode string
3426

3527
const (
36-
// ToolboxModeRun boots the toolbox VM cold from a cloud image.
37-
ToolboxModeRun ToolboxMode = "run"
38-
// ToolboxModeClone forks the toolbox VM from a snapshot in epoch.
39-
ToolboxModeClone ToolboxMode = "clone"
40-
// ToolboxModeStatic attaches to an externally managed VM and never
41-
// creates or destroys it; requires StaticIP and StaticVMID.
28+
ToolboxModeRun ToolboxMode = "run"
29+
ToolboxModeClone ToolboxMode = "clone"
4230
ToolboxModeStatic ToolboxMode = "static"
4331
)
4432

45-
// IsValid reports whether m is one of the recognized ToolboxMode values.
4633
func (m ToolboxMode) IsValid() bool {
4734
return m == ToolboxModeRun || m == ToolboxModeClone || m == ToolboxModeStatic
4835
}
4936

50-
// Default returns m when set, otherwise ToolboxModeRun.
5137
func (m ToolboxMode) Default() ToolboxMode {
5238
if m == "" {
5339
return ToolboxModeRun
5440
}
5541
return m
5642
}
5743

58-
// OSType is the guest operating system family.
59-
//
6044
// +kubebuilder:validation:Enum=linux;windows;android
6145
type OSType string
6246

@@ -66,48 +50,37 @@ const (
6650
OSAndroid OSType = "android"
6751
)
6852

69-
// IsValid reports whether o is one of the recognized OSType values.
7053
func (o OSType) IsValid() bool {
7154
return o == OSLinux || o == OSWindows || o == OSAndroid
7255
}
7356

74-
// Default returns o when set, otherwise OSLinux.
7557
func (o OSType) Default() OSType {
7658
if o == "" {
7759
return OSLinux
7860
}
7961
return o
8062
}
8163

82-
// SnapshotPolicy controls when vk-cocoon takes snapshots.
83-
//
8464
// +kubebuilder:validation:Enum=always;main-only;never
8565
type SnapshotPolicy string
8666

8767
const (
88-
// SnapshotPolicyAlways snapshots every agent before destroy.
89-
SnapshotPolicyAlways SnapshotPolicy = "always"
90-
// SnapshotPolicyMainOnly snapshots only the main agent (slot 0).
68+
SnapshotPolicyAlways SnapshotPolicy = "always"
9169
SnapshotPolicyMainOnly SnapshotPolicy = "main-only"
92-
// SnapshotPolicyNever skips snapshots entirely.
93-
SnapshotPolicyNever SnapshotPolicy = "never"
70+
SnapshotPolicyNever SnapshotPolicy = "never"
9471
)
9572

96-
// IsValid reports whether p is one of the recognized SnapshotPolicy values.
9773
func (p SnapshotPolicy) IsValid() bool {
9874
return p == SnapshotPolicyAlways || p == SnapshotPolicyMainOnly || p == SnapshotPolicyNever
9975
}
10076

101-
// Default returns p when set, otherwise SnapshotPolicyAlways.
10277
func (p SnapshotPolicy) Default() SnapshotPolicy {
10378
if p == "" {
10479
return SnapshotPolicyAlways
10580
}
10681
return p
10782
}
10883

109-
// CocoonSetPhase is the high-level lifecycle phase reported in status.
110-
//
11184
// +kubebuilder:validation:Enum=Pending;Running;Scaling;Suspended;Failed
11285
type CocoonSetPhase string
11386

apis/v1/groupversion_info.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@ import (
55
"sigs.k8s.io/controller-runtime/pkg/scheme"
66
)
77

8-
// GroupVersion is the API Group Version used to register the objects.
98
var GroupVersion = schema.GroupVersion{Group: "cocoonset.cocoonstack.io", Version: "v1"}
109

11-
// SchemeBuilder collects type registrations for this group; consumers
12-
// call AddToScheme to install them on a runtime.Scheme.
1310
var SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
1411

15-
// AddToScheme adds the types in this group-version to the given scheme.
1612
var AddToScheme = SchemeBuilder.AddToScheme

0 commit comments

Comments
 (0)