From ec604267934b72dcbd467659c8db6041f08050dd Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Thu, 22 Aug 2019 21:36:17 -0700 Subject: [PATCH] Add dropDisbledFields() to service --- pkg/registry/core/service/strategy.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/registry/core/service/strategy.go b/pkg/registry/core/service/strategy.go index d296a613116..1955944604a 100644 --- a/pkg/registry/core/service/strategy.go +++ b/pkg/registry/core/service/strategy.go @@ -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 }