Skip to content

Commit ff7af18

Browse files
authored
Fix assertion and add events log to the logs list (#1619)
* Add namespaced events in the collected logs list Fix the persistent volume claim log file name Fix the isPodReady test assertion to check for pod readyness instead of Running status Change the wait time from 5 minutes to 10 minutes * Fix the operator pod ready assertion * Adding roles, rolebindings, clusterroles and clusterrolebindings to the diagnostics * Increasing the introspector pod timeout to 5 minutes * change the namespaced roles and rolebindings file names
1 parent 9f8e5a7 commit ff7af18

File tree

7 files changed

+140
-18
lines changed

7 files changed

+140
-18
lines changed

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
import static oracle.weblogic.kubernetes.assertions.TestAssertions.doesImageExist;
8282
import static oracle.weblogic.kubernetes.assertions.TestAssertions.domainExists;
8383
import static oracle.weblogic.kubernetes.assertions.TestAssertions.isHelmReleaseDeployed;
84-
import static oracle.weblogic.kubernetes.assertions.TestAssertions.operatorIsRunning;
84+
import static oracle.weblogic.kubernetes.assertions.TestAssertions.operatorIsReady;
8585
import static oracle.weblogic.kubernetes.assertions.TestAssertions.podExists;
8686
import static oracle.weblogic.kubernetes.assertions.TestAssertions.podReady;
8787
import static oracle.weblogic.kubernetes.assertions.TestAssertions.serviceExists;
@@ -225,7 +225,7 @@ public static void initAll(@Namespaces(3) List<String> namespaces) {
225225
opNamespace,
226226
condition.getElapsedTimeInMS(),
227227
condition.getRemainingTimeInMS()))
228-
.until(operatorIsRunning(opNamespace));
228+
.until(operatorIsReady(opNamespace));
229229

230230
}
231231

@@ -666,7 +666,8 @@ private void createDomainResource(String domainUid, String domNamespace, String
666666
.configuration(new Configuration()
667667
.model(new Model()
668668
.domainType("WLS")
669-
.runtimeEncryptionSecret(encryptionSecretName))));
669+
.runtimeEncryptionSecret(encryptionSecretName))
670+
.introspectorJobActiveDeadlineSeconds(300L)));
670671

671672
logger.info("Create domain custom resource for domainUid {0} in namespace {1}",
672673
domainUid, domNamespace);

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItSimpleOperatorValidation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import static oracle.weblogic.kubernetes.actions.TestActions.getOperatorImageName;
4141
import static oracle.weblogic.kubernetes.actions.TestActions.installOperator;
4242
import static oracle.weblogic.kubernetes.assertions.TestAssertions.isHelmReleaseDeployed;
43-
import static oracle.weblogic.kubernetes.assertions.TestAssertions.operatorIsRunning;
43+
import static oracle.weblogic.kubernetes.assertions.TestAssertions.operatorIsReady;
4444
import static org.awaitility.Awaitility.with;
4545
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
4646
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -154,7 +154,7 @@ public void testInstallingOperator(@Namespaces(3) List<String> namespaces) {
154154
opNamespace,
155155
condition.getElapsedTimeInMS(),
156156
condition.getRemainingTimeInMS()))
157-
.until(operatorIsRunning(opNamespace));
157+
.until(operatorIsReady(opNamespace));
158158

159159
}
160160

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import java.io.OutputStream;
1313
import java.nio.file.Path;
1414
import java.util.ArrayList;
15+
import java.util.Collections;
16+
import java.util.Comparator;
1517
import java.util.List;
1618
import java.util.concurrent.Callable;
1719

@@ -42,6 +44,8 @@
4244
import io.kubernetes.client.openapi.models.V1ConfigMapList;
4345
import io.kubernetes.client.openapi.models.V1Deployment;
4446
import io.kubernetes.client.openapi.models.V1DeploymentList;
47+
import io.kubernetes.client.openapi.models.V1Event;
48+
import io.kubernetes.client.openapi.models.V1EventList;
4549
import io.kubernetes.client.openapi.models.V1Job;
4650
import io.kubernetes.client.openapi.models.V1JobList;
4751
import io.kubernetes.client.openapi.models.V1Namespace;
@@ -245,7 +249,7 @@ private static void initializeGenericKubernetesApiClients() {
245249
V1SecretList.class, // the api list type class
246250
"", // the api group
247251
"v1", // the api version
248-
"serviceaccounts", // the resource plural
252+
"secrets", // the resource plural
249253
apiClient //the api client
250254
);
251255

@@ -639,6 +643,40 @@ public Boolean call() throws Exception {
639643
};
640644
}
641645

