use of io.fabric8.kubernetes.api.model.events.v1beta1.EventBuilder in project entando-k8s-controller-coordinator by entando-k8s.
the class RestartingWatcher method onClose.
@Override
default void onClose(WatcherException cause) {
final StringWriter stringWriter = new StringWriter();
cause.printStackTrace(new PrintWriter(stringWriter));
String message = stringWriter.toString();
if (message.contains("too old")) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, () -> "EntandoResourceObserver closed due to out of date resourceVersion. Reconnecting ... ");
getRestartingAction().run();
} else {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, cause, () -> "EntandoResourceObserver closed. Can't reconnect. The container should restart now.");
Event event = new EventBuilder().withNewMetadata().withName(EntandoOperatorSpiConfig.getControllerPodName() + "-restart-" + NameUtils.randomNumeric(4)).addToLabels("entando-operator-restarted", "true").endMetadata().withCount(1).withFirstTimestamp(FormatUtils.format(LocalDateTime.now())).withLastTimestamp(FormatUtils.format(LocalDateTime.now())).withMessage(message).build();
issueOperatorDeathEvent(event);
Liveness.dead();
}
}
use of io.fabric8.kubernetes.api.model.events.v1beta1.EventBuilder in project entando-k8s-controller-coordinator by entando-k8s.
the class DefaultSimpleKubernetesClient method performStatusUpdate.
private SerializedEntandoResource performStatusUpdate(SerializedEntandoResource customResource, Consumer<SerializedEntandoResource> consumer, UnaryOperator<EventBuilder> eventPopulator) {
final EventBuilder doneableEvent = new EventBuilder().withNewMetadata().withNamespace(customResource.getMetadata().getNamespace()).withName(customResource.getMetadata().getName() + "-" + NameUtils.randomNumeric(8)).withOwnerReferences(ResourceUtils.buildOwnerReference(customResource)).withLabels(ResourceUtils.labelsFromResource(customResource)).endMetadata().withCount(1).withFirstTimestamp(dateTimeFormatter.get().format(LocalDateTime.now())).withLastTimestamp(dateTimeFormatter.get().format(LocalDateTime.now())).withNewSource(NameUtils.controllerNameOf(customResource), null).withNewInvolvedObject().withKind(customResource.getKind()).withNamespace(customResource.getMetadata().getNamespace()).withName(customResource.getMetadata().getName()).withUid(customResource.getMetadata().getUid()).withResourceVersion(customResource.getMetadata().getResourceVersion()).withApiVersion(customResource.getApiVersion()).withFieldPath("status").endInvolvedObject();
client.v1().events().inNamespace(customResource.getMetadata().getNamespace()).create(eventPopulator.apply(doneableEvent).build());
return ioSafe(() -> {
SerializedEntandoResource ser = customResource;
CustomResourceDefinitionContext definition = Optional.ofNullable(ser.getDefinition()).orElse(resolveDefinitionContext(ser));
ser.setDefinition(definition);
RawCustomResourceOperationsImpl resource = client.customResource(definition).inNamespace(customResource.getMetadata().getNamespace()).withName(customResource.getMetadata().getName());
final ObjectMapper objectMapper = new ObjectMapper();
ser = objectMapper.readValue(objectMapper.writeValueAsString(resource.get()), SerializedEntandoResource.class);
ser.setDefinition(definition);
consumer.accept(ser);
final Map<String, Object> map = resource.updateStatus(objectMapper.writeValueAsString(ser));
return objectMapper.readValue(objectMapper.writeValueAsString(map), SerializedEntandoResource.class);
});
}
use of io.fabric8.kubernetes.api.model.events.v1beta1.EventBuilder in project kubernetes-client by fabric8io.
the class EventTest method testInvolvedObjectFieldQuery.
@Test
void testInvolvedObjectFieldQuery() {
// Given
server.expect().get().withPath("/api/v1/namespaces/ns1/events?fieldSelector=" + Utils.toUrlEncoded("involvedObject.name=foo," + "involvedObject.namespace=ns1," + "involvedObject.kind=Deployment," + "involvedObject.uid=6d71451a-f8df-11ea-a8ac-0e13a02d8ebd")).andReturn(HttpURLConnection.HTTP_OK, new EventListBuilder().withItems(new EventBuilder().withNewMetadata().withName("foo-event").endMetadata().build()).build()).once();
// When
EventList eventList = client.v1().events().inNamespace("ns1").withInvolvedObject(new io.fabric8.kubernetes.api.model.ObjectReferenceBuilder().withName("foo").withNamespace("ns1").withKind("Deployment").withUid("6d71451a-f8df-11ea-a8ac-0e13a02d8ebd").build()).list();
// Then
assertNotNull(eventList);
assertEquals(1, eventList.getItems().size());
}
use of io.fabric8.kubernetes.api.model.events.v1beta1.EventBuilder in project stackgres by ongres.
the class ClusterEventResourceTest method ifEventsAreCreated_itShouldReturnThenInAnArray.
@Test
void ifEventsAreCreated_itShouldReturnThenInAnArray() {
try (KubernetesClient client = factory.create()) {
client.v1().events().inNamespace("test-namespace").create(new EventBuilder().withNewMetadata().withNamespace("test-namespace").withName("test.1").endMetadata().withType("Normal").withMessage("Test").withLastTimestamp(DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(1))).withInvolvedObject(new ObjectReferenceBuilder().withKind(StackGresCluster.KIND).withNamespace("test-namespace").withName("test").withUid("1").build()).build());
client.v1().events().inNamespace("test-namespace").create(new EventBuilder().withNewMetadata().withNamespace("test-namespace").withName("test.2").endMetadata().withType("Normal").withMessage("All good!").withLastTimestamp(DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(2))).withInvolvedObject(new ObjectReferenceBuilder().withKind("StatefulSet").withNamespace("test-namespace").withName("test").withUid("1").build()).build());
client.v1().events().inNamespace("test-namespace").create(new EventBuilder().withNewMetadata().withNamespace("test-namespace").withName("test.3").endMetadata().withType("Warning").withMessage("Something wrong :(").withLastTimestamp(DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(3))).withInvolvedObject(new ObjectReferenceBuilder().withKind("Pod").withNamespace("test-namespace").withName("test-0").withUid("1").build()).build());
client.v1().events().inNamespace("test-namespace").create(new EventBuilder().withNewMetadata().withNamespace("test-namespace").withName("test.4").endMetadata().withType("Normal").withMessage("I am here too").withLastTimestamp(DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochMilli(0))).withInvolvedObject(new ObjectReferenceBuilder().withKind(StackGresDbOps.KIND).withNamespace("test-namespace").withName("test-operation").withUid("1").build()).build());
}
given().when().header(AUTHENTICATION_HEADER).get("/stackgres/namespaces/test-namespace/sgclusters/test/events").then().statusCode(200).body("", Matchers.hasSize(4)).body("[0].metadata.name", Matchers.equalTo("test.4")).body("[0].type", Matchers.equalTo("Normal")).body("[0].message", Matchers.equalTo("I am here too")).body("[1].metadata.name", Matchers.equalTo("test.1")).body("[1].type", Matchers.equalTo("Normal")).body("[1].message", Matchers.equalTo("Test")).body("[2].metadata.name", Matchers.equalTo("test.2")).body("[2].type", Matchers.equalTo("Normal")).body("[2].message", Matchers.equalTo("All good!")).body("[3].metadata.name", Matchers.equalTo("test.3")).body("[3].type", Matchers.equalTo("Warning")).body("[3].message", Matchers.equalTo("Something wrong :("));
}
use of io.fabric8.kubernetes.api.model.events.v1beta1.EventBuilder in project flink-kubernetes-operator by apache.
the class FlinkDeploymentControllerTest method testUpgradeNotReadyCluster.
public void testUpgradeNotReadyCluster(FlinkDeployment appCluster, boolean allowUpgrade) {
mockServer.expect().delete().withPath("/apis/apps/v1/namespaces/flink-operator-test/deployments/test-cluster").andReturn(HttpURLConnection.HTTP_CREATED, new EventBuilder().withNewMetadata().endMetadata().build()).always();
mockServer.expect().get().withPath("/api/v1/namespaces/flink-operator-test/pods?labelSelector=app%3Dtest-cluster%2Ccomponent%3Djobmanager%2Ctype%3Dflink-native-kubernetes").andReturn(HttpURLConnection.HTTP_CREATED, new EventBuilder().withNewMetadata().endMetadata().build()).always();
testController.reconcile(appCluster, TestUtils.createEmptyContext());
assertEquals(appCluster.getSpec(), appCluster.getStatus().getReconciliationStatus().getLastReconciledSpec());
flinkService.setPortReady(false);
testController.reconcile(appCluster, context);
assertEquals(JobManagerDeploymentStatus.DEPLOYING, appCluster.getStatus().getJobManagerDeploymentStatus());
// trigger change
appCluster.getSpec().setServiceAccount(appCluster.getSpec().getServiceAccount() + "-2");
// Verify that even in DEPLOYING state we still redeploy
testController.reconcile(appCluster, context);
testController.reconcile(appCluster, context);
if (allowUpgrade) {
assertEquals(JobManagerDeploymentStatus.DEPLOYING, appCluster.getStatus().getJobManagerDeploymentStatus());
assertEquals(appCluster.getSpec(), appCluster.getStatus().getReconciliationStatus().getLastReconciledSpec());
flinkService.setPortReady(true);
testController.reconcile(appCluster, context);
testController.reconcile(appCluster, context);
if (appCluster.getSpec().getJob() != null) {
assertEquals("RUNNING", appCluster.getStatus().getJobStatus().getState());
} else {
assertNull(appCluster.getStatus().getJobStatus().getState());
}
assertEquals(JobManagerDeploymentStatus.READY, appCluster.getStatus().getJobManagerDeploymentStatus());
} else {
assertEquals(JobManagerDeploymentStatus.DEPLOYING, appCluster.getStatus().getJobManagerDeploymentStatus());
assertNotEquals(appCluster.getSpec(), appCluster.getStatus().getReconciliationStatus().getLastReconciledSpec());
flinkService.setPortReady(true);
testController.reconcile(appCluster, context);
testController.reconcile(appCluster, context);
assertEquals(JobManagerDeploymentStatus.DEPLOYING, appCluster.getStatus().getJobManagerDeploymentStatus());
assertEquals(appCluster.getSpec(), appCluster.getStatus().getReconciliationStatus().getLastReconciledSpec());
testController.reconcile(appCluster, context);
assertEquals(JobManagerDeploymentStatus.DEPLOYED_NOT_READY, appCluster.getStatus().getJobManagerDeploymentStatus());
testController.reconcile(appCluster, context);
assertEquals("RUNNING", appCluster.getStatus().getJobStatus().getState());
assertEquals(JobManagerDeploymentStatus.READY, appCluster.getStatus().getJobManagerDeploymentStatus());
}
}
Aggregations