Skip to content

Commit

Permalink
move ECS inteface to its own package
Browse files Browse the repository at this point in the history
this maybe used by multiple drivers
  • Loading branch information
huww98 committed Sep 25, 2023
1 parent 5f5dfe6 commit 4b23ffc
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ build-nas:
build-disk:
./build/build-disk.sh "" $(REPONAME)

pkg/disk/ecsmock.go: pkg/disk/ecsinterface.go
mockgen -source pkg/disk/ecsinterface.go -destination $@ -package disk
pkg/cloud/ecsmock.go: pkg/cloud/ecsinterface.go
mockgen -source pkg/cloud/ecsinterface.go -destination $@ -package cloud
2 changes: 1 addition & 1 deletion pkg/disk/ecsinterface.go → pkg/cloud/ecsinterface.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package disk
package cloud

import "github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"

Expand Down
6 changes: 3 additions & 3 deletions pkg/disk/ecsmock.go → pkg/cloud/ecsmock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/disk/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
alicloudErr "github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/cloud"
log "github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/log"
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/utils"
perrors "github.com/pkg/errors"
Expand Down Expand Up @@ -1050,7 +1051,7 @@ func IsDiskCreatedByCsi(disk ecs.Disk) bool {
return false
}

func deleteDisk(ecsClient ECSInterface, diskId string) (*ecs.DeleteDiskResponse, error) {
func deleteDisk(ecsClient cloud.ECSInterface, diskId string) (*ecs.DeleteDiskResponse, error) {
deleteDiskRequest := ecs.CreateDeleteDiskRequest()
deleteDiskRequest.DiskId = diskId

Expand Down
7 changes: 4 additions & 3 deletions pkg/disk/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
alicloudErr "github.com/aliyun/alibaba-cloud-sdk-go/sdk/errors"
"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
gomock "github.com/golang/mock/gomock"
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/cloud"
csilog "github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/log"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
Expand All @@ -23,7 +24,7 @@ func init() {

func TestDeleteDisk(t *testing.T) {
ctrl := gomock.NewController(t)
c := NewMockECSInterface(ctrl)
c := cloud.NewMockECSInterface(ctrl)

c.EXPECT().DeleteDisk(gomock.Any()).Return(deleteDiskResponse, nil)

Expand All @@ -33,7 +34,7 @@ func TestDeleteDisk(t *testing.T) {

func TestDeleteDiskRetryOnInitError(t *testing.T) {
ctrl := gomock.NewController(t)
c := NewMockECSInterface(ctrl)
c := cloud.NewMockECSInterface(ctrl)

initErr := alicloudErr.NewServerError(400, `{"Code": "IncorrectDiskStatus.Initializing"}`, "")
c.EXPECT().DeleteDisk(gomock.Any()).Return(nil, initErr)
Expand All @@ -45,7 +46,7 @@ func TestDeleteDiskRetryOnInitError(t *testing.T) {

func TestDeleteDiskPassthroughError(t *testing.T) {
ctrl := gomock.NewController(t)
c := NewMockECSInterface(ctrl)
c := cloud.NewMockECSInterface(ctrl)

serverErr := alicloudErr.NewServerError(400, `{"Code": "AnyOtherErrors"}`, "")
c.EXPECT().DeleteDisk(gomock.Any()).Return(nil, serverErr)
Expand Down
5 changes: 3 additions & 2 deletions pkg/disk/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
"github.com/golang/protobuf/ptypes/timestamp"
volumeSnapshotV1 "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
snapClientset "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned"
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/cloud"
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/common"
proto "github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/disk/proto"
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/utils"
Expand Down Expand Up @@ -1170,7 +1171,7 @@ func getBlockDeviceCapacity(devicePath string) float64 {
return float64(pos) / GBSIZE
}

func GetAvailableDiskTypes(ctx context.Context, c ECSInterface, instanceType, zoneID string) (types []string, err error) {
func GetAvailableDiskTypes(ctx context.Context, c cloud.ECSInterface, instanceType, zoneID string) (types []string, err error) {
request := ecs.CreateDescribeAvailableResourceRequest()
request.InstanceType = instanceType
request.DestinationResource = describeResourceType
Expand Down Expand Up @@ -1217,7 +1218,7 @@ func GetAvailableDiskTypes(ctx context.Context, c ECSInterface, instanceType, zo
}

// Retries for at most 1 hour if ECS OpenAPI or k8s API server is unavailable
func UpdateNode(nodes corev1.NodeInterface, c ECSInterface, maxDiskCount int64) {
func UpdateNode(nodes corev1.NodeInterface, c cloud.ECSInterface, maxDiskCount int64) {
ctx, cancel := context.WithTimeout(context.Background(), UpdateNodeTimeout)
defer cancel()
nodeName := os.Getenv(kubeNodeName)
Expand Down
3 changes: 2 additions & 1 deletion pkg/disk/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
gomock "github.com/golang/mock/gomock"
fakesnapshotv1 "github.com/kubernetes-csi/external-snapshotter/client/v4/clientset/versioned/fake"
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/cloud"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -307,7 +308,7 @@ func TestUpdateNode(t *testing.T) {
nodes := clientset.CoreV1().Nodes()

ctrl := gomock.NewController(t)
c := NewMockECSInterface(ctrl)
c := cloud.NewMockECSInterface(ctrl)

if !test.skipDiskLabel {
if test.retryECS {
Expand Down

0 comments on commit 4b23ffc

Please sign in to comment.