Skip to content
This repository was archived by the owner on Mar 22, 2018. It is now read-only.

Commit 9f7832e

Browse files
committed
Avoid looking up instance id until we need it
currently kube-controller-manager cannot run outside of a vm started by openstack (with --cloud-provider=openstack params). We try to read the instance id from the metadata provider or the config drive or the file location only when we really need it. In the normal scenario, the controller-manager uses the node name to get the instance id. https://github.com/kubernetes/kubernetes/blob/41541910e1699975a8f9202a89b6865e45921194/pkg/volume/cinder/attacher.go#L149 The localInstanceID is currently used only in the test case, so let us not read it until it is really needed.
1 parent 4246a22 commit 9f7832e

3 files changed

Lines changed: 19 additions & 13 deletions

File tree

pkg/cloudprovider/providers/openstack/openstack.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -280,18 +280,12 @@ func newOpenStack(cfg Config) (*OpenStack, error) {
280280
return nil, err
281281
}
282282

283-
id, err := readInstanceID()
284-
if err != nil {
285-
return nil, err
286-
}
287-
288283
os := OpenStack{
289-
provider: provider,
290-
region: cfg.Global.Region,
291-
lbOpts: cfg.LoadBalancer,
292-
bsOpts: cfg.BlockStorage,
293-
routeOpts: cfg.Route,
294-
localInstanceID: id,
284+
provider: provider,
285+
region: cfg.Global.Region,
286+
lbOpts: cfg.LoadBalancer,
287+
bsOpts: cfg.BlockStorage,
288+
routeOpts: cfg.Route,
295289
}
296290

297291
err = checkOpenStackOpts(&os)

pkg/cloudprovider/providers/openstack/openstack_instances.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ func (i *Instances) ExternalID(name types.NodeName) (string, error) {
143143

144144
// InstanceID returns the kubelet's cloud provider ID.
145145
func (os *OpenStack) InstanceID() (string, error) {
146+
if len(os.localInstanceID) == 0 {
147+
id, err := readInstanceID()
148+
if err != nil {
149+
return "", err
150+
}
151+
os.localInstanceID = id
152+
}
146153
return os.localInstanceID, nil
147154
}
148155

pkg/cloudprovider/providers/openstack/openstack_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,12 @@ func TestVolumes(t *testing.T) {
473473

474474
WaitForVolumeStatus(t, os, vol, volumeAvailableStatus)
475475

476-
diskId, err := os.AttachDisk(os.localInstanceID, vol)
476+
id, err := os.InstanceID()
477+
if err != nil {
478+
t.Fatalf("Cannot find instance id: %v", err)
479+
}
480+
481+
diskId, err := os.AttachDisk(id, vol)
477482
if err != nil {
478483
t.Fatalf("Cannot AttachDisk Cinder volume %s: %v", vol, err)
479484
}
@@ -487,7 +492,7 @@ func TestVolumes(t *testing.T) {
487492
}
488493
t.Logf("Volume (%s) found at path: %s\n", vol, devicePath)
489494

490-
err = os.DetachDisk(os.localInstanceID, vol)
495+
err = os.DetachDisk(id, vol)
491496
if err != nil {
492497
t.Fatalf("Cannot DetachDisk Cinder volume %s: %v", vol, err)
493498
}

0 commit comments

Comments
 (0)