8
8
import static oracle .kubernetes .operator .VersionConstants .DEFAULT_DOMAIN_VERSION ;
9
9
10
10
import io .kubernetes .client .custom .IntOrString ;
11
+ import io .kubernetes .client .custom .Quantity ;
11
12
import io .kubernetes .client .models .*;
12
13
import java .io .File ;
13
14
import java .util .*;
23
24
import oracle .kubernetes .operator .work .Step ;
24
25
import oracle .kubernetes .weblogic .domain .v2 .Domain ;
25
26
import oracle .kubernetes .weblogic .domain .v2 .ServerSpec ;
27
+ import org .apache .commons .collections .MapUtils ;
26
28
import org .apache .commons .lang3 .builder .EqualsBuilder ;
27
29
28
30
@ SuppressWarnings ("deprecation" )
@@ -279,19 +281,23 @@ private static boolean isCurrentPodValid(V1Pod build, V1Pod current) {
279
281
private static boolean isCurrentPodMetadataValid (V1ObjectMeta build , V1ObjectMeta current ) {
280
282
return VersionHelper .matchesResourceVersion (current , DEFAULT_DOMAIN_VERSION )
281
283
&& isRestartVersionValid (build , current )
282
- && Objects . equals (getCustomerLabels (current ), getCustomerLabels (build ))
283
- && Objects . equals (current .getAnnotations (), build .getAnnotations ());
284
+ && mapEquals (getCustomerLabels (current ), getCustomerLabels (build ))
285
+ && mapEquals (current .getAnnotations (), build .getAnnotations ());
284
286
}
285
287
286
288
private static boolean isCurrentPodSpecValid (
287
289
V1PodSpec build , V1PodSpec current , List <String > ignoring ) {
288
290
return Objects .equals (current .getSecurityContext (), build .getSecurityContext ())
289
- // && Objects.equals (current.getNodeSelector(), build.getNodeSelector())
291
+ && mapEquals (current .getNodeSelector (), build .getNodeSelector ())
290
292
&& equalSets (volumesWithout (current .getVolumes (), ignoring ), build .getVolumes ())
291
293
&& equalSets (current .getImagePullSecrets (), build .getImagePullSecrets ())
292
294
&& areCompatible (build .getContainers (), current .getContainers (), ignoring );
293
295
}
294
296
297
+ private static <K , V > boolean mapEquals (Map <K , V > first , Map <K , V > second ) {
298
+ return Objects .equals (first , second ) || (MapUtils .isEmpty (first ) && MapUtils .isEmpty (second ));
299
+ }
300
+
295
301
private static boolean areCompatible (
296
302
List <V1Container > build , List <V1Container > current , List <String > ignoring ) {
297
303
if (build != null ) {
@@ -323,6 +329,7 @@ private static boolean isCompatible(
323
329
&& Objects .equals (current .getSecurityContext (), build .getSecurityContext ())
324
330
&& equalSettings (current .getLivenessProbe (), build .getLivenessProbe ())
325
331
&& equalSettings (current .getReadinessProbe (), build .getReadinessProbe ())
332
+ && resourcesEqual (current .getResources (), build .getResources ())
326
333
&& equalSets (mountsWithout (current .getVolumeMounts (), ignoring ), build .getVolumeMounts ())
327
334
&& equalSets (current .getPorts (), build .getPorts ())
328
335
&& equalSets (current .getEnv (), build .getEnv ())
@@ -335,6 +342,18 @@ private static boolean equalSettings(V1Probe probe1, V1Probe probe2) {
335
342
&& Objects .equals (probe1 .getPeriodSeconds (), probe2 .getPeriodSeconds ());
336
343
}
337
344
345
+ private static boolean resourcesEqual (V1ResourceRequirements a , V1ResourceRequirements b ) {
346
+ return mapEquals (getLimits (a ), getLimits (b )) && mapEquals (getRequests (a ), getRequests (b ));
347
+ }
348
+
349
+ private static Map <String , Quantity > getLimits (V1ResourceRequirements requirements ) {
350
+ return requirements == null ? Collections .emptyMap () : requirements .getLimits ();
351
+ }
352
+
353
+ private static Map <String , Quantity > getRequests (V1ResourceRequirements requirements ) {
354
+ return requirements == null ? Collections .emptyMap () : requirements .getRequests ();
355
+ }
356
+
338
357
private static List <V1Volume > volumesWithout (
339
358
List <V1Volume > volumeMounts , List <String > volumesToIgnore ) {
340
359
List <V1Volume > result = new ArrayList <>(volumeMounts );
0 commit comments