-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[k8s] Fix panic in WaitUntilDeploymentAvailable
The `func (err DeploymentNotAvailable) Error()` method should not assume that `Status.Conditions[0]` is always valid for the Deployment. Fixes #1329 Signed-off-by: Antonin Bas <abas@vmware.com>
- Loading branch information
1 parent
a6467d4
commit f689e8c
Showing
4 changed files
with
92 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package k8s | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
appsv1 "k8s.io/api/apps/v1" | ||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestErrorDeploymentNotAvailable(t *testing.T) { | ||
testCases := []struct { | ||
title string | ||
deploy *appsv1.Deployment | ||
expectedErr string | ||
}{ | ||
{ | ||
title: "NoProgressingCondition", | ||
deploy: &appsv1.Deployment{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "foo", | ||
}, | ||
Status: appsv1.DeploymentStatus{ | ||
Conditions: []appsv1.DeploymentCondition{}, | ||
}, | ||
}, | ||
expectedErr: "Deployment foo is not available, missing 'Progressing' condition", | ||
}, | ||
{ | ||
title: "DeploymentNotComplete", | ||
deploy: &appsv1.Deployment{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "foo", | ||
}, | ||
Status: appsv1.DeploymentStatus{ | ||
Conditions: []appsv1.DeploymentCondition{ | ||
{ | ||
Type: appsv1.DeploymentProgressing, | ||
Status: v1.ConditionTrue, | ||
Reason: "ReplicaSetUpdated", | ||
Message: "bar", | ||
}, | ||
}, | ||
}, | ||
}, | ||
expectedErr: "Deployment foo is not available as 'Progressing' condition indicates that the Deployment is not complete, status: True, reason: ReplicaSetUpdated, message: bar", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
t.Run(tc.title, func(t *testing.T) { | ||
t.Parallel() | ||
err := NewDeploymentNotAvailableError(tc.deploy) | ||
assert.EqualError(t, err, tc.expectedErr) | ||
}) | ||
} | ||
} |