Skip to content

Commit 9bbcf49

Browse files
Added support for Block Storage Encryption (#572)
* Added support for Block Storage Encryption * Added instance test * Addressed PR comments * Added LA note
1 parent 7ea8057 commit 9bbcf49

10 files changed

+1978
-5
lines changed

instances.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ type Instance struct {
6767
// NOTE: Disk encryption may not currently be available to all users.
6868
DiskEncryption InstanceDiskEncryption `json:"disk_encryption"`
6969

70-
LKEClusterID int `json:"lke_cluster_id"`
70+
LKEClusterID int `json:"lke_cluster_id"`
71+
Capabilities []string `json:"capabilities"`
7172
}
7273

7374
// InstanceSpec represents a linode spec

regions.go

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const (
3535
CapabilityBackups string = "Backups"
3636
CapabilityPlacementGroup string = "Placement Group"
3737
CapabilityDiskEncryption string = "Disk Encryption"
38+
CapabilityBlockStorageEncryption string = "Block Storage Encryption"
3839
)
3940

4041
// Region-related endpoints have a custom expiry time as the

test/integration/fixtures/TestInstance_withBlockStorageEncryption.yaml

+468
Large diffs are not rendered by default.

test/integration/fixtures/TestRegions_blockStorageEncryption.yaml

+336
Large diffs are not rendered by default.

test/integration/fixtures/TestVolume_Create_withEncryption.yaml

+462
Large diffs are not rendered by default.

test/integration/fixtures/TestVolume_Get_withEncryption.yaml

+594
Large diffs are not rendered by default.

test/integration/instances_test.go

+21-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ package integration
33
import (
44
"context"
55
"encoding/base64"
6+
"github.com/linode/linodego"
7+
"github.com/stretchr/testify/require"
8+
"slices"
69
"strconv"
710
"testing"
8-
9-
"github.com/stretchr/testify/require"
10-
11-
"github.com/linode/linodego"
1211
)
1312

1413
type instanceModifier func(*linodego.Client, *linodego.InstanceCreateOptions)
@@ -561,6 +560,24 @@ func TestInstance_DiskEncryption(t *testing.T) {
561560
}
562561
}
563562

563+
func TestInstance_withBlockStorageEncryption(t *testing.T) {
564+
client, clientTeardown := createTestClient(t, "fixtures/TestInstance_withBlockStorageEncryption")
565+
566+
inst, err := createInstance(t, client, true, func(client *linodego.Client, options *linodego.InstanceCreateOptions) {
567+
options.Region = getRegionsWithCaps(t, client, []string{"Linodes", "Block Storage Encryption"})[0]
568+
options.Label = "go-inst-test-create-bde"
569+
})
570+
require.NoError(t, err)
571+
572+
defer func() {
573+
client.DeleteInstance(context.Background(), inst.ID)
574+
clientTeardown()
575+
}()
576+
577+
// Filtering is not currently supported on capabilities
578+
require.True(t, slices.Contains(inst.Capabilities, "Block Storage Encryption"))
579+
}
580+
564581
func TestInstance_withPG(t *testing.T) {
565582
client, clientTeardown := createTestClient(t, "fixtures/TestInstance_withPG")
566583

test/integration/regions_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,17 @@ func TestRegions_pgLimits(t *testing.T) {
4545
require.NotZero(t, region.PlacementGroupLimits.MaximumLinodesPerPG)
4646
require.NotZero(t, region.PlacementGroupLimits.MaximumPGsPerCustomer)
4747
}
48+
49+
func TestRegions_blockStorageEncryption(t *testing.T) {
50+
client, teardown := createTestClient(t, "fixtures/TestRegions_blockStorageEncryption")
51+
defer teardown()
52+
53+
regions, err := client.ListRegions(context.Background(), nil)
54+
require.NoError(t, err)
55+
56+
// Filtering is not currently supported on capabilities
57+
regionIdx := slices.IndexFunc(regions, func(region linodego.Region) bool {
58+
return slices.Contains(region.Capabilities, "Block Storage Encryption")
59+
})
60+
require.NotZero(t, regionIdx)
61+
}

test/integration/volumes_test.go

+76
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,33 @@ func TestVolume_Create_smoke(t *testing.T) {
3636
}
3737
}
3838

