Skip to content

Commit f2d9e3a

Browse files
committed
Merge remote-tracking branch 'origin/main' into release/4.0
2 parents fc7b595 + 2f5aa53 commit f2d9e3a

File tree

3 files changed

+55
-99
lines changed

3 files changed

+55
-99
lines changed

operator/src/main/java/oracle/kubernetes/operator/steps/HttpRequestProcessing.java

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
import io.kubernetes.client.openapi.models.V1ObjectMeta;
1313
import io.kubernetes.client.openapi.models.V1Pod;
14-
import io.kubernetes.client.openapi.models.V1PodStatus;
1514
import io.kubernetes.client.openapi.models.V1Service;
16-
import io.kubernetes.client.openapi.models.V1ServiceSpec;
1715
import oracle.kubernetes.operator.helpers.AuthorizationSource;
1816
import oracle.kubernetes.operator.helpers.SecretHelper;
1917
import oracle.kubernetes.operator.http.client.HttpAsyncRequestStep;
@@ -76,7 +74,7 @@ String getServiceUrl() {
7674
}
7775

7876
private String getServiceUrl(PortDetails portDetails) {
79-
return Optional.ofNullable(getPortalIP())
77+
return Optional.ofNullable(getHost())
8078
.map(portDetails::toHttpUrl)
8179
.orElse(null);
8280
}
@@ -86,29 +84,12 @@ private String getServiceUrl(PortDetails portDetails) {
8684
*/
8785
abstract PortDetails getPortDetails();
8886

89-
private String getPortalIP() {
90-
return hasClusterIP() ? getClusterIP() : getServerIP();
91-
}
92-
93-
private boolean hasClusterIP() {
94-
return Optional.ofNullable(service.getSpec())
95-
.map(V1ServiceSpec::getClusterIP)
96-
.map(ip -> !ip.equalsIgnoreCase("None"))
97-
.orElse(false);
98-
}
99-
100-
private String getClusterIP() {
101-
return Objects.requireNonNull(service.getSpec()).getClusterIP();
102-
}
103-
104-
private String getServerIP() {
105-
return Optional.ofNullable(pod)
106-
.map(V1Pod::getStatus)
107-
.map(V1PodStatus::getPodIP)
108-
.orElse(toServiceHost(getServiceMeta()));
87+
private String getHost() {
88+
return toServiceHost(getServiceMeta());
10989
}
11090

11191
private String toServiceHost(@Nonnull V1ObjectMeta meta) {
112-
return meta.getName() + "." + meta.getNamespace();
92+
String ns = Optional.ofNullable(meta.getNamespace()).orElse("default");
93+
return meta.getName() + "." + ns;
11394
}
11495
}

operator/src/test/java/oracle/kubernetes/operator/steps/MonitoringExporterStepsTest.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,14 @@ private void expectConfigurationUpdate(String serverName) {
186186
createStub(HttpResponseStub.class, 200, "OK"));
187187
}
188188

189+
@Nonnull
190+
private String getExporterHost(String serverName) {
191+
return DOMAIN_NAME + "-" + serverName + "." + NS;
192+
}
193+
189194
@Nonnull
190195
private String getExporterUrl(String serverName) {
191-
return "http://" + SERVER_NODES.get(serverName) + ":" + EXPORTER_PORT;
196+
return "http://" + getExporterHost(serverName) + ":" + EXPORTER_PORT;
192197
}
193198

194199
@SuppressWarnings("SameParameterValue")
@@ -255,7 +260,8 @@ void whenParallelStepsRun_sendNewConfigurationOnlyIfNeeded() {
255260

256261
testSupport.runSteps(MonitoringExporterSteps.updateExporterSidecars());
257262

258-
assertThat(getServersUpdated(), containsInAnyOrder(POD_NODE1, POD_NODE3));
263+
assertThat(getServersUpdated(), containsInAnyOrder(
264+
getExporterHost(MANAGED_SERVER1), getExporterHost(MANAGED_SERVER3)));
259265
}
260266

