Search in sources :

Example 1 with StrimziPodSetBuilder

use of io.strimzi.api.kafka.model.StrimziPodSetBuilder in project strimzi by strimzi.

the class StrimziPodSetController method maybeUpdateStatus.

/**
 * Updates the status of the StrimziPodSet. The status will be updated only when it changed since last time.
 *
 * @param reconciliation    Reconciliation in which this is executed
 * @param podSet            Original pod set with the current status
 * @param desiredStatus     The desired status which should be set if it differs
 */
private void maybeUpdateStatus(Reconciliation reconciliation, StrimziPodSet podSet, StrimziPodSetStatus desiredStatus) {
    if (!new StatusDiff(podSet.getStatus(), desiredStatus).isEmpty()) {
        try {
            LOGGER.debugCr(reconciliation, "Updating status of StrimziPodSet {} in namespace {}", reconciliation.name(), reconciliation.namespace());
            StrimziPodSet updatedPodSet = new StrimziPodSetBuilder(strimziPodSetLister.namespace(reconciliation.namespace()).get(reconciliation.name())).withStatus(desiredStatus).build();
            strimziPodSetOperator.client().inNamespace(reconciliation.namespace()).patchStatus(updatedPodSet);
        } catch (KubernetesClientException e) {
            if (e.getCode() == 409) {
                LOGGER.debugCr(reconciliation, "StrimziPodSet {} in namespace {} changed while trying to update status", reconciliation.name(), reconciliation.namespace(), e);
            } else {
                LOGGER.errorCr(reconciliation, "Failed to update status of StrimziPodSet {} in namespace {}", reconciliation.name(), reconciliation.namespace(), e);
            }
        }
    }
}
Also used : StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) StatusDiff(io.strimzi.operator.cluster.model.StatusDiff) StrimziPodSetBuilder(io.strimzi.api.kafka.model.StrimziPodSetBuilder) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 2 with StrimziPodSetBuilder

use of io.strimzi.api.kafka.model.StrimziPodSetBuilder in project strimzi-kafka-operator by strimzi.

the class AbstractModel method createPodSet.

/**
 * Creates the StrimziPodSet with the Pods which currently correspond to the existing StatefulSet pods.
 *
 * @param replicas          Defines how many pods should be generated and stored in this StrimziPodSet
 * @param setAnnotations    Map with annotations which should be set on the StrimziPodSet
 * @param podAnnotations    Map with annotation which should be set on the Pods
 * @param volumes           Function which returns a list of volumes which should be used by the Pod and its containers
 * @param affinity          Affinity rules for the pods
 * @param initContainers    List of init containers which should be used in the pods
 * @param containers        List of containers which should be used in the pods
 * @param imagePullSecrets  List of image pull secrets with container registry credentials
 * @param isOpenShift       Flag to specify whether we are on OpenShift or not
 *
 * @return                  Generated StrimziPodSet with all pods
 */
protected StrimziPodSet createPodSet(int replicas, Map<String, String> setAnnotations, Map<String, String> podAnnotations, Function<String, List<Volume>> volumes, Affinity affinity, List<Container> initContainers, List<Container> containers, List<LocalObjectReference> imagePullSecrets, boolean isOpenShift) {
    List<Map<String, Object>> pods = new ArrayList<>(replicas);
    for (int i = 0; i < replicas; i++) {
        String podName = getPodName(i);
        Pod pod = createStatefulPod(name, podName, podAnnotations, volumes.apply(podName), affinity, initContainers, containers, imagePullSecrets, isOpenShift);
        pods.add(PodSetUtils.podToMap(pod));
    }
    return new StrimziPodSetBuilder().withNewMetadata().withName(name).withLabels(getLabelsWithStrimziName(name, templatePodSetLabels).toMap()).withNamespace(namespace).withAnnotations(Util.mergeLabelsOrAnnotations(setAnnotations, templatePodSetAnnotations)).withOwnerReferences(createOwnerReference()).endMetadata().withNewSpec().withSelector(new LabelSelectorBuilder().withMatchLabels(getSelectorLabels().toMap()).build()).addAllToPods(pods).endSpec().build();
}
Also used : LabelSelectorBuilder(io.fabric8.kubernetes.api.model.LabelSelectorBuilder) Pod(io.fabric8.kubernetes.api.model.Pod) ArrayList(java.util.ArrayList) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) StrimziPodSetBuilder(io.strimzi.api.kafka.model.StrimziPodSetBuilder) Map(java.util.Map) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashMap(java.util.HashMap) Collections.emptyMap(java.util.Collections.emptyMap) TopologySpreadConstraint(io.fabric8.kubernetes.api.model.TopologySpreadConstraint)

Example 3 with StrimziPodSetBuilder

use of io.strimzi.api.kafka.model.StrimziPodSetBuilder in project strimzi-kafka-operator by strimzi.

the class StrimziPodSetController method maybeUpdateStatus.

