Skip to content

Commit

Permalink
Merge branch 'xc-118006-42' into 'release/4.2'
Browse files Browse the repository at this point in the history
catch NullPointerException in WKO tests in release/4.2

See merge request weblogic-cloud/weblogic-kubernetes-operator!4708
  • Loading branch information
rjeberhard committed May 17, 2024
2 parents f848e43 + e83a056 commit d0752d1
Show file tree
Hide file tree
Showing 42 changed files with 573 additions and 404 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,15 @@ public void initAll(@Namespaces(2) List<String> namespaces) throws ApiException,
//start two MySQL database instances
String dbService1 = createMySQLDB("mysqldb-1", "root", "root123", domainNamespace, null);
V1Pod pod = getPod(domainNamespace, null, "mysqldb-1");
assertNotNull(pod, "pod is null");
assertNotNull(pod.getMetadata(), "pod metadata is null");
createFileInPod(pod.getMetadata().getName(), domainNamespace, "root123");
runMysqlInsidePod(pod.getMetadata().getName(), domainNamespace, "root123");

String dbService2 = createMySQLDB("mysqldb-2", "root", "root456", domainNamespace, null);
pod = getPod(domainNamespace, null, "mysqldb-2");
assertNotNull(pod, "pod is null");
assertNotNull(pod.getMetadata(), "pod metadata is null");
createFileInPod(pod.getMetadata().getName(), domainNamespace, "root456");
runMysqlInsidePod(pod.getMetadata().getName(), domainNamespace, "root456");

