Commit 2904aa5a authored by Darren Shepherd's avatar Darren Shepherd

Fix CSI when running kubelet and controller-manager in the same process

Both kubelet and controller-manager init the volume plugins. We added a global flag that can be set that will force the init to wait for a valid hostname.
parent d8dc9e1f
...@@ -21,6 +21,7 @@ import ( ...@@ -21,6 +21,7 @@ import (
"net" "net"
"strings" "strings"
"sync" "sync"
"time"
authenticationv1 "k8s.io/api/authentication/v1" authenticationv1 "k8s.io/api/authentication/v1"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
...@@ -38,6 +39,10 @@ import ( ...@@ -38,6 +39,10 @@ import (
"k8s.io/kubernetes/pkg/volume/util/subpath" "k8s.io/kubernetes/pkg/volume/util/subpath"
) )
var (
WaitForValidHost = false
)
type ProbeOperation uint32 type ProbeOperation uint32
type ProbeEvent struct { type ProbeEvent struct {
Plugin VolumePlugin // VolumePlugin that was added/updated/removed. if ProbeEvent.Op is 'ProbeRemove', Plugin should be nil Plugin VolumePlugin // VolumePlugin that was added/updated/removed. if ProbeEvent.Op is 'ProbeRemove', Plugin should be nil
...@@ -551,9 +556,26 @@ func NewSpecFromPersistentVolume(pv *v1.PersistentVolume, readOnly bool) *Spec { ...@@ -551,9 +556,26 @@ func NewSpecFromPersistentVolume(pv *v1.PersistentVolume, readOnly bool) *Spec {
// This must be called exactly once before any New* methods are called on any // This must be called exactly once before any New* methods are called on any
// plugins. // plugins.
func (pm *VolumePluginMgr) InitPlugins(plugins []VolumePlugin, prober DynamicPluginProber, host VolumeHost) error { func (pm *VolumePluginMgr) InitPlugins(plugins []VolumePlugin, prober DynamicPluginProber, host VolumeHost) error {
if host.GetHostName() == "" && WaitForValidHost {
for {
pm.mutex.Lock()
if pm.Host != nil && pm.Host.GetHostName() != "" {
pm.mutex.Unlock()
break
}
pm.mutex.Unlock()
klog.Infof("Waiting for volume plugins to be initialized")
time.Sleep(time.Second)
}
}
pm.mutex.Lock() pm.mutex.Lock()
defer pm.mutex.Unlock() defer pm.mutex.Unlock()
if pm.Host != nil {
return nil
}
pm.Host = host pm.Host = host
if prober == nil { if prober == nil {
......
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