Commit 4560beb2 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

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 ```
parents 0af43066 6139f9ab
......@@ -281,18 +281,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