config.go 2.7 KB

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