Skip to content
This repository has been archived by the owner on Jun 24, 2020. It is now read-only.

Commit

Permalink
Fix the retry issue with deployment verification (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent authored Apr 4, 2020
1 parent d0e771a commit acb5e5d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
25 changes: 12 additions & 13 deletions test/resources/knativeserving.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,41 +132,40 @@ func getTestKSOperatorCRSpec() v1alpha1.KnativeServingSpec {

// WaitForKnativeServingDeploymentState polls the status of the Knative deployments every `interval`
// until `inState` returns `true` indicating the deployments match the desired deployments.
func WaitForKnativeServingDeploymentState(clients *test.Clients, namespace string, expectedDeployments []string,
inState func(deps *v1.DeploymentList, expectedDeployments []string, err error) (bool, error)) (*v1alpha1.KnativeServing, error) {
func WaitForKnativeServingDeploymentState(clients *test.Clients, namespace string, expectedDeployments []string, logf logging.FormatLogger,
inState func(deps *v1.DeploymentList, expectedDeployments []string, err error, logf logging.FormatLogger) (bool, error)) error {
span := logging.GetEmitableSpan(context.Background(), fmt.Sprintf("WaitForKnativeDeploymentState/%s/%s", expectedDeployments, "KnativeDeploymentIsReady"))
defer span.End()

var lastState *v1alpha1.KnativeServing
waitErr := wait.PollImmediate(Interval, Timeout, func() (bool, error) {
dpList, err := clients.KubeClient.Kube.AppsV1().Deployments(namespace).List(metav1.ListOptions{})
return inState(dpList, expectedDeployments, err)
return inState(dpList, expectedDeployments, err, logf)
})

if waitErr != nil {
return lastState, waitErr
return waitErr
}
return lastState, nil
return nil
}

// IsKnativeServingDeploymentReady will check the status conditions of the deployments and return true if the deployments meet the desired status.
func IsKnativeServingDeploymentReady(dpList *v1.DeploymentList, expectedDeployments []string, err error) (bool, error) {
func IsKnativeServingDeploymentReady(dpList *v1.DeploymentList, expectedDeployments []string, err error, logf logging.FormatLogger) (bool, error) {
if err != nil {
return false, err
}
if len(dpList.Items) != len(expectedDeployments) {
errMessage := fmt.Sprintf("The expected number of deployments is %v, and got %v.", len(expectedDeployments), len(dpList.Items))
return false, errors.New(errMessage)
logf("The expected number of deployments is %v, and got %v.", len(expectedDeployments), len(dpList.Items))
return false, nil
}
for _, deployment := range dpList.Items {
if !stringInList(deployment.Name, expectedDeployments) {
errMessage := fmt.Sprintf("The deployment %v is not found in the expected list of deployment.", deployment.Name)
return false, errors.New(errMessage)
logf("The deployment %v is not found in the expected list of deployment.", deployment.Name)
return false, nil
}
for _, c := range deployment.Status.Conditions {
if c.Type == v1.DeploymentAvailable && c.Status != corev1.ConditionTrue {
errMessage := fmt.Sprintf("The deployment %v is not ready.", deployment.Name)
return false, errors.New(errMessage)
logf("The deployment %v is not ready.", deployment.Name)
return false, nil
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/resources/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func verifyNoKSOperatorCR(clients *test.Clients) error {

// AssertKSOperatorDeploymentStatus verifies if the Knative deployments reach the READY status.
func AssertKSOperatorDeploymentStatus(t *testing.T, clients *test.Clients, namespace string, expectedDeployments []string) {
if _, err := WaitForKnativeServingDeploymentState(clients, namespace, expectedDeployments,
if err := WaitForKnativeServingDeploymentState(clients, namespace, expectedDeployments, t.Logf,
IsKnativeServingDeploymentReady); err != nil {
t.Fatalf("Knative Serving deployments failed to meet the expected deployments: %v", err)
}
Expand Down

0 comments on commit acb5e5d

Please sign in to comment.