ModelUtils { public static boolean doExistingCertificatesDiffer(Secret current, Secret desired) { Map<String, String> currentData = current.getData(); Map<String, String> desiredData = desired.getData(); for (Map.Entry<String, String> entry : currentData.entrySet()) { String desiredValue = desiredData.get(entry.getKey()); if (entry.getValue() != null && desiredValue != null && !entry.getValue().equals(desiredValue)) { return true; } } return false; } private  ModelUtils(); static int getCertificateValidity(CertificateAuthority certificateAuthority); static int getRenewalDays(CertificateAuthority certificateAuthority); static String formatTimestamp(Date date); static String defaultResourceLabels(String cluster); static Map<String, String> getContainerEnv(StatefulSet sts, String containerName); static Secret buildSecret(ClusterCa clusterCa, Secret secret, String namespace, String secretName,
            String commonName, String keyCertName, Labels labels, OwnerReference ownerReference, boolean isMaintenanceTimeWindowsSatisfied); static Secret createSecret(String name, String namespace, Labels labels, OwnerReference ownerReference, Map<String, String> data); static void parsePodDisruptionBudgetTemplate(AbstractModel model, PodDisruptionBudgetTemplate pdb); static void parsePodTemplate(AbstractModel model, PodTemplate pod); static boolean containsPersistentStorage(Storage storage); static Storage decodeStorageFromJson(String json); static String encodeStorageToJson(Storage storage); static Map<String, String> getCustomLabelsOrAnnotations(String envVarName); static boolean doExistingCertificatesDiffer(Secret current, Secret desired); static List<T> asListOrEmptyList(List<T> list); static String getJavaSystemPropertiesToString(List<SystemProperty> javaSystemProperties); static List<String> getLinesWithoutCommentsAndEmptyLines(String config); static void removeEmptyValuesFromTolerations(List<Toleration> tolerations); static List<Toleration> tolerations(String tolerations, List<Toleration> tolerationList, String templateTolerations, PodTemplate podTemplate); static AffinityBuilder populateAffinityBuilderWithRackLabelSelector(AffinityBuilder builder, Affinity userAffinity, String topologyKey); static final String TLS_SIDECAR_LOG_LEVEL; }
@Test public void testExistingCertificatesDiffer() { Secret defaultSecret = new SecretBuilder() .withNewMetadata() .withName("my-secret") .endMetadata() .addToData("my-cluster-kafka-0.crt", "Certificate0") .addToData("my-cluster-kafka-0.key", "Key0") .addToData("my-cluster-kafka-1.crt", "Certificate1") .addToData("my-cluster-kafka-1.key", "Key1") .addToData("my-cluster-kafka-2.crt", "Certificate2") .addToData("my-cluster-kafka-2.key", "Key2") .build(); Secret sameAsDefaultSecret = new SecretBuilder() .withNewMetadata() .withName("my-secret") .endMetadata() .addToData("my-cluster-kafka-0.crt", "Certificate0") .addToData("my-cluster-kafka-0.key", "Key0") .addToData("my-cluster-kafka-1.crt", "Certificate1") .addToData("my-cluster-kafka-1.key", "Key1") .addToData("my-cluster-kafka-2.crt", "Certificate2") .addToData("my-cluster-kafka-2.key", "Key2") .build(); Secret scaleDownSecret = new SecretBuilder() .withNewMetadata() .withName("my-secret") .endMetadata() .addToData("my-cluster-kafka-0.crt", "Certificate0") .addToData("my-cluster-kafka-0.key", "Key0") .build(); Secret scaleUpSecret = new SecretBuilder() .withNewMetadata() .withName("my-secret") .endMetadata() .addToData("my-cluster-kafka-0.crt", "Certificate0") .addToData("my-cluster-kafka-0.key", "Key0") .addToData("my-cluster-kafka-1.crt", "Certificate1") .addToData("my-cluster-kafka-1.key", "Key1") .addToData("my-cluster-kafka-2.crt", "Certificate2") .addToData("my-cluster-kafka-2.key", "Key2") .addToData("my-cluster-kafka-3.crt", "Certificate3") .addToData("my-cluster-kafka-3.key", "Key3") .addToData("my-cluster-kafka-4.crt", "Certificate4") .addToData("my-cluster-kafka-4.key", "Key4") .build(); Secret changedSecret = new SecretBuilder() .withNewMetadata() .withName("my-secret") .endMetadata() .addToData("my-cluster-kafka-0.crt", "Certificate0") .addToData("my-cluster-kafka-0.key", "Key0") .addToData("my-cluster-kafka-1.crt", "Certificate1") .addToData("my-cluster-kafka-1.key", "NewKey1") .addToData("my-cluster-kafka-2.crt", "Certificate2") .addToData("my-cluster-kafka-2.key", "Key2") .build(); Secret changedScaleUpSecret = new SecretBuilder() .withNewMetadata() .withName("my-secret") .endMetadata() .addToData("my-cluster-kafka-0.crt", "Certificate0") .addToData("my-cluster-kafka-0.key", "Key0") .addToData("my-cluster-kafka-1.crt", "Certificate1") .addToData("my-cluster-kafka-1.key", "Key1") .addToData("my-cluster-kafka-2.crt", "NewCertificate2") .addToData("my-cluster-kafka-2.key", "Key2") .addToData("my-cluster-kafka-3.crt", "Certificate3") .addToData("my-cluster-kafka-3.key", "Key3") .addToData("my-cluster-kafka-4.crt", "Certificate4") .addToData("my-cluster-kafka-4.key", "Key4") .build(); Secret changedScaleDownSecret = new SecretBuilder() .withNewMetadata() .withName("my-secret") .endMetadata() .addToData("my-cluster-kafka-0.crt", "NewCertificate0") .addToData("my-cluster-kafka-0.key", "NewKey0") .build(); assertThat(ModelUtils.doExistingCertificatesDiffer(defaultSecret, defaultSecret), is(false)); assertThat(ModelUtils.doExistingCertificatesDiffer(defaultSecret, sameAsDefaultSecret), is(false)); assertThat(ModelUtils.doExistingCertificatesDiffer(defaultSecret, scaleDownSecret), is(false)); assertThat(ModelUtils.doExistingCertificatesDiffer(defaultSecret, scaleUpSecret), is(false)); assertThat(ModelUtils.doExistingCertificatesDiffer(defaultSecret, changedSecret), is(true)); assertThat(ModelUtils.doExistingCertificatesDiffer(defaultSecret, changedScaleUpSecret), is(true)); assertThat(ModelUtils.doExistingCertificatesDiffer(defaultSecret, changedScaleDownSecret), is(true)); }