Expand Down Expand Up @@ -404,8 +409,9 @@ void testModifiedOverrideContent() {

testUntil(
withLongRetryPolicy,
() -> listConfigMaps(domainNamespace).getItems().stream().noneMatch((cm)
-> (cm.getMetadata().getName().equals(overridecm))),
() -> listConfigMaps(domainNamespace).getItems().stream().noneMatch(cm
-> cm.getMetadata() != null && cm.getMetadata().getName() != null
&& cm.getMetadata().getName().equals(overridecm)),
logger,
"configmap {0} to be deleted.");

Expand Down Expand Up @@ -1195,7 +1201,10 @@ private static Integer getMySQLNodePort(String namespace, String dbName) {
logger.info(dump(Kubernetes.listServices(namespace)));
List<V1Service> services = listServices(namespace).getItems();
for (V1Service service : services) {
if (service.getMetadata().getName().startsWith(dbName)) {
if (service.getMetadata() != null && service.getMetadata().getName() != null
&& service.getSpec() != null && service.getSpec().getPorts() != null
&& !service.getSpec().getPorts().isEmpty()
&& service.getMetadata().getName().startsWith(dbName)) {
return service.getSpec().getPorts().get(0).getNodePort();
}
}
Expand All @@ -1206,7 +1215,8 @@ private static String getMySQLSvcName(String namespace, String dbName) {
logger.info(dump(Kubernetes.listServices(namespace)));
List<V1Service> services = listServices(namespace).getItems();
for (V1Service service : services) {
if (service.getMetadata().getName().startsWith(dbName)) {
if (service.getMetadata() != null && service.getMetadata().getName() != null
&& service.getMetadata().getName().startsWith(dbName)) {
return service.getMetadata().getName();
}
}
Expand All @@ -1227,7 +1237,8 @@ private static String getMySQLSvcEndpoint(String domainNamespace, String dbName)
} catch (Exception e) {
getLogger().info("Got exception, command failed with errors " + e.getMessage());
}
return result.stdout();
assertNotNull(result, "result is null");
return result.stdout();
}

private static void runMysqlInsidePod(String podName, String namespace, String password) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,14 @@ private Callable<Boolean> checkEvictionEvent(String adminServerpodName,
boolean gotEvent = false;
List<CoreV1Event> events = Kubernetes.listNamespacedEvents(domainNamespace);
for (CoreV1Event event : events) {
if (event.getType().equals(type)
if (event.getType() != null
&& event.getType().equals(type)
&& event.getInvolvedObject() != null
&& event.getInvolvedObject().getName() != null
&& event.getInvolvedObject().getName().equals(adminServerpodName)
&& event.getReason() != null
&& event.getReason().equals(reason)
&& event.getMessage() != null
&& event.getMessage().contains(message)) {
logger.info(Yaml.dump(event));
gotEvent = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,7 @@ private static void verifyMemberHealth(String adminServerPodName, List<String> m
} catch (IOException | InterruptedException ex) {
logger.severe(ex.getMessage());
}
assertNotNull(result, "result is null");
String response = result.stdout().trim();
logger.info(response);
logger.info(result.stderr());
Expand Down Expand Up @@ -1574,7 +1575,10 @@ private DomainResource createDomainResourceWithConfigMap(String domainUid, Strin
private void updateIngressBackendServicePort(int newAdminPort) throws ApiException {
String ingressName = introDomainNamespace + "-" + domainUid + "-" + adminServerName + "-7001";
V1Ingress ingress = Ingress.getIngress(introDomainNamespace, ingressName).orElse(null);
if (ingress != null) {
if (ingress != null
&& ingress.getSpec() != null
&& ingress.getSpec().getRules() != null
&& !ingress.getSpec().getRules().isEmpty()) {
logger.info("Updating ingress {0} with new admin port {1}", ingressName, newAdminPort);
ingress.getSpec().getRules().getFirst().getHttp()
.getPaths().getFirst().getBackend().getService()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2023, Oracle and/or its affiliates.
// Copyright (c) 2023, 2024, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.

package oracle.weblogic.kubernetes;
Expand Down Expand Up @@ -102,7 +102,6 @@
import static oracle.weblogic.kubernetes.utils.K8sEvents.checkDomainEvent;
import static oracle.weblogic.kubernetes.utils.OKDUtils.createRouteForOKD;
import static oracle.weblogic.kubernetes.utils.OKDUtils.setTlsTerminationForRoute;
import static oracle.weblogic.kubernetes.utils.OperatorUtils.installAndVerifyOperator;
import static oracle.weblogic.kubernetes.utils.PatchDomainUtils.patchDomainResource;
import static oracle.weblogic.kubernetes.utils.PodUtils.getExternalServicePodName;
import static oracle.weblogic.kubernetes.utils.PodUtils.getPodsWithTimeStamps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@

@IntegrationTest
class ItLiftAndShiftFromOnPremDomain {
private static String opNamespace = null;
private static String traefikNamespace = null;
private static String domainNamespace = null;
private static final String LIFT_AND_SHIFT_WORK_DIR = WORK_DIR + "/liftandshiftworkdir";
Expand All @@ -124,10 +123,8 @@ class ItLiftAndShiftFromOnPremDomain {
private static final Path BUILD_SCRIPT_SOURCE_PATH = Paths.get(RESOURCE_DIR, "bash-scripts", BUILD_SCRIPT);
private static final String domainUid = "onprem-domain";
private static final String adminServerName = "admin-server";
private static final String appPath = "opdemo/index.jsp";
private static String imageName = null;
private static LoggingFacade logger = null;
private Path zipFile;

private static HelmParams traefikHelmParams = null;
private int traefikNodePort = 0;
Expand All @@ -145,7 +142,7 @@ public static void initAll(@Namespaces(3) List<String> namespaces) {
// get a new unique opNamespace
logger.info("Creating unique namespace for Operator");
assertNotNull(namespaces.get(0), "Namespace list is null");
opNamespace = namespaces.get(0);
String opNamespace = namespaces.get(0);

// get a unique traefik namespace
logger.info("Get a unique namespace for traefik");
Expand Down Expand Up @@ -220,13 +217,17 @@ void testCreateMiiDomainWithClusterFromOnPremDomain() throws UnknownHostExceptio
}

Path tempDomainDir = Paths.get(DOMAIN_TEMP_DIR);
zipFile = Paths.get(createZipFile(tempDomainDir));
String tmpDomainDirZip = createZipFile(tempDomainDir);
assertNotNull(tmpDomainDirZip, String.format("failed to create zip file %s", DOMAIN_TEMP_DIR));
Path zipFile = Paths.get(tmpDomainDirZip);
logger.info("zipfile is in {0}", zipFile.toString());

// Call WDT DiscoverDomain tool with wko target to get the required file to create a
// Mii domain image. Since WDT requires weblogic installation, we start a pod and run
// wdt discoverDomain tool in the pod
V1Pod webLogicPod = callSetupWebLogicPod(domainNamespace);
assertNotNull(webLogicPod, "webLogicPod is null");
assertNotNull(webLogicPod.getMetadata(), "webLogicPod metadata is null");

// copy the onprem domain zip file to /u01 location inside pod
try {
Expand Down Expand Up @@ -351,7 +352,7 @@ void testCreateMiiDomainWithClusterFromOnPremDomain() throws UnknownHostExceptio
}
}

String hostAndPort = null;
String hostAndPort;
if (OKD) {
hostAndPort = getHostAndPort(hostName, traefikNodePort);
} else {
Expand All @@ -378,7 +379,7 @@ void testCreateMiiDomainWithClusterFromOnPremDomain() throws UnknownHostExceptio
"opdemo/index.jsp",
"WebLogic on prem to wko App");

ExecResult execResult = null;
ExecResult execResult;
logger.info("curl command {0}", curlString);

execResult = assertDoesNotThrow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ private static void setLabelToNamespace(String domainNS, Map<String, String> lab
//add label to domain namespace
V1Namespace namespaceObject1 = assertDoesNotThrow(() -> Kubernetes.getNamespace(domainNS));
assertNotNull(namespaceObject1, "Can't find namespace with name " + domainNS);
assertNotNull(namespaceObject1.getMetadata(), "namespaceObject metadata is null");
namespaceObject1.getMetadata().setLabels(labels);
assertDoesNotThrow(() -> Kubernetes.replaceNamespace(namespaceObject1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,9 @@ WEBLOGIC_IMAGE_TO_USE_IN_SPEC, adminSecretName, createSecretsForImageRepos(domai
deleteConfigMap(configMapName, domainNamespace);
testUntil(
withLongRetryPolicy,
() -> listConfigMaps(domainNamespace).getItems().stream().noneMatch((cm)
-> (cm.getMetadata().getName().equals(configMapName))),
() -> listConfigMaps(domainNamespace).getItems().stream().noneMatch(cm
-> cm.getMetadata() != null && cm.getMetadata().getName() != null
&& cm.getMetadata().getName().equals(configMapName)),
logger,
"configmap {0} to be deleted.", configMapName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ public static void initAll(@Namespaces(2) List<String> namespaces) {

logger.info("Setting up WebLogic pod to access PV");
V1Pod pvPod = setupWebLogicPod(domainNamespace);
assertNotNull(pvPod, "pvPod is null");
assertNotNull(pvPod.getMetadata(), "pvPod metadata is null");

logger.info("Creating directory {0} in PV", modelMountPath + "/applications");
execInPod(pvPod, null, true, "mkdir -p " + modelMountPath + "/applications");
Expand Down Expand Up @@ -346,6 +348,7 @@ private static void verifyMemberHealth(String adminServerPodName, List<String> m
} catch (IOException | InterruptedException ex) {
logger.severe(ex.getMessage());
}
assertNotNull(result, "execResult is null");
String response = result.stdout().trim();
logger.info(response);
boolean health = true;
Expand Down Expand Up @@ -398,6 +401,7 @@ private static void verifyMemberHealth(String adminServerPodName, List<String> m
}

boolean health = true;
assertNotNull(result, "result is null");
for (String managedServer : managedServerNames) {
health = health && result.stdout().contains(managedServer + ":HEALTH_OK");
if (health) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020, 2023, Oracle and/or its affiliates.
// Copyright (c) 2020, 2024, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.

package oracle.weblogic.kubernetes;
Expand Down Expand Up @@ -268,8 +268,8 @@ void testMiiCustomEnv() {
for (int i = 0; i < envList.size(); i++) {
logger.info("The name is: {0}, value is: {1}", envList.get(i).getName(), envList.get(i).getValue());
if (envList.get(i).getName().equalsIgnoreCase("CUSTOM_ENV")) {
assertTrue(
envList.get(i).getValue().equalsIgnoreCase("${DOMAIN_UID}~##!'%*$(ls)"),
assertTrue(envList.get(i).getValue() != null
&& envList.get(i).getValue().equalsIgnoreCase("${DOMAIN_UID}~##!'%*$(ls)"),
"Expected value for CUSTOM_ENV variable does not mtach");
found = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ public static void initAll(@Namespaces(6) List<String> namespaces) {
dbService = createMySQLDB("mysql", "root", "root123", domain2Namespace, null);
assertNotNull(dbService, "Failed to create database");
V1Pod pod = getPod(domain2Namespace, null, "mysql");
assertNotNull(pod, "pod is null");
assertNotNull(pod.getMetadata(), "pod metadata is null");
createFileInPod(pod.getMetadata().getName(), domain2Namespace, "root123");
runMysqlInsidePod(pod.getMetadata().getName(), domain2Namespace, "root123", "/tmp/grant.sql");
runMysqlInsidePod(pod.getMetadata().getName(), domain2Namespace, "root123", "/tmp/create.sql");
Expand Down Expand Up @@ -390,10 +392,8 @@ private void fireAlert() throws ApiException {
List<V1Pod> pods = listPods(webhookNS, "app=webhook").getItems();
assertNotNull((pods), "No pods are running in namespace : " + webhookNS);
V1Pod pod = pods.stream()
.filter(testpod -> testpod
.getMetadata()
.getName()
.contains("webhook"))
.filter(testpod -> testpod.getMetadata() != null && testpod.getMetadata().getName() != null
&& testpod.getMetadata().getName().contains("webhook"))
.findAny()
.orElse(null);

Expand Down Expand Up @@ -706,7 +706,7 @@ private static void uninstallDeploymentService(V1Deployment deployment, V1Servic
String serviceName = null;
String deploymentName = null;
try {
if (service != null) {
if (service != null && service.getMetadata() != null) {
serviceName = service.getMetadata().getName();
namespace = service.getMetadata().getNamespace();
Kubernetes.deleteService(serviceName, namespace);
Expand All @@ -717,7 +717,7 @@ private static void uninstallDeploymentService(V1Deployment deployment, V1Servic
serviceName, namespace);
}
try {
if (deployment != null) {
if (deployment != null && deployment.getMetadata() != null) {
deploymentName = deployment.getMetadata().getName();
namespace = deployment.getMetadata().getNamespace();
Kubernetes.deleteDeployment(namespace, deploymentName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,13 @@ private static String getLoadBalancerIP(String namespace, String lbName) throws
V1Service service = getService(lbName, labels, namespace);
assertNotNull(service, "Can't find service with name " + lbName);
logger.info("Found service with name {0} in {1} namespace ", lbName, namespace);
assertNotNull(service.getStatus(), "service status is null");
assertNotNull(service.getStatus().getLoadBalancer(), "service loadbalancer is null");
List<V1LoadBalancerIngress> ingress = service.getStatus().getLoadBalancer().getIngress();
if (ingress != null) {
logger.info("LoadBalancer Ingress " + ingress.toString());
V1LoadBalancerIngress lbIng = ingress.stream().filter(c ->
!c.getIp().equals("pending")
).findAny().orElse(null);
V1LoadBalancerIngress lbIng =
ingress.stream().filter(c -> c.getIp() != null && !c.getIp().equals("pending")).findAny().orElse(null);
if (lbIng != null) {
logger.info("OCI LoadBalancer is created with external ip" + lbIng.getIp());
return lbIng.getIp();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020, 2022, Oracle and/or its affiliates.
// Copyright (c) 2020, 2024, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.

package oracle.weblogic.kubernetes;
Expand Down Expand Up @@ -139,6 +139,8 @@ private void createAndVerifyPodFromTemplate(String imageName,
//check that managed server pod is up and all applicable variable values are initialized.
assertNotNull(managedServerPod,"The managed server pod does not exist in namespace " + domainNamespace);
V1ObjectMeta managedServerMetadata = managedServerPod.getMetadata();
assertNotNull(managedServerMetadata, "managed server pod metadata is null");
assertNotNull(managedServerMetadata.getLabels(), "managed server metadata label is null");
String serverName = managedServerMetadata.getLabels().get("servername");
logger.info("Checking that variables used in the labels and annotations "
+ "in the serverPod for servername, domainname, clustername are initialized");
Expand Down Expand Up @@ -170,6 +172,7 @@ private void createAndVerifyPodFromTemplate(String imageName,

logger.info("Checking that applicable variables used "
+ "in the annotations for domainhome and loghome are initialized");
assertNotNull(managedServerMetadata.getAnnotations(), "managed server metadata annotation is null");
String loghome = managedServerMetadata.getAnnotations().get("loghome");
//check that annotation contains loghome in the pod
assertNotNull(loghome, "Can't find annotation loghome");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020, 2023, Oracle and/or its affiliates.
// Copyright (c) 2020, 2024, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.

package oracle.weblogic.kubernetes;
Expand Down Expand Up @@ -375,8 +375,8 @@ void testServerPodsRestartByChangingEnvProperty() {
envList = domain1.getSpec().getServerPod().getEnv();
String envValue = envList.get(0).getValue();
logger.info("In the new patched domain envValue is: {0}", envValue);
assertTrue(envValue.equalsIgnoreCase("-Dweblogic.StdoutDebugEnabled=true"), "JAVA_OPTIONS was not updated"
+ " in the new patched domain");
assertTrue(envValue != null && envValue.equalsIgnoreCase("-Dweblogic.StdoutDebugEnabled=true"),
"JAVA_OPTIONS was not updated in the new patched domain");

// verify the server pods are rolling restarted and back to ready state
logger.info("Verifying rolling restart occurred for domain {0} in namespace {1}",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020, 2023, Oracle and/or its affiliates.
// Copyright (c) 2020, 2024, Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.

package oracle.weblogic.kubernetes;
Expand Down Expand Up @@ -246,6 +246,8 @@ void testPodAnnotationWithSlash() {
assertNotNull(managedServerPod,
"The managed server pod does not exist in namespace " + domainNamespace);
V1ObjectMeta managedServerMetadata = managedServerPod.getMetadata();
assertNotNull(managedServerMetadata, "managed server metadata is null");
assertNotNull(managedServerMetadata.getAnnotations(), "managed server metadata annotation is null");
String myAnnotationValue = managedServerMetadata.getAnnotations().get(annotationKey);
String myAnnotationValue2 = managedServerMetadata.getAnnotations().get(annotationKey2);
String myAnnotationValue3 = managedServerMetadata.getAnnotations().get(annotationKey3);
Expand Down
Loading

0 comments on commit d0752d1

Please sign in to comment.