Skip to content

Commit 3ea1ecc

Browse files
authored
Fix for sanity (#113)
* Fix for sanity Signed-off-by: Sameer Shaikh <[email protected]> * Fix for sanity Signed-off-by: Sameer Shaikh <[email protected]> * Review Comments Signed-off-by: Sameer Shaikh <[email protected]> --------- Signed-off-by: Sameer Shaikh <[email protected]>
1 parent 68dbb35 commit 3ea1ecc

File tree

9 files changed

+63
-32
lines changed

9 files changed

+63
-32
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ script:
2828
- rsync -az . $GOPATH/src/github.com/IBM/ibm-vpc-file-csi-driver
2929

3030
- make fmt
31+
- make test-sanity
3132
- travis_wait 300 make test
3233
- make coverage && touch "Passing" || touch "Failed"
3334
- make driver

cmd/main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
csiConfig "github.com/IBM/ibm-vpc-file-csi-driver/config"
3636
driver "github.com/IBM/ibm-vpc-file-csi-driver/pkg/ibmcsidriver"
3737
cloudProvider "github.com/IBM/ibmcloud-volume-file-vpc/pkg/ibmcloudprovider"
38+
nodeInfoManager "github.com/IBM/ibmcloud-volume-file-vpc/pkg/metadata"
3839
"github.com/IBM/ibmcloud-volume-file-vpc/pkg/watcher"
3940
k8sUtils "github.com/IBM/secret-utils-lib/pkg/k8s_utils"
4041
"go.uber.org/zap"
@@ -100,9 +101,15 @@ func handle(logger *zap.Logger) {
100101
// Get new instance for the Mount Manager
101102
mounter := mountManager.NewNodeMounter()
102103

104+
nodeName := os.Getenv("KUBE_NODE_NAME")
105+
106+
nodeInfo := nodeInfoManager.NodeInfoManager{
107+
NodeName: nodeName,
108+
}
109+
103110
statUtil := &(driver.VolumeStatUtils{})
104111

105-
err = ibmCSIDriver.SetupIBMCSIDriver(ibmcloudProvider, mounter, statUtil, nil, logger, csiConfig.CSIDriverName, vendorVersion)
112+
err = ibmCSIDriver.SetupIBMCSIDriver(ibmcloudProvider, mounter, statUtil, nil, &nodeInfo, logger, csiConfig.CSIDriverName, vendorVersion)
106113
if err != nil {
107114
logger.Fatal("Failed to initialize driver...", zap.Error(err))
108115
}

go.mod

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ go 1.23.8
44

55
require (
66
github.com/IBM/ibm-csi-common v1.1.20
7-
github.com/IBM/ibmcloud-volume-file-vpc v1.2.8
7+
github.com/IBM/ibmcloud-volume-file-vpc v1.2.9
88
github.com/IBM/ibmcloud-volume-interface v1.2.12
99
github.com/IBM/secret-utils-lib v1.1.13
1010
github.com/container-storage-interface/spec v1.11.0
1111
github.com/golang/glog v1.2.4
1212
github.com/google/uuid v1.6.0
1313
github.com/kubernetes-csi/csi-test/v4 v4.4.0
14-
github.com/prometheus/client_golang v1.19.1
15-
github.com/stretchr/testify v1.9.0
14+
github.com/prometheus/client_golang v1.21.1
15+
github.com/stretchr/testify v1.10.0
1616
go.uber.org/zap v1.27.0
1717
golang.org/x/net v0.38.0
1818
golang.org/x/sys v0.31.0
1919
google.golang.org/grpc v1.65.0
20+
google.golang.org/protobuf v1.36.1
2021
k8s.io/api v0.32.3
2122
k8s.io/apimachinery v0.32.3
2223
k8s.io/client-go v0.32.3
@@ -62,6 +63,7 @@ require (
6263
github.com/josharian/intern v1.0.0 // indirect
6364
github.com/json-iterator/go v1.1.12 // indirect
6465
github.com/kelseyhightower/envconfig v1.4.0 // indirect
66+
github.com/klauspost/compress v1.17.11 // indirect
6567
github.com/leodido/go-urn v1.4.0 // indirect
6668
github.com/mailru/easyjson v0.7.7 // indirect
6769
github.com/mitchellh/mapstructure v1.5.0 // indirect
@@ -77,7 +79,7 @@ require (
7779
github.com/pkg/errors v0.9.1 // indirect
7880
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
7981
github.com/prometheus/client_model v0.6.1 // indirect
80-
github.com/prometheus/common v0.55.0 // indirect
82+
github.com/prometheus/common v0.62.0 // indirect
8183
github.com/prometheus/procfs v0.15.1 // indirect
8284
github.com/spf13/cobra v1.8.1 // indirect
8385
github.com/spf13/pflag v1.0.5 // indirect
@@ -87,12 +89,11 @@ require (
8789
go.opentelemetry.io/otel/trace v1.28.0 // indirect
8890
go.uber.org/multierr v1.11.0 // indirect
8991
golang.org/x/crypto v0.36.0 // indirect
90-
golang.org/x/oauth2 v0.23.0 // indirect
92+
golang.org/x/oauth2 v0.24.0 // indirect
9193
golang.org/x/term v0.30.0 // indirect
9294
golang.org/x/text v0.23.0 // indirect
9395
golang.org/x/time v0.7.0 // indirect
9496
google.golang.org/genproto/googleapis/rpc v0.0.0-20240826202546-f6391c0de4c7 // indirect
95-
google.golang.org/protobuf v1.35.1 // indirect
9697
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
9798
gopkg.in/inf.v0 v0.9.1 // indirect
9899
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect

go.sum

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ github.com/IBM/go-sdk-core/v5 v5.17.4 h1:VGb9+mRrnS2HpHZFM5hy4J6ppIWnwNrw0G+tLSg
99
github.com/IBM/go-sdk-core/v5 v5.17.4/go.mod h1:KsAAI7eStAWwQa4F96MLy+whYSh39JzNjklZRbN/8ns=
1010
github.com/IBM/ibm-csi-common v1.1.20 h1:83tWmb+39G/Mm4E9nZwn5/EL0SMcyEyLJDN6hAS4eg4=
1111
github.com/IBM/ibm-csi-common v1.1.20/go.mod h1:z9U3OmpKN92eUVdhhdbrr5kAT3MPRT9xwr6MVltLBFI=
12-
github.com/IBM/ibmcloud-volume-file-vpc v1.2.8 h1:3ioBF6NfXra7Wr4cVYE9NIsNQZf7Js6taZD9aMyazzQ=
13-
github.com/IBM/ibmcloud-volume-file-vpc v1.2.8/go.mod h1:W03g1YDzMDxakY+iXejsobLBfbSvOziwq/hqZ7gJmJc=
12+
github.com/IBM/ibmcloud-volume-file-vpc v1.2.9 h1:/qRMnb72GqjceRxIJFSJYCkPGpcPG00LYPZ9Os/HJ+0=
13+
github.com/IBM/ibmcloud-volume-file-vpc v1.2.9/go.mod h1:Ho9Or3nQ44KPmOY3dc5ZIkjDrOx7biBgWRwbvQfrh4E=
1414
github.com/IBM/ibmcloud-volume-interface v1.2.12 h1:ehj+EJ+bno4ZKKy5CQoxNaHdb92EfVQN/KAtSBkkLaU=
1515
github.com/IBM/ibmcloud-volume-interface v1.2.12/go.mod h1:q+ngxRIR206Vy6xGTT+7etk+wAViT2dYrDByw8mjFYk=
1616
github.com/IBM/secret-common-lib v1.1.12 h1:BvQvQU3Ft3qHRus8ZtDbd4kc2wd71uS5RXsgWAbal1Y=
@@ -162,6 +162,8 @@ github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dv
162162
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
163163
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
164164
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
165+
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc=
166+
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
165167
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
166168
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
167169
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
@@ -171,6 +173,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
171173
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
172174
github.com/kubernetes-csi/csi-test/v4 v4.4.0 h1:r0mnAwDURI24Vw3a/LyA/ga11yD5ZGuU7+REO35Na9s=
173175
github.com/kubernetes-csi/csi-test/v4 v4.4.0/go.mod h1:t1RzseMZJKy313nezI/d7TolbbiKpUZM3SXQvXxOX0w=
176+
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
177+
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
174178
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
175179
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
176180
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
@@ -217,13 +221,13 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
217221
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
218222
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
219223
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
220-
github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE=
221-
github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho=
224+
github.com/prometheus/client_golang v1.21.1 h1:DOvXXTqVzvkIewV/CDPFdejpMCGeMcbGCQ8YOmu+Ibk=
225+
github.com/prometheus/client_golang v1.21.1/go.mod h1:U9NM32ykUErtVBxdvD3zfi+EuFkkaBvMb09mIfe0Zgg=
222226
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
223227
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
224228
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
225-
github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc=
226-
github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8=
229+
github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ2Io=
230+
github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I=
227231
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
228232
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
229233
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
@@ -243,8 +247,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
243247
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
244248
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
245249
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
246-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
247-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
250+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
251+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
248252
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
249253
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
250254
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
@@ -303,8 +307,8 @@ golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
303307
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
304308
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
305309
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
306-
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
307-
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
310+
golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE=
311+
golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
308312
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
309313
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
310314
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -417,8 +421,8 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba
417421
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
418422
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
419423
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
420-
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
421-
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
424+
google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk=
425+
google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
422426
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
423427
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
424428
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

pkg/ibmcsidriver/controller.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package ibmcsidriver
2121

2222
import (
2323
"os"
24+
"strings"
2425
"time"
2526

2627
commonError "github.com/IBM/ibm-csi-common/pkg/messages"
@@ -447,6 +448,12 @@ func (csiCS *CSIControllerServer) ListVolumes(ctx context.Context, req *csi.List
447448
tags := map[string]string{}
448449
volumeList, err := session.ListVolumes(maxEntries, req.StartingToken, tags)
449450
if err != nil {
451+
errCode := err.(providerError.Message).Code
452+
if strings.Contains(errCode, "InvalidListVolumesLimit") {
453+
return nil, commonError.GetCSIError(ctxLogger, commonError.InvalidParameters, requestID, err)
454+
} else if strings.Contains(errCode, "StartVolumeIDNotFound") {
455+
return nil, commonError.GetCSIError(ctxLogger, commonError.StartVolumeIDNotFound, requestID, err, req.StartingToken)
456+
}
450457
return nil, commonError.GetCSIBackendError(ctxLogger, requestID, err)
451458
}
452459

pkg/ibmcsidriver/ibm_csi_driver.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ package ibmcsidriver
2121

2222
import (
2323
"fmt"
24-
"os"
2524

2625
commonError "github.com/IBM/ibm-csi-common/pkg/messages"
2726
mountManager "github.com/IBM/ibm-csi-common/pkg/mountmanager"
@@ -48,15 +47,13 @@ type IBMCSIDriver struct {
4847
nscap []*csi.NodeServiceCapability
4948
}
5049

51-
var nodeMeta = nodeMetadata.NewNodeMetadata
52-
5350
// GetIBMCSIDriver ...
5451
func GetIBMCSIDriver() *IBMCSIDriver {
5552
return &IBMCSIDriver{}
5653
}
5754

5855
// SetupIBMCSIDriver ...
59-
func (icDriver *IBMCSIDriver) SetupIBMCSIDriver(provider cloudProvider.CloudProviderInterface, mounter mountManager.Mounter, statsUtil StatsUtils, metadata nodeMetadata.NodeMetadata, lgr *zap.Logger, name, vendorVersion string) error {
56+
func (icDriver *IBMCSIDriver) SetupIBMCSIDriver(provider cloudProvider.CloudProviderInterface, mounter mountManager.Mounter, statsUtil StatsUtils, metadata nodeMetadata.NodeMetadata, nodeInfo nodeMetadata.NodeInfo, lgr *zap.Logger, name, vendorVersion string) error {
6057
icDriver.logger = lgr
6158
icDriver.logger.Info("IBMCSIDriver-SetupIBMCSIDriver setting up IBM CSI Driver...")
6259

@@ -112,9 +109,9 @@ func (icDriver *IBMCSIDriver) SetupIBMCSIDriver(provider cloudProvider.CloudProv
112109

113110
icDriver.logger.Info("Successfully setup IBM CSI driver")
114111
// Set up Region
115-
regionMetadata, err := nodeMeta(os.Getenv("KUBE_NODE_NAME"), lgr)
112+
regionMetadata, err := nodeInfo.NewNodeMetadata(lgr)
116113
if err != nil {
117-
return fmt.Errorf("Controller_Helper: Failed to initialize node metadata")
114+
return fmt.Errorf("Controller_Helper: Failed to initialize node metadata: error: %v", err)
118115
}
119116
icDriver.region = regionMetadata.GetRegion()
120117
return nil

pkg/ibmcsidriver/ibm_csi_driver_test.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
mountManager "github.com/IBM/ibm-csi-common/pkg/mountmanager"
2626
cloudProvider "github.com/IBM/ibmcloud-volume-file-vpc/pkg/ibmcloudprovider"
2727
nodeMetadata "github.com/IBM/ibmcloud-volume-file-vpc/pkg/metadata"
28+
nodeInfo "github.com/IBM/ibmcloud-volume-file-vpc/pkg/metadata/fake"
2829
"github.com/stretchr/testify/assert"
2930
testingexec "k8s.io/utils/exec/testing"
3031
)
@@ -37,7 +38,6 @@ func initIBMCSIDriver(t *testing.T, fakeActions ...testingexec.FakeCommandAction
3738
logger, teardown := cloudProvider.GetTestLogger(t)
3839
defer teardown()
3940
icDriver := GetIBMCSIDriver()
40-
nodeMeta = nodeMetadata.InitMetadata
4141
// Create fake provider and mounter
4242
provider, _ := cloudProvider.NewFakeIBMCloudStorageProvider("", logger)
4343
var mounter mountManager.Mounter
@@ -49,12 +49,14 @@ func initIBMCSIDriver(t *testing.T, fakeActions ...testingexec.FakeCommandAction
4949
statsUtil := &MockStatUtils{}
5050

5151
fakeNodeData := nodeMetadata.FakeNodeMetadata{}
52+
fakeNodeInfo := nodeInfo.FakeNodeInfo{}
5253
fakeNodeData.GetRegionReturns("testregion")
5354
fakeNodeData.GetZoneReturns("testzone")
5455
fakeNodeData.GetWorkerIDReturns("testworker")
56+
fakeNodeInfo.NewNodeMetadataReturns(&fakeNodeData, nil)
5557

5658
// Setup the IBM CSI driver
57-
err := icDriver.SetupIBMCSIDriver(provider, mounter, statsUtil, &fakeNodeData, logger, driver, vendorVersion)
59+
err := icDriver.SetupIBMCSIDriver(provider, mounter, statsUtil, &fakeNodeData, &fakeNodeInfo, logger, driver, vendorVersion)
5860
if err != nil {
5961
t.Fatalf("Failed to setup IBM CSI Driver: %v", err)
6062
}
@@ -81,19 +83,21 @@ func TestSetupIBMCSIDriver(t *testing.T) {
8183
statsUtil := &MockStatUtils{}
8284

8385
fakeNodeData := nodeMetadata.FakeNodeMetadata{}
86+
fakeNodeInfo := nodeInfo.FakeNodeInfo{}
8487
fakeNodeData.GetRegionReturns("testregion")
8588
fakeNodeData.GetZoneReturns("testzone")
8689
fakeNodeData.GetWorkerIDReturns("testworker")
90+
fakeNodeInfo.NewNodeMetadataReturns(&fakeNodeData, nil)
8791

8892
// Failed setting up driver, provider nil
89-
err := icDriver.SetupIBMCSIDriver(nil, mounter, statsUtil, &fakeNodeData, logger, name, vendorVersion)
93+
err := icDriver.SetupIBMCSIDriver(nil, mounter, statsUtil, &fakeNodeData, &fakeNodeInfo, logger, name, vendorVersion)
9094
assert.NotNil(t, err)
9195

9296
// Failed setting up driver, mounter nil
93-
err = icDriver.SetupIBMCSIDriver(provider, nil, statsUtil, &fakeNodeData, logger, name, vendorVersion)
97+
err = icDriver.SetupIBMCSIDriver(provider, nil, statsUtil, &fakeNodeData, &fakeNodeInfo, logger, name, vendorVersion)
9498
assert.NotNil(t, err)
9599

96100
// Failed setting up driver, name empty
97-
err = icDriver.SetupIBMCSIDriver(provider, mounter, statsUtil, &fakeNodeData, logger, "", vendorVersion)
101+
err = icDriver.SetupIBMCSIDriver(provider, mounter, statsUtil, &fakeNodeData, &fakeNodeInfo, logger, "", vendorVersion)
98102
assert.NotNil(t, err)
99103
}

pkg/ibmcsidriver/node.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,13 @@ func (csiNS *CSINodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInf
215215

216216
// Check if node metadata service initialized properly
217217
if csiNS.Metadata == nil { //nolint
218-
metadata, err := nodeMetadata.NewNodeMetadata(os.Getenv("KUBE_NODE_NAME"), ctxLogger)
218+
nodeName := os.Getenv("KUBE_NODE_NAME")
219+
220+
nodeInfo := nodeMetadata.NodeInfoManager{
221+
NodeName: nodeName,
222+
}
223+
224+
metadata, err := nodeInfo.NewNodeMetadata(ctxLogger)
219225
if err != nil {
220226
ctxLogger.Error("Failed to initialize node metadata", zap.Error(err))
221227
return nil, commonError.GetCSIError(ctxLogger, commonError.NodeMetadataInitFailed, requestID, err)

tests/sanity/sanity_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"golang.org/x/net/context"
3434
"google.golang.org/grpc"
3535

36+
nodeInfo "github.com/IBM/ibmcloud-volume-file-vpc/pkg/metadata/fake"
3637
"github.com/IBM/ibmcloud-volume-interface/config"
3738
"github.com/IBM/ibmcloud-volume-interface/lib/provider"
3839
providerError "github.com/IBM/ibmcloud-volume-interface/lib/utils"
@@ -79,6 +80,7 @@ func TestSanity(t *testing.T) {
7980
}
8081

8182
os.Setenv("VPC_SUBNET_IDS", "subnet-id")
83+
8284
// Create a fake CSI driver
8385
csiSanityDriver := initCSIDriverForSanity(t)
8486

@@ -157,12 +159,14 @@ func initCSIDriverForSanity(t *testing.T) *csiDriver.IBMCSIDriver {
157159

158160
// fake node metadata
159161
fakeNodeData := nodeMetadata.FakeNodeMetadata{}
162+
fakeNodeInfo := nodeInfo.FakeNodeInfo{}
160163
fakeNodeData.GetRegionReturns("testregion")
161164
fakeNodeData.GetZoneReturns("testzone")
162165
fakeNodeData.GetWorkerIDReturns("testworker")
166+
fakeNodeInfo.NewNodeMetadataReturns(&fakeNodeData, nil)
163167

164168
// Setup the IBM CSI Driver
165-
err := csiSanityDriver.SetupIBMCSIDriver(provider, mounter, statsUtil, &fakeNodeData, logger, driver, vendorVersion)
169+
err := csiSanityDriver.SetupIBMCSIDriver(provider, mounter, statsUtil, &fakeNodeData, &fakeNodeInfo, logger, driver, vendorVersion)
166170
if err != nil {
167171
t.Fatalf("Failed to setup IBM CSI Driver: %v", err)
168172
}

0 commit comments

Comments
 (0)