Skip to content

Commit 9c0d3ca

Browse files
committed
Merge remote-tracking branch 'origin/main' into release/4.0
2 parents 0ea8bd8 + e38912f commit 9c0d3ca

File tree

18 files changed

+346
-55
lines changed

18 files changed

+346
-55
lines changed

common/src/main/java/oracle/kubernetes/common/utils/SchemaConversionUtils.java

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ public class SchemaConversionUtils {
4949
private static final String CLUSTERS = "clusters";
5050
private static final String CLUSTER_NAME = "clusterName";
5151
private static final String ACPFE = "adminChannelPortForwardingEnabled";
52-
private static final String PRESERVED = "weblogic.v8.preserved";
52+
private static final String LHL = "logHomeLayout";
53+
private static final String PRESERVED_V9 = "weblogic.v9.preserved";
54+
private static final String PRESERVED_V8 = "weblogic.v8.preserved";
5355
private static final String PRESERVED_AUX = "weblogic.v8.preserved.aux";
5456
private static final String ADDED_ACPFE = "weblogic.v8.adminChannelPortForwardingEnabled";
5557
private static final String FAILED_REASON = "weblogic.v8.failed.reason";
@@ -134,24 +136,36 @@ public Resources convertDomainSchema(Map<String, Object> domain, ResourceLookup
134136
convertDomainStatusTargetV8(domain);
135137
constantsToCamelCase(spec);
136138

137-
restore(PRESERVED, domain);
139+
try {
140+
Map<String, Object> toBePreserved = new TreeMap<>();
141+
removeAndPreserveLogHomeLayout(spec, toBePreserved);
142+
143+
preserveV9(PRESERVED_V9, domain, toBePreserved, apiVersion);
144+
} catch (IOException io) {
145+
throw new RuntimeException(io); // need to use unchecked exception because of stream processing
146+
}
147+
148+
restore(PRESERVED_V8, domain);
138149
restore(PRESERVED_AUX, domain, this::validateRestoreLegacyAuxilaryImages);
139150
removeAddedAdminChannelPortForwardingEnabled(domain);
140151
} else {
152+
restore(PRESERVED_V9, domain);
153+
141154
adjustAdminPortForwardingDefault(domain, spec, apiVersion);
142155
convertDomainStatusTargetV9(domain);
143156
convertDomainHomeInImageToDomainHomeSourceType(domain);
144157
moveConfigOverrides(domain);
145158
moveConfigOverrideSecrets(domain);
146159
constantsToCamelCase(spec);
147160
adjustReplicasDefault(spec, apiVersion);
161+
adjustLogHomeLayoutDefault(spec, apiVersion);
148162
removeWebLogicCredentialsSecretNamespace(spec, apiVersion);
149163

150164
try {
151165
Map<String, Object> toBePreserved = new TreeMap<>();
152166
removeAndPreserveLegacyAuxiliaryImages(spec, toBePreserved);
153167

154-
preserve(PRESERVED_AUX, domain, toBePreserved, apiVersion);
168+
preserveV8(PRESERVED_AUX, domain, toBePreserved, apiVersion);
155169
} catch (IOException io) {
156170
throw new RuntimeException(io); // need to use unchecked exception because of stream processing
157171
}
@@ -163,7 +177,7 @@ public Resources convertDomainSchema(Map<String, Object> domain, ResourceLookup
163177
removeAndPreserveServerStartState(spec, toBePreserved);
164178
removeAndPreserveIstio(spec, toBePreserved);
165179

166-
preserve(PRESERVED, domain, toBePreserved, apiVersion);
180+
preserveV8(PRESERVED_V8, domain, toBePreserved, apiVersion);
167181
} catch (IOException io) {
168182
throw new RuntimeException(io); // need to use unchecked exception because of stream processing
169183
}
@@ -456,8 +470,6 @@ private void constantsToCamelCase(Map<String, Object> spec) {
456470
convertServerStartPolicy((Map<String, Object>) managedServer)));
457471

458472
Optional.ofNullable(getConfiguration(spec)).ifPresent(this::convertOverrideDistributionStrategy);
459-
460-
convertLogHomeLayout(spec);
461473
}
462474

