Search in sources :

Example 26 with Status

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

the class ConnectorStatusUpdaterTest method statusIsUpdated.

@Test
void statusIsUpdated() {
    final String clusterUrl = "/api/connector_mgmt/v1/agent/kafka_connector_clusters/" + config.cluster().id();
    final String statusUrl = clusterUrl + "/deployments/" + DEPLOYMENT_ID + "/status";
    final Condition condition = new Condition(null, uid(), null, uid(), uid(), uid());
    final Operator operator = new Operator(uid(), "operator-type", "1.2.3");
    final ManagedConnector connector = new ManagedConnectorBuilder().withMetadata(new ObjectMetaBuilder().withName(Connectors.generateConnectorId(DEPLOYMENT_ID)).withNamespace(ns).addToLabels(LABEL_CLUSTER_ID, config.cluster().id()).addToLabels(LABEL_CONNECTOR_ID, CONNECTOR_ID).addToLabels(LABEL_DEPLOYMENT_ID, DEPLOYMENT_ID).build()).withSpec(new ManagedConnectorSpecBuilder().withClusterId(config.cluster().id()).withConnectorId(CONNECTOR_ID).withDeploymentId(DEPLOYMENT_ID).withOperatorSelector(new OperatorSelectorBuilder().withId(operator.getId()).build()).build()).build();
    kubernetesClient.resources(ManagedConnector.class).inNamespace(ns).create(connector);
    connector.getStatus().setConnectorStatus(new ConnectorStatusSpecBuilder().withPhase(DESIRED_STATE_READY).withConditions(condition).withAssignedOperator(operator).build());
    kubernetesClient.resources(ManagedConnector.class).inNamespace(ns).withName(connector.getMetadata().getName()).replaceStatus(connector);
    untilAsserted(() -> {
        server.verify(putRequestedFor(urlEqualTo(statusUrl)).withHeader(ContentTypeHeader.KEY, equalTo(APPLICATION_JSON)).withRequestBody(matchingJsonPath("$.operators.assigned[?(@.version == '" + operator.getVersion() + "')]")).withRequestBody(matchingJsonPath("$.operators.assigned[?(@.type == '" + operator.getType() + "')]")).withRequestBody(matchingJsonPath("$.operators.assigned[?(@.id == '" + operator.getId() + "')]")).withRequestBody(matchingJsonPath("$[?($.phase == 'ready')]")));
    });
}
Also used : Condition(io.fabric8.kubernetes.api.model.Condition) Operator(org.bf2.cos.fleetshard.api.Operator) ManagedConnectorBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorBuilder) ManagedConnectorSpecBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorSpecBuilder) ConnectorStatusSpecBuilder(org.bf2.cos.fleetshard.api.ConnectorStatusSpecBuilder) 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 27 with Status

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

the class NamespaceProvisionerBadIdTestBase method namespaceIsProvisioned.

@Test
void namespaceIsProvisioned() {
    final String deployment1 = ConfigProvider.getConfig().getValue("test.deployment.id.1", String.class);
    final String deployment2 = ConfigProvider.getConfig().getValue("test.deployment.id.2", String.class);
    given().contentType(MediaType.TEXT_PLAIN).body(0L).post("/test/provisioner/namespaces");
    server.until(putRequestedFor(urlPathMatching("/api/connector_mgmt/v1/agent/kafka_connector_clusters/.*/namespaces/.*/status")).withHeader(ContentTypeHeader.KEY, equalTo(APPLICATION_JSON)).withRequestBody(jp("$.id", deployment1)).withRequestBody(jp("$.version", "1")).withRequestBody(jp("$.phase", ConnectorNamespaceState.DISCONNECTED.getValue())).withRequestBody(jp("$.conditions.size()", "1")).withRequestBody(jp("$.conditions[0].type", Conditions.TYPE_READY)).withRequestBody(jp("$.conditions[0].status", Conditions.STATUS_FALSE)).withRequestBody(jp("$.conditions[0].reason", Conditions.FAILED_TO_CREATE_OR_UPDATE_RESOURCE_REASON)));
    untilAsserted(() -> {
        assertThat(fleetShardClient.getKubernetesClient().v1().events().inNamespace(config.namespace()).list().getItems()).anySatisfy(e -> {
            assertThat(e.getInvolvedObject().getKind()).isEqualTo(ManagedConnectorCluster.class.getSimpleName());
            assertThat(e.getType()).isEqualTo("Warning");
            assertThat(e.getReason()).isEqualTo("FailedToCreateOrUpdateResource");
            assertThat(e.getMessage()).contains("Unable to create or update namespace " + deployment1);
        });
    });
    Namespace ns2 = until(() -> fleetShardClient.getNamespace(deployment2), Objects::nonNull);
    assertThat(ns2).satisfies(item -> {
        assertThat(item.getMetadata().getName()).isEqualTo(client.generateNamespaceId(deployment2));
        assertThat(item.getMetadata().getLabels()).containsEntry(Resources.LABEL_CLUSTER_ID, fleetShardClient.getClusterId()).containsEntry(Resources.LABEL_NAMESPACE_ID, deployment2).containsEntry(Resources.LABEL_KUBERNETES_MANAGED_BY, fleetShardClient.getClusterId()).containsEntry(Resources.LABEL_KUBERNETES_CREATED_BY, fleetShardClient.getClusterId()).containsEntry(Resources.LABEL_KUBERNETES_PART_OF, fleetShardClient.getClusterId()).containsEntry(Resources.LABEL_KUBERNETES_COMPONENT, Resources.COMPONENT_NAMESPACE).containsEntry(Resources.LABEL_KUBERNETES_INSTANCE, deployment2).containsEntry(Resources.LABEL_NAMESPACE_TENANT_KIND, ConnectorNamespaceTenantKind.ORGANISATION.getValue()).containsKey(Resources.LABEL_NAMESPACE_TENANT_ID);
    });
}
Also used : Objects(java.util.Objects) ManagedConnectorCluster(org.bf2.cos.fleetshard.api.ManagedConnectorCluster) ConnectorNamespace(org.bf2.cos.fleet.manager.model.ConnectorNamespace) Namespace(io.fabric8.kubernetes.api.model.Namespace) Test(org.junit.jupiter.api.Test)

