policy_restricted.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 topologymanager
  14. type restrictedPolicy struct {
  15. bestEffortPolicy
  16. }
  17. var _ Policy = &restrictedPolicy{}
  18. // PolicyRestricted policy name.
  19. const PolicyRestricted string = "restricted"
  20. // NewRestrictedPolicy returns restricted policy.
  21. func NewRestrictedPolicy(numaNodes []int) Policy {
  22. return &restrictedPolicy{bestEffortPolicy{numaNodes: numaNodes}}
  23. }
  24. func (p *restrictedPolicy) Name() string {
  25. return PolicyRestricted
  26. }
  27. func (p *restrictedPolicy) canAdmitPodResult(hint *TopologyHint) bool {
  28. if !hint.Preferred {
  29. return false
  30. }
  31. return true
  32. }
  33. func (p *restrictedPolicy) Merge(providersHints []map[string][]TopologyHint) (TopologyHint, bool) {
  34. filteredHints := filterProvidersHints(providersHints)
  35. hint := mergeFilteredHints(p.numaNodes, filteredHints)
  36. admit := p.canAdmitPodResult(&hint)
  37. return hint, admit
  38. }