Clean up pre-ControllerRef compatibility logic
This commit is contained in:
@@ -3206,16 +3206,6 @@ func NewDeployment(deploymentName string, replicas int32, podLabels map[string]s
|
||||
// Note that the status should stay valid at all times unless shortly after a scaling event or the deployment is just created.
|
||||
// To verify that the deployment status is valid and wait for the rollout to finish, use WaitForDeploymentStatus instead.
|
||||
func WaitForDeploymentStatusValid(c clientset.Interface, d *extensions.Deployment) error {
|
||||
return waitForDeploymentStatusValid(c, d, false)
|
||||
}
|
||||
|
||||
// WaitForDeploymentStatusValidV15 is a compatibility function that behaves the
|
||||
// way WaitForDeploymentStatusValid() did in v1.5.x.
|
||||
func WaitForDeploymentStatusValidV15(c clientset.Interface, d *extensions.Deployment) error {
|
||||
return waitForDeploymentStatusValid(c, d, true)
|
||||
}
|
||||
|
||||
func waitForDeploymentStatusValid(c clientset.Interface, d *extensions.Deployment, v15Compatible bool) error {
|
||||
var (
|
||||
oldRSs, allOldRSs, allRSs []*extensions.ReplicaSet
|
||||
newRS *extensions.ReplicaSet
|
||||
@@ -3229,11 +3219,7 @@ func waitForDeploymentStatusValid(c clientset.Interface, d *extensions.Deploymen
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if v15Compatible {
|
||||
oldRSs, allOldRSs, newRS, err = deploymentutil.GetAllReplicaSetsV15(deployment, c)
|
||||
} else {
|
||||
oldRSs, allOldRSs, newRS, err = deploymentutil.GetAllReplicaSets(deployment, c)
|
||||
}
|
||||
oldRSs, allOldRSs, newRS, err = deploymentutil.GetAllReplicaSets(deployment, c)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -3279,7 +3265,7 @@ func waitForDeploymentStatusValid(c clientset.Interface, d *extensions.Deploymen
|
||||
|
||||
if err == wait.ErrWaitTimeout {
|
||||
logReplicaSetsOfDeployment(deployment, allOldRSs, newRS)
|
||||
logPodsOfDeployment(c, deployment, allRSs, v15Compatible)
|
||||
logPodsOfDeployment(c, deployment, allRSs)
|
||||
err = fmt.Errorf("%s", reason)
|
||||
}
|
||||
if err != nil {
|
||||
@@ -3291,16 +3277,6 @@ func waitForDeploymentStatusValid(c clientset.Interface, d *extensions.Deploymen
|
||||
// Waits for the deployment to reach desired state.
|
||||
// Returns an error if the deployment's rolling update strategy (max unavailable or max surge) is broken at any times.
|
||||
func WaitForDeploymentStatus(c clientset.Interface, d *extensions.Deployment) error {
|
||||
return waitForDeploymentStatus(c, d, false)
|
||||
}
|
||||
|
||||
// WaitForDeploymentStatusV15 is a compatibility function that behaves the way
|
||||
// WaitForDeploymentStatus() did in v1.5.x.
|
||||
func WaitForDeploymentStatusV15(c clientset.Interface, d *extensions.Deployment) error {
|
||||
return waitForDeploymentStatus(c, d, true)
|
||||
}
|
||||
|
||||
func waitForDeploymentStatus(c clientset.Interface, d *extensions.Deployment, v15Compatible bool) error {
|
||||
var (
|
||||
oldRSs, allOldRSs, allRSs []*extensions.ReplicaSet
|
||||
newRS *extensions.ReplicaSet
|
||||
@@ -3313,11 +3289,7 @@ func waitForDeploymentStatus(c clientset.Interface, d *extensions.Deployment, v1
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if v15Compatible {
|
||||
oldRSs, allOldRSs, newRS, err = deploymentutil.GetAllReplicaSetsV15(deployment, c)
|
||||
} else {
|
||||
oldRSs, allOldRSs, newRS, err = deploymentutil.GetAllReplicaSets(deployment, c)
|
||||
}
|
||||
oldRSs, allOldRSs, newRS, err = deploymentutil.GetAllReplicaSets(deployment, c)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -3336,13 +3308,13 @@ func waitForDeploymentStatus(c clientset.Interface, d *extensions.Deployment, v1
|
||||
maxCreated := *(deployment.Spec.Replicas) + deploymentutil.MaxSurge(*deployment)
|
||||
if totalCreated > maxCreated {
|
||||
logReplicaSetsOfDeployment(deployment, allOldRSs, newRS)
|
||||
logPodsOfDeployment(c, deployment, allRSs, v15Compatible)
|
||||
logPodsOfDeployment(c, deployment, allRSs)
|
||||
return false, fmt.Errorf("total pods created: %d, more than the max allowed: %d", totalCreated, maxCreated)
|
||||
}
|
||||
minAvailable := deploymentutil.MinAvailable(deployment)
|
||||
if deployment.Status.AvailableReplicas < minAvailable {
|
||||
logReplicaSetsOfDeployment(deployment, allOldRSs, newRS)
|
||||
logPodsOfDeployment(c, deployment, allRSs, v15Compatible)
|
||||
logPodsOfDeployment(c, deployment, allRSs)
|
||||
return false, fmt.Errorf("total pods available: %d, less than the min required: %d", deployment.Status.AvailableReplicas, minAvailable)
|
||||
}
|
||||
|
||||
@@ -3352,7 +3324,7 @@ func waitForDeploymentStatus(c clientset.Interface, d *extensions.Deployment, v1
|
||||
|
||||
if err == wait.ErrWaitTimeout {
|
||||
logReplicaSetsOfDeployment(deployment, allOldRSs, newRS)
|
||||
logPodsOfDeployment(c, deployment, allRSs, v15Compatible)
|
||||
logPodsOfDeployment(c, deployment, allRSs)
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("error waiting for deployment %q status to match expectation: %v", d.Name, err)
|
||||
@@ -3422,7 +3394,7 @@ func WatchRecreateDeployment(c clientset.Interface, d *extensions.Deployment) er
|
||||
if err == nil && nerr == nil {
|
||||
Logf("%+v", d)
|
||||
logReplicaSetsOfDeployment(d, allOldRSs, newRS)
|
||||
logPodsOfDeployment(c, d, append(allOldRSs, newRS), false)
|
||||
logPodsOfDeployment(c, d, append(allOldRSs, newRS))
|
||||
}
|
||||
return false, fmt.Errorf("deployment %q is running new pods alongside old pods: %#v", d.Name, status)
|
||||
}
|
||||
@@ -3442,16 +3414,6 @@ func WatchRecreateDeployment(c clientset.Interface, d *extensions.Deployment) er
|
||||
// WaitForDeploymentRevisionAndImage waits for the deployment's and its new RS's revision and container image to match the given revision and image.
|
||||
// Note that deployment revision and its new RS revision should be updated shortly, so we only wait for 1 minute here to fail early.
|
||||
func WaitForDeploymentRevisionAndImage(c clientset.Interface, ns, deploymentName string, revision, image string) error {
|
||||
return waitForDeploymentRevisionAndImage(c, ns, deploymentName, revision, image, false)
|
||||
}
|
||||
|
||||
// WaitForDeploymentRevisionAndImageV15 is a compatibility function that behaves
|
||||
// the way WaitForDeploymentRevisionAndImage() did in v1.5.x.
|
||||
func WaitForDeploymentRevisionAndImageV15(c clientset.Interface, ns, deploymentName string, revision, image string) error {
|
||||
return waitForDeploymentRevisionAndImage(c, ns, deploymentName, revision, image, true)
|
||||
}
|
||||
|
||||
func waitForDeploymentRevisionAndImage(c clientset.Interface, ns, deploymentName string, revision, image string, v15Compatible bool) error {
|
||||
var deployment *extensions.Deployment
|
||||
var newRS *extensions.ReplicaSet
|
||||
var reason string
|
||||
@@ -3462,11 +3424,9 @@ func waitForDeploymentRevisionAndImage(c clientset.Interface, ns, deploymentName
|
||||
return false, err
|
||||
}
|
||||
// The new ReplicaSet needs to be non-nil and contain the pod-template-hash label
|
||||
if v15Compatible {
|
||||
newRS, err = deploymentutil.GetNewReplicaSetV15(deployment, c)
|
||||
} else {
|
||||
newRS, err = deploymentutil.GetNewReplicaSet(deployment, c)
|
||||
}
|
||||
|
||||
newRS, err = deploymentutil.GetNewReplicaSet(deployment, c)
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -3613,24 +3573,20 @@ func WaitForDeploymentWithCondition(c clientset.Interface, ns, deploymentName, r
|
||||
_, allOldRSs, newRS, err := deploymentutil.GetAllReplicaSets(deployment, c)
|
||||
if err == nil {
|
||||
logReplicaSetsOfDeployment(deployment, allOldRSs, newRS)
|
||||
logPodsOfDeployment(c, deployment, append(allOldRSs, newRS), false)
|
||||
logPodsOfDeployment(c, deployment, append(allOldRSs, newRS))
|
||||
}
|
||||
}
|
||||
return pollErr
|
||||
}
|
||||
|
||||
func logPodsOfDeployment(c clientset.Interface, deployment *extensions.Deployment, rsList []*extensions.ReplicaSet, v15Compatible bool) {
|
||||
func logPodsOfDeployment(c clientset.Interface, deployment *extensions.Deployment, rsList []*extensions.ReplicaSet) {
|
||||
minReadySeconds := deployment.Spec.MinReadySeconds
|
||||
podListFunc := func(namespace string, options metav1.ListOptions) (*v1.PodList, error) {
|
||||
return c.Core().Pods(namespace).List(options)
|
||||
}
|
||||
var podList *v1.PodList
|
||||
var err error
|
||||
if v15Compatible {
|
||||
podList, err = deploymentutil.ListPodsV15(deployment, rsList, podListFunc)
|
||||
} else {
|
||||
podList, err = deploymentutil.ListPods(deployment, rsList, podListFunc)
|
||||
}
|
||||
|
||||
podList, err := deploymentutil.ListPods(deployment, rsList, podListFunc)
|
||||
|
||||
if err != nil {
|
||||
Logf("Failed to list Pods of Deployment %s: %v", deployment.Name, err)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user