Search in sources :

Example 1 with SubscriptionSpec

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

use of io.fabric8.openshift.api.model.operatorhub.v1alpha1.SubscriptionSpec in project infinispan by infinispan.

the class Install method exec.

@Override
public CommandResult exec(ContextAwareCommandInvocation invocation) {
    if (namespace != null && (targetNamespaces == null || targetNamespaces.isEmpty())) {
        throw Messages.MSG.noTargetNamespaces();
    }
    KubernetesClient client = KubernetesContext.getClient(invocation);
    if (source == null) {
        // Determine whether this is OpenShift or K8S+OLM
        List<GenericKubernetesResource> sources = client.genericKubernetesResources(Kube.OPERATOR_CATALOGSOURCE_CRD).inAnyNamespace().list().getItems();
        Optional<GenericKubernetesResource> catalog = sources.stream().filter(cs -> Version.getProperty("infinispan.olm.k8s.source").equals(cs.getMetadata().getName())).findFirst();
        if (!catalog.isPresent()) {
            catalog = sources.stream().filter(cs -> Version.getProperty("infinispan.olm.openshift.source").equals(cs.getMetadata().getName())).findFirst();
        }
        if (catalog.isPresent()) {
            GenericKubernetesResource catalogSource = catalog.get();
            source = catalogSource.getMetadata().getName();
            sourceNamespace = catalogSource.getMetadata().getNamespace();
        } else {
            throw Messages.MSG.noCatalog();
        }
    }
    String olmName = Version.getProperty("infinispan.olm.name");
    if (namespace == null) {
        namespace = Kube.defaultOperatorNamespace(client);
    } else {
        // Non-global, we need to create an operator group
        GenericKubernetesResource group = new GenericKubernetesResource();
        group.setKind(Kube.OPERATOR_OPERATORGROUP_CRD.getKind());
        ObjectMeta groupMetadata = new ObjectMeta();
        groupMetadata.setName(olmName);
        groupMetadata.setNamespace(namespace);
        group.setMetadata(groupMetadata);
        GenericKubernetesResource groupSpec = new GenericKubernetesResource();
        groupSpec.setAdditionalProperty("targetNamespaces", targetNamespaces);
        group.setAdditionalProperty("spec", groupSpec);
        client.genericKubernetesResources(Kube.OPERATOR_OPERATORGROUP_CRD).inNamespace(namespace).createOrReplace(group);
    }
    GenericKubernetesResource subscription = new GenericKubernetesResource();
    subscription.setKind(Kube.OPERATOR_SUBSCRIPTION_CRD.getKind());
    ObjectMeta subscriptionMetadata = new ObjectMeta();
    subscriptionMetadata.setName(olmName);
    subscriptionMetadata.setNamespace(namespace);
    subscription.setMetadata(subscriptionMetadata);
    GenericKubernetesResource subscriptionSpec = new GenericKubernetesResource();
    subscriptionSpec.setAdditionalProperty("name", olmName);
    subscriptionSpec.setAdditionalProperty("installPlanApproval", manual ? "Manual" : "Automatic");
    subscriptionSpec.setAdditionalProperty("source", source);
    subscriptionSpec.setAdditionalProperty("sourceNamespace", sourceNamespace);
    if (channel != null) {
        subscriptionSpec.setAdditionalProperty("channel", channel);
    }
    subscription.setAdditionalProperty("spec", subscriptionSpec);
    client.genericKubernetesResources(Kube.OPERATOR_SUBSCRIPTION_CRD).inNamespace(namespace).createOrReplace(subscription);
    return CommandResult.SUCCESS;
}
Also used : CommandDefinition(org.aesh.command.CommandDefinition) OptionList(org.aesh.command.option.OptionList) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource) Messages(org.infinispan.cli.logging.Messages) CliCommand(org.infinispan.cli.commands.CliCommand) List(java.util.List) Version(org.infinispan.commons.util.Version) KubernetesContext(org.infinispan.cli.impl.KubernetesContext) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) CommandResult(org.aesh.command.CommandResult) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Optional(java.util.Optional) Option(org.aesh.command.option.Option) ContextAwareCommandInvocation(org.infinispan.cli.impl.ContextAwareCommandInvocation) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) GenericKubernetesResource(io.fabric8.kubernetes.api.model.GenericKubernetesResource)

Example 3 with SubscriptionSpec

use of io.fabric8.openshift.api.model.operatorhub.v1alpha1.SubscriptionSpec in project apicurio-registry by Apicurio.

the class OperatorUtils method deleteSubscription.

public static void deleteSubscription(Subscription subscription) {
    String name = subscription.getMetadata().getName();
    String namespace = subscription.getMetadata().getNamespace();
    SubscriptionSpec spec = subscription.getSpec();
    String startingCSV = spec.getStartingCSV();
    String info = MessageFormat.format("{0} in namespace {1}: packageName={2}, catalogSourceName={3}, catalogSourceNamespace={4}, " + "startingCSV={5}, channel={6}, installPlanApproval={7}", name, namespace, spec.getName(), spec.getSource(), spec.getSourceNamespace(), startingCSV, spec.getChannel(), spec.getInstallPlanApproval());
    if (Kubernetes.getSubscription(namespace, name) == null) {
        LOGGER.info("Subscription {} already removed.", info);
    } else {
        LOGGER.info("Removing subscription {}...", info);
        Kubernetes.deleteSubscription(namespace, name);
    }
}
Also used : SubscriptionSpec(io.fabric8.openshift.api.model.operatorhub.v1alpha1.SubscriptionSpec)

Aggregations

ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)2 SubscriptionSpec (io.fabric8.openshift.api.model.operatorhub.v1alpha1.SubscriptionSpec)2 GenericKubernetesResource (io.fabric8.kubernetes.api.model.GenericKubernetesResource)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 OperatorGroup (io.fabric8.openshift.api.model.operatorhub.v1.OperatorGroup)1 OperatorGroupSpec (io.fabric8.openshift.api.model.operatorhub.v1.OperatorGroupSpec)1 ClusterServiceVersion (io.fabric8.openshift.api.model.operatorhub.v1alpha1.ClusterServiceVersion)1 Subscription (io.fabric8.openshift.api.model.operatorhub.v1alpha1.Subscription)1 List (java.util.List)1 Optional (java.util.Optional)1 CommandDefinition (org.aesh.command.CommandDefinition)1 CommandResult (org.aesh.command.CommandResult)1 Option (org.aesh.command.option.Option)1 OptionList (org.aesh.command.option.OptionList)1 CliCommand (org.infinispan.cli.commands.CliCommand)1 ContextAwareCommandInvocation (org.infinispan.cli.impl.ContextAwareCommandInvocation)1 KubernetesContext (org.infinispan.cli.impl.KubernetesContext)1 Messages (org.infinispan.cli.logging.Messages)1 Version (org.infinispan.commons.util.Version)1