Search in sources :

Example 1 with UpdateControl

use of io.javaoperatorsdk.operator.api.reconciler.UpdateControl in project java-operator-sdk by java-operator-sdk.

the class DeploymentReconciler method reconcile.

@Override
public UpdateControl<Deployment> reconcile(Deployment resource, Context context) {
    log.info("Reconcile deployment: {}", resource);
    numberOfExecutions.incrementAndGet();
    if (resource.getStatus() == null) {
        resource.setStatus(new DeploymentStatus());
    }
    if (resource.getStatus().getConditions() == null) {
        resource.getStatus().setConditions(new ArrayList<>());
    }
    var conditions = resource.getStatus().getConditions();
    var condition = conditions.stream().filter(c -> c.getMessage().equals(STATUS_MESSAGE)).findFirst();
    if (condition.isEmpty()) {
        conditions.add(new DeploymentCondition(null, null, STATUS_MESSAGE, null, "unknown", "DeploymentReconciler"));
        return UpdateControl.updateStatus(resource);
    } else {
        return UpdateControl.noUpdate();
    }
}
Also used : Context(io.javaoperatorsdk.operator.api.reconciler.Context) ControllerConfiguration(io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration) TestExecutionInfoProvider(io.javaoperatorsdk.operator.support.TestExecutionInfoProvider) Reconciler(io.javaoperatorsdk.operator.api.reconciler.Reconciler) Logger(org.slf4j.Logger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LoggerFactory(org.slf4j.LoggerFactory) UpdateControl(io.javaoperatorsdk.operator.api.reconciler.UpdateControl) DeploymentStatus(io.fabric8.kubernetes.api.model.apps.DeploymentStatus) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ArrayList(java.util.ArrayList) DeploymentCondition(io.fabric8.kubernetes.api.model.apps.DeploymentCondition) DeploymentStatus(io.fabric8.kubernetes.api.model.apps.DeploymentStatus) DeploymentCondition(io.fabric8.kubernetes.api.model.apps.DeploymentCondition)

Aggregations

Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)1 DeploymentCondition (io.fabric8.kubernetes.api.model.apps.DeploymentCondition)1 DeploymentStatus (io.fabric8.kubernetes.api.model.apps.DeploymentStatus)1 Context (io.javaoperatorsdk.operator.api.reconciler.Context)1 ControllerConfiguration (io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration)1 Reconciler (io.javaoperatorsdk.operator.api.reconciler.Reconciler)1 UpdateControl (io.javaoperatorsdk.operator.api.reconciler.UpdateControl)1 TestExecutionInfoProvider (io.javaoperatorsdk.operator.support.TestExecutionInfoProvider)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1