From 263c581678656f5b9a0d02ff3827ffb18ec5d4f0 Mon Sep 17 00:00:00 2001 From: joshsiv-mulga Date: Sun, 11 Oct 2026 13:00:20 +1000 Subject: [PATCH] refactor: move system-image promotion to domains/ec2/image Move images_promote.go and its tests from admin to domains/ec2/image: SystemOwnerAlias, PromoteImageOpts/PromoteImageResult, PromoteSystemImage, GetAMIMetadata and the private snapshot reader. Storage, ordering, errors and promotion behaviour are unchanged; the daemon, gateway/spx and operator CLI callers import ec2image. admin now holds only account IDs and key generators. --- spinifex/admin/accounts.go | 4 ++-- spinifex/daemon/daemon_handlers_image.go | 5 ++--- .../{admin => domains/ec2/image}/images_promote.go | 2 +- .../ec2/image}/images_promote_test.go | 2 +- spinifex/gateway/spx/promote_image.go | 8 ++++---- spinifex/operator/cli/admin.go | 11 ++++++----- 6 files changed, 16 insertions(+), 16 deletions(-) rename spinifex/{admin => domains/ec2/image}/images_promote.go (99%) rename spinifex/{admin => domains/ec2/image}/images_promote_test.go (99%) diff --git a/spinifex/admin/accounts.go b/spinifex/admin/accounts.go index a67135bc3..d6f6a47ce 100644 --- a/spinifex/admin/accounts.go +++ b/spinifex/admin/accounts.go @@ -1,6 +1,6 @@ // Package admin holds what non-operator code still needs from the former admin -// package: default account identifiers and AWS credential generators (awaiting -// IAM owners) and system-image promotion (awaiting domains/ec2/image). +// package: default account identifiers and AWS credential generators, +// awaiting IAM owners. package admin import ( diff --git a/spinifex/daemon/daemon_handlers_image.go b/spinifex/daemon/daemon_handlers_image.go index 181828520..fe43e6b7d 100644 --- a/spinifex/daemon/daemon_handlers_image.go +++ b/spinifex/daemon/daemon_handlers_image.go @@ -7,7 +7,6 @@ import ( "log/slog" "github.com/aws/aws-sdk-go/service/ec2" - "github.com/mulgadc/spinifex/spinifex/admin" ec2image "github.com/mulgadc/spinifex/spinifex/domains/ec2/image" "github.com/mulgadc/spinifex/spinifex/foundation/aws/errors" "github.com/mulgadc/spinifex/spinifex/providers/objectstore" @@ -16,14 +15,14 @@ import ( ) func (d *Daemon) handleSpinifexPromoteImage(msg *nats.Msg) string { - promoteImage := func(_ context.Context, input *admin.PromoteImageOpts, _ string) (*admin.PromoteImageResult, error) { + promoteImage := func(_ context.Context, input *ec2image.PromoteImageOpts, _ string) (*ec2image.PromoteImageResult, error) { store := objectstore.NewS3ObjectStoreFromConfig( netaddr.DialTarget(d.config.Predastore.Host), d.config.Predastore.Region, d.config.Predastore.AccessKey, d.config.Predastore.SecretKey, ) - return admin.PromoteSystemImage(store, d.config.Predastore.Bucket, *input) + return ec2image.PromoteSystemImage(store, d.config.Predastore.Bucket, *input) } return handleNATSRequest(d.node, promoteImage)(msg) } diff --git a/spinifex/admin/images_promote.go b/spinifex/domains/ec2/image/images_promote.go similarity index 99% rename from spinifex/admin/images_promote.go rename to spinifex/domains/ec2/image/images_promote.go index 128c6c98b..acf0463b2 100644 --- a/spinifex/admin/images_promote.go +++ b/spinifex/domains/ec2/image/images_promote.go @@ -1,4 +1,4 @@ -package admin +package image import ( "context" diff --git a/spinifex/admin/images_promote_test.go b/spinifex/domains/ec2/image/images_promote_test.go similarity index 99% rename from spinifex/admin/images_promote_test.go rename to spinifex/domains/ec2/image/images_promote_test.go index 13f96a255..f671378a7 100644 --- a/spinifex/admin/images_promote_test.go +++ b/spinifex/domains/ec2/image/images_promote_test.go @@ -1,4 +1,4 @@ -package admin +package image import ( "bytes" diff --git a/spinifex/gateway/spx/promote_image.go b/spinifex/gateway/spx/promote_image.go index 717e51054..0ed041715 100644 --- a/spinifex/gateway/spx/promote_image.go +++ b/spinifex/gateway/spx/promote_image.go @@ -5,12 +5,12 @@ import ( "github.com/mulgadc/spinifex/spinifex/foundation/messaging/nats" "time" - "github.com/mulgadc/spinifex/spinifex/admin" + ec2image "github.com/mulgadc/spinifex/spinifex/domains/ec2/image" "github.com/nats-io/nats.go" ) // PromoteImage publishes a promotion request to the spinifex.image.promote NATS -// topic and waits for the daemon to call admin.PromoteSystemImage and reply. -func PromoteImage(ctx context.Context, nc *nats.Conn, imageID, accountID string) (*admin.PromoteImageResult, error) { - return natsmsg.NATSRequest[admin.PromoteImageResult](ctx, nc, "spinifex.image.promote", admin.PromoteImageOpts{ImageID: imageID}, 30*time.Second, accountID) +// topic and waits for the daemon to call ec2image.PromoteSystemImage and reply. +func PromoteImage(ctx context.Context, nc *nats.Conn, imageID, accountID string) (*ec2image.PromoteImageResult, error) { + return natsmsg.NATSRequest[ec2image.PromoteImageResult](ctx, nc, "spinifex.image.promote", ec2image.PromoteImageOpts{ImageID: imageID}, 30*time.Second, accountID) } diff --git a/spinifex/operator/cli/admin.go b/spinifex/operator/cli/admin.go index 5fe7032b6..2fd9bf238 100644 --- a/spinifex/operator/cli/admin.go +++ b/spinifex/operator/cli/admin.go @@ -32,6 +32,7 @@ import ( legacyadmin "github.com/mulgadc/spinifex/spinifex/admin" "github.com/mulgadc/spinifex/spinifex/bootstrap/config" "github.com/mulgadc/spinifex/spinifex/domains/ec2/ebs/metadata" + ec2image "github.com/mulgadc/spinifex/spinifex/domains/ec2/image" ec2vpc "github.com/mulgadc/spinifex/spinifex/domains/ec2/vpc" "github.com/mulgadc/spinifex/spinifex/domains/network/host" awsidentifiers "github.com/mulgadc/spinifex/spinifex/foundation/aws/identifiers" @@ -1122,7 +1123,7 @@ func runimagesPromoteCmd(cmd *cobra.Command, args []string) { bucket := node.Predastore.Bucket // Read current metadata for the confirmation prompt. - meta, err := legacyadmin.GetAMIMetadata(store, bucket, imageID) + meta, err := ec2image.GetAMIMetadata(store, bucket, imageID) if err != nil { fmt.Fprintln(os.Stderr, "Failed to inspect AMI:", err) os.Exit(1) @@ -1133,7 +1134,7 @@ func runimagesPromoteCmd(cmd *cobra.Command, args []string) { fmt.Printf(" Image ID: %s\n", imageID) fmt.Printf(" Name: %s\n", meta.Name) fmt.Printf(" Current owner: %s\n", meta.ImageOwnerAlias) - fmt.Printf(" New owner: %s\n", legacyadmin.SystemOwnerAlias) + fmt.Printf(" New owner: %s\n", ec2image.SystemOwnerAlias) if !meta.CreationDate.IsZero() { fmt.Printf(" Created: %s\n", meta.CreationDate.UTC().Format("2006-01-02T15:04:05Z")) } @@ -1150,12 +1151,12 @@ func runimagesPromoteCmd(cmd *cobra.Command, args []string) { } } - if _, err := legacyadmin.PromoteSystemImage(store, bucket, legacyadmin.PromoteImageOpts{ImageID: imageID}); err != nil { + if _, err := ec2image.PromoteSystemImage(store, bucket, ec2image.PromoteImageOpts{ImageID: imageID}); err != nil { fmt.Fprintln(os.Stderr, "Promote failed:", err) os.Exit(1) } - fmt.Printf("✅ Promoted %s to system image (owner: %s).\n", imageID, legacyadmin.SystemOwnerAlias) + fmt.Printf("✅ Promoted %s to system image (owner: %s).\n", imageID, ec2image.SystemOwnerAlias) } func runimagesDescribeCmd(cmd *cobra.Command, args []string) { @@ -1180,7 +1181,7 @@ func runimagesDescribeCmd(cmd *cobra.Command, args []string) { node.Predastore.SecretKey, ) - meta, err := legacyadmin.GetAMIMetadata(store, node.Predastore.Bucket, imageID) + meta, err := ec2image.GetAMIMetadata(store, node.Predastore.Bucket, imageID) if err != nil { fmt.Fprintln(os.Stderr, "Failed to describe AMI:", err) os.Exit(1)