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

Commit 12e7415

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request #49299 from dims/delay-looking-for-instance-id
Automatic merge from submit-queue (batch tested with PRs 49420, 49296, 49299, 49371, 46514) Avoid looking up instance id until we need it **What this PR does / why 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. So let's try to find the instance-id only when we need it. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: ```release-note NONE ```
2 parents 25bba44 + 9f7832e commit 12e7415

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
@@ -281,18 +281,12 @@ func newOpenStack(cfg Config) (*OpenStack, error) {
281281
return nil, err
282282
}
283283

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

298292
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)