-
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] - Adding a requirement to mark tests tht need OLM to be …
…deployed Fix CI steps order to prevent OpenSHift setup step frm wiping the local dir contents
- Loading branch information
Showing
5 changed files
with
101 additions
and
12 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
65 changes: 65 additions & 0 deletions
65
...src/main/java/org/arquillian/cube/openshift/impl/requirement/OpenshiftOlmRequirement.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,65 @@ | ||
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.olm.impl.requirement.RequiresOlm; | ||
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 OpenshiftOlmRequirement implements Constraint<RequiresOlm> { | ||
|
||
@Override | ||
public void check(RequiresOlm 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."); | ||
} | ||
if (client.namespaces().withName("openshift-operators").get() == null) { | ||
throw new UnsatisfiedRequirementException("OLM is not installed on 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 +1,2 @@ | ||
org.arquillian.cube.openshift.impl.requirement.OpenshiftRequirement | ||
org.arquillian.cube.openshift.impl.requirement.OpenshiftOlmRequirement |
20 changes: 20 additions & 0 deletions
20
requirement-spi/src/main/java/org/arquillian/cube/olm/impl/requirement/RequiresOlm.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,20 @@ | ||
package org.arquillian.cube.olm.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; | ||
|
||
/** | ||
* Marks tests that require Operator Lifecycle Manager | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE, ElementType.METHOD}) | ||
@Requires(Constraint.class) | ||
public @interface RequiresOlm { | ||
|
||
String name() default ""; | ||
} |