generated from hashicorp/packer-plugin-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add root_volume config and default to sbs volume type (#212)
* feat: add root_volume config and default to sbs volume type * update block cassettes * lint * wait for volumes before deletion * update simple_test * add root_volume test * update cassettes * add root_volume test * update cassettes * lint
- Loading branch information
Showing
24 changed files
with
3,576 additions
and
642 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package scaleway | ||
|
||
import ( | ||
_ "unsafe" // Import required for link | ||
|
||
"github.com/scaleway/scaleway-sdk-go/api/instance/v1" | ||
"github.com/scaleway/scaleway-sdk-go/scw" | ||
) | ||
|
||
//go:linkname createServer github.com/scaleway/scaleway-sdk-go/api/instance/v1.(*API).createServer | ||
func createServer(*instance.API, *instance.CreateServerRequest, ...scw.RequestOption) (*instance.CreateServerResponse, error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package scaleway | ||
|
||
import ( | ||
"errors" | ||
|
||
block "github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1" | ||
"github.com/scaleway/scaleway-sdk-go/api/instance/v1" | ||
"github.com/scaleway/scaleway-sdk-go/scw" | ||
) | ||
|
||
// IsConfigured returns true if root volume has been manually configured. | ||
// If true, the volume template should be used when creating the server. | ||
func (c *ConfigRootVolume) IsConfigured() bool { | ||
return c.Type != "" || c.IOPS != nil || c.SizeInGB != 0 | ||
} | ||
|
||
// VolumeServerTemplate returns the template to create the volume in a CreateServerRequest | ||
func (c *ConfigRootVolume) VolumeServerTemplate() *instance.VolumeServerTemplate { | ||
tmpl := &instance.VolumeServerTemplate{} | ||
|
||
if c.Type != "" { | ||
tmpl.VolumeType = instance.VolumeVolumeType(c.Type) | ||
} else { | ||
tmpl.VolumeType = instance.VolumeVolumeTypeSbsVolume | ||
} | ||
|
||
if c.SizeInGB > 0 { | ||
tmpl.Size = scw.SizePtr(scw.Size(c.SizeInGB) * scw.GB) | ||
} | ||
|
||
return tmpl | ||
} | ||
|
||
func (c *ConfigRootVolume) PostServerCreationSetup(blockAPI *block.API, server *instance.Server) error { | ||
if c.IOPS != nil { | ||
rootVolume, exists := server.Volumes["0"] | ||
if !exists { | ||
return errors.New("root volume not found") | ||
} | ||
_, err := blockAPI.UpdateVolume(&block.UpdateVolumeRequest{ | ||
Zone: rootVolume.Zone, | ||
VolumeID: rootVolume.ID, | ||
PerfIops: c.IOPS, | ||
}) | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
docs-partials/builder/scaleway/ConfigRootVolume-not-required.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!-- Code generated from the comments of the ConfigRootVolume struct in builder/scaleway/config.go; DO NOT EDIT MANUALLY --> | ||
|
||
- `type` (string) - The type of the root volume | ||
|
||
- `iops` (\*uint32) - IOPS of the root volume if using SBS, will only affect runtime. Image's volumes cannot have a configured IOPS. | ||
|
||
- `size_in_gb` (uint64) - Size of the root volume | ||
|
||
<!-- End of code generated from the comments of the ConfigRootVolume struct in builder/scaleway/config.go; --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package checks | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/scaleway/packer-plugin-scaleway/internal/tester" | ||
block "github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1" | ||
"github.com/scaleway/scaleway-sdk-go/scw" | ||
) | ||
|
||
type BlockSnapshotCheck struct { | ||
zone scw.Zone | ||
snapshotID *string | ||
|
||
size *scw.Size | ||
} | ||
|
||
func (c *BlockSnapshotCheck) SizeInGB(size uint64) *BlockSnapshotCheck { | ||
c.size = scw.SizePtr(scw.Size(size) * scw.GB) | ||
|
||
return c | ||
} | ||
|
||
func (c *BlockSnapshotCheck) Check(ctx context.Context) error { | ||
testCtx := tester.ExtractCtx(ctx) | ||
api := block.NewAPI(testCtx.ScwClient) | ||
|
||
if c.snapshotID == nil { | ||
return errors.New("snapshot ID is required") | ||
} | ||
|
||
snapshot, err := api.GetSnapshot(&block.GetSnapshotRequest{ | ||
Zone: c.zone, | ||
SnapshotID: *c.snapshotID, | ||
}) | ||
if err != nil { | ||
return fmt.Errorf("error getting snapshot %s: %w", *c.snapshotID, err) | ||
} | ||
|
||
if c.size != nil && snapshot.Size != *c.size { | ||
return fmt.Errorf("snapshot size %d does not match expected size %d", snapshot.Size, *c.size) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// BlockSnapshot returns an empty check, to be passed to another check to fill ID and zone | ||
func BlockSnapshot() *BlockSnapshotCheck { | ||
return &BlockSnapshotCheck{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.