Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,35 @@

jobs:
test:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Tidy
run: go mod tidy && git diff --exit-code

- name: Install dependencies
run: go install github.com/vektra/mockery/v2@v2.43.2

- name: Generate
run: go generate ./... && git diff --exit-code

- name: Build
run: go build -o=/dev/null ./cmd/...

- name: Lint
uses: golangci/golangci-lint-action@v5.0.0
with:
args: --timeout 3m

- name: Run tests
run: go test -race -shuffle=on -v ./...
run: go test -race -shuffle=on -v ./...
Comment thread
seukyaso marked this conversation as resolved.
1 change: 1 addition & 0 deletions pkg/diskapi/diskapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type CreateDiskRequest struct {
ZoneID string
TypeID string
Size int64
BlockSize int64
SnapshotID string
DiskPlacementPolicy *DiskPlacementPolicy
KMSKeyID string
Expand Down
1 change: 1 addition & 0 deletions pkg/diskapi/public/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func (d *publicDiskAPI) CreateDisk(ctx context.Context, req *diskapi.CreateDiskR
Name: req.Name,
Labels: labels,
Size: req.Size,
BlockSize: req.BlockSize,
DiskPlacementPolicy: convertDiskPlacementPolicyToComputeAPI(req.DiskPlacementPolicy),
KmsKeyId: req.KMSKeyID,
},
Expand Down
92 changes: 50 additions & 42 deletions pkg/diskapi/public/public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,28 @@ import (
)

const (
zoneID = "ru-central1-a"
diskName = "NewVolume"
diskTypeID = "mytype"
instanceID = "NewInstance"
kmsKeyID = "kms-key-id"
defaultDiskSizeBytes = 4 * 1024 * 1024 * 1024
zoneID = "ru-central1-a"
diskName = "NewVolume"
diskTypeID = "mytype"
instanceID = "NewInstance"
kmsKeyID = "kms-key-id"
defaultDiskSizeBytes = 4 * 1024 * 1024 * 1024
defaultBlockSizeBytes = 4 * 1024
)

type testResources struct {
t *testing.T
folderID string
networkFolderID string
clusterFolderID string
networkID string
zoneID string
diskTypeID string
diskName string
testData *testData
defaultDiskSizeBytes int64
kmsKeyID string
t *testing.T
folderID string
networkFolderID string
clusterFolderID string
networkID string
zoneID string
diskTypeID string
diskName string
testData *testData
defaultDiskSizeBytes int64
defaultBlockSizeBytes int64
kmsKeyID string
}

type controllerTest struct {
Expand All @@ -76,11 +78,12 @@ func TestCreateDisk(t *testing.T) {
disk, err := test.diskapi.CreateDisk(
context.Background(),
&diskapi.CreateDiskRequest{
Name: test.cloudRes.diskName,
ZoneID: test.cloudRes.zoneID,
TypeID: test.cloudRes.diskTypeID,
Size: test.cloudRes.defaultDiskSizeBytes,
KMSKeyID: test.cloudRes.kmsKeyID,
Name: test.cloudRes.diskName,
ZoneID: test.cloudRes.zoneID,
TypeID: test.cloudRes.diskTypeID,
Size: test.cloudRes.defaultDiskSizeBytes,
BlockSize: test.cloudRes.defaultBlockSizeBytes,
KMSKeyID: test.cloudRes.kmsKeyID,
})
require.NoError(t, err)
assert.Equal(t, disk.Name, test.cloudRes.diskName)
Expand All @@ -92,10 +95,11 @@ func TestExpandDisk(t *testing.T) {
disk, err := test.diskapi.CreateDisk(
context.Background(),
&diskapi.CreateDiskRequest{
Name: test.cloudRes.diskName,
ZoneID: test.cloudRes.zoneID,
TypeID: test.cloudRes.diskTypeID,
Size: test.cloudRes.defaultDiskSizeBytes,
Name: test.cloudRes.diskName,
ZoneID: test.cloudRes.zoneID,
TypeID: test.cloudRes.diskTypeID,
Size: test.cloudRes.defaultDiskSizeBytes,
BlockSize: test.cloudRes.defaultBlockSizeBytes,
})
require.NoError(t, err)
newSize := disk.Size + 4*1024*1024*1024
Expand Down Expand Up @@ -127,10 +131,11 @@ func TestDeleteDisk(t *testing.T) {
disk, err := test.diskapi.CreateDisk(
context.Background(),
&diskapi.CreateDiskRequest{
Name: test.cloudRes.diskName,
ZoneID: test.cloudRes.zoneID,
TypeID: test.cloudRes.diskTypeID,
Size: test.cloudRes.defaultDiskSizeBytes,
Name: test.cloudRes.diskName,
ZoneID: test.cloudRes.zoneID,
TypeID: test.cloudRes.diskTypeID,
Size: test.cloudRes.defaultDiskSizeBytes,
BlockSize: test.cloudRes.defaultBlockSizeBytes,
})
require.NoError(t, err)

Expand Down Expand Up @@ -168,10 +173,11 @@ func TestGetDisk(t *testing.T) {
disk, err := test.diskapi.CreateDisk(
context.Background(),
&diskapi.CreateDiskRequest{
Name: test.cloudRes.diskName,
ZoneID: test.cloudRes.zoneID,
TypeID: test.cloudRes.diskTypeID,
Size: test.cloudRes.defaultDiskSizeBytes,
Name: test.cloudRes.diskName,
ZoneID: test.cloudRes.zoneID,
TypeID: test.cloudRes.diskTypeID,
Size: test.cloudRes.defaultDiskSizeBytes,
BlockSize: test.cloudRes.defaultBlockSizeBytes,
})
require.NoError(t, err)

Expand Down Expand Up @@ -201,10 +207,11 @@ func TestGetDiskByName(t *testing.T) {
disk, err := test.diskapi.CreateDisk(
context.Background(),
&diskapi.CreateDiskRequest{
Name: test.cloudRes.diskName,
ZoneID: test.cloudRes.zoneID,
TypeID: test.cloudRes.diskTypeID,
Size: test.cloudRes.defaultDiskSizeBytes,
Name: test.cloudRes.diskName,
ZoneID: test.cloudRes.zoneID,
TypeID: test.cloudRes.diskTypeID,
Size: test.cloudRes.defaultDiskSizeBytes,
BlockSize: test.cloudRes.defaultBlockSizeBytes,
})

require.NoError(t, err)
Expand All @@ -225,10 +232,11 @@ func TestListDisks(t *testing.T) {
disk, err := test.diskapi.CreateDisk(
context.Background(),
&diskapi.CreateDiskRequest{
Name: test.cloudRes.diskName,
ZoneID: test.cloudRes.zoneID,
TypeID: test.cloudRes.diskTypeID,
Size: test.cloudRes.defaultDiskSizeBytes,
Name: test.cloudRes.diskName,
ZoneID: test.cloudRes.zoneID,
TypeID: test.cloudRes.diskTypeID,
Size: test.cloudRes.defaultDiskSizeBytes,
BlockSize: test.cloudRes.defaultBlockSizeBytes,
})
require.NoError(t, err)

Expand Down
2 changes: 2 additions & 0 deletions pkg/services/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const (
DiskPlacementGroupPartitionKey = "diskPlacementGroupPartition"

KMSKeyIDKey = "kmsKeyId"

BlockSizeKey = "blockSize"
)

var (
Expand Down
11 changes: 11 additions & 0 deletions pkg/services/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,17 @@ func (c *controller) createNewVolume(

diskAPIRequest.TypeID = volumeTypeID

blockSizeStr := parameters[services.BlockSizeKey]
if blockSizeStr != "" {
Comment thread
seukyaso marked this conversation as resolved.
blockSize, err := strconv.ParseInt(blockSizeStr, 10, 64)
if err != nil {
return nil, fmt.Errorf("failed to parse blockSize: %w", err)
}
diskAPIRequest.BlockSize = blockSize
}

klog.Infof("blockSize: %d", diskAPIRequest.BlockSize)

size, err := getVolumeSize(req.GetCapacityRange())
if err != nil {
return nil, err
Expand Down
Loading