Deployment: Filter Pods by Deployment selector in addition to ControllerRef.
Deployment should ignore Pods that don't match the selector, even if they have a ControllerRef pointing to one of the ReplicaSets it owns. The ReplicaSet itself will orphan the Pod as soon as it syncs.
This commit is contained in:
parent
37534b66df
commit
d96c4847b6
|
@ -371,7 +371,7 @@ func (dc *DeploymentController) deletePod(obj interface{}) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
podMap, err := dc.getPodMapForReplicaSets(d.Namespace, rsList)
|
podMap, err := dc.getPodMapForDeployment(d, rsList)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -506,11 +506,17 @@ func (dc *DeploymentController) getReplicaSetsForDeployment(d *extensions.Deploy
|
||||||
return cm.ClaimReplicaSets(rsList)
|
return cm.ClaimReplicaSets(rsList)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getPodMapForReplicaSets scans the list of all Pods and returns a map from
|
// getPodMapForDeployment returns the Pods managed by a Deployment.
|
||||||
// RS UID to Pods controlled by that RS, based on the Pod's ControllerRef.
|
//
|
||||||
func (dc *DeploymentController) getPodMapForReplicaSets(namespace string, rsList []*extensions.ReplicaSet) (map[types.UID]*v1.PodList, error) {
|
// It returns a map from ReplicaSet UID to a list of Pods controlled by that RS,
|
||||||
// List all Pods.
|
// according to the Pod's ControllerRef.
|
||||||
pods, err := dc.podLister.Pods(namespace).List(labels.Everything())
|
func (dc *DeploymentController) getPodMapForDeployment(d *extensions.Deployment, rsList []*extensions.ReplicaSet) (map[types.UID]*v1.PodList, error) {
|
||||||
|
// Get all Pods that potentially belong to this Deployment.
|
||||||
|
selector, err := metav1.LabelSelectorAsSelector(d.Spec.Selector)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
pods, err := dc.podLister.Pods(d.Namespace).List(selector)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -583,8 +589,7 @@ func (dc *DeploymentController) syncDeployment(key string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// List all Pods owned by this Deployment, grouped by their ReplicaSet.
|
// List all Pods owned by this Deployment, grouped by their ReplicaSet.
|
||||||
// This is expensive, so do it once and pass it along to subroutines.
|
podMap, err := dc.getPodMapForDeployment(d, rsList)
|
||||||
podMap, err := dc.getPodMapForReplicaSets(d.Namespace, rsList)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -515,9 +515,9 @@ func TestGetPodMapForReplicaSets(t *testing.T) {
|
||||||
defer close(stopCh)
|
defer close(stopCh)
|
||||||
informers.Start(stopCh)
|
informers.Start(stopCh)
|
||||||
|
|
||||||
podMap, err := c.getPodMapForReplicaSets(d.Namespace, f.rsLister)
|
podMap, err := c.getPodMapForDeployment(d, f.rsLister)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("getPodMapForReplicaSets() error: %v", err)
|
t.Fatalf("getPodMapForDeployment() error: %v", err)
|
||||||
}
|
}
|
||||||
podCount := 0
|
podCount := 0
|
||||||
for _, podList := range podMap {
|
for _, podList := range podMap {
|
||||||
|
|
|
@ -100,8 +100,7 @@ func (dc *DeploymentController) checkPausedConditions(d *extensions.Deployment)
|
||||||
// getAllReplicaSetsAndSyncRevision returns all the replica sets for the provided deployment (new and all old), with new RS's and deployment's revision updated.
|
// getAllReplicaSetsAndSyncRevision returns all the replica sets for the provided deployment (new and all old), with new RS's and deployment's revision updated.
|
||||||
//
|
//
|
||||||
// rsList should come from getReplicaSetsForDeployment(d).
|
// rsList should come from getReplicaSetsForDeployment(d).
|
||||||
// podMap should come from getPodMapForReplicaSets(rsList).
|
// podMap should come from getPodMapForDeployment(d, rsList).
|
||||||
// These are passed around to avoid repeating expensive API calls.
|
|
||||||
//
|
//
|
||||||
// 1. Get all old RSes this deployment targets, and calculate the max revision number among them (maxOldV).
|
// 1. Get all old RSes this deployment targets, and calculate the max revision number among them (maxOldV).
|
||||||
// 2. Get new RS this deployment targets (whose pod template matches deployment's), and update new RS's revision number to (maxOldV + 1),
|
// 2. Get new RS this deployment targets (whose pod template matches deployment's), and update new RS's revision number to (maxOldV + 1),
|
||||||
|
@ -134,8 +133,7 @@ func (dc *DeploymentController) getAllReplicaSetsAndSyncRevision(d *extensions.D
|
||||||
// targets, with pod-template-hash information synced.
|
// targets, with pod-template-hash information synced.
|
||||||
//
|
//
|
||||||
// rsList should come from getReplicaSetsForDeployment(d).
|
// rsList should come from getReplicaSetsForDeployment(d).
|
||||||
// podMap should come from getPodMapForReplicaSets(rsList).
|
// podMap should come from getPodMapForDeployment(d, rsList).
|
||||||
// These are passed around to avoid repeating expensive API calls.
|
|
||||||
func (dc *DeploymentController) rsAndPodsWithHashKeySynced(d *extensions.Deployment, rsList []*extensions.ReplicaSet, podMap map[types.UID]*v1.PodList) ([]*extensions.ReplicaSet, *v1.PodList, error) {
|
func (dc *DeploymentController) rsAndPodsWithHashKeySynced(d *extensions.Deployment, rsList []*extensions.ReplicaSet, podMap map[types.UID]*v1.PodList) ([]*extensions.ReplicaSet, *v1.PodList, error) {
|
||||||
syncedRSList := []*extensions.ReplicaSet{}
|
syncedRSList := []*extensions.ReplicaSet{}
|
||||||
for _, rs := range rsList {
|
for _, rs := range rsList {
|
||||||
|
@ -594,8 +592,7 @@ func calculateStatus(allRSs []*extensions.ReplicaSet, newRS *extensions.ReplicaS
|
||||||
// by looking at the desired-replicas annotation in the active replica sets of the deployment.
|
// by looking at the desired-replicas annotation in the active replica sets of the deployment.
|
||||||
//
|
//
|
||||||
// rsList should come from getReplicaSetsForDeployment(d).
|
// rsList should come from getReplicaSetsForDeployment(d).
|
||||||
// podMap should come from getPodMapForReplicaSets(rsList).
|
// podMap should come from getPodMapForDeployment(d, rsList).
|
||||||
// These are passed around to avoid repeating expensive API calls.
|
|
||||||
func (dc *DeploymentController) isScalingEvent(d *extensions.Deployment, rsList []*extensions.ReplicaSet, podMap map[types.UID]*v1.PodList) (bool, error) {
|
func (dc *DeploymentController) isScalingEvent(d *extensions.Deployment, rsList []*extensions.ReplicaSet, podMap map[types.UID]*v1.PodList) (bool, error) {
|
||||||
newRS, oldRSs, err := dc.getAllReplicaSetsAndSyncRevision(d, rsList, podMap, false)
|
newRS, oldRSs, err := dc.getAllReplicaSetsAndSyncRevision(d, rsList, podMap, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue