mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	update deployment lister
This commit is contained in:
		
							
								
								
									
										127
									
								
								pkg/client/cache/listers.go
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										127
									
								
								pkg/client/cache/listers.go
									
									
									
									
										vendored
									
									
								
							@@ -137,133 +137,6 @@ func (s storeToNodeConditionLister) List() (nodes []*api.Node, err error) {
 | 
				
			|||||||
	return
 | 
						return
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// StoreToDeploymentLister gives a store List and Exists methods. The store must contain only Deployments.
 | 
					 | 
				
			||||||
type StoreToDeploymentLister struct {
 | 
					 | 
				
			||||||
	Indexer
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Exists checks if the given deployment exists in the store.
 | 
					 | 
				
			||||||
func (s *StoreToDeploymentLister) Exists(deployment *extensions.Deployment) (bool, error) {
 | 
					 | 
				
			||||||
	_, exists, err := s.Indexer.Get(deployment)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return false, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return exists, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// StoreToDeploymentLister lists all deployments in the store.
 | 
					 | 
				
			||||||
// TODO: converge on the interface in pkg/client
 | 
					 | 
				
			||||||
func (s *StoreToDeploymentLister) List() (deployments []extensions.Deployment, err error) {
 | 
					 | 
				
			||||||
	for _, c := range s.Indexer.List() {
 | 
					 | 
				
			||||||
		deployments = append(deployments, *(c.(*extensions.Deployment)))
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return deployments, nil
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// GetDeploymentsForReplicaSet returns a list of deployments managing a replica set. Returns an error only if no matching deployments are found.
 | 
					 | 
				
			||||||
func (s *StoreToDeploymentLister) GetDeploymentsForReplicaSet(rs *extensions.ReplicaSet) (deployments []extensions.Deployment, err error) {
 | 
					 | 
				
			||||||
	if len(rs.Labels) == 0 {
 | 
					 | 
				
			||||||
		err = fmt.Errorf("no deployments found for ReplicaSet %v because it has no labels", rs.Name)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// TODO: MODIFY THIS METHOD so that it checks for the podTemplateSpecHash label
 | 
					 | 
				
			||||||
	dList, err := s.Deployments(rs.Namespace).List(labels.Everything())
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	for _, d := range dList {
 | 
					 | 
				
			||||||
		selector, err := unversioned.LabelSelectorAsSelector(d.Spec.Selector)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return nil, fmt.Errorf("invalid label selector: %v", err)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		// If a deployment with a nil or empty selector creeps in, it should match nothing, not everything.
 | 
					 | 
				
			||||||
		if selector.Empty() || !selector.Matches(labels.Set(rs.Labels)) {
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		deployments = append(deployments, d)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if len(deployments) == 0 {
 | 
					 | 
				
			||||||
		err = fmt.Errorf("could not find deployments set for ReplicaSet %s in namespace %s with labels: %v", rs.Name, rs.Namespace, rs.Labels)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
type storeToDeploymentNamespacer struct {
 | 
					 | 
				
			||||||
	indexer   Indexer
 | 
					 | 
				
			||||||
	namespace string
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// storeToDeploymentNamespacer lists deployments under its namespace in the store.
 | 
					 | 
				
			||||||
func (s storeToDeploymentNamespacer) List(selector labels.Selector) (deployments []extensions.Deployment, err error) {
 | 
					 | 
				
			||||||
	if s.namespace == api.NamespaceAll {
 | 
					 | 
				
			||||||
		for _, m := range s.indexer.List() {
 | 
					 | 
				
			||||||
			d := *(m.(*extensions.Deployment))
 | 
					 | 
				
			||||||
			if selector.Matches(labels.Set(d.Labels)) {
 | 
					 | 
				
			||||||
				deployments = append(deployments, d)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	key := &extensions.Deployment{ObjectMeta: api.ObjectMeta{Namespace: s.namespace}}
 | 
					 | 
				
			||||||
	items, err := s.indexer.Index(NamespaceIndex, key)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		// Ignore error; do slow search without index.
 | 
					 | 
				
			||||||
		glog.Warningf("can not retrieve list of objects using index : %v", err)
 | 
					 | 
				
			||||||
		for _, m := range s.indexer.List() {
 | 
					 | 
				
			||||||
			d := *(m.(*extensions.Deployment))
 | 
					 | 
				
			||||||
			if s.namespace == d.Namespace && selector.Matches(labels.Set(d.Labels)) {
 | 
					 | 
				
			||||||
				deployments = append(deployments, d)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return deployments, nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	for _, m := range items {
 | 
					 | 
				
			||||||
		d := *(m.(*extensions.Deployment))
 | 
					 | 
				
			||||||
		if selector.Matches(labels.Set(d.Labels)) {
 | 
					 | 
				
			||||||
			deployments = append(deployments, d)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (s *StoreToDeploymentLister) Deployments(namespace string) storeToDeploymentNamespacer {
 | 
					 | 
				
			||||||
	return storeToDeploymentNamespacer{s.Indexer, namespace}
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// GetDeploymentsForPods returns a list of deployments managing a pod. Returns an error only if no matching deployments are found.
 | 
					 | 
				
			||||||
func (s *StoreToDeploymentLister) GetDeploymentsForPod(pod *api.Pod) (deployments []extensions.Deployment, err error) {
 | 
					 | 
				
			||||||
	if len(pod.Labels) == 0 {
 | 
					 | 
				
			||||||
		err = fmt.Errorf("no deployments found for Pod %v because it has no labels", pod.Name)
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if len(pod.Labels[extensions.DefaultDeploymentUniqueLabelKey]) == 0 {
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	dList, err := s.Deployments(pod.Namespace).List(labels.Everything())
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	for _, d := range dList {
 | 
					 | 
				
			||||||
		selector, err := unversioned.LabelSelectorAsSelector(d.Spec.Selector)
 | 
					 | 
				
			||||||
		if err != nil {
 | 
					 | 
				
			||||||
			return nil, fmt.Errorf("invalid label selector: %v", err)
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		// If a deployment with a nil or empty selector creeps in, it should match nothing, not everything.
 | 
					 | 
				
			||||||
		if selector.Empty() || !selector.Matches(labels.Set(pod.Labels)) {
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		deployments = append(deployments, d)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if len(deployments) == 0 {
 | 
					 | 
				
			||||||
		err = fmt.Errorf("could not find deployments set for Pod %s in namespace %s with labels: %v", pod.Name, pod.Namespace, pod.Labels)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// StoreToReplicaSetLister gives a store List and Exists methods. The store must contain only ReplicaSets.
 | 
					// StoreToReplicaSetLister gives a store List and Exists methods. The store must contain only ReplicaSets.
 | 
				
			||||||
type StoreToReplicaSetLister struct {
 | 
					type StoreToReplicaSetLister struct {
 | 
				
			||||||
	Store
 | 
						Store
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										141
									
								
								pkg/client/cache/listers_extensions.go
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										141
									
								
								pkg/client/cache/listers_extensions.go
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,141 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					Copyright 2016 The Kubernetes Authors.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Licensed under the Apache License, Version 2.0 (the "License");
 | 
				
			||||||
 | 
					you may not use this file except in compliance with the License.
 | 
				
			||||||
 | 
					You may obtain a copy of the License at
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    http://www.apache.org/licenses/LICENSE-2.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Unless required by applicable law or agreed to in writing, software
 | 
				
			||||||
 | 
					distributed under the License is distributed on an "AS IS" BASIS,
 | 
				
			||||||
 | 
					WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
				
			||||||
 | 
					See the License for the specific language governing permissions and
 | 
				
			||||||
 | 
					limitations under the License.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					package cache
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/api"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/api/errors"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/api/unversioned"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/apis/extensions"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/labels"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//  TODO: generate these classes and methods for all resources of interest using
 | 
				
			||||||
 | 
					// a script.  Can use "go generate" once 1.4 is supported by all users.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Lister makes an Index have the List method.  The Stores must contain only the expected type
 | 
				
			||||||
 | 
					// Example:
 | 
				
			||||||
 | 
					// s := cache.NewStore()
 | 
				
			||||||
 | 
					// lw := cache.ListWatch{Client: c, FieldSelector: sel, Resource: "pods"}
 | 
				
			||||||
 | 
					// r := cache.NewReflector(lw, &extensions.Deployment{}, s).Run()
 | 
				
			||||||
 | 
					// l := StoreToDeploymentLister{s}
 | 
				
			||||||
 | 
					// l.List()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// StoreToDeploymentLister helps list pods
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// StoreToDeploymentLister gives a store List and Exists methods. The store must contain only Deployments.
 | 
				
			||||||
 | 
					type StoreToDeploymentLister struct {
 | 
				
			||||||
 | 
						Indexer Indexer
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (s *StoreToDeploymentLister) List(selector labels.Selector) (ret []*extensions.Deployment, err error) {
 | 
				
			||||||
 | 
						err = ListAll(s.Indexer, selector, func(m interface{}) {
 | 
				
			||||||
 | 
							ret = append(ret, m.(*extensions.Deployment))
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						return ret, err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (s *StoreToDeploymentLister) Deployments(namespace string) storeDeploymentsNamespacer {
 | 
				
			||||||
 | 
						return storeDeploymentsNamespacer{Indexer: s.Indexer, namespace: namespace}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type storeDeploymentsNamespacer struct {
 | 
				
			||||||
 | 
						Indexer   Indexer
 | 
				
			||||||
 | 
						namespace string
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (s storeDeploymentsNamespacer) List(selector labels.Selector) (ret []*extensions.Deployment, err error) {
 | 
				
			||||||
 | 
						err = ListAllByNamespace(s.Indexer, s.namespace, selector, func(m interface{}) {
 | 
				
			||||||
 | 
							ret = append(ret, m.(*extensions.Deployment))
 | 
				
			||||||
 | 
						})
 | 
				
			||||||
 | 
						return ret, err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (s storeDeploymentsNamespacer) Get(name string) (*extensions.Deployment, error) {
 | 
				
			||||||
 | 
						obj, exists, err := s.Indexer.GetByKey(s.namespace + "/" + name)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if !exists {
 | 
				
			||||||
 | 
							return nil, errors.NewNotFound(extensions.Resource("deployment"), name)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return obj.(*extensions.Deployment), nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GetDeploymentsForReplicaSet returns a list of deployments managing a replica set. Returns an error only if no matching deployments are found.
 | 
				
			||||||
 | 
					func (s *StoreToDeploymentLister) GetDeploymentsForReplicaSet(rs *extensions.ReplicaSet) (deployments []*extensions.Deployment, err error) {
 | 
				
			||||||
 | 
						if len(rs.Labels) == 0 {
 | 
				
			||||||
 | 
							err = fmt.Errorf("no deployments found for ReplicaSet %v because it has no labels", rs.Name)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// TODO: MODIFY THIS METHOD so that it checks for the podTemplateSpecHash label
 | 
				
			||||||
 | 
						dList, err := s.Deployments(rs.Namespace).List(labels.Everything())
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for _, d := range dList {
 | 
				
			||||||
 | 
							selector, err := unversioned.LabelSelectorAsSelector(d.Spec.Selector)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return nil, fmt.Errorf("invalid label selector: %v", err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							// If a deployment with a nil or empty selector creeps in, it should match nothing, not everything.
 | 
				
			||||||
 | 
							if selector.Empty() || !selector.Matches(labels.Set(rs.Labels)) {
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							deployments = append(deployments, d)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(deployments) == 0 {
 | 
				
			||||||
 | 
							err = fmt.Errorf("could not find deployments set for ReplicaSet %s in namespace %s with labels: %v", rs.Name, rs.Namespace, rs.Labels)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GetDeploymentsForDeployments returns a list of deployments managing a pod. Returns an error only if no matching deployments are found.
 | 
				
			||||||
 | 
					// TODO eliminate shallow copies
 | 
				
			||||||
 | 
					func (s *StoreToDeploymentLister) GetDeploymentsForPod(pod *api.Pod) (deployments []*extensions.Deployment, err error) {
 | 
				
			||||||
 | 
						if len(pod.Labels) == 0 {
 | 
				
			||||||
 | 
							err = fmt.Errorf("no deployments found for Pod %v because it has no labels", pod.Name)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if len(pod.Labels[extensions.DefaultDeploymentUniqueLabelKey]) == 0 {
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						dList, err := s.Deployments(pod.Namespace).List(labels.Everything())
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for _, d := range dList {
 | 
				
			||||||
 | 
							selector, err := unversioned.LabelSelectorAsSelector(d.Spec.Selector)
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
 | 
								return nil, fmt.Errorf("invalid label selector: %v", err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							// If a deployment with a nil or empty selector creeps in, it should match nothing, not everything.
 | 
				
			||||||
 | 
							if selector.Empty() || !selector.Matches(labels.Set(pod.Labels)) {
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							deployments = append(deployments, d)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(deployments) == 0 {
 | 
				
			||||||
 | 
							err = fmt.Errorf("could not find deployments set for Pod %s in namespace %s with labels: %v", pod.Name, pod.Namespace, pod.Labels)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -67,27 +67,27 @@ type DeploymentController struct {
 | 
				
			|||||||
	syncHandler func(dKey string) error
 | 
						syncHandler func(dKey string) error
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// A store of deployments, populated by the dController
 | 
						// A store of deployments, populated by the dController
 | 
				
			||||||
	dStore cache.StoreToDeploymentLister
 | 
						dLister cache.StoreToDeploymentLister
 | 
				
			||||||
	// Watches changes to all deployments
 | 
						// Watches changes to all deployments
 | 
				
			||||||
	dController *cache.Controller
 | 
						dController *cache.Controller
 | 
				
			||||||
	// A store of ReplicaSets, populated by the rsController
 | 
						// A store of ReplicaSets, populated by the rsController
 | 
				
			||||||
	rsStore cache.StoreToReplicaSetLister
 | 
						rsLister cache.StoreToReplicaSetLister
 | 
				
			||||||
	// Watches changes to all ReplicaSets
 | 
						// Watches changes to all ReplicaSets
 | 
				
			||||||
	rsController *cache.Controller
 | 
						rsController *cache.Controller
 | 
				
			||||||
	// A store of pods, populated by the podController
 | 
						// A store of pods, populated by the podController
 | 
				
			||||||
	podStore cache.StoreToPodLister
 | 
						podLister cache.StoreToPodLister
 | 
				
			||||||
	// Watches changes to all pods
 | 
						// Watches changes to all pods
 | 
				
			||||||
	podController *cache.Controller
 | 
						podController *cache.Controller
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// dStoreSynced returns true if the Deployment store has been synced at least once.
 | 
						// dListerSynced returns true if the Deployment store has been synced at least once.
 | 
				
			||||||
	// Added as a member to the struct to allow injection for testing.
 | 
						// Added as a member to the struct to allow injection for testing.
 | 
				
			||||||
	dStoreSynced func() bool
 | 
						dListerSynced func() bool
 | 
				
			||||||
	// rsStoreSynced returns true if the ReplicaSet store has been synced at least once.
 | 
						// rsListerSynced returns true if the ReplicaSet store has been synced at least once.
 | 
				
			||||||
	// Added as a member to the struct to allow injection for testing.
 | 
						// Added as a member to the struct to allow injection for testing.
 | 
				
			||||||
	rsStoreSynced func() bool
 | 
						rsListerSynced func() bool
 | 
				
			||||||
	// podStoreSynced returns true if the pod store has been synced at least once.
 | 
						// podListerSynced returns true if the pod store has been synced at least once.
 | 
				
			||||||
	// Added as a member to the struct to allow injection for testing.
 | 
						// Added as a member to the struct to allow injection for testing.
 | 
				
			||||||
	podStoreSynced func() bool
 | 
						podListerSynced func() bool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Deployments that need to be synced
 | 
						// Deployments that need to be synced
 | 
				
			||||||
	queue workqueue.RateLimitingInterface
 | 
						queue workqueue.RateLimitingInterface
 | 
				
			||||||
@@ -109,7 +109,7 @@ func NewDeploymentController(client clientset.Interface, resyncPeriod controller
 | 
				
			|||||||
		queue:         workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "deployment"),
 | 
							queue:         workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "deployment"),
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	dc.dStore.Indexer, dc.dController = cache.NewIndexerInformer(
 | 
						dc.dLister.Indexer, dc.dController = cache.NewIndexerInformer(
 | 
				
			||||||
		&cache.ListWatch{
 | 
							&cache.ListWatch{
 | 
				
			||||||
			ListFunc: func(options api.ListOptions) (runtime.Object, error) {
 | 
								ListFunc: func(options api.ListOptions) (runtime.Object, error) {
 | 
				
			||||||
				return dc.client.Extensions().Deployments(api.NamespaceAll).List(options)
 | 
									return dc.client.Extensions().Deployments(api.NamespaceAll).List(options)
 | 
				
			||||||
@@ -129,7 +129,7 @@ func NewDeploymentController(client clientset.Interface, resyncPeriod controller
 | 
				
			|||||||
		cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
 | 
							cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	dc.rsStore.Store, dc.rsController = cache.NewInformer(
 | 
						dc.rsLister.Store, dc.rsController = cache.NewInformer(
 | 
				
			||||||
		&cache.ListWatch{
 | 
							&cache.ListWatch{
 | 
				
			||||||
			ListFunc: func(options api.ListOptions) (runtime.Object, error) {
 | 
								ListFunc: func(options api.ListOptions) (runtime.Object, error) {
 | 
				
			||||||
				return dc.client.Extensions().ReplicaSets(api.NamespaceAll).List(options)
 | 
									return dc.client.Extensions().ReplicaSets(api.NamespaceAll).List(options)
 | 
				
			||||||
@@ -147,7 +147,7 @@ func NewDeploymentController(client clientset.Interface, resyncPeriod controller
 | 
				
			|||||||
		},
 | 
							},
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	dc.podStore.Indexer, dc.podController = cache.NewIndexerInformer(
 | 
						dc.podLister.Indexer, dc.podController = cache.NewIndexerInformer(
 | 
				
			||||||
		&cache.ListWatch{
 | 
							&cache.ListWatch{
 | 
				
			||||||
			ListFunc: func(options api.ListOptions) (runtime.Object, error) {
 | 
								ListFunc: func(options api.ListOptions) (runtime.Object, error) {
 | 
				
			||||||
				return dc.client.Core().Pods(api.NamespaceAll).List(options)
 | 
									return dc.client.Core().Pods(api.NamespaceAll).List(options)
 | 
				
			||||||
@@ -167,9 +167,9 @@ func NewDeploymentController(client clientset.Interface, resyncPeriod controller
 | 
				
			|||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	dc.syncHandler = dc.syncDeployment
 | 
						dc.syncHandler = dc.syncDeployment
 | 
				
			||||||
	dc.dStoreSynced = dc.dController.HasSynced
 | 
						dc.dListerSynced = dc.dController.HasSynced
 | 
				
			||||||
	dc.rsStoreSynced = dc.rsController.HasSynced
 | 
						dc.rsListerSynced = dc.rsController.HasSynced
 | 
				
			||||||
	dc.podStoreSynced = dc.podController.HasSynced
 | 
						dc.podListerSynced = dc.podController.HasSynced
 | 
				
			||||||
	return dc
 | 
						return dc
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -183,7 +183,7 @@ func (dc *DeploymentController) Run(workers int, stopCh <-chan struct{}) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// Wait for the rc and dc stores to sync before starting any work in this controller.
 | 
						// Wait for the rc and dc stores to sync before starting any work in this controller.
 | 
				
			||||||
	ready := make(chan struct{})
 | 
						ready := make(chan struct{})
 | 
				
			||||||
	go dc.waitForSyncedStores(ready, stopCh)
 | 
						go dc.waitForSyncedListers(ready, stopCh)
 | 
				
			||||||
	select {
 | 
						select {
 | 
				
			||||||
	case <-ready:
 | 
						case <-ready:
 | 
				
			||||||
	case <-stopCh:
 | 
						case <-stopCh:
 | 
				
			||||||
@@ -199,10 +199,10 @@ func (dc *DeploymentController) Run(workers int, stopCh <-chan struct{}) {
 | 
				
			|||||||
	dc.queue.ShutDown()
 | 
						dc.queue.ShutDown()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (dc *DeploymentController) waitForSyncedStores(ready chan<- struct{}, stopCh <-chan struct{}) {
 | 
					func (dc *DeploymentController) waitForSyncedListers(ready chan<- struct{}, stopCh <-chan struct{}) {
 | 
				
			||||||
	defer utilruntime.HandleCrash()
 | 
						defer utilruntime.HandleCrash()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for !dc.dStoreSynced() || !dc.rsStoreSynced() || !dc.podStoreSynced() {
 | 
						for !dc.dListerSynced() || !dc.rsListerSynced() || !dc.podListerSynced() {
 | 
				
			||||||
		select {
 | 
							select {
 | 
				
			||||||
		case <-time.After(StoreSyncedPollPeriod):
 | 
							case <-time.After(StoreSyncedPollPeriod):
 | 
				
			||||||
		case <-stopCh:
 | 
							case <-stopCh:
 | 
				
			||||||
@@ -255,7 +255,7 @@ func (dc *DeploymentController) addReplicaSet(obj interface{}) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// getDeploymentForReplicaSet returns the deployment managing the given ReplicaSet.
 | 
					// getDeploymentForReplicaSet returns the deployment managing the given ReplicaSet.
 | 
				
			||||||
func (dc *DeploymentController) getDeploymentForReplicaSet(rs *extensions.ReplicaSet) *extensions.Deployment {
 | 
					func (dc *DeploymentController) getDeploymentForReplicaSet(rs *extensions.ReplicaSet) *extensions.Deployment {
 | 
				
			||||||
	deployments, err := dc.dStore.GetDeploymentsForReplicaSet(rs)
 | 
						deployments, err := dc.dLister.GetDeploymentsForReplicaSet(rs)
 | 
				
			||||||
	if err != nil || len(deployments) == 0 {
 | 
						if err != nil || len(deployments) == 0 {
 | 
				
			||||||
		glog.V(4).Infof("Error: %v. No deployment found for ReplicaSet %v, deployment controller will avoid syncing.", err, rs.Name)
 | 
							glog.V(4).Infof("Error: %v. No deployment found for ReplicaSet %v, deployment controller will avoid syncing.", err, rs.Name)
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
@@ -268,7 +268,7 @@ func (dc *DeploymentController) getDeploymentForReplicaSet(rs *extensions.Replic
 | 
				
			|||||||
		sort.Sort(util.BySelectorLastUpdateTime(deployments))
 | 
							sort.Sort(util.BySelectorLastUpdateTime(deployments))
 | 
				
			||||||
		glog.Errorf("user error! more than one deployment is selecting replica set %s/%s with labels: %#v, returning %s/%s", rs.Namespace, rs.Name, rs.Labels, deployments[0].Namespace, deployments[0].Name)
 | 
							glog.Errorf("user error! more than one deployment is selecting replica set %s/%s with labels: %#v, returning %s/%s", rs.Namespace, rs.Name, rs.Labels, deployments[0].Namespace, deployments[0].Name)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return &deployments[0]
 | 
						return deployments[0]
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// updateReplicaSet figures out what deployment(s) manage a ReplicaSet when the ReplicaSet
 | 
					// updateReplicaSet figures out what deployment(s) manage a ReplicaSet when the ReplicaSet
 | 
				
			||||||
@@ -328,7 +328,7 @@ func (dc *DeploymentController) deleteReplicaSet(obj interface{}) {
 | 
				
			|||||||
// getDeploymentForPod returns the deployment that manages the given Pod.
 | 
					// getDeploymentForPod returns the deployment that manages the given Pod.
 | 
				
			||||||
// If there are multiple deployments for a given Pod, only return the oldest one.
 | 
					// If there are multiple deployments for a given Pod, only return the oldest one.
 | 
				
			||||||
func (dc *DeploymentController) getDeploymentForPod(pod *api.Pod) *extensions.Deployment {
 | 
					func (dc *DeploymentController) getDeploymentForPod(pod *api.Pod) *extensions.Deployment {
 | 
				
			||||||
	deployments, err := dc.dStore.GetDeploymentsForPod(pod)
 | 
						deployments, err := dc.dLister.GetDeploymentsForPod(pod)
 | 
				
			||||||
	if err != nil || len(deployments) == 0 {
 | 
						if err != nil || len(deployments) == 0 {
 | 
				
			||||||
		glog.V(4).Infof("Error: %v. No deployment found for Pod %v, deployment controller will avoid syncing.", err, pod.Name)
 | 
							glog.V(4).Infof("Error: %v. No deployment found for Pod %v, deployment controller will avoid syncing.", err, pod.Name)
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
@@ -338,7 +338,7 @@ func (dc *DeploymentController) getDeploymentForPod(pod *api.Pod) *extensions.De
 | 
				
			|||||||
		sort.Sort(util.BySelectorLastUpdateTime(deployments))
 | 
							sort.Sort(util.BySelectorLastUpdateTime(deployments))
 | 
				
			||||||
		glog.Errorf("user error! more than one deployment is selecting pod %s/%s with labels: %#v, returning %s/%s", pod.Namespace, pod.Name, pod.Labels, deployments[0].Namespace, deployments[0].Name)
 | 
							glog.Errorf("user error! more than one deployment is selecting pod %s/%s with labels: %#v, returning %s/%s", pod.Namespace, pod.Name, pod.Labels, deployments[0].Namespace, deployments[0].Name)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return &deployments[0]
 | 
						return deployments[0]
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// When a pod is created, ensure its controller syncs
 | 
					// When a pod is created, ensure its controller syncs
 | 
				
			||||||
@@ -478,7 +478,7 @@ func (dc *DeploymentController) syncDeployment(key string) error {
 | 
				
			|||||||
		glog.V(4).Infof("Finished syncing deployment %q (%v)", key, time.Now().Sub(startTime))
 | 
							glog.V(4).Infof("Finished syncing deployment %q (%v)", key, time.Now().Sub(startTime))
 | 
				
			||||||
	}()
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	obj, exists, err := dc.dStore.Indexer.GetByKey(key)
 | 
						obj, exists, err := dc.dLister.Indexer.GetByKey(key)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		glog.Errorf("Unable to retrieve deployment %v from store: %v", key, err)
 | 
							glog.Errorf("Unable to retrieve deployment %v from store: %v", key, err)
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
@@ -548,24 +548,27 @@ func (dc *DeploymentController) handleOverlap(d *extensions.Deployment) error {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return fmt.Errorf("deployment %s/%s has invalid label selector: %v", d.Namespace, d.Name, err)
 | 
							return fmt.Errorf("deployment %s/%s has invalid label selector: %v", d.Namespace, d.Name, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	deployments, err := dc.dStore.Deployments(d.Namespace).List(labels.Everything())
 | 
						deployments, err := dc.dLister.Deployments(d.Namespace).List(labels.Everything())
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return fmt.Errorf("error listing deployments in namespace %s: %v", d.Namespace, err)
 | 
							return fmt.Errorf("error listing deployments in namespace %s: %v", d.Namespace, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	overlapping := false
 | 
						overlapping := false
 | 
				
			||||||
	for i := range deployments {
 | 
						for _, other := range deployments {
 | 
				
			||||||
		other := &deployments[i]
 | 
					 | 
				
			||||||
		if !selector.Empty() && selector.Matches(labels.Set(other.Spec.Template.Labels)) && d.UID != other.UID {
 | 
							if !selector.Empty() && selector.Matches(labels.Set(other.Spec.Template.Labels)) && d.UID != other.UID {
 | 
				
			||||||
 | 
								deploymentCopy, err := util.DeploymentDeepCopy(other)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			overlapping = true
 | 
								overlapping = true
 | 
				
			||||||
			// We don't care if the overlapping annotation update failed or not (we don't make decision on it)
 | 
								// We don't care if the overlapping annotation update failed or not (we don't make decision on it)
 | 
				
			||||||
			d, _ = dc.markDeploymentOverlap(d, other.Name)
 | 
								d, _ = dc.markDeploymentOverlap(d, other.Name)
 | 
				
			||||||
			other, _ = dc.markDeploymentOverlap(other, d.Name)
 | 
								deploymentCopy, _ = dc.markDeploymentOverlap(deploymentCopy, d.Name)
 | 
				
			||||||
			// Skip syncing this one if older overlapping one is found
 | 
								// Skip syncing this one if older overlapping one is found
 | 
				
			||||||
			// TODO: figure out a better way to determine which deployment to skip,
 | 
								// TODO: figure out a better way to determine which deployment to skip,
 | 
				
			||||||
			// either with controller reference, or with validation.
 | 
								// either with controller reference, or with validation.
 | 
				
			||||||
			// Using oldest active replica set to determine which deployment to skip wouldn't make much difference,
 | 
								// Using oldest active replica set to determine which deployment to skip wouldn't make much difference,
 | 
				
			||||||
			// since new replica set hasn't been created after selector update
 | 
								// since new replica set hasn't been created after selector update
 | 
				
			||||||
			if util.SelectorUpdatedBefore(other, d) {
 | 
								if util.SelectorUpdatedBefore(deploymentCopy, d) {
 | 
				
			||||||
				return fmt.Errorf("found deployment %s/%s has overlapping selector with an older deployment %s/%s, skip syncing it", d.Namespace, d.Name, other.Namespace, other.Name)
 | 
									return fmt.Errorf("found deployment %s/%s has overlapping selector with an older deployment %s/%s, skip syncing it", d.Namespace, d.Name, other.Namespace, other.Name)
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -157,9 +157,9 @@ type fixture struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	client *fake.Clientset
 | 
						client *fake.Clientset
 | 
				
			||||||
	// Objects to put in the store.
 | 
						// Objects to put in the store.
 | 
				
			||||||
	dStore   []*exp.Deployment
 | 
						dLister   []*exp.Deployment
 | 
				
			||||||
	rsStore  []*exp.ReplicaSet
 | 
						rsLister  []*exp.ReplicaSet
 | 
				
			||||||
	podStore []*api.Pod
 | 
						podLister []*api.Pod
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Actions expected to happen on the client. Objects from here are also
 | 
						// Actions expected to happen on the client. Objects from here are also
 | 
				
			||||||
	// preloaded into NewSimpleFake.
 | 
						// preloaded into NewSimpleFake.
 | 
				
			||||||
@@ -200,16 +200,16 @@ func (f *fixture) run(deploymentName string) {
 | 
				
			|||||||
	f.client = fake.NewSimpleClientset(f.objects...)
 | 
						f.client = fake.NewSimpleClientset(f.objects...)
 | 
				
			||||||
	c := NewDeploymentController(f.client, controller.NoResyncPeriodFunc)
 | 
						c := NewDeploymentController(f.client, controller.NoResyncPeriodFunc)
 | 
				
			||||||
	c.eventRecorder = &record.FakeRecorder{}
 | 
						c.eventRecorder = &record.FakeRecorder{}
 | 
				
			||||||
	c.rsStoreSynced = alwaysReady
 | 
						c.rsListerSynced = alwaysReady
 | 
				
			||||||
	c.podStoreSynced = alwaysReady
 | 
						c.podListerSynced = alwaysReady
 | 
				
			||||||
	for _, d := range f.dStore {
 | 
						for _, d := range f.dLister {
 | 
				
			||||||
		c.dStore.Indexer.Add(d)
 | 
							c.dLister.Indexer.Add(d)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	for _, rs := range f.rsStore {
 | 
						for _, rs := range f.rsLister {
 | 
				
			||||||
		c.rsStore.Store.Add(rs)
 | 
							c.rsLister.Store.Add(rs)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	for _, pod := range f.podStore {
 | 
						for _, pod := range f.podLister {
 | 
				
			||||||
		c.podStore.Indexer.Add(pod)
 | 
							c.podLister.Indexer.Add(pod)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err := c.syncDeployment(deploymentName)
 | 
						err := c.syncDeployment(deploymentName)
 | 
				
			||||||
@@ -240,7 +240,7 @@ func TestSyncDeploymentCreatesReplicaSet(t *testing.T) {
 | 
				
			|||||||
	f := newFixture(t)
 | 
						f := newFixture(t)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	d := newDeployment(1, nil)
 | 
						d := newDeployment(1, nil)
 | 
				
			||||||
	f.dStore = append(f.dStore, d)
 | 
						f.dLister = append(f.dLister, d)
 | 
				
			||||||
	f.objects = append(f.objects, d)
 | 
						f.objects = append(f.objects, d)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rs := newReplicaSet(d, "deploymentrs-4186632231", 1)
 | 
						rs := newReplicaSet(d, "deploymentrs-4186632231", 1)
 | 
				
			||||||
@@ -258,7 +258,7 @@ func TestSyncDeploymentDontDoAnythingDuringDeletion(t *testing.T) {
 | 
				
			|||||||
	d := newDeployment(1, nil)
 | 
						d := newDeployment(1, nil)
 | 
				
			||||||
	now := unversioned.Now()
 | 
						now := unversioned.Now()
 | 
				
			||||||
	d.DeletionTimestamp = &now
 | 
						d.DeletionTimestamp = &now
 | 
				
			||||||
	f.dStore = append(f.dStore, d)
 | 
						f.dLister = append(f.dLister, d)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	f.run(getKey(d, t))
 | 
						f.run(getKey(d, t))
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -269,13 +269,13 @@ func TestDeploymentController_dontSyncDeploymentsWithEmptyPodSelector(t *testing
 | 
				
			|||||||
	controller := NewDeploymentController(fake, controller.NoResyncPeriodFunc)
 | 
						controller := NewDeploymentController(fake, controller.NoResyncPeriodFunc)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	controller.eventRecorder = &record.FakeRecorder{}
 | 
						controller.eventRecorder = &record.FakeRecorder{}
 | 
				
			||||||
	controller.rsStoreSynced = alwaysReady
 | 
						controller.rsListerSynced = alwaysReady
 | 
				
			||||||
	controller.podStoreSynced = alwaysReady
 | 
						controller.podListerSynced = alwaysReady
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	d := newDeployment(1, nil)
 | 
						d := newDeployment(1, nil)
 | 
				
			||||||
	empty := unversioned.LabelSelector{}
 | 
						empty := unversioned.LabelSelector{}
 | 
				
			||||||
	d.Spec.Selector = &empty
 | 
						d.Spec.Selector = &empty
 | 
				
			||||||
	controller.dStore.Indexer.Add(d)
 | 
						controller.dLister.Indexer.Add(d)
 | 
				
			||||||
	// We expect the deployment controller to not take action here since it's configuration
 | 
						// We expect the deployment controller to not take action here since it's configuration
 | 
				
			||||||
	// is invalid, even though no replicasets exist that match it's selector.
 | 
						// is invalid, even though no replicasets exist that match it's selector.
 | 
				
			||||||
	controller.syncDeployment(fmt.Sprintf("%s/%s", d.ObjectMeta.Namespace, d.ObjectMeta.Name))
 | 
						controller.syncDeployment(fmt.Sprintf("%s/%s", d.ObjectMeta.Namespace, d.ObjectMeta.Name))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -108,7 +108,7 @@ func (dc *DeploymentController) waitForInactiveReplicaSets(oldRSs []*extensions.
 | 
				
			|||||||
		statusReplicas := rs.Status.Replicas
 | 
							statusReplicas := rs.Status.Replicas
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if err := wait.ExponentialBackoff(unversionedclient.DefaultRetry, func() (bool, error) {
 | 
							if err := wait.ExponentialBackoff(unversionedclient.DefaultRetry, func() (bool, error) {
 | 
				
			||||||
			replicaSet, err := dc.rsStore.ReplicaSets(rs.Namespace).Get(rs.Name)
 | 
								replicaSet, err := dc.rsLister.ReplicaSets(rs.Namespace).Get(rs.Name)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				return false, err
 | 
									return false, err
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -106,7 +106,7 @@ func (dc *DeploymentController) getAllReplicaSetsAndSyncRevision(deployment *ext
 | 
				
			|||||||
func (dc *DeploymentController) rsAndPodsWithHashKeySynced(deployment *extensions.Deployment) ([]extensions.ReplicaSet, *api.PodList, error) {
 | 
					func (dc *DeploymentController) rsAndPodsWithHashKeySynced(deployment *extensions.Deployment) ([]extensions.ReplicaSet, *api.PodList, error) {
 | 
				
			||||||
	rsList, err := deploymentutil.ListReplicaSets(deployment,
 | 
						rsList, err := deploymentutil.ListReplicaSets(deployment,
 | 
				
			||||||
		func(namespace string, options api.ListOptions) ([]extensions.ReplicaSet, error) {
 | 
							func(namespace string, options api.ListOptions) ([]extensions.ReplicaSet, error) {
 | 
				
			||||||
			return dc.rsStore.ReplicaSets(namespace).List(options.LabelSelector)
 | 
								return dc.rsLister.ReplicaSets(namespace).List(options.LabelSelector)
 | 
				
			||||||
		})
 | 
							})
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, nil, fmt.Errorf("error listing ReplicaSets: %v", err)
 | 
							return nil, nil, fmt.Errorf("error listing ReplicaSets: %v", err)
 | 
				
			||||||
@@ -174,7 +174,7 @@ func (dc *DeploymentController) addHashKeyToRSAndPods(rs extensions.ReplicaSet)
 | 
				
			|||||||
		return nil, fmt.Errorf("error in converting selector to label selector for replica set %s: %s", updatedRS.Name, err)
 | 
							return nil, fmt.Errorf("error in converting selector to label selector for replica set %s: %s", updatedRS.Name, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	options := api.ListOptions{LabelSelector: selector}
 | 
						options := api.ListOptions{LabelSelector: selector}
 | 
				
			||||||
	pods, err := dc.podStore.Pods(namespace).List(options.LabelSelector)
 | 
						pods, err := dc.podLister.Pods(namespace).List(options.LabelSelector)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, fmt.Errorf("error in getting pod list for namespace %s and list options %+v: %s", namespace, options, err)
 | 
							return nil, fmt.Errorf("error in getting pod list for namespace %s and list options %+v: %s", namespace, options, err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -228,7 +228,7 @@ func (dc *DeploymentController) addHashKeyToRSAndPods(rs extensions.ReplicaSet)
 | 
				
			|||||||
func (dc *DeploymentController) listPods(deployment *extensions.Deployment) (*api.PodList, error) {
 | 
					func (dc *DeploymentController) listPods(deployment *extensions.Deployment) (*api.PodList, error) {
 | 
				
			||||||
	return deploymentutil.ListPods(deployment,
 | 
						return deploymentutil.ListPods(deployment,
 | 
				
			||||||
		func(namespace string, options api.ListOptions) (*api.PodList, error) {
 | 
							func(namespace string, options api.ListOptions) (*api.PodList, error) {
 | 
				
			||||||
			pods, err := dc.podStore.Pods(namespace).List(options.LabelSelector)
 | 
								pods, err := dc.podLister.Pods(namespace).List(options.LabelSelector)
 | 
				
			||||||
			result := api.PodList{Items: make([]api.Pod, 0, len(pods))}
 | 
								result := api.PodList{Items: make([]api.Pod, 0, len(pods))}
 | 
				
			||||||
			for i := range pods {
 | 
								for i := range pods {
 | 
				
			||||||
				result.Items = append(result.Items, *pods[i])
 | 
									result.Items = append(result.Items, *pods[i])
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -326,10 +326,10 @@ func TestDeploymentController_cleanupDeployment(t *testing.T) {
 | 
				
			|||||||
		controller := NewDeploymentController(fake, controller.NoResyncPeriodFunc)
 | 
							controller := NewDeploymentController(fake, controller.NoResyncPeriodFunc)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		controller.eventRecorder = &record.FakeRecorder{}
 | 
							controller.eventRecorder = &record.FakeRecorder{}
 | 
				
			||||||
		controller.rsStoreSynced = alwaysReady
 | 
							controller.rsListerSynced = alwaysReady
 | 
				
			||||||
		controller.podStoreSynced = alwaysReady
 | 
							controller.podListerSynced = alwaysReady
 | 
				
			||||||
		for _, rs := range test.oldRSs {
 | 
							for _, rs := range test.oldRSs {
 | 
				
			||||||
			controller.rsStore.Add(rs)
 | 
								controller.rsLister.Add(rs)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		d := newDeployment(1, &tests[i].revisionHistoryLimit)
 | 
							d := newDeployment(1, &tests[i].revisionHistoryLimit)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -826,12 +826,12 @@ func LastSelectorUpdate(d *extensions.Deployment) unversioned.Time {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// BySelectorLastUpdateTime sorts a list of deployments by the last update time of their selector,
 | 
					// BySelectorLastUpdateTime sorts a list of deployments by the last update time of their selector,
 | 
				
			||||||
// first using their creation timestamp and then their names as a tie breaker.
 | 
					// first using their creation timestamp and then their names as a tie breaker.
 | 
				
			||||||
type BySelectorLastUpdateTime []extensions.Deployment
 | 
					type BySelectorLastUpdateTime []*extensions.Deployment
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (o BySelectorLastUpdateTime) Len() int      { return len(o) }
 | 
					func (o BySelectorLastUpdateTime) Len() int      { return len(o) }
 | 
				
			||||||
func (o BySelectorLastUpdateTime) Swap(i, j int) { o[i], o[j] = o[j], o[i] }
 | 
					func (o BySelectorLastUpdateTime) Swap(i, j int) { o[i], o[j] = o[j], o[i] }
 | 
				
			||||||
func (o BySelectorLastUpdateTime) Less(i, j int) bool {
 | 
					func (o BySelectorLastUpdateTime) Less(i, j int) bool {
 | 
				
			||||||
	ti, tj := LastSelectorUpdate(&o[i]), LastSelectorUpdate(&o[j])
 | 
						ti, tj := LastSelectorUpdate(o[i]), LastSelectorUpdate(o[j])
 | 
				
			||||||
	if ti.Equal(tj) {
 | 
						if ti.Equal(tj) {
 | 
				
			||||||
		if o[i].CreationTimestamp.Equal(o[j].CreationTimestamp) {
 | 
							if o[i].CreationTimestamp.Equal(o[j].CreationTimestamp) {
 | 
				
			||||||
			return o[i].Name < o[j].Name
 | 
								return o[i].Name < o[j].Name
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -68,3 +68,45 @@ func (f *daemonSetInformer) Lister() *cache.StoreToDaemonSetLister {
 | 
				
			|||||||
	informer := f.Informer()
 | 
						informer := f.Informer()
 | 
				
			||||||
	return &cache.StoreToDaemonSetLister{Store: informer.GetIndexer()}
 | 
						return &cache.StoreToDaemonSetLister{Store: informer.GetIndexer()}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// DeploymentInformer is atype of SharedIndexInformer which watches and lists all deployments.
 | 
				
			||||||
 | 
					type DeploymentInformer interface {
 | 
				
			||||||
 | 
						Informer() cache.SharedIndexInformer
 | 
				
			||||||
 | 
						Lister() *cache.StoreToDeploymentLister
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type deploymentInformer struct {
 | 
				
			||||||
 | 
						*sharedInformerFactory
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (f *deploymentInformer) Informer() cache.SharedIndexInformer {
 | 
				
			||||||
 | 
						f.lock.Lock()
 | 
				
			||||||
 | 
						defer f.lock.Unlock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						informerType := reflect.TypeOf(&extensions.Deployment{})
 | 
				
			||||||
 | 
						informer, exists := f.informers[informerType]
 | 
				
			||||||
 | 
						if exists {
 | 
				
			||||||
 | 
							return informer
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						informer = cache.NewSharedIndexInformer(
 | 
				
			||||||
 | 
							&cache.ListWatch{
 | 
				
			||||||
 | 
								ListFunc: func(options api.ListOptions) (runtime.Object, error) {
 | 
				
			||||||
 | 
									return f.client.Extensions().Deployments(api.NamespaceAll).List(options)
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
								WatchFunc: func(options api.ListOptions) (watch.Interface, error) {
 | 
				
			||||||
 | 
									return f.client.Extensions().Deployments(api.NamespaceAll).Watch(options)
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
							&extensions.Deployment{},
 | 
				
			||||||
 | 
							f.defaultResync,
 | 
				
			||||||
 | 
							cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc},
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						f.informers[informerType] = informer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return informer
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (f *deploymentInformer) Lister() *cache.StoreToDeploymentLister {
 | 
				
			||||||
 | 
						informer := f.Informer()
 | 
				
			||||||
 | 
						return &cache.StoreToDeploymentLister{Store: informer.GetIndexer()}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,6 +38,7 @@ type SharedInformerFactory interface {
 | 
				
			|||||||
	PersistentVolumes() PVInformer
 | 
						PersistentVolumes() PVInformer
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	DaemonSets() DaemonSetInformer
 | 
						DaemonSets() DaemonSetInformer
 | 
				
			||||||
 | 
						Deployments() DeploymentInformer
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type sharedInformerFactory struct {
 | 
					type sharedInformerFactory struct {
 | 
				
			||||||
@@ -102,3 +103,7 @@ func (f *sharedInformerFactory) PersistentVolumes() PVInformer {
 | 
				
			|||||||
func (f *sharedInformerFactory) DaemonSets() DaemonSetInformer {
 | 
					func (f *sharedInformerFactory) DaemonSets() DaemonSetInformer {
 | 
				
			||||||
	return &daemonSetInformer{sharedInformerFactory: f}
 | 
						return &daemonSetInformer{sharedInformerFactory: f}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (f *sharedInformerFactory) Deployments() DeploymentInformer {
 | 
				
			||||||
 | 
						return &deploymentInformer{sharedInformerFactory: f}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user