Search in sources :

Example 21 with Type

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Type in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class ConnectorDeploymentProvisioner method createManagedConnector.

private ManagedConnector createManagedConnector(String uow, ConnectorDeployment deployment, HasMetadata owner) {
    ManagedConnector connector = fleetShard.getConnector(deployment).orElseGet(() -> {
        LOGGER.info("Connector not found (cluster_id: {}, connector_id: {}, deployment_id: {}, resource_version: {}), creating a new one", fleetShard.getClusterId(), deployment.getSpec().getConnectorId(), deployment.getId(), deployment.getMetadata().getResourceVersion());
        return Connectors.newConnector(fleetShard.getClusterId(), deployment.getSpec().getConnectorId(), deployment.getId(), Map.of());
    });
    // TODO: change APIs to include a single operator
    // move operator one level up
    // include full operator info in ConnectorDeployment APIs
    ArrayNode operatorsMeta = deployment.getSpec().getShardMetadata().withArray("operators");
    if (operatorsMeta.size() != 1) {
        throw new IllegalArgumentException("Multiple selectors are not yet supported");
    }
    OperatorSelector operatorSelector = new OperatorSelector(deployment.getSpec().getOperatorId(), operatorsMeta.get(0).requiredAt("/type").asText(), operatorsMeta.get(0).requiredAt("/version").asText());
    if (operatorSelector.getId() == null) {
        final OperatorSelector currentSelector = connector.getSpec().getOperatorSelector();
        // don't select a new operator if previously set.
        if (currentSelector != null && currentSelector.getId() != null) {
            operatorSelector.setId(currentSelector.getId());
        } else {
            OperatorSelectorUtil.assign(operatorSelector, fleetShard.lookupOperators()).map(Operator::getId).ifPresent(operatorSelector::setId);
        }
    }
    if (operatorSelector.getId() != null) {
        Resources.setLabel(connector, Resources.LABEL_OPERATOR_ASSIGNED, operatorSelector.getId());
    }
    if (operatorSelector.getType() != null) {
        Resources.setLabel(connector, Resources.LABEL_OPERATOR_TYPE, operatorSelector.getType());
    }
    if (config != null) {
        config.connectors().labels().forEach((k, v) -> {
            Resources.setLabel(connector, k, v);
        });
        config.connectors().annotations().forEach((k, v) -> {
            Resources.setAnnotation(connector, k, v);
        });
    }
    connector.getMetadata().setOwnerReferences(List.of(new OwnerReferenceBuilder().withApiVersion(owner.getApiVersion()).withKind(owner.getKind()).withName(owner.getMetadata().getName()).withUid(owner.getMetadata().getUid()).withBlockOwnerDeletion(true).build()));
    // add resource version to label
    Resources.setLabel(connector, Resources.LABEL_DEPLOYMENT_RESOURCE_VERSION, "" + deployment.getMetadata().getResourceVersion());
    // add uow
    Resources.setLabel(connector, Resources.LABEL_UOW, uow);
    connector.getSpec().getDeployment().setDeploymentResourceVersion(deployment.getMetadata().getResourceVersion());
    connector.getSpec().getDeployment().setDesiredState(deployment.getSpec().getDesiredState());
    connector.getSpec().getDeployment().setConnectorTypeId(deployment.getSpec().getConnectorTypeId());
    connector.getSpec().getDeployment().setConnectorResourceVersion(deployment.getSpec().getConnectorResourceVersion());
    KafkaConnectionSettings kafkaConnectionSettings = deployment.getSpec().getKafka();
    if (kafkaConnectionSettings != null) {
        connector.getSpec().getDeployment().setKafka(new KafkaSpecBuilder().withId(kafkaConnectionSettings.getId()).withUrl(kafkaConnectionSettings.getUrl()).build());
    }
    SchemaRegistryConnectionSettings schemaRegistryConnectionSettings = deployment.getSpec().getSchemaRegistry();
    if (schemaRegistryConnectionSettings != null) {
        connector.getSpec().getDeployment().setSchemaRegistry(new SchemaRegistrySpecBuilder().withId(schemaRegistryConnectionSettings.getId()).withUrl(schemaRegistryConnectionSettings.getUrl()).build());
    }
    connector.getSpec().getDeployment().setConnectorResourceVersion(deployment.getSpec().getConnectorResourceVersion());
    connector.getSpec().getDeployment().setSecret(Secrets.generateConnectorSecretId(deployment.getId()));
    connector.getSpec().getDeployment().setUnitOfWork(uow);
    connector.getSpec().setOperatorSelector(operatorSelector);
    LOGGER.info("Provisioning connector id={} rv={} - {}/{}: {}", connector.getMetadata().getName(), connector.getSpec().getDeployment().getDeploymentResourceVersion(), fleetShard.getConnectorsNamespace(), connector.getSpec().getConnectorId(), Serialization.asJson(connector.getSpec()));
    try {
        return fleetShard.createConnector(connector);
    } catch (Exception e) {
        LOGGER.warn("", e);
        throw e;
    }
}
Also used : OwnerReferenceBuilder(io.fabric8.kubernetes.api.model.OwnerReferenceBuilder) KafkaSpecBuilder(org.bf2.cos.fleetshard.api.KafkaSpecBuilder) SchemaRegistryConnectionSettings(org.bf2.cos.fleet.manager.model.SchemaRegistryConnectionSettings) SchemaRegistrySpecBuilder(org.bf2.cos.fleetshard.api.SchemaRegistrySpecBuilder) ManagedConnector(org.bf2.cos.fleetshard.api.ManagedConnector) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) OperatorSelector(org.bf2.cos.fleetshard.api.OperatorSelector) KafkaConnectionSettings(org.bf2.cos.fleet.manager.model.KafkaConnectionSettings)

