-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[issue-1323] - Added RequiresOpenshift4 to prevent RouteInOtherNamesp…
…aceIT from running in CI
- Loading branch information
Showing
5 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...t/src/main/java/org/arquillian/cube/openshift/impl/requirement/Openshift4Requirement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() + "]"); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...shift/src/main/resources/META-INF/services/org.arquillian.cube.spi.requirement.Constraint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
17 changes: 17 additions & 0 deletions
17
...-spi/src/main/java/org/arquillian/cube/openshift/impl/requirement/RequiresOpenshift4.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ""; | ||
} |