Search in sources :

Example 6 with Operator

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;
}
Also used : CatalogSource(io.fabric8.openshift.api.model.operatorhub.v1alpha1.CatalogSource) StrimziOperatorManager(org.bf2.systemtest.operator.StrimziOperatorManager) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) OperatorGroupBuilder(io.fabric8.openshift.api.model.operatorhub.v1.OperatorGroupBuilder) CatalogSourceBuilder(io.fabric8.openshift.api.model.operatorhub.v1alpha1.CatalogSourceBuilder) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Collectors(java.util.stream.Collectors) SubscriptionBuilder(io.fabric8.openshift.api.model.operatorhub.v1alpha1.SubscriptionBuilder) List(java.util.List) OperatorGroup(io.fabric8.openshift.api.model.operatorhub.v1.OperatorGroup) Subscription(io.fabric8.openshift.api.model.operatorhub.v1alpha1.Subscription) Logger(org.apache.logging.log4j.Logger) KubeClient(org.bf2.test.k8s.KubeClient) SubscriptionCatalogHealth(io.fabric8.openshift.api.model.operatorhub.v1alpha1.SubscriptionCatalogHealth) Map(java.util.Map) NamespaceBuilder(io.fabric8.kubernetes.api.model.NamespaceBuilder) Kafka(io.strimzi.api.kafka.model.Kafka) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) ClusterServiceVersion(io.fabric8.openshift.api.model.operatorhub.v1alpha1.ClusterServiceVersion) ClusterServiceVersion(io.fabric8.openshift.api.model.operatorhub.v1alpha1.ClusterServiceVersion) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Subscription(io.fabric8.openshift.api.model.operatorhub.v1alpha1.Subscription) SubscriptionCatalogHealth(io.fabric8.openshift.api.model.operatorhub.v1alpha1.SubscriptionCatalogHealth)

Example 7 with Operator

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());
        }
    });
}
Also used : KubeClient(org.bf2.test.k8s.KubeClient) IOException(java.io.IOException)

Example 8 with Operator

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);
}
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 9 with Operator

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;
}
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)

Example 10 with Operator

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')]")));
    });
}
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)

Aggregations

Operator (org.bf2.cos.fleetshard.api.Operator)8 ManagedConnector (org.bf2.cos.fleetshard.api.ManagedConnector)6 NamespaceBuilder (io.fabric8.kubernetes.api.model.NamespaceBuilder)5 Secret (io.fabric8.kubernetes.api.model.Secret)5 Map (java.util.Map)5 Test (org.junit.jupiter.api.Test)5 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)4 QuarkusTest (io.quarkus.test.junit.QuarkusTest)4 Objects (java.util.Objects)4 Collectors (java.util.stream.Collectors)4 ApplicationScoped (javax.enterprise.context.ApplicationScoped)4 Namespace (io.fabric8.kubernetes.api.model.Namespace)3 SecretBuilder (io.fabric8.kubernetes.api.model.SecretBuilder)3 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)3 URL (java.net.URL)3 HashMap (java.util.HashMap)3 List (java.util.List)3 OperatorSelector (org.bf2.cos.fleetshard.api.OperatorSelector)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 Condition (io.fabric8.kubernetes.api.model.Condition)2