Skip to content

Commit

Permalink
Make subscription and CSV related behavior overridable in OperaotrPro…
Browse files Browse the repository at this point in the history
…visioner, e.g. to let ODH provisioning deal with all namespaces
  • Loading branch information
fabiobrz committed Jan 6, 2025
1 parent 95ba7c6 commit 0001ba4
Showing 1 changed file with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
public abstract class OperatorProvisioner<A extends OperatorApplication, C extends NamespacedKubernetesClient>
implements Provisioner<A>, Scalable {
// cache the current csv and list of provided custom resource definitions
static String currentCSV;
final String packageManifestName;
protected static String currentCSV;
protected final String packageManifestName;
private CatalogSource catalogSource;
private final A operatorApplication;
private PackageManifest packageManifest;
Expand Down Expand Up @@ -180,6 +180,16 @@ private String getCatalogSourceNamespace() {
return namespace;
}

/**
* The CatalogSource is in the "openshift-marketplace" namespace by default on OpenShift, in the "olm" one on K8s.
* When a custom operator image must be used, then a custom CatalogSource will be created in the current namespace.
*
* @return namespace where the custom CatalogSource is located
*/
protected String getTargetNamespace() {
return this.client().getNamespace();
}

/**
* Initialize a reference to a proper catalog source which will be used to pull the required operator image.
*
Expand Down Expand Up @@ -350,7 +360,7 @@ public void subscribe(String installPlanApproval, Map<String, String> envVariabl
log.info("Subscribing the {} operator", packageManifestName);
// oc get packagemanifest wildfly -o template --template {{.status.defaultChannel}}
final String catalogSourceNamespace = getCatalogSourceNamespace();
final String targetNamespace = this.client().getNamespace();
final String targetNamespace = getTargetNamespace();
Subscription operatorSubscription = (envVariables == null || envVariables.isEmpty())
? new Subscription(catalogSourceNamespace, targetNamespace, getOperatorCatalogSource(),
packageManifestName,
Expand Down Expand Up @@ -462,7 +472,7 @@ protected void waitForOperatorPod() {
if (operatorSpec.length != 3) {
throw new IllegalStateException("Failed to get operator deployment spec from csvs!");
}
BooleanSupplier bs = () -> this.client().inNamespace(this.client().getNamespace()).pods().list().getItems().stream()
BooleanSupplier bs = () -> this.client().inNamespace(this.getTargetNamespace()).pods().list().getItems().stream()
.filter(p -> !com.google.common.base.Strings.isNullOrEmpty(p.getMetadata().getLabels().get(operatorSpec[1]))
&& p.getMetadata().getLabels().get(operatorSpec[1]).equals(operatorSpec[2])
&& p.getStatus().getContainerStatuses().size() > 0
Expand All @@ -486,8 +496,8 @@ protected FailFastCheck getFailFastCheck() {
* Documentation: https://docs.openshift.com/container-platform/4.4/operators/olm-deleting-operators-from-cluster.html#olm-deleting-operator-from-a-cluster-using-cli_olm-deleting-operators-from-a-cluster
*/
public void unsubscribe() {
this.execute("delete", "subscription", packageManifestName, "--ignore-not-found");
this.execute("delete", "csvs", currentCSV, "--ignore-not-found");
removeSubscription();
removeClusterServiceVersion();
for (String customResource : getCustomResourceDefinitions()) {
final String crds = this.execute("get", "crd", customResource, "--ignore-not-found");
if (crds != null && !crds.isEmpty()) {
Expand All @@ -496,6 +506,14 @@ public void unsubscribe() {
}
}

protected void removeClusterServiceVersion() {
this.execute("delete", "csvs", currentCSV, "--ignore-not-found");
}

protected void removeSubscription() {
this.execute("delete", "subscription", packageManifestName, "--ignore-not-found");
}

public String getCurrentCSV() {
return currentCSV;
}
Expand Down

0 comments on commit 0001ba4

Please sign in to comment.