Example 28 with Status

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

the class ConnectorDeletedTest method statusIsUpdated.

@Test
void statusIsUpdated() {
    final String clusterUrl = "/api/connector_mgmt/v1/agent/kafka_connector_clusters/" + config.cluster().id();
    final String statusUrl = clusterUrl + "/deployments/" + DEPLOYMENT_ID + "/status";
    final Condition condition = new Condition(null, uid(), null, uid(), uid(), uid());
    final Operator operator = new Operator(uid(), "operator-type", "1.2.3");
    final ManagedConnector connector = new ManagedConnectorBuilder().withMetadata(new ObjectMetaBuilder().withName(Connectors.generateConnectorId(DEPLOYMENT_ID)).withNamespace(ns).addToLabels(LABEL_CLUSTER_ID, config.cluster().id()).addToLabels(LABEL_CONNECTOR_ID, CONNECTOR_ID).addToLabels(LABEL_DEPLOYMENT_ID, DEPLOYMENT_ID).build()).withSpec(new ManagedConnectorSpecBuilder().withClusterId(config.cluster().id()).withConnectorId(CONNECTOR_ID).withDeploymentId(DEPLOYMENT_ID).withOperatorSelector(new OperatorSelectorBuilder().withId(operator.getId()).build()).build()).build();
    kubernetesClient.resources(ManagedConnector.class).inNamespace(ns).create(connector);
    connector.getStatus().setConnectorStatus(new ConnectorStatusSpecBuilder().withPhase(DESIRED_STATE_READY).withConditions(condition).withAssignedOperator(operator).build());
    kubernetesClient.resources(ManagedConnector.class).inNamespace(ns).withName(connector.getMetadata().getName()).replaceStatus(connector);
    untilAsserted(() -> {
        server.verify(putRequestedFor(urlEqualTo(statusUrl)).withHeader(ContentTypeHeader.KEY, equalTo(APPLICATION_JSON)).withRequestBody(matchingJsonPath("$[?($.phase == 'ready')]")));
    });
    connector.getStatus().setConnectorStatus(new ConnectorStatusSpecBuilder().withPhase(DESIRED_STATE_DELETED).withConditions(condition).withAssignedOperator(operator).build());
    kubernetesClient.resources(ManagedConnector.class).inNamespace(ns).withName(connector.getMetadata().getName()).replaceStatus(connector);
    untilAsserted(() -> {
        server.verify(putRequestedFor(urlEqualTo(statusUrl)).withHeader(ContentTypeHeader.KEY, equalTo(APPLICATION_JSON)).withRequestBody(matchingJsonPath("$[?($.phase == 'deleted')]")));
    });
    untilAsserted(() -> {
        assertThat(kubernetesClient.resources(ManagedConnector.class).inNamespace(ns).withName(connector.getMetadata().getName()).get()).isNull();
    });
}
Also used : Condition(io.fabric8.kubernetes.api.model.Condition) Operator(org.bf2.cos.fleetshard.api.Operator) ManagedConnectorBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorBuilder) ManagedConnectorSpecBuilder(org.bf2.cos.fleetshard.api.ManagedConnectorSpecBuilder) ConnectorStatusSpecBuilder(org.bf2.cos.fleetshard.api.ConnectorStatusSpecBuilder) 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 29 with Status

use of org.bf2.operator.resources.v1alpha1.ManagedKafkaCondition.Status 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 30 with Status

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

the class ConnectorStatusExtractorTest method errorIfNoOperatorId.

@Test
void errorIfNoOperatorId() {
    var status = ConnectorStatusExtractor.extract(new ManagedConnectorBuilder().withSpec(new ManagedConnectorSpecBuilder().withOperatorSelector(new OperatorSelectorBuilder().build()).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) OperatorSelectorBuilder(org.bf2.cos.fleetshard.api.OperatorSelectorBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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