Skip to content

Commit fe12393

Browse files
committed
Merge branch 'develop' of https://github.com/oracle/weblogic-kubernetes-operator into develop
2 parents 4f46f07 + 298dd3e commit fe12393

7 files changed

+358
-23
lines changed

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

Lines changed: 169 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,8 @@
66
import static java.util.Arrays.asList;
77

88
import io.kubernetes.client.custom.Quantity;
9-
import io.kubernetes.client.models.ExtensionsV1beta1Deployment;
10-
import io.kubernetes.client.models.V1beta1ClusterRole;
11-
import io.kubernetes.client.models.V1beta1ClusterRoleBinding;
12-
import io.kubernetes.client.models.V1ConfigMap;
13-
import io.kubernetes.client.models.V1Job;
14-
import io.kubernetes.client.models.V1PersistentVolume;
15-
import io.kubernetes.client.models.V1PersistentVolumeClaim;
16-
import io.kubernetes.client.models.V1Service;
17-
import io.kubernetes.client.models.V1ServiceAccount;
9+
import io.kubernetes.client.models.*;
10+
1811
import static oracle.kubernetes.operator.LabelConstants.*;
1912
import static oracle.kubernetes.operator.create.CreateDomainInputs.readInputsYamlFile;
2013
import static oracle.kubernetes.operator.create.KubernetesArtifactUtils.*;
@@ -66,6 +59,14 @@ protected ParsedTraefikYaml getTraefikYaml() {
6659
return getGeneratedFiles().getTraefikYaml();
6760
}
6861

62+
protected ParsedApacheSecurityYaml getApacheSecurityYaml() {
63+
return getGeneratedFiles().getApacheSecurityYaml();
64+
}
65+
66+
protected ParsedApacheYaml getApacheYaml() {
67+
return getGeneratedFiles().getApacheYaml();
68+
}
69+
6970
protected ParsedWeblogicDomainPersistentVolumeClaimYaml getWeblogicDomainPersistentVolumeClaimYaml() {
7071
return getGeneratedFiles().getWeblogicDomainPersistentVolumeClaimYaml();
7172
}
@@ -108,14 +109,14 @@ public void domainCustomResourceYaml_hasCorrectNumberOfObjects() throws Exceptio
108109
}
109110

