Skip to content

Commit 7da2d51

Browse files
committed
Fix operator typos in domain files, add tests for the traefik deployment artifact, test that the copy of the inputs file in the generated directories match the ones specified on the command line, test the valid startup control options, use constants for enum properties
1 parent fa5c2a2 commit 7da2d51

13 files changed

+196
-114
lines changed

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

Lines changed: 80 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.Map;
77
import static java.util.Arrays.asList;
88

9+
import io.kubernetes.client.models.ExtensionsV1beta1Deployment;
910
import io.kubernetes.client.models.V1beta1ClusterRole;
1011
import io.kubernetes.client.models.V1beta1ClusterRoleBinding;
1112
import io.kubernetes.client.models.V1ConfigMap;
@@ -14,16 +15,17 @@
1415
import io.kubernetes.client.models.V1PersistentVolumeClaim;
1516
import io.kubernetes.client.models.V1Service;
1617
import io.kubernetes.client.models.V1ServiceAccount;
18+
import static oracle.kubernetes.operator.create.CreateDomainInputs.readInputsYamlFile;
1719
import static oracle.kubernetes.operator.create.KubernetesArtifactUtils.*;
18-
import static oracle.kubernetes.operator.create.YamlUtils.*;
20+
import static oracle.kubernetes.operator.create.YamlUtils.yamlEqualTo;
1921
import oracle.kubernetes.weblogic.domain.v1.Domain;
2022
import static org.hamcrest.MatcherAssert.assertThat;
2123
import static org.hamcrest.Matchers.*;
2224
import org.junit.AfterClass;
2325
import org.junit.Test;
2426

2527
/**
26-
* Tests that the all artifacts in the yaml files that create-domain-operator.sh
28+
* Tests that the all artifacts in the yaml files that create-weblogic-domain.sh
2729
* creates are correct when the admin node port is disabled, the t3 channel is disabled,
2830
* there is no image pull secret, and production mode is disabled.
2931
*/
@@ -84,8 +86,10 @@ public static void tearDown() throws Exception {
8486
}
8587

8688
@Test
87-
public void generatedCorrect_weblogicDomainInputsYaml() {
88-
// TBD
89+
public void generatedCorrect_weblogicDomainInputsYaml() throws Exception {
90+
assertThat(
91+
readInputsYamlFile(generatedFiles.getDomainFiles().getCreateWeblogicDomainInputsYamlPath()),
92+
yamlEqualTo(readInputsYamlFile(generatedFiles.getInputsYamlPath())));
8993
}
9094

9195
@Test
@@ -410,80 +414,80 @@ protected V1ServiceAccount getExpectedTraefikServiceAccount() {
410414
.putLabelsItem("weblogic.clusterName", getClusterNameLC()));
411415
}
412416

