config.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 config
  14. import (
  15. apiserver "k8s.io/apiserver/pkg/server"
  16. "k8s.io/client-go/informers"
  17. coreinformers "k8s.io/client-go/informers/core/v1"
  18. clientset "k8s.io/client-go/kubernetes"
  19. v1core "k8s.io/client-go/kubernetes/typed/core/v1"
  20. "k8s.io/client-go/kubernetes/typed/events/v1beta1"
  21. restclient "k8s.io/client-go/rest"
  22. "k8s.io/client-go/tools/events"
  23. "k8s.io/client-go/tools/leaderelection"
  24. "k8s.io/client-go/tools/record"
  25. kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
  26. )
  27. // Config has all the context to run a Scheduler
  28. type Config struct {
  29. // ComponentConfig is the scheduler server's configuration object.
  30. ComponentConfig kubeschedulerconfig.KubeSchedulerConfiguration
  31. // LoopbackClientConfig is a config for a privileged loopback connection
  32. LoopbackClientConfig *restclient.Config
  33. InsecureServing *apiserver.DeprecatedInsecureServingInfo // nil will disable serving on an insecure port
  34. InsecureMetricsServing *apiserver.DeprecatedInsecureServingInfo // non-nil if metrics should be served independently
  35. Authentication apiserver.AuthenticationInfo
  36. Authorization apiserver.AuthorizationInfo
  37. SecureServing *apiserver.SecureServingInfo
  38. Client clientset.Interface
  39. InformerFactory informers.SharedInformerFactory
  40. PodInformer coreinformers.PodInformer
  41. // TODO: Remove the following after fully migrating to the new events api.
  42. CoreEventClient v1core.EventsGetter
  43. CoreBroadcaster record.EventBroadcaster
  44. EventClient v1beta1.EventsGetter
  45. Recorder events.EventRecorder
  46. Broadcaster events.EventBroadcaster
  47. // LeaderElection is optional.
  48. LeaderElection *leaderelection.LeaderElectionConfig
  49. }
  50. type completedConfig struct {
  51. *Config
  52. }
  53. // CompletedConfig same as Config, just to swap private object.
  54. type CompletedConfig struct {
  55. // Embed a private pointer that cannot be instantiated outside of this package.
  56. *completedConfig
  57. }
  58. // Complete fills in any fields not set that are required to have valid data. It's mutating the receiver.
  59. func (c *Config) Complete() CompletedConfig {
  60. cc := completedConfig{c}
  61. if c.InsecureServing != nil {
  62. c.InsecureServing.Name = "healthz"
  63. }
  64. if c.InsecureMetricsServing != nil {
  65. c.InsecureMetricsServing.Name = "metrics"
  66. }
  67. apiserver.AuthorizeClientBearerToken(c.LoopbackClientConfig, &c.Authentication, &c.Authorization)
  68. return CompletedConfig{&cc}
  69. }