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);
}
}
}
}
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();
}
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);
}
}
}
}
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();
}
Aggregations