413-
/*
414417
@Test
415418
public void generatesCorrect_traefikDeployment() throws Exception {
416-
//System.out.println("MOREAUT_DEBUG traefik deployment =\n" + newYaml().dump(generatedFiles.getTraefikYaml().getTraefikDeployment()));
417-
418-
//
419-
kind: Deployment
420-
apiVersion: extensions/v1beta1
421-
metadata:
422-
name: %DOMAIN_UID%-%CLUSTER_NAME_LC%-traefik
423-
namespace: %NAMESPACE%
424-
labels:
425-
app: %DOMAIN_UID%-%CLUSTER_NAME_LC%-traefik
426-
weblogic.domainUID: %DOMAIN_UID%
427-
weblogic.clusterName: %CLUSTER_NAME_LC%
428-
spec:
429-
replicas: 1
430-
selector:
431-
matchLabels:
432-
app: %DOMAIN_UID%-%CLUSTER_NAME_LC%-traefik
433-
template:
434-
metadata:
435-
labels:
436-
app: %DOMAIN_UID%-%CLUSTER_NAME_LC%-traefik
437-
weblogic.domainUID: %DOMAIN_UID%
438-
weblogic.clusterName: %CLUSTER_NAME_LC%
439-
spec:
440-
serviceAccountName: %DOMAIN_UID%-%CLUSTER_NAME_LC%-traefik
441-
terminationGracePeriodSeconds: 60
442-
containers:
443-
- image: traefik:1.4.5
444-
name: %DOMAIN_UID%-%CLUSTER_NAME_LC%-traefik
445-
resources:
446-
requests:
447-
cpu: "100m"
448-
memory: "20Mi"
449-
limits:
450-
cpu: "100m"
451-
memory: "30Mi"
452-
readinessProbe:
453-
tcpSocket:
454-
port: 80
455-
failureThreshold: 1
456-
initialDelaySeconds: 10
457-
periodSeconds: 10
458-
successThreshold: 1
459-
timeoutSeconds: 2
460-
livenessProbe:
461-
tcpSocket:
462-
port: 80
463-
failureThreshold: 3
464-
initialDelaySeconds: 10
465-
periodSeconds: 10
466-
successThreshold: 1
467-
timeoutSeconds: 2
468-
volumeMounts:
469-
- mountPath: /config
470-
name: config
471-
ports:
472-
- name: http
473-
containerPort: 80
474-
protocol: TCP
475-
- name: dash
476-
containerPort: 8080
477-
protocol: TCP
478-
args:
479-
- --configfile=/config/traefik.toml
480-
volumes:
481-
- name: config
482-
configMap:
483-
name: %DOMAIN_UID%-%CLUSTER_NAME_LC%-traefik
484-
//
485-
}
486-
*/
419+
assertThat(
420+
getActualTraefikDeployment(),
421+
yamlEqualTo(getExpectedTraefikDeployment()));
422+
}
423+
424+
protected ExtensionsV1beta1Deployment getActualTraefikDeployment() {
425+
return getTraefikYaml().getTraefikDeployment();
426+
}
427+
428+
protected ExtensionsV1beta1Deployment getExpectedTraefikDeployment() {
429+
return
430+
newDeployment()
431+
.apiVersion(API_VERSION_EXTENSIONS_V1BETA1) // TBD - why is traefik using this older version?
432+
.metadata(newObjectMeta()
433+
.name(getTraefikScope())
434+
.namespace(getInputs().getNamespace())
435+
.putLabelsItem("app", getTraefikScope())
436+
.putLabelsItem("weblogic.domainUID", getInputs().getDomainUid())
437+
.putLabelsItem("weblogic.clusterName", getClusterNameLC()))
438+
.spec(newDeploymentSpec()
439+
.replicas(1)
440+
.selector(newLabelSelector()
441+
.putMatchLabelsItem("app", getTraefikScope()))
442+
.template(newPodTemplateSpec()
443+
.metadata(newObjectMeta()
444+
.putLabelsItem("app", getTraefikScope())
445+
.putLabelsItem("weblogic.domainUID", getInputs().getDomainUid())
446+
.putLabelsItem("weblogic.clusterName", getClusterNameLC()))
447+
.spec(newPodSpec()
448+
.serviceAccountName(getTraefikScope())
449+
.terminationGracePeriodSeconds(60L)
450+
.addContainersItem(newContainer()
451+
.name(getTraefikScope())
452+
.image("traefik:1.4.5")
453+
.resources(newResourceRequirements()
454+
.putRequestsItem("cpu", "100m")
455+
.putRequestsItem("memory", "20Mi")
456+
.putLimitsItem("cpu", "100m")
457+
.putLimitsItem("memory", "30Mi"))
458+
.readinessProbe(newProbe()
459+
.tcpSocket(newTCPSocketAction()
460+
.port(newIntOrString(80)))
461+
.failureThreshold(1)
462+
.initialDelaySeconds(10)
463+
.periodSeconds(10)
464+
.successThreshold(1)
465+
.timeoutSeconds(2))
466+
.livenessProbe(newProbe()
467+
.tcpSocket(newTCPSocketAction()
468+
.port(newIntOrString(80)))
469+
.failureThreshold(3)
470+
.initialDelaySeconds(10)
471+
.periodSeconds(10)
472+
.successThreshold(1)
473+
.timeoutSeconds(2))
474+
.addVolumeMountsItem(newVolumeMount()
475+
.name("config")
476+
.mountPath("/config"))
477+
.addPortsItem(newContainerPort()
478+
.name("http")
479+
.containerPort(80)
480+
.protocol("TCP"))
481+
.addPortsItem(newContainerPort()
482+
.name("dash")
483+
.containerPort(8080)
484+
.protocol("TCP"))
485+
.addArgsItem("--configfile=/config/traefik.toml"))
486+
.addVolumesItem(newVolume()
487+
.name("config")
488+
.configMap(newConfigMapVolumeSource()
489+
.name(getTraefikScope()))))));
490+
}
487491

