6
6
7
7
import io .kubernetes .client .models .V1ObjectMeta ;
8
8
import java .lang .reflect .Field ;
9
- import java .util .HashMap ;
10
9
import java .util .Map ;
11
10
import java .util .Objects ;
12
11
import javax .json .JsonPatchBuilder ;
@@ -26,45 +25,6 @@ static <K, V> boolean mapEquals(Map<K, V> first, Map<K, V> second) {
26
25
return Objects .equals (first , second ) || (MapUtils .isEmpty (first ) && MapUtils .isEmpty (second ));
27
26
}
28
27
29
- /**
30
- * Returns true if the labels on the current artifact metadata match those on the build version.
31
- * This excludes any weblogic-specific labels, as identified by the existence of the weblogic.
32
- * prefix.
33
- *
34
- * @param build the desired version of the metadata
35
- * @param current the current version of the metadata
36
- * @return true if the labels match
37
- */
38
- static boolean areLabelsValid (V1ObjectMeta build , V1ObjectMeta current ) {
39
- return mapEquals (getCustomerLabels (current ), getCustomerLabels (build ));
40
- }
41
-
42
- private static Map <String , String > getCustomerLabels (V1ObjectMeta metadata ) {
43
- Map <String , String > result = new HashMap <>();
44
- for (Map .Entry <String , String > entry : metadata .getLabels ().entrySet ()) {
45
- if (!isOperatorLabel (entry )) {
46
- result .put (entry .getKey (), entry .getValue ());
47
- }
48
- }
49
- return result ;
50
- }
51
-
52
- private static boolean isOperatorLabel (Map .Entry <String , String > label ) {
53
- return label .getKey ().startsWith ("weblogic." );
54
- }
55
-
56
- /**
57
- * Returns true if the annotations on the current artifact metadata match those on the build
58
- * version.
59
- *
60
- * @param build the desired version of the metadata
61
- * @param current the current version of the metadata
62
- * @return true if the annotations match
63
- */
64
- static boolean areAnnotationsValid (V1ObjectMeta build , V1ObjectMeta current ) {
65
- return mapEquals (current .getAnnotations (), build .getAnnotations ());
66
- }
67
-
68
28
/**
69
29
* Returns true if the current map is missing values from the required map. This method is
70
30
* typically used to compare labels and annotations against specifications derived from the
@@ -100,7 +60,7 @@ private static boolean hasAllRequiredNames(Map<String, ?> current, Map<String, ?
100
60
* @param current a map of the values found in a Kubernetes resource
101
61
* @param required a map of the values specified for the resource by the domain
102
62
*/
103
- public static void addPatches (
63
+ static void addPatches (
104
64
JsonPatchBuilder patchBuilder ,
105
65
String basePath ,
106
66
Map <String , String > current ,
@@ -144,7 +104,9 @@ static V1ObjectMeta getResourceMetadata(Object resource) {
144
104
}
145
105
146
106
/**
147
- * Returns true if the first metadata indicates a newer resource than does the second.
107
+ * Returns true if the first metadata indicates a newer resource than does the second. 'Newer'
108
+ * indicates that the creation time is later. If two items have the same creation time, a higher
109
+ * resource version indicates the newer resource.
148
110
*
149
111
* @param first the first item to compare
150
112
* @param second the second item to compare
@@ -157,11 +119,16 @@ public static boolean isFirstNewer(V1ObjectMeta first, V1ObjectMeta second) {
157
119
DateTime time1 = first .getCreationTimestamp ();
158
120
DateTime time2 = second .getCreationTimestamp ();
159
121
160
- if (time2 .isAfter (time1 )) {
122
+ if (time1 .isAfter (time2 )) {
123
+ return true ;
124
+ } else if (time2 .isAfter (time1 )) {
161
125
return false ;
126
+ } else {
127
+ return getResourceVersion (first ) > getResourceVersion (second );
162
128
}
163
- return Integer .parseInt (second .getResourceVersion ())
164
- < Integer .parseInt (first .getResourceVersion ())
165
- || time2 .isBefore (time1 );
129
+ }
130
+
131
+ private static int getResourceVersion (V1ObjectMeta metadata ) {
132
+ return Integer .parseInt (metadata .getResourceVersion ());
166
133
}
167
134
}
0 commit comments