Example 22 with Type

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Type in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class CamelOperandController method doReify.

@Override
protected List<HasMetadata> doReify(ManagedConnector connector, CamelShardMetadata shardMetadata, ConnectorConfiguration<ObjectNode> connectorConfiguration, ServiceAccountSpec serviceAccountSpec) {
    final Map<String, String> properties = createSecretsData(connector, shardMetadata, connectorConfiguration, serviceAccountSpec, configuration, new TreeMap<>());
    final List<ProcessorKamelet> stepDefinitions = createSteps(connector, connectorConfiguration, shardMetadata, properties);
    final String source;
    final String sink;
    switch(shardMetadata.getConnectorType()) {
        case CONNECTOR_TYPE_SOURCE:
            source = shardMetadata.getKamelets().getAdapter().getName();
            sink = shardMetadata.getKamelets().getKafka().getName();
            break;
        case CONNECTOR_TYPE_SINK:
            source = shardMetadata.getKamelets().getKafka().getName();
            sink = shardMetadata.getKamelets().getAdapter().getName();
            break;
        default:
            throw new IllegalArgumentException("Unknown connector type: " + shardMetadata.getConnectorType());
    }
    final Secret secret = new SecretBuilder().withMetadata(new ObjectMetaBuilder().withName(connector.getMetadata().getName() + Resources.CONNECTOR_SECRET_SUFFIX).build()).addToData(APPLICATION_PROPERTIES, asBytesBase64(properties)).build();
    final KameletBinding binding = new KameletBindingBuilder().withMetadata(new ObjectMetaBuilder().withName(connector.getMetadata().getName()).build()).withSpec(new KameletBindingSpecBuilder().withIntegration(createIntegrationSpec(secret.getMetadata().getName(), configuration, Map.of("CONNECTOR_SECRET_NAME", secret.getMetadata().getName(), "CONNECTOR_SECRET_CHECKSUM", Secrets.computeChecksum(secret), "CONNECTOR_ID", connector.getSpec().getConnectorId(), "CONNECTOR_DEPLOYMENT_ID", connector.getSpec().getDeploymentId()))).withSource(KameletEndpoint.kamelet(source, Map.of("id", connector.getSpec().getDeploymentId() + "-source"))).withSink(KameletEndpoint.kamelet(sink, Map.of("id", connector.getSpec().getDeploymentId() + "-sink"))).withErrorHandler(createErrorHandler(connectorConfiguration.getErrorHandlerSpec())).withSteps(stepDefinitions.stream().map(s -> KameletEndpoint.kamelet(s.getTemplateId(), Map.of("id", s.getId()))).collect(Collectors.toList())).build()).build();
    Map<String, String> annotations = KubernetesResourceUtil.getOrCreateAnnotations(binding);
    if (shardMetadata.getAnnotations() != null) {
        annotations.putAll(shardMetadata.getAnnotations());
    }
    annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_CONTAINER_IMAGE, shardMetadata.getConnectorImage());
    annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_KAMELETS_ENABLED, "false");
    annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_JVM_ENABLED, "false");
    annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_LOGGING_JSON, "false");
    annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_OWNER_TARGET_LABELS, LABELS_TO_TRANSFER);
    // health check annotations
    annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_ENABLED, "true");
    annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_PROBE_ENABLED, "true");
    annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_PROBE_ENABLED, "true");
    Health health = configuration.health();
    if (health != null) {
        annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_SUCCESS_THRESHOLD, health.readinessSuccessThreshold());
        annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_FAILURE_THRESHOLD, health.readinessFailureThreshold());
        annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_PERIOD, health.readinessPeriodSeconds());
        annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_TIMEOUT, health.readinessTimeoutSeconds());
        annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_SUCCESS_THRESHOLD, health.livenessSuccessThreshold());
        annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_FAILURE_THRESHOLD, health.livenessFailureThreshold());
        annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_PERIOD, health.livenessPeriodSeconds());
        annotations.putIfAbsent(TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_TIMEOUT, health.livenessTimeoutSeconds());
    }
    return List.of(secret, binding);
}
Also used : KameletBindingSpecBuilder(org.bf2.cos.fleetshard.operator.camel.model.KameletBindingSpecBuilder) Secrets(org.bf2.cos.fleetshard.support.resources.Secrets) CamelOperandSupport.createSteps(org.bf2.cos.fleetshard.operator.camel.CamelOperandSupport.createSteps) CamelOperandSupport.createIntegrationSpec(org.bf2.cos.fleetshard.operator.camel.CamelOperandSupport.createIntegrationSpec) LoggerFactory(org.slf4j.LoggerFactory) KameletEndpoint(org.bf2.cos.fleetshard.operator.camel.model.KameletEndpoint) TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_PERIOD(org.bf2.cos.fleetshard.operator.camel.CamelConstants.TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_PERIOD) TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_SUCCESS_THRESHOLD(org.bf2.cos.fleetshard.operator.camel.CamelConstants.TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_SUCCESS_THRESHOLD) CamelOperandSupport.computeStatus(org.bf2.cos.fleetshard.operator.camel.CamelOperandSupport.computeStatus) TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_TIMEOUT(org.bf2.cos.fleetshard.operator.camel.CamelConstants.TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_TIMEOUT) Map(java.util.Map) CollectionUtils.asBytesBase64(org.bf2.cos.fleetshard.support.CollectionUtils.asBytesBase64) KameletBindingBuilder(org.bf2.cos.fleetshard.operator.camel.model.KameletBindingBuilder) CamelOperandSupport.createErrorHandler(org.bf2.cos.fleetshard.operator.camel.CamelOperandSupport.createErrorHandler) ManagedConnector(org.bf2.cos.fleetshard.api.ManagedConnector) ConnectorConfiguration(org.bf2.cos.fleetshard.operator.connector.ConnectorConfiguration) CamelShardMetadata(org.bf2.cos.fleetshard.operator.camel.model.CamelShardMetadata) Health(org.bf2.cos.fleetshard.operator.camel.CamelOperandConfiguration.Health) ProcessorKamelet(org.bf2.cos.fleetshard.operator.camel.model.ProcessorKamelet) TRAIT_CAMEL_APACHE_ORG_OWNER_TARGET_LABELS(org.bf2.cos.fleetshard.operator.camel.CamelConstants.TRAIT_CAMEL_APACHE_ORG_OWNER_TARGET_LABELS) CamelOperandSupport.createSecretsData(org.bf2.cos.fleetshard.operator.camel.CamelOperandSupport.createSecretsData) Collectors(java.util.stream.Collectors) ServiceAccountSpec(org.bf2.cos.fleetshard.api.ServiceAccountSpec) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_TIMEOUT(org.bf2.cos.fleetshard.operator.camel.CamelConstants.TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_TIMEOUT) TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_PERIOD(org.bf2.cos.fleetshard.operator.camel.CamelConstants.TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_PERIOD) List(java.util.List) Secret(io.fabric8.kubernetes.api.model.Secret) CONNECTOR_TYPE_SINK(org.bf2.cos.fleetshard.operator.camel.CamelConstants.CONNECTOR_TYPE_SINK) TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_PROBE_ENABLED(org.bf2.cos.fleetshard.operator.camel.CamelConstants.TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_PROBE_ENABLED) TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_FAILURE_THRESHOLD(org.bf2.cos.fleetshard.operator.camel.CamelConstants.TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_FAILURE_THRESHOLD) TRAIT_CAMEL_APACHE_ORG_LOGGING_JSON(org.bf2.cos.fleetshard.operator.camel.CamelConstants.TRAIT_CAMEL_APACHE_ORG_LOGGING_JSON) TRAIT_CAMEL_APACHE_ORG_KAMELETS_ENABLED(org.bf2.cos.fleetshard.operator.camel.CamelConstants.TRAIT_CAMEL_APACHE_ORG_KAMELETS_ENABLED) Singleton(javax.inject.Singleton) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_FAILURE_THRESHOLD(org.bf2.cos.fleetshard.operator.camel.CamelConstants.TRAIT_CAMEL_APACHE_ORG_HEALTH_READINESS_FAILURE_THRESHOLD) APPLICATION_PROPERTIES(org.bf2.cos.fleetshard.operator.camel.CamelConstants.APPLICATION_PROPERTIES) TRAIT_CAMEL_APACHE_ORG_JVM_ENABLED(org.bf2.cos.fleetshard.operator.camel.CamelConstants.TRAIT_CAMEL_APACHE_ORG_JVM_ENABLED) TRAIT_CAMEL_APACHE_ORG_CONTAINER_IMAGE(org.bf2.cos.fleetshard.operator.camel.CamelConstants.TRAIT_CAMEL_APACHE_ORG_CONTAINER_IMAGE) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) CamelOperandSupport.lookupBinding(org.bf2.cos.fleetshard.operator.camel.CamelOperandSupport.lookupBinding) LABELS_TO_TRANSFER(org.bf2.cos.fleetshard.operator.camel.CamelConstants.LABELS_TO_TRANSFER) Logger(org.slf4j.Logger) AbstractOperandController(org.bf2.cos.fleetshard.operator.operand.AbstractOperandController) TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_SUCCESS_THRESHOLD(org.bf2.cos.fleetshard.operator.camel.CamelConstants.TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_SUCCESS_THRESHOLD) KubernetesResourceUtil(io.fabric8.kubernetes.client.utils.KubernetesResourceUtil) KameletBinding(org.bf2.cos.fleetshard.operator.camel.model.KameletBinding) CONNECTOR_TYPE_SOURCE(org.bf2.cos.fleetshard.operator.camel.CamelConstants.CONNECTOR_TYPE_SOURCE) TRAIT_CAMEL_APACHE_ORG_HEALTH_ENABLED(org.bf2.cos.fleetshard.operator.camel.CamelConstants.TRAIT_CAMEL_APACHE_ORG_HEALTH_ENABLED) TreeMap(java.util.TreeMap) TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_PROBE_ENABLED(org.bf2.cos.fleetshard.operator.camel.CamelConstants.TRAIT_CAMEL_APACHE_ORG_HEALTH_LIVENESS_PROBE_ENABLED) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ResourceDefinitionContext(io.fabric8.kubernetes.client.dsl.base.ResourceDefinitionContext) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) Resources(org.bf2.cos.fleetshard.support.resources.Resources) Health(org.bf2.cos.fleetshard.operator.camel.CamelOperandConfiguration.Health) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) KameletBindingBuilder(org.bf2.cos.fleetshard.operator.camel.model.KameletBindingBuilder) ProcessorKamelet(org.bf2.cos.fleetshard.operator.camel.model.ProcessorKamelet) KameletBindingSpecBuilder(org.bf2.cos.fleetshard.operator.camel.model.KameletBindingSpecBuilder) KameletBinding(org.bf2.cos.fleetshard.operator.camel.model.KameletBinding)

Aggregations

ManagedConnector (org.bf2.cos.fleetshard.api.ManagedConnector)5 Secret (io.fabric8.kubernetes.api.model.Secret)4 Objects (java.util.Objects)4 Collectors (java.util.stream.Collectors)4 Operator (org.bf2.cos.fleetshard.api.Operator)4 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)3 QuarkusTest (io.quarkus.test.junit.QuarkusTest)3 List (java.util.List)3 Map (java.util.Map)3 ApplicationScoped (javax.enterprise.context.ApplicationScoped)3 ConnectorDeploymentStatus (org.bf2.cos.fleet.manager.model.ConnectorDeploymentStatus)3 MetaV1Condition (org.bf2.cos.fleet.manager.model.MetaV1Condition)3 Resources (org.bf2.cos.fleetshard.support.resources.Resources)3 Test (org.junit.jupiter.api.Test)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Condition (io.fabric8.kubernetes.api.model.Condition)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)2 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)2