mirror of https://github.com/k3s-io/k3s
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.k3s-v1.14.6
parent
94beca160e
commit
4ce15bb26b
|
@ -23,6 +23,7 @@ import (
|
|||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
@ -60,6 +61,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 {
|
||||
|
@ -76,11 +83,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
|
||||
|
@ -204,6 +218,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"
|
||||
|
@ -40,6 +36,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
|
||||
|
@ -570,6 +569,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 {
|
||||
|
|
Loading…
Reference in New Issue