Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,8 @@
import static java.util.Arrays.asList;

import io.kubernetes.client.custom.Quantity;
import io.kubernetes.client.models.ExtensionsV1beta1Deployment;
import io.kubernetes.client.models.V1beta1ClusterRole;
import io.kubernetes.client.models.V1beta1ClusterRoleBinding;
import io.kubernetes.client.models.V1ConfigMap;
import io.kubernetes.client.models.V1Job;
import io.kubernetes.client.models.V1PersistentVolume;
import io.kubernetes.client.models.V1PersistentVolumeClaim;
import io.kubernetes.client.models.V1Service;
import io.kubernetes.client.models.V1ServiceAccount;
import io.kubernetes.client.models.*;

import static oracle.kubernetes.operator.LabelConstants.*;
import static oracle.kubernetes.operator.create.CreateDomainInputs.readInputsYamlFile;
import static oracle.kubernetes.operator.create.KubernetesArtifactUtils.*;
Expand Down Expand Up @@ -66,6 +59,14 @@ protected ParsedTraefikYaml getTraefikYaml() {
return getGeneratedFiles().getTraefikYaml();
}

protected ParsedApacheSecurityYaml getApacheSecurityYaml() {
return getGeneratedFiles().getApacheSecurityYaml();
}

protected ParsedApacheYaml getApacheYaml() {
return getGeneratedFiles().getApacheYaml();
}

protected ParsedWeblogicDomainPersistentVolumeClaimYaml getWeblogicDomainPersistentVolumeClaimYaml() {
return getGeneratedFiles().getWeblogicDomainPersistentVolumeClaimYaml();
}
Expand Down Expand Up @@ -108,14 +109,14 @@ public void domainCustomResourceYaml_hasCorrectNumberOfObjects() throws Exceptio
}

@Test
public void traefikSecurityYaml_hasCorrectNumberOfObjects() throws Exception {
public void loadBalancerSecurityYaml_hasCorrectNumberOfObjects() throws Exception {
assertThat(
getTraefikSecurityYaml().getObjectCount(),
is(getTraefikSecurityYaml().getExpectedObjectCount()));
}

@Test
public void traefikYaml_hasCorrectNumberOfObjects() throws Exception {
public void loadBalancerYaml_hasCorrectNumberOfObjects() throws Exception {
assertThat(
getTraefikYaml().getObjectCount(),
is(getTraefikYaml().getExpectedObjectCount()));
Expand Down Expand Up @@ -392,12 +393,28 @@ protected Domain getExpectedDomain() {
}

@Test
public void generatesCorrect_traefikServiceAccount() throws Exception {
public void generatesCorrect_loadBalancerServiceAccount() throws Exception {
assertThat(
getActualTraefikServiceAccount(),
yamlEqualTo(getExpectedTraefikServiceAccount()));
}

protected V1ServiceAccount getActualApacheServiceAccount() {
return getApacheYaml().getApacheServiceAccount();
}

protected V1ServiceAccount getExpectedApacheServiceAccount() {
return
newServiceAccount()
.metadata(newObjectMeta()
.name(getApacheName())
.namespace(getInputs().getNamespace())
.putLabelsItem(DOMAINUID_LABEL, getInputs().getDomainUID())
.putLabelsItem(DOMAINNAME_LABEL, getInputs().getDomainName())
.putLabelsItem(APP_LABEL, getApacheAppName()));
}


protected V1ServiceAccount getActualTraefikServiceAccount() {
return getTraefikYaml().getTraefikServiceAccount();
}
Expand All @@ -414,12 +431,78 @@ protected V1ServiceAccount getExpectedTraefikServiceAccount() {
}

@Test
public void generatesCorrect_traefikDeployment() throws Exception {
public void generatesCorrect_loadBalancerDeployment() throws Exception {
assertThat(
getActualTraefikDeployment(),
yamlEqualTo(getExpectedTraefikDeployment()));
}

protected ExtensionsV1beta1Deployment getActualApacheDeployment() {
return getApacheYaml().getApacheDeployment();
}

protected ExtensionsV1beta1Deployment getExpectedApacheDeployment() {
return
newDeployment()
.apiVersion(API_VERSION_EXTENSIONS_V1BETA1) // TBD - why is apache using this older version?
.metadata(newObjectMeta()
.name(getApacheName())
.namespace(getInputs().getNamespace())
.putLabelsItem(DOMAINUID_LABEL, getInputs().getDomainUID())
.putLabelsItem(DOMAINNAME_LABEL, getInputs().getDomainName())
.putLabelsItem(APP_LABEL, getApacheAppName()))
.spec(newDeploymentSpec()
.replicas(1)
.selector(newLabelSelector()
.putMatchLabelsItem(DOMAINUID_LABEL, getInputs().getDomainUID())
.putMatchLabelsItem(DOMAINNAME_LABEL, getInputs().getDomainName())
.putMatchLabelsItem(APP_LABEL, getApacheAppName()))
.template(newPodTemplateSpec()
.metadata(newObjectMeta()
.putLabelsItem(DOMAINUID_LABEL, getInputs().getDomainUID())
.putLabelsItem(DOMAINNAME_LABEL, getInputs().getDomainName())
.putLabelsItem(APP_LABEL, getApacheAppName()))
.spec(newPodSpec()
.serviceAccountName(getApacheName())
.terminationGracePeriodSeconds(60L)
.addContainersItem(newContainer()
.name(getApacheName())
.image("12213-apache:latest")
.imagePullPolicy("Never")
.addEnvItem(newEnvVar()
.name("WEBLOGIC_CLUSTER")
.value(getInputs().getDomainUID() + "-cluster-" + getClusterNameLC() + ":" + getInputs().getManagedServerPort()))
.addEnvItem(newEnvVar()
.name("LOCATION")
.value(getInputs().getLoadBalancerAppPrepath()))
.addEnvItem(newEnvVar()
.name("WEBLOGIC_HOST")
.value(getInputs().getDomainUID() + "-" + getInputs().getAdminServerName()))
.addEnvItem(newEnvVar()
.name("WEBLOGIC_PORT")
.value(getInputs().getAdminPort()))
.readinessProbe(newProbe()
.tcpSocket(newTCPSocketAction()
.port(newIntOrString(80)))
.failureThreshold(1)
.initialDelaySeconds(10)
.periodSeconds(10)
.successThreshold(1)
.timeoutSeconds(2))
.livenessProbe(newProbe()
.tcpSocket(newTCPSocketAction()
.port(newIntOrString(80)))
.failureThreshold(3)
.initialDelaySeconds(10)
.periodSeconds(10)
.successThreshold(1)
.timeoutSeconds(2))
)
)
)
);
}

protected ExtensionsV1beta1Deployment getActualTraefikDeployment() {
return getTraefikYaml().getTraefikDeployment();
}
Expand Down Expand Up @@ -490,7 +573,7 @@ protected ExtensionsV1beta1Deployment getExpectedTraefikDeployment() {
}

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

@Test
public void generatesCorrect_traefikService() throws Exception {
public void generatesCorrect_loadBalancerService() throws Exception {
assertThat(
getActualTraefikService(),
yamlEqualTo(getExpectedTraefikService()));
}

protected V1Service getActualApacheService() {
return getApacheYaml().getApacheService();
}

protected V1Service getExpectedApacheService() {
return
newService()
.metadata(newObjectMeta()
.name(getApacheName())
.namespace(getInputs().getNamespace())
.putLabelsItem(DOMAINUID_LABEL, getInputs().getDomainUID())
.putLabelsItem(DOMAINNAME_LABEL, getInputs().getDomainName()))
.spec(newServiceSpec()
.type("NodePort")
.putSelectorItem(DOMAINUID_LABEL, getInputs().getDomainUID())
.putSelectorItem(DOMAINNAME_LABEL, getInputs().getDomainName())
.putSelectorItem(APP_LABEL, getApacheAppName())
.addPortsItem(newServicePort()
.name("rest-https")
.port(80)
.nodePort(Integer.parseInt(getInputs().getLoadBalancerWebPort()))));
}

protected V1Service getActualTraefikService() {
return getTraefikYaml().getTraefikService();
}
Expand All @@ -560,7 +666,7 @@ protected V1Service getExpectedTraefikService() {
}

@Test
public void generatesCorrect_traefikDashboardService() throws Exception {
public void generatesCorrect_loadBalancerDashboardService() throws Exception {
assertThat(
getActualTraefikDashboardService(),
yamlEqualTo(getExpectedTraefikDashboardService()));
Expand Down Expand Up @@ -591,12 +697,33 @@ protected V1Service getExpectedTraefikDashboardService() {
}

@Test
public void generatesCorrect_traefikClusterRole() throws Exception {
public void generatesCorrect_loadBalancerClusterRole() throws Exception {
assertThat(
getActualTraefikClusterRole(),
yamlEqualTo(getExpectedTraefikClusterRole()));
}

protected V1beta1ClusterRole getActualApacheClusterRole() {
return getApacheSecurityYaml().getApacheClusterRole();
}

protected V1beta1ClusterRole getExpectedApacheClusterRole() {
return
newClusterRole()
.metadata(newObjectMeta()
.name(getApacheName())
.putLabelsItem(DOMAINUID_LABEL, getInputs().getDomainUID())
.putLabelsItem(DOMAINNAME_LABEL, getInputs().getDomainName()))
.addRulesItem(newPolicyRule()
.addApiGroupsItem("")
.resources(asList("pods", "services", "endpoints", "secrets"))
.verbs(asList("get", "list", "watch")))
.addRulesItem(newPolicyRule()
.addApiGroupsItem("extensions")
.addResourcesItem("ingresses")
.verbs(asList("get", "list", "watch")));
}

protected V1beta1ClusterRole getActualTraefikClusterRole() {
return getTraefikSecurityYaml().getTraefikClusterRole();
}
Expand All @@ -620,12 +747,32 @@ protected V1beta1ClusterRole getExpectedTraefikClusterRole() {
}

@Test
public void generatesCorrect_traefikDashboardClusterRoleBinding() throws Exception {
public void generatesCorrect_loadBalancerClusterRoleBinding() throws Exception {
assertThat(
getActualTraefikDashboardClusterRoleBinding(),
yamlEqualTo(getExpectedTraefikDashboardClusterRoleBinding()));
}

protected V1beta1ClusterRoleBinding getActualApacheClusterRoleBinding() {
return getApacheSecurityYaml().getApacheClusterRoleBinding();
}

protected V1beta1ClusterRoleBinding getExpectedApacheClusterRoleBinding() {
return
newClusterRoleBinding()
.metadata(newObjectMeta()
.name(getApacheName())
.putLabelsItem(DOMAINUID_LABEL, getInputs().getDomainUID())
.putLabelsItem(DOMAINNAME_LABEL, getInputs().getDomainName()))
.addSubjectsItem(newSubject()
.kind("ServiceAccount")
.name(getApacheName())
.namespace(getInputs().getNamespace()))
.roleRef(newRoleRef()
.name(getApacheName())
.apiGroup("rbac.authorization.k8s.io"));
}

protected V1beta1ClusterRoleBinding getActualTraefikDashboardClusterRoleBinding() {
return getTraefikSecurityYaml().getTraefikDashboardClusterRoleBinding();
}
Expand Down Expand Up @@ -709,4 +856,8 @@ protected String getClusterLCScope() {
protected String getClusterNameLC() {
return getInputs().getClusterName().toLowerCase();
}

protected String getApacheName() { return getInputs().getDomainUID() + "-" + getApacheAppName(); }

protected String getApacheAppName() { return "apache-webtier";}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@
import io.kubernetes.client.models.V1PersistentVolume;
import static oracle.kubernetes.operator.create.CreateDomainInputs.*;
import static oracle.kubernetes.operator.create.KubernetesArtifactUtils.*;
import static oracle.kubernetes.operator.create.YamlUtils.yamlEqualTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertNull;

import oracle.kubernetes.weblogic.domain.v1.Domain;
import org.junit.BeforeClass;
import org.junit.Test;

/**
* Tests that the all artifacts in the yaml files that create-weblogic-domain.sh
Expand All @@ -26,7 +32,8 @@ public static void setup() throws Exception {
.exposeAdminT3Channel("true")
.clusterType("CONFIGURED")
.weblogicImagePullSecretName("test-weblogic-image-pull-secret-name")
.loadBalancer(LOAD_BALANCER_TRAEFIK)
.loadBalancer(LOAD_BALANCER_APACHE)
.loadBalancerAppPrepath("/loadBalancerAppPrePath")
.weblogicDomainStorageType(STORAGE_TYPE_NFS)
.productionModeEnabled("true")
);
Expand Down Expand Up @@ -58,4 +65,61 @@ protected V1PersistentVolume getExpectedWeblogicDomainPersistentVolume() {
.path(getInputs().getWeblogicDomainStoragePath()));
return expected;
}

@Override
public void generatesCorrect_loadBalancerDeployment() throws Exception {
assertThat(
getActualApacheDeployment(),
yamlEqualTo(getExpectedApacheDeployment()));
}

@Override
public void generatesCorrect_loadBalancerServiceAccount() throws Exception {
assertThat(
getActualApacheServiceAccount(),
yamlEqualTo(getExpectedApacheServiceAccount())); }

@Override
public void generatesCorrect_loadBalancerConfigMap() throws Exception {
// No config map in generated yaml for LOAD_BALANCER_APACHE
}

@Override
public void generatesCorrect_loadBalancerService() throws Exception {
assertThat(
getActualApacheService(),
yamlEqualTo(getExpectedApacheService()));
}

@Override
public void generatesCorrect_loadBalancerDashboardService() throws Exception {
// No dashboard service in generated yaml for LOAD_BALANCER_APACHE
}

@Override
public void generatesCorrect_loadBalancerClusterRole() throws Exception {
assertThat(
getActualApacheClusterRole(),
yamlEqualTo(getExpectedApacheClusterRole())); }

@Override
public void generatesCorrect_loadBalancerClusterRoleBinding() throws Exception {
assertThat(
getActualApacheClusterRoleBinding(),
yamlEqualTo(getExpectedApacheClusterRoleBinding()));
}

@Override
public void loadBalancerSecurityYaml_hasCorrectNumberOfObjects() throws Exception {
assertThat(
getApacheSecurityYaml().getObjectCount(),
is(getApacheSecurityYaml().getExpectedObjectCount()));
}

@Override
public void loadBalancerYaml_hasCorrectNumberOfObjects() throws Exception {
assertThat(
getApacheYaml().getObjectCount(),
is(getApacheYaml().getExpectedObjectCount()));
}
}
Loading