Search in sources :

Example 31 with Status

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

the class ConnectorStatusExtractorTest method errorIfNoOperatorSelector.

@Test
void errorIfNoOperatorSelector() {
    var status = ConnectorStatusExtractor.extract(new ManagedConnectorBuilder().withSpec(new ManagedConnectorSpecBuilder().build()).withStatus(new ManagedConnectorStatusBuilder().withPhase(ManagedConnectorStatus.PhaseType.Monitor).withDeployment(new DeploymentSpecBuilder().withDeploymentResourceVersion(1L).withDesiredState(DESIRED_STATE_READY).build()).build()).build());
    assertThat(status.getPhase()).isEqualTo(ConnectorState.FAILED);
    assertThat(status.getConditions()).anySatisfy(c -> {
        assertThat(c.getType()).isEqualTo(Conditions.TYPE_READY);
        assertThat(c.getStatus()).isEqualTo(Conditions.STATUS_FALSE);
        assertThat(c.getReason()).isEqualTo(Conditions.NO_ASSIGNABLE_OPERATOR_REASON);
    });
    assertThat(status.getResourceVersion()).isEqualTo(1L);
}
Also used : DeploymentSpecBuilder(org.bf2.cos.fleetshard.api.DeploymentSpecBuilder) ManagedConnectorBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorBuilder) ManagedConnectorStatusBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorStatusBuilder) ManagedConnectorSpecBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorSpecBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 32 with Status

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

the class ConnectorStatusExtractorTest method extractFromConnectorStatus.

/*
     * Test that if the status sub resource is provided and the phase is
     * "monitor", then the status extractor compute the phase according
     * to the reported deployment status
     */
@ParameterizedTest
@MethodSource
void extractFromConnectorStatus(String statusDesiredState, String connectorPhase, ConnectorState expectedState, List<Condition> conditions) {
    var status = ConnectorStatusExtractor.extract(new ManagedConnectorBuilder().withSpec(new ManagedConnectorSpecBuilder().withOperatorSelector(new OperatorSelectorBuilder().withId("1").build()).build()).withStatus(new ManagedConnectorStatusBuilder().withPhase(ManagedConnectorStatus.PhaseType.Monitor).withDeployment(new DeploymentSpecBuilder().withDeploymentResourceVersion(1L).withDesiredState(statusDesiredState).build()).withConnectorStatus(new ConnectorStatusSpecBuilder().withPhase(connectorPhase).withConditions(conditions).build()).build()).build());
    var v1Conditions = conditions.stream().map(ConnectorStatusExtractor::toMetaV1Condition).collect(Collectors.toList());
    assertThat(status.getPhase()).isEqualTo(expectedState);
    assertThat(status.getConditions()).hasSameSizeAs(conditions).hasSameElementsAs(v1Conditions);
    assertThat(status.getResourceVersion()).isEqualTo(1L);
    assertThat(status).extracting(ConnectorDeploymentStatus::getOperators).extracting(ConnectorDeploymentStatusOperators::getAssigned).hasAllNullFieldsOrProperties();
    assertThat(status).extracting(ConnectorDeploymentStatus::getOperators).extracting(ConnectorDeploymentStatusOperators::getAvailable).hasAllNullFieldsOrProperties();
}
Also used : DeploymentSpecBuilder(org.bf2.cos.fleetshard.api.DeploymentSpecBuilder) ManagedConnectorBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorBuilder) ManagedConnectorStatusBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorStatusBuilder) ManagedConnectorSpecBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorSpecBuilder) ConnectorStatusSpecBuilder(org.bf2.cos.fleetshard.api.ConnectorStatusSpecBuilder) ConnectorDeploymentStatus(org.bf2.cos.fleet.manager.model.ConnectorDeploymentStatus) OperatorSelectorBuilder(org.bf2.cos.fleetshard.api.OperatorSelectorBuilder) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 33 with Status

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

the class NamespaceReaperWithLeftoversTest method namespaceIsProvisioned.

