Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions util/src/main/java/io/kubernetes/client/util/Readiness.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ public static boolean isReplicaSetReady(V1ReplicaSet replicaSet) {
Integer readyReplicas = status.getReadyReplicas();

if (replicas == null) {
replicas = 1;
return false;
}
if (readyReplicas == null) {
readyReplicas = 0;
return false;
}

return replicas.equals(readyReplicas);
Expand Down Expand Up @@ -380,10 +380,10 @@ public static boolean isReplicationControllerReady(V1ReplicationController repli
Integer readyReplicas = status.getReadyReplicas();

if (replicas == null) {
replicas = 1;
return false;
}
if (readyReplicas == null) {
readyReplicas = 0;
return false;
}

return replicas.equals(readyReplicas);
Expand Down
50 changes: 49 additions & 1 deletion util/src/test/java/io/kubernetes/client/util/ReadinessTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,30 @@ void isReplicaSetReady_notAllReplicasReady_returnsFalse() {
assertThat(Readiness.isReplicaSetReady(replicaSet)).isFalse();
}

@Test
void isReplicaSetReady_nullSpecReplicas_returnsFalse() {
// Regression test: a null spec.replicas must not be silently treated as "1".
V1ReplicaSet replicaSet = new V1ReplicaSet()
.metadata(new V1ObjectMeta().name("test"))
.spec(new V1ReplicaSetSpec())
.status(new V1ReplicaSetStatus().readyReplicas(1));
assertThat(Readiness.isReplicaSetReady(replicaSet)).isFalse();
}

@Test
void isReplicaSetReady_nullReadyReplicas_returnsFalse() {
// Regression test: a null status.readyReplicas must not be silently treated as "0".
// Uses spec.replicas(0) specifically: under the old buggy code, a null readyReplicas
// defaulted to 0, so 0.equals(0) would wrongly report "ready" here. A non-zero
// replicas value wouldn't actually catch that bug, since it wouldn't match the
// default of 0 either way.
V1ReplicaSet replicaSet = new V1ReplicaSet()
.metadata(new V1ObjectMeta().name("test"))
.spec(new V1ReplicaSetSpec().replicas(0))
.status(new V1ReplicaSetStatus());
assertThat(Readiness.isReplicaSetReady(replicaSet)).isFalse();
}

// ========== DaemonSet Tests ==========

@Test
Expand Down Expand Up @@ -337,6 +361,30 @@ void isReplicationControllerReady_allReplicasReady_returnsTrue() {
assertThat(Readiness.isReplicationControllerReady(rc)).isTrue();
}

@Test
void isReplicationControllerReady_nullSpecReplicas_returnsFalse() {
// Regression test: a null spec.replicas must not be silently treated as "1".
V1ReplicationController rc = new V1ReplicationController()
.metadata(new V1ObjectMeta().name("test"))
.spec(new io.kubernetes.client.openapi.models.V1ReplicationControllerSpec())
.status(new V1ReplicationControllerStatus().readyReplicas(1));
assertThat(Readiness.isReplicationControllerReady(rc)).isFalse();
}

@Test
void isReplicationControllerReady_nullReadyReplicas_returnsFalse() {
// Regression test: a null status.readyReplicas must not be silently treated as "0".
// Uses spec.replicas(0) specifically: under the old buggy code, a null readyReplicas
// defaulted to 0, so 0.equals(0) would wrongly report "ready" here. A non-zero
// replicas value wouldn't actually catch that bug, since it wouldn't match the
// default of 0 either way.
V1ReplicationController rc = new V1ReplicationController()
.metadata(new V1ObjectMeta().name("test"))
.spec(new io.kubernetes.client.openapi.models.V1ReplicationControllerSpec().replicas(0))
.status(new V1ReplicationControllerStatus());
assertThat(Readiness.isReplicationControllerReady(rc)).isFalse();
}

// ========== PersistentVolumeClaim Tests ==========

@Test
Expand Down Expand Up @@ -447,4 +495,4 @@ void isReady_delegatesToCorrectMethod_forJob() {
.status("True"))));
assertThat(Readiness.isReady(job)).isTrue();
}
}
}