88import static oracle .kubernetes .operator .VersionConstants .DEFAULT_DOMAIN_VERSION ;
99
1010import io .kubernetes .client .custom .IntOrString ;
11+ import io .kubernetes .client .custom .Quantity ;
1112import io .kubernetes .client .models .*;
1213import java .io .File ;
1314import java .util .*;
2324import oracle .kubernetes .operator .work .Step ;
2425import oracle .kubernetes .weblogic .domain .v2 .Domain ;
2526import oracle .kubernetes .weblogic .domain .v2 .ServerSpec ;
27+ import org .apache .commons .collections .MapUtils ;
2628import org .apache .commons .lang3 .builder .EqualsBuilder ;
2729
2830@ SuppressWarnings ("deprecation" )
@@ -279,19 +281,23 @@ private static boolean isCurrentPodValid(V1Pod build, V1Pod current) {
279281 private static boolean isCurrentPodMetadataValid (V1ObjectMeta build , V1ObjectMeta current ) {
280282 return VersionHelper .matchesResourceVersion (current , DEFAULT_DOMAIN_VERSION )
281283 && 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 ());
284286 }
285287
286288 private static boolean isCurrentPodSpecValid (
287289 V1PodSpec build , V1PodSpec current , List <String > ignoring ) {
288290 return Objects .equals (current .getSecurityContext (), build .getSecurityContext ())
289- // && Objects.equals (current.getNodeSelector(), build.getNodeSelector())
291+ && mapEquals (current .getNodeSelector (), build .getNodeSelector ())
290292 && equalSets (volumesWithout (current .getVolumes (), ignoring ), build .getVolumes ())
291293 && equalSets (current .getImagePullSecrets (), build .getImagePullSecrets ())
292294 && areCompatible (build .getContainers (), current .getContainers (), ignoring );
293295 }
294296
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+
295301 private static boolean areCompatible (
296302 List <V1Container > build , List <V1Container > current , List <String > ignoring ) {
297303 if (build != null ) {
@@ -323,6 +329,7 @@ private static boolean isCompatible(
323329 && Objects .equals (current .getSecurityContext (), build .getSecurityContext ())
324330 && equalSettings (current .getLivenessProbe (), build .getLivenessProbe ())
325331 && equalSettings (current .getReadinessProbe (), build .getReadinessProbe ())
332+ && resourcesEqual (current .getResources (), build .getResources ())
326333 && equalSets (mountsWithout (current .getVolumeMounts (), ignoring ), build .getVolumeMounts ())
327334 && equalSets (current .getPorts (), build .getPorts ())
328335 && equalSets (current .getEnv (), build .getEnv ())
@@ -335,6 +342,18 @@ private static boolean equalSettings(V1Probe probe1, V1Probe probe2) {
335342 && Objects .equals (probe1 .getPeriodSeconds (), probe2 .getPeriodSeconds ());
336343 }
337344
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+
338357 private static List <V1Volume > volumesWithout (
339358 List <V1Volume > volumeMounts , List <String > volumesToIgnore ) {
340359 List <V1Volume > result = new ArrayList <>(volumeMounts );
0 commit comments