kubecloudshared.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. Copyright 2018 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. "github.com/spf13/pflag"
  16. kubectrlmgrconfig "k8s.io/kubernetes/pkg/controller/apis/config"
  17. )
  18. // KubeCloudSharedOptions holds the options shared between kube-controller-manager
  19. // and cloud-controller-manager.
  20. type KubeCloudSharedOptions struct {
  21. *kubectrlmgrconfig.KubeCloudSharedConfiguration
  22. CloudProvider *CloudProviderOptions
  23. }
  24. // NewKubeCloudSharedOptions returns common/default configuration values for both
  25. // the kube-controller-manager and the cloud-contoller-manager. Any common changes should
  26. // be made here. Any individual changes should be made in that controller.
  27. func NewKubeCloudSharedOptions(cfg *kubectrlmgrconfig.KubeCloudSharedConfiguration) *KubeCloudSharedOptions {
  28. o := &KubeCloudSharedOptions{
  29. KubeCloudSharedConfiguration: cfg,
  30. CloudProvider: &CloudProviderOptions{
  31. CloudProviderConfiguration: &kubectrlmgrconfig.CloudProviderConfiguration{},
  32. },
  33. }
  34. return o
  35. }
  36. // AddFlags adds flags related to shared variable for controller manager to the specified FlagSet.
  37. func (o *KubeCloudSharedOptions) AddFlags(fs *pflag.FlagSet) {
  38. if o == nil {
  39. return
  40. }
  41. o.CloudProvider.AddFlags(fs)
  42. fs.StringVar(&o.ExternalCloudVolumePlugin, "external-cloud-volume-plugin", o.ExternalCloudVolumePlugin, "The plugin to use when cloud provider is set to external. Can be empty, should only be set when cloud-provider is external. Currently used to allow node and volume controllers to work for in tree cloud providers.")
  43. fs.BoolVar(&o.UseServiceAccountCredentials, "use-service-account-credentials", o.UseServiceAccountCredentials, "If true, use individual service account credentials for each controller.")
  44. fs.BoolVar(&o.AllowUntaggedCloud, "allow-untagged-cloud", false, "Allow the cluster to run without the cluster-id on cloud instances. This is a legacy mode of operation and a cluster-id will be required in the future.")
  45. fs.MarkDeprecated("allow-untagged-cloud", "This flag is deprecated and will be removed in a future release. A cluster-id will be required on cloud instances.")
  46. fs.DurationVar(&o.RouteReconciliationPeriod.Duration, "route-reconciliation-period", o.RouteReconciliationPeriod.Duration, "The period for reconciling routes created for Nodes by cloud provider.")
  47. fs.DurationVar(&o.NodeMonitorPeriod.Duration, "node-monitor-period", o.NodeMonitorPeriod.Duration,
  48. "The period for syncing NodeStatus in NodeController.")
  49. fs.StringVar(&o.ClusterName, "cluster-name", o.ClusterName, "The instance prefix for the cluster.")
  50. fs.StringVar(&o.ClusterCIDR, "cluster-cidr", o.ClusterCIDR, "CIDR Range for Pods in cluster. Requires --allocate-node-cidrs to be true")
  51. fs.BoolVar(&o.AllocateNodeCIDRs, "allocate-node-cidrs", false, "Should CIDRs for Pods be allocated and set on the cloud provider.")
  52. fs.StringVar(&o.CIDRAllocatorType, "cidr-allocator-type", "RangeAllocator", "Type of CIDR allocator to use")
  53. fs.BoolVar(&o.ConfigureCloudRoutes, "configure-cloud-routes", true, "Should CIDRs allocated by allocate-node-cidrs be configured on the cloud provider.")
  54. fs.DurationVar(&o.NodeSyncPeriod.Duration, "node-sync-period", 0, ""+
  55. "This flag is deprecated and will be removed in future releases. See node-monitor-period for Node health checking or "+
  56. "route-reconciliation-period for cloud provider's route configuration settings.")
  57. fs.MarkDeprecated("node-sync-period", "This flag is currently no-op and will be deleted.")
  58. }
  59. // ApplyTo fills up KubeCloudShared config with options.
  60. func (o *KubeCloudSharedOptions) ApplyTo(cfg *kubectrlmgrconfig.KubeCloudSharedConfiguration) error {
  61. if o == nil {
  62. return nil
  63. }
  64. if err := o.CloudProvider.ApplyTo(&cfg.CloudProvider); err != nil {
  65. return err
  66. }
  67. cfg.ExternalCloudVolumePlugin = o.ExternalCloudVolumePlugin
  68. cfg.UseServiceAccountCredentials = o.UseServiceAccountCredentials
  69. cfg.AllowUntaggedCloud = o.AllowUntaggedCloud
  70. cfg.RouteReconciliationPeriod = o.RouteReconciliationPeriod
  71. cfg.NodeMonitorPeriod = o.NodeMonitorPeriod
  72. cfg.ClusterName = o.ClusterName
  73. cfg.ClusterCIDR = o.ClusterCIDR
  74. cfg.AllocateNodeCIDRs = o.AllocateNodeCIDRs
  75. cfg.CIDRAllocatorType = o.CIDRAllocatorType
  76. cfg.ConfigureCloudRoutes = o.ConfigureCloudRoutes
  77. cfg.NodeSyncPeriod = o.NodeSyncPeriod
  78. return nil
  79. }
  80. // Validate checks validation of KubeCloudSharedOptions.
  81. func (o *KubeCloudSharedOptions) Validate() []error {
  82. if o == nil {
  83. return nil
  84. }
  85. errs := []error{}
  86. errs = append(errs, o.CloudProvider.Validate()...)
  87. return errs
  88. }