Skip to content

Commit a060ae5

Browse files
authored
Merge pull request #358 from oracle/apache_volumepath_config_validation
Issue #330: Add validation for loadBalancerVolumePath
2 parents 7728c58 + 434f520 commit a060ae5

File tree

3 files changed

+55
-12
lines changed

3 files changed

+55
-12
lines changed

kubernetes/create-weblogic-domain-inputs.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,14 @@ loadBalancer: TRAEFIK
9999
# This defines the /location in the built-in Apache plugin configuration module for WebLogic
100100
loadBalancerAppPrepath: /
101101

102-
# Docker volume path for APACHE. By default, it is empty, which causes the volume mount be
103-
# disabled and, thereforem the built-in Apache plugin config be used.
104-
# Use this to provide your own Apache plugin configuration as needed; simply define this
105-
# path and put your own custom_mod_wl_apache.conf file under this path.
102+
# Docker volume path for APACHE.
103+
# By default, the path is empty, and therefore, the built-in default Apache plugin
104+
# configuration is used.
105+
# Use this to provide your own Apache plugin configuration as needed; simply define
106+
# this path and put your own custom_mod_wl_apache.conf file under this path.
107+
# If the specified path does not exist, or the customer_mod_wl_apache.conf file
108+
# is missing under the specified path, the create domain script will fail with
109+
# a validation error.
106110
loadBalancerVolumePath:
107111

108112
# Load balancer web port

kubernetes/internal/create-weblogic-domain.sh

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -567,14 +567,24 @@ function createYamlFiles {
567567
sed -i -e "s:%WEB_APP_PREPATH%:$loadBalancerAppPrepath:g" ${apacheOutput}
568568

569569
if [ ! -z "${loadBalancerVolumePath}" ]; then
570-
sed -i -e "s:%LOAD_BALANCER_VOLUME_PATH%:${loadBalancerVolumePath}:g" ${apacheOutput}
571-
sed -i -e "s:# volumes:volumes:g" ${apacheOutput}
572-
sed -i -e "s:# - name:- name:g" ${apacheOutput}
573-
sed -i -e "s:# hostPath: hostPath:g" ${apacheOutput}
574-
sed -i -e "s:# path: path:g" ${apacheOutput}
575-
sed -i -e "s:# volumeMounts:volumeMounts:g" ${apacheOutput}
576-
sed -i -e "s:# - name:- name:g" ${apacheOutput}
577-
sed -i -e "s:# mountPath: mountPath:g" ${apacheOutput}
570+
apacheConfigFileName="custom_mod_wl_apache.conf"
571+
if [ ! -d ${loadBalancerVolumePath} ]; then
572+
echo -e "\nERROR - The specified loadBalancerVolumePath $loadBalancerVolumePath does not exist! \n"
573+
fail "Exiting due to a validation error"
574+
elif [ ! -f ${loadBalancerVolumePath}/${apacheConfigFileName} ]; then
575+
echo -e "\nERROR - The required file ${apacheConfigFileName} does not exist under the specified loadBalancerVolumePath $loadBalancerVolumePath! \n"
576+
fail "Exiting due to a validation error"
577+
else
578+
sed -i -e "s:%LOAD_BALANCER_VOLUME_PATH%:${loadBalancerVolumePath}:g" ${apacheOutput}
579+
sed -i -e "s:# volumes:volumes:g" ${apacheOutput}
580+
sed -i -e "s:# - name:- name:g" ${apacheOutput}
581+
sed -i -e "s:# hostPath: hostPath:g" ${apacheOutput}
582+
sed -i -e "s:# path: path:g" ${apacheOutput}
583+
sed -i -e "s:# volumeMounts:volumeMounts:g" ${apacheOutput}
584+
sed -i -e "s:# - name:- name:g" ${apacheOutput}
585+
sed -i -e "s:# mountPath: mountPath:g" ${apacheOutput}
586+
587+
fi
578588
fi
579589

580590
# Apache security file

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public class CreateDomainInputsValidationTest {
4747
private static final String PARAM_LOAD_BALANCER = "loadBalancer";
4848
private static final String PARAM_LOAD_BALANCER_WEB_PORT = "loadBalancerWebPort";
4949
private static final String PARAM_LOAD_BALANCER_DASHBOARD_PORT = "loadBalancerDashboardPort";
50+
private static final String PARAM_LOAD_BALANCER_VOLUME_PATH = "loadBalancerVolumePath";
5051
private static final String PARAM_JAVA_OPTIONS = "javaOptions";
5152
private static final String PARAM_VERSION = "version";
5253

@@ -516,6 +517,25 @@ public void createDomain_with_invalidLoadBalancerDashboardPort_failsAndReturnsEr
516517
failsAndPrints(invalidIntegerParamValueError(PARAM_LOAD_BALANCER_DASHBOARD_PORT, val)));
517518
}
518519

520+
@Test
521+
public void createDomain_with_invalidLoadBalancerVolumePath_failsAndReturnsError()
522+
throws Exception {
523+
String val = "invalid-load-balancer-volume-path";
524+
assertThat(
525+
execCreateDomain(
526+
newInputs().loadBalancer(LOAD_BALANCER_APACHE).loadBalancerVolumePath(val)),
527+
failsAndPrints(missingDirectoryError(PARAM_LOAD_BALANCER_VOLUME_PATH, val)));
528+
}
529+
530+
public void createDomain_with_invalidLoadBalancerVolumePath_missingFile_failsAndReturnsError()
531+
throws Exception {
532+
String val = "/";
533+
assertThat(
534+
execCreateDomain(
535+
newInputs().loadBalancer(LOAD_BALANCER_APACHE).loadBalancerVolumePath(val)),
536+
failsAndPrints(
537+
missingFileError(PARAM_LOAD_BALANCER_VOLUME_PATH, val, "custom-mod-wl-apache.conf")));
538+
}
519539
// TBD - shouldn't we allow empty java options?
520540
@Test
521541
public void createDomain_with_missingJavaOptions_failsAndReturnsError() throws Exception {
@@ -572,6 +592,15 @@ private String invalidRelatedParamValueError(String param, String val, String pa
572592
return errorRegexp("Invalid.*" + param + ".*" + val + " with " + param2 + ".*" + val2);
573593
}
574594

595+
private String missingDirectoryError(String param, String val) {
596+
return errorRegexp(param + ".*" + val + ".*" + "does not exist!");
597+
}
598+
599+
private String missingFileError(String param, String val, String dir) {
600+
return errorRegexp(param + ".*" + val + ".*" + "does not exist under" + ".*" + dir + ".*");
601+
}
602+
603+
575604
private String paramMissingError(String param) {
576605
return errorRegexp(param + ".*missing");
577606
}

0 commit comments

Comments
 (0)