From 8de19758dafce802c0f93a63ae3083b5ad17162d Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Mon, 13 Jan 2025 18:55:27 +0400 Subject: [PATCH] fix: a couple of imager panics/crashes Fixes #8987 Signed-off-by: Andrey Smirnov --- pkg/imager/profile/profile.go | 4 ++++ pkg/machinery/extensions/extensions_test.go | 4 ++-- pkg/machinery/extensions/validate.go | 4 ++-- pkg/machinery/imager/quirks/quirks.go | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/imager/profile/profile.go b/pkg/imager/profile/profile.go index 1f276666da..bb5ff9554d 100644 --- a/pkg/imager/profile/profile.go +++ b/pkg/imager/profile/profile.go @@ -100,6 +100,10 @@ func (p *Profile) Validate() error { // cmdline supports all kinds of customization case OutKindImage: // Image supports all kinds of customization + if p.Output.ImageOptions == nil { + return errors.New("image options are required for image output") + } + if p.Output.ImageOptions.DiskSize == 0 { return errors.New("disk size is required for image output") } diff --git a/pkg/machinery/extensions/extensions_test.go b/pkg/machinery/extensions/extensions_test.go index 91e0842573..e4fe864b72 100644 --- a/pkg/machinery/extensions/extensions_test.go +++ b/pkg/machinery/extensions/extensions_test.go @@ -27,7 +27,7 @@ func TestLoadValidate(t *testing.T) { assert.NoError(t, ext.Validate( extensions.WithValidateConstraints(), extensions.WithValidateContents(), - extensions.WithTalosVersion(version), + extensions.WithTalosVersion(&version), )) } @@ -70,7 +70,7 @@ func TestValidateFailures(t *testing.T) { err = ext.Validate( extensions.WithValidateConstraints(), extensions.WithValidateContents(), - extensions.WithTalosVersion(version), + extensions.WithTalosVersion(&version), ) assert.EqualError(t, err, tt.validateError) diff --git a/pkg/machinery/extensions/validate.go b/pkg/machinery/extensions/validate.go index d295edcc12..83d5b094e5 100644 --- a/pkg/machinery/extensions/validate.go +++ b/pkg/machinery/extensions/validate.go @@ -46,9 +46,9 @@ func WithValidateContents() ValidationOption { } // WithTalosVersion sets the Talos version to validate against. -func WithTalosVersion(version semver.Version) ValidationOption { +func WithTalosVersion(version *semver.Version) ValidationOption { return func(o *ValidationOptions) error { - o.TalosVersion = &version + o.TalosVersion = version return nil } diff --git a/pkg/machinery/imager/quirks/quirks.go b/pkg/machinery/imager/quirks/quirks.go index 8a121e9ed4..da995f3329 100644 --- a/pkg/machinery/imager/quirks/quirks.go +++ b/pkg/machinery/imager/quirks/quirks.go @@ -30,8 +30,8 @@ func New(talosVersion string) Quirks { var minVersionResetOption = semver.MustParse("1.4.0") // Version returns the Talos version. -func (q Quirks) Version() semver.Version { - return *q.v +func (q Quirks) Version() *semver.Version { + return q.v } // SupportsResetGRUBOption returns true if the Talos version supports the reset option in GRUB menu (image and ISO).