mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Merge pull request #41250 from kargakis/switch-get-from-cache
Automatic merge from submit-queue (batch tested with PRs 41621, 41946, 41941, 41250, 41729) controller: poll replica sets from the cache
This commit is contained in:
		@@ -180,7 +180,9 @@ func (dc *DeploymentController) addHashKeyToRSAndPods(rs *extensions.ReplicaSet)
 | 
			
		||||
	}
 | 
			
		||||
	// Make sure rs pod template is updated so that it won't create pods without the new label (orphaned pods).
 | 
			
		||||
	if updatedRS.Generation > updatedRS.Status.ObservedGeneration {
 | 
			
		||||
		if err = deploymentutil.WaitForReplicaSetUpdated(dc.client, updatedRS.Generation, updatedRS.Namespace, updatedRS.Name); err != nil {
 | 
			
		||||
		// TODO: Revisit if we really need to wait here as opposed to returning and
 | 
			
		||||
		// potentially unblocking this worker (can wait up to 1min before timing out).
 | 
			
		||||
		if err = deploymentutil.WaitForReplicaSetUpdated(dc.rsLister, updatedRS.Generation, updatedRS.Namespace, updatedRS.Name); err != nil {
 | 
			
		||||
			return nil, fmt.Errorf("error waiting for replica set %s/%s to be observed by controller: %v", updatedRS.Namespace, updatedRS.Name, err)
 | 
			
		||||
		}
 | 
			
		||||
		glog.V(4).Infof("Observed the update of replica set %s/%s's pod template with hash %s.", rs.Namespace, rs.Name, hash)
 | 
			
		||||
@@ -213,7 +215,9 @@ func (dc *DeploymentController) addHashKeyToRSAndPods(rs *extensions.ReplicaSet)
 | 
			
		||||
	// WaitForReplicaSetUpdated, the replicaset controller should have dropped
 | 
			
		||||
	// FullyLabeledReplicas to 0 already, we only need to wait it to increase
 | 
			
		||||
	// back to the number of replicas in the spec.
 | 
			
		||||
	if err := deploymentutil.WaitForPodsHashPopulated(dc.client, updatedRS.Generation, updatedRS.Namespace, updatedRS.Name); err != nil {
 | 
			
		||||
	// TODO: Revisit if we really need to wait here as opposed to returning and
 | 
			
		||||
	// potentially unblocking this worker (can wait up to 1min before timing out).
 | 
			
		||||
	if err := deploymentutil.WaitForPodsHashPopulated(dc.rsLister, updatedRS.Generation, updatedRS.Namespace, updatedRS.Name); err != nil {
 | 
			
		||||
		return nil, fmt.Errorf("Replica set %s/%s: error waiting for replicaset controller to observe pods being labeled with template hash: %v", updatedRS.Namespace, updatedRS.Name, err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -41,6 +41,7 @@ import (
 | 
			
		||||
	extensions "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
 | 
			
		||||
	corelisters "k8s.io/kubernetes/pkg/client/listers/core/v1"
 | 
			
		||||
	extensionslisters "k8s.io/kubernetes/pkg/client/listers/extensions/v1beta1"
 | 
			
		||||
	"k8s.io/kubernetes/pkg/controller"
 | 
			
		||||
	labelsutil "k8s.io/kubernetes/pkg/util/labels"
 | 
			
		||||
)
 | 
			
		||||
@@ -668,9 +669,9 @@ func FindOldReplicaSets(deployment *extensions.Deployment, rsList []*extensions.
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// WaitForReplicaSetUpdated polls the replica set until it is updated.
 | 
			
		||||
func WaitForReplicaSetUpdated(c clientset.Interface, desiredGeneration int64, namespace, name string) error {
 | 
			
		||||
	return wait.Poll(10*time.Millisecond, 1*time.Minute, func() (bool, error) {
 | 
			
		||||
		rs, err := c.Extensions().ReplicaSets(namespace).Get(name, metav1.GetOptions{})
 | 
			
		||||
func WaitForReplicaSetUpdated(c extensionslisters.ReplicaSetLister, desiredGeneration int64, namespace, name string) error {
 | 
			
		||||
	return wait.PollImmediate(1*time.Second, 1*time.Minute, func() (bool, error) {
 | 
			
		||||
		rs, err := c.ReplicaSets(namespace).Get(name)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return false, err
 | 
			
		||||
		}
 | 
			
		||||
@@ -679,9 +680,9 @@ func WaitForReplicaSetUpdated(c clientset.Interface, desiredGeneration int64, na
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// WaitForPodsHashPopulated polls the replica set until updated and fully labeled.
 | 
			
		||||
func WaitForPodsHashPopulated(c clientset.Interface, desiredGeneration int64, namespace, name string) error {
 | 
			
		||||
	return wait.Poll(1*time.Second, 1*time.Minute, func() (bool, error) {
 | 
			
		||||
		rs, err := c.Extensions().ReplicaSets(namespace).Get(name, metav1.GetOptions{})
 | 
			
		||||
func WaitForPodsHashPopulated(c extensionslisters.ReplicaSetLister, desiredGeneration int64, namespace, name string) error {
 | 
			
		||||
	return wait.PollImmediate(1*time.Second, 1*time.Minute, func() (bool, error) {
 | 
			
		||||
		rs, err := c.ReplicaSets(namespace).Get(name)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return false, err
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user