Skip to content

Commit

Permalink
Update TF to 0.4.0 + Update resoruces due to ResoruceType api changes (
Browse files Browse the repository at this point in the history
…#158)

Signed-off-by: David Kornel <[email protected]>
  • Loading branch information
kornys authored Aug 8, 2024
1 parent 3720b9f commit b5f0630
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 86 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<aspectj.version>1.9.21.2</aspectj.version>
<allure.version>2.27.0</allure.version>
<allure.maven.version>2.12.0</allure.maven.version>
<test-frame.version>0.3.0</test-frame.version>
<test-frame.version>0.4.0</test-frame.version>
</properties>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@ public void update(DataScienceCluster resource) {
}

@Override
public void delete(String s) {
dataScienceCLusterClient().withName(s).delete();
public void delete(DataScienceCluster s) {
dataScienceCLusterClient().withName(s.getMetadata().getName()).delete();
}

@Override
public void replace(String s, Consumer<DataScienceCluster> editor) {
DataScienceCluster toBeUpdated = dataScienceCLusterClient().withName(s).get();
public void replace(DataScienceCluster s, Consumer<DataScienceCluster> editor) {
DataScienceCluster toBeUpdated = dataScienceCLusterClient().withName(s.getMetadata().getName()).get();
editor.accept(toBeUpdated);
update(toBeUpdated);
}

@Override
public boolean waitForReadiness(DataScienceCluster resource) {
public boolean isReady(DataScienceCluster resource) {
String message = String.format("DataScienceCluster %s readiness", resource.getMetadata().getName());
Wait.until(message, TestConstants.GLOBAL_POLL_INTERVAL_SHORT, TestConstants.GLOBAL_TIMEOUT, () -> {
boolean dscReady;
Expand Down Expand Up @@ -132,12 +132,13 @@ public boolean waitForReadiness(DataScienceCluster resource) {
// https://github.com/red-hat-data-services/rhods-operator/blob/rhoai-2.8/controllers/datasciencecluster/datasciencecluster_controller.go#L257

// Wait for standard Kubernetes condition types (status for the whole DSC)
record ConditionExpectation(String conditionType, String expectedStatus) { }
record ConditionExpectation(String conditionType, String expectedStatus) {
}
List<ConditionExpectation> conditionExpectations = List.of(
new ConditionExpectation("Available", "True"),
new ConditionExpectation("Progressing", "False"),
new ConditionExpectation("Degraded", "False"),
new ConditionExpectation("Upgradeable", "True")
new ConditionExpectation("Available", "True"),
new ConditionExpectation("Progressing", "False"),
new ConditionExpectation("Degraded", "False"),
new ConditionExpectation("Upgradeable", "True")
);
for (ConditionExpectation conditionExpectation : conditionExpectations) {
String conditionType = conditionExpectation.conditionType;
Expand All @@ -155,16 +156,17 @@ record ConditionExpectation(String conditionType, String expectedStatus) { }
// Wait for DataScienceClusterCreationSuccessful event
EventingAPIGroupDSL eventsClient = KubeResourceManager.getKubeClient().getClient().events();
List<Event> resourceEvents = eventsClient.v1().events().inAnyNamespace().withNewFilter()
.withField("regarding.name", resource.getMetadata().getName())
.withField("regarding.uid", resource.getMetadata().getUid())
.endFilter().list().getItems();
.withField("regarding.name", resource.getMetadata().getName())
.withField("regarding.uid", resource.getMetadata().getUid())
.endFilter().list().getItems();
LOGGER.debug("DataScienceCluster {} events: {}", resource.getMetadata().getName(), resourceEvents.stream().map(Event::getReason).toList());
boolean hasCreationSuccessfulEvent = resourceEvents.stream()
.anyMatch(resourceEvent -> Objects.equals(resourceEvent.getReason(), OdhConstants.DSC_CREATION_SUCCESSFUL_EVENT_NAME));
.anyMatch(resourceEvent -> Objects.equals(resourceEvent.getReason(), OdhConstants.DSC_CREATION_SUCCESSFUL_EVENT_NAME));
dscReady = dscReady && hasCreationSuccessfulEvent;

return dscReady;
}, () -> { });
}, () -> {
});

String namespace = OdhConstants.CONTROLLERS_NAMESPACE;
LOGGER.info("Waiting for pods readiness in {}", namespace);
Expand All @@ -177,7 +179,7 @@ record ConditionExpectation(String conditionType, String expectedStatus) { }
}

@Override
public boolean waitForDeletion(DataScienceCluster dataScienceCluster) {
public boolean isDeleted(DataScienceCluster dataScienceCluster) {
return get(dataScienceCluster.getMetadata().getName()) == null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ public void update(DSCInitialization resource) {
}

@Override
public void delete(String s) {
dsciClient().withName(s).delete();
public void delete(DSCInitialization s) {
dsciClient().withName(s.getMetadata().getName()).delete();
}

@Override
public void replace(String s, Consumer<DSCInitialization> editor) {
DSCInitialization toBeUpdated = dsciClient().withName(s).get();
public void replace(DSCInitialization s, Consumer<DSCInitialization> editor) {
DSCInitialization toBeUpdated = dsciClient().withName(s.getMetadata().getName()).get();
editor.accept(toBeUpdated);
update(toBeUpdated);
}

@Override
public boolean waitForReadiness(DSCInitialization resource) {
public boolean isReady(DSCInitialization resource) {
String message = String.format("DSCInitialization %s readiness", resource.getMetadata().getName());
Wait.until(message, TestConstants.GLOBAL_POLL_INTERVAL_SHORT, TestConstants.GLOBAL_TIMEOUT, () -> {
boolean dsciReady;
Expand All @@ -76,7 +76,7 @@ public boolean waitForReadiness(DSCInitialization resource) {
}

@Override
public boolean waitForDeletion(DSCInitialization dscInitialization) {
public boolean isDeleted(DSCInitialization dscInitialization) {
return get(dscInitialization.getMetadata().getName()) == null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import io.kserve.serving.v1beta1.InferenceService;
import io.odh.test.TestConstants;
import io.odh.test.TestUtils;
import io.skodjob.testframe.interfaces.NamespacedResourceType;
import io.skodjob.testframe.interfaces.ResourceType;
import io.skodjob.testframe.resources.KubeResourceManager;
import io.skodjob.testframe.utils.PodUtils;
import io.skodjob.testframe.wait.Wait;
Expand All @@ -19,7 +19,7 @@

import java.util.function.Consumer;

public class InferenceServiceType implements NamespacedResourceType<InferenceService> {
public class InferenceServiceType implements ResourceType<InferenceService> {

private static final Logger LOGGER = LoggerFactory.getLogger(InferenceServiceType.class);

Expand All @@ -34,28 +34,30 @@ public InferenceService get(String namespace, String name) {

@Override
public void create(InferenceService resource) {
inferenceServiceClient().resource(resource).create();
inferenceServiceClient().inNamespace(resource.getMetadata().getNamespace()).resource(resource).create();
}

@Override
public void update(InferenceService resource) {
inferenceServiceClient().resource(resource).update();
inferenceServiceClient().inNamespace(resource.getMetadata().getNamespace()).resource(resource).update();
}

@Override
public void delete(String resource) {
inferenceServiceClient().withName(resource).delete();
public void delete(InferenceService resource) {
inferenceServiceClient().inNamespace(resource.getMetadata().getNamespace())
.withName(resource.getMetadata().getName()).delete();
}

@Override
public void replace(String s, Consumer<InferenceService> editor) {
InferenceService toBeUpdated = inferenceServiceClient().withName(s).get();
public void replace(InferenceService s, Consumer<InferenceService> editor) {
InferenceService toBeUpdated = inferenceServiceClient().inNamespace(s.getMetadata().getNamespace())
.withName(s.getMetadata().getName()).get();
editor.accept(toBeUpdated);
update(toBeUpdated);
}

@Override
public boolean waitForReadiness(InferenceService resource) {
public boolean isReady(InferenceService resource) {
String message = String.format("InferenceService %s readiness", resource.getMetadata().getName());
Wait.until(message, TestConstants.GLOBAL_POLL_INTERVAL_SHORT, TestConstants.GLOBAL_TIMEOUT, () -> {
boolean isReady;
Expand All @@ -71,7 +73,8 @@ public boolean waitForReadiness(InferenceService resource) {
isReady = isReady && readyStatus.equals("True");

return isReady;
}, () -> { });
}, () -> {
});

String namespace = resource.getMetadata().getNamespace();
LOGGER.info("Waiting for pods readiness in {}", namespace);
Expand All @@ -84,7 +87,7 @@ public boolean waitForReadiness(InferenceService resource) {
}

@Override
public boolean waitForDeletion(InferenceService inferenceService) {
public boolean isDeleted(InferenceService inferenceService) {
return get(inferenceService.getMetadata().getNamespace(), inferenceService.getMetadata().getName()) == null;
}

Expand All @@ -96,26 +99,4 @@ public static MixedOperation<InferenceService, KubernetesResourceList<InferenceS
public MixedOperation<?, ?, ?> getClient() {
return inferenceServiceClient();
}

@Override
public void createInNamespace(String namespace, InferenceService inferenceService) {
inferenceServiceClient().inNamespace(namespace).resource(inferenceService).create();
}

@Override
public void updateInNamespace(String namespace, InferenceService inferenceService) {
inferenceServiceClient().inNamespace(namespace).resource(inferenceService).update();
}

@Override
public void deleteFromNamespace(String namespace, String resource) {
inferenceServiceClient().inNamespace(namespace).withName(resource).delete();
}

@Override
public void replaceInNamespace(String namespace, String s, Consumer<InferenceService> editor) {
InferenceService toBeUpdated = inferenceServiceClient().inNamespace(namespace).withName(s).get();
editor.accept(toBeUpdated);
update(toBeUpdated);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import io.odh.test.Environment;
import io.odh.test.OdhConstants;
import io.odh.test.TestUtils;
import io.skodjob.testframe.interfaces.NamespacedResourceType;
import io.skodjob.testframe.interfaces.ResourceType;
import io.skodjob.testframe.resources.KubeResourceManager;
import org.kubeflow.v1.Notebook;

Expand All @@ -24,7 +24,7 @@
import org.apache.commons.io.IOUtils;


public class NotebookType implements NamespacedResourceType<Notebook> {
public class NotebookType implements ResourceType<Notebook> {

private static final String REGISTRY_PATH = "image-registry.openshift-image-registry.svc:5000";
public static final String JUPYTER_MINIMAL_IMAGE = "jupyter-minimal-notebook";
Expand All @@ -40,7 +40,9 @@ public class NotebookType implements NamespacedResourceType<Notebook> {
static {
RHOAI_IMAGES_MAP = Map.<String, String>of(JUPYTER_MINIMAL_IMAGE, "s2i-minimal-notebook");
}

private static final String NOTEBOOK_TEMPLATE_PATH = "notebook.yaml";

@Override
public String getKind() {
return "Notebook";
Expand All @@ -61,24 +63,25 @@ public void update(Notebook resource) {
}

@Override
public void delete(String s) {
notebookClient().withName(s).delete();
public void delete(Notebook s) {
notebookClient().inNamespace(s.getMetadata().getNamespace()).withName(s.getMetadata().getName()).delete();
}

@Override
public void replace(String resource, Consumer<Notebook> editor) {
Notebook toBeUpdated = notebookClient().withName(resource).get();
public void replace(Notebook resource, Consumer<Notebook> editor) {
Notebook toBeUpdated = notebookClient().inNamespace(resource.getMetadata().getNamespace())
.withName(resource.getMetadata().getName()).get();
editor.accept(toBeUpdated);
update(toBeUpdated);
}

@Override
public boolean waitForReadiness(Notebook resource) {
public boolean isReady(Notebook resource) {
return resource != null;
}

@Override
public boolean waitForDeletion(Notebook notebook) {
public boolean isDeleted(Notebook notebook) {
return get(notebook.getMetadata().getNamespace(), notebook.getMetadata().getName()) == null;
}

Expand Down Expand Up @@ -114,26 +117,4 @@ public static String getNotebookImage(String imageName, String imageTag) {
public MixedOperation<?, ?, ?> getClient() {
return notebookClient();
}

@Override
public void createInNamespace(String namespace, Notebook notebook) {
notebookClient().inNamespace(namespace).resource(notebook).create();
}

@Override
public void updateInNamespace(String namespace, Notebook notebook) {
notebookClient().inNamespace(namespace).resource(notebook).update();
}

@Override
public void deleteFromNamespace(String namespace, String resource) {
notebookClient().inNamespace(namespace).withName(resource).delete();
}

@Override
public void replaceInNamespace(String namespace, String resoruce, Consumer<Notebook> editor) {
Notebook toBeUpdated = notebookClient().inNamespace(namespace).withName(resoruce).get();
editor.accept(toBeUpdated);
update(toBeUpdated);
}
}

0 comments on commit b5f0630

Please sign in to comment.