KafkaExporter extends AbstractModel { public Deployment generateDeployment(boolean isOpenShift, ImagePullPolicy imagePullPolicy, List<LocalObjectReference> imagePullSecrets) { if (!isDeployed()) { return null; } DeploymentStrategy updateStrategy = new DeploymentStrategyBuilder() .withType("RollingUpdate") .build(); return createDeployment( updateStrategy, Collections.emptyMap(), Collections.emptyMap(), getMergedAffinity(), getInitContainers(imagePullPolicy), getContainers(imagePullPolicy), getVolumes(isOpenShift), imagePullSecrets ); } protected  KafkaExporter(HasMetadata resource); static KafkaExporter fromCrd(Kafka kafkaAssembly, KafkaVersion.Lookup versions); Deployment generateDeployment(boolean isOpenShift, ImagePullPolicy imagePullPolicy, List<LocalObjectReference> imagePullSecrets); static String kafkaExporterName(String kafkaCluster); static String secretName(String kafkaCluster); static String containerServiceAccountName(String kafkaCluster); Secret generateSecret(ClusterCa clusterCa, boolean isMaintenanceTimeWindowsSatisfied); static final Probe READINESS_PROBE_OPTIONS; }
@Test public void testGenerateDeployment() { Deployment dep = ke.generateDeployment(true, null, null); List<Container> containers = dep.getSpec().getTemplate().getSpec().getContainers(); assertThat(containers.size(), is(1)); assertThat(dep.getMetadata().getName(), is(KafkaExporterResources.deploymentName(cluster))); assertThat(dep.getMetadata().getNamespace(), is(namespace)); assertThat(dep.getMetadata().getOwnerReferences().size(), is(1)); assertThat(dep.getMetadata().getOwnerReferences().get(0), is(ke.createOwnerReference())); assertThat(containers.get(0).getImage(), is(ke.image)); assertThat(containers.get(0).getEnv(), is(getExpectedEnvVars())); assertThat(containers.get(0).getPorts().size(), is(1)); assertThat(containers.get(0).getPorts().get(0).getName(), is(KafkaExporter.METRICS_PORT_NAME)); assertThat(containers.get(0).getPorts().get(0).getProtocol(), is("TCP")); assertThat(dep.getSpec().getStrategy().getType(), is("RollingUpdate")); List<Volume> volumes = dep.getSpec().getTemplate().getSpec().getVolumes(); assertThat(volumes.size(), is(2)); Volume volume = volumes.stream().filter(vol -> KafkaExporter.CLUSTER_CA_CERTS_VOLUME_NAME.equals(vol.getName())).findFirst().get(); assertThat(volume, is(notNullValue())); assertThat(volume.getSecret().getSecretName(), is(KafkaResources.clusterCaCertificateSecretName(cluster))); volume = volumes.stream().filter(vol -> KafkaExporter.KAFKA_EXPORTER_CERTS_VOLUME_NAME.equals(vol.getName())).findFirst().get(); assertThat(volume, is(notNullValue())); assertThat(volume.getSecret().getSecretName(), is(KafkaExporterResources.secretName(cluster))); List<VolumeMount> volumesMounts = dep.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts(); assertThat(volumesMounts.size(), is(2)); VolumeMount volumeMount = volumesMounts.stream().filter(vol -> KafkaExporter.CLUSTER_CA_CERTS_VOLUME_NAME.equals(vol.getName())).findFirst().get(); assertThat(volumeMount, is(notNullValue())); assertThat(volumeMount.getMountPath(), is(KafkaExporter.CLUSTER_CA_CERTS_VOLUME_MOUNT)); volumeMount = volumesMounts.stream().filter(vol -> KafkaExporter.KAFKA_EXPORTER_CERTS_VOLUME_NAME.equals(vol.getName())).findFirst().get(); assertThat(volumeMount, is(notNullValue())); assertThat(volumeMount.getMountPath(), is(KafkaExporter.KAFKA_EXPORTER_CERTS_VOLUME_MOUNT)); }