@Override int getDesiredReplicas(StatefulSet item) { return item.getSpec().getReplicas(); }
@Override protected int getReplicas(StatefulSet obj) { return obj.getSpec().getReplicas(); }
public static boolean isStatefulSetReady(StatefulSet ss) { Utils.checkNotNull(ss, "StatefulSet can't be null."); StatefulSetSpec spec = ss.getSpec(); StatefulSetStatus status =ss.getStatus(); if (status == null || status.getReplicas() == null) { return false; } //Can be true in testing, so handle it to make test writing easier. if (spec == null || spec.getReplicas() == null) { return false; } return spec.getReplicas().intValue() == status.getReplicas(); }
@Override protected Integer currentScale(String namespace, String name) { StatefulSet statefulSet = get(namespace, name); if (statefulSet != null) { return statefulSet.getSpec().getReplicas(); } else { return null; } }
/** * Returns a future that completes when all the pods [0..replicas-1] in the given statefulSet are ready. */ protected Future<?> podReadiness(String namespace, StatefulSet desired, long pollInterval, long operationTimeoutMs) { final int replicas = desired.getSpec().getReplicas(); List<Future> waitPodResult = new ArrayList<>(replicas); for (int i = 0; i < replicas; i++) { String podName = getPodName(desired, i); waitPodResult.add(podOperations.readiness(namespace, podName, pollInterval, operationTimeoutMs)); } return CompositeFuture.join(waitPodResult); }
private int findReplicas(List<HasMetadata> items) { for (HasMetadata item : items) { if (item instanceof StatefulSet) { return ((StatefulSet)item).getSpec().getReplicas(); } else if (item instanceof Deployment) { return ((Deployment)item).getSpec().getReplicas(); } } return 0; }
/** * Asynchronously perform a rolling update of all the pods in the StatefulSet identified by the given * {@code namespace} and {@code name}, returning a Future that will complete when the rolling update * is complete. Starting with pod 0, each pod will be deleted and re-created automatically by the ReplicaSet, * once the pod has been recreated then given {@code isReady} function will be polled until it returns true, * before the process proceeds with the pod with the next higher number. */ public Future<Void> maybeRollingUpdate(StatefulSet ss, Predicate<Pod> podRestart) { String namespace = ss.getMetadata().getNamespace(); String name = ss.getMetadata().getName(); final int replicas = ss.getSpec().getReplicas(); log.debug("Considering rolling update of {}/{}", namespace, name); Future<Void> f = Future.succeededFuture(); for (int i = 0; i < replicas; i++) { String podName = name + "-" + i; f = f.compose(ignored -> maybeRestartPod(ss, podName, podRestart)); } return f; }
@Override public RouterCluster getRouterCluster() throws IOException { StatefulSet s = client.apps().statefulSets().withName("qdrouterd-" + infraUuid).get(); StandardInfraConfig infraConfig = null; if (s.getMetadata().getAnnotations() != null && s.getMetadata().getAnnotations().get(AnnotationKeys.APPLIED_INFRA_CONFIG) != null) { infraConfig = mapper.readValue(s.getMetadata().getAnnotations().get(AnnotationKeys.APPLIED_INFRA_CONFIG), StandardInfraConfig.class); } return new RouterCluster(s.getMetadata().getName(), s.getSpec().getReplicas(), infraConfig); }
/** * Overridden to not cascade to dependent resources (e.g. pods). * * {@inheritDoc} */ @Override protected Future<ReconcileResult<StatefulSet>> internalPatch(String namespace, String name, StatefulSet current, StatefulSet desired) { if (shouldIncrementGeneration(current, desired)) { incrementGeneration(current, desired); } else { setGeneration(desired, getSsGeneration(current)); } // Don't scale via patch desired.getSpec().setReplicas(current.getSpec().getReplicas()); if (log.isTraceEnabled()) { log.trace("Patching {} {}/{} to match desired state {}", resourceKind, namespace, name, desired); } else { log.debug("Patching {} {}/{}", resourceKind, namespace, name); } return super.internalPatch(namespace, name, current, desired, false); }
String namespace = ss.getMetadata().getNamespace(); String name = ss.getMetadata().getName(); final int replicas = ss.getSpec().getReplicas(); log.debug("Considering rolling update of {}/{}", namespace, name); Future<Void> f = Future.succeededFuture();
/** * Scale up is divided by scaling up Zookeeper cluster in steps. * Scaling up from N to M (N > 0 and M>N) replicas is done in M-N steps. * Each step performs scale up by one replica and full tolling update of Zookeeper cluster. * This approach ensures a valid configuration of each Zk pod. * Together with modified `maybeRollingUpdate` the quorum is not lost after the scale up operation is performed. * There is one special case of scaling from standalone (single one) Zookeeper pod. * In this case quorum cannot be preserved. */ Future<ReconciliationState> zkScaleUpStep() { Future<StatefulSet> futss = zkSetOperations.getAsync(namespace, ZookeeperCluster.zookeeperClusterName(name)); return withVoid(futss.map(ss -> ss == null ? 0 : ss.getSpec().getReplicas()) .compose(currentReplicas -> { if (currentReplicas > 0 && zkCluster.getReplicas() > currentReplicas) { zkCluster.setReplicas(currentReplicas + 1); } Future<Integer> result = Future.succeededFuture(zkCluster.getReplicas() + 1); return result; })); }
public Future<Void> maybeDeletePodAndPvc(StatefulSet ss) { String namespace = ss.getMetadata().getNamespace(); String name = ss.getMetadata().getName(); final int replicas = ss.getSpec().getReplicas(); log.debug("Considering manual deletion and restart of pods for {}/{}", namespace, name); Future<Void> f = Future.succeededFuture();