From 463f0c22c0d7717beee734d87d4e4ad8690cdc70 Mon Sep 17 00:00:00 2001 From: Allison Pierson Date: Wed, 5 Apr 2023 15:17:52 -0500 Subject: [PATCH] fix tests and potential segfault in `configureLaunchInputForReleaseCommand` --- internal/command/deploy/deploy.go | 2 +- internal/command/deploy/machines.go | 8 ++++++-- internal/command/deploy/machines_test.go | 11 +++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/internal/command/deploy/deploy.go b/internal/command/deploy/deploy.go index 46e97e307b..56bdb634e9 100644 --- a/internal/command/deploy/deploy.go +++ b/internal/command/deploy/deploy.go @@ -71,7 +71,7 @@ var CommonFlags = flag.Set{ flag.Int{ Name: "release-command-memory", Description: "Set release command machine memory to a number of megabytes", - Default: 256, + Default: DefaultReleaseCommandMemoryMb, }, flag.Bool{ Name: "force-nomad", diff --git a/internal/command/deploy/machines.go b/internal/command/deploy/machines.go index 4633469116..71b50bc295 100644 --- a/internal/command/deploy/machines.go +++ b/internal/command/deploy/machines.go @@ -27,8 +27,9 @@ import ( ) const ( - DefaultWaitTimeout = 120 * time.Second - DefaultLeaseTtl = 13 * time.Second + DefaultWaitTimeout = 120 * time.Second + DefaultLeaseTtl = 13 * time.Second + DefaultReleaseCommandMemoryMb = 256 ) type MachineDeployment interface { @@ -504,6 +505,9 @@ func (md *machineDeployment) configureLaunchInputForReleaseCommand(launchInput * if _, present := launchInput.Config.Env["RELEASE_COMMAND"]; !present { launchInput.Config.Env["RELEASE_COMMAND"] = "1" } + if launchInput.Config.Guest == nil { + launchInput.Config.Guest = &api.MachineGuest{} + } launchInput.Config.Guest.MemoryMB = md.releaseCommandMemory return launchInput } diff --git a/internal/command/deploy/machines_test.go b/internal/command/deploy/machines_test.go index 36b744510c..2f17d48961 100644 --- a/internal/command/deploy/machines_test.go +++ b/internal/command/deploy/machines_test.go @@ -16,8 +16,9 @@ func stabMachineDeployment(appConfig *appconfig.Config) (*machineDeployment, err ID: "my-dangling-org", }, }, - img: "super/balloon", - appConfig: appConfig, + img: "super/balloon", + appConfig: appConfig, + releaseCommandMemory: 891, } var err error md.processConfigs, err = md.appConfig.GetProcessConfigs() @@ -161,6 +162,9 @@ func Test_resolveUpdatedMachineConfig_ReleaseCommand(t *testing.T) { DNS: &api.DNSConfig{ SkipRegistration: true, }, + Guest: &api.MachineGuest{ + MemoryMB: 891, + }, }, }, md.resolveUpdatedMachineConfig(nil, true)) @@ -204,6 +208,9 @@ func Test_resolveUpdatedMachineConfig_ReleaseCommand(t *testing.T) { DNS: &api.DNSConfig{ SkipRegistration: true, }, + Guest: &api.MachineGuest{ + MemoryMB: 891, + }, }, }, md.resolveUpdatedMachineConfig(origMachine, true)) }