463475
private void convertServerStartPolicy(Map<String, Object> spec) {
@@ -509,19 +521,6 @@ private Object overrideDistributionStrategyCamelCase(String key, Object value) {
509521
return convertWithMap(select(overrideDistributionStrategyMap, invertOverrideDistributionStrategyMap), value);
510522
}
511523

512-
private void convertLogHomeLayout(Map<String, Object> configuration) {
513-
configuration.computeIfPresent("logHomeLayout", this::logHomeLayoutCamelCase);
514-
}
515-
516-
private static final Map<String, String> logHomeLayoutMap = Map.of(
517-
"FLAT", "Flat", "BY_SERVERS", "ByServers");
518-
519-
private static final Map<String, String> invertLogHomeLayoutMap = invertMapUsingMapper(logHomeLayoutMap);
520-
521-
private Object logHomeLayoutCamelCase(String key, Object value) {
522-
return convertWithMap(select(logHomeLayoutMap, invertLogHomeLayoutMap), value);
523-
}
524-
525524
private Map<String, Object> getConfiguration(Map<String, Object> spec) {
526525
return (Map<String, Object>) spec.get("configuration");
527526
}
@@ -768,6 +767,19 @@ private void adjustReplicasDefault(Map<String, Object> spec, String apiVersion)
768767
}
769768
}
770769

