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