Search in sources :

Example 21 with Status

use of org.bf2.operator.clients.canary.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, String 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 22 with Status

use of org.bf2.operator.clients.canary.Status in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class ConnectorClusterStatusSync method update.

private void update() {
    ConnectorClusterStatus status = new ConnectorClusterStatus();
    status.setPhase(ConnectorClusterState.READY);
    fleetShardClient.getOperators().stream().map(o -> new ConnectorClusterStatusOperators().namespace(o.getMetadata().getNamespace()).operator(new ConnectorOperator().id(o.getMetadata().getName()).type(o.getSpec().getType()).version(o.getSpec().getVersion())).status(Operators.PHASE_READY)).forEach(status::addOperatorsItem);
    fleetShardClient.getNamespaces().stream().map(n -> {
        ConnectorNamespaceState phase = ConnectorNamespaceState.DISCONNECTED;
        if (n.getStatus() != null) {
            if (Objects.equals(Namespaces.STATUS_ACTIVE, n.getStatus().getPhase())) {
                phase = ConnectorNamespaceState.READY;
            } else if (Objects.equals(Namespaces.STATUS_TERMINATING, n.getStatus().getPhase())) {
                phase = ConnectorNamespaceState.DELETING;
            }
        }
        return new ConnectorNamespaceStatus().id(n.getMetadata().getLabels().get(Resources.LABEL_NAMESPACE_ID)).version(Resources.getLabel(n, Resources.LABEL_KUBERNETES_VERSION)).connectorsDeployed(fleetShardClient.getConnectors(n).size()).phase(phase);
    }).forEach(status::addNamespacesItem);
    controlPlane.updateClusterStatus(status);
}
Also used : ConnectorNamespaceState(org.bf2.cos.fleet.manager.model.ConnectorNamespaceState) Operators(org.bf2.cos.fleetshard.support.resources.Operators) FleetShardSyncScheduler(org.bf2.cos.fleetshard.sync.FleetShardSyncScheduler) Logger(org.slf4j.Logger) ConnectorClusterStatusOperators(org.bf2.cos.fleet.manager.model.ConnectorClusterStatusOperators) ConnectorClusterStatus(org.bf2.cos.fleet.manager.model.ConnectorClusterStatus) LoggerFactory(org.slf4j.LoggerFactory) ConnectorClusterState(org.bf2.cos.fleet.manager.model.ConnectorClusterState) FleetShardSyncConfig(org.bf2.cos.fleetshard.sync.FleetShardSyncConfig) MetricsRecorder(org.bf2.cos.fleetshard.support.metrics.MetricsRecorder) ConnectorOperator(org.bf2.cos.fleet.manager.model.ConnectorOperator) Service(org.bf2.cos.fleetshard.support.Service) Namespaces(org.bf2.cos.fleetshard.support.resources.Namespaces) Objects(java.util.Objects) Inject(javax.inject.Inject) ConnectorNamespaceStatus(org.bf2.cos.fleet.manager.model.ConnectorNamespaceStatus) FleetManagerClient(org.bf2.cos.fleetshard.sync.client.FleetManagerClient) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) ApplicationScoped(javax.enterprise.context.ApplicationScoped) FleetShardClient(org.bf2.cos.fleetshard.sync.client.FleetShardClient) Resources(org.bf2.cos.fleetshard.support.resources.Resources) ConnectorClusterStatusOperators(org.bf2.cos.fleet.manager.model.ConnectorClusterStatusOperators) ConnectorOperator(org.bf2.cos.fleet.manager.model.ConnectorOperator) ConnectorNamespaceStatus(org.bf2.cos.fleet.manager.model.ConnectorNamespaceStatus) ConnectorClusterStatus(org.bf2.cos.fleet.manager.model.ConnectorClusterStatus) ConnectorNamespaceState(org.bf2.cos.fleet.manager.model.ConnectorNamespaceState)

Example 23 with Status

use of org.bf2.operator.clients.canary.Status in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class ConnectorDeploymentProvisioner method provisionConnectors.

