EntityOperator extends AbstractModel { public Deployment generateDeployment(boolean isOpenShift, Map<String, String> annotations, ImagePullPolicy imagePullPolicy, List<LocalObjectReference> imagePullSecrets) { if (!isDeployed()) { log.warn("Topic and/or User Operators not declared: Entity Operator will not be deployed"); return null; } DeploymentStrategy updateStrategy = new DeploymentStrategyBuilder() .withType("Recreate") .build(); return createDeployment( updateStrategy, Collections.emptyMap(), annotations, getMergedAffinity(), getInitContainers(imagePullPolicy), getContainers(imagePullPolicy), getVolumes(isOpenShift), imagePullSecrets ); } protected  EntityOperator(HasMetadata resource); void setTopicOperator(EntityTopicOperator topicOperator); EntityTopicOperator getTopicOperator(); void setUserOperator(EntityUserOperator userOperator); EntityUserOperator getUserOperator(); static String entityOperatorName(String cluster); void setZookeeperConnect(String zookeeperConnect); String getZookeeperConnect(); static String secretName(String cluster); void setDeployed(boolean isDeployed); boolean isDeployed(); static EntityOperator fromCrd(Kafka kafkaAssembly, KafkaVersion.Lookup versions); Deployment generateDeployment(boolean isOpenShift, Map<String, String> annotations, ImagePullPolicy imagePullPolicy, List<LocalObjectReference> imagePullSecrets); Secret generateSecret(ClusterCa clusterCa, boolean isMaintenanceTimeWindowsSatisfied); static String entityOperatorServiceAccountName(String cluster); @Override ServiceAccount generateServiceAccount(); static final String ENV_VAR_ZOOKEEPER_CONNECT; static final String EO_CLUSTER_ROLE_NAME; }
@Test public void testGenerateDeployment() { Deployment dep = entityOperator.generateDeployment(true, Collections.EMPTY_MAP, null, null); List<Container> containers = dep.getSpec().getTemplate().getSpec().getContainers(); assertThat(dep.getMetadata().getName(), is(entityOperator.entityOperatorName(cluster))); assertThat(dep.getMetadata().getNamespace(), is(namespace)); assertThat(dep.getSpec().getReplicas(), is(Integer.valueOf(EntityOperatorSpec.DEFAULT_REPLICAS))); assertThat(dep.getMetadata().getOwnerReferences().size(), is(1)); assertThat(dep.getMetadata().getOwnerReferences().get(0), is(entityOperator.createOwnerReference())); assertThat(containers.size(), is(3)); assertThat(containers.get(0).getName(), is(EntityTopicOperator.TOPIC_OPERATOR_CONTAINER_NAME)); assertThat(containers.get(1).getName(), is(EntityUserOperator.USER_OPERATOR_CONTAINER_NAME)); Container tlsSidecarContainer = containers.get(2); assertThat(tlsSidecarContainer.getImage(), is(image)); assertThat(AbstractModel.containerEnvVars(tlsSidecarContainer).get(EntityOperator.ENV_VAR_ZOOKEEPER_CONNECT), is(EntityOperator.defaultZookeeperConnect(cluster))); assertThat(AbstractModel.containerEnvVars(tlsSidecarContainer).get(ModelUtils.TLS_SIDECAR_LOG_LEVEL), is(TlsSidecarLogLevel.NOTICE.toValue())); assertThat(EntityOperatorTest.volumeMounts(tlsSidecarContainer.getVolumeMounts()), is(map( EntityOperator.TLS_SIDECAR_CA_CERTS_VOLUME_NAME, EntityOperator.TLS_SIDECAR_CA_CERTS_VOLUME_MOUNT, EntityOperator.TLS_SIDECAR_EO_CERTS_VOLUME_NAME, EntityOperator.TLS_SIDECAR_EO_CERTS_VOLUME_MOUNT))); assertThat(tlsSidecarContainer.getReadinessProbe().getInitialDelaySeconds(), is(Integer.valueOf(tlsHealthDelay))); assertThat(tlsSidecarContainer.getReadinessProbe().getTimeoutSeconds(), is(Integer.valueOf(tlsHealthTimeout))); assertThat(tlsSidecarContainer.getLivenessProbe().getInitialDelaySeconds(), is(Integer.valueOf(tlsHealthDelay))); assertThat(tlsSidecarContainer.getLivenessProbe().getTimeoutSeconds(), is(Integer.valueOf(tlsHealthTimeout))); }
@Test public void withOldAffinityAndTolerations() throws IOException { ResourceTester<Kafka, EntityOperator> helper = new ResourceTester<>(Kafka.class, VERSIONS, EntityOperator::fromCrd, this.getClass().getSimpleName() + ".withOldAffinityAndTolerations"); helper.assertDesiredResource("-DeploymentAffinity.yaml", zc -> zc.generateDeployment(true, Collections.EMPTY_MAP, null, null).getSpec().getTemplate().getSpec().getAffinity()); helper.assertDesiredResource("-DeploymentTolerations.yaml", zc -> zc.generateDeployment(true, Collections.EMPTY_MAP, null, null).getSpec().getTemplate().getSpec().getTolerations()); }
@Test public void withAffinityAndTolerations() throws IOException { ResourceTester<Kafka, EntityOperator> helper = new ResourceTester<>(Kafka.class, VERSIONS, EntityOperator::fromCrd, this.getClass().getSimpleName() + ".withAffinityAndTolerations"); helper.assertDesiredResource("-DeploymentAffinity.yaml", zc -> zc.generateDeployment(true, Collections.EMPTY_MAP, null, null).getSpec().getTemplate().getSpec().getAffinity()); helper.assertDesiredResource("-DeploymentTolerations.yaml", zc -> zc.generateDeployment(true, Collections.EMPTY_MAP, null, null).getSpec().getTemplate().getSpec().getTolerations()); }