Skip to content

Commit

Permalink
[issue-1323] - Added RequiresOpenshift4 to prevent RouteInOtherNamesp…
Browse files Browse the repository at this point in the history
…aceIT from running in CI
  • Loading branch information
fabiobrz committed Dec 22, 2024
1 parent b84c923 commit 9d4333d
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
- name: Build and run integration tests for OpenShift target (${{ matrix.java }})
if: ${{ matrix.target == 'openshift' }}
run: |
./mvnw verify -pl openshift -amd -Dfailsafe.groups=org.arquillian.cube.openshift.impl.requirement.RequiresOpenshift -Dcontainerless.skip.tests=true
./mvnw verify -pl openshift -amd -Dfailsafe.groups=org.arquillian.cube.openshift.impl.requirement.RequiresOpenshift -Dfailsafe.excludedGroups=org.arquillian.cube.openshift.impl.requirement.RequiresOpenshift4 -Dcontainerless.skip.tests=true
- uses: actions/upload-artifact@v4
if: failure()
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
import java.net.URL;
import org.arquillian.cube.openshift.impl.enricher.RouteURL;
import org.arquillian.cube.openshift.impl.requirement.RequiresOpenshift;
import org.arquillian.cube.openshift.impl.requirement.RequiresOpenshift4;
import org.arquillian.cube.requirement.ArquillianConditionalRunner;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

@Category(RequiresOpenshift.class)
@RequiresOpenshift
@RunWith(ArquillianConditionalRunner.class)
@RequiresOpenshift4
public class RouteInOtherNamespaceIT {

@RouteURL(value = "prometheus-k8s", namespace = "openshift-monitoring")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.arquillian.cube.openshift.impl.requirement;

import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.http.HttpClient;
import io.fabric8.kubernetes.client.http.HttpRequest;
import io.fabric8.kubernetes.client.http.HttpResponse;
import io.fabric8.kubernetes.client.jdkhttp.JdkHttpClientFactory;
import io.fabric8.kubernetes.client.utils.URLUtils;
import io.fabric8.openshift.client.OpenShiftClient;
import org.arquillian.cube.kubernetes.impl.ClientConfigBuilder;
import org.arquillian.cube.kubernetes.impl.DefaultConfiguration;
import org.arquillian.cube.kubernetes.impl.ExtensionRegistrar;
import org.arquillian.cube.kubernetes.impl.utils.CommandExecutor;
import org.arquillian.cube.spi.requirement.Constraint;
import org.arquillian.cube.spi.requirement.UnsatisfiedRequirementException;

import java.io.IOException;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;

import static org.arquillian.cube.kubernetes.impl.DefaultConfigurationFactory.KUBERNETES_EXTENSION_NAME;
import static org.arquillian.cube.openshift.impl.client.CubeOpenShiftConfigurationFactory.OPENSHIFT_EXTENSION_NAME;

public class Openshift4Requirement implements Constraint<RequiresOpenshift4> {

@Override
public void check(RequiresOpenshift4 context) throws UnsatisfiedRequirementException {
final List<String> extension = Arrays.asList(KUBERNETES_EXTENSION_NAME, OPENSHIFT_EXTENSION_NAME);

final DefaultConfiguration config = new ExtensionRegistrar().loadExtension(extension);

final Config httpClientConfig = new ClientConfigBuilder().configuration(config).build();
try (KubernetesClient client = new DefaultKubernetesClient(httpClientConfig)) {

HttpClient.Factory httpClientFactory = new JdkHttpClientFactory();
HttpClient httpClient = httpClientFactory.newBuilder(httpClientConfig).build();

HttpRequest versionRequest = httpClient.newHttpRequestBuilder()
.url(new URL(URLUtils.join(client.getMasterUrl().toString(), "version").toString()))
.method("GET", "application/json", null)
.build();

HttpResponse<String> response = httpClient.sendAsync(versionRequest, String.class).get();
if (!response.isSuccessful()) {
throw new UnsatisfiedRequirementException(
"Failed to verify Openshift version, due to: [" + response.message() + "]");
} else if (!client.isAdaptable(OpenShiftClient.class)) {
throw new UnsatisfiedRequirementException(
"A valid Kubernetes environment was found, but not Openshift.");
}
CommandExecutor ce = new CommandExecutor();
List<String> ocVersion = ce.execCommand("oc version");
if (ocVersion.stream().noneMatch(o -> o.contains("Server Version: 4"))) {
throw new UnsatisfiedRequirementException(
"A valid OpenShift 4 environment was found, but not Openshift.");
}
} catch (IOException | IllegalArgumentException | InterruptedException | ExecutionException e) {
throw new UnsatisfiedRequirementException(
"Error while checking Openshift version: [" + e.getMessage() + "]");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
org.arquillian.cube.openshift.impl.requirement.OpenshiftRequirement
org.arquillian.cube.openshift.impl.requirement.Openshift4Requirement
org.arquillian.cube.openshift.impl.requirement.OpenshiftOlmRequirement
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.arquillian.cube.openshift.impl.requirement;

import org.arquillian.cube.spi.requirement.Constraint;
import org.arquillian.cube.spi.requirement.Requires;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
@Requires(Constraint.class)
public @interface RequiresOpenshift4 {

String name() default "";
}

0 comments on commit 9d4333d

Please sign in to comment.