Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apis/v1/cocoonset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

// CocoonSetSpec defines the desired state of a CocoonSet.
// +kubebuilder:validation:XValidation:rule="!has(self.hibernatePolicy) || self.hibernatePolicy != 'release' || ((!has(self.agent.replicas) || self.agent.replicas == 0) && (!has(self.toolboxes) || size(self.toolboxes) == 0))",message="hibernatePolicy=release requires agent.replicas=0 and no toolboxes"
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.snapshotCompatibilityClass) || (has(self.snapshotCompatibilityClass) && self.snapshotCompatibilityClass == oldSelf.snapshotCompatibilityClass)",message="snapshotCompatibilityClass is immutable once set"
type CocoonSetSpec struct {
// +optional
Suspend bool `json:"suspend,omitempty"`
Expand All @@ -27,6 +28,11 @@ type CocoonSetSpec struct {
// +kubebuilder:default=default
NodePool string `json:"nodePool,omitempty"`

// +optional
// +kubebuilder:validation:MaxLength=63
// +kubebuilder:validation:Pattern=`^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$`
SnapshotCompatibilityClass string `json:"snapshotCompatibilityClass,omitempty"`

// NodeName pins the VM to a node (cross-node migrate). Empty = let the
// scheduler place it within NodePool and leave it alone; a value adds a
// hostname nodeAffinity so the pod lands there or stays Pending if it won't fit.
Expand Down
26 changes: 26 additions & 0 deletions apis/v1/cocoonset_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package v1

import (
"encoding/json"
"strings"
"testing"
)

func TestCocoonSetSpecSnapshotCompatibilityClassJSON(t *testing.T) {
spec := CocoonSetSpec{SnapshotCompatibilityClass: "n2-cascade-lake-v1"}
raw, err := json.Marshal(spec)
if err != nil {
t.Fatalf("marshal CocoonSetSpec: %v", err)
}
if !strings.Contains(string(raw), `"snapshotCompatibilityClass":"n2-cascade-lake-v1"`) {
t.Fatalf("snapshot compatibility class missing from JSON: %s", raw)
}

raw, err = json.Marshal(CocoonSetSpec{})
if err != nil {
t.Fatalf("marshal empty CocoonSetSpec: %v", err)
}
if strings.Contains(string(raw), "snapshotCompatibilityClass") {
t.Fatalf("empty snapshot compatibility class must be omitted: %s", raw)
}
}
11 changes: 11 additions & 0 deletions apis/v1/crds/cocoonset.cocoonstack.io_cocoonsets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,14 @@ spec:
nodePool:
default: default
type: string
snapshotCompatibilityClass:
description: |-
SnapshotCompatibilityClass selects nodes that expose a guest-visible CPU
ABI compatible with this set's memory snapshots. It is independent from
NodePool so multiple workload pools can share one snapshot class.
maxLength: 63
pattern: ^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$
type: string
snapshotPolicy:
default: always
description: SnapshotPolicy defines when VM snapshots are taken.
Expand Down Expand Up @@ -436,6 +444,9 @@ spec:
rule: '!has(self.hibernatePolicy) || self.hibernatePolicy != ''release''
|| ((!has(self.agent.replicas) || self.agent.replicas == 0) && (!has(self.toolboxes)
|| size(self.toolboxes) == 0))'
- message: snapshotCompatibilityClass is immutable once set
rule: '!has(oldSelf.snapshotCompatibilityClass) || (has(self.snapshotCompatibilityClass)
&& self.snapshotCompatibilityClass == oldSelf.snapshotCompatibilityClass)'
status:
description: CocoonSetStatus represents the observed state of a CocoonSet.
properties:
Expand Down
2 changes: 2 additions & 0 deletions meta/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const (
LabelNodePool = "cocoonstack.io/pool"
// DefaultNodePool is the pool name used when LabelNodePool is unset.
DefaultNodePool = "default"
// LabelSnapshotCompatibilityClass selects nodes whose guest-visible CPU ABI
LabelSnapshotCompatibilityClass = "cocoonstack.io/snapshot-cpu-class"

// AnnotationMode declares the VM provisioning mode (clone / run / static).
AnnotationMode = "cocoonset.cocoonstack.io/mode"
Expand Down