mirror of https://github.com/k3s-io/k3s
Merge pull request #21902 from janetkuo/deployment-unavailable-replicas
Fix the incorrect deployment.status.unavailableReplicaspull/6/head
commit
88056edab2
|
@ -593,11 +593,11 @@ func (dc *DeploymentController) syncRollingUpdateDeployment(deployment extension
|
|||
|
||||
// syncDeploymentStatus checks if the status is up-to-date and sync it if necessary
|
||||
func (dc *DeploymentController) syncDeploymentStatus(allRSs []*extensions.ReplicaSet, newRS *extensions.ReplicaSet, d extensions.Deployment) error {
|
||||
totalReplicas, updatedReplicas, availableReplicas, _, err := dc.calculateStatus(allRSs, newRS, d)
|
||||
totalActualReplicas, updatedReplicas, availableReplicas, _, err := dc.calculateStatus(allRSs, newRS, d)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if d.Generation > d.Status.ObservedGeneration || d.Status.Replicas != totalReplicas || d.Status.UpdatedReplicas != updatedReplicas || d.Status.AvailableReplicas != availableReplicas {
|
||||
if d.Generation > d.Status.ObservedGeneration || d.Status.Replicas != totalActualReplicas || d.Status.UpdatedReplicas != updatedReplicas || d.Status.AvailableReplicas != availableReplicas {
|
||||
return dc.updateDeploymentStatus(allRSs, newRS, d)
|
||||
}
|
||||
return nil
|
||||
|
@ -1044,7 +1044,7 @@ func (dc *DeploymentController) cleanupOldReplicaSets(oldRSs []*extensions.Repli
|
|||
}
|
||||
|
||||
func (dc *DeploymentController) updateDeploymentStatus(allRSs []*extensions.ReplicaSet, newRS *extensions.ReplicaSet, deployment extensions.Deployment) error {
|
||||
totalReplicas, updatedReplicas, availableReplicas, unavailableReplicas, err := dc.calculateStatus(allRSs, newRS, deployment)
|
||||
totalActualReplicas, updatedReplicas, availableReplicas, unavailableReplicas, err := dc.calculateStatus(allRSs, newRS, deployment)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1053,7 +1053,7 @@ func (dc *DeploymentController) updateDeploymentStatus(allRSs []*extensions.Repl
|
|||
newDeployment.Status = extensions.DeploymentStatus{
|
||||
// TODO: Ensure that if we start retrying status updates, we won't pick up a new Generation value.
|
||||
ObservedGeneration: deployment.Generation,
|
||||
Replicas: totalReplicas,
|
||||
Replicas: totalActualReplicas,
|
||||
UpdatedReplicas: updatedReplicas,
|
||||
AvailableReplicas: availableReplicas,
|
||||
UnavailableReplicas: unavailableReplicas,
|
||||
|
@ -1062,8 +1062,8 @@ func (dc *DeploymentController) updateDeploymentStatus(allRSs []*extensions.Repl
|
|||
return err
|
||||
}
|
||||
|
||||
func (dc *DeploymentController) calculateStatus(allRSs []*extensions.ReplicaSet, newRS *extensions.ReplicaSet, deployment extensions.Deployment) (totalReplicas, updatedReplicas, availableReplicas, unavailableReplicas int, err error) {
|
||||
totalReplicas = deploymentutil.GetActualReplicaCountForReplicaSets(allRSs)
|
||||
func (dc *DeploymentController) calculateStatus(allRSs []*extensions.ReplicaSet, newRS *extensions.ReplicaSet, deployment extensions.Deployment) (totalActualReplicas, updatedReplicas, availableReplicas, unavailableReplicas int, err error) {
|
||||
totalActualReplicas = deploymentutil.GetActualReplicaCountForReplicaSets(allRSs)
|
||||
updatedReplicas = deploymentutil.GetActualReplicaCountForReplicaSets([]*extensions.ReplicaSet{newRS})
|
||||
minReadySeconds := deployment.Spec.MinReadySeconds
|
||||
availableReplicas, err = deploymentutil.GetAvailablePodsForReplicaSets(dc.client, allRSs, minReadySeconds)
|
||||
|
@ -1071,6 +1071,7 @@ func (dc *DeploymentController) calculateStatus(allRSs []*extensions.ReplicaSet,
|
|||
err = fmt.Errorf("failed to count available pods: %v", err)
|
||||
return
|
||||
}
|
||||
totalReplicas := deploymentutil.GetReplicaCountForReplicaSets(allRSs)
|
||||
unavailableReplicas = totalReplicas - availableReplicas
|
||||
return
|
||||
}
|
||||
|
|
|
@ -377,7 +377,7 @@ func IsPodAvailable(pod *api.Pod, minReadySeconds int) bool {
|
|||
}
|
||||
|
||||
func GetPodsForReplicaSets(c clientset.Interface, replicaSets []*extensions.ReplicaSet) ([]api.Pod, error) {
|
||||
allPods := []api.Pod{}
|
||||
allPods := map[string]api.Pod{}
|
||||
for _, rs := range replicaSets {
|
||||
selector, err := unversioned.LabelSelectorAsSelector(rs.Spec.Selector)
|
||||
if err != nil {
|
||||
|
@ -386,11 +386,17 @@ func GetPodsForReplicaSets(c clientset.Interface, replicaSets []*extensions.Repl
|
|||
options := api.ListOptions{LabelSelector: selector}
|
||||
podList, err := c.Core().Pods(rs.ObjectMeta.Namespace).List(options)
|
||||
if err != nil {
|
||||
return allPods, fmt.Errorf("error listing pods: %v", err)
|
||||
return nil, fmt.Errorf("error listing pods: %v", err)
|
||||
}
|
||||
allPods = append(allPods, podList.Items...)
|
||||
for _, pod := range podList.Items {
|
||||
allPods[pod.Name] = pod
|
||||
}
|
||||
return allPods, nil
|
||||
}
|
||||
requiredPods := []api.Pod{}
|
||||
for _, pod := range allPods {
|
||||
requiredPods = append(requiredPods, pod)
|
||||
}
|
||||
return requiredPods, nil
|
||||
}
|
||||
|
||||
// Revision returns the revision number of the input replica set
|
||||
|
|
Loading…
Reference in New Issue