Merge pull request #3040 from liggitt/feature-gate
Update feature gate and alpha field guidance
This commit is contained in:
commit
b20003f0b8
|
@ -927,8 +927,10 @@ The preferred approach adds an alpha field to the existing object, and ensures i
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Before persisting the object to storage, clear disabled alpha fields.
|
3. Before persisting the object to storage, clear disabled alpha fields on create,
|
||||||
One possible place to do this is in the REST storage strategy's PrepareForCreate/PrepareForUpdate methods:
|
and on update if the existing object does not already have a value in the field.
|
||||||
|
This prevents new usage of the feature while it is disabled, while ensuring existing data is preserved.
|
||||||
|
The recommended place to do this is in the REST storage strategy's PrepareForCreate/PrepareForUpdate methods:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func (frobberStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Object) {
|
func (frobberStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Object) {
|
||||||
|
@ -943,30 +945,24 @@ One possible place to do this is in the REST storage strategy's PrepareForCreate
|
||||||
newFrobber := obj.(*api.Frobber)
|
newFrobber := obj.(*api.Frobber)
|
||||||
oldFrobber := old.(*api.Frobber)
|
oldFrobber := old.(*api.Frobber)
|
||||||
|
|
||||||
if !utilfeature.DefaultFeatureGate.Enabled(features.Frobber2D) {
|
if !utilfeature.DefaultFeatureGate.Enabled(features.Frobber2D) && oldFrobber.Width == nil {
|
||||||
newFrobber.Width = nil
|
newFrobber.Width = nil
|
||||||
oldFrobber.Width = nil
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
4. In validation, ensure the alpha field is not set if the feature gate is disabled (covers cases we might miss in the above):
|
4. In validation, validate the field if present:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func ValidateFrobber(f *api.Frobber, fldPath *field.Path) field.ErrorList {
|
func ValidateFrobber(f *api.Frobber, fldPath *field.Path) field.ErrorList {
|
||||||
...
|
...
|
||||||
if utilfeature.DefaultFeatureGate.Enabled(features.Frobber2D) {
|
if f.Width != nil {
|
||||||
... normal validation of width field ...
|
... validation of width field ...
|
||||||
} else if f.Width != nil {
|
|
||||||
allErrs = append(allErrs, field.Forbidden(fldPath.Child("width"), "disabled by feature-gate"))
|
|
||||||
}
|
}
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Eventually, the API machinery will handle a lot of these things automatically from
|
|
||||||
declarative inputs.
|
|
||||||
|
|
||||||
In future Kubernetes versions:
|
In future Kubernetes versions:
|
||||||
|
|
||||||
* if the feature progresses to beta or stable status, the feature gate can be removed or be enabled by default.
|
* if the feature progresses to beta or stable status, the feature gate can be removed or be enabled by default.
|
||||||
|
|
Loading…
Reference in New Issue