Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions junit5/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -44,5 +45,4 @@
</dependency>
</dependencies>


</project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
import io.fabric8.openshift.api.model.DeploymentConfig;
import io.fabric8.openshift.api.model.ImageStream;
import io.fabric8.openshift.api.model.Route;
import io.fabric8.openshift.api.model.operatorhub.v1.OperatorGroup;
import io.fabric8.openshift.api.model.operatorhub.v1alpha1.ClusterServiceVersion;
import io.fabric8.openshift.api.model.operatorhub.v1alpha1.InstallPlan;
import io.fabric8.openshift.api.model.operatorhub.v1alpha1.Subscription;

/**
* Record OpenShift isolated state relative to a test.
Expand Down Expand Up @@ -213,6 +217,10 @@ public void recordState(ExtensionContext context) throws IOException {
!isMasterAndBuildNamespaceSame() ? getFilter(context, BUILD_FILTER_MASTER) : null);
saveEvents(context, getFilter(context, EVENT_FILTER_MASTER),
!isMasterAndBuildNamespaceSame() ? getFilter(context, EVENT_FILTER_BUILDS) : null);
saveClusterServiceVersions(context);
saveInstallPlans(context);
saveOperatorGroups(context);
saveSubscriptions(context);
}

private boolean isFilterInitializationComplete(ExtensionContext context) {
Expand Down Expand Up @@ -521,6 +529,39 @@ protected void saveBuildLogs(ExtensionContext context, ResourcesFilterBuilder<Bu
}
}

protected void saveClusterServiceVersions(ExtensionContext context) throws IOException {
final Path logPath = Paths.get(attachmentsDir(), dirNameForTest(context), "clusterServiceVersions.log");
try (final ResourcesPrinterHelper<ClusterServiceVersion> printer = ResourcesPrinterHelper
.forClusterServiceVersion(logPath)) {
OpenShifts.admin().operatorHub().clusterServiceVersions().inNamespace(OpenShifts.master().getNamespace())
.list().getItems().stream().forEach(printer::row);
}
}

protected void saveInstallPlans(ExtensionContext context) throws IOException {
final Path logPath = Paths.get(attachmentsDir(), dirNameForTest(context), "installPlans.log");
try (final ResourcesPrinterHelper<InstallPlan> printer = ResourcesPrinterHelper.forInstallPlan(logPath)) {
OpenShifts.admin().operatorHub().installPlans().inNamespace(OpenShifts.master().getNamespace())
.list().getItems().stream().forEach(printer::row);
}
}

protected void saveOperatorGroups(ExtensionContext context) throws IOException {
final Path logPath = Paths.get(attachmentsDir(), dirNameForTest(context), "operatorGroups.log");
try (final ResourcesPrinterHelper<OperatorGroup> printer = ResourcesPrinterHelper.forOperatorGroup(logPath)) {
OpenShifts.admin().operatorHub().operatorGroups().inNamespace(OpenShifts.master().getNamespace())
.list().getItems().stream().forEach(printer::row);
}
}

protected void saveSubscriptions(ExtensionContext context) throws IOException {
final Path logPath = Paths.get(attachmentsDir(), dirNameForTest(context), "subscriptions.log");
try (final ResourcesPrinterHelper<Subscription> printer = ResourcesPrinterHelper.forSubscription(logPath)) {
OpenShifts.admin().operatorHub().subscriptions().inNamespace(OpenShifts.master().getNamespace())
.list().getItems().stream().forEach(printer::row);
}
}

private String attachmentsDir() {
return JUnitConfig.recordDir() != null ? JUnitConfig.recordDir() : System.getProperty("user.dir");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.api.model.ContainerStatus;
Expand All @@ -23,6 +24,10 @@
import io.fabric8.openshift.api.model.DeploymentConfig;
import io.fabric8.openshift.api.model.ImageStream;
import io.fabric8.openshift.api.model.Route;
import io.fabric8.openshift.api.model.operatorhub.v1.OperatorGroup;
import io.fabric8.openshift.api.model.operatorhub.v1alpha1.ClusterServiceVersion;
import io.fabric8.openshift.api.model.operatorhub.v1alpha1.InstallPlan;
import io.fabric8.openshift.api.model.operatorhub.v1alpha1.Subscription;

public class ResourcesPrinterHelper<X> implements AutoCloseable {
private final Path file;
Expand Down Expand Up @@ -189,6 +194,72 @@ private static LinkedHashMap<String, String> getServicesCols(Service service) {
return map;
}

public static ResourcesPrinterHelper<ClusterServiceVersion> forClusterServiceVersion(Path filePath) {
return new ResourcesPrinterHelper<>(filePath,
ResourcesPrinterHelper::getClusterServiceVersionCols);
}

private static LinkedHashMap<String, String> getClusterServiceVersionCols(ClusterServiceVersion csv) {
LinkedHashMap<String, String> map = new LinkedHashMap<>(5);
map.put("NAME", csv.getMetadata().getName());
map.put("CREATED", csv.getMetadata().getCreationTimestamp());
map.put("PHASE", csv.getStatus().getPhase());
map.put("REASON", csv.getStatus().getReason());
map.put("MESSAGE", csv.getStatus().getMessage());
return map;
}

public static ResourcesPrinterHelper<InstallPlan> forInstallPlan(Path filePath) {
return new ResourcesPrinterHelper<>(filePath,
ResourcesPrinterHelper::getInstallPlanCols);
}

private static LinkedHashMap<String, String> getInstallPlanCols(InstallPlan ip) {
LinkedHashMap<String, String> map = new LinkedHashMap<>(6);
map.put("NAME", ip.getMetadata().getName());
map.put("CREATED", ip.getMetadata().getCreationTimestamp());
map.put("PHASE", ip.getStatus().getPhase());
map.put("CATALOG SOURCES", ip.getStatus().getCatalogSources().toString());
map.put("CSVS", ip.getSpec().getClusterServiceVersionNames().toString());
map.put("CONDITIONS", ip.getStatus().getConditions()
.stream()
.filter(cond -> "True".equalsIgnoreCase(cond.getStatus()))
.map(cond -> cond.getType())
.collect(Collectors.joining(",", "[", "]")));
return map;
}

public static ResourcesPrinterHelper<OperatorGroup> forOperatorGroup(Path filePath) {
return new ResourcesPrinterHelper<>(filePath,
ResourcesPrinterHelper::getOperatorGroupCols);
}

private static LinkedHashMap<String, String> getOperatorGroupCols(OperatorGroup og) {
LinkedHashMap<String, String> map = new LinkedHashMap<>(3);
map.put("NAME", og.getMetadata().getName());
map.put("TARGET NAMESPACE", og.getSpec().getTargetNamespaces().toString());
map.put("NAMESPACES", og.getStatus().getNamespaces().toString());
return map;
}

public static ResourcesPrinterHelper<Subscription> forSubscription(Path filePath) {
return new ResourcesPrinterHelper<>(filePath,
ResourcesPrinterHelper::getSubscriptionCols);
}

private static LinkedHashMap<String, String> getSubscriptionCols(Subscription subscription) {
LinkedHashMap<String, String> map = new LinkedHashMap<>(8);
map.put("NAME", subscription.getMetadata().getName());
map.put("SOURCE", subscription.getSpec().getSource());
map.put("CHANNEL", subscription.getSpec().getChannel());
map.put("STARTING CSV", subscription.getSpec().getStartingCSV());
map.put("INSTALLED CSV", subscription.getStatus().getInstalledCSV());
map.put("CURRENT CSV", subscription.getStatus().getCurrentCSV());
map.put("STATE", subscription.getStatus().getState());
map.put("REASON", subscription.getStatus().getReason());
return map;
}

public void row(X resource) {
row(resourceToCols.apply(resource));
}
Expand Down