Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to check minimum availability time in waitForDeploymentRo…
…llout
- Loading branch information
Showing
4 changed files
with
164 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package operator | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
appsv1 "k8s.io/api/apps/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
) | ||
|
||
func TestWaitForDeploymentRollout(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
deployment *appsv1.Deployment | ||
expected error | ||
}{ | ||
{ | ||
name: "Deployment is available for more than deploymentMinimumAvailabilityTime min", | ||
deployment: &appsv1.Deployment{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: "Deployment", | ||
APIVersion: "apps/v1", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test", | ||
Namespace: targetNamespace, | ||
}, | ||
Status: appsv1.DeploymentStatus{ | ||
Replicas: 1, | ||
UpdatedReplicas: 1, | ||
ReadyReplicas: 1, | ||
AvailableReplicas: 1, | ||
UnavailableReplicas: 0, | ||
Conditions: []appsv1.DeploymentCondition{ | ||
{ | ||
Type: appsv1.DeploymentAvailable, | ||
Status: corev1.ConditionTrue, | ||
LastTransitionTime: metav1.Time{Time: time.Now().Add(-deploymentMinimumAvailabilityTime - 1*time.Second)}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: nil, | ||
}, | ||
{ | ||
name: "Deployment is available for less than deploymentMinimumAvailabilityTime min", | ||
deployment: &appsv1.Deployment{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: "Deployment", | ||
APIVersion: "apps/v1", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test", | ||
Namespace: targetNamespace, | ||
}, | ||
Status: appsv1.DeploymentStatus{ | ||
Replicas: 1, | ||
UpdatedReplicas: 1, | ||
ReadyReplicas: 1, | ||
AvailableReplicas: 1, | ||
UnavailableReplicas: 0, | ||
Conditions: []appsv1.DeploymentCondition{ | ||
{ | ||
Type: appsv1.DeploymentAvailable, | ||
Status: corev1.ConditionTrue, | ||
LastTransitionTime: metav1.Time{Time: time.Now().Add(-10 * time.Second)}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: fmt.Errorf("deployment test has been available for less than 3 min"), | ||
}, | ||
{ | ||
name: "Deployment has unavailable replicas", | ||
deployment: &appsv1.Deployment{ | ||
TypeMeta: metav1.TypeMeta{ | ||
Kind: "Deployment", | ||
APIVersion: "apps/v1", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "test", | ||
Namespace: targetNamespace, | ||
}, | ||
Status: appsv1.DeploymentStatus{ | ||
Replicas: 1, | ||
UpdatedReplicas: 1, | ||
ReadyReplicas: 1, | ||
AvailableReplicas: 1, | ||
UnavailableReplicas: 1, | ||
Conditions: []appsv1.DeploymentCondition{ | ||
{ | ||
Type: appsv1.DeploymentAvailable, | ||
Status: corev1.ConditionTrue, | ||
LastTransitionTime: metav1.Time{Time: time.Now().Add(-10 * time.Second)}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
expected: fmt.Errorf("deployment test is not ready. status: (replicas: 1, updated: 1, ready: 1, unavailable: 1)"), | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
optr := newFakeOperator([]runtime.Object{tc.deployment}, nil, make(<-chan struct{})) | ||
|
||
got := optr.waitForDeploymentRollout(tc.deployment, 1*time.Second, 3*time.Second) | ||
if tc.expected != nil { | ||
if tc.expected.Error() != got.Error() { | ||
t.Errorf("Got: %v, expected: %v", got, tc.expected) | ||
} | ||
} else if tc.expected != got { | ||
t.Errorf("Got: %v, expected: %v", got, tc.expected) | ||
} | ||
}) | ||
} | ||
} |
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