EntityOperator extends AbstractModel { public static EntityOperator fromCrd(Kafka kafkaAssembly, KafkaVersion.Lookup versions) { EntityOperator result = null; EntityOperatorSpec entityOperatorSpec = kafkaAssembly.getSpec().getEntityOperator(); if (entityOperatorSpec != null) { result = new EntityOperator(kafkaAssembly); result.setOwnerReference(kafkaAssembly); EntityTopicOperator topicOperator = EntityTopicOperator.fromCrd(kafkaAssembly); EntityUserOperator userOperator = EntityUserOperator.fromCrd(kafkaAssembly); TlsSidecar tlsSidecar = entityOperatorSpec.getTlsSidecar(); if (entityOperatorSpec.getTemplate() != null) { EntityOperatorTemplate template = entityOperatorSpec.getTemplate(); if (template.getDeployment() != null && template.getDeployment().getMetadata() != null) { result.templateDeploymentLabels = template.getDeployment().getMetadata().getLabels(); result.templateDeploymentAnnotations = template.getDeployment().getMetadata().getAnnotations(); } ModelUtils.parsePodTemplate(result, template.getPod()); if (template.getTopicOperatorContainer() != null && template.getTopicOperatorContainer().getEnv() != null) { topicOperator.setContainerEnvVars(template.getTopicOperatorContainer().getEnv()); } if (template.getTopicOperatorContainer() != null && template.getTopicOperatorContainer().getSecurityContext() != null) { topicOperator.setContainerSecurityContext(template.getTopicOperatorContainer().getSecurityContext()); } if (template.getUserOperatorContainer() != null && template.getUserOperatorContainer().getEnv() != null) { userOperator.setContainerEnvVars(template.getUserOperatorContainer().getEnv()); } if (template.getUserOperatorContainer() != null && template.getUserOperatorContainer().getSecurityContext() != null) { userOperator.setContainerSecurityContext(template.getUserOperatorContainer().getSecurityContext()); } if (template.getTlsSidecarContainer() != null && template.getTlsSidecarContainer().getEnv() != null) { result.templateTlsSidecarContainerEnvVars = template.getTlsSidecarContainer().getEnv(); } if (template.getTlsSidecarContainer() != null && template.getTlsSidecarContainer().getSecurityContext() != null) { result.templateTlsSidecarContainerSecurityContext = template.getTlsSidecarContainer().getSecurityContext(); } } result.setUserAffinity(affinity(entityOperatorSpec)); result.setTolerations(tolerations(entityOperatorSpec)); result.setTlsSidecar(tlsSidecar); result.setTopicOperator(topicOperator); result.setUserOperator(userOperator); result.setDeployed(result.getTopicOperator() != null || result.getUserOperator() != null); String tlsSideCarImage = tlsSidecar != null ? tlsSidecar.getImage() : null; if (tlsSideCarImage == null) { KafkaClusterSpec kafkaClusterSpec = kafkaAssembly.getSpec().getKafka(); tlsSideCarImage = System.getenv().getOrDefault(ClusterOperatorConfig.STRIMZI_DEFAULT_TLS_SIDECAR_ENTITY_OPERATOR_IMAGE, versions.kafkaImage(kafkaClusterSpec.getImage(), versions.defaultVersion().version())); } result.tlsSidecarImage = tlsSideCarImage; } return result; } 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 testFromCrd() { assertThat(entityOperator.namespace, is(namespace)); assertThat(entityOperator.cluster, is(cluster)); assertThat(entityOperator.getZookeeperConnect(), is(EntityOperator.defaultZookeeperConnect(cluster))); }