validation.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. Copyright 2015 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 validation
  14. import (
  15. "fmt"
  16. utilerrors "k8s.io/kubernetes/pkg/util/errors"
  17. schedulerapi "k8s.io/kubernetes/plugin/pkg/scheduler/api"
  18. )
  19. // Validate checks for errors in the Config
  20. // It does not return early so that it can find as many errors as possible
  21. func ValidatePolicy(policy schedulerapi.Policy) error {
  22. validationErrors := make([]error, 0)
  23. for _, priority := range policy.Priorities {
  24. if priority.Weight <= 0 {
  25. validationErrors = append(validationErrors, fmt.Errorf("Priority %s should have a positive weight applied to it", priority.Name))
  26. }
  27. }
  28. for _, extender := range policy.ExtenderConfigs {
  29. if extender.Weight < 0 {
  30. validationErrors = append(validationErrors, fmt.Errorf("Priority for extender %s should have a non negative weight applied to it", extender.URLPrefix))
  31. }
  32. }
  33. return utilerrors.NewAggregate(validationErrors)
  34. }