Search in sources :

Example 1 with ConnectorNamespaceStatus

use of org.bf2.cos.fleet.manager.model.ConnectorNamespaceStatus 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 2 with ConnectorNamespaceStatus

use of org.bf2.cos.fleet.manager.model.ConnectorNamespaceStatus 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)

Aggregations

ConnectorNamespaceStatus (org.bf2.cos.fleet.manager.model.ConnectorNamespaceStatus)2 Namespace (io.fabric8.kubernetes.api.model.Namespace)1 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)1 Objects (java.util.Objects)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Inject (javax.inject.Inject)1 ConnectorClusterState (org.bf2.cos.fleet.manager.model.ConnectorClusterState)1 ConnectorClusterStatus (org.bf2.cos.fleet.manager.model.ConnectorClusterStatus)1 ConnectorClusterStatusOperators (org.bf2.cos.fleet.manager.model.ConnectorClusterStatusOperators)1 ConnectorNamespace (org.bf2.cos.fleet.manager.model.ConnectorNamespace)1 ConnectorNamespaceState (org.bf2.cos.fleet.manager.model.ConnectorNamespaceState)1 ConnectorOperator (org.bf2.cos.fleet.manager.model.ConnectorOperator)1 MetaV1Condition (org.bf2.cos.fleet.manager.model.MetaV1Condition)1 Service (org.bf2.cos.fleetshard.support.Service)1 MetricsRecorder (org.bf2.cos.fleetshard.support.metrics.MetricsRecorder)1 Namespaces (org.bf2.cos.fleetshard.support.resources.Namespaces)1 Operators (org.bf2.cos.fleetshard.support.resources.Operators)1 Resources (org.bf2.cos.fleetshard.support.resources.Resources)1 FleetShardSyncConfig (org.bf2.cos.fleetshard.sync.FleetShardSyncConfig)1 FleetShardSyncScheduler (org.bf2.cos.fleetshard.sync.FleetShardSyncScheduler)1