6
6
import java .text .DateFormat ;
7
7
import java .text .SimpleDateFormat ;
8
8
import java .util .Arrays ;
9
- import java .util .Base64 ;
10
9
import java .util .Collections ;
11
10
import java .util .Date ;
12
11
import java .util .HashMap ;
48
47
49
48
import static java .util .concurrent .TimeUnit .MINUTES ;
50
49
import static java .util .concurrent .TimeUnit .SECONDS ;
50
+ import static oracle .weblogic .kubernetes .TestConstants .OPERATOR_CHART_DIR ;
51
+ import static oracle .weblogic .kubernetes .TestConstants .OPERATOR_RELEASE_NAME ;
52
+ import static oracle .weblogic .kubernetes .TestConstants .REPO_DUMMY_VALUE ;
53
+ import static oracle .weblogic .kubernetes .TestConstants .REPO_EMAIL ;
54
+ import static oracle .weblogic .kubernetes .TestConstants .REPO_NAME ;
55
+ import static oracle .weblogic .kubernetes .TestConstants .REPO_PASSWORD ;
56
+ import static oracle .weblogic .kubernetes .TestConstants .REPO_REGISTRY ;
57
+ import static oracle .weblogic .kubernetes .TestConstants .REPO_SECRET_NAME ;
58
+ import static oracle .weblogic .kubernetes .TestConstants .REPO_USERNAME ;
51
59
import static oracle .weblogic .kubernetes .actions .ActionConstants .ARCHIVE_DIR ;
52
60
import static oracle .weblogic .kubernetes .actions .ActionConstants .MODEL_DIR ;
53
61
import static oracle .weblogic .kubernetes .actions .ActionConstants .WDT_VERSION ;
54
62
import static oracle .weblogic .kubernetes .actions .ActionConstants .WIT_BUILD_DIR ;
55
63
import static oracle .weblogic .kubernetes .actions .TestActions .buildAppArchive ;
64
+ import static oracle .weblogic .kubernetes .actions .TestActions .createDockerConfigJson ;
56
65
import static oracle .weblogic .kubernetes .actions .TestActions .createDomainCustomResource ;
57
66
import static oracle .weblogic .kubernetes .actions .TestActions .createMiiImage ;
58
67
import static oracle .weblogic .kubernetes .actions .TestActions .createSecret ;
65
74
import static oracle .weblogic .kubernetes .actions .TestActions .deleteServiceAccount ;
66
75
import static oracle .weblogic .kubernetes .actions .TestActions .dockerLogin ;
67
76
import static oracle .weblogic .kubernetes .actions .TestActions .dockerPush ;
68
- import static oracle .weblogic .kubernetes .actions .TestActions .helmList ;
77
+ import static oracle .weblogic .kubernetes .actions .TestActions .getOperatorImageName ;
69
78
import static oracle .weblogic .kubernetes .actions .TestActions .installOperator ;
70
79
import static oracle .weblogic .kubernetes .actions .TestActions .uninstallOperator ;
71
- import static oracle .weblogic .kubernetes .assertions .TestAssertions .dockerImageExists ;
80
+ import static oracle .weblogic .kubernetes .assertions .TestAssertions .doesImageExist ;
72
81
import static oracle .weblogic .kubernetes .assertions .TestAssertions .domainExists ;
82
+ import static oracle .weblogic .kubernetes .assertions .TestAssertions .isHelmReleaseDeployed ;
73
83
import static oracle .weblogic .kubernetes .assertions .TestAssertions .operatorIsRunning ;
74
84
import static oracle .weblogic .kubernetes .assertions .TestAssertions .podExists ;
75
85
import static oracle .weblogic .kubernetes .assertions .TestAssertions .podReady ;
76
86
import static oracle .weblogic .kubernetes .assertions .TestAssertions .serviceExists ;
77
87
import static oracle .weblogic .kubernetes .utils .FileUtils .checkDirectory ;
78
88
import static org .awaitility .Awaitility .with ;
79
89
import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
90
+ import static org .junit .jupiter .api .Assertions .assertFalse ;
80
91
import static org .junit .jupiter .api .Assertions .assertNotNull ;
81
92
import static org .junit .jupiter .api .Assertions .assertTrue ;
82
93
86
97
@ IntegrationTest
87
98
class ItMiiDomain implements LoggedTest {
88
99
89
- // operator constants
90
- private static final String OPERATOR_RELEASE_NAME = "weblogic-operator" ;
91
- private static final String OPERATOR_CHART_DIR =
92
- "../kubernetes/charts/weblogic-operator" ;
93
- private static final String OPERATOR_IMAGE =
94
- "oracle/weblogic-kubernetes-operator:3.0.0" ;
95
- //"phx.ocir.io/weblogick8s/weblogic-kubernetes-operator:develop";
96
-
97
100
// mii constants
98
101
private static final String WDT_MODEL_FILE = "model1-wls.yaml" ;
99
102
private static final String MII_IMAGE_NAME = "mii-image" ;
@@ -108,14 +111,10 @@ class ItMiiDomain implements LoggedTest {
108
111
private static String opNamespace = null ;
109
112
private static String domainNamespace = null ;
110
113
private static ConditionFactory withStandardRetryPolicy = null ;
114
+ private static String dockerConfigJson = "" ;
111
115
112
116
private String domainUid = "domain1" ;
113
- private String repoSecretName = "reposecret" ;
114
117
private String miiImage = null ;
115
- private String repoRegistry = "dummy" ;
116
- private String repoUserName = "dummy" ;
117
- private String repoPassword = "dummy" ;
118
- private String repoEmail = "dummy" ;
119
118
120
119
/**
121
120
* Install Operator.
@@ -148,6 +147,33 @@ public static void initAll(@Namespaces(2) List<String> namespaces) {
148
147
.name (serviceAccountName ))));
149
148
logger .info ("Created service account: {0}" , serviceAccountName );
150
149
150
+ // get Operator image name
151
+ String operatorImage = getOperatorImageName ();
152
+ assertFalse (operatorImage .isEmpty (), "Operator image name can not be empty" );
153
+ logger .info ("Operator image name {0}" , operatorImage );
154
+
155
+ // Create docker registry secret in the operator namespace to pull the image from repository
156
+ logger .info ("Creating docker registry secret in namespace {0}" , opNamespace );
157
+ JsonObject dockerConfigJsonObject = createDockerConfigJson (
158
+ REPO_USERNAME , REPO_PASSWORD , REPO_EMAIL , REPO_REGISTRY );
159
+ dockerConfigJson = dockerConfigJsonObject .toString ();
160
+
161
+ // Create the V1Secret configuration
162
+ V1Secret repoSecret = new V1Secret ()
163
+ .metadata (new V1ObjectMeta ()
164
+ .name (REPO_SECRET_NAME )
165
+ .namespace (opNamespace ))
166
+ .type ("kubernetes.io/dockerconfigjson" )
167
+ .putDataItem (".dockerconfigjson" , dockerConfigJson .getBytes ());
168
+
169
+ boolean secretCreated = assertDoesNotThrow (() -> createSecret (repoSecret ),
170
+ String .format ("createSecret failed for %s" , REPO_SECRET_NAME ));
171
+ assertTrue (secretCreated , String .format ("createSecret failed while creating secret %s in namespace" ,
172
+ REPO_SECRET_NAME , opNamespace ));
173
+
174
+ // map with secret
175
+ Map <String , Object > secretNameMap = new HashMap <String , Object >();
176
+ secretNameMap .put ("name" , REPO_SECRET_NAME );
151
177
// helm install parameters
152
178
opHelmParams = new HelmParams ()
153
179
.releaseName (OPERATOR_RELEASE_NAME )
@@ -158,7 +184,8 @@ public static void initAll(@Namespaces(2) List<String> namespaces) {
158
184
OperatorParams opParams =
159
185
new OperatorParams ()
160
186
.helmParams (opHelmParams )
161
- .image (OPERATOR_IMAGE )
187
+ .image (operatorImage )
188
+ .imagePullSecrets (secretNameMap )
162
189
.domainNamespaces (Arrays .asList (domainNamespace ))
163
190
.serviceAccount (serviceAccountName );
164
191
@@ -168,9 +195,14 @@ public static void initAll(@Namespaces(2) List<String> namespaces) {
168
195
String .format ("Operator install failed in namespace %s" , opNamespace ));
169
196
logger .info ("Operator installed in namespace {0}" , opNamespace );
170
197
171
- // list helm releases
172
- logger .info ("List helm releases in namespace {0}" , opNamespace );
173
- helmList (opHelmParams );
198
+ // list helm releases matching Operator release name in operator namespace
199
+ logger .info ("Checking Operator release {0} status in namespace {1}" ,
200
+ OPERATOR_RELEASE_NAME , opNamespace );
201
+ assertTrue (isHelmReleaseDeployed (OPERATOR_RELEASE_NAME , opNamespace ),
202
+ String .format ("Operator release %s is not in deployed status in namespace %s" ,
203
+ OPERATOR_RELEASE_NAME , opNamespace ));
204
+ logger .info ("Operator release {0} status is deployed in namespace {1}" ,
205
+ OPERATOR_RELEASE_NAME , opNamespace );
174
206
175
207
// check operator is running
176
208
logger .info ("Check Operator pod is running in namespace {0}" , opNamespace );
@@ -200,36 +232,25 @@ public void testCreateMiiDomain() {
200
232
miiImage = createImageAndVerify ();
201
233
202
234
// push the image to OCIR to make the test work in multi node cluster
203
- if (System .getenv ("REPO_REGISTRY" ) != null && System .getenv ("REPO_USERNAME" ) != null
204
- && System .getenv ("REPO_PASSWORD" ) != null && System .getenv ("REPO_EMAIL" ) != null ) {
205
- repoRegistry = System .getenv ("REPO_REGISTRY" );
206
- repoUserName = System .getenv ("REPO_USERNAME" );
207
- repoPassword = System .getenv ("REPO_PASSWORD" );
208
- repoEmail = System .getenv ("REPO_EMAIL" );
209
-
235
+ if (!REPO_USERNAME .equals (REPO_DUMMY_VALUE )) {
210
236
logger .info ("docker login" );
211
- assertTrue (dockerLogin (repoRegistry , repoUserName , repoPassword ), "docker login failed" );
237
+ assertTrue (dockerLogin (REPO_REGISTRY , REPO_USERNAME , REPO_PASSWORD ), "docker login failed" );
212
238
213
239
logger .info ("docker push image {0} to OCIR" , miiImage );
214
240
assertTrue (dockerPush (miiImage ), String .format ("docker push failed for image %s" , miiImage ));
215
241
}
216
242
217
- // create docker registry secret in the domain namespace to pull the image from OCIR
218
- JsonObject dockerConfigJsonObject = getDockerConfigJson (
219
- repoUserName , repoPassword , repoEmail , repoRegistry );
220
- String dockerConfigJson = dockerConfigJsonObject .toString ();
221
-
222
243
// Create the V1Secret configuration
223
244
V1Secret repoSecret = new V1Secret ()
224
245
.metadata (new V1ObjectMeta ()
225
- .name (repoSecretName )
246
+ .name (REPO_SECRET_NAME )
226
247
.namespace (domainNamespace ))
227
248
.type ("kubernetes.io/dockerconfigjson" )
228
249
.putDataItem (".dockerconfigjson" , dockerConfigJson .getBytes ());
229
250
230
251
boolean secretCreated = assertDoesNotThrow (() -> createSecret (repoSecret ),
231
- String .format ("createSecret failed for %s" , repoSecretName ));
232
- assertTrue (secretCreated , String .format ("createSecret failed while creating secret %s" , repoSecretName ));
252
+ String .format ("createSecret failed for %s" , REPO_SECRET_NAME ));
253
+ assertTrue (secretCreated , String .format ("createSecret failed while creating secret %s" , REPO_SECRET_NAME ));
233
254
234
255
// create secret for admin credentials
235
256
logger .info ("Create secret for admin credentials" );
@@ -269,7 +290,7 @@ public void testCreateMiiDomain() {
269
290
.domainHomeSourceType ("FromModel" )
270
291
.image (miiImage )
271
292
.addImagePullSecretsItem (new V1LocalObjectReference ()
272
- .name (repoSecretName ))
293
+ .name (REPO_SECRET_NAME ))
273
294
.webLogicCredentialsSecret (new V1SecretReference ()
274
295
.name (adminSecretName )
275
296
.namespace (domainNamespace ))
@@ -287,7 +308,7 @@ public void testCreateMiiDomain() {
287
308
.adminService (new AdminService ()
288
309
.addChannelsItem (new Channel ()
289
310
.channelName ("default" )
290
- .nodePort (30711 ))))
311
+ .nodePort (0 ))))
291
312
.addClustersItem (new Cluster ()
292
313
.clusterName ("cluster-1" )
293
314
.replicas (replicaCount )
@@ -413,6 +434,9 @@ private String createImageAndVerify() {
413
434
DateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd" );
414
435
Date date = new Date ();
415
436
final String imageTag = dateFormat .format (date ) + "-" + System .currentTimeMillis ();
437
+ // Add repository name in image name for Jenkins runs
438
+ final String imageName = REPO_USERNAME .equals (REPO_DUMMY_VALUE ) ? MII_IMAGE_NAME : REPO_NAME + MII_IMAGE_NAME ;
439
+ final String image = imageName + ":" + imageTag ;
416
440
417
441
// build the model file list
418
442
final List <String > modelList = Collections .singletonList (MODEL_DIR + "/" + WDT_MODEL_FILE );
@@ -431,25 +455,29 @@ private String createImageAndVerify() {
431
455
env .put ("WLSIMG_BLDDIR" , WIT_BUILD_DIR );
432
456
433
457
// build an image using WebLogic Image Tool
434
- logger .info ("Create image {0}:{1} using model directory {2}" ,
435
- MII_IMAGE_NAME , imageTag , MODEL_DIR );
458
+ logger .info ("Create image {0} using model directory {1}" , image , MODEL_DIR );
436
459
boolean result = createMiiImage (
437
460
defaultWitParams ()
438
- .modelImageName (MII_IMAGE_NAME )
461
+ .modelImageName (imageName )
439
462
.modelImageTag (imageTag )
440
463
.modelFiles (modelList )
441
464
.modelArchiveFiles (archiveList )
442
465
.wdtVersion (WDT_VERSION )
443
466
.env (env )
444
467
.redirect (true ));
445
468
446
- assertTrue (result , String .format ("Failed to create the image %s using WebLogic Image Tool" , MII_IMAGE_NAME ));
469
+ assertTrue (result , String .format ("Failed to create the image %s using WebLogic Image Tool" , image ));
447
470
448
- // check image exists
449
- assertTrue (dockerImageExists (MII_IMAGE_NAME , imageTag ),
450
- String .format ("Image %s doesn't exist" , MII_IMAGE_NAME + ":" + imageTag ));
471
+ /* Check image exists using docker images | grep image tag.
472
+ * Tag name is unique as it contains date and timestamp.
473
+ * This is a workaround for the issue on Jenkins machine
474
+ * as docker images imagename:imagetag is not working and
475
+ * the test fails even though the image exists.
476
+ */
477
+ assertTrue (doesImageExist (imageTag ),
478
+ String .format ("Image %s doesn't exist" , image ));
451
479
452
- return MII_IMAGE_NAME + ":" + imageTag ;
480
+ return image ;
453
481
}
454
482
455
483
@@ -498,19 +526,4 @@ private void checkServiceCreated(String serviceName) {
498
526
499
527
}
500
528
501
- private static JsonObject getDockerConfigJson (String username , String password , String email , String registry ) {
502
- JsonObject authObject = new JsonObject ();
503
- authObject .addProperty ("username" , username );
504
- authObject .addProperty ("password" , password );
505
- authObject .addProperty ("email" , email );
506
- String auth = username + ":" + password ;
507
- String authEncoded = Base64 .getEncoder ().encodeToString (auth .getBytes ());
508
- System .out .println ("auth encoded: " + authEncoded );
509
- authObject .addProperty ("auth" , authEncoded );
510
- JsonObject registryObject = new JsonObject ();
511
- registryObject .add (registry , authObject );
512
- JsonObject configJsonObject = new JsonObject ();
513
- configJsonObject .add ("auths" , registryObject );
514
- return configJsonObject ;
515
- }
516
529
}
0 commit comments