Skip to content

Commit df8469d

Browse files
authored
Merge pull request #1073 from oracle/owls-73691
OWLS-73691 - readiness probe needs to work with domain with administration port enabled
2 parents 662dc2a + 64ac168 commit df8469d

File tree

10 files changed

+208
-5
lines changed

10 files changed

+208
-5
lines changed

integration-tests/src/test/java/oracle/kubernetes/operator/JrfInOperatorAdvancedTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,13 @@ public void testJRFDomainAdminPortEnabled() throws Exception {
293293
domain1Map.put(
294294
"createDomainPyScript",
295295
"integration-tests/src/test/resources/domain-home-on-pv/create-jrfdomain-admin-port-enabled.py");
296+
// Use -Dweblogic.ssl.AcceptKSSDemoCertsEnabled=true so that managed servers can connect
297+
// to admin server using SSL without running into host name verifcation check error
298+
// in default JRF domain that uses KSS demo identity and trust
299+
// https://docs.oracle.com/middleware/12213/wls/SECMG/kss.htm#SECMG673tm#ADMRF202
300+
domain1Map.put(
301+
"javaOptions",
302+
"-Dweblogic.StdoutDebugEnabled=false -Dweblogic.ssl.AcceptKSSDemoCertsEnabled=true");
296303

297304
// run RCU script to load db schema
298305
DBUtils.runRCU(rcuPodName, domain1Map);

operator/src/main/java/oracle/kubernetes/operator/helpers/PodHelper.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,16 @@ protected Map<String, String> getPodAnnotations() {
289289
return getServerSpec().getPodAnnotations();
290290
}
291291

292+
@Override
293+
boolean isLocalAdminProtocolChannelSecure() {
294+
return scan.isLocalAdminProtocolChannelSecure();
295+
}
296+
297+
@Override
298+
Integer getLocalAdminProtocolChannelPort() {
299+
return scan.getLocalAdminProtocolChannelPort();
300+
}
301+
292302
@Override
293303
Integer getDefaultPort() {
294304
return scan.getListenPort();

operator/src/main/java/oracle/kubernetes/operator/helpers/PodStepContext.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,21 @@ String getAsName() {
172172
}
173173

174174
Integer getAsPort() {
175-
return domainTopology.getServerConfig(domainTopology.getAdminServerName()).getListenPort();
175+
return domainTopology
176+
.getServerConfig(domainTopology.getAdminServerName())
177+
.getLocalAdminProtocolChannelPort();
178+
}
179+
180+
boolean isLocalAdminProtocolChannelSecure() {
181+
return domainTopology
182+
.getServerConfig(domainTopology.getAdminServerName())
183+
.isLocalAdminProtocolChannelSecure();
184+
}
185+
186+
Integer getLocalAdminProtocolChannelPort() {
187+
return domainTopology
188+
.getServerConfig(domainTopology.getAdminServerName())
189+
.getLocalAdminProtocolChannelPort();
176190
}
177191

178192
private String getLogHome() {
@@ -789,6 +803,9 @@ void overrideContainerWeblogicEnvVars(List<V1EnvVar> vars) {
789803
addEnvVar(vars, "DOMAIN_HOME", getDomainHome());
790804
addEnvVar(vars, "ADMIN_NAME", getAsName());
791805
addEnvVar(vars, "ADMIN_PORT", getAsPort().toString());
806+
if (isLocalAdminProtocolChannelSecure()) {
807+
addEnvVar(vars, "ADMIN_PORT_SECURE", "true");
808+
}
792809
addEnvVar(vars, "SERVER_NAME", getServerName());
793810
addEnvVar(vars, "DOMAIN_UID", getDomainUID());
794811
addEnvVar(vars, "NODEMGR_HOME", NODEMGR_HOME);
@@ -825,14 +842,21 @@ private V1Probe createReadinessProbe(TuningParameters.PodTuning tuning) {
825842
.timeoutSeconds(getReadinessProbeTimeoutSeconds(tuning))
826843
.periodSeconds(getReadinessProbePeriodSeconds(tuning))
827844
.failureThreshold(FAILURE_THRESHOLD)
828-
.httpGet(httpGetAction(READINESS_PATH, getDefaultPort()));
845+
.httpGet(
846+
httpGetAction(
847+
READINESS_PATH,
848+
getLocalAdminProtocolChannelPort(),
849+
isLocalAdminProtocolChannelSecure()));
829850
return readinessProbe;
830851
}
831852

832853
@SuppressWarnings("SameParameterValue")
833-
private V1HTTPGetAction httpGetAction(String path, int port) {
854+
private V1HTTPGetAction httpGetAction(String path, int port, boolean useHTTPS) {
834855
V1HTTPGetAction getAction = new V1HTTPGetAction();
835856
getAction.path(path).port(new IntOrString(port));
857+
if (useHTTPS) {
858+
getAction.scheme("HTTPS");
859+
}
836860
return getAction;
837861
}
838862

operator/src/main/java/oracle/kubernetes/operator/wlsconfig/WlsDynamicServerConfig.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ static WlsDynamicServerConfig create(
7272
macroSubstitutor.substituteMacro(serverTemplate.getListenAddress()),
7373
sslListenPort,
7474
macroSubstitutor.substituteMacro(serverTemplate.getMachineName()),
75+
serverTemplate.getAdminPort(),
7576
networkAccessPoints);
7677
}
7778

@@ -84,6 +85,7 @@ static WlsDynamicServerConfig create(
8485
* @param listenAddress listen address of the dynamic server
8586
* @param sslListenPort SSL listen port of the dynamic server
8687
* @param machineName machine name of the dynamic server
88+
* @param adminPort administration port if administration port is enabled
8789
* @param networkAccessPoints network access points or channels configured for this dynamic server
8890
*/
8991
private WlsDynamicServerConfig(
@@ -92,8 +94,16 @@ private WlsDynamicServerConfig(
9294
String listenAddress,
9395
Integer sslListenPort,
9496
String machineName,
97+
Integer adminPort,
9598
List<NetworkAccessPoint> networkAccessPoints) {
96-
super(name, listenAddress, machineName, listenPort, sslListenPort, null, networkAccessPoints);
99+
super(
100+
name,
101+
listenAddress,
102+
machineName,
103+
listenPort,
104+
sslListenPort,
105+
adminPort,
106+
networkAccessPoints);
97107
}
98108

99109
/**

operator/src/main/java/oracle/kubernetes/operator/wlsconfig/WlsServerConfig.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,31 @@ public Integer getLocalAdminProtocolChannelPort() {
203203
return adminProtocolPort;
204204
}
205205

206+
public boolean isLocalAdminProtocolChannelSecure() {
207+
boolean adminProtocolPortSecure = false;
208+
boolean adminProtocolPortFound = false;
209+
if (networkAccessPoints != null) {
210+
for (NetworkAccessPoint nap : networkAccessPoints) {
211+
if (nap.isAdminProtocol()) {
212+
adminProtocolPortFound = true;
213+
adminProtocolPortSecure = true;
214+
break;
215+
}
216+
}
217+
}
218+
if (!adminProtocolPortFound) {
219+
if (adminPort != null) {
220+
adminProtocolPortSecure = true;
221+
} else if (sslListenPort != null) {
222+
adminProtocolPortSecure = true;
223+
} else if (listenPort != null) {
224+
adminProtocolPortSecure = false;
225+
}
226+
}
227+
228+
return adminProtocolPortSecure;
229+
}
230+
206231
/**
207232
* Creates a WLSServerConfig object using an "servers" or "serverTemplates" item parsed from JSON
208233
* result from WLS REST call.

operator/src/main/resources/scripts/introspectDomain.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,9 @@ def addServer(self, server):
583583
self.writeln(" listenAddress: " + self.quote(self.env.toDNS1123Legal(self.env.getDomainUID() + "-" + server.getName())))
584584
if server.isAdministrationPortEnabled():
585585
self.writeln(" adminPort: " + str(server.getAdministrationPort()))
586+
else:
587+
if self.env.getDomain().isAdministrationPortEnabled():
588+
self.writeln(" adminPort: " + str(self.env.getDomain().getAdministrationPort()))
586589
self.addSSL(server)
587590
self.addNetworkAccessPoints(server)
588591

operator/src/main/resources/scripts/startNodeManager.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
# ${DOMAIN_UID}/${SERVER_NAME}_nodemanager.out
2727
# Default:
2828
# Use LOG_HOME. If LOG_HOME not set, use NODEMGR_HOME.
29+
# ADMIN_PORT_SECURE = "true" if the admin protocol is secure. Default is false
2930
#
3031
# If SERVER_NAME is set, then this NM is for a WL Server and these must also be set:
3132
#
@@ -51,6 +52,7 @@ export WL_HOME="${WL_HOME:-/u01/oracle/wlserver}"
5152
stm_script=${WL_HOME}/server/bin/startNodeManager.sh
5253

5354
SERVER_NAME=${SERVER_NAME:-introspector}
55+
ADMIN_PORT_SECURE=${ADMIN_PORT_SECURE:-false}
5456

5557
trace "Starting node manager for domain-uid='$DOMAIN_UID' and server='$SERVER_NAME'."
5658

@@ -244,7 +246,11 @@ EOF
244246
[ ! $? -eq 0 ] && trace "Failed to create '${wl_props_file}'." && exit 1
245247

246248
if [ ! "${ADMIN_NAME}" = "${SERVER_NAME}" ]; then
247-
echo "AdminURL=http\\://${AS_SERVICE_NAME}\\:${ADMIN_PORT}" >> ${wl_props_file}
249+
admin_protocol="http"
250+
if [ "${ADMIN_PORT_SECURE}" = "true" ]; then
251+
admin_protocol="https"
252+
fi
253+
echo "AdminURL=$admin_protocol\\://${AS_SERVICE_NAME}\\:${ADMIN_PORT}" >> ${wl_props_file}
248254
fi
249255
fi
250256

operator/src/test/java/oracle/kubernetes/operator/helpers/PodHelperTestBase.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,23 @@ public void whenPodCreated_readinessProbeHasDefinedTuning() {
365365
hasExpectedTuning(READINESS_INITIAL_DELAY, READINESS_TIMEOUT, READINESS_PERIOD));
366366
}
367367

368+
@Test
369+
public void whenPodCreatedWithAdminPortEnabled_readinessProbeHasReadinessCommand() {
370+
final Integer ADMIN_PORT = 9002;
371+
domainTopology.getServerConfig(serverName).setAdminPort(ADMIN_PORT);
372+
V1HTTPGetAction getAction = getCreatedPodSpecContainer().getReadinessProbe().getHttpGet();
373+
assertThat(getAction.getPath(), equalTo("/weblogic/ready"));
374+
assertThat(getAction.getPort().getIntValue(), equalTo(ADMIN_PORT));
375+
assertThat(getAction.getScheme(), equalTo("HTTPS"));
376+
}
377+
378+
@Test
379+
public void whenPodCreatedWithAdminPortEnabled_adminPortSecureEnvVarIsTrue() {
380+
final Integer ADMIN_PORT = 9002;
381+
domainTopology.getServerConfig(serverName).setAdminPort(ADMIN_PORT);
382+
assertThat(getCreatedPodSpecContainer().getEnv(), hasEnvVar("ADMIN_PORT_SECURE", "true"));
383+
}
384+
368385
@Test
369386
public void whenPodCreatedWithDomainV2Settings_livenessProbeHasConfiguredTuning() {
370387
configureServer()

operator/src/test/java/oracle/kubernetes/operator/wlsconfig/WlsDynamicServerConfigTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
package oracle.kubernetes.operator.wlsconfig;
66

7+
import static org.hamcrest.MatcherAssert.assertThat;
8+
import static org.hamcrest.Matchers.is;
79
import static org.junit.Assert.assertEquals;
810
import static org.junit.Assert.assertNull;
911

@@ -84,4 +86,17 @@ public void testCreateWithCalculatedDefaultPorts() {
8486
assertEquals(new Integer(9102), networkAccessPoint1.getListenPort());
8587
assertNull(networkAccessPoint1.getPublicPort());
8688
}
89+
90+
@Test
91+
public void verifyAdminPortIsSetOnServerConfigs() {
92+
final int ADMIN_PORT = 9002;
93+
List<NetworkAccessPoint> networkAccessPointList = new ArrayList<>();
94+
WlsServerConfig template =
95+
new WlsServerConfig("template1", null, null, null, null, 9002, networkAccessPointList);
96+
97+
WlsServerConfig wlsServerConfig =
98+
WlsDynamicServerConfig.create("server1", 2, "cluster1", "domain1", true, template);
99+
100+
assertThat(wlsServerConfig.getAdminPort(), is(ADMIN_PORT));
101+
}
87102
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at
3+
// http://oss.oracle.com/licenses/upl.
4+
5+
package oracle.kubernetes.operator.wlsconfig;
6+
7+
import static org.hamcrest.CoreMatchers.is;
8+
import static org.junit.Assert.*;
9+
10+
import org.junit.Test;
11+
12+
public class WlsServerConfigTest {
13+
14+
static final int LISTEN_PORT = 8001;
15+
static final int SSL_LISTEN_PORT = 8002;
16+
static final int ADMIN_PORT = 9002;
17+
static final int NAP_ADMIN_PORT = 8082;
18+
static final int NAP_NON_ADMIN_PORT = 8081;
19+
20+
@Test
21+
public void verify_getLocalAdminProtocolChannelPort_returnsListenPort() {
22+
WlsServerConfig wlsServerConfig = createConfigWithOnlyListenPort();
23+
assertThat(wlsServerConfig.getLocalAdminProtocolChannelPort(), is(LISTEN_PORT));
24+
assertThat(wlsServerConfig.isLocalAdminProtocolChannelSecure(), is(false));
25+
}
26+
27+
@Test
28+
public void verify_getLocalAdminProtocolChannelPort_returnsSslListenPort() {
29+
WlsServerConfig wlsServerConfig = createConfigWithListenPortAndSslListenPort();
30+
assertThat(wlsServerConfig.getLocalAdminProtocolChannelPort(), is(SSL_LISTEN_PORT));
31+
assertThat(wlsServerConfig.isLocalAdminProtocolChannelSecure(), is(true));
32+
}
33+
34+
@Test
35+
public void verify_getLocalAdminProtocolChannelPort_returnsAdminPort() {
36+
WlsServerConfig wlsServerConfig = createConfigWithAllListenPorts();
37+
assertThat(wlsServerConfig.getLocalAdminProtocolChannelPort(), is(ADMIN_PORT));
38+
assertThat(wlsServerConfig.isLocalAdminProtocolChannelSecure(), is(true));
39+
}
40+
41+
@Test
42+
public void verify_getLocalAdminProtocolChannelPort_withAdminNAP_returnsNapAdminPort() {
43+
WlsServerConfig wlsServerConfig = createConfigWithAdminNAP();
44+
assertThat(wlsServerConfig.getLocalAdminProtocolChannelPort(), is(NAP_ADMIN_PORT));
45+
assertThat(wlsServerConfig.isLocalAdminProtocolChannelSecure(), is(true));
46+
}
47+
48+
@Test
49+
public void verify_getLocalAdminProtocolChannelPort_withNonAdminNAP_returnsAdminPort() {
50+
WlsServerConfig wlsServerConfig = createConfigWithNonAdminNAP();
51+
assertThat(wlsServerConfig.getLocalAdminProtocolChannelPort(), is(ADMIN_PORT));
52+
assertThat(wlsServerConfig.isLocalAdminProtocolChannelSecure(), is(true));
53+
}
54+
55+
WlsServerConfig createConfigWithOnlyListenPort() {
56+
WlsServerConfig wlsServerConfig = new WlsServerConfig();
57+
wlsServerConfig.setListenPort(LISTEN_PORT);
58+
return wlsServerConfig;
59+
}
60+
61+
WlsServerConfig createConfigWithListenPortAndSslListenPort() {
62+
WlsServerConfig wlsServerConfig = createConfigWithOnlyListenPort();
63+
wlsServerConfig.setSslListenPort(SSL_LISTEN_PORT);
64+
return wlsServerConfig;
65+
}
66+
67+
WlsServerConfig createConfigWithAllListenPorts() {
68+
WlsServerConfig wlsServerConfig = createConfigWithListenPortAndSslListenPort();
69+
wlsServerConfig.setAdminPort(ADMIN_PORT);
70+
return wlsServerConfig;
71+
}
72+
73+
WlsServerConfig createConfigWithAdminNAP() {
74+
WlsServerConfig wlsServerConfig = createConfigWithAllListenPorts();
75+
wlsServerConfig.addNetworkAccessPoint(
76+
new NetworkAccessPoint("admin-channel", "admin", NAP_ADMIN_PORT, null));
77+
return wlsServerConfig;
78+
}
79+
80+
WlsServerConfig createConfigWithNonAdminNAP() {
81+
WlsServerConfig wlsServerConfig = createConfigWithAllListenPorts();
82+
wlsServerConfig.addNetworkAccessPoint(
83+
new NetworkAccessPoint("non-admin-channel", "t3", NAP_NON_ADMIN_PORT, null));
84+
return wlsServerConfig;
85+
}
86+
}

0 commit comments

Comments
 (0)