3
3
4
4
import static java .util .Arrays .asList ;
5
5
6
- import io .kubernetes .client .models .V1Service ;
7
6
import static oracle .kubernetes .operator .create .KubernetesArtifactUtils .*;
8
7
import static oracle .kubernetes .operator .create .YamlUtils .*;
9
8
import static org .hamcrest .MatcherAssert .assertThat ;
@@ -64,15 +63,19 @@ public void generatesCorrect_weblogicOperatorYaml_externalOperatorService() thro
64
63
65
64
@ Test
66
65
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 ));
73
66
assertThat (
74
67
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 )))));
76
79
}
77
80
78
81
@ Test
@@ -86,15 +89,21 @@ public void generatesCorrect_weblogicOperatorSecurityYaml_operatorNamespace() th
86
89
public void generatesCorrect_weblogicOperatorSecurityYaml_operatorServiceAccount () throws Exception {
87
90
assertThat (
88
91
weblogicOperatorSecurityYaml ().getOperatorServiceAccount (),
89
- yamlEqualTo (newServiceAccount (inputs .getServiceAccount (), inputs .getNamespace ())));
92
+ yamlEqualTo (
93
+ newServiceAccount ()
94
+ .metadata (newObjectMeta ()
95
+ .name (inputs .getServiceAccount ())
96
+ .namespace (inputs .getNamespace ()))));
90
97
}
91
98
92
99
@ Test
93
100
public void generatesCorrect_weblogicOperatorSecurityYaml_weblogicOperatorClusterRole () throws Exception {
94
101
assertThat (
95
102
weblogicOperatorSecurityYaml ().getWeblogicOperatorClusterRole (),
96
103
yamlEqualTo (
97
- newClusterRole ("weblogic-operator-cluster-role" )
104
+ newClusterRole ()
105
+ .metadata (newObjectMeta ()
106
+ .name ("weblogic-operator-cluster-role" ))
98
107
.addRulesItem (newPolicyRule ()
99
108
.addApiGroupsItem ("" )
100
109
.resources (asList ("namespaces" , "persistentvolumes" ))
@@ -122,7 +131,9 @@ public void generatesCorrect_weblogicOperatorSecurityYaml_weblogicOperatorCluste
122
131
assertThat (
123
132
weblogicOperatorSecurityYaml ().getWeblogicOperatorClusterRoleNonResource (),
124
133
yamlEqualTo (
125
- newClusterRole ("weblogic-operator-cluster-role-nonresource" )
134
+ newClusterRole ()
135
+ .metadata (newObjectMeta ()
136
+ .name ("weblogic-operator-cluster-role-nonresource" ))
126
137
.addRulesItem (newPolicyRule ()
127
138
.addNonResourceURLsItem ("/version/*" )
128
139
.addVerbsItem ("get" ))));
@@ -133,47 +144,81 @@ public void generatesCorrect_weblogicOperatorSecurityYaml_operatorRoleBinding()
133
144
assertThat (
134
145
weblogicOperatorSecurityYaml ().getOperatorRoleBinding (),
135
146
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" ))));
139
158
}
140
159
141
160
@ Test
142
161
public void generatesCorrect_weblogicOperatorSecurityYaml_operatorRoleBindingNonResource () throws Exception {
143
162
assertThat (
144
163
weblogicOperatorSecurityYaml ().getOperatorRoleBindingNonResource (),
145
164
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" ))));
149
176
}
150
177
151
178
@ Test
152
179
public void generatesCorrect_weblogicOperatorSecurityYaml_operatorRoleBindingDiscovery () throws Exception {
153
180
assertThat (
154
181
weblogicOperatorSecurityYaml ().getOperatorRoleBindingDiscovery (),
155
182
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" ))));
159
194
}
160
195
161
196
@ Test
162
197
public void generatesCorrect_weblogicOperatorSecurityYaml_operatorRoleBindingAuthDelegator () throws Exception {
163
198
assertThat (
164
199
weblogicOperatorSecurityYaml ().getOperatorRoleBindingAuthDelegator (),
165
200
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" ))));
169
212
}
170
213
171
214
@ Test
172
215
public void generatesCorrect_weblogicOperatorSecurityYaml_weblogicOperatorNamespaceRole () throws Exception {
173
216
assertThat (
174
217
weblogicOperatorSecurityYaml ().getWeblogicOperatorNamespaceRole (),
175
218
yamlEqualTo (
176
- newClusterRole ("weblogic-operator-namespace-role" )
219
+ newClusterRole ()
220
+ .metadata (newObjectMeta ()
221
+ .name ("weblogic-operator-namespace-role" ))
177
222
.addRulesItem (newPolicyRule ()
178
223
.addApiGroupsItem ("" )
179
224
.resources (asList ("secrets" , "persistentvolumeclaims" ))
@@ -203,9 +248,18 @@ public void generatesCorrect_weblogicOperatorSecurityYaml_targetNamespaces_weblo
203
248
assertThat (
204
249
weblogicOperatorSecurityYaml ().getWeblogicOperatorRoleBinding (ns ),
205
250
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 ("" ))));
209
263
}
210
264
}
211
265
0 commit comments