261267
@Nonnull
@@ -279,7 +285,8 @@ void skipPodBeingDeleted() {
279285

280286
testSupport.runSteps(MonitoringExporterSteps.updateExporterSidecars());
281287

282-
assertThat(getServersUpdated(), containsInAnyOrder(POD_NODE2, POD_NODE3));
288+
assertThat(getServersUpdated(), containsInAnyOrder(
289+
getExporterHost(MANAGED_SERVER2), getExporterHost(MANAGED_SERVER3)));
283290
}
284291

285292
private void expectQueryAndReturnOldConfiguration(String serverName) {
@@ -304,7 +311,7 @@ void dontUpdatePodWhileNotReady() {
304311

305312
testSupport.runSteps(MonitoringExporterSteps.updateExporterSidecars());
306313

307-
assertThat(getServersUpdated(), containsInAnyOrder(POD_NODE2));
314+
assertThat(getServersUpdated(), containsInAnyOrder(getExporterHost(MANAGED_SERVER2)));
308315
}
309316

310317
@SuppressWarnings("SameParameterValue")
@@ -328,7 +335,8 @@ void updateOncePodsAreReady() {
328335
testSupport.runSteps(MonitoringExporterSteps.updateExporterSidecars());
329336
testSupport.setTime(3, TimeUnit.SECONDS);
330337

331-
assertThat(getServersUpdated(), containsInAnyOrder(POD_NODE1, POD_NODE2, POD_NODE3));
338+
assertThat(getServersUpdated(), containsInAnyOrder(
339+
getExporterHost(MANAGED_SERVER1), getExporterHost(MANAGED_SERVER2), getExporterHost(MANAGED_SERVER3)));
332340
}
333341

334342
@SuppressWarnings("SameParameterValue")

operator/src/test/java/oracle/kubernetes/operator/steps/ReadHealthStepTest.java

Lines changed: 37 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616

1717
import com.meterware.httpunit.Base64;
1818
import com.meterware.simplestub.Memento;
19-
import io.kubernetes.client.openapi.models.V1ObjectMeta;
2019
import io.kubernetes.client.openapi.models.V1Service;
21-
import io.kubernetes.client.openapi.models.V1ServiceSpec;
20+
import io.kubernetes.client.openapi.models.V1ServiceBuilder;
2221
import oracle.kubernetes.operator.DomainProcessorTestSetup;
2322
import oracle.kubernetes.operator.helpers.DomainPresenceInfo;
2423
import oracle.kubernetes.operator.helpers.KubernetesTestSupport;
@@ -76,10 +75,6 @@ class ReadHealthStepTest {
7675
private static final String DYNAMIC_MANAGED_SERVER2 = "dyn-managed-server2";
7776

7877
private static final ClassCastException CLASSCAST_EXCEPTION = new ClassCastException("");
79-
static final String MS1_URL = "http://127.0.0.1:7001";
80-
private final V1Service service = createStub(V1ServiceStub.class);
81-
private final V1Service headlessService = createStub(V1HeadlessServiceStub.class);
82-
private final V1Service headlessMSService = createStub(V1HeadlessMSServiceStub.class);
8378
private final List<LogRecord> logRecords = new ArrayList<>();
8479
private final List<Memento> mementos = new ArrayList<>();
8580
private final KubernetesTestSupport testSupport = new KubernetesTestSupport();
@@ -123,22 +118,15 @@ private int getRemainingServersToRead(Packet packet) {
123118
return ((AtomicInteger) packet.get(REMAINING_SERVERS_HEALTH_TO_READ)).get();
124119
}
125120

126-
private void selectServer(String serverName) {
127-
selectServer(serverName, false);
121+
private V1Service createService(String serverName) {
122+
return new V1ServiceBuilder().withNewMetadata().withName(serverName).withNamespace("Test").endMetadata().build();
128123
}
129124

130-
private void selectServer(String serverName, V1Service service) {
125+
private V1Service selectServer(String serverName) {
126+
V1Service service = createService(serverName);
131127
testSupport.addToPacket(SERVER_NAME, serverName);
132128
info.setServerService(serverName, service);
133-
}
134-
135-
private void selectServer(String serverName, boolean headless) {
136-
testSupport.addToPacket(SERVER_NAME, serverName);
137-
if (headless) {
138-
info.setServerService(serverName, headlessService);
139-
} else {
140-
info.setServerService(serverName, service);
141-
}
129+
return service;
142130
}
143131

144132
@AfterEach
@@ -149,7 +137,7 @@ public void tearDown() {
149137
@Test
150138
void whenReadAdminServerHealth_decrementRemainingServers() {
151139
selectServer(ADMIN_NAME);
152-
defineResponse(200, OK_RESPONSE, "http://127.0.0.1:3456");
140+
defineResponse(200, OK_RESPONSE, "http://" + ADMIN_NAME + ".Test:3456");
153141

154142
Packet packet = testSupport.runSteps(readHealthStep);
155143

@@ -165,9 +153,9 @@ private void defineResponse(int status, String body, @Nonnull String url) {
165153

166154
@Test
167155
void whenReadConfiguredManagedServerHealth_decrementRemainingServers() {
168-
selectServer(CONFIGURED_MANAGED_SERVER1);
169-
configureServiceWithClusterName(CONFIGURED_CLUSTER_NAME);
170-
defineResponse(200, OK_RESPONSE, MS1_URL);
156+
V1Service service = selectServer(CONFIGURED_MANAGED_SERVER1);
157+
configureServiceWithClusterName(CONFIGURED_CLUSTER_NAME, service);
158+
defineResponse(200, OK_RESPONSE, "http://" + CONFIGURED_MANAGED_SERVER1 + ".Test:7001");
171159

172160
Packet packet = testSupport.runSteps(readHealthStep);
173161

@@ -179,9 +167,9 @@ void whenReadConfiguredManagedServerHealth_decrementRemainingServers() {
179167

180168
@Test
181169
void whenReadDynamicManagedServerHealth_decrementRemainingServers() {
182-
selectServer(DYNAMIC_MANAGED_SERVER1);
183-
configureServiceWithClusterName(DYNAMIC_CLUSTER_NAME);
184-
defineResponse(200, OK_RESPONSE, MS1_URL);
170+
V1Service service = selectServer(DYNAMIC_MANAGED_SERVER1);
171+
configureServiceWithClusterName(DYNAMIC_CLUSTER_NAME, service);
172+
defineResponse(200, OK_RESPONSE, "http://" + DYNAMIC_MANAGED_SERVER1 + ".Test:7001");
185173

186174
Packet packet = testSupport.runSteps(readHealthStep);
187175

@@ -192,7 +180,7 @@ void whenReadDynamicManagedServerHealth_decrementRemainingServers() {
192180
void whenServerRunning_verifyServerHealth() {
193181
selectServer(MANAGED_SERVER1);
194182

195-
defineResponse(200, OK_RESPONSE, "http://127.0.0.1:8001");
183+
defineResponse(200, OK_RESPONSE, "http://" + MANAGED_SERVER1 + ".Test:8001");
196184

197185
Packet packet = testSupport.runSteps(readHealthStep);
198186

@@ -210,7 +198,7 @@ private Map<String, String> getServerStateMap(Packet packet) {
210198

211199
@Test
212200
void whenAdminPodIPNull_verifyServerHealth() {
213-
selectServer(ADMIN_NAME, true);
201+
selectServer(ADMIN_NAME);
214202
defineResponse(200, OK_RESPONSE, "http://admin-server.Test:3456");
215203

216204
Packet packet = testSupport.runSteps(readHealthStep);
@@ -220,7 +208,7 @@ void whenAdminPodIPNull_verifyServerHealth() {
220208

221209
@Test
222210
void whenAdminPodIPNull_requestSendWithCredentials() {
223-
selectServer(ADMIN_NAME, true);
211+
selectServer(ADMIN_NAME);
224212
defineResponse(200, OK_RESPONSE, "http://admin-server.Test:3456");
225213

226214
testSupport.runSteps(readHealthStep);
@@ -244,7 +232,7 @@ private String expectedAuthorizationHeader() {
244232
void whenServerOverloaded_verifyServerHealth() {
245233
selectServer(MANAGED_SERVER1);
246234

247-
defineResponse(500, "", "http://127.0.0.1:8001");
235+
defineResponse(500, "", "http://" + MANAGED_SERVER1 + ".Test:8001");
248236

249237
Packet packet = testSupport.runSteps(readHealthStep);
250238

@@ -257,7 +245,7 @@ void whenServerOverloaded_verifyServerHealth() {
257245
void whenUnableToReadHealth_verifyNotAvailable() {
258246
selectServer(MANAGED_SERVER1);
259247

260-
defineResponse(404, "", MS1_URL);
248+
defineResponse(404, "", "http://" + MANAGED_SERVER1 + ".Test:8001");
261249

262250
Packet packet = testSupport.runSteps(readHealthStep);
263251

@@ -268,7 +256,8 @@ void whenUnableToReadHealth_verifyNotAvailable() {
268256

269257
@Test
270258
void whenServerConfiguredWithServerListenPortOnly_readHealthUsingServerListenPort() {
271-
selectServer(DYNAMIC_MANAGED_SERVER2, headlessMSService);
259+
V1Service service = selectServer(DYNAMIC_MANAGED_SERVER2);
260+
configureServiceWithClusterName(DYNAMIC_CLUSTER_NAME, service);
272261
WlsServerConfig server = getDynamicClusterServer2();
273262
server.setListenPort(8001);
274263
defineExpectedURLInResponse("http", 8001);
@@ -280,7 +269,8 @@ void whenServerConfiguredWithServerListenPortOnly_readHealthUsingServerListenPor
280269

281270
@Test
282271
void whenServerConfiguredWithSSLPortOnly_readHealthUsingSSLPort() {
283-
selectServer(DYNAMIC_MANAGED_SERVER2, headlessMSService);
272+
V1Service service = selectServer(DYNAMIC_MANAGED_SERVER2);
273+
configureServiceWithClusterName(DYNAMIC_CLUSTER_NAME, service);
284274
WlsServerConfig server = getDynamicClusterServer2();
285275
server.setSslListenPort(7002);
286276
defineExpectedURLInResponse("https", 7002);
@@ -292,7 +282,8 @@ void whenServerConfiguredWithSSLPortOnly_readHealthUsingSSLPort() {
292282

293283
@Test
294284
void whenServerConfiguredWithServerListenPortAndSSLPort_readHealthUsingSSLPort() {
295-
selectServer(DYNAMIC_MANAGED_SERVER2, headlessMSService);
285+
V1Service service = selectServer(DYNAMIC_MANAGED_SERVER2);
286+
configureServiceWithClusterName(DYNAMIC_CLUSTER_NAME, service);
296287
WlsServerConfig server = getDynamicClusterServer2();
297288
server.setListenPort(8001);
298289
server.setSslListenPort(7002);
@@ -305,7 +296,8 @@ void whenServerConfiguredWithServerListenPortAndSSLPort_readHealthUsingSSLPort()
305296

306297
@Test
307298
void whenServerConfiguredWithServerListenPortAndNonAdminNAP_readHealthUsingServerListenPort() {
308-
selectServer(DYNAMIC_MANAGED_SERVER2, headlessMSService);
299+
V1Service service = selectServer(DYNAMIC_MANAGED_SERVER2);
300+
configureServiceWithClusterName(DYNAMIC_CLUSTER_NAME, service);
309301
WlsServerConfig server = getDynamicClusterServer2();
310302
server.setListenPort(8001);
311303
server.addNetworkAccessPoint(new NetworkAccessPoint("nap1", "t3", 9001, 9001));
@@ -318,7 +310,8 @@ void whenServerConfiguredWithServerListenPortAndNonAdminNAP_readHealthUsingServe
318310

319311
@Test
320312
void whenServerConfiguredWithServerSSLPortAndNonAdminNAP_readHealthUsingSSLPort() {
321-
selectServer(DYNAMIC_MANAGED_SERVER2, headlessMSService);
313+
V1Service service = selectServer(DYNAMIC_MANAGED_SERVER2);
314+
configureServiceWithClusterName(DYNAMIC_CLUSTER_NAME, service);
322315
WlsServerConfig server = getDynamicClusterServer2();
323316
server.setSslListenPort(7002);
324317
server.addNetworkAccessPoint(new NetworkAccessPoint("nap1", "t3", 9001, 9001));
@@ -331,7 +324,8 @@ void whenServerConfiguredWithServerSSLPortAndNonAdminNAP_readHealthUsingSSLPort(
331324

332325
@Test
333326
void whenServerConfiguredWithSSLPortAndAdminNAP_readHealthUsingAdminNAPPort() {
334-
selectServer(DYNAMIC_MANAGED_SERVER2, headlessMSService);
327+
V1Service service = selectServer(DYNAMIC_MANAGED_SERVER2);
328+
configureServiceWithClusterName(DYNAMIC_CLUSTER_NAME, service);
335329
WlsServerConfig server = getDynamicClusterServer2();
336330
server.setSslListenPort(7002);
337331
server.addNetworkAccessPoint(new NetworkAccessPoint("admin", "admin", 8888, 8888));
@@ -344,7 +338,8 @@ void whenServerConfiguredWithSSLPortAndAdminNAP_readHealthUsingAdminNAPPort() {
344338

345339
@Test
346340
void whenServerConfiguredWithServerListenPortAndAdminNAP_readHealthUsingAdminNAPPort() {
347-
selectServer(DYNAMIC_MANAGED_SERVER2, headlessMSService);
341+
V1Service service = selectServer(DYNAMIC_MANAGED_SERVER2);
342+
configureServiceWithClusterName(DYNAMIC_CLUSTER_NAME, service);
348343
WlsServerConfig server = getDynamicClusterServer2();
349344
server.setListenPort(8001);
350345
server.setListenPort(null);
@@ -358,7 +353,8 @@ void whenServerConfiguredWithServerListenPortAndAdminNAP_readHealthUsingAdminNAP
358353

359354
@Test
360355
void whenServerConfiguredWithNonAdminNAPOnly_readHealthFailed() {
361-
selectServer(DYNAMIC_MANAGED_SERVER2, headlessMSService);
356+
V1Service service = selectServer(DYNAMIC_MANAGED_SERVER2);
357+
configureServiceWithClusterName(DYNAMIC_CLUSTER_NAME, service);
362358
WlsServerConfig server = getDynamicClusterServer2();
363359
server.addNetworkAccessPoint(new NetworkAccessPoint("nap1", "t3", 9001, 9001));
364360
defineExpectedURLInResponse("http", 9001);
@@ -398,7 +394,7 @@ void whenAuthorizedToReadHealthAndThenWait_verifySecretCleared() {
398394
void whenNotAuthorizedToReadHealth_verifySecretCleared() {
399395
selectServer(MANAGED_SERVER1);
400396

401-
defineResponse(403, "", "http://127.0.0.1:8001");
397+
defineResponse(403, "", "http://" + MANAGED_SERVER1 + ".Test:8001");
402398

403399
testSupport.runSteps(readHealthStep);
404400

@@ -418,37 +414,8 @@ private WlsServerConfig getDynamicClusterServer2() {
418414
return wlsDomainConfig.getClusterConfig(DYNAMIC_CLUSTER_NAME).getServerConfigs().get(1);
419415
}
420416

421-
public abstract static class V1ServiceStub extends V1Service {
422-
423-
@Override
424-
public V1ServiceSpec getSpec() {
425-
return new V1ServiceSpec().clusterIP("127.0.0.1");
426-
}
427-
}
428-
429-
public abstract static class V1HeadlessServiceStub extends V1Service {
430-
431-
@Override
432-
public V1ObjectMeta getMetadata() {
433-
return new V1ObjectMeta().name(ADMIN_NAME).namespace("Test");
434-
}
435-
436-
@Override
437-
public V1ServiceSpec getSpec() {
438-
return new V1ServiceSpec().clusterIP("None");
439-
}
440-
}
441-
442-
public abstract static class V1HeadlessMSServiceStub extends V1Service {
443-
@Override
444-
public V1ObjectMeta getMetadata() {
445-
return new V1ObjectMeta().name(DYNAMIC_MANAGED_SERVER2).namespace("Test")
446-
.putLabelsItem(CLUSTERNAME_LABEL, DYNAMIC_CLUSTER_NAME);
447-
}
448-
}
449-
450-
private void configureServiceWithClusterName(String clusterName) {
451-
service.setMetadata(new V1ObjectMeta().putLabelsItem(CLUSTERNAME_LABEL, clusterName));
417+
private void configureServiceWithClusterName(String clusterName, V1Service service) {
418+
service.getMetadata().putLabelsItem(CLUSTERNAME_LABEL, clusterName);
452419
}
453420

454421
}

0 commit comments

Comments
 (0)