110111
@Test
111-
public void traefikSecurityYaml_hasCorrectNumberOfObjects() throws Exception {
112+
public void loadBalancerSecurityYaml_hasCorrectNumberOfObjects() throws Exception {
112113
assertThat(
113114
getTraefikSecurityYaml().getObjectCount(),
114115
is(getTraefikSecurityYaml().getExpectedObjectCount()));
115116
}
116117

117118
@Test
118-
public void traefikYaml_hasCorrectNumberOfObjects() throws Exception {
119+
public void loadBalancerYaml_hasCorrectNumberOfObjects() throws Exception {
119120
assertThat(
120121
getTraefikYaml().getObjectCount(),
121122
is(getTraefikYaml().getExpectedObjectCount()));
@@ -392,12 +393,28 @@ protected Domain getExpectedDomain() {
392393
}
393394

394395
@Test
395-
public void generatesCorrect_traefikServiceAccount() throws Exception {
396+
public void generatesCorrect_loadBalancerServiceAccount() throws Exception {
396397
assertThat(
397398
getActualTraefikServiceAccount(),
398399
yamlEqualTo(getExpectedTraefikServiceAccount()));
399400
}
400401

402+
protected V1ServiceAccount getActualApacheServiceAccount() {
403+
return getApacheYaml().getApacheServiceAccount();
404+
}
405+
406+
protected V1ServiceAccount getExpectedApacheServiceAccount() {
407+
return
408+
newServiceAccount()
409+
.metadata(newObjectMeta()
410+
.name(getApacheName())
411+
.namespace(getInputs().getNamespace())
412+
.putLabelsItem(DOMAINUID_LABEL, getInputs().getDomainUID())
413+
.putLabelsItem(DOMAINNAME_LABEL, getInputs().getDomainName())
414+
.putLabelsItem(APP_LABEL, getApacheAppName()));
415+
}
416+
417+
401418
protected V1ServiceAccount getActualTraefikServiceAccount() {
402419
return getTraefikYaml().getTraefikServiceAccount();
403420
}
@@ -414,12 +431,78 @@ protected V1ServiceAccount getExpectedTraefikServiceAccount() {
414431
}
415432

416433
@Test
417-
public void generatesCorrect_traefikDeployment() throws Exception {
434+
public void generatesCorrect_loadBalancerDeployment() throws Exception {
418435
assertThat(
419436
getActualTraefikDeployment(),
420437
yamlEqualTo(getExpectedTraefikDeployment()));
421438
}
422439

440+
protected ExtensionsV1beta1Deployment getActualApacheDeployment() {
441+
return getApacheYaml().getApacheDeployment();
442+
}
443+
444+
protected ExtensionsV1beta1Deployment getExpectedApacheDeployment() {
445+
return
446+
newDeployment()
447+
.apiVersion(API_VERSION_EXTENSIONS_V1BETA1) // TBD - why is apache using this older version?
448+
.metadata(newObjectMeta()
449+
.name(getApacheName())
450+
.namespace(getInputs().getNamespace())
451+
.putLabelsItem(DOMAINUID_LABEL, getInputs().getDomainUID())
452+
.putLabelsItem(DOMAINNAME_LABEL, getInputs().getDomainName())
453+
.putLabelsItem(APP_LABEL, getApacheAppName()))
454+
.spec(newDeploymentSpec()
455+
.replicas(1)
456+
.selector(newLabelSelector()
457+
.putMatchLabelsItem(DOMAINUID_LABEL, getInputs().getDomainUID())
458+
.putMatchLabelsItem(DOMAINNAME_LABEL, getInputs().getDomainName())
459+
.putMatchLabelsItem(APP_LABEL, getApacheAppName()))
460+
.template(newPodTemplateSpec()
461+
.metadata(newObjectMeta()
462+
.putLabelsItem(DOMAINUID_LABEL, getInputs().getDomainUID())
463+
.putLabelsItem(DOMAINNAME_LABEL, getInputs().getDomainName())
464+
.putLabelsItem(APP_LABEL, getApacheAppName()))
465+
.spec(newPodSpec()
466+
.serviceAccountName(getApacheName())
467+
.terminationGracePeriodSeconds(60L)
468+
.addContainersItem(newContainer()
469+
.name(getApacheName())
470+
.image("12213-apache:latest")
471+
.imagePullPolicy("Never")
472+
.addEnvItem(newEnvVar()
473+
.name("WEBLOGIC_CLUSTER")
474+
.value(getInputs().getDomainUID() + "-cluster-" + getClusterNameLC() + ":" + getInputs().getManagedServerPort()))
475+
.addEnvItem(newEnvVar()
476+
.name("LOCATION")
477+
.value(getInputs().getLoadBalancerAppPrepath()))
478+
.addEnvItem(newEnvVar()
479+
.name("WEBLOGIC_HOST")
480+
.value(getInputs().getDomainUID() + "-" + getInputs().getAdminServerName()))
481+
.addEnvItem(newEnvVar()
482+
.name("WEBLOGIC_PORT")
483+
.value(getInputs().getAdminPort()))
484+
.readinessProbe(newProbe()
485+
.tcpSocket(newTCPSocketAction()
486+
.port(newIntOrString(80)))
487+
.failureThreshold(1)
488+
.initialDelaySeconds(10)
489+
.periodSeconds(10)
490+
.successThreshold(1)
491+
.timeoutSeconds(2))
492+
.livenessProbe(newProbe()
493+
.tcpSocket(newTCPSocketAction()
494+
.port(newIntOrString(80)))
495+
.failureThreshold(3)
496+
.initialDelaySeconds(10)
497+
.periodSeconds(10)
498+
.successThreshold(1)
499+
.timeoutSeconds(2))
500+
)
501+
)
502+
)
503+
);
504+
}
505+
423506
protected ExtensionsV1beta1Deployment getActualTraefikDeployment() {
424507
return getTraefikYaml().getTraefikDeployment();
425508
}
@@ -490,7 +573,7 @@ protected ExtensionsV1beta1Deployment getExpectedTraefikDeployment() {
490573
}
491574

492575
@Test
493-
public void generatesCorrect_traefikConfigMap() throws Exception {
576+
public void generatesCorrect_loadBalancerConfigMap() throws Exception {
494577
// The config map contains a 'traefik.toml' property that has a lot of text
495578
// that we don't want to duplicate in the test. However, part of the text
496579
// is computed from the inputs, so we want to validate that part of the info.
@@ -529,12 +612,35 @@ protected void assertThatActualTraefikTomlIsCorrect(String actualTraefikToml) {
529612
}
530613

531614
@Test
532-
public void generatesCorrect_traefikService() throws Exception {
615+
public void generatesCorrect_loadBalancerService() throws Exception {
533616
assertThat(
534617
getActualTraefikService(),
535618
yamlEqualTo(getExpectedTraefikService()));
536619
}
537620

621+
protected V1Service getActualApacheService() {
622+
return getApacheYaml().getApacheService();
623+
}
624+
625+
protected V1Service getExpectedApacheService() {
626+
return
627+
newService()
628+
.metadata(newObjectMeta()
629+
.name(getApacheName())
630+
.namespace(getInputs().getNamespace())
631+
.putLabelsItem(DOMAINUID_LABEL, getInputs().getDomainUID())
632+
.putLabelsItem(DOMAINNAME_LABEL, getInputs().getDomainName()))
633+
.spec(newServiceSpec()
634+
.type("NodePort")
635+
.putSelectorItem(DOMAINUID_LABEL, getInputs().getDomainUID())
636+
.putSelectorItem(DOMAINNAME_LABEL, getInputs().getDomainName())
637+
.putSelectorItem(APP_LABEL, getApacheAppName())
638+
.addPortsItem(newServicePort()
639+
.name("rest-https")
640+
.port(80)
641+
.nodePort(Integer.parseInt(getInputs().getLoadBalancerWebPort()))));
642+
}
643+
538644
protected V1Service getActualTraefikService() {
539645
return getTraefikYaml().getTraefikService();
540646
}
@@ -560,7 +666,7 @@ protected V1Service getExpectedTraefikService() {
560666
}
561667

562668
@Test
563-
public void generatesCorrect_traefikDashboardService() throws Exception {
669+
public void generatesCorrect_loadBalancerDashboardService() throws Exception {
564670
assertThat(
565671
getActualTraefikDashboardService(),
566672
yamlEqualTo(getExpectedTraefikDashboardService()));
@@ -591,12 +697,33 @@ protected V1Service getExpectedTraefikDashboardService() {
591697
}
592698

593699
@Test
594-
public void generatesCorrect_traefikClusterRole() throws Exception {
700+
public void generatesCorrect_loadBalancerClusterRole() throws Exception {
595701
assertThat(
596702
getActualTraefikClusterRole(),
597703
yamlEqualTo(getExpectedTraefikClusterRole()));
598704
}
599705

706+
protected V1beta1ClusterRole getActualApacheClusterRole() {
707+
return getApacheSecurityYaml().getApacheClusterRole();
708+
}
709+
710+
protected V1beta1ClusterRole getExpectedApacheClusterRole() {
711+
return
712+
newClusterRole()
713+
.metadata(newObjectMeta()
714+
.name(getApacheName())
715+
.putLabelsItem(DOMAINUID_LABEL, getInputs().getDomainUID())
716+
.putLabelsItem(DOMAINNAME_LABEL, getInputs().getDomainName()))
717+
.addRulesItem(newPolicyRule()
718+
.addApiGroupsItem("")
719+
.resources(asList("pods", "services", "endpoints", "secrets"))
720+
.verbs(asList("get", "list", "watch")))
721+
.addRulesItem(newPolicyRule()
722+
.addApiGroupsItem("extensions")
723+
.addResourcesItem("ingresses")
724+
.verbs(asList("get", "list", "watch")));
725+
}
726+
600727
protected V1beta1ClusterRole getActualTraefikClusterRole() {
601728
return getTraefikSecurityYaml().getTraefikClusterRole();
602729
}
@@ -620,12 +747,32 @@ protected V1beta1ClusterRole getExpectedTraefikClusterRole() {
620747
}
621748

622749
@Test
623-
public void generatesCorrect_traefikDashboardClusterRoleBinding() throws Exception {
750+
public void generatesCorrect_loadBalancerClusterRoleBinding() throws Exception {
624751
assertThat(
625752
getActualTraefikDashboardClusterRoleBinding(),
626753
yamlEqualTo(getExpectedTraefikDashboardClusterRoleBinding()));
627754
}
628755

756+
protected V1beta1ClusterRoleBinding getActualApacheClusterRoleBinding() {
757+
return getApacheSecurityYaml().getApacheClusterRoleBinding();
758+
}
759+
760+
protected V1beta1ClusterRoleBinding getExpectedApacheClusterRoleBinding() {
761+
return
762+
newClusterRoleBinding()
763+
.metadata(newObjectMeta()
764+
.name(getApacheName())
765+
.putLabelsItem(DOMAINUID_LABEL, getInputs().getDomainUID())
766+
.putLabelsItem(DOMAINNAME_LABEL, getInputs().getDomainName()))
767+
.addSubjectsItem(newSubject()
768+
.kind("ServiceAccount")
769+
.name(getApacheName())
770+
.namespace(getInputs().getNamespace()))
771+
.roleRef(newRoleRef()
772+
.name(getApacheName())
773+
.apiGroup("rbac.authorization.k8s.io"));
774+
}
775+
629776
protected V1beta1ClusterRoleBinding getActualTraefikDashboardClusterRoleBinding() {
630777
return getTraefikSecurityYaml().getTraefikDashboardClusterRoleBinding();
631778
}
@@ -709,4 +856,8 @@ protected String getClusterLCScope() {
709856
protected String getClusterNameLC() {
710857
return getInputs().getClusterName().toLowerCase();
711858
}
859+
860+
protected String getApacheName() { return getInputs().getDomainUID() + "-" + getApacheAppName(); }
861+
862+
protected String getApacheAppName() { return "apache-webtier";}
712863
}

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

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@
77
import io.kubernetes.client.models.V1PersistentVolume;
88
import static oracle.kubernetes.operator.create.CreateDomainInputs.*;
99
import static oracle.kubernetes.operator.create.KubernetesArtifactUtils.*;
10+
import static oracle.kubernetes.operator.create.YamlUtils.yamlEqualTo;
11+
import static org.hamcrest.MatcherAssert.assertThat;
12+
import static org.hamcrest.Matchers.is;
13+
import static org.junit.Assert.assertNull;
14+
1015
import oracle.kubernetes.weblogic.domain.v1.Domain;
1116
import org.junit.BeforeClass;
17+
import org.junit.Test;
1218

1319
/**
1420
* Tests that the all artifacts in the yaml files that create-weblogic-domain.sh
@@ -26,7 +32,8 @@ public static void setup() throws Exception {
2632
.exposeAdminT3Channel("true")
2733
.clusterType("CONFIGURED")
2834
.weblogicImagePullSecretName("test-weblogic-image-pull-secret-name")
29-
.loadBalancer(LOAD_BALANCER_TRAEFIK)
35+
.loadBalancer(LOAD_BALANCER_APACHE)
36+
.loadBalancerAppPrepath("/loadBalancerAppPrePath")
3037
.weblogicDomainStorageType(STORAGE_TYPE_NFS)
3138
.productionModeEnabled("true")
3239
);
@@ -58,4 +65,61 @@ protected V1PersistentVolume getExpectedWeblogicDomainPersistentVolume() {
5865
.path(getInputs().getWeblogicDomainStoragePath()));
5966
return expected;
6067
}
68+
69+
@Override
70+
public void generatesCorrect_loadBalancerDeployment() throws Exception {
71+
assertThat(
72+
getActualApacheDeployment(),
73+
yamlEqualTo(getExpectedApacheDeployment()));
74+
}
75+
76+
@Override
77+
public void generatesCorrect_loadBalancerServiceAccount() throws Exception {
78+
assertThat(
79+
getActualApacheServiceAccount(),
80+
yamlEqualTo(getExpectedApacheServiceAccount())); }
81+
82+
@Override
83+
public void generatesCorrect_loadBalancerConfigMap() throws Exception {
84+
// No config map in generated yaml for LOAD_BALANCER_APACHE
85+
}
86+
87+
@Override
88+
public void generatesCorrect_loadBalancerService() throws Exception {
89+
assertThat(
90+
getActualApacheService(),
91+
yamlEqualTo(getExpectedApacheService()));
92+
}
93+
94+
@Override
95+
public void generatesCorrect_loadBalancerDashboardService() throws Exception {
96+
// No dashboard service in generated yaml for LOAD_BALANCER_APACHE
97+
}
98+
99+
@Override
100+
public void generatesCorrect_loadBalancerClusterRole() throws Exception {
101+
assertThat(
102+
getActualApacheClusterRole(),
103+
yamlEqualTo(getExpectedApacheClusterRole())); }
104+
105+
@Override
106+
public void generatesCorrect_loadBalancerClusterRoleBinding() throws Exception {
107+
assertThat(
108+
getActualApacheClusterRoleBinding(),
109+
yamlEqualTo(getExpectedApacheClusterRoleBinding()));
110+
}
111+
112+
@Override
113+
public void loadBalancerSecurityYaml_hasCorrectNumberOfObjects() throws Exception {
114+
assertThat(
115+
getApacheSecurityYaml().getObjectCount(),
116+
is(getApacheSecurityYaml().getExpectedObjectCount()));
117+
}
118+
119+
@Override
120+
public void loadBalancerYaml_hasCorrectNumberOfObjects() throws Exception {
121+
assertThat(
122+
getApacheYaml().getObjectCount(),
123+
is(getApacheYaml().getExpectedObjectCount()));
124+
}
61125
}

0 commit comments

Comments
 (0)