Search in sources :

Example 11 with ManagedConnector

use of org.bf2.cos.fleetshard.api.ManagedConnector in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class AbstractOperandController method reify.

@Override
public List<HasMetadata> reify(ManagedConnector connector, Secret secret) {
    LOGGER.debug("Reifying connector: {} and secret.metadata: {}", connector, secret.getMetadata());
    final ServiceAccount serviceAccountSettings = extract(secret, SECRET_ENTRY_SERVICE_ACCOUNT, ServiceAccount.class);
    LOGGER.debug("Extracted serviceAccount {}", serviceAccountSettings == null ? "is null" : "with clientId: " + serviceAccountSettings.getClientId());
    ServiceAccountSpec sas = serviceAccountSettings == null ? new ServiceAccountSpecBuilder().build() : new ServiceAccountSpecBuilder().withClientId(serviceAccountSettings.getClientId()).withClientSecret(serviceAccountSettings.getClientSecret()).build();
    ConnectorConfiguration<S, D> connectorConfig;
    try {
        connectorConfig = new ConnectorConfiguration<>(extract(secret, SECRET_ENTRY_CONNECTOR, ObjectNode.class), connectorSpecType, dataShapeType);
    } catch (IncompleteConnectorSpecException e) {
        throw new RuntimeException("Incomplete connectorSpec for connector \"" + connector.getSpec().getConnectorId() + "@" + connector.getSpec().getDeploymentId() + "#" + connector.getSpec().getDeployment().getDeploymentResourceVersion() + "\": " + e.getLocalizedMessage(), e);
    }
    return doReify(connector, extract(secret, SECRET_ENTRY_META, metadataType), connectorConfig, sas);
}
Also used : IncompleteConnectorSpecException(org.bf2.cos.fleetshard.operator.connector.IncompleteConnectorSpecException) ServiceAccount(org.bf2.cos.fleet.manager.model.ServiceAccount) ServiceAccountSpec(org.bf2.cos.fleetshard.api.ServiceAccountSpec) ServiceAccountSpecBuilder(org.bf2.cos.fleetshard.api.ServiceAccountSpecBuilder)

Example 12 with ManagedConnector

use of org.bf2.cos.fleetshard.api.ManagedConnector in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class DebeziumOperandController method status.

