ZookeeperSetOperator extends StatefulSetOperator { public static boolean needsRollingUpdate(StatefulSetDiff diff) { if (diff.changesLabels()) { log.debug("Changed labels => needs rolling update"); return true; } if (diff.changesSpecTemplate()) { log.debug("Changed template spec => needs rolling update"); return true; } if (diff.changesVolumeClaimTemplates()) { log.debug("Changed volume claim template => needs rolling update"); return true; } if (diff.changesVolumeSize()) { log.debug("Changed size of the volume claim template => no need for rolling update"); return false; } return false; } ZookeeperSetOperator(Vertx vertx, KubernetesClient client, ZookeeperLeaderFinder leaderFinder, long operationTimeoutMs); static boolean needsRollingUpdate(StatefulSetDiff diff); @Override Future<Void> maybeRollingUpdate(StatefulSet sts, Function<Pod, List<String>> podRestart, Secret clusterCaSecret, Secret coKeySecret);  }
@Test public void testNotNeedsRollingUpdateIdentical() { assertThat(ZookeeperSetOperator.needsRollingUpdate(diff()), is(false)); }
@Test public void testNotNeedsRollingUpdateReplicas() { a.getSpec().setReplicas(b.getSpec().getReplicas() + 1); assertThat(ZookeeperSetOperator.needsRollingUpdate(diff()), is(false)); }
@Test public void testNeedsRollingUpdateLabels() { Map<String, String> labels = new HashMap<>(b.getMetadata().getLabels()); labels.put("foo", "bar"); a.getMetadata().setLabels(labels); assertThat(ZookeeperSetOperator.needsRollingUpdate(diff()), is(true)); }
@Test public void testNeedsRollingUpdateImage() { a.getSpec().getTemplate().getSpec().getContainers().get(0).setImage( a.getSpec().getTemplate().getSpec().getContainers().get(0).getImage() + "-foo"); assertThat(ZookeeperSetOperator.needsRollingUpdate(diff()), is(true)); }
@Test public void testNeedsRollingUpdateReadinessDelay() { a.getSpec().getTemplate().getSpec().getContainers().get(0).getReadinessProbe().setInitialDelaySeconds( a.getSpec().getTemplate().getSpec().getContainers().get(0).getReadinessProbe().getInitialDelaySeconds() + 1); assertThat(ZookeeperSetOperator.needsRollingUpdate(diff()), is(true)); }
@Test public void testNeedsRollingUpdateReadinessTimeout() { a.getSpec().getTemplate().getSpec().getContainers().get(0).getReadinessProbe().setTimeoutSeconds( a.getSpec().getTemplate().getSpec().getContainers().get(0).getReadinessProbe().getTimeoutSeconds() + 1); assertThat(ZookeeperSetOperator.needsRollingUpdate(diff()), is(true)); }
@Test public void testNeedsRollingUpdateEnvZkMetricsEnabled() { String envVar = ENV_VAR_ZOOKEEPER_METRICS_ENABLED; a.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv().add(new EnvVar(envVar, containerEnvVars(a.getSpec().getTemplate().getSpec().getContainers().get(0)).get(envVar) + "-foo", null)); assertThat(ZookeeperSetOperator.needsRollingUpdate(diff()), is(true)); }
@Test public void testNeedsRollingUpdateEnvSomeOtherThing() { String envVar = "SOME_RANDOM_ENV"; a.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv().add(new EnvVar(envVar, "foo", null)); assertThat(ZookeeperSetOperator.needsRollingUpdate(diff()), is(true)); }