770+
private void adjustLogHomeLayoutDefault(Map<String, Object> spec, String apiVersion) {
771+
if (CommonConstants.API_VERSION_V8.equals(apiVersion)) {
772+
spec.putIfAbsent(LHL, "Flat");
773+
}
774+
}
775+
776+
private void removeAndPreserveLogHomeLayout(Map<String, Object> spec, Map<String, Object> toBePreserved) {
777+
Object existing = Optional.ofNullable(spec.remove(LHL)).orElse("ByServers");
778+
if (!"Flat".equals(existing)) {
779+
preserve(toBePreserved, "$.spec", Map.of(LHL, existing));
780+
}
781+
}
782+
771783
private void removeAndPreserveIstio(Map<String, Object> spec, Map<String, Object> toBePreserved) {
772784
Optional.ofNullable(getConfiguration(spec)).ifPresent(configuration -> {
773785
Object existing = configuration.remove("istio");
@@ -854,16 +866,27 @@ private void preserve(Map<String, Object> toBePreserved, String key, Map<String,
854866
}
855867

856868
private void preserve(String annoName, Map<String, Object> domain,
857-
Map<String, Object> toBePreserved, String apiVersion)
869+
Map<String, Object> toBePreserved, String apiVersion, boolean targetV8)
858870
throws IOException {
859-
if (!toBePreserved.isEmpty() && API_VERSION_V8.equals(apiVersion)) {
871+
if (!toBePreserved.isEmpty() && (API_VERSION_V8.equals(apiVersion) == targetV8)) {
860872
Map<String, Object> meta = getMetadata(domain);
861873
Map<String, Object> annotations = (Map<String, Object>) meta.computeIfAbsent(
862874
ANNOTATIONS, k -> new LinkedHashMap<>());
863875
annotations.put(annoName, new ObjectMapper().writeValueAsString(toBePreserved));
864876
}
865877
}
866878

879+
private void preserveV8(String annoName, Map<String, Object> domain,
880+
Map<String, Object> toBePreserved, String apiVersion) throws IOException {
881+
preserve(annoName, domain, toBePreserved, apiVersion, true);
882+
}
883+
884+
private void preserveV9(String annoName, Map<String, Object> domain,
885+
Map<String, Object> toBePreserved, String apiVersion)
886+
throws IOException {
887+
preserve(annoName, domain, toBePreserved, apiVersion, false);
888+
}
889+
867890
private void removeAddedAdminChannelPortForwardingEnabled(Map<String, Object> domain) {
868891
withAnnotation(ADDED_ACPFE, domain, labelValue -> {
869892
if ("true".equals(labelValue)) {

common/src/test/java/oracle/kubernetes/common/utils/SchemaConversionUtilsTest.java

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,59 @@ void testV8DomainWithOverrideDistributionStrategy_changeToCamelCase() {
467467
}
468468

469469
@Test
470-
void testV8DomainWithLogHomeLayout_changeToCamelCase() {
471-
getMapAtPath(v8Domain, "spec").put("logHomeLayout", "BY_SERVERS");
470+
void testV8Domain_addLogHomeLayout() {
471+
converter.convert(v8Domain);
472+
473+
assertThat(converter.getDomain(),
474+
hasJsonPath("$.spec.logHomeLayout", equalTo("Flat")));
475+
}
472476

477+
@Test
478+
void testV8DomainWithPreservedLogHomeLayout_restoreLogHomeLayout() {
479+
Map<String, Object> annotations = new HashMap<>();
480+
getMapAtPath(v8Domain, "metadata").put("annotations", annotations);
481+
annotations.put("weblogic.v9.preserved", "{\"$.spec\":{\"logHomeLayout\":\"ByServers\"}}");
473482
converter.convert(v8Domain);
474483

475484
assertThat(converter.getDomain(),
476-
hasJsonPath("$.spec.logHomeLayout", equalTo("ByServers")));
485+
hasJsonPath("$.spec.logHomeLayout", equalTo("ByServers")));
486+
}
487+
488+
@Test
489+
void testV9DomainWithLogHomeLayoutFlat_dropIt() throws IOException {
490+
Map<String, Object> v9Domain = readAsYaml(DOMAIN_V9_CONVERTED_LEGACY_AUX_IMAGE_YAML);
491+
getMapAtPath(v9Domain, "spec")
492+
.put("logHomeLayout", "Flat");
493+
494+
converterv8.convert(v9Domain);
495+
496+
assertThat(converterv8.getDomain(), hasNoJsonPath("$.metadata.annotations.['weblogic.v9.preserved']"));
497+
}
498+
499+
@Test
500+
void testV9DomainWithLogHomeLayoutByServers_preserveIt() throws IOException {
501+
Map<String, Object> v9Domain = readAsYaml(DOMAIN_V9_CONVERTED_LEGACY_AUX_IMAGE_YAML);
502+
getMapAtPath(v9Domain, "spec")
503+
.put("logHomeLayout", "ByServers");
504+
505+
converterv8.convert(v9Domain);
506+
507+
assertThat(converterv8.getDomain(), hasNoJsonPath("$.spec.logHomeLayout"));
508+
assertThat(converterv8.getDomain(), hasJsonPath("$.metadata.annotations.['weblogic.v9.preserved']",
509+
equalTo("{\"$.spec\":{\"logHomeLayout\":\"ByServers\"}}")));
510+
}
511+
512+
@Test
513+
void testV9DomainWithNoLogHomeLayout_preserveItAsByServers() throws IOException {
514+
Map<String, Object> v9Domain = readAsYaml(DOMAIN_V9_CONVERTED_LEGACY_AUX_IMAGE_YAML);
515+
getMapAtPath(v9Domain, "spec")
516+
.remove("logHomeLayout");
517+
518+
converterv8.convert(v9Domain);
519+
520+
assertThat(converterv8.getDomain(), hasNoJsonPath("$.spec.logHomeLayout"));
521+
assertThat(converterv8.getDomain(), hasJsonPath("$.metadata.annotations.['weblogic.v9.preserved']",
522+
equalTo("{\"$.spec\":{\"logHomeLayout\":\"ByServers\"}}")));
477523
}
478524

479525
@Test

common/src/test/resources/oracle/kubernetes/common/utils/converted-domain-sample-2.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ spec:
7575
modelHome: /auxiliary/models
7676
wdtInstallHome: /auxiliary/weblogic-deploy
7777
runtimeEncryptionSecret: sample-domain1-runtime-encryption-secret
78+
logHomeLayout: Flat
7879
clusters:
7980
- name: sample-domain1-cluster-1
8081

common/src/test/resources/oracle/kubernetes/common/utils/converted-domain-sample.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ spec:
7373
modelHome: /auxiliary/models
7474
wdtInstallHome: /auxiliary/weblogic-deploy
7575
runtimeEncryptionSecret: sample-domain1-runtime-encryption-secret
76+
logHomeLayout: Flat
7677
clusters:
7778
- name: sample-domain1-cluster-1
7879

deployment/scripts/operator.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,7 @@ HEAP="-XshowSettings:vm"
7070
java $HEAP $MOCKING_WLS $DEBUG $LOGGING -jar /operator/weblogic-kubernetes-operator.jar &
7171
PID=$!
7272
wait $PID
73+
74+
SHUTDOWN_COMPLETE_MARKER_FILE="${DEPLOYMENT_DIR}/marker.shutdown-complete"
75+
76+
touch ${SHUTDOWN_COMPLETE_MARKER_FILE}

deployment/scripts/stop.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
# Copyright (c) 2022, Oracle and/or its affiliates.
3+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
5+
echo "Setting stop signal"
6+
7+
DEPLOYMENT_DIR="/deployment"
8+
SHUTDOWN_MARKER_FILE="${DEPLOYMENT_DIR}/marker.shutdown"
9+
SHUTDOWN_COMPLETE_MARKER_FILE="${DEPLOYMENT_DIR}/marker.shutdown-complete"
10+
11+
touch ${SHUTDOWN_MARKER_FILE}
12+
13+
while true; do
14+
if [ -e ${SHUTDOWN_COMPLETE_MARKER_FILE} ] ; then
15+
exit 0
16+
fi
17+
sleep 1
18+
done

deployment/scripts/webhook.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,8 @@ HEAP="-XshowSettings:vm"
6363
java -cp /operator/weblogic-kubernetes-operator.jar $HEAP $MOCKING_WLS $DEBUG $LOGGING oracle.kubernetes.operator.WebhookMain &
6464
PID=$!
6565
wait $PID
66+
67+
DEPLOYMENT_DIR="/deployment"
68+
SHUTDOWN_COMPLETE_MARKER_FILE="${DEPLOYMENT_DIR}/marker.shutdown-complete"
69+
70+
touch ${SHUTDOWN_COMPLETE_MARKER_FILE}

kubernetes/charts/weblogic-operator/templates/_operator-clusterrole-general.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ rules:
3838
verbs: ["create"]
3939
- apiGroups: ["admissionregistration.k8s.io"]
4040
resources: ["validatingwebhookconfigurations"]
41-
verbs: ["get", "create", "update", "patch"]
41+
verbs: ["get", "create", "update", "patch", "delete"]
4242
{{- end }}

kubernetes/charts/weblogic-operator/templates/_operator-dep.tpl

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ spec:
5454
- name: "weblogic-operator"
5555
image: {{ .image | quote }}
5656
imagePullPolicy: {{ .imagePullPolicy | quote }}
57-
command: ["bash"]
58-
args: ["/deployment/operator.sh"]
57+
command: ["/deployment/operator.sh"]
58+
lifecycle:
59+
preStop:
60+
exec:
61+
command: ["/deployment/stop.sh"]
5962
env:
6063
- name: "OPERATOR_NAMESPACE"
6164
valueFrom:
@@ -131,17 +134,13 @@ spec:
131134
{{- if not .remoteDebugNodePortEnabled }}
132135
livenessProbe:
133136
exec:
134-
command:
135-
- "bash"
136-
- "/probes/livenessProbe.sh"
137+
command: ["/probes/livenessProbe.sh"]
137138
initialDelaySeconds: 40
138139
periodSeconds: 10
139140
failureThreshold: 5
140141
readinessProbe:
141142
exec:
142-
command:
143-
- "bash"
144-
- "/probes/readinessProbe.sh"
143+
command: ["/probes/readinessProbe.sh"]
145144
initialDelaySeconds: 2
146145
periodSeconds: 10
147146
{{- end }}
@@ -276,8 +275,11 @@ spec:
276275
- name: "weblogic-operator-webhook"
277276
image: {{ .image | quote }}
278277
imagePullPolicy: {{ .imagePullPolicy | quote }}
279-
command: ["bash"]
280-
args: ["/deployment/webhook.sh"]
278+
command: ["/deployment/webhook.sh"]
279+
lifecycle:
280+
preStop:
281+
exec:
282+
command: ["/deployment/stop.sh"]
281283
env:
282284
- name: "WEBHOOK_NAMESPACE"
283285
valueFrom:
@@ -341,16 +343,12 @@ spec:
341343
{{- if not .remoteDebugNodePortEnabled }}
342344
livenessProbe:
343345
exec:
344-
command:
345-
- "bash"
346-
- "/probes/livenessProbe.sh"
346+
command: ["/probes/livenessProbe.sh"]
347347
initialDelaySeconds: 40
348348
periodSeconds: 5
349349
readinessProbe:
350350
exec:
351-
command:
352-
- "bash"
353-
- "/probes/readinessProbe.sh"
351+
command: ["/probes/readinessProbe.sh"]
354352
initialDelaySeconds: 2
355353
periodSeconds: 10
356354
{{- end }}

kubernetes/charts/weblogic-operator/templates/_operator-role.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2021, Oracle and/or its affiliates.
1+
# Copyright (c) 2018, 2022, Oracle and/or its affiliates.
22
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
{{- define "operator.operatorRole" }}
@@ -16,5 +16,5 @@ rules:
1616
verbs: ["get", "list", "watch", "create", "update", "patch", "delete", "deletecollection"]
1717
- apiGroups: ["admissionregistration.k8s.io"]
1818
resources: ["validatingwebhookconfigurations"]
19-
verbs: ["get", "create", "update", "patch"]
19+
verbs: ["get", "create", "update", "patch", "delete"]
2020
{{- end }}

kubernetes/src/test/java/oracle/kubernetes/operator/create/CreateOperatorGeneratedFilesTestBase.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
import io.kubernetes.client.openapi.models.V1Deployment;
1414
import io.kubernetes.client.openapi.models.V1DeploymentStrategy;
1515
import io.kubernetes.client.openapi.models.V1EnvVarSource;
16+
import io.kubernetes.client.openapi.models.V1ExecAction;
1617
import io.kubernetes.client.openapi.models.V1LabelSelector;
18+
import io.kubernetes.client.openapi.models.V1Lifecycle;
19+
import io.kubernetes.client.openapi.models.V1LifecycleHandler;
1720
import io.kubernetes.client.openapi.models.V1Namespace;
1821
import io.kubernetes.client.openapi.models.V1PolicyRule;
1922
import io.kubernetes.client.openapi.models.V1Probe;
@@ -218,8 +221,10 @@ protected V1Deployment getExpectedWeblogicOperatorDeployment() {
218221
.image(getInputs().getWeblogicOperatorImage())
219222
.imagePullPolicy(
220223
getInputs().getWeblogicOperatorImagePullPolicy())
221-
.addCommandItem("bash")
222-
.addArgsItem("/deployment/operator.sh")
224+
.addCommandItem("/deployment/operator.sh")
225+
.lifecycle(
226+
new V1Lifecycle().preStop(new V1LifecycleHandler().exec(
227+
new V1ExecAction().addCommandItem("/deployment/stop.sh"))))
223228
.addEnvItem(
224229
newEnvVar()
225230
.name("OPERATOR_NAMESPACE")
@@ -305,7 +310,7 @@ private V1Probe createProbe(Integer initialDelaySeconds, Integer periodSeconds,
305310
.initialDelaySeconds(initialDelaySeconds)
306311
.periodSeconds(periodSeconds)
307312
.failureThreshold(failureThreshold)
308-
.exec(newExecAction().addCommandItem("bash").addCommandItem(shellScript));
313+
.exec(newExecAction().addCommandItem(shellScript));
309314
}
310315

311316
@Test
@@ -758,7 +763,8 @@ private V1PolicyRule newPolicyRuleForValidatingWebhookConfiguration() {
758763
"get",
759764
"create",
760765
"update",
761-
"patch"));
766+
"patch",
767+
"delete"));
762768
}
763769

764770
@Test

0 commit comments

Comments
 (0)