mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
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.
41541910e1/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.
This commit is contained in:
parent
2853f46b02
commit
6139f9ab89
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user