@Override
public void status(ManagedConnector connector) {
    KafkaConnector kctr = lookupConnector(getKubernetesClient(), connector).filter(_kctr -> _kctr.getStatus() != null).orElse(null);
    KafkaConnect kc = lookupKafkaConnect(getKubernetesClient(), connector).filter(_kc -> _kc.getStatus() != null).orElse(null);
    computeStatus(connector.getStatus().getConnectorStatus(), kc, kctr);
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) Secrets(org.bf2.cos.fleetshard.support.resources.Secrets) ExternalConfigurationBuilder(io.strimzi.api.kafka.model.connect.ExternalConfigurationBuilder) LoggerFactory(org.slf4j.LoggerFactory) KAFKA_CLIENT_SECRET_KEY(org.bf2.cos.fleetshard.operator.debezium.DebeziumConstants.KAFKA_CLIENT_SECRET_KEY) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) KeyAndValueConverters(org.bf2.cos.fleetshard.operator.debezium.model.KeyAndValueConverters) Map(java.util.Map) CollectionUtils.asBytesBase64(org.bf2.cos.fleetshard.support.CollectionUtils.asBytesBase64) DebeziumOperandSupport.computeStatus(org.bf2.cos.fleetshard.operator.debezium.DebeziumOperandSupport.computeStatus) ManagedConnector(org.bf2.cos.fleetshard.api.ManagedConnector) ConnectorConfiguration(org.bf2.cos.fleetshard.operator.connector.ConnectorConfiguration) SecretVolumeSourceBuilder(io.fabric8.kubernetes.api.model.SecretVolumeSourceBuilder) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) ExternalConfigurationVolumeSourceBuilder(io.strimzi.api.kafka.model.connect.ExternalConfigurationVolumeSourceBuilder) KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) ServiceAccountSpec(org.bf2.cos.fleetshard.api.ServiceAccountSpec) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) List(java.util.List) PasswordSecretSourceBuilder(io.strimzi.api.kafka.model.PasswordSecretSourceBuilder) Secret(io.fabric8.kubernetes.api.model.Secret) KafkaConnectTemplateBuilder(io.strimzi.api.kafka.model.template.KafkaConnectTemplateBuilder) EXTERNAL_CONFIG_FILE(org.bf2.cos.fleetshard.operator.debezium.DebeziumConstants.EXTERNAL_CONFIG_FILE) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) RESOURCE_TYPES(org.bf2.cos.fleetshard.operator.debezium.DebeziumConstants.RESOURCE_TYPES) DebeziumDataShape(org.bf2.cos.fleetshard.operator.debezium.model.DebeziumDataShape) EXTERNAL_CONFIG_DIRECTORY(org.bf2.cos.fleetshard.operator.debezium.DebeziumConstants.EXTERNAL_CONFIG_DIRECTORY) ResourceRequirementsBuilder(io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder) Singleton(javax.inject.Singleton) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) KafkaClientAuthenticationPlainBuilder(io.strimzi.api.kafka.model.authentication.KafkaClientAuthenticationPlainBuilder) LinkedHashMap(java.util.LinkedHashMap) KafkaConnectSpecBuilder(io.strimzi.api.kafka.model.KafkaConnectSpecBuilder) ExternalConfigurationReferenceBuilder(io.strimzi.api.kafka.model.ExternalConfigurationReferenceBuilder) JmxPrometheusExporterMetricsBuilder(io.strimzi.api.kafka.model.JmxPrometheusExporterMetricsBuilder) STRIMZI_IO_USE_CONNECTOR_RESOURCES(org.bf2.cos.fleetshard.operator.debezium.DebeziumConstants.STRIMZI_IO_USE_CONNECTOR_RESOURCES) DebeziumOperandSupport.lookupKafkaConnect(org.bf2.cos.fleetshard.operator.debezium.DebeziumOperandSupport.lookupKafkaConnect) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) KafkaConnectorBuilder(io.strimzi.api.kafka.model.KafkaConnectorBuilder) Logger(org.slf4j.Logger) AbstractOperandController(org.bf2.cos.fleetshard.operator.operand.AbstractOperandController) IOException(java.io.IOException) STRIMZI_DOMAIN(org.bf2.cos.fleetshard.operator.debezium.DebeziumConstants.STRIMZI_DOMAIN) PodTemplateBuilder(io.strimzi.api.kafka.model.template.PodTemplateBuilder) DebeziumOperandSupport.createSecretsData(org.bf2.cos.fleetshard.operator.debezium.DebeziumOperandSupport.createSecretsData) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ClientTlsBuilder(io.strimzi.api.kafka.model.ClientTlsBuilder) DebeziumOperandSupport.lookupConnector(org.bf2.cos.fleetshard.operator.debezium.DebeziumOperandSupport.lookupConnector) TreeMap(java.util.TreeMap) Constants(io.strimzi.api.kafka.model.Constants) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ResourceDefinitionContext(io.fabric8.kubernetes.client.dsl.base.ResourceDefinitionContext) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) Collections(java.util.Collections) Resources(org.bf2.cos.fleetshard.support.resources.Resources) KafkaConnectorSpecBuilder(io.strimzi.api.kafka.model.KafkaConnectorSpecBuilder) DebeziumOperandSupport.createConfig(org.bf2.cos.fleetshard.operator.debezium.DebeziumOperandSupport.createConfig) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) DebeziumOperandSupport.lookupKafkaConnect(org.bf2.cos.fleetshard.operator.debezium.DebeziumOperandSupport.lookupKafkaConnect)

Example 13 with ManagedConnector

use of org.bf2.cos.fleetshard.api.ManagedConnector in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class AbstractApicurioConverter method getAdditionalConfig.

@Override
public Map<String, String> getAdditionalConfig(ManagedConnector config, ServiceAccountSpec serviceAccountSpec) {
    Map<String, String> additionalConfig = new HashMap<>();
    additionalConfig.put("apicurio.auth.service.url", APICURIO_AUTH_SERVICE_URL);
    additionalConfig.put("apicurio.auth.realm", "rhoas");
    SchemaRegistrySpec schemaRegistrySpec = config.getSpec().getDeployment().getSchemaRegistry();
    if (null == schemaRegistrySpec || null == schemaRegistrySpec.getUrl() || schemaRegistrySpec.getUrl().isBlank()) {
        throw new RuntimeException("Can't create a schema-based connector without providing a valid 'schema_registry'");
    }
    String schemaRegistryURL = schemaRegistrySpec.getUrl();
    additionalConfig.put("apicurio.registry.url", schemaRegistryURL);
    additionalConfig.put("apicurio.auth.client.id", serviceAccountSpec.getClientId());
    additionalConfig.put("apicurio.auth.client.secret", "${dir:/opt/kafka/external-configuration/" + DebeziumConstants.EXTERNAL_CONFIG_DIRECTORY + ":" + DebeziumConstants.KAFKA_CLIENT_SECRET_KEY + "}");
    additionalConfig.put("apicurio.registry.auto-register", "true");
    additionalConfig.put("apicurio.registry.find-latest", "true");
    return additionalConfig;
}
Also used : HashMap(java.util.HashMap) SchemaRegistrySpec(org.bf2.cos.fleetshard.api.SchemaRegistrySpec)

