Skip to content

Commit db7b448

Browse files
committed
Merge branch 'events' into 'main'
Use most current types for Kubernetes Events See merge request weblogic-cloud/weblogic-kubernetes-operator!5032
2 parents 7d7ebe5 + 28782b7 commit db7b448

File tree

47 files changed

+605
-529
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+605
-529
lines changed

documentation/site/content/managing-domains/accessing-the-domain/domain-events.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ Each operator-generated event contains the following fields:
8888
* `namespace`: Namespace in which the event is generated.
8989
* `labels`: `weblogic.createdByOperator=true` and, for a domain event, `weblogic.domainUID=<domainUID>`.
9090
* `type`: String that describes the type of the event. Possible values are `Normal` or `Warning`.
91-
* `count`: Integer that indicates the number of occurrences of the event. Note that the events are matched by the combination of the `reason`, `involvedObject`, and `message` fields.
91+
* `count`: Integer that indicates the number of occurrences of the event. Note that the events are matched by the combination of the `reason`, `regarding`, and `message` fields.
9292
* `reportingComponent`: String that describes the component that reports the event. The value is `weblogic.operator` for all operator-generated events.
9393
* `reportingInstance`: String that describes the instance that reports the event. The value is the Kubernetes pod name of the operator instance that generates the event.
9494
* `firstTimestamp`: `DateTime` field that presents the timestamp of the first occurrence of this event.
9595
* `lastTimestamp`: `DateTime` field that presents the timestamp of the last occurrence of this event.
9696
* `reason`: Short, machine understandable string that gives the reason for the transition to the object's current status.
97-
* `message`: String that describes the details of the event.
98-
* `involvedObject`: `V1ObjectReference` object that describes the Kubernetes resources with which this event is associated.
97+
* `note`: String that describes the details of the event.
98+
* `regarding`: `V1ObjectReference` object that describes the Kubernetes resources with which this event is associated.
9999
* `name`: String that describes the name of the resource with which the event is associated. It may be the `domainUID`, the name of the namespace that the operator watches, or the name of the operator pod.
100100
* `namespace`: String that describes the namespace of the event, which is either the namespace of the domain resource or the namespace of the operator.
101101
* `kind`: String that describes the kind of resource this object represents. The value is `Domain` for a domain event, `Namespace` for a namespace event in the domain namespace, or `Pod` for the operator pod.

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItEvictedPodsCycling.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import java.util.Map;
99
import java.util.concurrent.Callable;
1010

11-
import io.kubernetes.client.openapi.models.CoreV1Event;
11+
import io.kubernetes.client.openapi.models.EventsV1Event;
1212
import io.kubernetes.client.openapi.models.V1ResourceRequirements;
1313
import io.kubernetes.client.util.Yaml;
1414
import oracle.weblogic.domain.DomainResource;
@@ -198,18 +198,18 @@ private static void checkServerPodsAndServiceReady() {
198198
}
199199