646+
// --------------------------- Events ---------------------------------------------------
647+
648+
/**
649+
* List events in a namespace.
650+
*
651+
* @param namespace name of the namespace in which to list events
652+
* @return List of {@link V1Event} objects
653+
* @throws ApiException when listing events fails
654+
*/
655+
public static List<V1Event> listNamespacedEvents(String namespace) throws ApiException {
656+
List<V1Event> events = null;
657+
try {
658+
V1EventList list = coreV1Api.listNamespacedEvent(
659+
namespace, // String | namespace.
660+
PRETTY, // String | If 'true', then the output is pretty printed.
661+
ALLOW_WATCH_BOOKMARKS, // Boolean | allowWatchBookmarks requests watch events with type "BOOKMARK".
662+
null, // String | The continue option should be set when retrieving more results from the server.
663+
null, // String | A selector to restrict the list of returned objects by their fields.
664+
null, // String | A selector to restrict the list of returned objects by their labels.
665+
null, // Integer | limit is a maximum number of responses to return for a list call.
666+
RESOURCE_VERSION, // String | Shows changes that occur after that particular version of a resource.
667+
TIMEOUT_SECONDS, // Integer | Timeout for the list call.
668+
Boolean.FALSE // Boolean | Watch for changes to the described resources.
669+
);
670+
events = list.getItems();
671+
events.sort(Comparator.comparing(e -> e.getMetadata().getCreationTimestamp()));
672+
Collections.reverse(events);
673+
} catch (ApiException apex) {
674+
logger.warning(apex.getResponseBody());
675+
throw apex;
676+
}
677+
return events;
678+
}
679+
642680
// --------------------------- Custom Resource Domain -----------------------------------
643681
/**
644682
* Create a Domain Custom Resource.

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public class TestAssertions {
2626
* @param namespace in which is operator is running
2727
* @return true if running false otherwise
2828
*/
29-
public static Callable<Boolean> operatorIsRunning(String namespace) {
30-
return Operator.isRunning(namespace);
29+
public static Callable<Boolean> operatorIsReady(String namespace) {
30+
return Operator.isReady(namespace);
3131
}
3232

3333
/**
@@ -91,10 +91,11 @@ public static Callable<Boolean> podDoesNotExist(String podName, String domainUid
9191
* @param domainUid WebLogic domain uid in which the pod belongs
9292
* @param namespace in which the pod is running
9393
* @return true if the pod is running otherwise false
94+
* @throws ApiException when Kubernetes cluster query fails to get pod
9495
*/
9596
public static Callable<Boolean> podReady(String podName, String domainUid, String namespace) throws ApiException {
9697
return () -> {
97-
return Kubernetes.isPodRunning(namespace, domainUid, podName);
98+
return Kubernetes.isPodReady(namespace, domainUid, podName);
9899
};
99100
}
100101

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.kubernetes.client.openapi.apis.CoreV1Api;
1616
import io.kubernetes.client.openapi.apis.CustomObjectsApi;
1717
import io.kubernetes.client.openapi.models.V1Pod;
18+
import io.kubernetes.client.openapi.models.V1PodCondition;
1819
import io.kubernetes.client.openapi.models.V1PodList;
1920
import io.kubernetes.client.openapi.models.V1Service;
2021
import io.kubernetes.client.openapi.models.V1ServiceList;
@@ -87,6 +88,40 @@ public static boolean isPodRunning(String namespace, String domainUid, String po
8788
return status;
8889
}
8990

91+
/**
92+
* Checks if a pod is ready in a given namespace.
93+
*
94+
* @param namespace in which to check if the pod is ready
95+
* @param domainUid the label the pod is decorated with
96+
* @param podName name of the pod to check for
97+
* @return true if the pod is in the ready condition, false otherwise
98+
* @throws ApiException if Kubernetes client API call fails
99+
*/
100+
public static boolean isPodReady(String namespace, String domainUid, String podName) throws ApiException {
101+
boolean status = false;
102+
String labelSelector = null;
103+
if (domainUid != null) {
104+
labelSelector = String.format("weblogic.domainUID in (%s)", domainUid);
105+
}
106+
107+
V1Pod pod = getPod(namespace, labelSelector, podName);
108+
if (pod != null) {
109+
110+
// get the podCondition with the 'Ready' type field
111+
V1PodCondition v1PodReadyCondition = pod.getStatus().getConditions().stream()
112+
.filter(v1PodCondition -> "Ready".equals(v1PodCondition.getType()))
113+
.findAny()
114+
.orElse(null);
115+
116+
if (v1PodReadyCondition != null) {
117+
status = v1PodReadyCondition.getStatus().equalsIgnoreCase("true");
118+
}
119+
} else {
120+
logger.info("Pod doesn't exist");
121+
}
122+
return status;
123+
}
124+
90125
/**
91126
* Checks if a pod exists in a given namespace and in Terminating state.
92127
* @param namespace in which to check for the pod
@@ -119,12 +154,20 @@ public static boolean isPodTerminating(String namespace, String domainUid, Strin
119154
* @return true if pod exists and running otherwise false
120155
* @throws ApiException when there is error in querying the cluster
121156
*/
122-
public static boolean isOperatorPodRunning(String namespace) throws ApiException {
157+
public static boolean isOperatorPodReady(String namespace) throws ApiException {
123158
boolean status = false;
124159
String labelSelector = String.format("weblogic.operatorName in (%s)", namespace);
125160
V1Pod pod = getPod(namespace, labelSelector, "weblogic-operator-");
126161
if (pod != null) {
127-
status = pod.getStatus().getPhase().equals(RUNNING);
162+
// get the podCondition with the 'Ready' type field
163+
V1PodCondition v1PodReadyCondition = pod.getStatus().getConditions().stream()
164+
.filter(v1PodCondition -> "Ready".equals(v1PodCondition.getType()))
165+
.findAny()
166+
.orElse(null);
167+
168+
if (v1PodReadyCondition != null) {
169+
status = v1PodReadyCondition.getStatus().equalsIgnoreCase("true");
170+
}
128171
} else {
129172
logger.info("Pod doesn't exist");
130173
}
@@ -155,10 +198,10 @@ public static V1Pod getPod(String namespace, String labelSelector, String podNam
155198
);
156199
for (V1Pod item : v1PodList.getItems()) {
157200
if (item.getMetadata().getName().startsWith(podName.trim())) {
158-
logger.info("Pod Name :" + item.getMetadata().getName());
159-
logger.info("Pod Namespace :" + item.getMetadata().getNamespace());
160-
logger.info("Pod UID :" + item.getMetadata().getUid());
161-
logger.info("Pod Status :" + item.getStatus().getPhase());
201+
logger.info("Pod Name: " + item.getMetadata().getName());
202+
logger.info("Pod Namespace: " + item.getMetadata().getNamespace());
203+
logger.info("Pod UID: " + item.getMetadata().getUid());
204+
logger.info("Pod Status: " + item.getStatus().getPhase());
162205
return item;
163206
}
164207
}

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Operator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public class Operator {
1616
* @param namespace in which to check for the operator pod
1717
* @return true if found and running otherwise false
1818
*/
19-
public static Callable<Boolean> isRunning(String namespace) {
19+
public static Callable<Boolean> isReady(String namespace) {
2020
return () -> {
21-
return Kubernetes.isOperatorPodRunning(namespace);
21+
return Kubernetes.isOperatorPodReady(namespace);
2222
};
2323
}
2424

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/LoggingUtil.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ public static void generateLog(Object itInstance, List namespaces) {
7878
public static void collectLogs(String namespace, String resultDir) {
7979
logger.info("Collecting logs in namespace : {0}", namespace);
8080

81+
// get events
82+
try {
83+
writeToFile(Kubernetes.listNamespacedEvents(namespace), resultDir, namespace + ".list.events.log");
84+
} catch (Exception ex) {
85+
logger.warning("Listing events failed, not collecting any data for events");
86+
}
87+
8188
// get service accounts
8289
try {
8390
writeToFile(Kubernetes.listServiceAccounts(namespace), resultDir,
@@ -130,7 +137,7 @@ public static void collectLogs(String namespace, String resultDir) {
130137
}
131138
// write pv list
132139
try {
133-
writeToFile(pvList, resultDir, ".list.persistent-volumes.log");
140+
writeToFile(pvList, resultDir, "list.persistent-volumes.log");
134141
} catch (IOException ex) {
135142
logger.warning(ex.getMessage());
136143
}
@@ -173,6 +180,38 @@ public static void collectLogs(String namespace, String resultDir) {
173180
logger.warning(ex.getMessage());
174181
}
175182

183+
// get cluster roles
184+
try {
185+
writeToFile(Kubernetes.listClusterRoles(null), resultDir,
186+
"list.cluster-roles.log");
187+
} catch (Exception ex) {
188+
logger.warning(ex.getMessage());
189+
}
190+
191+
// get cluster role bindings
192+
try {
193+
writeToFile(Kubernetes.listClusterRoleBindings(null), resultDir,
194+
"list.cluster-rolebindings.log");
195+
} catch (Exception ex) {
196+
logger.warning(ex.getMessage());
197+
}
198+
199+
// get namespaced roles
200+
try {
201+
writeToFile(Kubernetes.listNamespacedRoles(namespace), resultDir,
202+
namespace + ".list.roles.log");
203+
} catch (Exception ex) {
204+
logger.warning(ex.getMessage());
205+
}
206+
207+
// get namespaced rolebindings
208+
try {
209+
writeToFile(Kubernetes.listNamespacedRoleBinding(namespace), resultDir,
210+
namespace + ".list.rolebindings.log");
211+
} catch (Exception ex) {
212+
logger.warning(ex.getMessage());
213+
}
214+
176215
// get domain objects in the given namespace
177216
try {
178217
writeToFile(Kubernetes.listDomains(namespace), resultDir, namespace + ".list.domains.log");

0 commit comments

Comments
 (0)