use of org.bf2.cos.fleetshard.api.Operator in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class OlmBasedStrimziOperatorManager method isSubscriptionInstalled.
private boolean isSubscriptionInstalled() {
OpenShiftClient client = kubeClient.client().adapt(OpenShiftClient.class);
Subscription s = client.operatorHub().subscriptions().inNamespace(namespace).withName(OLM_SUBSCRIPTION_NAME).get();
if (s != null && s.getStatus() != null && !s.getStatus().getCatalogHealth().isEmpty()) {
List<SubscriptionCatalogHealth> healths = s.getStatus().getCatalogHealth();
boolean result = !healths.stream().filter(h -> h.getHealthy()).map(ref -> ref.getCatalogSourceRef()).filter(h -> h.getName().equals(CATALOG_SOURCE_NAME)).collect(Collectors.toList()).isEmpty();
if (result) {
String currentCsv = s.getStatus().getCurrentCSV();
if (currentCsv == null) {
return false;
}
ClusterServiceVersion csv = client.operatorHub().clusterServiceVersions().inNamespace(namespace).withName(currentCsv).get();
if (csv == null) {
return false;
}
versions = csv.getSpec().getInstall().getSpec().getDeployments().stream().map(sds -> sds.getName()).filter(version -> version.startsWith("strimzi-cluster-operator.")).collect(Collectors.toList());
}
return result;
}
return false;
}
use of org.bf2.cos.fleetshard.api.Operator in project kas-fleetshard by bf2fc6cc711aee1a0c2a.
the class LogCollector method saveClusterState.
private static void saveClusterState(Path logpath) throws IOException {
KubeClient kube = KubeClient.getInstance();
Files.writeString(logpath.resolve("describe-cluster-nodes.log"), kube.cmdClient().exec(false, false, "describe", "nodes").out());
Files.writeString(logpath.resolve("all-events.log"), kube.cmdClient().exec(false, false, "get", "events", "--all-namespaces").out());
Files.writeString(logpath.resolve("pvs.log"), kube.cmdClient().exec(false, false, "describe", "pv").out());
Files.writeString(logpath.resolve("operator-routes.yml"), kube.cmdClient().exec(false, false, "get", "routes", "-n", FleetShardOperatorManager.OPERATOR_NS, "-o", "yaml").out());
Files.writeString(logpath.resolve("operator-services.yml"), kube.cmdClient().exec(false, false, "get", "service", "-n", FleetShardOperatorManager.OPERATOR_NS, "-o", "yaml").out());
Files.writeString(logpath.resolve("kas-fleetshard-operator-pods.yml"), kube.cmdClient().exec(false, false, "get", "pod", "-l", "app=" + FleetShardOperatorManager.OPERATOR_NAME, "--all-namespaces", "-o", "yaml").out());
Files.writeString(logpath.resolve("strimzi-kafka-pods.yml"), kube.cmdClient().exec(false, false, "get", "pod", "-l", "app.kubernetes.io/managed-by=strimzi-cluster-operator", "--all-namespaces", "-o", "yaml").out());
Files.writeString(logpath.resolve("managedkafkas.yml"), kube.cmdClient().exec(false, false, "get", "managedkafka", "--all-namespaces", "-o", "yaml").out());
Files.writeString(logpath.resolve("kafkas.yml"), kube.cmdClient().exec(false, false, "get", "kafka", "-l", "app.kubernetes.io/managed-by=" + FleetShardOperatorManager.OPERATOR_NAME, "--all-namespaces", "-o", "yaml").out());
Files.writeString(logpath.resolve("pods-managed-by-operator.yml"), kube.cmdClient().exec(false, false, "get", "pods", "-l", "app.kubernetes.io/managed-by=" + FleetShardOperatorManager.OPERATOR_NAME, "--all-namespaces", "-o", "yaml").out());
Files.writeString(logpath.resolve("operator-namespace-events.yml"), kube.cmdClient().exec(false, false, "get", "events", "-n", FleetShardOperatorManager.OPERATOR_NS).out());
Files.writeString(logpath.resolve("operator.log"), kube.cmdClient().exec(false, false, "logs", "deployment/" + FleetShardOperatorManager.OPERATOR_NAME, "-n", FleetShardOperatorManager.OPERATOR_NS).out());
Files.writeString(logpath.resolve("sync.log"), kube.cmdClient().exec(false, false, "logs", "deployment/" + FleetShardOperatorManager.SYNC_NAME, "-n", FleetShardOperatorManager.OPERATOR_NS).out());
StrimziOperatorManager.getStrimziOperatorPods().forEach(pod -> {
try {
Files.writeString(logpath.resolve(pod.getMetadata().getName() + ".log"), kube.cmdClient().exec(false, false, "logs", pod.getMetadata().getName(), "--tail", "-1", "-n", pod.getMetadata().getNamespace()).out());
} catch (Exception e) {
LOGGER.warn("Cannot get logs from pod {} in namespace {}", pod.getMetadata().getName(), pod.getMetadata().getNamespace());
}
});
}
use of org.bf2.cos.fleetshard.api.Operator 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);
}
use of org.bf2.cos.fleetshard.api.Operator 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.fleetshard.api.Operator 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')]")));
});
}
Aggregations