ZookeeperCluster extends AbstractModel { public Secret generateNodesSecret(ClusterCa clusterCa, Kafka kafka, boolean isMaintenanceTimeWindowsSatisfied) { Map<String, String> data = new HashMap<>(replicas * 4); log.debug("Generating certificates"); Map<String, CertAndKey> certs; try { log.debug("Cluster communication certificates"); certs = clusterCa.generateZkCerts(kafka, isMaintenanceTimeWindowsSatisfied); log.debug("End generating certificates"); for (int i = 0; i < replicas; i++) { CertAndKey cert = certs.get(ZookeeperCluster.zookeeperPodName(cluster, i)); data.put(ZookeeperCluster.zookeeperPodName(cluster, i) + ".key", cert.keyAsBase64String()); data.put(ZookeeperCluster.zookeeperPodName(cluster, i) + ".crt", cert.certAsBase64String()); data.put(ZookeeperCluster.zookeeperPodName(cluster, i) + ".p12", cert.keyStoreAsBase64String()); data.put(ZookeeperCluster.zookeeperPodName(cluster, i) + ".password", cert.storePasswordAsBase64String()); } } catch (IOException e) { log.warn("Error while generating certificates", e); } return createSecret(ZookeeperCluster.nodesSecretName(cluster), data); } private  ZookeeperCluster(HasMetadata resource); static String zookeeperClusterName(String cluster); static String zookeeperMetricAndLogConfigsName(String cluster); static String serviceName(String cluster); static String headlessServiceName(String cluster); static String podDnsName(String namespace, String cluster, int podId); static String podDnsNameWithoutSuffix(String namespace, String cluster, int podId); static String zookeeperPodName(String cluster, int pod); static String nodesSecretName(String cluster); static ZookeeperCluster fromCrd(Kafka kafkaAssembly, KafkaVersion.Lookup versions); @SuppressWarnings({"checkstyle:MethodLength", "checkstyle:CyclomaticComplexity"}) static ZookeeperCluster fromCrd(Kafka kafkaAssembly, KafkaVersion.Lookup versions, Storage oldStorage, int oldReplicas); Service generateService(); static String policyName(String cluster); NetworkPolicy generateNetworkPolicy(boolean namespaceAndPodSelectorNetworkPolicySupported); Service generateHeadlessService(); StatefulSet generateStatefulSet(boolean isOpenShift, ImagePullPolicy imagePullPolicy, List<LocalObjectReference> imagePullSecrets); Secret generateNodesSecret(ClusterCa clusterCa, Kafka kafka, boolean isMaintenanceTimeWindowsSatisfied); List<PersistentVolumeClaim> generatePersistentVolumeClaims(); PodDisruptionBudget generatePodDisruptionBudget(); static String containerServiceAccountName(String zookeeperResourceName); @Override void setImage(String image); void setVersion(String version); String getVersion(); ConfigMap generateConfigurationConfigMap(ConfigMap cm); static final int CLIENT_PLAINTEXT_PORT; static final int CLIENT_TLS_PORT; static final int CLUSTERING_PORT; static final int LEADER_ELECTION_PORT; static final String ZOOKEEPER_NAME; static final Probe DEFAULT_HEALTHCHECK_OPTIONS; static final String ENV_VAR_ZOOKEEPER_METRICS_ENABLED; static final String ENV_VAR_ZOOKEEPER_CONFIGURATION; static final String ENV_VAR_ZOOKEEPER_SNAPSHOT_CHECK_ENABLED; static final String CONFIG_MAP_KEY_ZOOKEEPER_NODE_COUNT; }
@Test public void testGenerateBrokerSecret() throws CertificateParsingException { ClusterCa clusterCa = new ClusterCa(new OpenSslCertManager(), new PasswordGenerator(10, "a", "a"), cluster, null, null); clusterCa.createRenewOrReplace(namespace, cluster, emptyMap(), null, true); Secret secret = zc.generateNodesSecret(clusterCa, ka, true); assertThat(secret.getData().keySet(), is(set( "foo-zookeeper-0.crt", "foo-zookeeper-0.key", "foo-zookeeper-0.p12", "foo-zookeeper-0.password", "foo-zookeeper-1.crt", "foo-zookeeper-1.key", "foo-zookeeper-1.p12", "foo-zookeeper-1.password", "foo-zookeeper-2.crt", "foo-zookeeper-2.key", "foo-zookeeper-2.p12", "foo-zookeeper-2.password"))); X509Certificate cert = Ca.cert(secret, "foo-zookeeper-0.crt"); assertThat(cert.getSubjectDN().getName(), is("CN=foo-zookeeper, O=io.strimzi")); assertThat(new HashSet<Object>(cert.getSubjectAlternativeNames()), is(set( asList(2, "foo-zookeeper-0.foo-zookeeper-nodes.test.svc"), asList(2, "foo-zookeeper-0.foo-zookeeper-nodes.test.svc.cluster.local"), asList(2, "foo-zookeeper-client"), asList(2, "foo-zookeeper-client.test"), asList(2, "foo-zookeeper-client.test.svc"), asList(2, "foo-zookeeper-client.test.svc.cluster.local"), asList(2, "*.foo-zookeeper-client.test.svc"), asList(2, "*.foo-zookeeper-client.test.svc.cluster.local"), asList(2, "*.foo-zookeeper-nodes.test.svc"), asList(2, "*.foo-zookeeper-nodes.test.svc.cluster.local")))); }