Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: ODS-xxxx expose dashboard 8080 and curl to it #52

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
@Tag(TestSuite.CONTINUOUS)
public class DataScienceClusterST extends Abstract {

private static final String DS_CLUSTER_NAME = "default";
// TODO on my cluster this is default-dsc, cluster created with existing jenkins automation in PSI
private static final String DS_CLUSTER_NAME = "default-dsc";
private static final String DS_DASHBOARD_CONFIG_NAME = "odh-dashboard-config";
MixedOperation<DataScienceCluster, KubernetesResourceList<DataScienceCluster>, Resource<DataScienceCluster>> dataScienceProjectCli;
MixedOperation<OdhDashboardConfig, KubernetesResourceList<OdhDashboardConfig>, Resource<OdhDashboardConfig>> dashboardConfigCli;
Expand Down
115 changes: 115 additions & 0 deletions src/test/java/io/odh/test/e2e/continuous/DataScienceDashboardST.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright Skodjob authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
package io.odh.test.e2e.continuous;

import io.fabric8.kubernetes.api.model.IntOrString;
import io.fabric8.kubernetes.api.model.KubernetesResourceList;
import io.fabric8.kubernetes.api.model.Service;
import io.fabric8.kubernetes.api.model.ServicePort;
import io.fabric8.kubernetes.api.model.ServicePortBuilder;
import io.fabric8.kubernetes.client.dsl.MixedOperation;
import io.fabric8.kubernetes.client.dsl.Resource;
import io.fabric8.openshift.api.model.Route;
import io.fabric8.openshift.client.OpenShiftClient;
import io.odh.test.TestSuite;
import io.odh.test.e2e.Abstract;
import io.odh.test.framework.manager.ResourceManager;
import io.odh.test.framework.manager.resources.NotebookResource;
import io.odh.test.utils.DeploymentUtils;
import lombok.extern.java.Log;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.provider.Arguments;
import org.kubeflow.v1.Notebook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.util.stream.Stream;

// TODO: what's difference between continuous and standard?
@Tag(TestSuite.CONTINUOUS)
//TODO: what is ST? system test?
public class DataScienceDashboardST extends Abstract {
static final Logger LOGGER = LoggerFactory.getLogger(DataScienceDashboardST.class);

@Test
void checkDataScienceProjects() throws IOException, InterruptedException {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Tag("ODS-1860")?

try (OpenShiftClient kubeClient = ResourceManager.getClient().getClient().adapt(OpenShiftClient.class)) {
Service service = kubeClient.services()
.inNamespace("redhat-ods-applications")
.withName("rhods-dashboard")
.get();

ServicePort port1 = new ServicePortBuilder()
.withName("8443-tcp")
.withProtocol("TCP")
.withPort(8443)
.withTargetPort(new IntOrString(8443))
.build();

ServicePort port2 = new ServicePortBuilder()
.withName("8080-tcp")
.withProtocol("TCP")
.withPort(8080)
.withTargetPort(new IntOrString(8080))
.build();

Service updatedService = service.edit()
.editSpec()
.addToPorts(port1, port2)
.endSpec()
.build();

Route route = kubeClient.routes().load(new ByteArrayInputStream("""
apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: rhods-dashboard-internal
namespace: redhat-ods-applications
labels:
app: rhods-dashboard
app.kubernetes.io/part-of: rhods-dashboard
spec:
port:
targetPort: 8080-tcp
to:
kind: Service
name: rhods-dashboard
wildcardPolicy: None
""".getBytes(StandardCharsets.UTF_8))).item();
kubeClient.routes().resource(route).create();

// do I need to wait here?

// fetch the route object from the server
Route r2 = kubeClient.routes().resource(route).get();
String url = "http://%s/api/status".formatted(r2.getSpec().getHost());

HttpRequest request = HttpRequest.newBuilder(URI.create(url))
.GET()
.header("x-forwarded-access-token", "asdfadsfasd")
.build();
LOGGER.debug("Making request {}", request);
HttpClient httpClient = HttpClient.newHttpClient();
HttpResponse<Void> response = httpClient.send(request, HttpResponse.BodyHandlers.discarding());
LOGGER.debug("Got response {}", response);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the test scenario itself. Maybe run this curl directly in the container the service is fronting? Or put my own container that contains curl there, and don't expose any routes...?


Assertions.assertEquals(401, response.statusCode());

service.edit().editSpec().removeFromPorts(port1, port2).endSpec().build();
kubeClient.routes().resource(route).delete();
Comment on lines +111 to +112
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this teardown. I can put it either in finally or do @nested test class and make it regular @after... teardown?

}
}
}
Loading