config.go 2.5 KB

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