private void provisionConnectors(Collection<ConnectorDeployment> deployments) {
    for (ConnectorDeployment deployment : deployments) {
        this.recorder.record(() -> provision(deployment), Tags.of(TAG_DEPLOYMENT_ID, deployment.getId()), e -> {
            LOGGER.error("Failure while trying to provision connector deployment: id={}, revision={}", deployment.getId(), deployment.getMetadata().getResourceVersion(), e);
            try {
                MetaV1Condition condition = new MetaV1Condition();
                condition.setType(Conditions.TYPE_READY);
                condition.setStatus(Conditions.STATUS_FALSE);
                condition.setReason(Conditions.FAILED_TO_CREATE_OR_UPDATE_RESOURCE_REASON);
                condition.setMessage(e.getMessage());
                ConnectorDeploymentStatus status = new ConnectorDeploymentStatus();
                status.setResourceVersion(deployment.getMetadata().getResourceVersion());
                status.addConditionsItem(condition);
                fleetManager.updateConnectorStatus(fleetShard.getClusterId(), deployment.getId(), status);
            } catch (Exception ex) {
                LOGGER.warn("Error wile reporting failure to the control plane", e);
            }
            fleetShard.getConnectorCluster().ifPresent(cc -> {
                fleetShard.broadcast("Warning", "FailedToCreateOrUpdateResource", String.format("Unable to create or update deployment %s, revision: %s, reason: %s", deployment.getId(), deployment.getMetadata().getResourceVersion(), e.getMessage()), cc);
            });
        });
    }
}
Also used : ConnectorDeployment(org.bf2.cos.fleet.manager.model.ConnectorDeployment) MetaV1Condition(org.bf2.cos.fleet.manager.model.MetaV1Condition) ConnectorDeploymentStatus(org.bf2.cos.fleet.manager.model.ConnectorDeploymentStatus)

Example 24 with Status

use of org.bf2.operator.clients.canary.Status in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class ConnectorNamespaceProvisioner method provisionNamespaces.

private void provisionNamespaces(Collection<ConnectorNamespace> namespaces, boolean sync) {
    for (ConnectorNamespace namespace : namespaces) {
        this.recorder.record(() -> provision(namespace), Tags.of(TAG_NAMESPACE_ID, namespace.getId()), e -> {
            LOGGER.error("Failure while trying to provision connector namespace: id={}, revision={}", namespace.getId(), namespace.getResourceVersion(), e);
            try {
                MetaV1Condition condition = new MetaV1Condition();
                condition.setType(Conditions.TYPE_READY);
                condition.setStatus(Conditions.STATUS_FALSE);
                condition.setReason(Conditions.FAILED_TO_CREATE_OR_UPDATE_RESOURCE_REASON);
                condition.setMessage(e.getMessage());
                ConnectorNamespaceStatus status = new ConnectorNamespaceStatus().id(namespace.getId()).version("" + namespace.getResourceVersion()).phase(ConnectorNamespaceState.DISCONNECTED).conditions(List.of(condition));
                fleetManager.updateNamespaceStatus(fleetShard.getClusterId(), namespace.getId(), status);
            } catch (Exception ex) {
                LOGGER.warn("Error wile reporting failure to the control plane", e);
            }
            fleetShard.getConnectorCluster().ifPresent(cc -> {
                fleetShard.broadcast("Warning", "FailedToCreateOrUpdateResource", String.format("Unable to create or update namespace %s, revision: %s, reason: %s", namespace.getId(), namespace.getResourceVersion(), e.getMessage()), cc);
            });
        });
    }
    if (sync) {
        Set<String> knownIds = namespaces.stream().map(ConnectorNamespace::getId).collect(Collectors.toSet());
        for (Namespace namespace : fleetShard.getNamespaces()) {
            String nsId = Resources.getLabel(namespace, Resources.LABEL_NAMESPACE_ID);
            if (nsId == null || knownIds.contains(nsId)) {
                continue;
            }
            try {
                Resources.setLabels(namespace, Resources.LABEL_NAMESPACE_STATE, Namespaces.PHASE_DELETED);
                Resources.setLabels(namespace, Resources.LABEL_NAMESPACE_STATE_FORCED, "true");
                fleetShard.getKubernetesClient().namespaces().withName(namespace.getMetadata().getName()).replace(namespace);
            } catch (Exception e) {
                LOGGER.warn("Error marking na {} for deletion (sync)", namespace.getMetadata().getName(), e);
            }
        }
    }
}
Also used : ConnectorNamespace(org.bf2.cos.fleet.manager.model.ConnectorNamespace) MetaV1Condition(org.bf2.cos.fleet.manager.model.MetaV1Condition) ConnectorNamespaceStatus(org.bf2.cos.fleet.manager.model.ConnectorNamespaceStatus) ConnectorNamespace(org.bf2.cos.fleet.manager.model.ConnectorNamespace) Namespace(io.fabric8.kubernetes.api.model.Namespace)

