@@ -23,35 +23,40 @@ public class ConfigHelper {
23
23
* Returns {@code true} if the given {@link io.fabric8.kubernetes.client.Config}s are equal.
24
24
* They are considered equal if they're equal in
25
25
* <ul>
26
- * <li>current context (cluster, user, current namespace, extensions )</li>
27
- * <li>(authentication) token </li>
26
+ * <li>current context (cluster, user, current namespace)</li>
27
+ * <li>auth info </li>
28
28
* </ul>
29
29
*
30
30
* @param thisConfig the first config to compare
31
31
* @param thatConfig the second config to compare
32
32
* @return true if both configs are equal in context, contexts and token
33
33
*
34
- * @see #areEqualContext(NamedContext, NamedContext)
34
+ * @see #areEqualCurrentContext(Config, Config)
35
+ * @see #areEqualCluster(Config, Config)
36
+ * @see #areEqualAuthInfo(Config, Config)
35
37
*/
36
38
public static boolean areEqual (Config thisConfig , Config thatConfig ) {
37
39
return areEqualCurrentContext (thisConfig , thatConfig )
38
- && areEqualToken (thisConfig , thatConfig );
40
+ && areEqualCluster (thisConfig , thatConfig )
41
+ && areEqualAuthInfo (thisConfig , thatConfig );
39
42
}
40
43
41
44
/**
42
45
* Returns {@code true} if the given {@link io.fabric8.kubernetes.client.Config}s are equal in current context.
43
46
* They are considered equal if they're equal in
44
47
* <ul>
45
- * <li>current context (cluster, user, current namespace, extensions)</li>
46
- * <li>(existing) contexts</li>
47
- * <li>(authentication) token</li>
48
+ * <li>name</li>
49
+ * <li>cluster</li>
50
+ * <li>user</li>
51
+ * <li>current namespace</li>
48
52
* </ul>
49
53
*
50
54
* @param thisConfig the first config to compare
51
55
* @param thatConfig the second config to compare
52
- * @return true if both configs are equal in context, contexts and token
56
+ * @return true if both configs are equal in context, existing contexts and token
53
57
*
54
58
* @see Config#getCurrentContext()
59
+ * @see #areEqualContext(NamedContext, NamedContext)
55
60
*/
56
61
public static boolean areEqualCurrentContext (Config thisConfig , Config thatConfig ) {
57
62
if (thisConfig == null ) {
@@ -64,9 +69,9 @@ public static boolean areEqualCurrentContext(Config thisConfig, Config thatConfi
64
69
}
65
70
66
71
/**
67
- * Returns {@code true} if both given {@link NamedContext} are equal.
68
- * They are considered equal if they're equal in
72
+ * Returns {@code true} if both given {@link NamedContext} are equal in
69
73
* <ul>
74
+ * <li>name</li>
70
75
* <li>cluster</li>
71
76
* <li>user</li>
72
77
* <li>current namespace</li>
@@ -76,20 +81,19 @@ public static boolean areEqualCurrentContext(Config thisConfig, Config thatConfi
76
81
* @param thatContext the second context to compare
77
82
* @return true if both contexts are equal
78
83
*
84
+ * @see #areEqualContext(Context, Context)
79
85
* @see NamedContext
80
86
* @see Context
81
87
*/
82
- private static boolean areEqualContext (NamedContext thisContext , NamedContext thatContext ) {
88
+ public static boolean areEqualContext (NamedContext thisContext , NamedContext thatContext ) {
83
89
if (thisContext == null ) {
84
90
return thatContext == null ;
85
91
} else if (thatContext == null ) {
86
92
return false ;
87
93
}
88
- if (!Objects .equals (thisContext .getName (), thatContext .getName ())) {
89
- return false ;
90
- }
91
94
92
- return areEqualContext (thisContext .getContext (), thatContext .getContext ());
95
+ return Objects .equals (thisContext .getName (), thatContext .getName ())
96
+ && areEqualContext (thisContext .getContext (), thatContext .getContext ());
93
97
}
94
98
95
99
/**
@@ -115,13 +119,132 @@ private static boolean areEqualContext(Context thisContext, Context thatContext)
115
119
return false ;
116
120
}
117
121
118
- if (!Objects .equals (thisContext .getCluster (), thatContext .getCluster ())){
122
+ return Objects .equals (thisContext .getCluster (), thatContext .getCluster ())
123
+ && Objects .equals (thisContext .getUser (), thatContext .getUser ())
124
+ && Objects .equals (thisContext .getNamespace (), thatContext .getNamespace ());
125
+ }
126
+
127
+ /**
128
+ * Returns {@code true} if both given {@link Config} are equal in
129
+ * <ul>
130
+ * <li>master url</li>
131
+ * <li>(blindly) trust certificates</li>
132
+ * <li>proxies</li>
133
+ * <li>auth info</li>
134
+ * </ul>
135
+ *
136
+ * @param thisConfig the first config to compare
137
+ * @param thatConfig the second config to compare
138
+ * @return true if both configs are equal in master url, trust certs, proxies and auth info
139
+ *
140
+ * @see Config
141
+ */
142
+ public static boolean areEqualCluster (Config thisConfig , Config thatConfig ) {
143
+ if (thisConfig == null ) {
144
+ return thatConfig == null ;
145
+ } else if (thatConfig == null ) {
146
+ return false ;
147
+ }
148
+
149
+ return Objects .equals (thisConfig .getMasterUrl (), thatConfig .getMasterUrl ())
150
+ && areEqualTrustCerts (thisConfig , thatConfig )
151
+ && areEqualProxy (thisConfig , thatConfig )
152
+ && areEqualAuthInfo (thisConfig , thatConfig );
153
+ }
154
+
155
+ /**
156
+ * Returns {@code true} if both given {@link Config} are equal in
157
+ * <ul>
158
+ * <li>http proxy</li>
159
+ * <li>https proxy</li>
160
+ * <li>proxy username</li>
161
+ * <li>proxy password</li>
162
+ * </ul>
163
+ *
164
+ * @param thisConfig the first config to compare
165
+ * @param thatConfig the second config to compare
166
+ * @return true if both configs are equal in http- & https-proxy, proxy username & password
167
+ *
168
+ * @see Config
169
+ */
170
+ private static boolean areEqualProxy (Config thisConfig , Config thatConfig ) {
171
+ if (thisConfig == null ) {
172
+ return thatConfig == null ;
173
+ } else if (thatConfig == null ) {
174
+ return false ;
175
+ }
176
+
177
+ return Objects .equals (thisConfig .getHttpProxy (), thatConfig .getHttpProxy ())
178
+ && Objects .equals (thisConfig .getHttpsProxy (), thatConfig .getHttpsProxy ())
179
+ && Objects .equals (thisConfig .getProxyUsername (), thatConfig .getProxyUsername ())
180
+ && Objects .equals (thisConfig .getProxyPassword (), thatConfig .getProxyPassword ());
181
+ }
182
+
183
+ /**
184
+ * Returns {@code true} if both given {@link Config} are equal in
185
+ * <ul>
186
+ * <li>(blindly) trusting certificates</li>
187
+ * <li>disable hostname verification</li>
188
+ * <li>ca cert data</li>
189
+ * <li>ca cert file</li>
190
+ * </ul>
191
+ *
192
+ * @param thisConfig the first config to compare
193
+ * @param thatConfig the second config to compare
194
+ * @return true if both configs are equal in trusting certs, disabling hostname verification, ca cert data & file
195
+ *
196
+ * @see Config
197
+ */
198
+ private static boolean areEqualTrustCerts (Config thisConfig , Config thatConfig ) {
199
+ if (thisConfig == null ) {
200
+ return thatConfig == null ;
201
+ } else if (thatConfig == null ) {
119
202
return false ;
120
- } else if (!Objects .equals (thisContext .getNamespace (), thatContext .getNamespace ())){
203
+ }
204
+
205
+ return thisConfig .isTrustCerts () == thatConfig .isTrustCerts ()
206
+ && thisConfig .isDisableHostnameVerification () == thatConfig .isDisableHostnameVerification ()
207
+ && Objects .equals (thisConfig .getCaCertData (), thatConfig .getCaCertData ())
208
+ && Objects .equals (thisConfig .getCaCertFile (), thatConfig .getCaCertFile ());
209
+ }
210
+
211
+ /**
212
+ * Returns {@code true} if both given {@link Config} are equal in auth info
213
+ * <ul>
214
+ * <li>client cert file</li>
215
+ * <li>client cert data</li>
216
+ * <li>client key file</li>
217
+ * <li>client key data</li>
218
+ * <li>client key algo</li>
219
+ * <li>username</li>
220
+ * <li>password</li>
221
+ * <li>proxies</li>
222
+ * <li>token</li>
223
+ * </ul>
224
+ *
225
+ * @param thisConfig the first config to compare
226
+ * @param thatConfig the second config to compare
227
+ * @return true if both configs are equal in client cert file/data, key file/data/algo, username, password
228
+ * proxies and token
229
+ *
230
+ * @see Config
231
+ */
232
+ public static boolean areEqualAuthInfo (Config thisConfig , Config thatConfig ) {
233
+ if (thisConfig == null ) {
234
+ return thatConfig == null ;
235
+ } else if (thatConfig == null ) {
121
236
return false ;
122
- } else {
123
- return Objects .equals (thisContext .getUser (), thatContext .getUser ());
124
237
}
238
+
239
+ return Objects .equals (thisConfig .getClientCertFile (), thatConfig .getClientCertFile ())
240
+ && Objects .equals (thisConfig .getClientCertData (), thatConfig .getClientCertData ())
241
+ && Objects .equals (thisConfig .getClientKeyFile (), thatConfig .getClientKeyFile ())
242
+ && Objects .equals (thisConfig .getClientKeyData (), thatConfig .getClientKeyData ())
243
+ && Objects .equals (thisConfig .getClientKeyAlgo (), thatConfig .getClientKeyAlgo ())
244
+ && Objects .equals (thisConfig .getUsername (), thatConfig .getUsername ())
245
+ && Objects .equals (thisConfig .getPassword (), thatConfig .getPassword ())
246
+ && areEqualProxy (thisConfig , thatConfig )
247
+ && areEqualToken (thisConfig , thatConfig );
125
248
}
126
249
127
250
/**
0 commit comments