@Test
void namespaceIsProvisioned() {
    final String deploymentId = ConfigProvider.getConfig().getValue("test.deployment.id", String.class);
    final String statusUrl = "/api/connector_mgmt/v1/agent/kafka_connector_clusters/" + config.cluster().id() + "/status";
    final String namespaceName = fleetShardClient.generateNamespaceId(deploymentId);
    given().contentType(MediaType.TEXT_PLAIN).body(0L).post("/test/provisioner/namespaces");
    until(() -> fleetShardClient.getNamespace(deploymentId), Objects::nonNull);
    server.until(putRequestedFor(urlEqualTo(statusUrl)).withHeader(ContentTypeHeader.KEY, equalTo(APPLICATION_JSON)).withRequestBody(jp("$.namespaces.size()", "1")).withRequestBody(jp("$.namespaces[0].phase", Namespaces.PHASE_READY)).withRequestBody(jp("$.namespaces[0].version", "0")).withRequestBody(jp("$.namespaces[0].connectors_deployed", "0")));
    final ManagedConnector connector = new ManagedConnectorBuilder().withMetadata(new ObjectMetaBuilder().withName(Connectors.generateConnectorId(deploymentId)).withNamespace(namespaceName).addToLabels(LABEL_CLUSTER_ID, config.cluster().id()).addToLabels(LABEL_CONNECTOR_ID, deploymentId).addToLabels(LABEL_DEPLOYMENT_ID, deploymentId).build()).withSpec(new ManagedConnectorSpecBuilder().withClusterId(config.cluster().id()).withConnectorId(deploymentId).withDeploymentId(deploymentId).withOperatorSelector(new OperatorSelectorBuilder().withId(deploymentId).build()).build()).build();
    kubernetesClient.resources(ManagedConnector.class).inNamespace(connector.getMetadata().getNamespace()).create(connector);
    untilAsserted(() -> {
        assertThat(fleetShardClient.getAllConnectors()).isNotEmpty();
        assertThat(fleetShardClient.getConnectors(connector.getMetadata().getNamespace())).isNotEmpty();
    });
    given().contentType(MediaType.TEXT_PLAIN).body(1L).post("/test/provisioner/namespaces");
    server.until(putRequestedFor(urlEqualTo(statusUrl)).withHeader(ContentTypeHeader.KEY, equalTo(APPLICATION_JSON)).withRequestBody(matchingJsonPath("$.namespaces", WireMock.absent())));
}
Also used : ManagedConnectorBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorBuilder) Objects(java.util.Objects) ManagedConnectorSpecBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorSpecBuilder) ManagedConnector(org.bf2.cos.fleetshard.api.ManagedConnector) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) OperatorSelectorBuilder(org.bf2.cos.fleetshard.api.OperatorSelectorBuilder) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 34 with Status

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

the class ClusterStatusUpdaterWithOperatorTest method statusIsUpdated.

@Test
void statusIsUpdated() {
    final String statusUrl = "/api/connector_mgmt/v1/agent/kafka_connector_clusters/" + config.cluster().id() + "/status";
    final String operatorId = uid();
    kubernetesClient.resources(ManagedConnectorOperator.class).inNamespace(ns).create(new ManagedConnectorOperatorBuilder().withNewMetadata().withName(operatorId).endMetadata().withSpec(new ManagedConnectorOperatorSpecBuilder().withType("operator-type").withVersion("999").withRuntime("operator-runtime").build()).build());
    RestAssured.given().contentType(MediaType.TEXT_PLAIN).post("/test/provisioner/all");
    untilAsserted(() -> {
        server.verify(putRequestedFor(urlEqualTo(statusUrl)).withHeader(ContentTypeHeader.KEY, equalTo(APPLICATION_JSON)).withRequestBody(jp("$.phase", "ready")).withRequestBody(jp("$.operators.size()", "1")).withRequestBody(jp("$.operators[0].namespace", ns)).withRequestBody(jp("$.operators[0].status", "ready")).withRequestBody(jp("$.operators[0].operator.id", operatorId)).withRequestBody(jp("$.operators[0].operator.type", "operator-type")).withRequestBody(jp("$.operators[0].operator.version", "999")));
    });
}
Also used : ManagedConnectorOperatorBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorOperatorBuilder) ManagedConnectorOperatorSpecBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorOperatorSpecBuilder) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 35 with Status

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

the class DebeziumOperandController method doReify.

