@ -44,27 +44,51 @@ func Test_ReadyChecker_deploymentReady(t *testing.T) {
{
{
name : "deployment is ready" ,
name : "deployment is ready" ,
args : args {
args : args {
rs : newReplicaSet ( "foo" , 1 , 1 ),
rs : newReplicaSet ( "foo" , 1 , 1 , true ),
dep : newDeployment ( "foo" , 1 , 1 , 0 ),
dep : newDeployment ( "foo" , 1 , 1 , 0 , true ),
} ,
} ,
want : true ,
want : true ,
} ,
} ,
{
{
name : "deployment is not ready" ,
name : "deployment is not ready" ,
args : args {
args : args {
rs : newReplicaSet ( "foo" , 0 , 0 ),
rs : newReplicaSet ( "foo" , 0 , 0 , true ),
dep : newDeployment ( "foo" , 1 , 1 , 0 ),
dep : newDeployment ( "foo" , 1 , 1 , 0 , true ),
} ,
} ,
want : false ,
want : false ,
} ,
} ,
{
{
name : "deployment is ready when maxUnavailable is set" ,
name : "deployment is ready when maxUnavailable is set" ,
args : args {
args : args {
rs : newReplicaSet ( "foo" , 2 , 1 ),
rs : newReplicaSet ( "foo" , 2 , 1 , true ),
dep : newDeployment ( "foo" , 2 , 1 , 1 ),
dep : newDeployment ( "foo" , 2 , 1 , 1 , true ),
} ,
} ,
want : true ,
want : true ,
} ,
} ,
{
name : "deployment is not ready when replicaset generations are out of sync" ,
args : args {
rs : newReplicaSet ( "foo" , 1 , 1 , false ) ,
dep : newDeployment ( "foo" , 1 , 1 , 0 , true ) ,
} ,
want : false ,
} ,
{
name : "deployment is not ready when deployment generations are out of sync" ,
args : args {
rs : newReplicaSet ( "foo" , 1 , 1 , true ) ,
dep : newDeployment ( "foo" , 1 , 1 , 0 , false ) ,
} ,
want : false ,
} ,
{
name : "deployment is not ready when generations are out of sync" ,
args : args {
rs : newReplicaSet ( "foo" , 1 , 1 , false ) ,
dep : newDeployment ( "foo" , 1 , 1 , 0 , false ) ,
} ,
want : false ,
} ,
}
}
for _ , tt := range tests {
for _ , tt := range tests {
t . Run ( tt . name , func ( t * testing . T ) {
t . Run ( tt . name , func ( t * testing . T ) {
@ -76,6 +100,74 @@ func Test_ReadyChecker_deploymentReady(t *testing.T) {
}
}
}
}
func Test_ReadyChecker_replicaSetReady ( t * testing . T ) {
type args struct {
rs * appsv1 . ReplicaSet
}
tests := [ ] struct {
name string
args args
want bool
} {
{
name : "replicaSet is ready" ,
args : args {
rs : newReplicaSet ( "foo" , 1 , 1 , true ) ,
} ,
want : true ,
} ,
{
name : "replicaSet is not ready when generations are out of sync" ,
args : args {
rs : newReplicaSet ( "foo" , 1 , 1 , false ) ,
} ,
want : false ,
} ,
}
for _ , tt := range tests {
t . Run ( tt . name , func ( t * testing . T ) {
c := NewReadyChecker ( fake . NewSimpleClientset ( ) , nil )
if got := c . replicaSetReady ( tt . args . rs ) ; got != tt . want {
t . Errorf ( "replicaSetReady() = %v, want %v" , got , tt . want )
}
} )
}
}
func Test_ReadyChecker_replicationControllerReady ( t * testing . T ) {
type args struct {
rc * corev1 . ReplicationController
}
tests := [ ] struct {
name string
args args
want bool
} {
{
name : "replicationController is ready" ,
args : args {
rc : newReplicationController ( "foo" , true ) ,
} ,
want : true ,
} ,
{
name : "replicationController is not ready when generations are out of sync" ,
args : args {
rc : newReplicationController ( "foo" , false ) ,
} ,
want : false ,
} ,
}
for _ , tt := range tests {
t . Run ( tt . name , func ( t * testing . T ) {
c := NewReadyChecker ( fake . NewSimpleClientset ( ) , nil )
if got := c . replicationControllerReady ( tt . args . rc ) ; got != tt . want {
t . Errorf ( "replicationControllerReady() = %v, want %v" , got , tt . want )
}
} )
}
}
func Test_ReadyChecker_daemonSetReady ( t * testing . T ) {
func Test_ReadyChecker_daemonSetReady ( t * testing . T ) {
type args struct {
type args struct {
ds * appsv1 . DaemonSet
ds * appsv1 . DaemonSet
@ -88,31 +180,38 @@ func Test_ReadyChecker_daemonSetReady(t *testing.T) {
{
{
name : "daemonset is ready" ,
name : "daemonset is ready" ,
args : args {
args : args {
ds : newDaemonSet ( "foo" , 0 , 1 , 1 , 1 ),
ds : newDaemonSet ( "foo" , 0 , 1 , 1 , 1 , true ),
} ,
} ,
want : true ,
want : true ,
} ,
} ,
{
{
name : "daemonset is not ready" ,
name : "daemonset is not ready" ,
args : args {
args : args {
ds : newDaemonSet ( "foo" , 0 , 0 , 1 , 1 ),
ds : newDaemonSet ( "foo" , 0 , 0 , 1 , 1 , true ),
} ,
} ,
want : false ,
want : false ,
} ,
} ,
{
{
name : "daemonset pods have not been scheduled successfully" ,
name : "daemonset pods have not been scheduled successfully" ,
args : args {
args : args {
ds : newDaemonSet ( "foo" , 0 , 0 , 1 , 0 ),
ds : newDaemonSet ( "foo" , 0 , 0 , 1 , 0 , true ),
} ,
} ,
want : false ,
want : false ,
} ,
} ,
{
{
name : "daemonset is ready when maxUnavailable is set" ,
name : "daemonset is ready when maxUnavailable is set" ,
args : args {
args : args {
ds : newDaemonSet ( "foo" , 1 , 1 , 2 , 2 ),
ds : newDaemonSet ( "foo" , 1 , 1 , 2 , 2 , true ),
} ,
} ,
want : true ,
want : true ,
} ,
} ,
{
name : "daemonset is not ready when generations are out of sync" ,
args : args {
ds : newDaemonSet ( "foo" , 0 , 1 , 1 , 1 , false ) ,
} ,
want : false ,
} ,
}
}
for _ , tt := range tests {
for _ , tt := range tests {
t . Run ( tt . name , func ( t * testing . T ) {
t . Run ( tt . name , func ( t * testing . T ) {
@ -136,45 +235,52 @@ func Test_ReadyChecker_statefulSetReady(t *testing.T) {
{
{
name : "statefulset is ready" ,
name : "statefulset is ready" ,
args : args {
args : args {
sts : newStatefulSet ( "foo" , 1 , 0 , 1 , 1 ),
sts : newStatefulSet ( "foo" , 1 , 0 , 1 , 1 , true ),
} ,
} ,
want : true ,
want : true ,
} ,
} ,
{
{
name : "statefulset is not ready" ,
name : "statefulset is not ready" ,
args : args {
args : args {
sts : newStatefulSet ( "foo" , 1 , 0 , 0 , 1 ),
sts : newStatefulSet ( "foo" , 1 , 0 , 0 , 1 , true ),
} ,
} ,
want : false ,
want : false ,
} ,
} ,
{
{
name : "statefulset is ready when partition is specified" ,
name : "statefulset is ready when partition is specified" ,
args : args {
args : args {
sts : newStatefulSet ( "foo" , 2 , 1 , 2 , 1 ),
sts : newStatefulSet ( "foo" , 2 , 1 , 2 , 1 , true ),
} ,
} ,
want : true ,
want : true ,
} ,
} ,
{
{
name : "statefulset is not ready when partition is set" ,
name : "statefulset is not ready when partition is set" ,
args : args {
args : args {
sts : newStatefulSet ( "foo" , 2 , 1 , 1 , 0 ),
sts : newStatefulSet ( "foo" , 2 , 1 , 1 , 0 , true ),
} ,
} ,
want : false ,
want : false ,
} ,
} ,
{
{
name : "statefulset is ready when partition is set and no change in template" ,
name : "statefulset is ready when partition is set and no change in template" ,
args : args {
args : args {
sts : newStatefulSet ( "foo" , 2 , 1 , 2 , 2 ),
sts : newStatefulSet ( "foo" , 2 , 1 , 2 , 2 , true ),
} ,
} ,
want : true ,
want : true ,
} ,
} ,
{
{
name : "statefulset is ready when partition is greater than replicas" ,
name : "statefulset is ready when partition is greater than replicas" ,
args : args {
args : args {
sts : newStatefulSet ( "foo" , 1 , 2 , 1 , 1 ),
sts : newStatefulSet ( "foo" , 1 , 2 , 1 , 1 , true ),
} ,
} ,
want : true ,
want : true ,
} ,
} ,
{
name : "statefulset is not ready when generations are out of sync" ,
args : args {
sts : newStatefulSet ( "foo" , 1 , 0 , 1 , 1 , false ) ,
} ,
want : false ,
} ,
}
}
for _ , tt := range tests {
for _ , tt := range tests {
t . Run ( tt . name , func ( t * testing . T ) {
t . Run ( tt . name , func ( t * testing . T ) {
@ -202,7 +308,7 @@ func Test_ReadyChecker_podsReadyForObject(t *testing.T) {
name : "pods ready for a replicaset" ,
name : "pods ready for a replicaset" ,
args : args {
args : args {
namespace : defaultNamespace ,
namespace : defaultNamespace ,
obj : newReplicaSet ( "foo" , 1 , 1 ),
obj : newReplicaSet ( "foo" , 1 , 1 , true ),
} ,
} ,
existPods : [ ] corev1 . Pod {
existPods : [ ] corev1 . Pod {
* newPodWithCondition ( "foo" , corev1 . ConditionTrue ) ,
* newPodWithCondition ( "foo" , corev1 . ConditionTrue ) ,
@ -214,7 +320,7 @@ func Test_ReadyChecker_podsReadyForObject(t *testing.T) {
name : "pods not ready for a replicaset" ,
name : "pods not ready for a replicaset" ,
args : args {
args : args {
namespace : defaultNamespace ,
namespace : defaultNamespace ,
obj : newReplicaSet ( "foo" , 1 , 1 ),
obj : newReplicaSet ( "foo" , 1 , 1 , true ),
} ,
} ,
existPods : [ ] corev1 . Pod {
existPods : [ ] corev1 . Pod {
* newPodWithCondition ( "foo" , corev1 . ConditionFalse ) ,
* newPodWithCondition ( "foo" , corev1 . ConditionFalse ) ,
@ -338,11 +444,16 @@ func Test_ReadyChecker_volumeReady(t *testing.T) {
}
}
}
}
func newDaemonSet ( name string , maxUnavailable , numberReady , desiredNumberScheduled , updatedNumberScheduled int ) * appsv1 . DaemonSet {
func newDaemonSet ( name string , maxUnavailable , numberReady , desiredNumberScheduled , updatedNumberScheduled int , generationInSync bool ) * appsv1 . DaemonSet {
var generation , observedGeneration int64 = 1 , 1
if ! generationInSync {
generation = 2
}
return & appsv1 . DaemonSet {
return & appsv1 . DaemonSet {
ObjectMeta : metav1 . ObjectMeta {
ObjectMeta : metav1 . ObjectMeta {
Name : name ,
Name : name ,
Namespace : defaultNamespace ,
Namespace : defaultNamespace ,
Generation : generation ,
} ,
} ,
Spec : appsv1 . DaemonSetSpec {
Spec : appsv1 . DaemonSetSpec {
UpdateStrategy : appsv1 . DaemonSetUpdateStrategy {
UpdateStrategy : appsv1 . DaemonSetUpdateStrategy {
@ -370,15 +481,21 @@ func newDaemonSet(name string, maxUnavailable, numberReady, desiredNumberSchedul
DesiredNumberScheduled : int32 ( desiredNumberScheduled ) ,
DesiredNumberScheduled : int32 ( desiredNumberScheduled ) ,
NumberReady : int32 ( numberReady ) ,
NumberReady : int32 ( numberReady ) ,
UpdatedNumberScheduled : int32 ( updatedNumberScheduled ) ,
UpdatedNumberScheduled : int32 ( updatedNumberScheduled ) ,
ObservedGeneration : observedGeneration ,
} ,
} ,
}
}
}
}
func newStatefulSet ( name string , replicas , partition , readyReplicas , updatedReplicas int ) * appsv1 . StatefulSet {
func newStatefulSet ( name string , replicas , partition , readyReplicas , updatedReplicas int , generationInSync bool ) * appsv1 . StatefulSet {
var generation , observedGeneration int64 = 1 , 1
if ! generationInSync {
generation = 2
}
return & appsv1 . StatefulSet {
return & appsv1 . StatefulSet {
ObjectMeta : metav1 . ObjectMeta {
ObjectMeta : metav1 . ObjectMeta {
Name : name ,
Name : name ,
Namespace : defaultNamespace ,
Namespace : defaultNamespace ,
Generation : generation ,
} ,
} ,
Spec : appsv1 . StatefulSetSpec {
Spec : appsv1 . StatefulSetSpec {
UpdateStrategy : appsv1 . StatefulSetUpdateStrategy {
UpdateStrategy : appsv1 . StatefulSetUpdateStrategy {
@ -406,15 +523,21 @@ func newStatefulSet(name string, replicas, partition, readyReplicas, updatedRepl
Status : appsv1 . StatefulSetStatus {
Status : appsv1 . StatefulSetStatus {
UpdatedReplicas : int32 ( updatedReplicas ) ,
UpdatedReplicas : int32 ( updatedReplicas ) ,
ReadyReplicas : int32 ( readyReplicas ) ,
ReadyReplicas : int32 ( readyReplicas ) ,
ObservedGeneration : observedGeneration ,
} ,
} ,
}
}
}
}
func newDeployment ( name string , replicas , maxSurge , maxUnavailable int ) * appsv1 . Deployment {
func newDeployment ( name string , replicas , maxSurge , maxUnavailable int , generationInSync bool ) * appsv1 . Deployment {
var generation , observedGeneration int64 = 1 , 1
if ! generationInSync {
generation = 2
}
return & appsv1 . Deployment {
return & appsv1 . Deployment {
ObjectMeta : metav1 . ObjectMeta {
ObjectMeta : metav1 . ObjectMeta {
Name : name ,
Name : name ,
Namespace : defaultNamespace ,
Namespace : defaultNamespace ,
Generation : generation ,
} ,
} ,
Spec : appsv1 . DeploymentSpec {
Spec : appsv1 . DeploymentSpec {
Strategy : appsv1 . DeploymentStrategy {
Strategy : appsv1 . DeploymentStrategy {
@ -440,17 +563,37 @@ func newDeployment(name string, replicas, maxSurge, maxUnavailable int) *appsv1.
} ,
} ,
} ,
} ,
} ,
} ,
Status : appsv1 . DeploymentStatus {
ObservedGeneration : observedGeneration ,
} ,
}
}
func newReplicationController ( name string , generationInSync bool ) * corev1 . ReplicationController {
var generation , observedGeneration int64 = 1 , 1
if ! generationInSync {
generation = 2
}
return & corev1 . ReplicationController {
ObjectMeta : metav1 . ObjectMeta {
Name : name ,
Generation : generation ,
} ,
Status : corev1 . ReplicationControllerStatus {
ObservedGeneration : observedGeneration ,
} ,
}
}
}
}
func newReplicaSet ( name string , replicas int , readyReplicas int ) * appsv1 . ReplicaSet {
func newReplicaSet ( name string , replicas int , readyReplicas int , generationInSync bool ) * appsv1 . ReplicaSet {
d := newDeployment ( name , replicas , 0 , 0 )
d := newDeployment ( name , replicas , 0 , 0 , generationInSync )
return & appsv1 . ReplicaSet {
return & appsv1 . ReplicaSet {
ObjectMeta : metav1 . ObjectMeta {
ObjectMeta : metav1 . ObjectMeta {
Name : name ,
Name : name ,
Namespace : defaultNamespace ,
Namespace : defaultNamespace ,
Labels : d . Spec . Selector . MatchLabels ,
Labels : d . Spec . Selector . MatchLabels ,
OwnerReferences : [ ] metav1 . OwnerReference { * metav1 . NewControllerRef ( d , d . GroupVersionKind ( ) ) } ,
OwnerReferences : [ ] metav1 . OwnerReference { * metav1 . NewControllerRef ( d , d . GroupVersionKind ( ) ) } ,
Generation : d . Generation ,
} ,
} ,
Spec : appsv1 . ReplicaSetSpec {
Spec : appsv1 . ReplicaSetSpec {
Selector : d . Spec . Selector ,
Selector : d . Spec . Selector ,
@ -459,6 +602,7 @@ func newReplicaSet(name string, replicas int, readyReplicas int) *appsv1.Replica
} ,
} ,
Status : appsv1 . ReplicaSetStatus {
Status : appsv1 . ReplicaSetStatus {
ReadyReplicas : int32 ( readyReplicas ) ,
ReadyReplicas : int32 ( readyReplicas ) ,
ObservedGeneration : d . Status . ObservedGeneration ,
} ,
} ,
}
}
}
}