util.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. Copyright 2019 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package resourcequota
  14. import (
  15. utilfeature "k8s.io/apiserver/pkg/util/feature"
  16. api "k8s.io/kubernetes/pkg/apis/core"
  17. "k8s.io/kubernetes/pkg/features"
  18. )
  19. // DropDisabledFields removes disabled fields from the ResourceQuota spec.
  20. // This should be called from PrepareForCreate/PrepareForUpdate for all resources containing a ResourceQuota spec.
  21. func DropDisabledFields(resSpec *api.ResourceQuotaSpec, oldResSpec *api.ResourceQuotaSpec) {
  22. if !utilfeature.DefaultFeatureGate.Enabled(features.ResourceQuotaScopeSelectors) && !resourceQuotaScopeSelectorInUse(oldResSpec) {
  23. resSpec.ScopeSelector = nil
  24. }
  25. }
  26. func resourceQuotaScopeSelectorInUse(oldResSpec *api.ResourceQuotaSpec) bool {
  27. if oldResSpec == nil {
  28. return false
  29. }
  30. if oldResSpec.ScopeSelector != nil {
  31. return true
  32. }
  33. return false
  34. }