Skip to content

Commit f657aca

Browse files
committed
Merge remote-tracking branch 'origin/main' into release/4.0
2 parents 8d77f1a + 3f86211 commit f657aca

File tree

241 files changed

+2897
-1889
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

241 files changed

+2897
-1889
lines changed

buildDockerImage.sh

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

55
usage() {
@@ -11,7 +11,7 @@ Builds a container image for the Oracle WebLogic Kubernetes Operator.
1111
Parameters:
1212
-t: image name and tag in 'name:tag' format
1313
14-
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
14+
Copyright (c) 2020, 2022, Oracle and/or its affiliates.
1515
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
1616
1717
EOF
@@ -65,7 +65,7 @@ echo "Building image '$IMAGE_NAME' ..."
6565

6666
# BUILD THE IMAGE (replace all environment variables)
6767
BUILD_START=$(date '+%s')
68-
docker build $PROXY_SETTINGS -t $IMAGE_NAME -f $SCRIPTPATH/Dockerfile $SCRIPTPATH || {
68+
${WLSIMG_BUILDER:-docker} build $PROXY_SETTINGS -t $IMAGE_NAME -f $SCRIPTPATH/Dockerfile $SCRIPTPATH || {
6969
echo "There was an error building the image."
7070
exit 1
7171
}
@@ -76,13 +76,13 @@ echo ""
7676

7777
if [ $? -eq 0 ]; then
7878
cat << EOF
79-
WebLogic Kubernetes Operator Docker Image is ready:
79+
WebLogic Kubernetes Operator Image is ready:
8080
8181
--> $IMAGE_NAME
8282
8383
Build completed in $BUILD_ELAPSED seconds.
8484
8585
EOF
8686
else
87-
echo "WebLogic Kubernetes Operator container image was NOT successfully created. Check the output and correct any reported problems with the docker build operation."
88-
fi
87+
echo "WebLogic Kubernetes Operator container image was NOT successfully created. Check the output and correct any reported problems with the ${WLSIMG_BUILDER:-docker} build operation."
88+
fi

common/src/main/java/oracle/kubernetes/common/AuxiliaryImageConstants.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ private AuxiliaryImageConstants() {
1010
}
1111

1212
public static final String AUXILIARY_IMAGE_TARGET_PATH = "/tmpAuxiliaryImage";
13-
public static final String AUXILIARY_IMAGE_VOLUME_NAME_PREFIX = "aux-image-volume-";
13+
public static final String AUXILIARY_IMAGE_VOLUME_NAME_PREFIX = "ai-vol-";
14+
public static final String AUXILIARY_IMAGE_VOLUME_NAME_OLD_PREFIX = "aux-image-volume-";
1415
public static final String AUXILIARY_IMAGE_INIT_CONTAINER_WRAPPER_SCRIPT = "/weblogic-operator/scripts/auxImage.sh";
1516
public static final String AUXILIARY_IMAGE_INIT_CONTAINER_NAME_PREFIX = "operator-aux-container";
1617
public static final String AUXILIARY_IMAGE_DEFAULT_INIT_CONTAINER_COMMAND

common/src/main/java/oracle/kubernetes/common/CommonConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ private CommonConstants() {
99
//not called
1010
}
1111

12-
public static final String COMPATIBILITY_MODE = "compatibility-mode-";
12+
public static final String COMPATIBILITY_MODE = "compat-";
1313
public static final String API_VERSION_V9 = "weblogic.oracle/v9";
1414
public static final String API_VERSION_V8 = "weblogic.oracle/v8";
1515

common/src/main/java/oracle/kubernetes/common/logging/MessageKeys.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public class MessageKeys {
167167
public static final String WATCH_CLUSTER_DELETED = "WLSKO-0229";
168168
public static final String CLUSTER_STATUS = "WLSKO-0230";
169169
public static final String DOMAIN_INTROSPECTION_INCOMPLETE = "WLSKO-0231";
170+
public static final String WATCH_CLUSTER_WITHOUT_DOMAIN = "WLSKO-0232";
170171

171172
// domain status messages
172173
public static final String MAKE_RIGHT_WILL_RETRY = "WLSDO-0000";

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,20 @@
33

44
package oracle.kubernetes.common.utils;
55

6+
import java.nio.charset.StandardCharsets;
7+
import java.security.MessageDigest;
8+
import java.security.NoSuchAlgorithmException;
9+
import java.util.Optional;
10+
611
import oracle.kubernetes.common.CommonConstants;
712

813
public class CommonUtils {
914

15+
private static CheckedFunction<String, String> getMD5Hash = CommonUtils::getMD5Hash;
16+
17+
public static final int MAX_ALLOWED_VOLUME_NAME_LENGTH = 63;
18+
public static final String VOLUME_NAME_SUFFIX = "-volume";
19+
1020
private CommonUtils() {
1121
//not called
1222
}
@@ -33,4 +43,45 @@ public static String toDns1123LegalName(String value) {
3343
return value.toLowerCase().replace('_', '-');
3444
}
3545

46+
/**
47+
* Returns a truncated volume name if the name exceeds the max allowed limit of characters for volume name.
48+
* @param volumeName volume name
49+
* @return truncated volume name if the name exceeds the limit, else return volumeName
50+
* @throws NoSuchAlgorithmException Thrown when particular cryptographic algorithm
51+
* is not available in the environment.
52+
*/
53+
public static String getLegalVolumeName(String volumeName) throws NoSuchAlgorithmException {
54+
return volumeName.length() > (MAX_ALLOWED_VOLUME_NAME_LENGTH)
55+
? getShortName(volumeName)
56+
: volumeName;
57+
}
58+
59+
60+
private static String getShortName(String resourceName) throws NoSuchAlgorithmException {
61+
String volumeSuffix = Optional.ofNullable(getMD5Hash.apply(resourceName)).orElse("");
62+
return resourceName.substring(0, MAX_ALLOWED_VOLUME_NAME_LENGTH - volumeSuffix.length()) + volumeSuffix;
63+
}
64+
65+
/**
66+
* Gets the MD5 hash of a string.
67+
*
68+
* @param data input string
69+
* @return MD5 hash value of the data, null in case of an exception.
70+
*/
71+
public static String getMD5Hash(String data) throws NoSuchAlgorithmException {
72+
return bytesToHex(MessageDigest.getInstance("MD5").digest(data.getBytes(StandardCharsets.UTF_8)));
73+
}
74+
75+
private static String bytesToHex(byte[] hash) {
76+
StringBuilder result = new StringBuilder();
77+
for (byte b : hash) {
78+
result.append(String.format("%02x", b));
79+
}
80+
return result.toString();
81+
}
82+
83+
@FunctionalInterface
84+
public interface CheckedFunction<T, R> {
85+
R apply(T t) throws NoSuchAlgorithmException;
86+
}
3687
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public class SchemaConversionUtils {
5959
private static final String DOLLAR_SPEC_AS_SERVERPOD = "$.spec.adminServer.serverPod";
6060

6161
public static final String INTERNAL = "Internal";
62+
6263
/**
6364
* The list of failure reason strings. Hard-coded here to match the values in DomainFailureReason.
6465
* Validated in tests in the operator.
@@ -683,7 +684,15 @@ private boolean hasMatchingVolumeMountName(Object volumeMount, Map<String, Objec
683684
return getDNS1123auxiliaryImageVolumeName(auxiliaryImage.get(VOLUME)).equals(((Map)volumeMount).get("name"));
684685
}
685686

686-
public static String getDNS1123auxiliaryImageVolumeName(Object name) {
687+
private static String getDNS1123auxiliaryImageVolumeName(Object name) {
688+
try {
689+
return CommonUtils.getLegalVolumeName(getVolumeName(name));
690+
} catch (Exception ex) {
691+
return getVolumeName(name);
692+
}
693+
}
694+
695+
private static String getVolumeName(Object name) {
687696
return CommonUtils.toDns1123LegalName(CommonConstants.COMPATIBILITY_MODE
688697
+ AuxiliaryImageConstants.AUXILIARY_IMAGE_VOLUME_NAME_PREFIX + name);
689698
}

common/src/main/resources/Operator.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ WLSKO-0229=Watch event triggered for deletion of WebLogic Cluster {0} in WebLogi
175175
WLSKO-0230=Status for Cluster Resource with name {0} is now: {1}
176176
WLSKO-0231=Domain introspection is incomplete. \
177177
Check the introspector job logs for possible errors. Job logs are -> {0}.
178+
WLSKO-0232=Watch event triggered for WebLogic Cluster {0}, which is not referenced by any domain.
179+
178180
# Domain status messages
179181

180182
WLSDO-0000={0}. Will retry next at {1} and approximately every {2} seconds afterward until {3} if the failure is not resolved.

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.io.IOException;
77
import java.io.InputStream;
8+
import java.security.NoSuchAlgorithmException;
89
import java.util.ArrayList;
910
import java.util.Collections;
1011
import java.util.HashMap;
@@ -15,6 +16,8 @@
1516
import java.util.Optional;
1617

1718
import com.meterware.simplestub.Memento;
19+
import com.meterware.simplestub.StaticStubSupport;
20+
import oracle.kubernetes.common.CommonConstants;
1821
import org.junit.jupiter.api.AfterEach;
1922
import org.junit.jupiter.api.BeforeEach;
2023
import org.junit.jupiter.api.Test;
@@ -24,6 +27,7 @@
2427

2528
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
2629
import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasNoJsonPath;
30+
import static oracle.kubernetes.common.AuxiliaryImageConstants.AUXILIARY_IMAGE_VOLUME_NAME_PREFIX;
2731
import static oracle.kubernetes.common.CommonConstants.API_VERSION_V8;
2832
import static oracle.kubernetes.common.CommonConstants.API_VERSION_V9;
2933
import static org.hamcrest.Matchers.contains;
@@ -47,11 +51,16 @@ class SchemaConversionUtilsTest {
4751
private final ConversionAdapter converterv8 = new ConversionAdapter(API_VERSION_V8);
4852
private Map<String, Object> v8Domain;
4953

54+
private static CommonUtils.CheckedFunction<String, String> getMD5Hash = SchemaConversionUtilsTest::getMD5Hash;
55+
56+
private static String getMD5Hash(String s) throws NoSuchAlgorithmException {
57+
throw new NoSuchAlgorithmException();
58+
}
59+
5060
@BeforeEach
5161
public void setUp() throws Exception {
5262
mementos.add(CommonTestUtils.silenceLogger());
5363
mementos.add(BaseTestUtils.silenceJsonPathLogger());
54-
5564
v8Domain = readAsYaml(DOMAIN_V8_AUX_IMAGE30_YAML);
5665
}
5766

@@ -606,4 +615,35 @@ void testV8DomainWebLogicCredentialsSecretWithNamespace_remove() {
606615

607616
assertThat(converter.getDomain(), hasNoJsonPath("$.spec.webLogicCredentialsSecret.namespace"));
608617
}
618+
619+
@Test
620+
void testV8DomainWithLongAuxiliaryImageVolumeName_convertedVolumeNameIsTruncated() throws NoSuchAlgorithmException {
621+
Map<String, Object> auxImageVolume = ((Map<String, Object>)
622+
((List<Object>) getDomainSpec(v8Domain).get("auxiliaryImageVolumes")).get(0));
623+
auxImageVolume.put("name", "test-domain-aux-image-volume-test-domain-aux-image-volume");
624+
getDomainSpec(v8Domain).put("auxiliaryImageVolumes", Collections.singletonList(auxImageVolume));
625+
626+
converter.convert(v8Domain);
627+
628+
assertThat(converter.getDomain(), hasJsonPath("$.spec.serverPod.volumes[0].name",
629+
equalTo(CommonUtils.getLegalVolumeName(CommonUtils.toDns1123LegalName(CommonConstants.COMPATIBILITY_MODE
630+
+ AUXILIARY_IMAGE_VOLUME_NAME_PREFIX + (String)auxImageVolume.get("name"))))));
631+
}
632+
633+
@Test
634+
void testV8DomainWithLongAuxiliaryImageVolumeNameAndMessageDigestThrowsException_volumeNameIsNotChanged()
635+
throws NoSuchFieldException {
636+
mementos.add(StaticStubSupport.install(CommonUtils.class, "getMD5Hash", getMD5Hash));
637+
638+
Map<String, Object> auxImageVolume = ((Map<String, Object>)
639+
((List<Object>) getDomainSpec(v8Domain).get("auxiliaryImageVolumes")).get(0));
640+
auxImageVolume.put("name", "test-domain-aux-image-volume-test-domain-aux-image-volume");
641+
getDomainSpec(v8Domain).put("auxiliaryImageVolumes", Collections.singletonList(auxImageVolume));
642+
643+
converter.convert(v8Domain);
644+
645+
assertThat(converter.getDomain(), hasJsonPath("$.spec.serverPod.volumes[0].name",
646+
equalTo(CommonUtils.toDns1123LegalName(CommonConstants.COMPATIBILITY_MODE
647+
+ AUXILIARY_IMAGE_VOLUME_NAME_PREFIX + "test-domain-aux-image-volume-test-domain-aux-image-volume"))));
648+
}
609649
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ spec:
3434
adminServer:
3535
serverPod:
3636
volumes:
37-
- name: compatibility-mode-aux-image-volume-auxiliaryimagevolume1
37+
- name: compat-ai-vol-auxiliaryimagevolume1
3838
emptyDir: {
3939
}
4040
initContainers:
41-
- name: compatibility-mode-operator-aux-container1
41+
- name: compat-operator-aux-container1
4242
image: model-in-image:WLS-AI-v1
4343
command:
4444
- /weblogic-operator/scripts/auxImage.sh
@@ -53,14 +53,14 @@ spec:
5353
- name: AUXILIARY_IMAGE_CONTAINER_IMAGE
5454
value: model-in-image:WLS-AI-v1
5555
- name: AUXILIARY_IMAGE_CONTAINER_NAME
56-
value: compatibility-mode-operator-aux-container1
56+
value: compat-operator-aux-container1
5757
volumeMounts:
58-
- name: compatibility-mode-aux-image-volume-auxiliaryimagevolume1
58+
- name: compat-ai-vol-auxiliaryimagevolume1
5959
mountPath: /tmpAuxiliaryImage
6060
- name: weblogic-scripts-cm-volume
6161
mountPath: /weblogic-operator/scripts
6262
volumeMounts:
63-
- name: compatibility-mode-aux-image-volume-auxiliaryimagevolume1
63+
- name: compat-ai-vol-auxiliaryimagevolume1
6464
mountPath: /auxiliary
6565
env:
6666
- name: AUXILIARY_IMAGE_PATHS

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ spec:
3434
cpu: 250m
3535
memory: 768Mi
3636
volumes:
37-
- name: compatibility-mode-aux-image-volume-auxiliaryimagevolume1
37+
- name: compat-ai-vol-auxiliaryimagevolume1
3838
emptyDir: {
3939
}
4040
initContainers:
41-
- name: compatibility-mode-operator-aux-container1
41+
- name: compat-operator-aux-container1
4242
image: model-in-image:WLS-AI-v1
4343
command:
4444
- /weblogic-operator/scripts/auxImage.sh
@@ -53,14 +53,14 @@ spec:
5353
- name: AUXILIARY_IMAGE_CONTAINER_IMAGE
5454
value: model-in-image:WLS-AI-v1
5555
- name: AUXILIARY_IMAGE_CONTAINER_NAME
56-
value: compatibility-mode-operator-aux-container1
56+
value: compat-operator-aux-container1
5757
volumeMounts:
58-
- name: compatibility-mode-aux-image-volume-auxiliaryimagevolume1
58+
- name: compat-ai-vol-auxiliaryimagevolume1
5959
mountPath: /tmpAuxiliaryImage
6060
- name: weblogic-scripts-cm-volume
6161
mountPath: /weblogic-operator/scripts
6262
volumeMounts:
63-
- name: compatibility-mode-aux-image-volume-auxiliaryimagevolume1
63+
- name: compat-ai-vol-auxiliaryimagevolume1
6464
mountPath: /auxiliary
6565
adminServer:
6666
adminChannelPortForwardingEnabled: false

0 commit comments

Comments
 (0)