Skip to content

Commit 36b0e35

Browse files
authored
Merge pull request #351 from oracle/apache_config_validation
Issue#330: Add validation for Apache loadBalancerVolumePath
2 parents 9b2132d + be94481 commit 36b0e35

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

kubernetes/create-weblogic-domain-inputs.yaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,13 @@ loadBalancer: TRAEFIK
102102
# This defines the /location in the built-in Apache plugin configuration module for WebLogic
103103
loadBalancerAppPrepath: /
104104

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

111114
# Boolean to indicate if the admin port is going to be exposed for APACHE. By default, it is false.

kubernetes/internal/create-weblogic-domain.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -604,11 +604,20 @@ function createYamlFiles {
604604
enableLoadBalancerExposeAdminPortPrefix="${disabledPrefix}"
605605
fi
606606

607+
enableLoadBalancerVolumePathPrefix="${disabledPrefix}"
608+
apacheConfigFileName="custom_mod_wl_apache.conf"
607609
if [ ! -z "${loadBalancerVolumePath}" ]; then
608-
enableLoadBalancerVolumePathPrefix="${enabledPrefix}"
609-
sed -i -e "s:%LOAD_BALANCER_VOLUME_PATH%:${loadBalancerVolumePath}:g" ${apacheOutput}
610-
else
611-
enableLoadBalancerVolumePathPrefix="${disabledPrefix}"
610+
if [ ! -d ${loadBalancerVolumePath} ]; then
611+
echo -e "\nERROR - The specified loadBalancerVolumePath $loadBalancerVolumePath does not exist! \n"
612+
fail "Exiting due to a validation error"
613+
elif [ ! -f ${loadBalancerVolumePath}/${apacheConfigFileName} ]; then
614+
echo -e "\nERROR - The required file ${apacheConfigFileName} does not exist under the specified loadBalancerVolumePath $loadBalancerVolumePath! \n"
615+
fail "Exiting due to a validation error"
616+
else
617+
enableLoadBalancerVolumePathPrefix="${enabledPrefix}"
618+
sed -i -e "s:%LOAD_BALANCER_VOLUME_PATH%:${loadBalancerVolumePath}:g" ${apacheOutput}
619+
620+
fi
612621
fi
613622

614623
sed -i -e "s:%ENABLE_LOAD_BALANCER_EXPOSE_ADMIN_PORT%:${enableLoadBalancerExposeAdminPortPrefix}:g" ${apacheOutput}

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public class CreateDomainInputsValidationTest {
5858
private static final String PARAM_LOAD_BALANCER = "loadBalancer";
5959
private static final String PARAM_LOAD_BALANCER_WEB_PORT = "loadBalancerWebPort";
6060
private static final String PARAM_LOAD_BALANCER_DASHBOARD_PORT = "loadBalancerDashboardPort";
61+
private static final String PARAM_LOAD_BALANCER_VOLUME_PATH = "loadBalancerVolumePath";
6162
private static final String PARAM_JAVA_OPTIONS = "javaOptions";
6263
private static final String PARAM_VERSION = "version";
6364

@@ -554,6 +555,26 @@ public void createDomain_with_invalidLoadBalancerDashboardPort_failsAndReturnsEr
554555
failsAndPrints(invalidIntegerParamValueError(PARAM_LOAD_BALANCER_DASHBOARD_PORT, val)));
555556
}
556557

558+
@Test
559+
public void createDomain_with_invalidLoadBalancerVolumePath_failsAndReturnsError()
560+
throws Exception {
561+
String val = "invalid-load-balancer-volume-path";
562+
assertThat(
563+
execCreateDomain(
564+
newInputs().loadBalancer(LOAD_BALANCER_APACHE).loadBalancerVolumePath(val)),
565+
failsAndPrints(missingDirectoryError(PARAM_LOAD_BALANCER_VOLUME_PATH, val)));
566+
}
567+
568+
public void createDomain_with_invalidLoadBalancerVolumePath_missingFile_failsAndReturnsError()
569+
throws Exception {
570+
String val = "/";
571+
assertThat(
572+
execCreateDomain(
573+
newInputs().loadBalancer(LOAD_BALANCER_APACHE).loadBalancerVolumePath(val)),
574+
failsAndPrints(
575+
missingFileError(PARAM_LOAD_BALANCER_VOLUME_PATH, val, "custom-mod-wl-apache.conf")));
576+
}
577+
557578
// TBD - shouldn't we allow empty java options?
558579
@Test
559580
public void createDomain_with_missingJavaOptions_failsAndReturnsError() throws Exception {
@@ -613,6 +634,14 @@ private String invalidRelatedParamValueError(
613634
return errorRegexp("Invalid.*" + param + ".*" + val + " with " + param2 + ".*" + val2);
614635
}
615636

637+
private String missingDirectoryError(String param, String val) {
638+
return errorRegexp(param + ".*" + val + ".*" + "does not exist!");
639+
}
640+
641+
private String missingFileError(String param, String val, String dir) {
642+
return errorRegexp(param + ".*" + val + ".*" + "does not exist under" + ".*" + dir + ".*");
643+
}
644+
616645
private String paramMissingError(String param) {
617646
return errorRegexp(param + ".*missing");
618647
}

0 commit comments

Comments
 (0)