Util { @SafeVarargs public static Map<String, String> mergeLabelsOrAnnotations(Map<String, String> base, Map<String, String>... overrides) { Map<String, String> merged = new HashMap<>(); if (base != null) { merged.putAll(base); } if (overrides != null) { for (Map<String, String> toMerge : overrides) { if (toMerge == null) { continue; } List<String> bannedLabelsOrAnnotations = toMerge .keySet() .stream() .filter(key -> key.startsWith(Labels.STRIMZI_DOMAIN)) .collect(Collectors.toList()); if (bannedLabelsOrAnnotations.size() > 0) { throw new InvalidResourceException("User provided labels or annotations includes a Strimzi annotation: " + bannedLabelsOrAnnotations.toString()); } Map<String, String> filteredToMerge = toMerge .entrySet() .stream() .filter(entryset -> !entryset.getKey().startsWith(Labels.KUBERNETES_DOMAIN)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); merged.putAll(filteredToMerge); } } return merged; }  static Future<T> async(Vertx vertx, Supplier<T> supplier); static Future<Void> waitFor(Vertx vertx, String logContext, String logState, long pollIntervalMs, long timeoutMs, BooleanSupplier completed); static Future<Void> waitFor(Vertx vertx, String logContext, String logState, long pollIntervalMs, long timeoutMs, BooleanSupplier completed,
                                       Predicate<Throwable> failOnError); static Map<String, String> parseMap(String str); static RuntimeException missingSecretException(String namespace, String secretName); static File createFileStore(String prefix, String suffix, byte[] bytes); static byte[] decodeFromSecret(Secret secret, String key); static File createFileTrustStore(String prefix, String suffix, X509Certificate certificate, char[] password); static void printEnvInfo(); static String maskPassword(String key, String value); @SafeVarargs static Map<String, String> mergeLabelsOrAnnotations(Map<String, String> base, Map<String, String>... overrides); static Future<T> kafkaFutureToVertxFuture(Vertx vertx, KafkaFuture<T> kf); static ConfigResource getBrokersConfig(int podId); static ConfigResource getBrokersLogging(int podId); static ConfigResource getBrokersConfig(String podId); static ConfigResource getBrokersLogging(String podId); static String stringHash(String toBeHashed); static String getLoggingDynamicallyUnmodifiableEntries(String loggingConfiguration); static String expandVars(String env); static String expandVar(String value, Map<String, String> env);  }
@Test public void testMergeLabelsOrAnnotations() { Map<String, String> base = new HashMap<>(); base.put("label1", "value1"); base.put(Labels.STRIMZI_DOMAIN + "label2", "value2"); Map<String, String> overrides1 = new HashMap<>(); overrides1.put("override1", "value1"); overrides1.put(Labels.KUBERNETES_DOMAIN + "override2", "value2"); Map<String, String> overrides2 = new HashMap<>(); overrides2.put("override3", "value3"); Map<String, String> forbiddenOverrides = new HashMap<>(); forbiddenOverrides.put(Labels.STRIMZI_DOMAIN + "override4", "value4"); Map<String, String> expected = new HashMap<>(); expected.put("label1", "value1"); expected.put(Labels.STRIMZI_DOMAIN + "label2", "value2"); expected.put("override1", "value1"); expected.put("override3", "value3"); assertThat(Util.mergeLabelsOrAnnotations(base, overrides1, overrides2), is(expected)); assertThat(Util.mergeLabelsOrAnnotations(base, overrides1, null, overrides2), is(expected)); assertThat(Util.mergeLabelsOrAnnotations(base, null), is(base)); assertThat(Util.mergeLabelsOrAnnotations(base), is(base)); assertThat(Util.mergeLabelsOrAnnotations(null, overrides2), is(overrides2)); assertThrows(InvalidResourceException.class, () -> Util.mergeLabelsOrAnnotations(base, forbiddenOverrides)); }