use of io.javaoperatorsdk.operator.api.reconciler.Context in project java-operator-sdk by java-operator-sdk.
the class ReconciliationDispatcherTest method propagatesRetryInfoToContextIfFinalizerSet.
@Test
void propagatesRetryInfoToContextIfFinalizerSet() {
testCustomResource.addFinalizer(DEFAULT_FINALIZER);
reconciliationDispatcher.handleExecution(new ExecutionScope(testCustomResource, new RetryInfo() {
@Override
public int getAttemptCount() {
return 2;
}
@Override
public boolean isLastAttempt() {
return true;
}
}));
ArgumentCaptor<Context> contextArgumentCaptor = ArgumentCaptor.forClass(Context.class);
verify(reconciler, times(1)).reconcile(any(), contextArgumentCaptor.capture());
Context context = contextArgumentCaptor.getValue();
final var retryInfo = context.getRetryInfo().get();
assertThat(retryInfo.getAttemptCount()).isEqualTo(2);
assertThat(retryInfo.isLastAttempt()).isEqualTo(true);
}
use of io.javaoperatorsdk.operator.api.reconciler.Context in project java-operator-sdk by java-operator-sdk.
the class ReconciliationDispatcher method handleDispatch.
private PostExecutionControl<R> handleDispatch(ExecutionScope<R> executionScope) {
R resource = executionScope.getResource();
log.debug("Handling dispatch for resource {}", getName(resource));
final var markedForDeletion = resource.isMarkedForDeletion();
if (markedForDeletion && shouldNotDispatchToDelete(resource)) {
log.debug("Skipping delete of resource {} because finalizer(s) {} don't allow processing yet", getName(resource), resource.getMetadata().getFinalizers());
return PostExecutionControl.defaultDispatch();
}
Context context = new DefaultContext<>(executionScope.getRetryInfo(), controller, resource);
if (markedForDeletion) {
return handleCleanup(resource, context);
} else {
return handleReconcile(executionScope, resource, context);
}
}
use of io.javaoperatorsdk.operator.api.reconciler.Context in project flink-kubernetes-operator by apache.
the class JobReconcilerTest method triggerSavepoint.
@Test
public void triggerSavepoint() throws Exception {
Context context = TestUtils.createContextWithReadyJobManagerDeployment();
TestingFlinkService flinkService = new TestingFlinkService();
JobReconciler reconciler = new JobReconciler(null, flinkService, operatorConfiguration);
FlinkDeployment deployment = TestUtils.buildApplicationCluster();
Configuration config = FlinkUtils.getEffectiveConfig(deployment, new Configuration());
reconciler.reconcile("test", deployment, context, config);
List<Tuple2<String, JobStatusMessage>> runningJobs = flinkService.listJobs();
verifyAndSetRunningJobsToStatus(deployment, runningJobs);
assertNull(deployment.getStatus().getJobStatus().getSavepointInfo().getTriggerId());
// trigger savepoint
FlinkDeployment spDeployment = ReconciliationUtils.clone(deployment);
long oldValue = spDeployment.getSpec().getJob().getSavepointTriggerNonce();
spDeployment.getSpec().getJob().setSavepointTriggerNonce(oldValue + 1);
reconciler.reconcile("test", spDeployment, context, config);
assertEquals("trigger_0", spDeployment.getStatus().getJobStatus().getSavepointInfo().getTriggerId());
}
use of io.javaoperatorsdk.operator.api.reconciler.Context in project flink-kubernetes-operator by apache.
the class TestUtils method createContextWithReadyJobManagerDeployment.
public static Context createContextWithReadyJobManagerDeployment() {
return new Context() {
@Override
public Optional<RetryInfo> getRetryInfo() {
return Optional.empty();
}
@Override
public <T> Optional<T> getSecondaryResource(Class<T> expectedType, String eventSourceName) {
DeploymentStatus status = new DeploymentStatus();
status.setAvailableReplicas(1);
status.setReplicas(1);
DeploymentSpec spec = new DeploymentSpec();
spec.setReplicas(1);
Deployment deployment = new Deployment();
deployment.setSpec(spec);
deployment.setStatus(status);
return Optional.of((T) deployment);
}
};
}
use of io.javaoperatorsdk.operator.api.reconciler.Context 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();
}
}
Aggregations