Skip to content

Commit 52a9f18

Browse files
authored
Merge pull request kubernetes#81826 from thockin/service-drop-disabled-fields
Add dropDisbledFields() to service
2 parents 5cc31b7 + ec60426 commit 52a9f18

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pkg/registry/core/service/strategy.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,17 @@ func (svcStrategy) NamespaceScoped() bool {
4747
func (svcStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
4848
service := obj.(*api.Service)
4949
service.Status = api.ServiceStatus{}
50+
51+
dropServiceDisabledFields(service, nil)
5052
}
5153

5254
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
5355
func (svcStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
5456
newService := obj.(*api.Service)
5557
oldService := old.(*api.Service)
5658
newService.Status = oldService.Status
59+
60+
dropServiceDisabledFields(newService, oldService)
5761
}
5862

5963
// Validate validates a new service.
@@ -104,6 +108,14 @@ func (svcStrategy) Export(ctx context.Context, obj runtime.Object, exact bool) e
104108
return nil
105109
}
106110

111+
// dropServiceDisabledFields drops fields that are not used if their associated feature gates
112+
// are not enabled. The typical pattern is:
113+
// if !utilfeature.DefaultFeatureGate.Enabled(features.MyFeature) && !myFeatureInUse(oldSvc) {
114+
// newSvc.Spec.MyFeature = nil
115+
// }
116+
func dropServiceDisabledFields(newSvc *api.Service, oldSvc *api.Service) {
117+
}
118+
107119
type serviceStatusStrategy struct {
108120
svcStrategy
109121
}

0 commit comments

Comments
 (0)