/**
 * Updates the status of the StrimziPodSet. The status will be updated only when it changed since last time.
 *
 * @param reconciliation    Reconciliation in which this is executed
 * @param podSet            Original pod set with the current status
 * @param desiredStatus     The desired status which should be set if it differs
 */
private void maybeUpdateStatus(Reconciliation reconciliation, StrimziPodSet podSet, StrimziPodSetStatus desiredStatus) {
    if (!new StatusDiff(podSet.getStatus(), desiredStatus).isEmpty()) {
        try {
            LOGGER.debugCr(reconciliation, "Updating status of StrimziPodSet {} in namespace {}", reconciliation.name(), reconciliation.namespace());
            StrimziPodSet updatedPodSet = new StrimziPodSetBuilder(strimziPodSetLister.namespace(reconciliation.namespace()).get(reconciliation.name())).withStatus(desiredStatus).build();
            strimziPodSetOperator.client().inNamespace(reconciliation.namespace()).patchStatus(updatedPodSet);
        } catch (KubernetesClientException e) {
            if (e.getCode() == 409) {
                LOGGER.debugCr(reconciliation, "StrimziPodSet {} in namespace {} changed while trying to update status", reconciliation.name(), reconciliation.namespace(), e);
            } else {
                LOGGER.errorCr(reconciliation, "Failed to update status of StrimziPodSet {} in namespace {}", reconciliation.name(), reconciliation.namespace(), e);
            }
        }
    }
}
Also used : StrimziPodSet(io.strimzi.api.kafka.model.StrimziPodSet) StatusDiff(io.strimzi.operator.cluster.model.StatusDiff) StrimziPodSetBuilder(io.strimzi.api.kafka.model.StrimziPodSetBuilder) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 4 with StrimziPodSetBuilder

use of io.strimzi.api.kafka.model.StrimziPodSetBuilder in project strimzi by strimzi.

the class AbstractModel method createPodSet.

/**
 * Creates the StrimziPodSet with the Pods which currently correspond to the existing StatefulSet pods.
 *
 * @param replicas          Defines how many pods should be generated and stored in this StrimziPodSet
 * @param setAnnotations    Map with annotations which should be set on the StrimziPodSet
 * @param podAnnotations    Map with annotation which should be set on the Pods
 * @param volumes           Function which returns a list of volumes which should be used by the Pod and its containers
 * @param affinity          Affinity rules for the pods
 * @param initContainers    List of init containers which should be used in the pods
 * @param containers        List of containers which should be used in the pods
 * @param imagePullSecrets  List of image pull secrets with container registry credentials
 * @param isOpenShift       Flag to specify whether we are on OpenShift or not
 *
 * @return                  Generated StrimziPodSet with all pods
 */
protected StrimziPodSet createPodSet(int replicas, Map<String, String> setAnnotations, Map<String, String> podAnnotations, Function<String, List<Volume>> volumes, Affinity affinity, List<Container> initContainers, List<Container> containers, List<LocalObjectReference> imagePullSecrets, boolean isOpenShift) {
    List<Map<String, Object>> pods = new ArrayList<>(replicas);
    for (int i = 0; i < replicas; i++) {
        String podName = getPodName(i);
        Pod pod = createStatefulPod(name, podName, podAnnotations, volumes.apply(podName), affinity, initContainers, containers, imagePullSecrets, isOpenShift);
        pods.add(PodSetUtils.podToMap(pod));
    }
    return new StrimziPodSetBuilder().withNewMetadata().withName(name).withLabels(getLabelsWithStrimziName(name, templatePodSetLabels).toMap()).withNamespace(namespace).withAnnotations(Util.mergeLabelsOrAnnotations(setAnnotations, templatePodSetAnnotations)).withOwnerReferences(createOwnerReference()).endMetadata().withNewSpec().withSelector(new LabelSelectorBuilder().withMatchLabels(getSelectorLabels().toMap()).build()).addAllToPods(pods).endSpec().build();
}
Also used : LabelSelectorBuilder(io.fabric8.kubernetes.api.model.LabelSelectorBuilder) Pod(io.fabric8.kubernetes.api.model.Pod) ArrayList(java.util.ArrayList) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) StrimziPodSetBuilder(io.strimzi.api.kafka.model.StrimziPodSetBuilder) Map(java.util.Map) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) HashMap(java.util.HashMap) Collections.emptyMap(java.util.Collections.emptyMap) TopologySpreadConstraint(io.fabric8.kubernetes.api.model.TopologySpreadConstraint)

Aggregations

StrimziPodSetBuilder (io.strimzi.api.kafka.model.StrimziPodSetBuilder)4 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)2 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)2 LabelSelectorBuilder (io.fabric8.kubernetes.api.model.LabelSelectorBuilder)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 TopologySpreadConstraint (io.fabric8.kubernetes.api.model.TopologySpreadConstraint)2 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)2 StrimziPodSet (io.strimzi.api.kafka.model.StrimziPodSet)2 StatusDiff (io.strimzi.operator.cluster.model.StatusDiff)2 ArrayList (java.util.ArrayList)2 Collections.emptyMap (java.util.Collections.emptyMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2