Example 25 with Status

use of org.bf2.operator.clients.canary.Status in project cos-fleetshard by bf2fc6cc711aee1a0c2a.

the class ConnectorStatusExtractor method extract.

public static ConnectorDeploymentStatus extract(ManagedConnector connector) {
    ConnectorDeploymentStatus status = new ConnectorDeploymentStatus();
    DeploymentSpec deployment = connector.getSpec().getDeployment();
    if (connector.getStatus() != null && connector.getStatus().getPhase() != null) {
        deployment = connector.getStatus().getDeployment();
    }
    status.setResourceVersion(deployment.getDeploymentResourceVersion());
    if (connector.getSpec().getOperatorSelector() == null || connector.getSpec().getOperatorSelector().getId() == null) {
        status.setPhase(ConnectorState.FAILED);
        status.addConditionsItem(new MetaV1Condition().type(Conditions.TYPE_READY).status(Conditions.STATUS_FALSE).message("No assignable operator").reason(Conditions.NO_ASSIGNABLE_OPERATOR_REASON).lastTransitionTime(Conditions.now()));
        return status;
    }
    if (connector.getStatus() != null && connector.getStatus().getConnectorStatus() != null) {
        status.setOperators(new ConnectorDeploymentStatusOperators().assigned(toConnectorOperator(connector.getStatus().getConnectorStatus().getAssignedOperator())).available(toConnectorOperator(connector.getStatus().getConnectorStatus().getAvailableOperator())));
        if (connector.getStatus().getConnectorStatus() != null) {
            if (connector.getStatus().getConnectorStatus().getPhase() != null) {
                status.setPhase(ConnectorState.fromValue(connector.getStatus().getConnectorStatus().getPhase()));
            }
            if (connector.getStatus().getConnectorStatus().getConditions() != null) {
                for (var cond : connector.getStatus().getConnectorStatus().getConditions()) {
                    status.addConditionsItem(toMetaV1Condition(cond));
                }
            }
        }
    }
    if (status.getPhase() == null) {
        status.setPhase(ConnectorState.PROVISIONING);
        if (DESIRED_STATE_DELETED.equals(deployment.getDesiredState())) {
            status.setPhase(ConnectorState.DEPROVISIONING);
        } else if (DESIRED_STATE_STOPPED.equals(deployment.getDesiredState())) {
            status.setPhase(ConnectorState.DEPROVISIONING);
        } else if (DESIRED_STATE_UNASSIGNED.equals(deployment.getDesiredState())) {
            status.setPhase(ConnectorState.DEPROVISIONING);
        }
    }
    return status;
}
Also used : DeploymentSpec(org.bf2.cos.fleetshard.api.DeploymentSpec) ConnectorDeploymentStatusOperators(org.bf2.cos.fleet.manager.model.ConnectorDeploymentStatusOperators) MetaV1Condition(org.bf2.cos.fleet.manager.model.MetaV1Condition) ConnectorDeploymentStatus(org.bf2.cos.fleet.manager.model.ConnectorDeploymentStatus)

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