From c41cc7de661525ef40bed3d3da265ea0ecad53e5 Mon Sep 17 00:00:00 2001 From: Jakub Stejskal Date: Tue, 5 Dec 2023 10:43:24 +0100 Subject: [PATCH] Use instanceOf instead of string comparison Signed-off-by: Jakub Stejskal --- src/main/java/io/odh/test/TestConstants.java | 5 --- .../framework/manager/ResourceManager.java | 39 +++++++++---------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/main/java/io/odh/test/TestConstants.java b/src/main/java/io/odh/test/TestConstants.java index 045b03a8..e51b12ae 100644 --- a/src/main/java/io/odh/test/TestConstants.java +++ b/src/main/java/io/odh/test/TestConstants.java @@ -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() { } } diff --git a/src/main/java/io/odh/test/framework/manager/ResourceManager.java b/src/main/java/io/odh/test/framework/manager/ResourceManager.java index b151f27e..0028c57e 100644 --- a/src/main/java/io/odh/test/framework/manager/ResourceManager.java +++ b/src/main/java/io/odh/test/framework/manager/ResourceManager.java @@ -74,18 +74,17 @@ private 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); @@ -110,15 +109,13 @@ public final void deleteResource(T... resources) { for (T resource : resources) { ResourceType 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) {