@Override
protected List<HasMetadata> doReify(ManagedConnector connector, DebeziumShardMetadata shardMetadata, ConnectorConfiguration<ObjectNode, DebeziumDataShape> connectorConfiguration, ServiceAccountSpec serviceAccountSpec) {
    final Map<String, String> secretsData = createSecretsData(connectorConfiguration.getConnectorSpec());
    final Secret secret = new SecretBuilder().withMetadata(new ObjectMetaBuilder().withName(connector.getMetadata().getName() + Resources.CONNECTOR_SECRET_SUFFIX).build()).addToData(EXTERNAL_CONFIG_FILE, asBytesBase64(secretsData)).addToData(KAFKA_CLIENT_SECRET_KEY, serviceAccountSpec.getClientSecret()).build();
    ConfigMap kafkaConnectMetricsConfigMap = new ConfigMapBuilder().withNewMetadata().withName(connector.getMetadata().getName() + KAFKA_CONNECT_METRICS_CONFIGMAP_NAME_SUFFIX).endMetadata().addToData(METRICS_CONFIG_FILENAME, METRICS_CONFIG).build();
    final KafkaConnectSpecBuilder kcsb = new KafkaConnectSpecBuilder().withReplicas(1).withBootstrapServers(connector.getSpec().getDeployment().getKafka().getUrl()).withKafkaClientAuthenticationPlain(new KafkaClientAuthenticationPlainBuilder().withUsername(serviceAccountSpec.getClientId()).withPasswordSecret(new PasswordSecretSourceBuilder().withSecretName(secret.getMetadata().getName()).withPassword(KAFKA_CLIENT_SECRET_KEY).build()).build()).addToConfig(DebeziumConstants.DEFAULT_CONFIG_OPTIONS).addToConfig(new TreeMap<>(configuration.kafkaConnect().config())).addToConfig("group.id", connector.getMetadata().getName()).addToConfig(KeyAndValueConverters.getConfig(connectorConfiguration.getDataShapeSpec(), connector, serviceAccountSpec)).addToConfig("offset.storage.topic", connector.getMetadata().getName() + "-offset").addToConfig("config.storage.topic", connector.getMetadata().getName() + "-config").addToConfig("status.storage.topic", connector.getMetadata().getName() + "-status").addToConfig("topic.creation.enable", "true").addToConfig("connector.secret.name", secret.getMetadata().getName()).addToConfig("connector.secret.checksum", Secrets.computeChecksum(secret)).withTls(new ClientTlsBuilder().withTrustedCertificates(Collections.emptyList()).build()).withTemplate(new KafkaConnectTemplateBuilder().withPod(new PodTemplateBuilder().withImagePullSecrets(configuration.imagePullSecretsName()).build()).build()).withJmxPrometheusExporterMetricsConfig(new JmxPrometheusExporterMetricsBuilder().withValueFrom(new ExternalConfigurationReferenceBuilder().withNewConfigMapKeyRef(METRICS_CONFIG_FILENAME, kafkaConnectMetricsConfigMap.getMetadata().getName(), false).build()).build()).withExternalConfiguration(new ExternalConfigurationBuilder().addToVolumes(new ExternalConfigurationVolumeSourceBuilder().withName(EXTERNAL_CONFIG_DIRECTORY).withSecret(new SecretVolumeSourceBuilder().withSecretName(secret.getMetadata().getName()).build()).build()).build()).withResources(new ResourceRequirementsBuilder().addToRequests("cpu", new Quantity("10m")).addToRequests("memory", new Quantity("256Mi")).addToLimits("cpu", new Quantity("500m")).addToLimits("memory", new Quantity("1Gi")).build());
    kcsb.withImage(shardMetadata.getContainerImage());
    final KafkaConnect kc = new KafkaConnectBuilder().withApiVersion(Constants.RESOURCE_GROUP_NAME + "/" + KafkaConnect.CONSUMED_VERSION).withMetadata(new ObjectMetaBuilder().withName(connector.getMetadata().getName()).addToAnnotations(STRIMZI_IO_USE_CONNECTOR_RESOURCES, "true").build()).withSpec(kcsb.build()).build();
    Map<String, Object> connectorConfig = createConfig(configuration, connectorConfiguration.getConnectorSpec());
    // handle connector config defaults
    switch(shardMetadata.getConnectorClass()) {
        case CLASS_NAME_POSTGRES_CONNECTOR:
            if (!connectorConfig.containsKey(CONFIG_OPTION_POSTGRES_PLUGIN_NAME)) {
                connectorConfig.put(CONFIG_OPTION_POSTGRES_PLUGIN_NAME, PLUGIN_NAME_PGOUTPUT);
            }
            break;
        default:
            break;
    }
    if (isDatabaseHistorySupported(shardMetadata)) {
        final Map<String, Object> databaseHistoryConfigs = new LinkedHashMap<>();
        databaseHistoryConfigs.put("database.history.kafka.bootstrap.servers", connector.getSpec().getDeployment().getKafka().getUrl());
        databaseHistoryConfigs.put("database.history.kafka.topic", connector.getMetadata().getName() + "-database-history");
        databaseHistoryConfigs.put("database.history.producer.security.protocol", "SASL_SSL");
        databaseHistoryConfigs.put("database.history.consumer.security.protocol", "SASL_SSL");
        databaseHistoryConfigs.put("database.history.producer.sasl.mechanism", "PLAIN");
        databaseHistoryConfigs.put("database.history.consumer.sasl.mechanism", "PLAIN");
        databaseHistoryConfigs.put("database.history.producer.sasl.jaas.config", "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"" + serviceAccountSpec.getClientId() + "\" password=\"" + "${dir:/opt/kafka/external-configuration/" + EXTERNAL_CONFIG_DIRECTORY + ":" + KAFKA_CLIENT_SECRET_KEY + "}\";");
        databaseHistoryConfigs.put("database.history.consumer.sasl.jaas.config", "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"" + serviceAccountSpec.getClientId() + "\" password=\"" + "${dir:/opt/kafka/external-configuration/" + EXTERNAL_CONFIG_DIRECTORY + ":" + KAFKA_CLIENT_SECRET_KEY + "}\";");
        connectorConfig.putAll(databaseHistoryConfigs);
    }
    final KafkaConnector kctr = new KafkaConnectorBuilder().withApiVersion(Constants.RESOURCE_GROUP_NAME + "/" + KafkaConnector.CONSUMED_VERSION).withMetadata(new ObjectMetaBuilder().withName(connector.getMetadata().getName()).addToLabels(STRIMZI_DOMAIN + "cluster", connector.getMetadata().getName()).build()).withSpec(new KafkaConnectorSpecBuilder().withClassName(shardMetadata.getConnectorClass()).withTasksMax(1).withPause(false).withConfig(connectorConfig).addToConfig("topic.creation.default.replication.factor", -1).addToConfig("topic.creation.default.partitions", -1).addToConfig("topic.creation.default.cleanup.policy", "compact").addToConfig("topic.creation.default.compression.type", "lz4").addToConfig("topic.creation.default.delete.retention.ms", 2_678_400_000L).build()).build();
    return List.of(secret, kafkaConnectMetricsConfigMap, kc, kctr);
}
Also used : PodTemplateBuilder(io.strimzi.api.kafka.model.template.PodTemplateBuilder) KafkaConnectTemplateBuilder(io.strimzi.api.kafka.model.template.KafkaConnectTemplateBuilder) ResourceRequirementsBuilder(io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder) KafkaConnect(io.strimzi.api.kafka.model.KafkaConnect) DebeziumOperandSupport.lookupKafkaConnect(org.bf2.cos.fleetshard.operator.debezium.DebeziumOperandSupport.lookupKafkaConnect) PasswordSecretSourceBuilder(io.strimzi.api.kafka.model.PasswordSecretSourceBuilder) LinkedHashMap(java.util.LinkedHashMap) SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) KafkaConnectBuilder(io.strimzi.api.kafka.model.KafkaConnectBuilder) ClientTlsBuilder(io.strimzi.api.kafka.model.ClientTlsBuilder) KafkaConnectorSpecBuilder(io.strimzi.api.kafka.model.KafkaConnectorSpecBuilder) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) KafkaClientAuthenticationPlainBuilder(io.strimzi.api.kafka.model.authentication.KafkaClientAuthenticationPlainBuilder) KafkaConnector(io.strimzi.api.kafka.model.KafkaConnector) KafkaConnectSpecBuilder(io.strimzi.api.kafka.model.KafkaConnectSpecBuilder) SecretVolumeSourceBuilder(io.fabric8.kubernetes.api.model.SecretVolumeSourceBuilder) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ExternalConfigurationBuilder(io.strimzi.api.kafka.model.connect.ExternalConfigurationBuilder) ExternalConfigurationVolumeSourceBuilder(io.strimzi.api.kafka.model.connect.ExternalConfigurationVolumeSourceBuilder) Quantity(io.fabric8.kubernetes.api.model.Quantity) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) TreeMap(java.util.TreeMap) Secret(io.fabric8.kubernetes.api.model.Secret) ExternalConfigurationReferenceBuilder(io.strimzi.api.kafka.model.ExternalConfigurationReferenceBuilder) JmxPrometheusExporterMetricsBuilder(io.strimzi.api.kafka.model.JmxPrometheusExporterMetricsBuilder) KafkaConnectorBuilder(io.strimzi.api.kafka.model.KafkaConnectorBuilder)

Aggregations

Test (org.junit.jupiter.api.Test)14 ManagedKafka (org.bf2.operator.resources.v1alpha1.ManagedKafka)12 Objects (java.util.Objects)11 QuarkusTest (io.quarkus.test.junit.QuarkusTest)9 ManagedConnectorBuilder (org.bf2.cos.fleetshard.api.ManagedConnectorBuilder)7 ManagedConnectorSpecBuilder (org.bf2.cos.fleetshard.api.ManagedConnectorSpecBuilder)7 Map (java.util.Map)6 Inject (javax.inject.Inject)6 OperatorSelectorBuilder (org.bf2.cos.fleetshard.api.OperatorSelectorBuilder)6 RegistryData (org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)5 List (java.util.List)5 ConnectorDeploymentStatus (org.bf2.cos.fleet.manager.model.ConnectorDeploymentStatus)5 Status (org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status)5 Quantity (io.fabric8.kubernetes.api.model.Quantity)4 KafkaConnectorBuilder (io.strimzi.api.kafka.model.KafkaConnectorBuilder)4 Transactional (javax.transaction.Transactional)4 ManagedKafkaCondition (org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition)4 ManagedKafkaStatus (org.bf2.operator.resources.v1alpha1.ManagedKafkaStatus)4