io.fabric8.kubernetes.api.model.Event Java Examples
The following examples show how to use
io.fabric8.kubernetes.api.model.Event.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Diagnostics.java From dekorate with Apache License 2.0 | 7 votes |
protected void events(Pod pod) { try { Map<String, String> fields = new HashMap<>(); fields.put("involvedObject.uid", pod.getMetadata().getUid()); fields.put("involvedObject.name", pod.getMetadata().getName()); fields.put("involvedObject.namespace", pod.getMetadata().getNamespace()); EventList eventList = client.events().inNamespace(pod.getMetadata().getNamespace()).withFields(fields).list(); if (eventList == null) { return; } logger.warning("Events of pod: [" + pod.getMetadata().getName() + "]"); for (Event event : eventList.getItems()) { logger.info(String.format("%s\t\t%s", event.getReason(), event.getMessage())); } } catch (Throwable t) { logger.error("Failed to read events, due to:" + t.getMessage()); } finally { logger.warning("\t---"); } }
Example #2
Source File: KubernetesElasticAgent.java From kubernetes-elastic-agents with Apache License 2.0 | 6 votes |
private static ArrayList<KubernetesPodEvent> getAllEventsForPod(Pod pod, KubernetesClient client) { ArrayList<KubernetesPodEvent> events = new ArrayList<>(); for (Event event : client.events().inAnyNamespace().list().getItems()) { if (event.getInvolvedObject().getKind().equals("Pod") && event.getInvolvedObject().getName().equals(pod.getMetadata().getName())) { KubernetesPodEvent podEvent = new KubernetesPodEvent(event.getFirstTimestamp(), event.getLastTimestamp(), event.getCount(), event.getInvolvedObject().getFieldPath(), event.getType(), event.getReason(), event.getMessage()); events.add(podEvent); } } return events; }
Example #3
Source File: TopicOperatorBaseIT.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
protected void waitForEvent(KafkaTopic kafkaTopic, String expectedMessage, TopicOperator.EventType expectedType) throws InterruptedException, ExecutionException, TimeoutException { waitFor(() -> { List<Event> items = kubeClient.events().inNamespace(NAMESPACE).withLabels(labels.labels()).list().getItems(); List<Event> filtered = items.stream(). filter(evt -> !preExistingEvents.contains(evt.getMetadata().getUid()) && "KafkaTopic".equals(evt.getInvolvedObject().getKind()) && kafkaTopic.getMetadata().getName().equals(evt.getInvolvedObject().getName())). collect(Collectors.toList()); LOGGER.debug("Waiting for events: {}", filtered.stream().map(evt -> evt.getMessage()).collect(Collectors.toList())); return filtered.stream().anyMatch(event -> Pattern.matches(expectedMessage, event.getMessage()) && Objects.equals(expectedType.name, event.getType()) && event.getInvolvedObject() != null && event.getLastTimestamp() != null && Objects.equals("KafkaTopic", event.getInvolvedObject().getKind()) && Objects.equals(kafkaTopic.getMetadata().getName(), event.getInvolvedObject().getName())); }, "Expected an error event"); }
Example #4
Source File: HasAnyOfReasons.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") public boolean matches(Object actualValue) { List<String> actualReasons = ((List<Event>) actualValue).stream() .map(Event::getReason) .collect(Collectors.toList()); List<String> expectedReasons = Arrays.stream(eventReasons) .map(Enum::name) .collect(Collectors.toList()); for (String actualReason : actualReasons) { if (expectedReasons.contains(actualReason)) { return true; } } return false; }
Example #5
Source File: KubernetesPersistentVolumeClaims.java From che with Eclipse Public License 2.0 | 5 votes |
/** * Creates and returns {@link Watch} that watches for 'WaitForFirstConsumer' events on given PVC. */ private Watch pvcIsWaitingForConsumerWatcher( CompletableFuture<PersistentVolumeClaim> future, PersistentVolumeClaim actualPvc) throws InfrastructureException { return clientFactory .create(workspaceId) .events() .inNamespace(namespace) .withField(PVC_EVENT_REASON_FIELD_KEY, PVC_EVENT_WAIT_CONSUMER_REASON) .withField(PVC_EVENT_UID_FIELD_KEY, actualPvc.getMetadata().getUid()) .watch( new Watcher<Event>() { @Override public void eventReceived(Action action, Event resource) { LOG.debug( "PVC '" + actualPvc.getMetadata().getName() + "' is waiting for first consumer. Don't wait to bound to avoid deadlock."); future.complete(actualPvc); } @Override public void onClose(KubernetesClientException cause) { safelyFinishFutureOnClose(cause, future, actualPvc.getMetadata().getName()); } }); }
Example #6
Source File: TaskListenerEventWatcher.java From kubernetes-plugin with Apache License 2.0 | 5 votes |
@Override public void eventReceived(Action action, Event event) { PrintStream logger = listener.getLogger(); // Messages can have multiple lines String[] lines = event.getMessage().split("\n"); for (String line : lines) { logger.printf("[%s][%s/%s][%s] %s%n", event.getType(), event.getInvolvedObject().getNamespace(), event.getInvolvedObject().getName(), event.getReason(), line); } }
Example #7
Source File: KubernetesComputer.java From kubernetes-plugin with Apache License 2.0 | 5 votes |
@Exported public List<Event> getPodEvents() throws KubernetesAuthException, IOException { if(!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) { LOGGER.log(Level.FINE, " Computer {0} getPodEvents, lack of admin permission, returning empty list", this); return Collections.emptyList(); } KubernetesSlave slave = getNode(); if(slave != null) { KubernetesCloud cloud = slave.getKubernetesCloud(); KubernetesClient client = cloud.connect(); String namespace = StringUtils.defaultIfBlank(slave.getNamespace(), client.getNamespace()); Pod pod = client.pods().inNamespace(namespace).withName(getName()).get(); if(pod != null) { ObjectMeta podMeta = pod.getMetadata(); String podNamespace = podMeta.getNamespace(); Map<String, String> fields = new HashMap<>(); fields.put("involvedObject.uid", podMeta.getUid()); fields.put("involvedObject.name", podMeta.getName()); fields.put("involvedObject.namespace", podNamespace); EventList eventList = client.events().inNamespace(podNamespace).withFields(fields).list(); if(eventList != null) { return eventList.getItems(); } } } return Collections.emptyList(); }
Example #8
Source File: KubernetesDeploymentsTest.java From che with Eclipse Public License 2.0 | 5 votes |
@Test public void shouldHandleEventWithEmptyLastTimestampAndFirstTimestamp() throws Exception { // Given when(objectReference.getKind()).thenReturn(POD_OBJECT_KIND); kubernetesDeployments.watchEvents(podEventHandler); Calendar cal = Calendar.getInstance(); cal.add(Calendar.MINUTE, -1); Date minuteAgo = cal.getTime(); Field f = KubernetesDeployments.class.getDeclaredField("watcherInitializationDate"); f.setAccessible(true); f.set(kubernetesDeployments, minuteAgo); verify(eventNamespaceMixedOperation).watch(eventWatcherCaptor.capture()); Watcher<Event> watcher = eventWatcherCaptor.getValue(); Event event = mock(Event.class); when(event.getInvolvedObject()).thenReturn(objectReference); when(event.getMetadata()).thenReturn(new ObjectMeta()); when(event.getLastTimestamp()).thenReturn(null); when(event.getFirstTimestamp()).thenReturn(null); // When watcher.eventReceived(Watcher.Action.ADDED, event); // Then verify(event, times(1)).getLastTimestamp(); verify(event, times(1)).getFirstTimestamp(); ArgumentCaptor<PodEvent> captor = ArgumentCaptor.forClass(PodEvent.class); verify(podEventHandler).handle(captor.capture()); PodEvent podEvent = captor.getValue(); assertNotNull(podEvent.getLastTimestamp()); }
Example #9
Source File: KubernetesDeploymentsTest.java From che with Eclipse Public License 2.0 | 5 votes |
@Test public void shouldUseLastTimestampIfAvailable() throws InfrastructureException { // Given when(objectReference.getKind()).thenReturn(POD_OBJECT_KIND); kubernetesDeployments.watchEvents(podEventHandler); verify(eventNamespaceMixedOperation).watch(eventWatcherCaptor.capture()); Watcher<Event> watcher = eventWatcherCaptor.getValue(); Event event = mock(Event.class); when(event.getInvolvedObject()).thenReturn(objectReference); when(event.getMetadata()).thenReturn(new ObjectMeta()); Calendar cal = Calendar.getInstance(); cal.add(Calendar.YEAR, 2); Date nextYear = cal.getTime(); when(event.getLastTimestamp()).thenReturn(PodEvents.convertDateToEventTimestamp(nextYear)); when(event.getFirstTimestamp()).thenReturn(PodEvents.convertDateToEventTimestamp(new Date())); // When watcher.eventReceived(Watcher.Action.ADDED, event); // Then verify(event, times(1)).getLastTimestamp(); verify(event, never()).getFirstTimestamp(); ArgumentCaptor<PodEvent> captor = ArgumentCaptor.forClass(PodEvent.class); verify(podEventHandler).handle(captor.capture()); PodEvent podEvent = captor.getValue(); assertEquals(podEvent.getLastTimestamp(), PodEvents.convertDateToEventTimestamp(nextYear)); }
Example #10
Source File: KubernetesDeploymentsTest.java From che with Eclipse Public License 2.0 | 5 votes |
@Test public void shouldFallbackToFirstTimeStampIfLastTimeStampIsNull() throws InfrastructureException { // Given when(objectReference.getKind()).thenReturn(POD_OBJECT_KIND); kubernetesDeployments.watchEvents(podEventHandler); verify(eventNamespaceMixedOperation).watch(eventWatcherCaptor.capture()); Watcher<Event> watcher = eventWatcherCaptor.getValue(); Event event = mock(Event.class); when(event.getInvolvedObject()).thenReturn(objectReference); when(event.getMetadata()).thenReturn(new ObjectMeta()); Calendar cal = Calendar.getInstance(); cal.add(Calendar.YEAR, 1); Date nextYear = cal.getTime(); when(event.getFirstTimestamp()).thenReturn(PodEvents.convertDateToEventTimestamp(nextYear)); when(event.getLastTimestamp()).thenReturn(null); // When watcher.eventReceived(Watcher.Action.ADDED, event); // Then verify(event, times(1)).getLastTimestamp(); verify(event, times(1)).getFirstTimestamp(); ArgumentCaptor<PodEvent> captor = ArgumentCaptor.forClass(PodEvent.class); verify(podEventHandler).handle(captor.capture()); PodEvent podEvent = captor.getValue(); assertEquals(podEvent.getLastTimestamp(), PodEvents.convertDateToEventTimestamp(nextYear)); }
Example #11
Source File: KubernetesDeploymentsTest.java From che with Eclipse Public License 2.0 | 5 votes |
@Test public void shouldCallHandlerForEventsOnDeployments() throws Exception { // Given when(objectReference.getKind()).thenReturn(DEPLOYMENT_OBJECT_KIND); kubernetesDeployments.watchEvents(podEventHandler); verify(eventNamespaceMixedOperation).watch(eventWatcherCaptor.capture()); Watcher<Event> watcher = eventWatcherCaptor.getValue(); // When watcher.eventReceived(Watcher.Action.ADDED, event); // Then verify(podEventHandler).handle(any()); }
Example #12
Source File: KubernetesDeploymentsTest.java From che with Eclipse Public License 2.0 | 5 votes |
@Test public void shouldCallHandlerForEventsOnReplicaSets() throws Exception { // Given when(objectReference.getKind()).thenReturn(REPLICASET_OBJECT_KIND); kubernetesDeployments.watchEvents(podEventHandler); verify(eventNamespaceMixedOperation).watch(eventWatcherCaptor.capture()); Watcher<Event> watcher = eventWatcherCaptor.getValue(); // When watcher.eventReceived(Watcher.Action.ADDED, event); // Then verify(podEventHandler).handle(any()); }
Example #13
Source File: KubernetesDeploymentsTest.java From che with Eclipse Public License 2.0 | 5 votes |
@Test public void shouldCallHandlerForEventsOnPods() throws Exception { // Given when(objectReference.getKind()).thenReturn(POD_OBJECT_KIND); kubernetesDeployments.watchEvents(podEventHandler); verify(eventNamespaceMixedOperation).watch(eventWatcherCaptor.capture()); Watcher<Event> watcher = eventWatcherCaptor.getValue(); // When watcher.eventReceived(Watcher.Action.ADDED, event); // Then verify(podEventHandler).handle(any()); }
Example #14
Source File: HasNoneOfReasons.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public void describeMismatch(Object item, Description description) { describeTo(description); description.appendValueList(" but actual event reasons were {", ", ", "}.", ((List<Event>) item).stream().map(evt -> { String objRef = ""; if (evt.getInvolvedObject() != null) { objRef = " involved object: " + evt.getInvolvedObject().getKind() + "/" + evt.getInvolvedObject().getName(); } return evt.getReason() + " (" + evt.getType() + " " + evt.getMessage() + objRef + ")\n"; }) .collect(Collectors.toList())); }
Example #15
Source File: HasAllOfReasons.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public boolean matches(Object actualValue) { List<String> actualReasons = ((List<Event>) actualValue).stream() .map(Event::getReason) .collect(Collectors.toList()); List<String> expectedReasons = Arrays.stream(eventReasons) .map(Enum::name) .collect(Collectors.toList()); return actualReasons.containsAll(expectedReasons); }
Example #16
Source File: MockK8s.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@Override public Future<Void> createEvent(Event event) { Promise<Void> handler = Promise.promise(); events.add(event); handler.handle(Future.succeededFuture()); return handler.future(); }
Example #17
Source File: MockK8s.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
public void assertContainsEvent(VertxTestContext context, Predicate<Event> test) { for (Event event : events) { if (test.test(event)) { return; } } context.failNow(new Throwable("Missing event")); }
Example #18
Source File: DefaultOpenShiftClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public MixedOperation<Event, EventList, DoneableEvent, Resource<Event, DoneableEvent>> events() { return delegate.events(); }
Example #19
Source File: HasNoneOfReasons.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
@Override @SuppressWarnings("unchecked") public boolean matches(Object actualValue) { return !filtered((List<Event>) actualValue).findFirst().isPresent(); }
Example #20
Source File: ManagedOpenShiftClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public MixedOperation<Event, EventList, DoneableEvent, Resource<Event, DoneableEvent>> events() { return delegate.events(); }
Example #21
Source File: UtilsTest.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Test @DisplayName("Should test whether resource is namespaced or not") void testWhetherNamespacedOrNot() { assertTrue(Utils.isResourceNamespaced(Binding.class)); assertFalse(Utils.isResourceNamespaced(ComponentStatus.class)); assertTrue(Utils.isResourceNamespaced(ConfigMap.class)); assertTrue(Utils.isResourceNamespaced(Endpoints.class)); assertTrue(Utils.isResourceNamespaced(Event.class)); assertTrue(Utils.isResourceNamespaced(LimitRange.class)); assertFalse(Utils.isResourceNamespaced(Namespace.class)); assertFalse(Utils.isResourceNamespaced(Node.class)); assertTrue(Utils.isResourceNamespaced(PersistentVolumeClaim.class)); assertFalse(Utils.isResourceNamespaced(PersistentVolume.class)); assertTrue(Utils.isResourceNamespaced(Pod.class)); assertTrue(Utils.isResourceNamespaced(PodTemplate.class)); assertTrue(Utils.isResourceNamespaced(ReplicationController.class)); assertTrue(Utils.isResourceNamespaced(ResourceQuota.class)); assertTrue(Utils.isResourceNamespaced(Secret.class)); assertTrue(Utils.isResourceNamespaced(ServiceAccount.class)); assertTrue(Utils.isResourceNamespaced(Service.class)); assertFalse(Utils.isResourceNamespaced(MutatingWebhookConfiguration.class)); assertFalse(Utils.isResourceNamespaced(ValidatingWebhookConfiguration.class)); assertFalse(Utils.isResourceNamespaced(CustomResourceDefinition.class)); assertTrue(Utils.isResourceNamespaced(ControllerRevision.class)); assertTrue(Utils.isResourceNamespaced(DaemonSet.class)); assertTrue(Utils.isResourceNamespaced(Deployment.class)); assertTrue(Utils.isResourceNamespaced(ReplicaSet.class)); assertTrue(Utils.isResourceNamespaced(StatefulSet.class)); assertTrue(Utils.isResourceNamespaced(TokenReview.class)); assertTrue(Utils.isResourceNamespaced(LocalSubjectAccessReview.class)); assertTrue(Utils.isResourceNamespaced(SelfSubjectAccessReview.class)); assertTrue(Utils.isResourceNamespaced(SelfSubjectRulesReview.class)); assertTrue(Utils.isResourceNamespaced(SubjectAccessReview.class)); assertTrue(Utils.isResourceNamespaced(HorizontalPodAutoscaler.class)); assertTrue(Utils.isResourceNamespaced(CronJob.class)); assertTrue(Utils.isResourceNamespaced(Job.class)); assertTrue(Utils.isResourceNamespaced(CertificateSigningRequest.class)); assertTrue(Utils.isResourceNamespaced(Lease.class)); assertTrue(Utils.isResourceNamespaced(EndpointSlice.class)); assertTrue(Utils.isResourceNamespaced(Ingress.class)); assertTrue(Utils.isResourceNamespaced(NetworkPolicy.class)); assertTrue(Utils.isResourceNamespaced(PodDisruptionBudget.class)); assertFalse(Utils.isResourceNamespaced(PodSecurityPolicy.class)); assertFalse(Utils.isResourceNamespaced(ClusterRoleBinding.class)); assertFalse(Utils.isResourceNamespaced(ClusterRole.class)); assertTrue(Utils.isResourceNamespaced(RoleBinding.class)); assertTrue(Utils.isResourceNamespaced(Role.class)); assertFalse(Utils.isResourceNamespaced(PriorityClass.class)); assertTrue(Utils.isResourceNamespaced(CSIDriver.class)); assertTrue(Utils.isResourceNamespaced(CSINode.class)); assertFalse(Utils.isResourceNamespaced(StorageClass.class)); assertTrue(Utils.isResourceNamespaced(VolumeAttachment.class)); }
Example #22
Source File: UtilsTest.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Test void testGetPluralFromKind() { // Given Map<String, Class> pluralToKubernetesResourceMap = new HashMap<>(); pluralToKubernetesResourceMap.put("bindings", Binding.class); pluralToKubernetesResourceMap.put("componentstatuses", ComponentStatus.class); pluralToKubernetesResourceMap.put("configmaps", ConfigMap.class); pluralToKubernetesResourceMap.put("endpoints", Endpoints.class); pluralToKubernetesResourceMap.put("events", Event.class); pluralToKubernetesResourceMap.put("limitranges", LimitRange.class); pluralToKubernetesResourceMap.put("namespaces", Namespace.class); pluralToKubernetesResourceMap.put("nodes", Node.class); pluralToKubernetesResourceMap.put("persistentvolumeclaims", PersistentVolumeClaim.class); pluralToKubernetesResourceMap.put("persistentvolumes", PersistentVolume.class); pluralToKubernetesResourceMap.put("pods", Pod.class); pluralToKubernetesResourceMap.put("podtemplates", PodTemplate.class); pluralToKubernetesResourceMap.put("replicationcontrollers", ReplicationController.class); pluralToKubernetesResourceMap.put("resourcequotas", ResourceQuota.class); pluralToKubernetesResourceMap.put("secrets", Secret.class); pluralToKubernetesResourceMap.put("serviceaccounts", ServiceAccount.class); pluralToKubernetesResourceMap.put("services", Service.class); pluralToKubernetesResourceMap.put("mutatingwebhookconfigurations", MutatingWebhookConfiguration.class); pluralToKubernetesResourceMap.put("validatingwebhookconfigurations", ValidatingWebhookConfiguration.class); pluralToKubernetesResourceMap.put("customresourcedefinitions", CustomResourceDefinition.class); pluralToKubernetesResourceMap.put("controllerrevisions", ControllerRevision.class); pluralToKubernetesResourceMap.put("daemonsets", DaemonSet.class); pluralToKubernetesResourceMap.put("deployments", Deployment.class); pluralToKubernetesResourceMap.put("replicasets", ReplicaSet.class); pluralToKubernetesResourceMap.put("statefulsets", StatefulSet.class); pluralToKubernetesResourceMap.put("tokenreviews", TokenReview.class); pluralToKubernetesResourceMap.put("localsubjectaccessreviews", LocalSubjectAccessReview.class); pluralToKubernetesResourceMap.put("selfsubjectaccessreviews", SelfSubjectAccessReview.class); pluralToKubernetesResourceMap.put("selfsubjectrulesreviews", SelfSubjectRulesReview.class); pluralToKubernetesResourceMap.put("subjectaccessreviews", SubjectAccessReview.class); pluralToKubernetesResourceMap.put("horizontalpodautoscalers", HorizontalPodAutoscaler.class); pluralToKubernetesResourceMap.put("cronjobs", CronJob.class); pluralToKubernetesResourceMap.put("jobs", Job.class); pluralToKubernetesResourceMap.put("certificatesigningrequests", CertificateSigningRequest.class); pluralToKubernetesResourceMap.put("leases", Lease.class); pluralToKubernetesResourceMap.put("endpointslices", EndpointSlice.class); pluralToKubernetesResourceMap.put("ingresses", Ingress.class); pluralToKubernetesResourceMap.put("networkpolicies", NetworkPolicy.class); pluralToKubernetesResourceMap.put("poddisruptionbudgets", PodDisruptionBudget.class); pluralToKubernetesResourceMap.put("podsecuritypolicies", PodSecurityPolicy.class); pluralToKubernetesResourceMap.put("clusterrolebindings", ClusterRoleBinding.class); pluralToKubernetesResourceMap.put("clusterroles", ClusterRole.class); pluralToKubernetesResourceMap.put("rolebindings", RoleBinding.class); pluralToKubernetesResourceMap.put("roles", Role.class); pluralToKubernetesResourceMap.put("priorityclasses", PriorityClass.class); pluralToKubernetesResourceMap.put("csidrivers", CSIDriver.class); pluralToKubernetesResourceMap.put("csinodes", CSINode.class); pluralToKubernetesResourceMap.put("storageclasses", StorageClass.class); pluralToKubernetesResourceMap.put("volumeattachments", VolumeAttachment.class); // When & Then pluralToKubernetesResourceMap.forEach((plural, kubernetesResource) -> assertEquals(plural, Utils.getPluralFromKind(kubernetesResource.getSimpleName()))); }
Example #23
Source File: ManagedKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
public MixedOperation<Event, EventList, DoneableEvent, Resource<Event, DoneableEvent>> events() { return delegate.events(); }
Example #24
Source File: DefaultKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public MixedOperation<Event, EventList, DoneableEvent, Resource<Event, DoneableEvent>> events() { return new EventOperationsImpl(httpClient, getConfiguration()); }
Example #25
Source File: V1APIGroupClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public MixedOperation<Event, EventList, DoneableEvent, Resource<Event, DoneableEvent>> events() { return new EventOperationsImpl(httpClient, getConfiguration()); }
Example #26
Source File: AutoAdaptableKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public MixedOperation<Event, EventList, DoneableEvent, Resource<Event, DoneableEvent>> events() { return delegate.events(); }
Example #27
Source File: KubeClient.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
public List<Event> listEvents() { return client.events().inNamespace(getNamespace()).list().getItems(); }
Example #28
Source File: KubeClient.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
public List<Event> listEvents(String resourceType, String resourceName) { return client.events().inNamespace(getNamespace()).list().getItems().stream() .filter(event -> event.getInvolvedObject().getKind().equals(resourceType)) .filter(event -> event.getInvolvedObject().getName().equals(resourceName)) .collect(Collectors.toList()); }
Example #29
Source File: KubeClient.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
public List<Event> listEvents(String resourceUid) { return listEvents().stream() .filter(event -> event.getInvolvedObject().getUid().equals(resourceUid)) .collect(Collectors.toList()); }
Example #30
Source File: KafkaRollerST.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
@Test void testKafkaRollsWhenTopicIsUnderReplicated() { String topicName = KafkaTopicUtils.generateRandomNameOfTopic(); timeMeasuringSystem.setOperationID(timeMeasuringSystem.startTimeMeasuring(Operation.CLUSTER_RECOVERY)); KafkaResource.kafkaPersistent(CLUSTER_NAME, 4) .editSpec() .editKafka() .addToConfig("auto.create.topics.enable", "false") .endKafka() .endSpec() .done(); LOGGER.info("Running kafkaScaleUpScaleDown {}", CLUSTER_NAME); final int initialReplicas = kubeClient().getStatefulSet(KafkaResources.kafkaStatefulSetName(CLUSTER_NAME)).getStatus().getReplicas(); assertEquals(4, initialReplicas); Map<String, String> kafkaPods = StatefulSetUtils.ssSnapshot(KafkaResources.kafkaStatefulSetName(CLUSTER_NAME)); KafkaTopicResource.topic(CLUSTER_NAME, topicName, 4, 4, 4).done(); //Test that the new pod does not have errors or failures in events String uid = kubeClient().getPodUid(KafkaResources.kafkaPodName(CLUSTER_NAME, 3)); List<Event> events = kubeClient().listEvents(uid); assertThat(events, hasAllOfReasons(Scheduled, Pulled, Created, Started)); //Test that CO doesn't have any exceptions in log timeMeasuringSystem.stopOperation(timeMeasuringSystem.getOperationID()); assertNoCoErrorsLogged(timeMeasuringSystem.getDurationInSeconds(testClass, testName, timeMeasuringSystem.getOperationID())); // scale down int scaledDownReplicas = 3; LOGGER.info("Scaling down to {}", scaledDownReplicas); timeMeasuringSystem.setOperationID(timeMeasuringSystem.startTimeMeasuring(Operation.SCALE_DOWN)); KafkaResource.replaceKafkaResource(CLUSTER_NAME, k -> k.getSpec().getKafka().setReplicas(scaledDownReplicas)); StatefulSetUtils.waitForAllStatefulSetPodsReady(KafkaResources.kafkaStatefulSetName(CLUSTER_NAME), scaledDownReplicas); PodUtils.verifyThatRunningPodsAreStable(CLUSTER_NAME); // set annotation to trigger Kafka rolling update kubeClient().statefulSet(KafkaResources.kafkaStatefulSetName(CLUSTER_NAME)).cascading(false).edit() .editMetadata() .addToAnnotations(Annotations.ANNO_STRIMZI_IO_MANUAL_ROLLING_UPDATE, "true") .endMetadata() .done(); StatefulSetUtils.waitTillSsHasRolled(KafkaResources.kafkaStatefulSetName(CLUSTER_NAME), kafkaPods); }