statefulsetcontroller.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 options
  14. import (
  15. "fmt"
  16. "github.com/spf13/pflag"
  17. statefulsetconfig "k8s.io/kubernetes/pkg/controller/statefulset/config"
  18. )
  19. // StatefulSetControllerOptions holds the StatefulSetController options.
  20. type StatefulSetControllerOptions struct {
  21. *statefulsetconfig.StatefulSetControllerConfiguration
  22. }
  23. // AddFlags adds flags related to StatefulSetController for controller manager to the specified FlagSet.
  24. func (o *StatefulSetControllerOptions) AddFlags(fs *pflag.FlagSet) {
  25. if o == nil {
  26. return
  27. }
  28. fs.Int32Var(&o.ConcurrentStatefulSetSyncs, "concurrent-statefulset-syncs", o.ConcurrentStatefulSetSyncs, "The number of statefulset objects that are allowed to sync concurrently. Larger number = more responsive statefulsets, but more CPU (and network) load")
  29. }
  30. // ApplyTo fills up StatefulSetController config with options.
  31. func (o *StatefulSetControllerOptions) ApplyTo(cfg *statefulsetconfig.StatefulSetControllerConfiguration) error {
  32. if o == nil {
  33. return nil
  34. }
  35. cfg.ConcurrentStatefulSetSyncs = o.ConcurrentStatefulSetSyncs
  36. return nil
  37. }
  38. // Validate checks validation of StatefulSetControllerOptions.
  39. func (o *StatefulSetControllerOptions) Validate() []error {
  40. if o == nil {
  41. return nil
  42. }
  43. errs := []error{}
  44. if o.ConcurrentStatefulSetSyncs < 1 {
  45. errs = append(errs, fmt.Errorf("concurrent-statefulset-syncs must be greater than 0, but got %d", o.ConcurrentStatefulSetSyncs))
  46. }
  47. return errs
  48. }