use of org.bf2.cos.fleet.manager.model.MetaV1Condition 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);
});
});
}
}
use of org.bf2.cos.fleet.manager.model.MetaV1Condition 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);
}
}
}
}
use of org.bf2.cos.fleet.manager.model.MetaV1Condition 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;
}
use of org.bf2.cos.fleet.manager.model.MetaV1Condition 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(STATE_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(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) {
if (DESIRED_STATE_DELETED.equals(deployment.getDesiredState())) {
status.setPhase(STATE_DE_PROVISIONING);
} else if (DESIRED_STATE_STOPPED.equals(deployment.getDesiredState())) {
status.setPhase(STATE_DE_PROVISIONING);
} else {
status.setPhase(STATE_PROVISIONING);
}
}
return status;
}
Aggregations