Example 14 with ManagedConnector

use of org.bf2.cos.fleetshard.api.ManagedConnector in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class ConnectorSteps method deploy_connector_with_uow.

public void deploy_connector_with_uow(String uow) {
    ManagedConnector res = kubernetesClient.resources(ManagedConnector.class).inNamespace(ctx.connectorsNamespace()).withName(ctx.connector().getMetadata().getName()).get();
    if (res != null) {
        ctx.connector(res);
    }
    Resources.setAnnotation(ctx.connector(), Resources.ANNOTATION_UPDATED_TIMESTAMP, ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT));
    Resources.setLabel(ctx.connector(), Resources.LABEL_UOW, uow);
    ctx.connector().getSpec().getDeployment().setUnitOfWork(uow);
    ctx.connector(kubernetesClient.resources(ManagedConnector.class).inNamespace(ctx.connectorsNamespace()).createOrReplace(ctx.connector()));
}
Also used : ManagedConnector(org.bf2.cos.fleetshard.api.ManagedConnector)

Example 15 with ManagedConnector

use of org.bf2.cos.fleetshard.api.ManagedConnector in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class ConnectorProvisionerTest method updateResources.

@Test
void updateResources() {
    // 
    // Given that the resources associated to the provided deployment exist
    // 
    final ConnectorDeployment oldDeployment = createDeployment(0);
    final List<ManagedConnector> connectors = List.of(new ManagedConnectorBuilder().withMetadata(new ObjectMetaBuilder().withName(Connectors.generateConnectorId(oldDeployment.getId())).addToLabels(LABEL_CLUSTER_ID, CLUSTER_ID).addToLabels(LABEL_CONNECTOR_ID, oldDeployment.getSpec().getConnectorId()).addToLabels(LABEL_DEPLOYMENT_ID, oldDeployment.getId()).build()).build());
    final List<Secret> secrets = List.of(new SecretBuilder().withMetadata(new ObjectMetaBuilder().withName(Secrets.generateConnectorSecretId(oldDeployment.getId())).addToLabels(LABEL_CLUSTER_ID, CLUSTER_ID).addToLabels(LABEL_CONNECTOR_ID, oldDeployment.getSpec().getConnectorId()).addToLabels(LABEL_DEPLOYMENT_ID, oldDeployment.getId()).addToLabels(LABEL_DEPLOYMENT_RESOURCE_VERSION, "" + oldDeployment.getMetadata().getResourceVersion()).build()).build());
    final FleetShardClient fleetShard = ConnectorTestSupport.fleetShard(CLUSTER_ID, connectors, secrets);
    final FleetManagerClient fleetManager = ConnectorTestSupport.fleetManagerClient();
    final FleetShardSyncConfig config = ConnectorTestSupport.config();
    final MeterRegistry registry = Mockito.mock(MeterRegistry.class);
    final ConnectorDeploymentProvisioner provisioner = new ConnectorDeploymentProvisioner(config, fleetShard, fleetManager, registry);
    final ArgumentCaptor<Secret> sc = ArgumentCaptor.forClass(Secret.class);
    final ArgumentCaptor<ManagedConnector> mcc = ArgumentCaptor.forClass(ManagedConnector.class);
    // 
    // When deployment is updated
    // 
    final ConnectorDeployment newDeployment = createDeployment(0, d -> {
        d.getSpec().getKafka().setUrl("my-kafka.acme.com:218");
        ((ObjectNode) d.getSpec().getConnectorSpec()).with("connector").put("foo", "connector-baz");
        ((ObjectNode) d.getSpec().getShardMetadata()).put("connector_image", "quay.io/mcs_dev/aws-s3-sink:0.1.0");
    });
    provisioner.provision(newDeployment);
    verify(fleetShard).createSecret(sc.capture());
    verify(fleetShard).createConnector(mcc.capture());
    // 
    // Then the existing resources must be updated to reflect the changes made to the
    // deployment. This scenario could happen when a resource on the connector cluster
    // is amended outside the control of fleet manager (i.e. with kubectl) and in such
    // case, the expected behavior is that the resource is re-set to the configuration
    // from the fleet manager.
    // 
    assertThat(sc.getValue()).satisfies(val -> {
        assertThat(val.getMetadata().getName()).isEqualTo(Secrets.generateConnectorSecretId(oldDeployment.getId()));
        assertThat(val.getMetadata().getLabels()).containsEntry(LABEL_CLUSTER_ID, CLUSTER_ID).containsEntry(LABEL_CONNECTOR_ID, newDeployment.getSpec().getConnectorId()).containsEntry(LABEL_DEPLOYMENT_ID, newDeployment.getId()).containsEntry(LABEL_DEPLOYMENT_RESOURCE_VERSION, "" + newDeployment.getMetadata().getResourceVersion()).containsKey(LABEL_UOW);
        assertThat(val.getData()).containsKey(Secrets.SECRET_ENTRY_SERVICE_ACCOUNT).containsKey(Secrets.SECRET_ENTRY_CONNECTOR);
        var serviceAccountNode = Secrets.extract(val, Secrets.SECRET_ENTRY_SERVICE_ACCOUNT, ServiceAccount.class);
        assertThat(serviceAccountNode.getClientSecret()).isEqualTo(newDeployment.getSpec().getServiceAccount().getClientSecret());
        assertThat(serviceAccountNode.getClientId()).isEqualTo(newDeployment.getSpec().getServiceAccount().getClientId());
        var connectorNode = Secrets.extract(val, Secrets.SECRET_ENTRY_CONNECTOR);
        assertThatJson(Secrets.extract(val, Secrets.SECRET_ENTRY_CONNECTOR)).inPath("connector.foo").isEqualTo("connector-baz");
        assertThatJson(connectorNode).inPath("kafka.topic").isEqualTo("kafka-foo");
        var metaNode = Secrets.extract(val, Secrets.SECRET_ENTRY_META);
        assertThatJson(metaNode).isObject().containsKey("connector_type").containsKey("connector_image").containsKey("kamelets").containsKey("operators");
    });
    assertThat(mcc.getValue()).satisfies(val -> {
        assertThat(val.getMetadata().getName()).isEqualTo(Connectors.generateConnectorId(oldDeployment.getId()));
        assertThat(val.getMetadata().getLabels()).containsEntry(LABEL_CLUSTER_ID, CLUSTER_ID).containsEntry(LABEL_CONNECTOR_ID, oldDeployment.getSpec().getConnectorId()).containsEntry(LABEL_DEPLOYMENT_ID, oldDeployment.getId()).containsKey(LABEL_UOW);
        assertThat(val.getSpec().getDeployment()).satisfies(d -> {
            assertThat(d.getDeploymentResourceVersion()).isEqualTo(oldDeployment.getMetadata().getResourceVersion());
            assertThat(d.getDeploymentResourceVersion()).isEqualTo(newDeployment.getMetadata().getResourceVersion());
            assertThat(d.getSecret()).isEqualTo(sc.getValue().getMetadata().getName());
            assertThat(d.getUnitOfWork()).isNotEmpty().isEqualTo(sc.getValue().getMetadata().getLabels().get(LABEL_UOW));
            assertThat(d.getKafka().getUrl()).isNotEmpty().isEqualTo(newDeployment.getSpec().getKafka().getUrl());
        });
    });
}
Also used : FleetShardClient(org.bf2.cos.fleetshard.sync.client.FleetShardClient) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ConnectorDeploymentProvisioner(org.bf2.cos.fleetshard.sync.resources.ConnectorDeploymentProvisioner) ManagedConnector(org.bf2.cos.fleetshard.api.ManagedConnector) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Secret(io.fabric8.kubernetes.api.model.Secret) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) ConnectorDeployment(org.bf2.cos.fleet.manager.model.ConnectorDeployment) ManagedConnectorBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorBuilder) FleetManagerClient(org.bf2.cos.fleetshard.sync.client.FleetManagerClient) FleetShardSyncConfig(org.bf2.cos.fleetshard.sync.FleetShardSyncConfig) Test(org.junit.jupiter.api.Test)

Aggregations

ManagedConnector (org.bf2.cos.fleetshard.api.ManagedConnector)24 Secret (io.fabric8.kubernetes.api.model.Secret)15 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)9 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)8 Map (java.util.Map)6 FleetShardSyncConfig (org.bf2.cos.fleetshard.sync.FleetShardSyncConfig)6 FleetManagerClient (org.bf2.cos.fleetshard.sync.client.FleetManagerClient)6 FleetShardClient (org.bf2.cos.fleetshard.sync.client.FleetShardClient)6 Test (org.junit.jupiter.api.Test)6 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)5 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)5 List (java.util.List)5 ConnectorDeployment (org.bf2.cos.fleet.manager.model.ConnectorDeployment)5 Operator (org.bf2.cos.fleetshard.api.Operator)5 ServiceAccountSpec (org.bf2.cos.fleetshard.api.ServiceAccountSpec)5 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)4 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)4 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)4 ManagedConnectorBuilder (org.bf2.cos.fleetshard.api.ManagedConnectorBuilder)4 ConnectorConfiguration (org.bf2.cos.fleetshard.operator.connector.ConnectorConfiguration)4