replication_controller.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. Copyright 2014 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. // ### ATTENTION ###
  14. //
  15. // ReplicationManager is now just a wrapper around ReplicaSetController,
  16. // with a conversion layer that effectively treats ReplicationController
  17. // as if it were an older API version of ReplicaSet.
  18. //
  19. // However, RC and RS still have separate storage and separate instantiations
  20. // of the ReplicaSetController object.
  21. package replication
  22. import (
  23. "k8s.io/api/core/v1"
  24. coreinformers "k8s.io/client-go/informers/core/v1"
  25. clientset "k8s.io/client-go/kubernetes"
  26. "k8s.io/client-go/kubernetes/scheme"
  27. v1core "k8s.io/client-go/kubernetes/typed/core/v1"
  28. "k8s.io/client-go/tools/record"
  29. "k8s.io/klog"
  30. "k8s.io/kubernetes/pkg/controller"
  31. "k8s.io/kubernetes/pkg/controller/replicaset"
  32. )
  33. const (
  34. BurstReplicas = replicaset.BurstReplicas
  35. )
  36. // ReplicationManager is responsible for synchronizing ReplicationController objects stored
  37. // in the system with actual running pods.
  38. // It is actually just a wrapper around ReplicaSetController.
  39. type ReplicationManager struct {
  40. replicaset.ReplicaSetController
  41. }
  42. // NewReplicationManager configures a replication manager with the specified event recorder
  43. func NewReplicationManager(podInformer coreinformers.PodInformer, rcInformer coreinformers.ReplicationControllerInformer, kubeClient clientset.Interface, burstReplicas int) *ReplicationManager {
  44. eventBroadcaster := record.NewBroadcaster()
  45. eventBroadcaster.StartLogging(klog.Infof)
  46. eventBroadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: kubeClient.CoreV1().Events("")})
  47. return &ReplicationManager{
  48. *replicaset.NewBaseController(informerAdapter{rcInformer}, podInformer, clientsetAdapter{kubeClient}, burstReplicas,
  49. v1.SchemeGroupVersion.WithKind("ReplicationController"),
  50. "replication_controller",
  51. "replicationmanager",
  52. podControlAdapter{controller.RealPodControl{
  53. KubeClient: kubeClient,
  54. Recorder: eventBroadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "replication-controller"}),
  55. }},
  56. ),
  57. }
  58. }