Merge pull request #81826 from thockin/service-drop-disabled-fields

Add dropDisbledFields() to service
This commit is contained in:
Kubernetes Prow Robot 2019-08-23 08:23:58 -07:00 committed by GitHub
commit 52a9f18b07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -47,6 +47,8 @@ func (svcStrategy) NamespaceScoped() bool {
func (svcStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
service := obj.(*api.Service)
service.Status = api.ServiceStatus{}
dropServiceDisabledFields(service, nil)
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
@ -54,6 +56,8 @@ func (svcStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object
newService := obj.(*api.Service)
oldService := old.(*api.Service)
newService.Status = oldService.Status
dropServiceDisabledFields(newService, oldService)
}
// Validate validates a new service.
@ -104,6 +108,14 @@ func (svcStrategy) Export(ctx context.Context, obj runtime.Object, exact bool) e
return nil
}
// dropServiceDisabledFields drops fields that are not used if their associated feature gates
// are not enabled. The typical pattern is:
// if !utilfeature.DefaultFeatureGate.Enabled(features.MyFeature) && !myFeatureInUse(oldSvc) {
// newSvc.Spec.MyFeature = nil
// }
func dropServiceDisabledFields(newSvc *api.Service, oldSvc *api.Service) {
}
type serviceStatusStrategy struct {
svcStrategy
}