All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.javaoperatorsdk.operator.sample.WebPageManagedDependentsReconciler Maven / Gradle / Ivy

There is a newer version: 4.9.5
Show newest version
package io.javaoperatorsdk.operator.sample;

import io.fabric8.kubernetes.api.model.ConfigMap;
import io.javaoperatorsdk.operator.api.reconciler.*;
import io.javaoperatorsdk.operator.api.reconciler.dependent.Dependent;
import io.javaoperatorsdk.operator.sample.customresource.WebPage;
import io.javaoperatorsdk.operator.sample.dependentresource.*;

import static io.javaoperatorsdk.operator.sample.Utils.createStatus;
import static io.javaoperatorsdk.operator.sample.Utils.handleError;
import static io.javaoperatorsdk.operator.sample.Utils.simulateErrorIfRequested;

/**
 * Shows how to implement a reconciler with managed dependent resources.
 */
@ControllerConfiguration(
    dependents = {
        @Dependent(type = ConfigMapDependentResource.class),
        @Dependent(type = DeploymentDependentResource.class),
        @Dependent(type = ServiceDependentResource.class),
        @Dependent(type = IngressDependentResource.class,
            reconcilePrecondition = ExposedIngressCondition.class)
    })
public class WebPageManagedDependentsReconciler
    implements Reconciler, ErrorStatusHandler, Cleaner {

  public static final String SELECTOR = "managed";

  @Override
  public ErrorStatusUpdateControl updateErrorStatus(WebPage resource,
      Context context, Exception e) {
    return handleError(resource, e);
  }

  @Override
  public UpdateControl reconcile(WebPage webPage, Context context)
      throws Exception {
    simulateErrorIfRequested(webPage);

    final var name = context.getSecondaryResource(ConfigMap.class).orElseThrow()
        .getMetadata().getName();
    webPage.setStatus(createStatus(name));
    return UpdateControl.patchStatus(webPage);
  }

  @Override
  public DeleteControl cleanup(WebPage resource, Context context) {
    return DeleteControl.defaultDelete();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy