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
12 changes: 12 additions & 0 deletions meta/hibernate.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,15 @@ func ReadRestoreFromHibernate(pod *corev1.Pod) bool {
}
return pod.Annotations[AnnotationRestoreFromHibernate] == annotationTrue
}

// MarkRestoreFromHibernate flags a freshly-built pod to restore its VM from the
// :hibernate snapshot instead of cloning from the base image. The operator sets
// this when it (re)creates a pod for an agent that is currently hibernated (see
// AnnotationRestoreFromHibernate); symmetric with ReadRestoreFromHibernate.
func MarkRestoreFromHibernate(pod *corev1.Pod) {
if pod == nil {
return
}
a := ensurePodAnnotations(pod)
a[AnnotationRestoreFromHibernate] = annotationTrue
}
15 changes: 15 additions & 0 deletions meta/hibernate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ func TestReadHibernateStateNilPod(t *testing.T) {
}
}

func TestMarkRestoreFromHibernate(t *testing.T) {
pod := &corev1.Pod{}
if ReadRestoreFromHibernate(pod) {
t.Fatal("fresh pod should not be flagged for restore")
}
MarkRestoreFromHibernate(pod)
if !ReadRestoreFromHibernate(pod) {
t.Errorf("MarkRestoreFromHibernate should round-trip through ReadRestoreFromHibernate")
}
}

func TestMarkRestoreFromHibernateNilPod(t *testing.T) {
MarkRestoreFromHibernate(nil) // must not panic
}

func TestHibernateSnapshotTagConstant(t *testing.T) {
if HibernateSnapshotTag != "hibernate" {
t.Errorf("HibernateSnapshotTag = %q, want %q", HibernateSnapshotTag, "hibernate")
Expand Down