cmd/kube-controller-manager

This commit is contained in:
Chao Xu
2016-11-18 12:50:17 -08:00
parent 48536eaef9
commit 7eeb71f698
109 changed files with 4380 additions and 4153 deletions

View File

@@ -21,15 +21,15 @@ import (
"strings"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/labels"
)
type PodControllerRefManager struct {
podControl PodControlInterface
controllerObject api.ObjectMeta
controllerObject v1.ObjectMeta
controllerSelector labels.Selector
controllerKind unversioned.GroupVersionKind
}
@@ -38,7 +38,7 @@ type PodControllerRefManager struct {
// methods to manage the controllerRef of pods.
func NewPodControllerRefManager(
podControl PodControlInterface,
controllerObject api.ObjectMeta,
controllerObject v1.ObjectMeta,
controllerSelector labels.Selector,
controllerKind unversioned.GroupVersionKind,
) *PodControllerRefManager {
@@ -53,10 +53,10 @@ func NewPodControllerRefManager(
// controllerRef pointing to other object are ignored) 3. controlledDoesNotMatch
// are the pods that have a controllerRef pointing to the controller, but their
// labels no longer match the selector.
func (m *PodControllerRefManager) Classify(pods []*api.Pod) (
matchesAndControlled []*api.Pod,
matchesNeedsController []*api.Pod,
controlledDoesNotMatch []*api.Pod) {
func (m *PodControllerRefManager) Classify(pods []*v1.Pod) (
matchesAndControlled []*v1.Pod,
matchesNeedsController []*v1.Pod,
controlledDoesNotMatch []*v1.Pod) {
for i := range pods {
pod := pods[i]
if !IsPodActive(pod) {
@@ -91,7 +91,7 @@ func (m *PodControllerRefManager) Classify(pods []*api.Pod) (
// getControllerOf returns the controllerRef if controllee has a controller,
// otherwise returns nil.
func getControllerOf(controllee api.ObjectMeta) *api.OwnerReference {
func getControllerOf(controllee v1.ObjectMeta) *v1.OwnerReference {
for _, owner := range controllee.OwnerReferences {
// controlled by other controller
if owner.Controller != nil && *owner.Controller == true {
@@ -103,7 +103,7 @@ func getControllerOf(controllee api.ObjectMeta) *api.OwnerReference {
// AdoptPod sends a patch to take control of the pod. It returns the error if
// the patching fails.
func (m *PodControllerRefManager) AdoptPod(pod *api.Pod) error {
func (m *PodControllerRefManager) AdoptPod(pod *v1.Pod) error {
// we should not adopt any pods if the controller is about to be deleted
if m.controllerObject.DeletionTimestamp != nil {
return fmt.Errorf("cancel the adopt attempt for pod %s because the controlller is being deleted",
@@ -118,7 +118,7 @@ func (m *PodControllerRefManager) AdoptPod(pod *api.Pod) error {
// ReleasePod sends a patch to free the pod from the control of the controller.
// It returns the error if the patching fails. 404 and 422 errors are ignored.
func (m *PodControllerRefManager) ReleasePod(pod *api.Pod) error {
func (m *PodControllerRefManager) ReleasePod(pod *v1.Pod) error {
glog.V(2).Infof("patching pod %s_%s to remove its controllerRef to %s/%s:%s",
pod.Namespace, pod.Name, m.controllerKind.GroupVersion(), m.controllerKind.Kind, m.controllerObject.Name)
deleteOwnerRefPatch := fmt.Sprintf(`{"metadata":{"ownerReferences":[{"$patch":"delete","uid":"%s"}],"uid":"%s"}}`, m.controllerObject.UID, pod.UID)