Skip to content

Commit

Permalink
UPSTREAM: <carry>: openshift KCM volume plugin manager uses a disjoin…
Browse files Browse the repository at this point in the history
…t set of featuregates

The volume plugin manager for openshfit's Attach Detach controller in
kube-controller-manager uses a set of featuregates that are NOT the same as
the the other controllers in KCM and the kubelet.

This means these featuregates (if we kept the old names) would be
inconsistent inside of a single binary. There are now separate featuregates
for the volumepluginmanger when running in the Attach Detach controller to
reflect this distintion.

See openshift/enhancements#549 for details.

Stop <carrying> the patch when CSI migration becomes GA (i.e.
features.CSIMigrationAWS / features.CSIMigrationOpenStack are GA).
  • Loading branch information
jsafrane committed Apr 7, 2021
1 parent dd7e566 commit 2d9a8f9
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func NewAttachDetachController(

csiTranslator := csitrans.New()
adc.intreeToCSITranslator = csiTranslator
adc.csiMigratedPluginManager = csimigration.NewPluginManager(csiTranslator, utilfeature.DefaultFeatureGate)
adc.csiMigratedPluginManager = csimigration.NewADCPluginManager(csiTranslator, utilfeature.DefaultFeatureGate)

adc.desiredStateOfWorldPopulator = populator.NewDesiredStateOfWorldPopulator(
timerConfig.DesiredStateOfWorldPopulatorLoopSleepPeriod,
Expand Down
30 changes: 30 additions & 0 deletions pkg/features/patch_kube_features.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package features

import (
"k8s.io/apimachinery/pkg/util/runtime"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/component-base/featuregate"
)

var (
// owner: @jsafrane
// alpha: v1.21
//
// Enables the AWS EBS CSI migration for the Attach/Detach controller (ADC) only.
ADCCSIMigrationAWS featuregate.Feature = "ADC_CSIMigrationAWS"

// owner: @jsafrane
// alpha: v1.21
//
// Enables the Cinder CSI migration for the Attach/Detach controller (ADC) only.
ADCCSIMigrationCinder featuregate.Feature = "ADC_CSIMigrationCinder"
)

var ocpDefaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{
ADCCSIMigrationAWS: {Default: true, PreRelease: featuregate.Beta},
ADCCSIMigrationCinder: {Default: true, PreRelease: featuregate.Beta},
}

func init() {
runtime.Must(utilfeature.DefaultMutableFeatureGate.Add(ocpDefaultKubernetesFeatureGates))
}
44 changes: 44 additions & 0 deletions pkg/volume/csimigration/patch_adc_plugin_manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package csimigration

import (
"k8s.io/component-base/featuregate"
csilibplugins "k8s.io/csi-translation-lib/plugins"
"k8s.io/kubernetes/pkg/features"
)

// NewADCPluginManager returns a new PluginManager instance for the Attach Detach controller which uses different
// featuregates in openshift to control enablement/disablement which *DO NOT MATCH* the featuregates for the rest of the
// cluster.
func NewADCPluginManager(m PluginNameMapper, featureGate featuregate.FeatureGate) PluginManager {
ret := NewPluginManager(m, featureGate)
ret.useADCPluginManagerFeatureGates = true
return ret
}

// adcIsMigrationEnabledForPlugin indicates whether CSI migration has been enabled
// for a particular storage plugin in Attach/Detach controller.
func (pm PluginManager) adcIsMigrationEnabledForPlugin(pluginName string) bool {
// CSIMigration feature should be enabled along with the plugin-specific one
if !pm.featureGate.Enabled(features.CSIMigration) {
return false
}

switch pluginName {
case csilibplugins.AWSEBSInTreePluginName:
return pm.featureGate.Enabled(features.ADCCSIMigrationAWS)
case csilibplugins.CinderInTreePluginName:
return pm.featureGate.Enabled(features.ADCCSIMigrationCinder)
default:
return pm.isMigrationEnabledForPlugin(pluginName)
}
}

// IsMigrationEnabledForPlugin indicates whether CSI migration has been enabled
// for a particular storage plugin
func (pm PluginManager) IsMigrationEnabledForPlugin(pluginName string) bool {
if pm.useADCPluginManagerFeatureGates {
return pm.adcIsMigrationEnabledForPlugin(pluginName)
}

return pm.isMigrationEnabledForPlugin(pluginName)
}
6 changes: 3 additions & 3 deletions pkg/volume/csimigration/plugin_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type PluginNameMapper interface {
type PluginManager struct {
PluginNameMapper
featureGate featuregate.FeatureGate

useADCPluginManagerFeatureGates bool
}

// NewPluginManager returns a new PluginManager instance
Expand Down Expand Up @@ -77,9 +79,7 @@ func (pm PluginManager) IsMigrationCompleteForPlugin(pluginName string) bool {
}
}

// IsMigrationEnabledForPlugin indicates whether CSI migration has been enabled
// for a particular storage plugin
func (pm PluginManager) IsMigrationEnabledForPlugin(pluginName string) bool {
func (pm PluginManager) isMigrationEnabledForPlugin(pluginName string) bool {
// CSIMigration feature should be enabled along with the plugin-specific one
if !pm.featureGate.Enabled(features.CSIMigration) {
return false
Expand Down

0 comments on commit 2d9a8f9

Please sign in to comment.