@@ -75,13 +75,28 @@ type nodeService struct {
75
75
// newNodeService creates a new node service
76
76
// it will print stack trace and osexit if failed to create the service
77
77
func newNodeService (driverOptions * Options ) nodeService {
78
- klog .V (4 ).Infof ("retrieving node info from metadata service" )
79
- metadata , err := cloud .NewMetadataService (cloud .DefaultKubernetesAPIClient , driverOptions .kubeconfig )
80
- if err != nil {
81
- klog .Fatalf ("Failed to get metadata service: %v" , err )
78
+ var cloudInstanceId , zone , instanceID string
79
+
80
+ // Following env vars will be checked before looking up the metadata service
81
+ // if all are not set. It will help with running the nodes tests locally
82
+ // on a powervs vm. Currently, it relies on k8s cluster node.
83
+ cID := os .Getenv ("POWERVS_CLOUD_INSTANCE_ID" )
84
+ z := os .Getenv ("POWERVS_ZONE" )
85
+ insID := os .Getenv ("POWERVS_INSTANCE_ID" )
86
+
87
+ if cID != "" && z != "" && insID != "" {
88
+ klog .V (4 ).Info ("using node info from environment variables" )
89
+ cloudInstanceId , zone , instanceID = cID , z , insID
90
+ } else {
91
+ klog .V (4 ).Infof ("retrieving node info from metadata service" )
92
+ metadata , err := cloud .NewMetadataService (cloud .DefaultKubernetesAPIClient , driverOptions .kubeconfig )
93
+ if err != nil {
94
+ klog .Fatalf ("Failed to get metadata service: %v" , err )
95
+ }
96
+ cloudInstanceId , zone , instanceID = metadata .GetCloudInstanceId (), metadata .GetZone (), metadata .GetPvmInstanceId ()
82
97
}
83
98
84
- pvsCloud , err := NewPowerVSCloudFunc (metadata . GetCloudInstanceId (), metadata . GetZone () , driverOptions .debug )
99
+ pvsCloud , err := NewPowerVSCloudFunc (cloudInstanceId , zone , driverOptions .debug )
85
100
if err != nil {
86
101
klog .Fatalf ("Failed to get powervs cloud: %v" , err )
87
102
}
@@ -90,7 +105,7 @@ func newNodeService(driverOptions *Options) nodeService {
90
105
cloud : pvsCloud ,
91
106
mounter : newNodeMounter (),
92
107
driverOptions : driverOptions ,
93
- pvmInstanceId : metadata . GetPvmInstanceId () ,
108
+ pvmInstanceId : instanceID ,
94
109
volumeLocks : util .NewVolumeLocks (),
95
110
stats : & VolumeStatUtils {},
96
111
}
0 commit comments