Skip to content

Commit

Permalink
Install using OLM with bundle-image (#15)
Browse files Browse the repository at this point in the history
Signed-off-by: David Kornel <[email protected]>
  • Loading branch information
kornys authored Aug 1, 2024
1 parent cf43e1b commit d235255
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<test-frame.version>0.2.1</test-frame.version>
<test-frame.version>0.3.0</test-frame.version>
<fabric8.version>6.13.1</fabric8.version>
<log4j.version>2.23.1</log4j.version>
<slf4j.version>2.0.13</slf4j.version>
Expand Down Expand Up @@ -73,7 +73,6 @@
<groupId>io.skodjob</groupId>
<artifactId>test-frame-openshift</artifactId>
<version>${test-frame.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.skodjob</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright Skodjob authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
package io.streams.operators.olm.bundle;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.fabric8.kubernetes.api.model.LabelSelectorBuilder;
import io.fabric8.kubernetes.api.model.Namespace;
import io.fabric8.kubernetes.api.model.NamespaceBuilder;
import io.skodjob.testframe.TestFrameConstants;
import io.skodjob.testframe.olm.OperatorSdkRun;
import io.skodjob.testframe.olm.OperatorSdkRunBuilder;
import io.skodjob.testframe.resources.KubeResourceManager;
import io.skodjob.testframe.utils.PodUtils;
import io.skodjob.testframe.wait.Wait;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.concurrent.CompletableFuture;

/**
* Installer strimzi operator using olm from bundle-image
*/
public class StrimziOlmBundleInstaller {
private static final Logger LOGGER = LoggerFactory.getLogger(StrimziOlmBundleInstaller.class);

/**
* Install strimzi operator from bundle-image using OLM
*
* @param operatorName name of operator
* @param operatorNamespace namespace where to install
* @param bundleImageRef bundle image
* @return wait future
*/
public static CompletableFuture<Void> install(String operatorName, String operatorNamespace, String bundleImageRef) {
// Create ns for the operator
Namespace ns = new NamespaceBuilder()
.withNewMetadata()
.withName(operatorNamespace)
.endMetadata()
.build();
KubeResourceManager.getInstance().createOrUpdateResourceWithWait(ns);

OperatorSdkRun osr = new OperatorSdkRunBuilder()
.withBundleImage(bundleImageRef)
.withInstallMode("AllNamespaces")
.withNamespace(operatorNamespace)
.build();

CompletableFuture<Void> osrRun = CompletableFuture.runAsync(osr::run);

return Wait.untilAsync(operatorName + " is ready", TestFrameConstants.GLOBAL_POLL_INTERVAL_1_SEC,
TestFrameConstants.GLOBAL_TIMEOUT, () -> {
CompletableFuture.allOf(osrRun).join();
return isOperatorReady(operatorNamespace);
});
}

@SuppressFBWarnings("REC_CATCH_EXCEPTION")
private static boolean isOperatorReady(String ns) {
try {
PodUtils.waitForPodsReadyWithRestart(ns, new LabelSelectorBuilder()
.withMatchLabels(Map.of("strimzi.io/kind", "cluster-operator")).build(), 1, true);
LOGGER.info("Strimzi operator in namespace {} is ready", ns);
return true;
} catch (Exception ex) {
return false;
}
}
}
12 changes: 12 additions & 0 deletions src/test/java/io/streams/e2e/dummy/DummyST.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.streams.operators.manifests.DebeziumManifestInstaller;
import io.streams.operators.manifests.FlinkManifestInstaller;
import io.streams.operators.manifests.StrimziManifestInstaller;
import io.streams.operators.olm.bundle.StrimziOlmBundleInstaller;
import io.streams.operators.olm.catalog.StrimziOlmCatalogInstaller;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -57,6 +58,17 @@ void installStrimziByOlmCatalogTest() {
.withName("strimzi-cluster-operator-v0.42.0").isReady());
}

@Test
void installStrimziByOlmBundleTest() {
CompletableFuture.allOf(
StrimziOlmBundleInstaller.install("strimzi-kafka-operator", "strimzi-olm",
"quay.io/operatorhubio/strimzi-kafka-operator:v0.42.0--20240710T183231")
).join();
assertTrue(KubeResourceManager.getKubeClient().getClient().apps()
.deployments().inNamespace("strimzi-olm")
.withName("strimzi-cluster-operator-v0.42.0").isReady());
}

@Test
void installDebeziumFromManifestsTest() throws IOException {
CompletableFuture.allOf(
Expand Down

0 comments on commit d235255

Please sign in to comment.