config.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. clientset "k8s.io/client-go/kubernetes"
  17. restclient "k8s.io/client-go/rest"
  18. "k8s.io/client-go/tools/record"
  19. kubectrlmgrconfig "k8s.io/kubernetes/pkg/controller/apis/config"
  20. )
  21. // Config is the main context object for the controller manager.
  22. type Config struct {
  23. ComponentConfig kubectrlmgrconfig.KubeControllerManagerConfiguration
  24. SecureServing *apiserver.SecureServingInfo
  25. // LoopbackClientConfig is a config for a privileged loopback connection
  26. LoopbackClientConfig *restclient.Config
  27. // TODO: remove deprecated insecure serving
  28. InsecureServing *apiserver.DeprecatedInsecureServingInfo
  29. Authentication apiserver.AuthenticationInfo
  30. Authorization apiserver.AuthorizationInfo
  31. // the general kube client
  32. Client *clientset.Clientset
  33. // the client only used for leader election
  34. LeaderElectionClient *clientset.Clientset
  35. // the rest config for the master
  36. Kubeconfig *restclient.Config
  37. // the event sink
  38. EventRecorder record.EventRecorder
  39. }
  40. type completedConfig struct {
  41. *Config
  42. }
  43. // CompletedConfig same as Config, just to swap private object.
  44. type CompletedConfig struct {
  45. // Embed a private pointer that cannot be instantiated outside of this package.
  46. *completedConfig
  47. }
  48. // Complete fills in any fields not set that are required to have valid data. It's mutating the receiver.
  49. func (c *Config) Complete() *CompletedConfig {
  50. cc := completedConfig{c}
  51. apiserver.AuthorizeClientBearerToken(c.LoopbackClientConfig, &c.Authentication, &c.Authorization)
  52. return &CompletedConfig{&cc}
  53. }