forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 131
OCPBUGS-11146: Enable CSI migration configuration via env vars #1514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
openshift-merge-robot
merged 4 commits into
openshift:release-4.13
from
dobsonj:STOR-1270
Apr 19, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8d0fd27
UPSTREAM: 116396: Unlock CSIMigrationvSphere feature gate until there…
dobsonj ee8faf4
UPSTREAM: <carry>: STOR-1270: Restore carry patch that enables CSI mi…
dobsonj 152fe4e
UPSTREAM: <carry>: STOR-1270: Enable CSI migration configuration via …
dobsonj 67514bd
UPSTREAM: <carry>: STOR-1270: Admission plugin to deny deletion of st…
dobsonj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...rver/admission/customresourcevalidation/operator/deny_delete_cluster_operator_resource.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package operator | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "io" | ||
|
|
||
| "k8s.io/apiserver/pkg/admission" | ||
| ) | ||
|
|
||
| const PluginName = "operator.openshift.io/DenyDeleteClusterOperators" | ||
|
|
||
| // Register registers an admission plugin factory whose plugin prevents the deletion of cluster operator resources. | ||
| func Register(plugins *admission.Plugins) { | ||
| plugins.Register(PluginName, func(config io.Reader) (admission.Interface, error) { | ||
| return newAdmissionPlugin(), nil | ||
| }) | ||
| } | ||
|
|
||
| var _ admission.ValidationInterface = &admissionPlugin{} | ||
|
|
||
| type admissionPlugin struct { | ||
| *admission.Handler | ||
| } | ||
|
|
||
| func newAdmissionPlugin() *admissionPlugin { | ||
| return &admissionPlugin{Handler: admission.NewHandler(admission.Delete)} | ||
| } | ||
|
|
||
| // Validate returns an error if there is an attempt to delete a cluster operator resource. | ||
| func (p *admissionPlugin) Validate(ctx context.Context, attributes admission.Attributes, _ admission.ObjectInterfaces) error { | ||
| if len(attributes.GetSubresource()) > 0 { | ||
| return nil | ||
| } | ||
| if attributes.GetResource().Group != "operator.openshift.io" { | ||
| return nil | ||
| } | ||
| switch attributes.GetResource().Resource { | ||
| // Deletion is denied for storages.operator.openshift.io objects named cluster, | ||
| // because MCO and KCM-O depend on this resource being present in order to | ||
| // correctly set environment variables on kubelet and kube-controller-manager. | ||
| case "storages": | ||
| if attributes.GetName() != "cluster" { | ||
| return nil | ||
| } | ||
| // Deletion is allowed for all other operator.openshift.io objects unless | ||
| // explicitly listed above. | ||
| default: | ||
| return nil | ||
| } | ||
| return admission.NewForbidden(attributes, fmt.Errorf("deleting required %s.%s resource, named %s, is not allowed", attributes.GetResource().Resource, attributes.GetResource().Group, attributes.GetName())) | ||
| } | ||
73 changes: 73 additions & 0 deletions
73
...admission/customresourcevalidation/operator/deny_delete_cluster_operator_resource_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package operator | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "k8s.io/apimachinery/pkg/runtime/schema" | ||
| "k8s.io/apiserver/pkg/admission" | ||
| ) | ||
|
|
||
| func TestAdmissionPlugin_Validate(t *testing.T) { | ||
| testCases := []struct { | ||
| tcName string | ||
| group string | ||
| resource string | ||
| name string | ||
| denyDelete bool | ||
| }{ | ||
| { | ||
| tcName: "NotBlackListedResourceNamedCluster", | ||
| group: "operator.openshift.io", | ||
| resource: "notBlacklisted", | ||
| name: "cluster", | ||
| denyDelete: false, | ||
| }, | ||
| { | ||
| tcName: "NotBlackListedResourceNamedNotCluster", | ||
| group: "operator.openshift.io", | ||
| resource: "notBlacklisted", | ||
| name: "notCluster", | ||
| denyDelete: false, | ||
| }, | ||
| { | ||
| tcName: "StorageResourceNamedCluster", | ||
| group: "operator.openshift.io", | ||
| resource: "storages", | ||
| name: "cluster", | ||
| denyDelete: true, | ||
| }, | ||
| { | ||
| tcName: "StorageResourceNamedNotCluster", | ||
| group: "operator.openshift.io", | ||
| resource: "storages", | ||
| name: "notCluster", | ||
| denyDelete: false, | ||
| }, | ||
| { | ||
| tcName: "ClusterVersionNotVersion", | ||
| group: "config.openshift.io", | ||
| resource: "clusterversions", | ||
| name: "instance", | ||
| denyDelete: false, | ||
| }, | ||
| { | ||
| tcName: "OtherGroup", | ||
| group: "not.operator.openshift.io", | ||
| resource: "notBlacklisted", | ||
| name: "cluster", | ||
| denyDelete: false, | ||
| }, | ||
| } | ||
| for _, tc := range testCases { | ||
| t.Run(tc.tcName, func(t *testing.T) { | ||
| err := newAdmissionPlugin().Validate(context.TODO(), admission.NewAttributesRecord( | ||
| nil, nil, schema.GroupVersionKind{}, "", | ||
| tc.name, schema.GroupVersionResource{Group: tc.group, Resource: tc.resource}, | ||
| "", admission.Delete, nil, false, nil), nil) | ||
| if tc.denyDelete != (err != nil) { | ||
| t.Error(tc.denyDelete, err) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package features | ||
|
|
||
| import ( | ||
| "os" | ||
|
|
||
| "k8s.io/apimachinery/pkg/util/runtime" | ||
| utilfeature "k8s.io/apiserver/pkg/util/feature" | ||
| "k8s.io/component-base/featuregate" | ||
| ) | ||
|
|
||
| var ( | ||
| // owner: @fbertina | ||
| // beta: v1.23 | ||
| // | ||
| // Enables the vSphere CSI migration for the Attach/Detach controller (ADC) only. | ||
| ADCCSIMigrationVSphere featuregate.Feature = "ADC_CSIMigrationVSphere" | ||
dobsonj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| var ocpDefaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{ | ||
| ADCCSIMigrationVSphere: {Default: true, PreRelease: featuregate.GA}, | ||
| } | ||
|
|
||
| func OpenShiftStartCSIMigrationVSphere() bool { | ||
| _, migrationEnabled := os.LookupEnv("OPENSHIFT_DO_VSPHERE_MIGRATION") | ||
| return migrationEnabled | ||
| } | ||
|
|
||
| func init() { | ||
| runtime.Must(utilfeature.DefaultMutableFeatureGate.Add(ocpDefaultKubernetesFeatureGates)) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| 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 { | ||
dobsonj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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.VSphereInTreePluginName: | ||
| return pm.featureGate.Enabled(features.ADCCSIMigrationVSphere) | ||
| 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) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this is equivalent to the following, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it's equivalent, but I like the more verbose form because it's easier to add new objects that should not be deleted in the future, and it also matches the form in this admission plugin for config objects.