200200
private Callable<Boolean> checkEvictionEvent(String adminServerpodName,
201-
String reason, String message, String type) {
201+
String reason, String note, String type) {
202202
return (() -> {
203203
boolean gotEvent = false;
204-
List<CoreV1Event> events = Kubernetes.listNamespacedEvents(domainNamespace);
205-
for (CoreV1Event event : events) {
204+
List<EventsV1Event> events = Kubernetes.listNamespacedEvents(domainNamespace);
205+
for (EventsV1Event event : events) {
206206
if (event.getType() != null && event.getType().equals(type)
207-
&& event.getInvolvedObject().getName() != null
208-
&& event.getInvolvedObject().getName().equals(adminServerpodName)
207+
&& event.getRegarding().getName() != null
208+
&& event.getRegarding().getName().equals(adminServerpodName)
209209
&& event.getReason() != null
210210
&& event.getReason().equals(reason)
211-
&& event.getMessage() != null
212-
&& event.getMessage().contains(message)) {
211+
&& event.getNote() != null
212+
&& event.getNote().contains(note)) {
213213
logger.info(Yaml.dump(event));
214214
gotEvent = true;
215215
}

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItHorizontalPodAutoscalerCustomMetrics.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import io.kubernetes.client.custom.Quantity;
1818
import io.kubernetes.client.openapi.ApiException;
19-
import io.kubernetes.client.openapi.models.CoreV1Event;
19+
import io.kubernetes.client.openapi.models.EventsV1Event;
2020
import io.kubernetes.client.openapi.models.V1LocalObjectReference;
2121
import io.kubernetes.client.openapi.models.V1ResourceRequirements;
2222
import io.kubernetes.client.util.Yaml;
@@ -392,8 +392,8 @@ void testHPAWithCustomMetrics() {
392392
logger.info("Executing command " + command);
393393
result = ExecCommand.exec(command);
394394
logger.info(" Result output: " + result.stdout());
395-
List<CoreV1Event> events = getEvents(domainNamespace,timestamp);
396-
for (CoreV1Event event : events) {
395+
List<EventsV1Event> events = getEvents(domainNamespace,timestamp);
396+
for (EventsV1Event event : events) {
397397
logger.info("Generated events after HPA scaling " + Yaml.dump(event));
398398
}
399399
int numberOfManagedSvs = 3;

integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/primitive/Kubernetes.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@
3232
import io.kubernetes.client.openapi.apis.BatchV1Api;
3333
import io.kubernetes.client.openapi.apis.CoreV1Api;
3434
import io.kubernetes.client.openapi.apis.CustomObjectsApi;
35+
import io.kubernetes.client.openapi.apis.EventsV1Api;
3536
import io.kubernetes.client.openapi.apis.NetworkingV1Api;
3637
import io.kubernetes.client.openapi.apis.PolicyV1Api;
3738
import io.kubernetes.client.openapi.apis.RbacAuthorizationV1Api;
38-
import io.kubernetes.client.openapi.models.CoreV1Event;
39-
import io.kubernetes.client.openapi.models.CoreV1EventList;
39+
import io.kubernetes.client.openapi.models.EventsV1Event;
40+
import io.kubernetes.client.openapi.models.EventsV1EventList;
41+
import io.kubernetes.client.openapi.models.EventsV1EventSeries;
4042
import io.kubernetes.client.openapi.models.V1ClusterRole;
4143
import io.kubernetes.client.openapi.models.V1ClusterRoleBinding;
4244
import io.kubernetes.client.openapi.models.V1ClusterRoleBindingList;
@@ -123,6 +125,7 @@ public class Kubernetes {
123125
// Core Kubernetes API clients
124126
private static ApiClient apiClient = null;
125127
private static CoreV1Api coreV1Api = null;
128+
private static EventsV1Api eventsV1Api = null;
126129
private static PolicyV1Api policyV1Api = null;
127130
private static CustomObjectsApi customObjectsApi = null;
128131
private static RbacAuthorizationV1Api rbacAuthApi = null;
@@ -153,6 +156,7 @@ public class Kubernetes {
153156
apiClient.setConnectTimeout(0);
154157
apiClient.setReadTimeout(0);
155158
coreV1Api = new CoreV1Api();
159+
eventsV1Api = new EventsV1Api();
156160
policyV1Api = new PolicyV1Api();
157161
customObjectsApi = new CustomObjectsApi();
158162
rbacAuthApi = new RbacAuthorizationV1Api();
@@ -1146,13 +1150,13 @@ private static Callable<Boolean> namespaceDeleted(String namespace) {
11461150
* List events in a namespace.
11471151
*
11481152
* @param namespace name of the namespace in which to list events
1149-
* @return List of {@link CoreV1Event} objects
1153+
* @return List of {@link EventsV1Event} objects
11501154
* @throws ApiException when listing events fails
11511155
*/
1152-
public static List<CoreV1Event> listNamespacedEvents(String namespace) throws ApiException {
1153-
List<CoreV1Event> events = null;
1156+
public static List<EventsV1Event> listNamespacedEvents(String namespace) throws ApiException {
1157+
List<EventsV1Event> events = null;
11541158
try {
1155-
CoreV1EventList list = coreV1Api.listNamespacedEvent(
1159+
EventsV1EventList list = eventsV1Api.listNamespacedEvent(
11561160
namespace, // String | namespace.
11571161
PRETTY, // String | If 'true', then the output is pretty printed.
11581162
ALLOW_WATCH_BOOKMARKS, // Boolean | allowWatchBookmarks requests watch events with type "BOOKMARK".
@@ -1166,8 +1170,8 @@ public static List<CoreV1Event> listNamespacedEvents(String namespace) throws Ap
11661170
TIMEOUT_SECONDS, // Integer | Timeout for the list call.
11671171
Boolean.FALSE // Boolean | Watch for changes to the described resources.
11681172
);
1169-
events = Optional.ofNullable(list).map(CoreV1EventList::getItems).orElse(Collections.emptyList());
1170-
events.sort(Comparator.comparing(CoreV1Event::getLastTimestamp,
1173+
events = Optional.ofNullable(list).map(EventsV1EventList::getItems).orElse(Collections.emptyList());
1174+
events.sort(Comparator.comparing(Kubernetes::getEventTime,
11711175
Comparator.nullsFirst(Comparator.naturalOrder())));
11721176
Collections.reverse(events);
11731177
} catch (ApiException apex) {
@@ -1177,17 +1181,22 @@ public static List<CoreV1Event> listNamespacedEvents(String namespace) throws Ap
11771181
return events;
11781182
}
11791183

1184+
private static OffsetDateTime getEventTime(EventsV1Event event) {
1185+
return Optional.ofNullable(event.getSeries())
1186+
.map(EventsV1EventSeries::getLastObservedTime).orElse(event.getEventTime());
1187+
}
1188+
11801189
/**
11811190
* List operator generated events in a namespace.
11821191
*
11831192
* @param namespace name of the namespace in which to list events
1184-
* @return List of {@link CoreV1Event} objects
1193+
* @return List of {@link EventsV1Event} objects
11851194
* @throws ApiException when listing events fails
11861195
*/
1187-
public static List<CoreV1Event> listOpGeneratedNamespacedEvents(String namespace) throws ApiException {
1188-
List<CoreV1Event> events = null;
1196+
public static List<EventsV1Event> listOpGeneratedNamespacedEvents(String namespace) throws ApiException {
1197+
List<EventsV1Event> events = null;
11891198
try {
1190-
CoreV1EventList list = coreV1Api.listNamespacedEvent(
1199+
EventsV1EventList list = eventsV1Api.listNamespacedEvent(
11911200
namespace, // String | namespace.
11921201
PRETTY, // String | If 'true', then the output is pretty printed.
11931202
ALLOW_WATCH_BOOKMARKS, // Boolean | allowWatchBookmarks requests watch events with type "BOOKMARK".
@@ -1201,8 +1210,8 @@ public static List<CoreV1Event> listOpGeneratedNamespacedEvents(String namespace
12011210
TIMEOUT_SECONDS, // Integer | Timeout for the list call.
12021211
Boolean.FALSE // Boolean | Watch for changes to the described resources.
12031212
);
1204-
events = Optional.ofNullable(list).map(CoreV1EventList::getItems).orElse(Collections.emptyList());
1205-
events.sort(Comparator.comparing(CoreV1Event::getLastTimestamp,
1213+
events = Optional.ofNullable(list).map(EventsV1EventList::getItems).orElse(Collections.emptyList());
1214+
events.sort(Comparator.comparing(Kubernetes::getEventTime,
12061215
Comparator.nullsFirst(Comparator.naturalOrder())));
12071216
Collections.reverse(events);
12081217
} catch (ApiException apex) {

0 commit comments

Comments
 (0)