Skip to content

Commit 38410dc

Browse files
authored
Merge pull request #440 from yussufsh/clean
use instance storage type instead of querying for image
2 parents 4af7010 + fdfebe4 commit 38410dc

File tree

6 files changed

+16
-74
lines changed

6 files changed

+16
-74
lines changed

pkg/cloud/cloud_interface.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,5 @@ type Cloud interface {
3333
GetPVMInstanceByID(instanceID string) (instance *PVMInstance, err error)
3434
GetPVMInstanceDetails(instanceID string) (*models.PVMInstance, error)
3535
UpdateStoragePoolAffinity(instanceID string) error
36-
GetImageByID(imageID string) (image *PVMImage, err error)
3736
IsAttached(volumeID string, nodeID string) (attached bool, err error)
3837
}

pkg/cloud/mocks/mock_cloud.go

Lines changed: 0 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cloud/powervs.go

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,14 @@ type powerVSCloud struct {
5454

5555
cloudInstanceID string
5656

57-
imageClient *instance.IBMPIImageClient
5857
pvmInstancesClient *instance.IBMPIInstanceClient
5958
volClient *instance.IBMPIVolumeClient
6059
}
6160

6261
type PVMInstance struct {
63-
ID string
64-
ImageID string
65-
Name string
66-
}
67-
68-
type PVMImage struct {
6962
ID string
70-
Name string
7163
DiskType string
64+
Name string
7265
}
7366

7467
func NewPowerVSCloud(cloudInstanceID, zone string, debug bool) (Cloud, error) {
@@ -104,12 +97,10 @@ func newPowerVSCloud(cloudInstanceID, zone string, debug bool) (Cloud, error) {
10497
backgroundContext := context.Background()
10598
volClient := instance.NewIBMPIVolumeClient(backgroundContext, piSession, cloudInstanceID)
10699
pvmInstancesClient := instance.NewIBMPIInstanceClient(backgroundContext, piSession, cloudInstanceID)
107-
imageClient := instance.NewIBMPIImageClient(backgroundContext, piSession, cloudInstanceID)
108100

109101
return &powerVSCloud{
110102
piSession: piSession,
111103
cloudInstanceID: cloudInstanceID,
112-
imageClient: imageClient,
113104
pvmInstancesClient: pvmInstancesClient,
114105
volClient: volClient,
115106
}, nil
@@ -123,9 +114,9 @@ func (p *powerVSCloud) GetPVMInstanceByName(name string) (*PVMInstance, error) {
123114
for _, pvmInstance := range in.PvmInstances {
124115
if name == *pvmInstance.ServerName {
125116
return &PVMInstance{
126-
ID: *pvmInstance.PvmInstanceID,
127-
ImageID: *pvmInstance.ImageID,
128-
Name: *pvmInstance.ServerName,
117+
ID: *pvmInstance.PvmInstanceID,
118+
DiskType: pvmInstance.StorageType,
119+
Name: *pvmInstance.ServerName,
129120
}, nil
130121
}
131122
}
@@ -139,21 +130,9 @@ func (p *powerVSCloud) GetPVMInstanceByID(instanceID string) (*PVMInstance, erro
139130
}
140131

141132
return &PVMInstance{
142-
ID: *in.PvmInstanceID,
143-
ImageID: *in.ImageID,
144-
Name: *in.ServerName,
145-
}, nil
146-
}
147-
148-
func (p *powerVSCloud) GetImageByID(imageID string) (*PVMImage, error) {
149-
image, err := p.imageClient.Get(imageID)
150-
if err != nil {
151-
return nil, err
152-
}
153-
return &PVMImage{
154-
ID: *image.ImageID,
155-
Name: *image.Name,
156-
DiskType: *image.StorageType,
133+
ID: *in.PvmInstanceID,
134+
DiskType: *in.StorageType,
135+
Name: *in.ServerName,
157136
}, nil
158137
}
159138

pkg/driver/node.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -575,13 +575,9 @@ func (d *nodeService) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoReque
575575
klog.Errorf("failed to get the instance for pvmInstanceId %s, err: %s", d.pvmInstanceId, err)
576576
return nil, fmt.Errorf("failed to get the instance for pvmInstanceId %s, err: %s", d.pvmInstanceId, err)
577577
}
578-
image, err := d.cloud.GetImageByID(in.ImageID)
579-
if err != nil {
580-
return nil, fmt.Errorf("failed to get the image details for %s, err: %s", in.ImageID, err)
581-
}
582578

583579
segments := map[string]string{
584-
DiskTypeKey: image.DiskType,
580+
DiskTypeKey: in.DiskType,
585581
}
586582

587583
topology := &csi.Topology{Segments: segments}

pkg/driver/node_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,14 +1096,8 @@ func TestNodeGetInfo(t *testing.T) {
10961096
mockCloud := cloudmocks.NewMockCloud(mockCtl)
10971097

10981098
mockCloud.EXPECT().GetPVMInstanceByID(tc.instanceID).Return(&cloud.PVMInstance{
1099-
ID: tc.instanceID,
1100-
Name: tc.name,
1101-
ImageID: "test-image",
1102-
}, nil)
1103-
1104-
mockCloud.EXPECT().GetImageByID(gomock.Eq("test-image")).Return(&cloud.PVMImage{
1105-
ID: "test-image",
1106-
Name: "test-image",
1099+
ID: tc.instanceID,
1100+
Name: tc.name,
11071101
DiskType: "tier3",
11081102
}, nil)
11091103

pkg/driver/sanity_test.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,19 @@ func newFakeCloudProvider() *fakeCloudProvider {
134134
}
135135

136136
func (p *fakeCloudProvider) GetPVMInstanceByName(name string) (*cloud.PVMInstance, error) {
137-
138137
return &cloud.PVMInstance{
139-
ID: name + "-" + "id",
140-
ImageID: name + "-" + "image",
141-
Name: name,
138+
ID: name + "-" + "id",
139+
DiskType: "tier3",
140+
Name: name,
142141
}, nil
143142

144143
}
145144

146145
func (p *fakeCloudProvider) GetPVMInstanceByID(instanceID string) (*cloud.PVMInstance, error) {
147-
148146
return &cloud.PVMInstance{
149-
ID: instanceID,
150-
ImageID: strings.Split(instanceID, "-")[0] + "-" + "image",
151-
Name: strings.Split(instanceID, "-")[0],
147+
ID: instanceID,
148+
DiskType: "tier3",
149+
Name: strings.Split(instanceID, "-")[0],
152150
}, nil
153151
}
154152

@@ -166,15 +164,6 @@ func (p *fakeCloudProvider) UpdateStoragePoolAffinity(instanceID string) error {
166164
return nil
167165
}
168166

169-
func (p *fakeCloudProvider) GetImageByID(imageID string) (*cloud.PVMImage, error) {
170-
171-
return &cloud.PVMImage{
172-
ID: imageID,
173-
Name: strings.Split(imageID, "-")[0] + "-" + "image",
174-
DiskType: "tier3",
175-
}, nil
176-
}
177-
178167
func (c *fakeCloudProvider) CreateDisk(volumeName string, diskOptions *cloud.DiskOptions) (*cloud.Disk, error) {
179168
r1 := rand.New(rand.NewSource(time.Now().UnixNano()))
180169

0 commit comments

Comments
 (0)