Skip to content

Commit 5224fe3

Browse files
committed
Using env vars for getting the metadata details
Signed-off-by: Yussuf Shaikh <[email protected]>
1 parent 076e4da commit 5224fe3

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

pkg/driver/controller.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,19 @@ var (
9191
// newControllerService creates a new controller service
9292
// it will print stack trace and osexit if failed to create the service
9393
func newControllerService(driverOptions *Options) controllerService {
94-
var (
95-
cloudInstanceId string
96-
zone string
97-
)
98-
if driverOptions.cloudconfig != "" {
94+
var cloudInstanceId, zone string
95+
96+
// Following env vars will be checked before looking up the
97+
// cli options and metadata service if both are not set.
98+
// It will help with running the controller tests locally
99+
// on a powervs vm. Currently, it relies on k8s cluster node.
100+
cID := os.Getenv("POWERVS_CLOUD_INSTANCE_ID")
101+
z := os.Getenv("POWERVS_ZONE")
102+
103+
if cID != "" && z != "" {
104+
klog.V(4).Info("using node info from environment variables")
105+
cloudInstanceId, zone = cID, z
106+
} else if driverOptions.cloudconfig != "" {
99107
var cloudConfig CloudConfig
100108
config, err := os.Open(driverOptions.cloudconfig)
101109
if nil != err {

pkg/driver/node.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,28 @@ type nodeService struct {
7575
// newNodeService creates a new node service
7676
// it will print stack trace and osexit if failed to create the service
7777
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()
8297
}
8398

84-
pvsCloud, err := NewPowerVSCloudFunc(metadata.GetCloudInstanceId(), metadata.GetZone(), driverOptions.debug)
99+
pvsCloud, err := NewPowerVSCloudFunc(cloudInstanceId, zone, driverOptions.debug)
85100
if err != nil {
86101
klog.Fatalf("Failed to get powervs cloud: %v", err)
87102
}
@@ -90,7 +105,7 @@ func newNodeService(driverOptions *Options) nodeService {
90105
cloud: pvsCloud,
91106
mounter: newNodeMounter(),
92107
driverOptions: driverOptions,
93-
pvmInstanceId: metadata.GetPvmInstanceId(),
108+
pvmInstanceId: instanceID,
94109
volumeLocks: util.NewVolumeLocks(),
95110
stats: &VolumeStatUtils{},
96111
}

0 commit comments

Comments
 (0)