Commit c8b3a393 authored by Darren Shepherd's avatar Darren Shepherd Committed by root

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 86d36393
......@@ -23,6 +23,7 @@ import (
"path"
"sort"
"strings"
"sync"
"time"
"context"
......@@ -63,6 +64,12 @@ const (
csiResyncPeriod = time.Minute
)
var (
WaitForValidHostName bool
csiPluginInstance *csiPlugin
csiPluginLock sync.Mutex
)
var deprecatedSocketDirVersions = []string{"0.1.0", "0.2.0", "0.3.0", "0.4.0"}
type csiPlugin struct {
......@@ -80,11 +87,18 @@ const ephemeralDriverMode driverMode = "ephemeral"
// ProbeVolumePlugins returns implemented plugins
func ProbeVolumePlugins() []volume.VolumePlugin {
p := &csiPlugin{
csiPluginLock.Lock()
defer csiPluginLock.Unlock()
if csiPluginInstance != nil {
return []volume.VolumePlugin{csiPluginInstance}
}
csiPluginInstance = &csiPlugin{
host: nil,
blockEnabled: utilfeature.DefaultFeatureGate.Enabled(features.CSIBlockVolume),
}
return []volume.VolumePlugin{p}
return []volume.VolumePlugin{csiPluginInstance}
}
// volume.VolumePlugin methods
......@@ -208,6 +222,21 @@ func (h *RegistrationHandler) DeRegisterPlugin(pluginName string) {
}
func (p *csiPlugin) Init(host volume.VolumeHost) error {
csiPluginLock.Lock()
defer csiPluginLock.Unlock()
if WaitForValidHostName && host.GetHostName() == "" {
for {
if p.host != nil {
return nil
}
csiPluginLock.Unlock()
time.Sleep(time.Second)
klog.Infof("Waiting for CSI volume hostname")
csiPluginLock.Lock()
}
}
p.host = host
if utilfeature.DefaultFeatureGate.Enabled(features.CSIDriverRegistry) {
......
......@@ -18,10 +18,6 @@ package volume
import (
"fmt"
"net"
"strings"
"sync"
authenticationv1 "k8s.io/api/authentication/v1"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
......@@ -36,6 +32,9 @@ import (
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/volume/util/recyclerclient"
"k8s.io/kubernetes/pkg/volume/util/subpath"
"net"
"strings"
"sync"
)
type ProbeOperation uint32
......@@ -554,6 +553,10 @@ func (pm *VolumePluginMgr) InitPlugins(plugins []VolumePlugin, prober DynamicPlu
pm.mutex.Lock()
defer pm.mutex.Unlock()
if pm.Host != nil {
return nil
}
pm.Host = host
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