Skip to content

Commit

Permalink
Use instanceOf instead of string comparison
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Stejskal <[email protected]>
  • Loading branch information
Frawless committed Dec 5, 2023
1 parent 5a25d8f commit 98cb1e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
5 changes: 0 additions & 5 deletions src/main/java/io/odh/test/TestConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ public class TestConstants {
public static final long GLOBAL_POLL_INTERVAL_SHORT = Duration.ofSeconds(1).toMillis();
public static final long GLOBAL_TIMEOUT = Duration.ofMinutes(5).toMillis();


/**
* Kube objects
*/
public static final String DEPLOYMENT = "Deployment";
private TestConstants() {
}
}
39 changes: 18 additions & 21 deletions src/main/java/io/odh/test/framework/manager/ResourceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,17 @@ private <T extends HasMetadata> void createResource(boolean waitReady, T... reso
}

if (type == null) {
switch (resource.getKind()) {
case TestConstants.DEPLOYMENT:
Deployment deployment = (Deployment) resource;
ResourceManager.getClient().getClient().apps().deployments().resource(deployment).create();
if (waitReady) {
DeploymentUtils.waitForDeploymentReady(resource.getMetadata().getNamespace(), resource.getMetadata().getName());
}
break;
default:
LOGGER.error("Invalid resource {} {}/{}. Please implement it in ResourceManager",
resource.getKind(), resource.getMetadata().getNamespace(), resource.getMetadata().getName());
continue;
if (resource instanceof Deployment) {
Deployment deployment = (Deployment) resource;
ResourceManager.getClient().getClient().apps().deployments().resource(deployment).create();
if (waitReady) {
DeploymentUtils.waitForDeploymentReady(resource.getMetadata().getNamespace(), resource.getMetadata().getName());
}
continue;
} else {
LOGGER.error("Invalid resource {} {}/{}. Please implement it in ResourceManager",
resource.getKind(), resource.getMetadata().getNamespace(), resource.getMetadata().getName());
continue;
}
} else {
type.create(resource);
Expand All @@ -110,15 +109,13 @@ public final <T extends HasMetadata> void deleteResource(T... resources) {
for (T resource : resources) {
ResourceType<T> type = findResourceType(resource);
if (type == null) {
switch (resource.getKind()) {
case TestConstants.DEPLOYMENT:
Deployment deployment = (Deployment) resource;
ResourceManager.getClient().getClient().apps().deployments().resource(deployment).delete();
DeploymentUtils.waitForDeploymentDeletion(resource.getMetadata().getNamespace(), resource.getMetadata().getName());
break;
default:
LOGGER.error("Invalid resource {} {}/{}. Please implement it in ResourceManager",
resource.getKind(), resource.getMetadata().getNamespace(), resource.getMetadata().getName());
if (resource instanceof Deployment) {
Deployment deployment = (Deployment) resource;
ResourceManager.getClient().getClient().apps().deployments().resource(deployment).delete();
DeploymentUtils.waitForDeploymentDeletion(resource.getMetadata().getNamespace(), resource.getMetadata().getName());
} else {
LOGGER.error("Invalid resource {} {}/{}. Please implement it in ResourceManager",
resource.getKind(), resource.getMetadata().getNamespace(), resource.getMetadata().getName());
}
} else {
if (resource.getMetadata().getNamespace() == null) {
Expand Down

0 comments on commit 98cb1e9

Please sign in to comment.