EntityTopicOperator extends AbstractModel { public static EntityTopicOperator fromCrd(Kafka kafkaAssembly) { EntityTopicOperator result = null; EntityOperatorSpec entityOperatorSpec = kafkaAssembly.getSpec().getEntityOperator(); if (entityOperatorSpec != null) { EntityTopicOperatorSpec topicOperatorSpec = entityOperatorSpec.getTopicOperator(); if (topicOperatorSpec != null) { String namespace = kafkaAssembly.getMetadata().getNamespace(); result = new EntityTopicOperator(kafkaAssembly); result.setOwnerReference(kafkaAssembly); String image = topicOperatorSpec.getImage(); if (image == null) { image = System.getenv().getOrDefault(ClusterOperatorConfig.STRIMZI_DEFAULT_TOPIC_OPERATOR_IMAGE, "strimzi/operator:latest"); } result.setImage(image); result.setWatchedNamespace(topicOperatorSpec.getWatchedNamespace() != null ? topicOperatorSpec.getWatchedNamespace() : namespace); result.setReconciliationIntervalMs(topicOperatorSpec.getReconciliationIntervalSeconds() * 1_000); result.setZookeeperSessionTimeoutMs(topicOperatorSpec.getZookeeperSessionTimeoutSeconds() * 1_000); result.setTopicMetadataMaxAttempts(topicOperatorSpec.getTopicMetadataMaxAttempts()); result.setLogging(topicOperatorSpec.getLogging()); result.setGcLoggingEnabled(topicOperatorSpec.getJvmOptions() == null ? DEFAULT_JVM_GC_LOGGING_ENABLED : topicOperatorSpec.getJvmOptions().isGcLoggingEnabled()); if (topicOperatorSpec.getJvmOptions() != null) { result.setJavaSystemProperties(topicOperatorSpec.getJvmOptions().getJavaSystemProperties()); } result.setJvmOptions(topicOperatorSpec.getJvmOptions()); result.setResources(topicOperatorSpec.getResources()); if (topicOperatorSpec.getReadinessProbe() != null) { result.setReadinessProbe(topicOperatorSpec.getReadinessProbe()); } if (topicOperatorSpec.getLivenessProbe() != null) { result.setLivenessProbe(topicOperatorSpec.getLivenessProbe()); } } } return result; } protected  EntityTopicOperator(HasMetadata resource); void setWatchedNamespace(String watchedNamespace); String getWatchedNamespace(); void setResourceLabels(String resourceLabels); String getResourceLabels(); void setReconciliationIntervalMs(int reconciliationIntervalMs); int getReconciliationIntervalMs(); void setZookeeperSessionTimeoutMs(int zookeeperSessionTimeoutMs); int getZookeeperSessionTimeoutMs(); void setKafkaBootstrapServers(String kafkaBootstrapServers); String getKafkaBootstrapServers(); void setTopicMetadataMaxAttempts(int topicMetadataMaxAttempts); int getTopicMetadataMaxAttempts(); void setZookeeperConnect(String zookeeperConnect); String getZookeeperConnect(); static String topicOperatorName(String cluster); static String metricAndLogConfigsName(String cluster); static String roleBindingName(String cluster); @Override String getAncillaryConfigMapKeyLogConfig(); static EntityTopicOperator fromCrd(Kafka kafkaAssembly); List<Volume> getVolumes(); RoleBinding generateRoleBinding(String namespace, String watchedNamespace); void setContainerEnvVars(List<ContainerEnvVar> envVars); void setContainerSecurityContext(SecurityContext securityContext); @Override String createLog4jProperties(OrderedProperties properties); static final String ENV_VAR_RESOURCE_LABELS; static final String ENV_VAR_KAFKA_BOOTSTRAP_SERVERS; static final String ENV_VAR_ZOOKEEPER_CONNECT; static final String ENV_VAR_WATCHED_NAMESPACE; static final String ENV_VAR_FULL_RECONCILIATION_INTERVAL_MS; static final String ENV_VAR_ZOOKEEPER_SESSION_TIMEOUT_MS; static final String ENV_VAR_TOPIC_METADATA_MAX_ATTEMPTS; static final String ENV_VAR_TLS_ENABLED; static final Probe DEFAULT_HEALTHCHECK_OPTIONS; }
@Test public void testFromCrd() { assertThat(entityTopicOperator.namespace, is(namespace)); assertThat(entityTopicOperator.cluster, is(cluster)); assertThat(entityTopicOperator.image, is(toImage)); assertThat(entityTopicOperator.readinessProbeOptions.getInitialDelaySeconds(), is(readinessProbe.getInitialDelaySeconds())); assertThat(entityTopicOperator.readinessProbeOptions.getTimeoutSeconds(), is(readinessProbe.getTimeoutSeconds())); assertThat(entityTopicOperator.readinessProbeOptions.getSuccessThreshold(), is(readinessProbe.getSuccessThreshold())); assertThat(entityTopicOperator.readinessProbeOptions.getFailureThreshold(), is(readinessProbe.getFailureThreshold())); assertThat(entityTopicOperator.readinessProbeOptions.getPeriodSeconds(), is(readinessProbe.getPeriodSeconds())); assertThat(entityTopicOperator.livenessProbeOptions.getInitialDelaySeconds(), is(livenessProbe.getInitialDelaySeconds())); assertThat(entityTopicOperator.livenessProbeOptions.getTimeoutSeconds(), is(livenessProbe.getTimeoutSeconds())); assertThat(entityTopicOperator.livenessProbeOptions.getSuccessThreshold(), is(livenessProbe.getSuccessThreshold())); assertThat(entityTopicOperator.livenessProbeOptions.getFailureThreshold(), is(livenessProbe.getFailureThreshold())); assertThat(entityTopicOperator.livenessProbeOptions.getPeriodSeconds(), is(livenessProbe.getPeriodSeconds())); assertThat(entityTopicOperator.getWatchedNamespace(), is(toWatchedNamespace)); assertThat(entityTopicOperator.getReconciliationIntervalMs(), is(toReconciliationInterval * 1000)); assertThat(entityTopicOperator.getZookeeperSessionTimeoutMs(), is(toZookeeperSessionTimeout * 1000)); assertThat(entityTopicOperator.getZookeeperConnect(), is(EntityTopicOperator.defaultZookeeperConnect(cluster))); assertThat(entityTopicOperator.getKafkaBootstrapServers(), is(EntityTopicOperator.defaultBootstrapServers(cluster))); assertThat(entityTopicOperator.getResourceLabels(), is(ModelUtils.defaultResourceLabels(cluster))); assertThat(entityTopicOperator.getTopicMetadataMaxAttempts(), is(toTopicMetadataMaxAttempts)); assertThat(entityTopicOperator.getLogging().getType(), is(topicOperatorLogging.getType())); assertThat(((InlineLogging) entityTopicOperator.getLogging()).getLoggers(), is(topicOperatorLogging.getLoggers())); }
@Test public void testFromCrdNoEntityOperator() { Kafka resource = ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout); EntityTopicOperator entityTopicOperator = EntityTopicOperator.fromCrd(resource); assertThat(entityTopicOperator, is(nullValue())); }
@Test public void testFromCrdNoTopicOperatorInEntityOperator() { EntityOperatorSpec entityOperatorSpec = new EntityOperatorSpecBuilder().build(); Kafka resource = new KafkaBuilder(ResourceUtils.createKafka(namespace, cluster, replicas, image, healthDelay, healthTimeout)) .editSpec() .withEntityOperator(entityOperatorSpec) .endSpec() .build(); EntityTopicOperator entityTopicOperator = EntityTopicOperator.fromCrd(resource); assertThat(entityTopicOperator, is(nullValue())); }