CruiseControl extends AbstractModel { public Deployment generateDeployment(boolean isOpenShift, Map<String, String> annotations, ImagePullPolicy imagePullPolicy, List<LocalObjectReference> imagePullSecrets) { if (!isDeployed()) { return null; } DeploymentStrategy updateStrategy = new DeploymentStrategyBuilder() .withType("RollingUpdate") .withRollingUpdate(new RollingUpdateDeploymentBuilder() .withMaxSurge(new IntOrString(1)) .withMaxUnavailable(new IntOrString(0)) .build()) .build(); return createDeployment( updateStrategy, Collections.emptyMap(), Collections.emptyMap(), getMergedAffinity(), getInitContainers(imagePullPolicy), getContainers(imagePullPolicy), getVolumes(isOpenShift), imagePullSecrets); } protected  CruiseControl(HasMetadata resource); static String metricAndLogConfigsName(String cluster); static CruiseControl fromCrd(Kafka kafkaAssembly, KafkaVersion.Lookup versions); static CruiseControl updateConfiguration(CruiseControlSpec spec, CruiseControl cruiseControl); static void checkGoals(CruiseControlConfiguration configuration); static CruiseControl updateTemplate(CruiseControlSpec spec, CruiseControl cruiseControl); static String cruiseControlName(String cluster); static String cruiseControlServiceName(String cluster); Service generateService(); Deployment generateDeployment(boolean isOpenShift, Map<String, String> annotations, ImagePullPolicy imagePullPolicy, List<LocalObjectReference> imagePullSecrets); PodDisruptionBudget generatePodDisruptionBudget(); static String cruiseControlServiceAccountName(String cluster); static String secretName(String kafkaCluster); Secret generateSecret(ClusterCa clusterCa, boolean isMaintenanceTimeWindowsSatisfied); static String policyName(String cluster); NetworkPolicy generateNetworkPolicy(boolean namespaceAndPodSelectorNetworkPolicySupported); static final String CRUISE_CONTROL_METRIC_REPORTER; static final String ANNO_STRIMZI_IO_LOGGING; static final String ENV_VAR_CRUISE_CONTROL_METRICS_ENABLED; static final boolean DEFAULT_CRUISE_CONTROL_METRICS_ENABLED; static final Probe DEFAULT_HEALTHCHECK_OPTIONS; static final String REST_API_PORT_NAME; static final int REST_API_PORT; static final String MIN_INSYNC_REPLICAS; }
@Test public void testGenerateDeployment() { Deployment dep = cc.generateDeployment(true, null, null, null); List<Container> containers = dep.getSpec().getTemplate().getSpec().getContainers(); assertThat(containers.size(), is(2)); assertThat(dep.getMetadata().getName(), is(CruiseControlResources.deploymentName(cluster))); assertThat(dep.getMetadata().getNamespace(), is(namespace)); assertThat(dep.getMetadata().getOwnerReferences().size(), is(1)); assertThat(dep.getMetadata().getOwnerReferences().get(0), is(cc.createOwnerReference())); Container ccContainer = containers.stream().filter(container -> ccImage.equals(container.getImage())).findFirst().get(); assertThat(ccContainer.getImage(), is(cc.image)); assertThat(ccContainer.getLivenessProbe().getInitialDelaySeconds(), is(Integer.valueOf(CruiseControl.DEFAULT_HEALTHCHECK_DELAY))); assertThat(ccContainer.getLivenessProbe().getTimeoutSeconds(), is(Integer.valueOf(CruiseControl.DEFAULT_HEALTHCHECK_TIMEOUT))); assertThat(ccContainer.getReadinessProbe().getInitialDelaySeconds(), is(Integer.valueOf(CruiseControl.DEFAULT_HEALTHCHECK_DELAY))); assertThat(ccContainer.getReadinessProbe().getTimeoutSeconds(), is(Integer.valueOf(CruiseControl.DEFAULT_HEALTHCHECK_TIMEOUT))); assertThat(ccContainer.getEnv(), is(getExpectedEnvVars())); assertThat(ccContainer.getPorts().size(), is(1)); assertThat(ccContainer.getPorts().get(0).getName(), is(CruiseControl.REST_API_PORT_NAME)); assertThat(ccContainer.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(3)); Volume volume = volumes.stream().filter(vol -> CruiseControl.TLS_SIDECAR_CC_CERTS_VOLUME_NAME.equals(vol.getName())).findFirst().get(); assertThat(volume, is(notNullValue())); assertThat(volume.getSecret().getSecretName(), is(CruiseControl.secretName(cluster))); volume = volumes.stream().filter(vol -> CruiseControl.TLS_SIDECAR_CA_CERTS_VOLUME_NAME.equals(vol.getName())).findFirst().get(); assertThat(volume, is(notNullValue())); assertThat(volume.getSecret().getSecretName(), is(AbstractModel.clusterCaCertSecretName(cluster))); volume = volumes.stream().filter(vol -> CruiseControl.LOG_AND_METRICS_CONFIG_VOLUME_NAME.equals(vol.getName())).findFirst().get(); assertThat(volume, is(notNullValue())); assertThat(volume.getConfigMap().getName(), is(CruiseControl.metricAndLogConfigsName(cluster))); List<VolumeMount> volumesMounts = dep.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts(); assertThat(volumesMounts.size(), is(3)); VolumeMount volumeMount = volumesMounts.stream().filter(vol -> CruiseControl.TLS_SIDECAR_CC_CERTS_VOLUME_NAME.equals(vol.getName())).findFirst().get(); assertThat(volumeMount, is(notNullValue())); assertThat(volumeMount.getMountPath(), is(CruiseControl.TLS_SIDECAR_CC_CERTS_VOLUME_MOUNT)); volumeMount = volumesMounts.stream().filter(vol -> CruiseControl.TLS_SIDECAR_CA_CERTS_VOLUME_NAME.equals(vol.getName())).findFirst().get(); assertThat(volumeMount, is(notNullValue())); assertThat(volumeMount.getMountPath(), is(CruiseControl.TLS_SIDECAR_CA_CERTS_VOLUME_MOUNT)); volumeMount = volumesMounts.stream().filter(vol -> CruiseControl.LOG_AND_METRICS_CONFIG_VOLUME_NAME.equals(vol.getName())).findFirst().get(); assertThat(volumeMount, is(notNullValue())); assertThat(volumeMount.getMountPath(), is(CruiseControl.LOG_AND_METRICS_CONFIG_VOLUME_MOUNT)); }
@Test public void testDefaultSecurityContext() { Deployment dep = cc.generateDeployment(true, null, null, null); assertThat(dep.getSpec().getTemplate().getSpec().getSecurityContext(), is(nullValue())); }