refactor: move EC2 volume action adapters to domains/ec2/awsapi

This commit is contained in:
joshsiv-mulga
2026-10-07 14:36:36 +10:00
parent 8b106e7966
commit 7ee808d2d9
20 changed files with 33 additions and 33 deletions
+4 -4
View File
@@ -19,10 +19,10 @@ import (
ec2placementgroupapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/placementgroup"
ec2routetableapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/routetable"
ec2snapshotapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/snapshot"
ec2volumeapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/volume"
ec2vpcapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/vpc"
"github.com/mulgadc/spinifex/spinifex/foundation/aws/errors"
gateway_ec2_instance "github.com/mulgadc/spinifex/spinifex/gateway/ec2/instance"
gateway_ec2_volume "github.com/mulgadc/spinifex/spinifex/gateway/ec2/volume"
"github.com/nats-io/nats.go"
)
@@ -117,7 +117,7 @@ func (r *volumeReaper) Kind() string { return "volume" }
func (r *volumeReaper) Stage() Stage { return StageStorage }
func (r *volumeReaper) List(ctx context.Context, accountID string) ([]Resource, error) {
out, err := gateway_ec2_volume.DescribeVolumes(ctx, &ec2.DescribeVolumesInput{}, r.nc, accountID)
out, err := ec2volumeapi.DescribeVolumes(ctx, &ec2.DescribeVolumesInput{}, r.nc, accountID)
if err != nil {
return nil, err
}
@@ -142,7 +142,7 @@ func (r *volumeReaper) List(ctx context.Context, accountID string) ([]Resource,
}
func (r *volumeReaper) Delete(ctx context.Context, accountID string, resource Resource, force bool) error {
_, err := gateway_ec2_volume.DeleteVolume(ctx, &ec2.DeleteVolumeInput{
_, err := ec2volumeapi.DeleteVolume(ctx, &ec2.DeleteVolumeInput{
VolumeId: aws.String(resource.ID),
}, r.nc, r.expectedNodes, accountID)
if isAlreadyGone(err) {
@@ -707,7 +707,7 @@ func forceDeleteVolume(ctx context.Context, nc *nats.Conn, expectedNodes int, ac
return fmt.Errorf("force detach %s: %w", volumeID, err)
}
_, err = gateway_ec2_volume.DeleteVolume(ctx, &ec2.DeleteVolumeInput{
_, err = ec2volumeapi.DeleteVolume(ctx, &ec2.DeleteVolumeInput{
VolumeId: aws.String(volumeID),
}, nc, expectedNodes, accountID)
return ignoreAlreadyGone(err)
@@ -1,4 +1,4 @@
package gateway_ec2_volume
package volume
import (
"context"
@@ -1,4 +1,4 @@
package gateway_ec2_volume
package volume
import (
"testing"
@@ -1,4 +1,4 @@
package gateway_ec2_volume
package volume
import (
"context"
@@ -1,4 +1,4 @@
package gateway_ec2_volume
package volume
import (
"testing"
@@ -1,4 +1,4 @@
package gateway_ec2_volume
package volume
import (
"context"
@@ -1,4 +1,4 @@
package gateway_ec2_volume
package volume
import (
"testing"
@@ -1,4 +1,4 @@
package gateway_ec2_volume
package volume
import (
"context"
@@ -1,4 +1,4 @@
package gateway_ec2_volume
package volume
import (
"context"
@@ -1,4 +1,4 @@
package gateway_ec2_volume
package volume
import (
"context"
@@ -1,4 +1,4 @@
package gateway_ec2_volume
package volume
import (
"context"
@@ -1,4 +1,4 @@
package gateway_ec2_volume
package volume
import (
"testing"
@@ -1,4 +1,4 @@
package gateway_ec2_volume
package volume
import (
"testing"
@@ -1,4 +1,4 @@
package gateway_ec2_volume
package volume
import (
"context"
@@ -1,4 +1,4 @@
package gateway_ec2_volume
package volume
import (
"context"
@@ -1,4 +1,4 @@
package gateway_ec2_volume
package volume
import (
"context"
@@ -1,4 +1,4 @@
package gateway_ec2_volume
package volume
import (
"testing"
@@ -1,4 +1,4 @@
package gateway_ec2_volume
package volume
import (
"context"
+9 -9
View File
@@ -25,6 +25,7 @@ import (
ec2placementgroupapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/placementgroup"
ec2routetableapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/routetable"
ec2snapshotapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/snapshot"
ec2volumeapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/volume"
ec2vpcapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/vpc"
ec2zoneapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/zone"
"github.com/mulgadc/spinifex/spinifex/foundation/aws/errors"
@@ -34,7 +35,6 @@ import (
gateway_ec2_instance "github.com/mulgadc/spinifex/spinifex/gateway/ec2/instance"
gateway_ec2_spotinstance "github.com/mulgadc/spinifex/spinifex/gateway/ec2/spotinstance"
gateway_ec2_tags "github.com/mulgadc/spinifex/spinifex/gateway/ec2/tags"
gateway_ec2_volume "github.com/mulgadc/spinifex/spinifex/gateway/ec2/volume"
handlers_quota "github.com/mulgadc/spinifex/spinifex/handlers/quota"
"github.com/mulgadc/spinifex/spinifex/ingress/aws/query"
"github.com/nats-io/nats.go"
@@ -336,34 +336,34 @@ var ec2Actions = map[string]ec2Action{
return ec2zoneapi.DescribeAvailabilityZones(input, gw.Region, gw.AZ)
}),
"DescribeVolumes": ec2Handler(func(ctx context.Context, input *ec2.DescribeVolumesInput, gw *GatewayConfig, accountID string) (any, error) {
return gateway_ec2_volume.DescribeVolumes(ctx, input, gw.NATSConn, accountID)
return ec2volumeapi.DescribeVolumes(ctx, input, gw.NATSConn, accountID)
}),
"ModifyVolume": ec2Handler(func(ctx context.Context, input *ec2.ModifyVolumeInput, gw *GatewayConfig, accountID string) (any, error) {
if err := gw.Quota.EnforceVolumeModify(ctx, gw.NATSConn, accountID, aws.StringValue(input.VolumeId), int(aws.Int64Value(input.Size))); err != nil {
return nil, err
}
return gateway_ec2_volume.ModifyVolume(ctx, input, gw.NATSConn, accountID)
return ec2volumeapi.ModifyVolume(ctx, input, gw.NATSConn, accountID)
}),
"CreateVolume": ec2IdempotentHandler(func(ctx context.Context, input *ec2.CreateVolumeInput, gw *GatewayConfig, accountID string) (ec2.Volume, error) {
if err := gw.Quota.EnforceVolumeCreate(ctx, gw.NATSConn, accountID, int(aws.Int64Value(input.Size))); err != nil {
return ec2.Volume{}, err
}
return gateway_ec2_volume.CreateVolume(ctx, input, gw.NATSConn, accountID)
return ec2volumeapi.CreateVolume(ctx, input, gw.NATSConn, accountID)
}),
"DeleteVolume": ec2Handler(func(ctx context.Context, input *ec2.DeleteVolumeInput, gw *GatewayConfig, accountID string) (any, error) {
return gateway_ec2_volume.DeleteVolume(ctx, input, gw.NATSConn, gw.DiscoverActiveNodes(ctx), accountID)
return ec2volumeapi.DeleteVolume(ctx, input, gw.NATSConn, gw.DiscoverActiveNodes(ctx), accountID)
}),
"AttachVolume": ec2Handler(func(ctx context.Context, input *ec2.AttachVolumeInput, gw *GatewayConfig, accountID string) (any, error) {
return gateway_ec2_volume.AttachVolume(ctx, input, gw.NATSConn, accountID)
return ec2volumeapi.AttachVolume(ctx, input, gw.NATSConn, accountID)
}),
"DescribeVolumeStatus": ec2Handler(func(ctx context.Context, input *ec2.DescribeVolumeStatusInput, gw *GatewayConfig, accountID string) (any, error) {
return gateway_ec2_volume.DescribeVolumeStatus(ctx, input, gw.NATSConn, accountID)
return ec2volumeapi.DescribeVolumeStatus(ctx, input, gw.NATSConn, accountID)
}),
"DescribeVolumesModifications": ec2Handler(func(ctx context.Context, input *ec2.DescribeVolumesModificationsInput, gw *GatewayConfig, accountID string) (any, error) {
return gateway_ec2_volume.DescribeVolumesModifications(ctx, input, gw.NATSConn, accountID)
return ec2volumeapi.DescribeVolumesModifications(ctx, input, gw.NATSConn, accountID)
}),
"DetachVolume": ec2Handler(func(ctx context.Context, input *ec2.DetachVolumeInput, gw *GatewayConfig, accountID string) (any, error) {
return gateway_ec2_volume.DetachVolume(ctx, input, gw.NATSConn, accountID)
return ec2volumeapi.DetachVolume(ctx, input, gw.NATSConn, accountID)
}),
"DescribeAccountAttributes": ec2Handler(func(ctx context.Context, input *ec2.DescribeAccountAttributesInput, gw *GatewayConfig, accountID string) (any, error) {
return ec2accountapi.DescribeAccountAttributes(input, func() (string, error) {
+3 -3
View File
@@ -4,7 +4,7 @@ import (
"context"
"github.com/aws/aws-sdk-go/service/ec2"
gateway_ec2_volume "github.com/mulgadc/spinifex/spinifex/gateway/ec2/volume"
ec2volumeapi "github.com/mulgadc/spinifex/spinifex/domains/ec2/awsapi/volume"
"github.com/nats-io/nats.go"
)
@@ -19,7 +19,7 @@ func (s *Service) EnforceVolumeCreate(ctx context.Context, natsConn *nats.Conn,
if s.Exempt(accountID) {
return nil
}
out, err := gateway_ec2_volume.DescribeVolumes(ctx, &ec2.DescribeVolumesInput{}, natsConn, accountID)
out, err := ec2volumeapi.DescribeVolumes(ctx, &ec2.DescribeVolumesInput{}, natsConn, accountID)
if err != nil {
return err
}
@@ -50,7 +50,7 @@ func (s *Service) EnforceVolumeModify(ctx context.Context, natsConn *nats.Conn,
// sweep and, when volumeID is non-empty, also returns that volume's current size
// (0 if absent). One pass serves both the create and modify checks.
func (s *Service) volumeUsage(ctx context.Context, natsConn *nats.Conn, accountID, volumeID string) (total, target int, err error) {
out, err := gateway_ec2_volume.DescribeVolumes(ctx, &ec2.DescribeVolumesInput{}, natsConn, accountID)
out, err := ec2volumeapi.DescribeVolumes(ctx, &ec2.DescribeVolumesInput{}, natsConn, accountID)
if err != nil {
return 0, 0, err
}