提交 1549dd39 编写于 作者: Z zhangmin

fix "Failed to list *v1beta1.VolumeSnapshotClass" on k8s 1.16

上级 0f63b5ba
...@@ -101,6 +101,7 @@ func NewController( ...@@ -101,6 +101,7 @@ func NewController(
) *StorageCapabilityController { ) *StorageCapabilityController {
utilruntime.Must(crdscheme.AddToScheme(scheme.Scheme)) utilruntime.Must(crdscheme.AddToScheme(scheme.Scheme))
controller := &StorageCapabilityController{ controller := &StorageCapabilityController{
storageClassCapabilityClient: capabilityClient, storageClassCapabilityClient: capabilityClient,
storageCapabilityLister: capabilityInformer.StorageClassCapabilities().Lister(), storageCapabilityLister: capabilityInformer.StorageClassCapabilities().Lister(),
...@@ -111,15 +112,18 @@ func NewController( ...@@ -111,15 +112,18 @@ func NewController(
storageClassLister: storageClassInformer.Lister(), storageClassLister: storageClassInformer.Lister(),
storageClassSynced: storageClassInformer.Informer().HasSynced, storageClassSynced: storageClassInformer.Informer().HasSynced,
snapshotSupported: snapshotSupported, snapshotSupported: snapshotSupported,
snapshotClassClient: snapshotClassClient,
snapshotClassLister: snapshotClassInformer.Lister(),
snapshotClassSynced: snapshotClassInformer.Informer().HasSynced,
csiDriverLister: csiDriverInformer.Lister(), csiDriverLister: csiDriverInformer.Lister(),
csiDriverSynced: csiDriverInformer.Informer().HasSynced, csiDriverSynced: csiDriverInformer.Informer().HasSynced,
csiAddressGetter: csiAddress, csiAddressGetter: csiAddress,
workQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "StorageClasses"), workQueue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "StorageClasses"),
} }
if snapshotSupported {
controller.snapshotClassClient = snapshotClassClient
controller.snapshotClassLister = snapshotClassInformer.Lister()
controller.snapshotClassSynced = snapshotClassInformer.Informer().HasSynced
}
storageClassInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{ storageClassInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: controller.enqueueStorageClass, AddFunc: controller.enqueueStorageClass,
UpdateFunc: func(old, new interface{}) { UpdateFunc: func(old, new interface{}) {
...@@ -161,6 +165,10 @@ func (c *StorageCapabilityController) Run(threadCnt int, stopCh <-chan struct{}) ...@@ -161,6 +165,10 @@ func (c *StorageCapabilityController) Run(threadCnt int, stopCh <-chan struct{})
c.csiDriverSynced, c.csiDriverSynced,
} }
if c.snapshotAllowed() {
cacheSyncs = append(cacheSyncs, c.snapshotClassSynced)
}
if ok := cache.WaitForCacheSync(stopCh, cacheSyncs...); !ok { if ok := cache.WaitForCacheSync(stopCh, cacheSyncs...); !ok {
return fmt.Errorf("failed to wait for caches to sync") return fmt.Errorf("failed to wait for caches to sync")
} }
...@@ -250,7 +258,7 @@ func (c *StorageCapabilityController) syncHandler(key string) error { ...@@ -250,7 +258,7 @@ func (c *StorageCapabilityController) syncHandler(key string) error {
if err != nil { if err != nil {
// StorageClass has been deleted, delete StorageClassCapability and VolumeSnapshotClass // StorageClass has been deleted, delete StorageClassCapability and VolumeSnapshotClass
if errors.IsNotFound(err) { if errors.IsNotFound(err) {
if c.snapshotSupported { if c.snapshotAllowed() {
err = c.deleteSnapshotClass(name) err = c.deleteSnapshotClass(name)
if err != nil { if err != nil {
return err return err
...@@ -280,7 +288,7 @@ func (c *StorageCapabilityController) syncHandler(key string) error { ...@@ -280,7 +288,7 @@ func (c *StorageCapabilityController) syncHandler(key string) error {
// Handle VolumeSnapshotClass with same name of StorageClass // Handle VolumeSnapshotClass with same name of StorageClass
// annotate "support-snapshot" of StorageClass // annotate "support-snapshot" of StorageClass
withSnapshotCapability := false withSnapshotCapability := false
if c.snapshotSupported && capabilitySpec.Features.Snapshot.Create { if c.snapshotAllowed() && capabilitySpec.Features.Snapshot.Create {
_, err = c.snapshotClassLister.Get(name) _, err = c.snapshotClassLister.Get(name)
if err != nil { if err != nil {
// If VolumeSnapshotClass not exist, create it // If VolumeSnapshotClass not exist, create it
...@@ -356,7 +364,7 @@ func (c *StorageCapabilityController) deleteStorageCapability(name string) error ...@@ -356,7 +364,7 @@ func (c *StorageCapabilityController) deleteStorageCapability(name string) error
} }
func (c *StorageCapabilityController) deleteSnapshotClass(name string) error { func (c *StorageCapabilityController) deleteSnapshotClass(name string) error {
if !c.snapshotSupported { if !c.snapshotAllowed() {
return nil return nil
} }
_, err := c.snapshotClassLister.Get(name) _, err := c.snapshotClassLister.Get(name)
...@@ -429,6 +437,10 @@ func (c *StorageCapabilityController) setCSIAddressGetter(getter csiAddressGette ...@@ -429,6 +437,10 @@ func (c *StorageCapabilityController) setCSIAddressGetter(getter csiAddressGette
c.csiAddressGetter = getter c.csiAddressGetter = getter
} }
func (c *StorageCapabilityController) snapshotAllowed() bool {
return c.snapshotSupported && c.snapshotClassClient != nil && c.snapshotClassLister != nil && c.snapshotClassSynced != nil
}
func SnapshotSupported(discoveryInterface discovery.DiscoveryInterface) bool { func SnapshotSupported(discoveryInterface discovery.DiscoveryInterface) bool {
minVer := version.MustParseGeneric(minSnapshotSupportedVersion) minVer := version.MustParseGeneric(minSnapshotSupportedVersion)
rawVer, err := discoveryInterface.ServerVersion() rawVer, err := discoveryInterface.ServerVersion()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册