Search in sources :

Example 1 with ClusterServiceVersion

use of io.fabric8.openshift.api.model.operatorhub.v1alpha1.ClusterServiceVersion in project quarkus-test-framework by quarkus-qe.

the class OpenShiftClient method installOperator.

public void installOperator(Service service, String name, String channel, String source, String sourceNamespace) {
    if (!ENABLED_EPHEMERAL_NAMESPACES.getAsBoolean()) {
        throw new UnsupportedOperationException("Operators not supported with ephemeral namespaces disabled");
    }
    // Install the operator group
    OperatorGroup groupModel = new OperatorGroup();
    groupModel.setMetadata(new ObjectMeta());
    groupModel.getMetadata().setName(service.getName());
    groupModel.setSpec(new OperatorGroupSpec());
    groupModel.getSpec().setTargetNamespaces(Arrays.asList(currentNamespace));
    client.resource(groupModel).createOrReplace();
    // Install the subscription
    Subscription subscriptionModel = new Subscription();
    subscriptionModel.setMetadata(new ObjectMeta());
    subscriptionModel.getMetadata().setName(name);
    subscriptionModel.getMetadata().setNamespace(currentNamespace);
    subscriptionModel.setSpec(new SubscriptionSpec());
    subscriptionModel.getSpec().setChannel(channel);
    subscriptionModel.getSpec().setName(name);
    subscriptionModel.getSpec().setSource(source);
    subscriptionModel.getSpec().setSourceNamespace(sourceNamespace);
    Log.info("Installing operator... %s", service.getName());
    client.operatorHub().subscriptions().create(subscriptionModel);
    // Wait for the operator to be installed
    untilIsTrue(() -> {
        // Get Cluster Service Version
        Subscription subscription = client.operatorHub().subscriptions().withName(name).get();
        String installedCsv = subscription.getStatus().getInstalledCSV();
        if (StringUtils.isEmpty(installedCsv)) {
            return false;
        }
        // Check Cluster Service Version status
        ClusterServiceVersion operatorService = client.operatorHub().clusterServiceVersions().withName(installedCsv).get();
        return OPERATOR_PHASE_INSTALLED.equals(operatorService.getStatus().getPhase());
    }, AwaitilitySettings.defaults().withService(service).usingTimeout(service.getConfiguration().getAsDuration(OPERATOR_INSTALL_TIMEOUT, TIMEOUT_DEFAULT)));
    Log.info("Operator installed... %s", service.getName());
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) OperatorGroupSpec(io.fabric8.openshift.api.model.operatorhub.v1.OperatorGroupSpec) ClusterServiceVersion(io.fabric8.openshift.api.model.operatorhub.v1alpha1.ClusterServiceVersion) Subscription(io.fabric8.openshift.api.model.operatorhub.v1alpha1.Subscription) OperatorGroup(io.fabric8.openshift.api.model.operatorhub.v1.OperatorGroup) SubscriptionSpec(io.fabric8.openshift.api.model.operatorhub.v1alpha1.SubscriptionSpec)

Example 2 with ClusterServiceVersion

use of io.fabric8.openshift.api.model.operatorhub.v1alpha1.ClusterServiceVersion in project kubernetes-client by fabric8io.

the class ClusterServiceVersionTest method testLoad.

@Test
void testLoad() {
    ClusterServiceVersion clusterServiceVersion = client.operatorHub().clusterServiceVersions().load(getClass().getResourceAsStream("/test-clusterserviceversion.yml")).get();
    assertThat(clusterServiceVersion).isNotNull().hasFieldOrPropertyWithValue("metadata.name", "memcached-operator.v0.0.1").hasFieldOrPropertyWithValue("spec.version", "0.0.1");
}
Also used : ClusterServiceVersion(io.fabric8.openshift.api.model.operatorhub.v1alpha1.ClusterServiceVersion) Test(org.junit.jupiter.api.Test)

Example 3 with ClusterServiceVersion

use of io.fabric8.openshift.api.model.operatorhub.v1alpha1.ClusterServiceVersion 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)

Aggregations

ClusterServiceVersion (io.fabric8.openshift.api.model.operatorhub.v1alpha1.ClusterServiceVersion)3 OperatorGroup (io.fabric8.openshift.api.model.operatorhub.v1.OperatorGroup)2 Subscription (io.fabric8.openshift.api.model.operatorhub.v1alpha1.Subscription)2 NamespaceBuilder (io.fabric8.kubernetes.api.model.NamespaceBuilder)1 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)1 OperatorGroupBuilder (io.fabric8.openshift.api.model.operatorhub.v1.OperatorGroupBuilder)1 OperatorGroupSpec (io.fabric8.openshift.api.model.operatorhub.v1.OperatorGroupSpec)1 CatalogSource (io.fabric8.openshift.api.model.operatorhub.v1alpha1.CatalogSource)1 CatalogSourceBuilder (io.fabric8.openshift.api.model.operatorhub.v1alpha1.CatalogSourceBuilder)1 SubscriptionBuilder (io.fabric8.openshift.api.model.operatorhub.v1alpha1.SubscriptionBuilder)1 SubscriptionCatalogHealth (io.fabric8.openshift.api.model.operatorhub.v1alpha1.SubscriptionCatalogHealth)1 SubscriptionSpec (io.fabric8.openshift.api.model.operatorhub.v1alpha1.SubscriptionSpec)1 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)1 Kafka (io.strimzi.api.kafka.model.Kafka)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Collectors (java.util.stream.Collectors)1