options.go 5.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. Copyright 2016 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. "time"
  16. "github.com/spf13/pflag"
  17. )
  18. // VolumeConfigFlags is used to bind CLI flags to variables. This top-level struct contains *all* enumerated
  19. // CLI flags meant to configure all volume plugins. From this config, the binary will create many instances
  20. // of volume.VolumeConfig which are then passed to the appropriate plugin. The ControllerManager binary is the only
  21. // part of the code which knows what plugins are supported and which CLI flags correspond to each plugin.
  22. type VolumeConfigFlags struct {
  23. PersistentVolumeRecyclerMaximumRetry int
  24. PersistentVolumeRecyclerMinimumTimeoutNFS int
  25. PersistentVolumeRecyclerPodTemplateFilePathNFS string
  26. PersistentVolumeRecyclerIncrementTimeoutNFS int
  27. PersistentVolumeRecyclerPodTemplateFilePathHostPath string
  28. PersistentVolumeRecyclerMinimumTimeoutHostPath int
  29. PersistentVolumeRecyclerIncrementTimeoutHostPath int
  30. EnableHostPathProvisioning bool
  31. EnableDynamicProvisioning bool
  32. }
  33. type PersistentVolumeControllerOptions struct {
  34. PVClaimBinderSyncPeriod time.Duration
  35. VolumeConfigFlags VolumeConfigFlags
  36. }
  37. func NewPersistentVolumeControllerOptions() PersistentVolumeControllerOptions {
  38. return PersistentVolumeControllerOptions{
  39. PVClaimBinderSyncPeriod: 15 * time.Second,
  40. VolumeConfigFlags: VolumeConfigFlags{
  41. // default values here
  42. PersistentVolumeRecyclerMaximumRetry: 3,
  43. PersistentVolumeRecyclerMinimumTimeoutNFS: 300,
  44. PersistentVolumeRecyclerIncrementTimeoutNFS: 30,
  45. PersistentVolumeRecyclerMinimumTimeoutHostPath: 60,
  46. PersistentVolumeRecyclerIncrementTimeoutHostPath: 30,
  47. EnableHostPathProvisioning: false,
  48. EnableDynamicProvisioning: true,
  49. },
  50. }
  51. }
  52. func (o *PersistentVolumeControllerOptions) AddFlags(fs *pflag.FlagSet) {
  53. fs.DurationVar(&o.PVClaimBinderSyncPeriod, "pvclaimbinder-sync-period", o.PVClaimBinderSyncPeriod,
  54. "The period for syncing persistent volumes and persistent volume claims")
  55. fs.StringVar(&o.VolumeConfigFlags.PersistentVolumeRecyclerPodTemplateFilePathNFS,
  56. "pv-recycler-pod-template-filepath-nfs", o.VolumeConfigFlags.PersistentVolumeRecyclerPodTemplateFilePathNFS,
  57. "The file path to a pod definition used as a template for NFS persistent volume recycling")
  58. fs.IntVar(&o.VolumeConfigFlags.PersistentVolumeRecyclerMinimumTimeoutNFS, "pv-recycler-minimum-timeout-nfs",
  59. o.VolumeConfigFlags.PersistentVolumeRecyclerMinimumTimeoutNFS, "The minimum ActiveDeadlineSeconds to use for an NFS Recycler pod")
  60. fs.IntVar(&o.VolumeConfigFlags.PersistentVolumeRecyclerIncrementTimeoutNFS, "pv-recycler-increment-timeout-nfs",
  61. o.VolumeConfigFlags.PersistentVolumeRecyclerIncrementTimeoutNFS, "the increment of time added per Gi to ActiveDeadlineSeconds for an NFS scrubber pod")
  62. fs.StringVar(&o.VolumeConfigFlags.PersistentVolumeRecyclerPodTemplateFilePathHostPath, "pv-recycler-pod-template-filepath-hostpath",
  63. o.VolumeConfigFlags.PersistentVolumeRecyclerPodTemplateFilePathHostPath,
  64. "The file path to a pod definition used as a template for HostPath persistent volume recycling. "+
  65. "This is for development and testing only and will not work in a multi-node cluster.")
  66. fs.IntVar(&o.VolumeConfigFlags.PersistentVolumeRecyclerMinimumTimeoutHostPath, "pv-recycler-minimum-timeout-hostpath",
  67. o.VolumeConfigFlags.PersistentVolumeRecyclerMinimumTimeoutHostPath,
  68. "The minimum ActiveDeadlineSeconds to use for a HostPath Recycler pod. This is for development and testing only and will not work in a multi-node cluster.")
  69. fs.IntVar(&o.VolumeConfigFlags.PersistentVolumeRecyclerIncrementTimeoutHostPath, "pv-recycler-timeout-increment-hostpath",
  70. o.VolumeConfigFlags.PersistentVolumeRecyclerIncrementTimeoutHostPath,
  71. "the increment of time added per Gi to ActiveDeadlineSeconds for a HostPath scrubber pod. "+
  72. "This is for development and testing only and will not work in a multi-node cluster.")
  73. fs.IntVar(&o.VolumeConfigFlags.PersistentVolumeRecyclerMaximumRetry, "pv-recycler-maximum-retry",
  74. o.VolumeConfigFlags.PersistentVolumeRecyclerMaximumRetry,
  75. "Maximum number of attempts to recycle or delete a persistent volume")
  76. fs.BoolVar(&o.VolumeConfigFlags.EnableHostPathProvisioning, "enable-hostpath-provisioner", o.VolumeConfigFlags.EnableHostPathProvisioning,
  77. "Enable HostPath PV provisioning when running without a cloud provider. This allows testing and development of provisioning features. "+
  78. "HostPath provisioning is not supported in any way, won't work in a multi-node cluster, and should not be used for anything other than testing or development.")
  79. fs.BoolVar(&o.VolumeConfigFlags.EnableDynamicProvisioning, "enable-dynamic-provisioning", o.VolumeConfigFlags.EnableDynamicProvisioning,
  80. "Enable dynamic provisioning for environments that support it.")
  81. }