Skip to content

Commit

Permalink
hibernation is immediate
Browse files Browse the repository at this point in the history
  • Loading branch information
purpleclay committed Aug 28, 2022
1 parent fb26b0c commit 5aabba9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
9 changes: 6 additions & 3 deletions pkg/imds/patch/spot.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ type Spot struct {
// document will conform to the IMDS specification and expose spot details within
// the IMDS metadata
func (p Spot) Patch(in []byte) ([]byte, error) {
// TODO: do not add 2 minutes onto a hibernate interruption notice
// A spot interruption notice can be issued two minutes in advance during a best case scenario
nowTime := time.Now().UTC()
if p.InstanceAction != HibernateSpotInstanceAction {
nowTime = nowTime.Add(2 * time.Minute)
}

// A spot interruption notice is issued two minutes in advance during a best case scenario
now := time.Now().UTC().Add(2 * time.Minute).Format(time.RFC3339)
now := nowTime.Format(time.RFC3339)

spotDetails := struct {
Action SpotInstanceAction
Expand Down
24 changes: 14 additions & 10 deletions pkg/imds/patch/spot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,26 @@ type spotPatchJSON struct {
} `json:"events"`
}

func TestSpotPatch_TerminateAction(t *testing.T) {
func TestSpotPatch(t *testing.T) {
tests := []struct {
name string
action patch.SpotInstanceAction
name string
action patch.SpotInstanceAction
duration time.Duration
}{
{
name: "TerminateAction",
action: patch.TerminateSpotInstanceAction,
name: "TerminateAction",
action: patch.TerminateSpotInstanceAction,
duration: 2 * time.Minute,
},
{
name: "StopAction",
action: patch.StopSpotInstanceAction,
name: "StopAction",
action: patch.StopSpotInstanceAction,
duration: 2 * time.Minute,
},
{
name: "HibernateAction",
action: patch.HibernateSpotInstanceAction,
name: "HibernateAction",
action: patch.HibernateSpotInstanceAction,
duration: 0,
},
}
for _, tt := range tests {
Expand All @@ -82,7 +86,7 @@ func TestSpotPatch_TerminateAction(t *testing.T) {
var spotJSON spotPatchJSON
json.Unmarshal(out, &spotJSON)

now := time.Now().UTC().Add(2 * time.Minute)
now := time.Now().UTC().Add(tt.duration)

assert.Equal(t, "spot", spotJSON.InstanceLifeCycle)
assert.Equal(t, string(tt.action), spotJSON.Spot.InstanceAction.Action)
Expand Down

0 comments on commit 5aabba9

Please sign in to comment.