1212import io .kubernetes .client .openapi .models .V1EnvVar ;
1313import io .kubernetes .client .openapi .models .V1LocalObjectReference ;
1414import io .kubernetes .client .openapi .models .V1ObjectMeta ;
15+ import io .kubernetes .client .openapi .models .V1Secret ;
1516import io .kubernetes .client .openapi .models .V1SecretReference ;
1617import io .kubernetes .client .openapi .models .V1ServiceAccount ;
1718import io .kubernetes .client .openapi .models .V1ServiceAccountList ;
6364import static oracle .weblogic .kubernetes .actions .TestActions .getServiceNodePort ;
6465import static oracle .weblogic .kubernetes .actions .TestActions .helmValuesToString ;
6566import static oracle .weblogic .kubernetes .actions .TestActions .installOperator ;
67+ import static oracle .weblogic .kubernetes .actions .TestActions .listSecrets ;
6668import static oracle .weblogic .kubernetes .actions .TestActions .scaleClusterWithRestApi ;
6769import static oracle .weblogic .kubernetes .actions .TestActions .uninstallOperator ;
6870import static oracle .weblogic .kubernetes .assertions .TestAssertions .checkHelmReleaseStatus ;
@@ -207,80 +209,86 @@ public void tearDownAll() {
207209 @ DisplayName ("install operator helm chart and domain, "
208210 + " then uninstall operator helm chart and verify the domain is still running" )
209211 void testDeleteOperatorButNotDomain () {
210- // install and verify operator
211- logger .info ("Installing and verifying operator" );
212- HelmParams opHelmParams = installAndVerifyOperator (opNamespace , domain1Namespace ).getHelmParams ();
213- if (!isDomain1Running ) {
214- logger .info ("Installing and verifying domain" );
215- assertTrue (createVerifyDomain (domain1Namespace , domain1Uid ),
216- "can't start or verify domain in namespace " + domain1Namespace );
217- isDomain1Running = true ;
218- }
219- // get the admin server pod original creation timestamp
220- logger .info ("Getting admin server pod original creation timestamp" );
221- String adminServerPodName = domain1Uid + adminServerPrefix ;
222- OffsetDateTime adminPodOriginalTimestamp =
223- assertDoesNotThrow (() -> getPodCreationTimestamp (domain1Namespace , "" , adminServerPodName ),
224- String .format ("getPodCreationTimestamp failed with ApiException for pod %s in namespace %s" ,
225- adminServerPodName , domain1Namespace ));
226-
227- // get the managed server pods original creation timestamps
228- logger .info ("Getting managed server pods original creation timestamps" );
229- List <OffsetDateTime > managedServerPodOriginalTimestampList = new ArrayList <>();
230- for (int i = 1 ; i <= replicaCountDomain1 ; i ++) {
231- final String managedServerPodName = domain1Uid + managedServerPrefix + i ;
232- managedServerPodOriginalTimestampList .add (
233- assertDoesNotThrow (() -> getPodCreationTimestamp (domain1Namespace , "" , managedServerPodName ),
234- String .format ("getPodCreationTimestamp failed with ApiException for pod %s in namespace %s" ,
235- managedServerPodName , domain1Namespace )));
236- }
237- // delete operator
238- logger .info ("Uninstalling operator" );
239- uninstallOperator (opHelmParams );
240- cleanUpSA (opNamespace );
241- deleteSecret (OCIR_SECRET_NAME ,opNamespace );
242-
243- // verify the operator pod does not exist in the operator namespace
244- logger .info ("Checking that operator pod does not exist in operator namespace" );
245- checkPodDoesNotExist ("weblogic-operator-" , null , opNamespace );
246-
247- // verify the operator service does not exist in the operator namespace
248- logger .info ("Checking that operator service does not exist in operator namespace" );
249- checkServiceDoesNotExist (OPERATOR_SERVICE_NAME , opNamespace );
250-
251- // check that the state of admin server pod in the domain was not changed
252- // wait some time here to ensure the pod state is not changed
253212 try {
254- Thread .sleep (15000 );
255- } catch (InterruptedException e ) {
256- // ignore
257- }
213+ // install and verify operator
214+ logger .info ("Installing and verifying operator" );
215+ HelmParams opHelmParams = installAndVerifyOperator (opNamespace , domain1Namespace ).getHelmParams ();
216+ if (!isDomain1Running ) {
217+ logger .info ("Installing and verifying domain" );
218+ assertTrue (createVerifyDomain (domain1Namespace , domain1Uid ),
219+ "can't start or verify domain in namespace " + domain1Namespace );
220+ isDomain1Running = true ;
221+ }
222+ // get the admin server pod original creation timestamp
223+ logger .info ("Getting admin server pod original creation timestamp" );
224+ String adminServerPodName = domain1Uid + adminServerPrefix ;
225+ OffsetDateTime adminPodOriginalTimestamp =
226+ assertDoesNotThrow (() -> getPodCreationTimestamp (domain1Namespace , "" , adminServerPodName ),
227+ String .format ("getPodCreationTimestamp failed with ApiException for pod %s in namespace %s" ,
228+ adminServerPodName , domain1Namespace ));
229+
230+ // get the managed server pods original creation timestamps
231+ logger .info ("Getting managed server pods original creation timestamps" );
232+ List <OffsetDateTime > managedServerPodOriginalTimestampList = new ArrayList <>();
233+ for (int i = 1 ; i <= replicaCountDomain1 ; i ++) {
234+ final String managedServerPodName = domain1Uid + managedServerPrefix + i ;
235+ managedServerPodOriginalTimestampList .add (
236+ assertDoesNotThrow (() -> getPodCreationTimestamp (domain1Namespace , "" , managedServerPodName ),
237+ String .format ("getPodCreationTimestamp failed with ApiException for pod %s in namespace %s" ,
238+ managedServerPodName , domain1Namespace )));
239+ }
240+ // delete operator
241+ logger .info ("Uninstalling operator" );
242+ uninstallOperator (opHelmParams );
243+ cleanUpSA (opNamespace );
244+ deleteSecret (OCIR_SECRET_NAME , opNamespace );
245+
246+ // verify the operator pod does not exist in the operator namespace
247+ logger .info ("Checking that operator pod does not exist in operator namespace" );
248+ checkPodDoesNotExist ("weblogic-operator-" , null , opNamespace );
249+
250+ // verify the operator service does not exist in the operator namespace
251+ logger .info ("Checking that operator service does not exist in operator namespace" );
252+ checkServiceDoesNotExist (OPERATOR_SERVICE_NAME , opNamespace );
258253
259- logger .info ("Checking that the admin server pod state was not changed after the operator was deleted" );
260- assertThat (podStateNotChanged (adminServerPodName , domain1Uid ,
261- domain1Namespace , adminPodOriginalTimestamp ))
262- .as ("Test state of pod {0} was not changed in namespace {1}" , adminServerPodName , domain1Namespace )
263- .withFailMessage ("State of pod {0} was changed in namespace {1}" ,
264- adminServerPodName , domain1Namespace )
265- .isTrue ();
266-
267- // check that the states of managed server pods in the domain were not changed
268- logger .info ("Checking that the managed server pod state was not changed after the operator was deleted" );
269- for (int i = 1 ; i <= replicaCountDomain1 ; i ++) {
270- String managedServerPodName = managedServerPrefix + i ;
271- assertThat (podStateNotChanged (managedServerPodName , domain1Uid , domain1Namespace ,
272- managedServerPodOriginalTimestampList .get (i - 1 )))
273- .as ("Test state of pod {0} was not changed in namespace {1}" ,
274- managedServerPodName , domain1Namespace )
254+ // check that the state of admin server pod in the domain was not changed
255+ // wait some time here to ensure the pod state is not changed
256+ try {
257+ Thread .sleep (15000 );
258+ } catch (InterruptedException e ) {
259+ // ignore
260+ }
261+
262+ logger .info ("Checking that the admin server pod state was not changed after the operator was deleted" );
263+ assertThat (podStateNotChanged (adminServerPodName , domain1Uid ,
264+ domain1Namespace , adminPodOriginalTimestamp ))
265+ .as ("Test state of pod {0} was not changed in namespace {1}" , adminServerPodName , domain1Namespace )
275266 .withFailMessage ("State of pod {0} was changed in namespace {1}" ,
276- managedServerPodName , domain1Namespace )
267+ adminServerPodName , domain1Namespace )
277268 .isTrue ();
278- }
279269
280- // verify the managed server Mbean is still accessible via rest api
281- logger .info ("Verify the managed server1 MBean configuration through rest API "
282- + "after the operator was deleted" );
283- assertTrue (checkManagedServerConfiguration (domain1Namespace , domain1Uid ));
270+ // check that the states of managed server pods in the domain were not changed
271+ logger .info ("Checking that the managed server pod state was not changed after the operator was deleted" );
272+ for (int i = 1 ; i <= replicaCountDomain1 ; i ++) {
273+ String managedServerPodName = managedServerPrefix + i ;
274+ assertThat (podStateNotChanged (managedServerPodName , domain1Uid , domain1Namespace ,
275+ managedServerPodOriginalTimestampList .get (i - 1 )))
276+ .as ("Test state of pod {0} was not changed in namespace {1}" ,
277+ managedServerPodName , domain1Namespace )
278+ .withFailMessage ("State of pod {0} was changed in namespace {1}" ,
279+ managedServerPodName , domain1Namespace )
280+ .isTrue ();
281+ }
282+
283+ // verify the managed server Mbean is still accessible via rest api
284+ logger .info ("Verify the managed server1 MBean configuration through rest API "
285+ + "after the operator was deleted" );
286+ assertTrue (checkManagedServerConfiguration (domain1Namespace , domain1Uid ));
287+ } finally {
288+ if (!isDomain1Running ) {
289+ cleanUpDomainSecrets (domain1Namespace );
290+ }
291+ }
284292
285293 }
286294
@@ -343,6 +351,9 @@ void testCreateDeleteCreateOperatorButNotDomain() {
343351 uninstallOperator (op1HelmParams );
344352 deleteSecret (OCIR_SECRET_NAME ,opNamespace );
345353 cleanUpSA (opNamespace );
354+ if (!isDomain1Running ) {
355+ cleanUpDomainSecrets (domain1Namespace );
356+ }
346357 }
347358 }
348359
@@ -454,6 +465,9 @@ void testAddRemoveDomainNameSpacesOnOperator() {
454465 uninstallOperator (op1HelmParams );
455466 deleteSecret (OCIR_SECRET_NAME ,op2Namespace );
456467 cleanUpSA (op2Namespace );
468+ if (!isDomain2Running ) {
469+ cleanUpDomainSecrets (domain2Namespace );
470+ }
457471 }
458472 }
459473
@@ -469,22 +483,25 @@ void testAddRemoveDomainNameSpacesOnOperator() {
469483 @ Test
470484 @ DisplayName ("Negative test to install two operators sharing the same namespace" )
471485 void testCreateSecondOperatorUsingSameOperatorNsNegativeInstall () {
472- HelmParams opHelmParams = installAndVerifyOperator (opNamespace , domain1Namespace ).getHelmParams ();
473- if (!isDomain1Running ) {
474- logger .info ("Installing and verifying domain" );
475- assertTrue (createVerifyDomain (domain1Namespace , domain1Uid ),
476- "can't start or verify domain in namespace " + domain1Namespace );
477- isDomain1Running = true ;
478- }
479- String opReleaseName = OPERATOR_RELEASE_NAME + "2" ;
480- String opServiceAccount = opNamespace + "-sa2" ;
481- HelmParams op2HelmParams = new HelmParams ().releaseName (opReleaseName )
482- .namespace (opNamespace )
483- .chartDir (OPERATOR_CHART_DIR );;
484-
485- // install and verify operator will fail with expected error message
486- logger .info ("Installing and verifying operator will fail with expected error message" );
486+ HelmParams opHelmParams = null ;
487+ HelmParams op2HelmParams = null ;
487488 try {
489+ opHelmParams = installAndVerifyOperator (opNamespace , domain1Namespace ).getHelmParams ();
490+ if (!isDomain1Running ) {
491+ logger .info ("Installing and verifying domain" );
492+ assertTrue (createVerifyDomain (domain1Namespace , domain1Uid ),
493+ "can't start or verify domain in namespace " + domain1Namespace );
494+ isDomain1Running = true ;
495+ }
496+ String opReleaseName = OPERATOR_RELEASE_NAME + "2" ;
497+ String opServiceAccount = opNamespace + "-sa2" ;
498+ op2HelmParams = new HelmParams ().releaseName (opReleaseName )
499+ .namespace (opNamespace )
500+ .chartDir (OPERATOR_CHART_DIR );;
501+
502+ // install and verify operator will fail with expected error message
503+ logger .info ("Installing and verifying operator will fail with expected error message" );
504+
488505 String expectedError = "rendered manifests contain a resource that already exists."
489506 + " Unable to continue with install" ;
490507 HelmParams opHelmParam2 = installOperatorHelmChart (opNamespace , opServiceAccount , true , false ,
@@ -497,6 +514,9 @@ void testCreateSecondOperatorUsingSameOperatorNsNegativeInstall() {
497514 uninstallOperator (op2HelmParams );
498515 deleteSecret (OCIR_SECRET_NAME ,opNamespace );
499516 cleanUpSA (opNamespace );
517+ if (!isDomain1Running ) {
518+ cleanUpDomainSecrets (domain1Namespace );
519+ }
500520 }
501521 }
502522
@@ -511,24 +531,28 @@ void testCreateSecondOperatorUsingSameOperatorNsNegativeInstall() {
511531 @ Test
512532 @ DisplayName ("Negative test to install two operators sharing the same domain namespace" )
513533 void testSecondOpSharingSameDomainNamespacesNegativeInstall () {
514- // install and verify operator1
515- logger .info ("Installing and verifying operator1" );
516- HelmParams opHelmParams = installAndVerifyOperator (opNamespace , domain2Namespace ).getHelmParams ();
517- if (!isDomain2Running ) {
518- logger .info ("Installing and verifying domain" );
519- assertTrue (createVerifyDomain (domain2Namespace , domain2Uid ),
520- "can't start or verify domain in namespace " + domain2Namespace );
521- isDomain2Running = true ;
522- }
523- String opReleaseName = OPERATOR_RELEASE_NAME + "2" ;
524- HelmParams op2HelmParams = new HelmParams ().releaseName (opReleaseName )
525- .namespace (op2Namespace )
526- .chartDir (OPERATOR_CHART_DIR );
527-
528- // install and verify operator2 will fail
529- logger .info ("Installing and verifying operator2 will fail with expected error message" );
530- String opServiceAccount = op2Namespace + "-sa2" ;
534+ HelmParams opHelmParams = null ;
535+ HelmParams op2HelmParams = null ;
531536 try {
537+ // install and verify operator1
538+ logger .info ("Installing and verifying operator1" );
539+ opHelmParams = installAndVerifyOperator (opNamespace , domain2Namespace ).getHelmParams ();
540+ if (!isDomain2Running ) {
541+ logger .info ("Installing and verifying domain" );
542+ assertTrue (createVerifyDomain (domain2Namespace , domain2Uid ),
543+ "can't start or verify domain in namespace " + domain2Namespace );
544+ isDomain2Running = true ;
545+ }
546+ String opReleaseName = OPERATOR_RELEASE_NAME + "2" ;
547+ op2HelmParams = new HelmParams ().releaseName (opReleaseName )
548+ .namespace (op2Namespace )
549+ .chartDir (OPERATOR_CHART_DIR );
550+
551+ // install and verify operator2 will fail
552+ logger .info ("Installing and verifying operator2 will fail with expected error message" );
553+ String opServiceAccount = op2Namespace + "-sa2" ;
554+
555+
532556 String expectedError = "rendered manifests contain a resource that already exists."
533557 + " Unable to continue with install" ;
534558 HelmParams opHelmParam2 = installOperatorHelmChart (op2Namespace , opServiceAccount , true , false , false ,
@@ -540,6 +564,9 @@ void testSecondOpSharingSameDomainNamespacesNegativeInstall() {
540564 deleteSecret (OCIR_SECRET_NAME ,opNamespace );
541565 cleanUpSA (opNamespace );
542566 cleanUpSA (op2Namespace );
567+ if (!isDomain2Running ) {
568+ cleanUpDomainSecrets (domain2Namespace );
569+ }
543570 }
544571 }
545572
@@ -676,6 +703,9 @@ void testCreateWithEmptyDomainNamespaceInstall() {
676703 uninstallOperator (op2HelmParams );
677704 deleteSecret (OCIR_SECRET_NAME ,op2Namespace );
678705 cleanUpSA (op2Namespace );
706+ if (!isDomain2Running ) {
707+ cleanUpDomainSecrets (domain2Namespace );
708+ }
679709 }
680710 }
681711
@@ -1211,4 +1241,14 @@ private boolean checkManagedServerConfiguration(String domainNamespace, String d
12111241 return false ;
12121242 }
12131243 }
1244+
1245+ private void cleanUpDomainSecrets (String domainNamespace ) {
1246+ //cleanup created artifacts for failed domain creation
1247+ for (V1Secret secret : listSecrets (domainNamespace ).getItems ()) {
1248+ if (secret .getMetadata () != null ) {
1249+ String name = secret .getMetadata ().getName ();
1250+ Kubernetes .deleteSecret (name , domainNamespace );
1251+ }
1252+ }
1253+ }
12141254}
0 commit comments