488492
@Test
489493
public void generatesCorrect_traefikConfigMap() throws Exception {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.junit.BeforeClass;
77

88
/**
9-
* Tests that the all artifacts in the yaml files that create-domain-operator.sh
9+
* Tests that the all artifacts in the yaml files that create-weblogic-domain.sh
1010
* creates are correct when the admin node port is disabled, the t3 channel is disabled,
1111
* there is no image pull secret, production mode is disabled and the persistence type
1212
* is hostPath

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import org.junit.BeforeClass;
1111

1212
/**
13-
* Tests that the all artifacts in the yaml files that create-domain-operator.sh
13+
* Tests that the all artifacts in the yaml files that create-weblogic-domain.sh
1414
* creates are correct when the admin node port is enabled, the t3 channel is enabled,
1515
* there is an image pull secret, production mode is enabled, and the persistence type
1616
* is nfs

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
import static oracle.kubernetes.operator.create.YamlUtils.newYaml;
1212

1313
/**
14-
* Class that mirrors create-weblogic-operator-inputs.yaml
14+
* Class that mirrors create-weblogic-domain-inputs.yaml
1515
*
16-
* Used to parse create-weblogic-operator-inputs.yaml into java
17-
* and convert java to create-weblogic-operator-inputs.yaml
16+
* Used to parse create-weblogic-domain-inputs.yaml into java
17+
* and convert java to create-weblogic-domain-inputs.yaml
1818
*
1919
* Note: use strings to represent params that must be ints or booleans at runtime
2020
* so that we can test more invalid input options (e.g. missing value, not int value)
@@ -97,8 +97,12 @@ public static CreateDomainInputs newInputs() throws Exception {
9797
.t3ChannelPort("30013");
9898
}
9999

100-
public static CreateDomainInputs readDefaultInputsFile() throws IOException {
101-
Reader r = Files.newBufferedReader(defaultInputsPath(), Charset.forName("UTF-8"));
100+
public static CreateDomainInputs readDefaultInputsFile() throws Exception {
101+
return readInputsYamlFile(defaultInputsPath());
102+
}
103+
104+
public static CreateDomainInputs readInputsYamlFile(Path path) throws Exception {
105+
Reader r = Files.newBufferedReader(path, Charset.forName("UTF-8"));
102106
return (CreateDomainInputs)newYaml().loadAs(r, CreateDomainInputs.class);
103107
}
104108

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void defaultInputsFile_hasCorrectContents() throws Exception {
5252
.exposeAdminT3Channel("false")
5353
.imagePullSecretName("")
5454
.javaOptions("-Dweblogic.StdoutDebugEnabled=false")
55-
.loadBalancer("traefik")
55+
.loadBalancer(LOAD_BALANCER_TRAEFIK)
5656
.loadBalancerAdminPort("30315")
5757
.loadBalancerWebPort("30305")
5858
.managedServerCount("2")
@@ -63,12 +63,12 @@ public void defaultInputsFile_hasCorrectContents() throws Exception {
6363
.nfsServer("nfsServer")
6464
.persistencePath("/scratch/k8s_dir/persistentVolume001")
6565
.persistenceSize("10Gi")
66-
.persistenceType("hostPath")
66+
.persistenceType(PERSISTENCE_TYPE_HOST_PATH)
6767
.persistenceVolumeClaimName("pv001-claim")
6868
.persistenceVolumeName("pv001")
6969
.productionModeEnabled("true")
7070
.secretName("domain1-weblogic-credentials")
71-
.startupControl("AUTO")
71+
.startupControl(STARTUP_CONTROL_AUTO)
7272
.t3ChannelPort("30012")
7373
.t3PublicAddress("kubernetes")));
7474
}

0 commit comments

Comments
 (0)