1
- // Copyright (c) 2022, 2023 , Oracle and/or its affiliates.
1
+ // Copyright (c) 2022, 2024 , Oracle and/or its affiliates.
2
2
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3
3
4
4
package oracle .weblogic .kubernetes ;
5
5
6
6
import java .util .HashMap ;
7
7
import java .util .List ;
8
8
import java .util .Map ;
9
+ import java .util .concurrent .Callable ;
9
10
11
+ import io .kubernetes .client .openapi .ApiException ;
12
+ import io .kubernetes .client .openapi .models .CoreV1Event ;
10
13
import io .kubernetes .client .openapi .models .V1ResourceRequirements ;
14
+ import io .kubernetes .client .util .Yaml ;
11
15
import oracle .weblogic .domain .DomainResource ;
16
+ import oracle .weblogic .kubernetes .actions .impl .primitive .Kubernetes ;
12
17
import oracle .weblogic .kubernetes .annotations .IntegrationTest ;
13
18
import oracle .weblogic .kubernetes .annotations .Namespaces ;
14
19
import oracle .weblogic .kubernetes .logging .LoggingFacade ;
25
30
import static oracle .weblogic .kubernetes .TestConstants .MII_BASIC_IMAGE_TAG ;
26
31
import static oracle .weblogic .kubernetes .TestConstants .TEST_IMAGES_REPO_SECRET_NAME ;
27
32
import static oracle .weblogic .kubernetes .utils .CommonMiiTestUtils .createDomainResource ;
28
- import static oracle .weblogic .kubernetes .utils .CommonTestUtils .checkPodEvictedStatus ;
29
33
import static oracle .weblogic .kubernetes .utils .CommonTestUtils .checkPodReadyAndServiceExists ;
34
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .testUntil ;
35
+ import static oracle .weblogic .kubernetes .utils .CommonTestUtils .withLongRetryPolicy ;
30
36
import static oracle .weblogic .kubernetes .utils .DomainUtils .createDomainAndVerify ;
31
37
import static oracle .weblogic .kubernetes .utils .ImageUtils .createTestRepoSecret ;
32
38
import static oracle .weblogic .kubernetes .utils .OperatorUtils .installAndVerifyOperator ;
38
44
39
45
/**
40
46
* Use Operator log to test WLS server pods were evicted due to Pod ephemeral local
41
- * storage usage exceeds the total limit of containers 50M and replaced.
47
+ * storage usage exceeds the total limit of containers 25M and replaced.
42
48
* 1. Install and start Operators
43
- * 2. Create and start the WebLogic domain with configuration of resource limit "ephemeral-storage=50M "
49
+ * 2. Create and start the WebLogic domain with configuration of resource limit "ephemeral-storage=25M "
44
50
* 3. Verify that WLS server pods were evicted due to Pod ephemeral local
45
- * storage usage exceeds the total limit of containers 50M and replaced.
51
+ * storage usage exceeds the total limit of containers 25M and replaced.
46
52
*/
47
53
@ DisplayName ("Test WLS server pods were evicted due to Pod ephemeral storage usage exceeds the total limit" )
48
54
@ IntegrationTest
@@ -63,13 +69,13 @@ class ItEvictedPodsCycling {
63
69
64
70
private static Map <String , String > resourceRequest = new HashMap <>();
65
71
private static Map <String , String > resourceLimit = new HashMap <>();
66
- private static final String ephemeralStorage = "50M " ;
72
+ private static final String ephemeralStorage = "25M " ;
67
73
68
74
private static LoggingFacade logger = null ;
69
75
70
76
/**
71
77
* Install Operator.
72
- * Config resource limit and set ephemeral-storage=50M
78
+ * Config resource limit and set ephemeral-storage=25M
73
79
* Create domain.
74
80
*
75
81
* @param namespaces list of namespaces created by the IntegrationTestWatcher by the
@@ -97,22 +103,29 @@ public static void init(@Namespaces(2) List<String> namespaces) {
97
103
}
98
104
99
105
/**
100
- * Set domain resources limits tp 50M and then use Operator log to verify
106
+ * Set domain resources limits to 25M and then use Operator log to verify
101
107
* that WLS server pods were evicted due to Pod ephemeral local
102
- * storage usage exceeds the total limit of containers 50M and replaced.
108
+ * storage usage exceeds the total limit of containers 25M and replaced.
103
109
*/
104
110
@ Test
105
111
@ DisplayName ("Use Operator log to verify that WLS server pods were evicted and replaced" )
106
- void testEvictedPodReplaced () {
112
+ void testEvictedPodReplaced () throws ApiException {
107
113
resourceLimit .put ("ephemeral-storage" , ephemeralStorage );
108
114
resourceRequest .put ("cpu" , "250m" );
109
115
resourceRequest .put ("memory" , "768Mi" );
110
116
111
- // patch domain with ephemeral-storage = 50M
117
+ // patch domain with ephemeral-storage = 25M
118
+ String reason = "Pod ephemeral local storage usage exceeds the total limit of containers" ;
119
+ addServerPodResources (domainUid , domainNamespace , resourceLimit , resourceRequest );
120
+ // verify that admin server pod evicted event is logged
121
+ testUntil (withLongRetryPolicy ,
122
+ checkEvictionEvent (adminServerPodName , "Evicted" , reason , "Warning" ),
123
+ logger ,
124
+ "domain event {0} to be logged in namespace {1}" ,
125
+ reason ,
126
+ domainNamespace );
127
+ resourceLimit .replace ("ephemeral-storage" , "250M" );
112
128
addServerPodResources (domainUid , domainNamespace , resourceLimit , resourceRequest );
113
-
114
- // verify that admin server pod evicted status exists in Operator log
115
- checkPodEvictedStatus (opNamespace , adminServerPodName , ephemeralStorage );
116
129
117
130
// verify that evicted pods are replaced and started
118
131
checkServerPodsAndServiceReady ();
@@ -184,4 +197,22 @@ private static void checkServerPodsAndServiceReady() {
184
197
checkPodReadyAndServiceExists (managedServerPodPrefix + i , domainUid , domainNamespace );
185
198
}
186
199
}
200
+
201
+ private Callable <Boolean > checkEvictionEvent (String adminServerpodName ,
202
+ String reason , String message , String type ) throws ApiException {
203
+ return (() -> {
204
+ boolean gotEvent = false ;
205
+ List <CoreV1Event > events = Kubernetes .listNamespacedEvents (domainNamespace );
206
+ for (CoreV1Event event : events ) {
207
+ if (event .getType ().equals (type )
208
+ && event .getInvolvedObject ().getName ().equals (adminServerpodName )
209
+ && event .getReason ().equals (reason )
210
+ && event .getMessage ().contains (message )) {
211
+ logger .info (Yaml .dump (event ));
212
+ gotEvent = true ;
213
+ }
214
+ }
215
+ return gotEvent ;
216
+ });
217
+ }
187
218
}
0 commit comments