Commit 6139f9ab authored by Davanum Srinivas's avatar Davanum Srinivas

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.
parent 2853f46b
......@@ -280,18 +280,12 @@ func newOpenStack(cfg Config) (*OpenStack, error) {
return nil, err
}
id, err := readInstanceID()
if err != nil {
return nil, err
}
os := OpenStack{
provider: provider,
region: cfg.Global.Region,
lbOpts: cfg.LoadBalancer,
bsOpts: cfg.BlockStorage,
routeOpts: cfg.Route,
localInstanceID: id,
provider: provider,
region: cfg.Global.Region,
lbOpts: cfg.LoadBalancer,
bsOpts: cfg.BlockStorage,
routeOpts: cfg.Route,
}
err = checkOpenStackOpts(&os)
......
......@@ -143,6 +143,13 @@ func (i *Instances) ExternalID(name types.NodeName) (string, error) {
// InstanceID returns the kubelet's cloud provider ID.
func (os *OpenStack) InstanceID() (string, error) {
if len(os.localInstanceID) == 0 {
id, err := readInstanceID()
if err != nil {
return "", err
}
os.localInstanceID = id
}
return os.localInstanceID, nil
}
......
......@@ -473,7 +473,12 @@ func TestVolumes(t *testing.T) {
WaitForVolumeStatus(t, os, vol, volumeAvailableStatus)
diskId, err := os.AttachDisk(os.localInstanceID, vol)
id, err := os.InstanceID()
if err != nil {
t.Fatalf("Cannot find instance id: %v", err)
}
diskId, err := os.AttachDisk(id, vol)
if err != nil {
t.Fatalf("Cannot AttachDisk Cinder volume %s: %v", vol, err)
}
......@@ -487,7 +492,7 @@ func TestVolumes(t *testing.T) {
}
t.Logf("Volume (%s) found at path: %s\n", vol, devicePath)
err = os.DetachDisk(os.localInstanceID, vol)
err = os.DetachDisk(id, vol)
if err != nil {
t.Fatalf("Cannot DetachDisk Cinder volume %s: %v", vol, err)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment