Skip to content

Commit e3c49f2

Browse files
committed
Continue to fill in generated domain yaml file tests
1 parent c05256b commit e3c49f2

11 files changed

+837
-119
lines changed

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

Lines changed: 349 additions & 25 deletions
Large diffs are not rendered by default.
Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
// Copyright 2018, Oracle Corporation and/or its affiliates. All rights reserved.
22
package oracle.kubernetes.operator.create;
33

4+
import io.kubernetes.client.models.V1Job;
5+
import static oracle.kubernetes.operator.create.KubernetesArtifactUtils.*;
46
import static oracle.kubernetes.operator.create.YamlUtils.*;
7+
import oracle.kubernetes.weblogic.domain.v1.Domain;
58
import static org.hamcrest.MatcherAssert.assertThat;
69
import org.junit.AfterClass;
710
import org.junit.BeforeClass;
811
import org.junit.Test;
912

1013
/**
1114
* Tests that the all artifacts in the yaml files that create-domain-operator.sh
12-
* creates are correct when the admin node port is disabled and t3 channel is disable,
13-
* and there is no image pull secret.
15+
* creates are correct when the admin node port is enabled, the t3 channel is enabled,
16+
* there is no image pull secret, and production mode is enabled
1417
*/
1518
public class CreateDomainGeneratedFilesOptionalFeaturesEnabledTest {
1619

1720
private static CreateDomainInputs inputs;
1821
private static GeneratedDomainYamlFiles generatedFiles;
1922

20-
private static final String TEST_WEBLOGIC_IMAGE_PULL_SECRET_NAME = "test-weblogic-image-pull-secret-name";
21-
2223
@BeforeClass
2324
public static void setup() throws Exception {
2425
inputs =
2526
CreateDomainInputs.newInputs()
2627
.exposeAdminNodePort("true")
2728
.exposeAdminT3Channel("true")
28-
.imagePullSecretName(TEST_WEBLOGIC_IMAGE_PULL_SECRET_NAME);
29+
.imagePullSecretName("test-weblogic-image-pull-secret-name")
30+
.productionModeEnabled("true");
2931
generatedFiles = GeneratedDomainYamlFiles.generateDomainYamlFiles(inputs);
3032
}
3133

@@ -38,13 +40,22 @@ public static void tearDown() throws Exception {
3840

3941
@Test
4042
public void generatesCorrect_createWeblogicDomainYaml_createWeblogicDomainJob() throws Exception {
41-
//System.out.println("MOREAUT_DEBUG create domain job =\n" + newYaml().dump(generatedFiles.getCreateWeblogicDomainJobYaml().getCreateWeblogicDomainJob()));
42-
// TBD
43+
V1Job want = generatedFiles.getCreateWeblogicDomainJobYaml().getExpectedBaseCreateWeblogicDomainJob();
44+
want.getSpec().getTemplate().getSpec().addImagePullSecretsItem(newLocalObjectReference()
45+
.name(inputs.getImagePullSecretName()));
46+
assertThat(
47+
generatedFiles.getCreateWeblogicDomainJobYaml().getCreateWeblogicDomainJob(),
48+
yamlEqualTo(want));
4349
}
4450

4551
@Test
4652
public void generatesCorrect_domainCustomResourceYaml_domain() throws Exception {
47-
//System.out.println("MOREAUT_DEBUG domain custom resource =\n" + newYaml().dump(generatedFiles.getDomainCustomResourceYaml().getDomain()));
48-
// TBD
53+
Domain want = generatedFiles.getDomainCustomResourceYaml().getBaseExpectedDomain();
54+
want.getSpec().withExportT3Channels(newStringList().addElement("T3Channel"));
55+
// there is only one server startup item in the base domain config - set its node port:
56+
want.getSpec().getServerStartup().get(0).withNodePort(Integer.parseInt(inputs.getAdminNodePort()));
57+
assertThat(
58+
generatedFiles.getDomainCustomResourceYaml().getDomain(),
59+
yamlEqualTo(want));
4960
}
5061
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public static CreateDomainInputs newInputs() throws Exception {
6666
.domainName("TestDomain")
6767
.domainUid("test-domain-uid")
6868
.javaOptions("TestJavaOptions")
69+
.loadBalancerAdminPort("31315")
70+
.loadBalancerWebPort("31305")
6971
.managedServerCount("4")
7072
.managedServerNameBase("TestManagedServer")
7173
.managedServerPort("8002")

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

Lines changed: 81 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import static java.util.Arrays.asList;
55

6-
import io.kubernetes.client.models.V1Service;
76
import static oracle.kubernetes.operator.create.KubernetesArtifactUtils.*;
87
import static oracle.kubernetes.operator.create.YamlUtils.*;
98
import static org.hamcrest.MatcherAssert.assertThat;
@@ -64,15 +63,19 @@ public void generatesCorrect_weblogicOperatorYaml_externalOperatorService() thro
6463

6564
@Test
6665
public void generatesCorrect_weblogicOperatorYaml_internalOperatorService() throws Exception {
67-
V1Service want =
68-
newService("internal-weblogic-operator-service", inputs.getNamespace());
69-
want.getSpec()
70-
.type("ClusterIP")
71-
.putSelectorItem("app", "weblogic-operator")
72-
.addPortsItem(newServicePort("rest-https").port(8082));
7366
assertThat(
7467
weblogicOperatorYaml().getInternalOperatorService(),
75-
yamlEqualTo(want));
68+
yamlEqualTo(
69+
newService()
70+
.metadata(newObjectMeta()
71+
.name("internal-weblogic-operator-service")
72+
.namespace(inputs.getNamespace()))
73+
.spec(newServiceSpec()
74+
.type("ClusterIP")
75+
.putSelectorItem("app", "weblogic-operator")
76+
.addPortsItem(newServicePort()
77+
.name("rest-https")
78+
.port(8082)))));
7679
}
7780

7881
@Test
@@ -86,15 +89,21 @@ public void generatesCorrect_weblogicOperatorSecurityYaml_operatorNamespace() th
8689
public void generatesCorrect_weblogicOperatorSecurityYaml_operatorServiceAccount() throws Exception {
8790
assertThat(
8891
weblogicOperatorSecurityYaml().getOperatorServiceAccount(),
89-
yamlEqualTo(newServiceAccount(inputs.getServiceAccount(), inputs.getNamespace())));
92+
yamlEqualTo(
93+
newServiceAccount()
94+
.metadata(newObjectMeta()
95+
.name(inputs.getServiceAccount())
96+
.namespace(inputs.getNamespace()))));
9097
}
9198

9299
@Test
93100
public void generatesCorrect_weblogicOperatorSecurityYaml_weblogicOperatorClusterRole() throws Exception {
94101
assertThat(
95102
weblogicOperatorSecurityYaml().getWeblogicOperatorClusterRole(),
96103
yamlEqualTo(
97-
newClusterRole("weblogic-operator-cluster-role")
104+
newClusterRole()
105+
.metadata(newObjectMeta()
106+
.name("weblogic-operator-cluster-role"))
98107
.addRulesItem(newPolicyRule()
99108
.addApiGroupsItem("")
100109
.resources(asList("namespaces", "persistentvolumes"))
@@ -122,7 +131,9 @@ public void generatesCorrect_weblogicOperatorSecurityYaml_weblogicOperatorCluste
122131
assertThat(
123132
weblogicOperatorSecurityYaml().getWeblogicOperatorClusterRoleNonResource(),
124133
yamlEqualTo(
125-
newClusterRole("weblogic-operator-cluster-role-nonresource")
134+
newClusterRole()
135+
.metadata(newObjectMeta()
136+
.name("weblogic-operator-cluster-role-nonresource"))
126137
.addRulesItem(newPolicyRule()
127138
.addNonResourceURLsItem("/version/*")
128139
.addVerbsItem("get"))));
@@ -133,47 +144,81 @@ public void generatesCorrect_weblogicOperatorSecurityYaml_operatorRoleBinding()
133144
assertThat(
134145
weblogicOperatorSecurityYaml().getOperatorRoleBinding(),
135146
yamlEqualTo(
136-
newClusterRoleBinding(inputs.getNamespace() + "-operator-rolebinding")
137-
.addSubjectsItem(newSubject("ServiceAccount", inputs.getServiceAccount(), inputs.getNamespace(), ""))
138-
.roleRef(newRoleRef("weblogic-operator-cluster-role", "rbac.authorization.k8s.io"))));
147+
newClusterRoleBinding()
148+
.metadata(newObjectMeta()
149+
.name(inputs.getNamespace() + "-operator-rolebinding"))
150+
.addSubjectsItem(newSubject()
151+
.kind("ServiceAccount")
152+
.name(inputs.getServiceAccount())
153+
.namespace(inputs.getNamespace())
154+
.apiGroup(""))
155+
.roleRef(newRoleRef()
156+
.name("weblogic-operator-cluster-role")
157+
.apiGroup("rbac.authorization.k8s.io"))));
139158
}
140159

141160
@Test
142161
public void generatesCorrect_weblogicOperatorSecurityYaml_operatorRoleBindingNonResource() throws Exception {
143162
assertThat(
144163
weblogicOperatorSecurityYaml().getOperatorRoleBindingNonResource(),
145164
yamlEqualTo(
146-
newClusterRoleBinding(inputs.getNamespace() + "-operator-rolebinding-nonresource")
147-
.addSubjectsItem(newSubject("ServiceAccount", inputs.getServiceAccount(), inputs.getNamespace(), ""))
148-
.roleRef(newRoleRef("weblogic-operator-cluster-role-nonresource", "rbac.authorization.k8s.io"))));
165+
newClusterRoleBinding()
166+
.metadata(newObjectMeta()
167+
.name(inputs.getNamespace() + "-operator-rolebinding-nonresource"))
168+
.addSubjectsItem(newSubject()
169+
.kind("ServiceAccount")
170+
.name(inputs.getServiceAccount())
171+
.namespace(inputs.getNamespace())
172+
.apiGroup(""))
173+
.roleRef(newRoleRef()
174+
.name("weblogic-operator-cluster-role-nonresource")
175+
.apiGroup("rbac.authorization.k8s.io"))));
149176
}
150177

151178
@Test
152179
public void generatesCorrect_weblogicOperatorSecurityYaml_operatorRoleBindingDiscovery() throws Exception {
153180
assertThat(
154181
weblogicOperatorSecurityYaml().getOperatorRoleBindingDiscovery(),
155182
yamlEqualTo(
156-
newClusterRoleBinding(inputs.getNamespace() + "-operator-rolebinding-discovery")
157-
.addSubjectsItem(newSubject("ServiceAccount", inputs.getServiceAccount(), inputs.getNamespace(), ""))
158-
.roleRef(newRoleRef("system:discovery", "rbac.authorization.k8s.io"))));
183+
newClusterRoleBinding()
184+
.metadata(newObjectMeta()
185+
.name(inputs.getNamespace() + "-operator-rolebinding-discovery"))
186+
.addSubjectsItem(newSubject()
187+
.kind("ServiceAccount")
188+
.name(inputs.getServiceAccount())
189+
.namespace(inputs.getNamespace())
190+
.apiGroup(""))
191+
.roleRef(newRoleRef()
192+
.name("system:discovery")
193+
.apiGroup("rbac.authorization.k8s.io"))));
159194
}
160195

161196
@Test
162197
public void generatesCorrect_weblogicOperatorSecurityYaml_operatorRoleBindingAuthDelegator() throws Exception {
163198
assertThat(
164199
weblogicOperatorSecurityYaml().getOperatorRoleBindingAuthDelegator(),
165200
yamlEqualTo(
166-
newClusterRoleBinding(inputs.getNamespace() + "-operator-rolebinding-auth-delegator")
167-
.addSubjectsItem(newSubject("ServiceAccount", inputs.getServiceAccount(), inputs.getNamespace(), ""))
168-
.roleRef(newRoleRef("system:auth-delegator", "rbac.authorization.k8s.io"))));
201+
newClusterRoleBinding()
202+
.metadata(newObjectMeta()
203+
.name(inputs.getNamespace() + "-operator-rolebinding-auth-delegator"))
204+
.addSubjectsItem(newSubject()
205+
.kind("ServiceAccount")
206+
.name(inputs.getServiceAccount())
207+
.namespace(inputs.getNamespace())
208+
.apiGroup(""))
209+
.roleRef(newRoleRef()
210+
.name("system:auth-delegator")
211+
.apiGroup("rbac.authorization.k8s.io"))));
169212
}
170213

171214
@Test
172215
public void generatesCorrect_weblogicOperatorSecurityYaml_weblogicOperatorNamespaceRole() throws Exception {
173216
assertThat(
174217
weblogicOperatorSecurityYaml().getWeblogicOperatorNamespaceRole(),
175218
yamlEqualTo(
176-
newClusterRole("weblogic-operator-namespace-role")
219+
newClusterRole()
220+
.metadata(newObjectMeta()
221+
.name("weblogic-operator-namespace-role"))
177222
.addRulesItem(newPolicyRule()
178223
.addApiGroupsItem("")
179224
.resources(asList("secrets", "persistentvolumeclaims"))
@@ -203,9 +248,18 @@ public void generatesCorrect_weblogicOperatorSecurityYaml_targetNamespaces_weblo
203248
assertThat(
204249
weblogicOperatorSecurityYaml().getWeblogicOperatorRoleBinding(ns),
205250
yamlEqualTo(
206-
newRoleBinding("weblogic-operator-rolebinding", ns)
207-
.addSubjectsItem(newSubject("ServiceAccount", inputs.getServiceAccount(), inputs.getNamespace(), ""))
208-
.roleRef(newRoleRef("weblogic-operator-namespace-role", ""))));
251+
newRoleBinding()
252+
.metadata(newObjectMeta()
253+
.name("weblogic-operator-rolebinding")
254+
.namespace(ns))
255+
.addSubjectsItem(newSubject()
256+
.kind("ServiceAccount")
257+
.name(inputs.getServiceAccount())
258+
.namespace(inputs.getNamespace())
259+
.apiGroup(""))
260+
.roleRef(newRoleRef()
261+
.name("weblogic-operator-namespace-role")
262+
.apiGroup(""))));
209263
}
210264
}
211265

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
*/
1818
public class CreateOperatorGeneratedFilesHaveImagePullSecretTest {
1919

20-
private static final String TEST_OPERATOR_IMAGE_PULL_SECRET_NAME = "test-operator-image-pull-secret-name";
21-
20+
private static CreateOperatorInputs inputs;
2221
private static GeneratedOperatorYamlFiles generatedFiles;
2322

2423
@BeforeClass
2524
public static void setup() throws Exception {
26-
CreateOperatorInputs inputs =
27-
CreateOperatorInputs.newInputs().imagePullSecretName(TEST_OPERATOR_IMAGE_PULL_SECRET_NAME);
25+
inputs =
26+
CreateOperatorInputs.newInputs()
27+
.imagePullSecretName("test-operator-image-pull-secret-name");
2828
generatedFiles = GeneratedOperatorYamlFiles.generateOperatorYamlFiles(inputs);
2929
}
3030

@@ -40,7 +40,7 @@ public void generatesCorrect_weblogicOperatorYaml_operatorDeployment() throws Ex
4040
ExtensionsV1beta1Deployment want =
4141
weblogicOperatorYaml().getBaseExpectedOperatorDeployment();
4242
want.getSpec().getTemplate().getSpec().addImagePullSecretsItem(newLocalObjectReference()
43-
.name(TEST_OPERATOR_IMAGE_PULL_SECRET_NAME));
43+
.name(inputs.getImagePullSecretName()));
4444
assertThat(
4545
weblogicOperatorYaml().getOperatorDeployment(),
4646
yamlEqualTo(want));

0 commit comments

Comments
 (0)