-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Add VolumeBindingMode to StorageClass API #54436
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package util | ||
|
||
import ( | ||
utilfeature "k8s.io/apiserver/pkg/util/feature" | ||
"k8s.io/kubernetes/pkg/apis/storage" | ||
"k8s.io/kubernetes/pkg/features" | ||
) | ||
|
||
// DropDisabledAlphaFields removes disabled fields from the StorageClass object. | ||
func DropDisabledAlphaFields(class *storage.StorageClass) { | ||
if !utilfeature.DefaultFeatureGate.Enabled(features.VolumeScheduling) { | ||
class.VolumeBindingMode = nil | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package util | ||
|
||
import ( | ||
"testing" | ||
|
||
utilfeature "k8s.io/apiserver/pkg/util/feature" | ||
"k8s.io/kubernetes/pkg/apis/storage" | ||
) | ||
|
||
func TestDropAlphaFields(t *testing.T) { | ||
bindingMode := storage.VolumeBindingWaitForFirstConsumer | ||
|
||
// Test that field gets dropped when feature gate is not set | ||
class := &storage.StorageClass{ | ||
VolumeBindingMode: &bindingMode, | ||
} | ||
DropDisabledAlphaFields(class) | ||
if class.VolumeBindingMode != nil { | ||
t.Errorf("VolumeBindingMode field didn't get dropped: %+v", class.VolumeBindingMode) | ||
} | ||
|
||
// Test that field does not get dropped when feature gate is set | ||
class = &storage.StorageClass{ | ||
VolumeBindingMode: &bindingMode, | ||
} | ||
if err := utilfeature.DefaultFeatureGate.Set("VolumeScheduling=true"); err != nil { | ||
t.Fatalf("Failed to set feature gate for VolumeScheduling: %v", err) | ||
} | ||
DropDisabledAlphaFields(class) | ||
if class.VolumeBindingMode != &bindingMode { | ||
t.Errorf("VolumeBindingMode field got unexpectantly modified: %+v", class.VolumeBindingMode) | ||
} | ||
if err := utilfeature.DefaultFeatureGate.Set("VolumeScheduling=false"); err != nil { | ||
t.Fatalf("Failed to disable feature gate for VolumeScheduling: %v", err) | ||
} | ||
} |
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.
This doesn't work with upgrades. Need to discuss with @kubernetes/sig-api-machinery-pr-reviews if it's possible to default new alpha fields.
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.
When gate disabled, they should not be persisted or returned from the API, so… not really
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.
Discussed with @thockin and @lavalamp and verified that defaults are applied on read to objects that were stored with a nil field. So we can default new fields under a feature gate as long as we also access the fields under the feature gate.
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.
Doesn't that mean the default values are serialized back out and returned to API clients even when the gate is disabled? If so, that isn't what we want
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.
Ah, you're saying the defaulting itself would be gated. I thought I looked into that at one point and it resulted in weird (and possibly circular) dependencies, but maybe I'm misremembering
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.
Here's a scenario I'm not sure how to handle:
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.
it doesn't (and shouldn't). the old object decoded from etcd will get the default, get sent to the user, and any update coming from the user without that value will also get the default. from validation's perspective, both the old and new object will have the default value, so the field will not appear to have changed.