From be1542f62e0c53774760c82173d38accbeba1ba1 Mon Sep 17 00:00:00 2001 From: Zhiwei Liang Date: Thu, 26 Mar 2026 22:42:29 -0400 Subject: [PATCH 1/5] fix: change swap_size to pointer type and update related logic --- .web-docs/components/builder/linode/README.md | 2 +- builder/linode/builder_test.go | 38 +++++++++++++++++++ builder/linode/config.go | 4 +- builder/linode/step_create_linode.go | 2 +- 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/.web-docs/components/builder/linode/README.md b/.web-docs/components/builder/linode/README.md index 0b562880..e588e301 100644 --- a/.web-docs/components/builder/linode/README.md +++ b/.web-docs/components/builder/linode/README.md @@ -88,7 +88,7 @@ can also be supplied to override the typical auto-generated key: for more information on the Images available for use. Examples are `linode/debian12`, `linode/debian13`, `linode/ubuntu24.04`, `linode/arch`, and `private/12345`. -- `swap_size` (int) - The disk size (MiB) allocated for swap space. +- `swap_size` (\*int) - The disk size (MiB) allocated for swap space. - `private_ip` (bool) - If true, the created Linode will have private networking enabled and assigned a private IPv4 address. diff --git a/builder/linode/builder_test.go b/builder/linode/builder_test.go index 9b310199..24261cf6 100644 --- a/builder/linode/builder_test.go +++ b/builder/linode/builder_test.go @@ -123,6 +123,44 @@ func TestBuilderPrepare_Size(t *testing.T) { } } +func TestBuilderPrepare_SwapSize(t *testing.T) { + t.Run("omitted remains nil", func(t *testing.T) { + var b Builder + config := testConfig() + delete(config, "swap_size") + + _, warnings, err := b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } + if err != nil { + t.Fatalf("should not have error: %s", err) + } + + if b.config.SwapSize != nil { + t.Fatalf("swap_size = %v, want nil", b.config.SwapSize) + } + }) + + t.Run("explicit zero remains non-nil", func(t *testing.T) { + var b Builder + config := testConfig() + config["swap_size"] = 0 + + _, warnings, err := b.Prepare(config) + if len(warnings) > 0 { + t.Fatalf("bad: %#v", warnings) + } + if err != nil { + t.Fatalf("should not have error: %s", err) + } + + if b.config.SwapSize == nil || *b.config.SwapSize != 0 { + t.Fatalf("swap_size = %v, want pointer to 0", b.config.SwapSize) + } + }) +} + func TestBuilderPrepare_Image(t *testing.T) { var b Builder config := testConfig() diff --git a/builder/linode/config.go b/builder/linode/config.go index 7e209ea5..548e4935 100644 --- a/builder/linode/config.go +++ b/builder/linode/config.go @@ -288,7 +288,7 @@ type Config struct { Image string `mapstructure:"image" required:"false"` // The disk size (MiB) allocated for swap space. - SwapSize int `mapstructure:"swap_size" required:"false"` + SwapSize *int `mapstructure:"swap_size" required:"false"` // If true, the created Linode will have private networking enabled and assigned // a private IPv4 address. @@ -720,7 +720,7 @@ func (c *Config) Prepare(raws ...any) ([]string, error) { errs, errors.New("authorized_users cannot be specified when using custom disks (specify in disk blocks instead)")) } - if c.SwapSize > 0 { + if c.SwapSize != nil && *c.SwapSize > 0 { errs = packersdk.MultiErrorAppend( errs, errors.New("swap_size cannot be specified when using custom disks (create a swap disk instead)")) } diff --git a/builder/linode/step_create_linode.go b/builder/linode/step_create_linode.go index f479aa59..fc9772c9 100644 --- a/builder/linode/step_create_linode.go +++ b/builder/linode/step_create_linode.go @@ -168,7 +168,7 @@ func (s *stepCreateLinode) Run(ctx context.Context, state multistep.StateBag) mu if !useCustomDisks { createOpts.RootPass = c.Comm.Password() createOpts.Image = c.Image - createOpts.SwapSize = &c.SwapSize + createOpts.SwapSize = c.SwapSize createOpts.StackScriptID = c.StackScriptID createOpts.StackScriptData = c.StackScriptData From daabfdee4ca7af013c8b9d3afad6b205f232f23c Mon Sep 17 00:00:00 2001 From: Zhiwei Liang <121905282+zliang-akamai@users.noreply.github.com> Date: Wed, 1 Apr 2026 13:34:58 -0400 Subject: [PATCH 2/5] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- builder/linode/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/linode/config.go b/builder/linode/config.go index 548e4935..fc0d90ec 100644 --- a/builder/linode/config.go +++ b/builder/linode/config.go @@ -720,7 +720,7 @@ func (c *Config) Prepare(raws ...any) ([]string, error) { errs, errors.New("authorized_users cannot be specified when using custom disks (specify in disk blocks instead)")) } - if c.SwapSize != nil && *c.SwapSize > 0 { + if c.SwapSize != nil { errs = packersdk.MultiErrorAppend( errs, errors.New("swap_size cannot be specified when using custom disks (create a swap disk instead)")) } From 526908c9f90337347fb8f2a9868eba919c9eed49 Mon Sep 17 00:00:00 2001 From: Zhiwei Liang Date: Wed, 1 Apr 2026 16:16:26 -0400 Subject: [PATCH 3/5] Add IncompatibleSwapSizeZero test case --- builder/linode/builder_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/builder/linode/builder_test.go b/builder/linode/builder_test.go index 24261cf6..901fa7c9 100644 --- a/builder/linode/builder_test.go +++ b/builder/linode/builder_test.go @@ -1027,6 +1027,27 @@ func TestBuilderPrepare_CustomDisksValidation(t *testing.T) { } }) + t.Run("IncompatibleSwapSizeZero", func(t *testing.T) { + var b Builder + config := testConfig() + delete(config, "image") + config["swap_size"] = 0 + config["disk"] = []map[string]any{ + {"label": "boot", "size": 25000, "image": "linode/arch"}, + } + config["config"] = []map[string]any{ + {"label": "my-config"}, + } + + _, _, err := b.Prepare(config) + if err == nil { + t.Fatal("expected error with swap_size=0 and custom disks") + } + if !strings.Contains(err.Error(), "swap_size cannot be specified when using custom disks") { + t.Fatalf("expected specific error message, got: %s", err) + } + }) + t.Run("IncompatibleStackScriptID", func(t *testing.T) { var b Builder config := testConfig() From 2af800e847adc91d427aeba3214970da3f1af7e2 Mon Sep 17 00:00:00 2001 From: Zhiwei Liang <121905282+zliang-akamai@users.noreply.github.com> Date: Fri, 3 Apr 2026 18:41:45 -0400 Subject: [PATCH 4/5] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .web-docs/components/builder/linode/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.web-docs/components/builder/linode/README.md b/.web-docs/components/builder/linode/README.md index e588e301..8f60bc06 100644 --- a/.web-docs/components/builder/linode/README.md +++ b/.web-docs/components/builder/linode/README.md @@ -88,7 +88,7 @@ can also be supplied to override the typical auto-generated key: for more information on the Images available for use. Examples are `linode/debian12`, `linode/debian13`, `linode/ubuntu24.04`, `linode/arch`, and `private/12345`. -- `swap_size` (\*int) - The disk size (MiB) allocated for swap space. +- `swap_size` (int) - The disk size (MiB) allocated for swap space. If omitted, no swap size is sent in the API payload. - `private_ip` (bool) - If true, the created Linode will have private networking enabled and assigned a private IPv4 address. From a61f46e56e31173dd06975809a94fdeddd60bd6c Mon Sep 17 00:00:00 2001 From: Zhiwei Liang Date: Fri, 3 Apr 2026 18:43:35 -0400 Subject: [PATCH 5/5] make generate --- .web-docs/components/builder/linode/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.web-docs/components/builder/linode/README.md b/.web-docs/components/builder/linode/README.md index 8f60bc06..e588e301 100644 --- a/.web-docs/components/builder/linode/README.md +++ b/.web-docs/components/builder/linode/README.md @@ -88,7 +88,7 @@ can also be supplied to override the typical auto-generated key: for more information on the Images available for use. Examples are `linode/debian12`, `linode/debian13`, `linode/ubuntu24.04`, `linode/arch`, and `private/12345`. -- `swap_size` (int) - The disk size (MiB) allocated for swap space. If omitted, no swap size is sent in the API payload. +- `swap_size` (\*int) - The disk size (MiB) allocated for swap space. - `private_ip` (bool) - If true, the created Linode will have private networking enabled and assigned a private IPv4 address.