39+
func TestVolume_Create_withEncryption(t *testing.T) {
40+
client, teardown := createTestClient(t, "fixtures/TestVolume_Create_withEncryption")
41+
defer teardown()
42+
43+
createOpts := linodego.VolumeCreateOptions{
44+
Label: "go-vol-test-create-encryption",
45+
Region: getRegionsWithCaps(t, client, []string{"Linodes", "Block Storage Encryption"})[0],
46+
Encryption: "enabled",
47+
}
48+
volume, err := client.CreateVolume(context.Background(), createOpts)
49+
if err != nil {
50+
t.Errorf("Error listing volumes, expected struct, got error %v", err)
51+
}
52+
if volume.ID == 0 {
53+
t.Errorf("Expected a volumes id, but got 0")
54+
}
55+
56+
assertDateSet(t, volume.Created)
57+
assertDateSet(t, volume.Updated)
58+
59+
// volumes deleted too fast tend to stick, adding a few seconds to catch up
60+
time.Sleep(time.Second * 5)
61+
if err := client.DeleteVolume(context.Background(), volume.ID); err != nil {
62+
t.Errorf("Expected to delete a volume, but got %v", err)
63+
}
64+
}
65+
3966
func TestVolume_Resize(t *testing.T) {
4067
client, volume, teardown, err := setupVolume(t, "fixtures/TestVolume_Resize")
4168
defer teardown()
@@ -88,6 +115,55 @@ func TestVolume_Get(t *testing.T) {
88115
assertDateSet(t, volume.Updated)
89116
}
90117

118+
func TestVolume_Get_withEncryption(t *testing.T) {
119+
client, teardown := createTestClient(t, "fixtures/TestVolume_Get_withEncryption")
120+
defer teardown()
121+
122+
createOpts := linodego.VolumeCreateOptions{
123+
Label: "go-vol-test-get-encryption",
124+
Region: getRegionsWithCaps(t, client, []string{"Linodes", "Block Storage Encryption"})[0],
125+
Encryption: "enabled",
126+
}
127+
volume, err := client.CreateVolume(context.Background(), createOpts)
128+
if err != nil {
129+
t.Errorf("Error listing volumes, expected struct, got error %v", err)
130+
}
131+
if volume.ID == 0 {
132+
t.Errorf("Expected a volumes id, but got 0")
133+
}
134+
135+
returnedVolume, err := client.GetVolume(context.Background(), volume.ID)
136+
if err != nil {
137+
t.Errorf("Error getting volume %d, expected *LinodeVolume, got error %v", volume.ID, err)
138+
}
139+
if returnedVolume.Encryption != "enabled" {
140+
t.Errorf("Expected volume encryption to be enabled, but got %v", returnedVolume.Encryption)
141+
}
142+
143+
volumes, err := client.ListVolumes(context.Background(), nil)
144+
if err != nil {
145+
t.Errorf("Error listing volumes, expected struct, got error %v", err)
146+
}
147+
found := false
148+
for _, v := range volumes {
149+
if v.ID == volume.ID {
150+
found = true
151+
if v.Encryption != "enabled" {
152+
t.Errorf("Expected volume encryption to be enabled, but got %v", v.Encryption)
153+
}
154+
}
155+
}
156+
if !found {
157+
t.Errorf("%d volume not found in list", volume.ID)
158+
}
159+
160+
// volumes deleted too fast tend to stick, adding a few seconds to catch up
161+
time.Sleep(time.Second * 5)
162+
if err := client.DeleteVolume(context.Background(), volume.ID); err != nil {
163+
t.Errorf("Expected to delete a volume, but got %v", err)
164+
}
165+
}
166+
91167
func TestVolume_WaitForLinodeID_nil(t *testing.T) {
92168
client, volume, teardown, err := setupVolume(t, "fixtures/TestVolume_WaitForLinodeID_nil")
93169
defer teardown()

volumes.go

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ type Volume struct {
3737
Tags []string `json:"tags"`
3838
Created *time.Time `json:"-"`
3939
Updated *time.Time `json:"-"`
40+
41+
// Note: Block Storage Disk Encryption is not currently available to all users.
42+
Encryption string `json:"encryption"`
4043
}
4144

4245
// VolumeCreateOptions fields are those accepted by CreateVolume
@@ -50,6 +53,7 @@ type VolumeCreateOptions struct {
5053
// An array of tags applied to this object. Tags are for organizational purposes only.
5154
Tags []string `json:"tags"`
5255
PersistAcrossBoots *bool `json:"persist_across_boots,omitempty"`
56+
Encryption string `json:"encryption,omitempty"`
5357
}
5458

5559
// VolumeUpdateOptions fields are those accepted by UpdateVolume

0 commit comments

Comments
 (0)