diff --git a/test-frame-common/src/main/java/io/skodjob/testframe/interfaces/NamespacedResourceType.java b/test-frame-common/src/main/java/io/skodjob/testframe/interfaces/NamespacedResourceType.java deleted file mode 100644 index 00ae8cb..0000000 --- a/test-frame-common/src/main/java/io/skodjob/testframe/interfaces/NamespacedResourceType.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright Skodjob authors. - * License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html). - */ -package io.skodjob.testframe.interfaces; - -import java.util.function.Consumer; - -import io.fabric8.kubernetes.api.model.HasMetadata; -import io.fabric8.kubernetes.client.dsl.MixedOperation; - -/** - * Class for encapsulating methods related to {@link T} resource. - * - * @param resource type - */ -public interface NamespacedResourceType extends ResourceType { - - /** - * Get specific {@link T} client for resoruce - * - * @return specific client - */ - MixedOperation getClient(); - - /** - * Creates specific {@link T} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be created - * @param resource {@link T} resource - */ - void createInNamespace(String namespaceName, T resource); - - /** - * Updates specific {@link T} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be updated - * @param resource {@link T} updated resource - */ - void updateInNamespace(String namespaceName, T resource); - - /** - * Deletes {@link T} resource from Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be deleted - * @param resourceName name of the {@link T} that will be deleted - */ - void deleteFromNamespace(String namespaceName, String resourceName); - - /** - * Replaces {@link T} resource in Namespace specified by user, using {@link Consumer} - * from which is the current {@link T} resource updated - * - * @param namespaceName Namespace, where the resource should be replaced - * @param resourceName name of the {@link T} that will be replaced - * @param editor {@link Consumer} containing updates to the resource - */ - void replaceInNamespace(String namespaceName, String resourceName, Consumer editor); -} diff --git a/test-frame-common/src/main/java/io/skodjob/testframe/interfaces/ResourceType.java b/test-frame-common/src/main/java/io/skodjob/testframe/interfaces/ResourceType.java index ed53f85..129ca09 100644 --- a/test-frame-common/src/main/java/io/skodjob/testframe/interfaces/ResourceType.java +++ b/test-frame-common/src/main/java/io/skodjob/testframe/interfaces/ResourceType.java @@ -47,18 +47,18 @@ public interface ResourceType { /** * Deletes {@link T} resource from Namespace in current context * - * @param resourceName name of the {@link T} that will be deleted + * @param resource {@link T} resource that will be deleted */ - void delete(String resourceName); + void delete(T resource); /** * Replaces {@link T} resource using {@link Consumer} * from which is the current {@link T} resource updated * - * @param resourceName name of the {@link T} that will be replaced - * @param editor {@link Consumer} containing updates to the resource + * @param resource {@link T} resource that will be replaced + * @param editor {@link Consumer} containing updates to the resource */ - void replace(String resourceName, Consumer editor); + void replace(T resource, Consumer editor); /** * Confirms that {@link T} is ready (created/running) diff --git a/test-frame-common/src/main/java/io/skodjob/testframe/resources/KubeResourceManager.java b/test-frame-common/src/main/java/io/skodjob/testframe/resources/KubeResourceManager.java index f574d3c..66517ba 100644 --- a/test-frame-common/src/main/java/io/skodjob/testframe/resources/KubeResourceManager.java +++ b/test-frame-common/src/main/java/io/skodjob/testframe/resources/KubeResourceManager.java @@ -31,7 +31,6 @@ import io.skodjob.testframe.clients.cmdClient.KubeCmdClient; import io.skodjob.testframe.clients.cmdClient.Kubectl; import io.skodjob.testframe.clients.cmdClient.Oc; -import io.skodjob.testframe.interfaces.NamespacedResourceType; import io.skodjob.testframe.interfaces.ResourceType; import io.skodjob.testframe.wait.Wait; import org.junit.jupiter.api.extension.ExtensionContext; @@ -383,12 +382,7 @@ public final void deleteResource(T... resources) { String.format("Timed out deleting %s/%s in %s", resource.getKind(), resource.getMetadata().getName(), resource.getMetadata().getNamespace())); } else { - if (type instanceof NamespacedResourceType) { - ((NamespacedResourceType) type).deleteFromNamespace(resource.getMetadata().getNamespace(), - resource.getMetadata().getName()); - } else { - type.delete(resource.getMetadata().getName()); - } + type.delete(resource); assertTrue(waitResourceCondition(resource, ResourceCondition.deletion()), String.format("Timed out deleting %s/%s in %s", resource.getKind(), resource.getMetadata().getName(), resource.getMetadata().getNamespace())); @@ -418,12 +412,7 @@ public final void updateResource(T... resources) { LoggerUtils.logResource("Updating", resource); ResourceType type = findResourceType(resource); if (type != null) { - if (type instanceof NamespacedResourceType) { - ((NamespacedResourceType) type).updateInNamespace(resource.getMetadata().getNamespace(), - resource); - } else { - type.update(resource); - } + type.update(resource); } else { client.getClient().resource(resource).update(); } @@ -459,7 +448,7 @@ public final boolean waitResourceCondition(T resource, R if (type == null) { client.getClient().resource(resource).delete(); } else { - type.delete(res.getMetadata().getName()); + type.delete(res); } }); diff --git a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ClusterRoleBindingType.java b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ClusterRoleBindingType.java index 64e9f98..d7a178d 100644 --- a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ClusterRoleBindingType.java +++ b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ClusterRoleBindingType.java @@ -70,23 +70,23 @@ public void update(ClusterRoleBinding resource) { /** * Deletes {@link ClusterRoleBinding} resource from Namespace in current context * - * @param resourceName name of the {@link ClusterRoleBinding} that will be deleted + * @param resource {@link ClusterRoleBinding} resource that will be deleted */ @Override - public void delete(String resourceName) { - client.withName(resourceName).delete(); + public void delete(ClusterRoleBinding resource) { + client.withName(resource.getMetadata().getName()).delete(); } /** * Replaces {@link ClusterRoleBinding} resource using {@link Consumer} * from which is the current {@link ClusterRoleBinding} resource updated * - * @param resourceName name of the {@link ClusterRoleBinding} that will be replaced - * @param editor {@link Consumer} containing updates to the resource + * @param resource {@link ClusterRoleBinding} resource that will be replaced + * @param editor {@link Consumer} containing updates to the resource */ @Override - public void replace(String resourceName, Consumer editor) { - ClusterRoleBinding toBeUpdated = client.withName(resourceName).get(); + public void replace(ClusterRoleBinding resource, Consumer editor) { + ClusterRoleBinding toBeUpdated = client.withName(resource.getMetadata().getName()).get(); editor.accept(toBeUpdated); update(toBeUpdated); } diff --git a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ClusterRoleType.java b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ClusterRoleType.java index c77aed6..f05a6fa 100644 --- a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ClusterRoleType.java +++ b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ClusterRoleType.java @@ -69,23 +69,23 @@ public void update(ClusterRole resource) { /** * Deletes {@link ClusterRole} resource from Namespace in current context * - * @param resourceName name of the {@link ClusterRole} that will be deleted + * @param resource {@link ClusterRole} resource that will be deleted */ @Override - public void delete(String resourceName) { - client.withName(resourceName).delete(); + public void delete(ClusterRole resource) { + client.withName(resource.getMetadata().getName()).delete(); } /** * Replaces {@link ClusterRole} resource using {@link Consumer} * from which is the current {@link ClusterRole} resource updated * - * @param resourceName name of the {@link ClusterRole} that will be replaced - * @param editor {@link Consumer} containing updates to the resource + * @param resource {@link ClusterRole} resource that will be replaced + * @param editor {@link Consumer} containing updates to the resource */ @Override - public void replace(String resourceName, Consumer editor) { - ClusterRole toBeUpdated = client.withName(resourceName).get(); + public void replace(ClusterRole resource, Consumer editor) { + ClusterRole toBeUpdated = client.withName(resource.getMetadata().getName()).get(); editor.accept(toBeUpdated); update(toBeUpdated); } diff --git a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ConfigMapType.java b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ConfigMapType.java index aba3ee7..ab37cc6 100644 --- a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ConfigMapType.java +++ b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ConfigMapType.java @@ -10,12 +10,12 @@ import io.fabric8.kubernetes.api.model.ConfigMapList; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.Resource; -import io.skodjob.testframe.interfaces.NamespacedResourceType; +import io.skodjob.testframe.interfaces.ResourceType; /** * Implementation of ResourceType for specific kubernetes resource */ -public class ConfigMapType implements NamespacedResourceType { +public class ConfigMapType implements ResourceType { private final MixedOperation> client; /** @@ -45,54 +45,6 @@ public String getKind() { return client; } - /** - * Creates specific {@link ConfigMap} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be created - * @param resource {@link ConfigMap} resource - */ - @Override - public void createInNamespace(String namespaceName, ConfigMap resource) { - client.inNamespace(namespaceName).resource(resource).create(); - } - - /** - * Updates specific {@link ConfigMap} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be updated - * @param resource {@link ConfigMap} updated resource - */ - @Override - public void updateInNamespace(String namespaceName, ConfigMap resource) { - client.inNamespace(namespaceName).resource(resource).update(); - } - - /** - * Deletes {@link ConfigMap} resource from Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be deleted - * @param resourceName name of the {@link ConfigMap} that will be deleted - */ - @Override - public void deleteFromNamespace(String namespaceName, String resourceName) { - client.inNamespace(namespaceName).withName(resourceName).delete(); - } - - /** - * Replaces {@link ConfigMap} resource in Namespace specified by user, using {@link Consumer} - * from which is the current {@link ConfigMap} resource updated - * - * @param namespaceName Namespace, where the resource should be replaced - * @param resourceName name of the {@link ConfigMap} that will be replaced - * @param editor {@link Consumer} containing updates to the resource - */ - @Override - public void replaceInNamespace(String namespaceName, String resourceName, Consumer editor) { - ConfigMap toBeUpdated = client.inNamespace(namespaceName).withName(resourceName).get(); - editor.accept(toBeUpdated); - updateInNamespace(namespaceName, toBeUpdated); - } - /** * Creates specific {@link ConfigMap} resource * @@ -100,41 +52,42 @@ public void replaceInNamespace(String namespaceName, String resourceName, Consum */ @Override public void create(ConfigMap resource) { - client.resource(resource).create(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).create(); } /** * Updates specific {@link ConfigMap} resource * - * @param resource {@link ConfigMap} resource that will be updated + * @param resource {@link ConfigMap} updated resource */ @Override public void update(ConfigMap resource) { - client.resource(resource).update(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).update(); } /** - * Deletes {@link ConfigMap} resource from Namespace in current context + * Replaces {@link ConfigMap} resource using {@link Consumer} + * from which is the current {@link ConfigMap} resource updated * - * @param resourceName name of the {@link ConfigMap} that will be deleted + * @param resource {@link ConfigMap} replaced resource + * @param editor {@link Consumer} containing updates to the resource */ @Override - public void delete(String resourceName) { - client.withName(resourceName).delete(); + public void replace(ConfigMap resource, Consumer editor) { + ConfigMap toBeUpdated = client.inNamespace(resource.getMetadata().getNamespace()) + .withName(resource.getMetadata().getName()).get(); + editor.accept(toBeUpdated); + update(toBeUpdated); } /** - * Replaces {@link ConfigMap} resource using {@link Consumer} - * from which is the current {@link ConfigMap} resource updated + * Deletes {@link ConfigMap} resource * - * @param resourceName name of the {@link ConfigMap} that will be replaced - * @param editor {@link Consumer} containing updates to the resource + * @param resource {@link ConfigMap} deleted resource */ @Override - public void replace(String resourceName, Consumer editor) { - ConfigMap toBeUpdated = client.withName(resourceName).get(); - editor.accept(toBeUpdated); - update(toBeUpdated); + public void delete(ConfigMap resource) { + client.inNamespace(resource.getMetadata().getNamespace()).withName(resource.getMetadata().getName()).delete(); } /** diff --git a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/CustomResourceDefinitionType.java b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/CustomResourceDefinitionType.java index 516264d..d5a3350 100644 --- a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/CustomResourceDefinitionType.java +++ b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/CustomResourceDefinitionType.java @@ -70,23 +70,23 @@ public void update(CustomResourceDefinition resource) { /** * Deletes {@link CustomResourceDefinition} resource from Namespace in current context * - * @param resourceName name of the {@link CustomResourceDefinition} that will be deleted + * @param resource {@link CustomResourceDefinition} resource that will be deleted */ @Override - public void delete(String resourceName) { - client.withName(resourceName).delete(); + public void delete(CustomResourceDefinition resource) { + client.withName(resource.getMetadata().getName()).delete(); } /** * Replaces {@link CustomResourceDefinition} resource using {@link Consumer} * from which is the current {@link CustomResourceDefinition} resource updated * - * @param resourceName name of the {@link CustomResourceDefinition} that will be replaced + * @param resource {@link CustomResourceDefinition} resource that will be replaced * @param editor {@link Consumer} containing updates to the resource */ @Override - public void replace(String resourceName, Consumer editor) { - CustomResourceDefinition toBeUpdated = client.withName(resourceName).get(); + public void replace(CustomResourceDefinition resource, Consumer editor) { + CustomResourceDefinition toBeUpdated = client.withName(resource.getMetadata().getName()).get(); editor.accept(toBeUpdated); update(toBeUpdated); } diff --git a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/DeploymentType.java b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/DeploymentType.java index 9484dcf..85653c2 100644 --- a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/DeploymentType.java +++ b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/DeploymentType.java @@ -10,12 +10,12 @@ import io.fabric8.kubernetes.api.model.apps.DeploymentList; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.RollableScalableResource; -import io.skodjob.testframe.interfaces.NamespacedResourceType; +import io.skodjob.testframe.interfaces.ResourceType; /** * Implementation of ResourceType for specific kubernetes resource */ -public class DeploymentType implements NamespacedResourceType { +public class DeploymentType implements ResourceType { private final MixedOperation> client; @@ -53,7 +53,7 @@ public String getKind() { */ @Override public void create(Deployment resource) { - client.resource(resource).create(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).create(); } /** @@ -63,29 +63,30 @@ public void create(Deployment resource) { */ @Override public void update(Deployment resource) { - client.resource(resource).update(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).update(); } /** * Deletes {@link Deployment} resource from Namespace in current context * - * @param resourceName name of the {@link Deployment} that will be deleted + * @param resource {@link Deployment} resource that will be deleted */ @Override - public void delete(String resourceName) { - client.withName(resourceName).delete(); + public void delete(Deployment resource) { + client.inNamespace(resource.getMetadata().getNamespace()).withName(resource.getMetadata().getName()).delete(); } /** * Replaces {@link Deployment} resource using {@link Consumer} * from which is the current {@link Deployment} resource updated * - * @param resourceName name of the {@link Deployment} that will be replaced - * @param editor {@link Consumer} containing updates to the resource + * @param resource {@link Deployment} resource that will be replaced + * @param editor {@link Consumer} containing updates to the resource */ @Override - public void replace(String resourceName, Consumer editor) { - Deployment toBeUpdated = client.withName(resourceName).get(); + public void replace(Deployment resource, Consumer editor) { + Deployment toBeUpdated = client.inNamespace(resource.getMetadata().getNamespace()) + .withName(resource.getMetadata().getName()).get(); editor.accept(toBeUpdated); update(toBeUpdated); } @@ -111,52 +112,4 @@ public boolean isReady(Deployment resource) { public boolean isDeleted(Deployment resource) { return resource == null; } - - /** - * Creates specific {@link Deployment} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be created - * @param resource {@link Deployment} resource - */ - @Override - public void createInNamespace(String namespaceName, Deployment resource) { - client.inNamespace(namespaceName).resource(resource).create(); - } - - /** - * Updates specific {@link Deployment} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be updated - * @param resource {@link Deployment} updated resource - */ - @Override - public void updateInNamespace(String namespaceName, Deployment resource) { - client.inNamespace(namespaceName).resource(resource).update(); - } - - /** - * Deletes {@link Deployment} resource from Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be deleted - * @param resourceName name of the {@link Deployment} that will be deleted - */ - @Override - public void deleteFromNamespace(String namespaceName, String resourceName) { - client.inNamespace(namespaceName).withName(resourceName).delete(); - } - - /** - * Replaces {@link Deployment} resource in Namespace specified by user, using {@link Consumer} - * from which is the current {@link Deployment} resource updated - * - * @param namespaceName Namespace, where the resource should be replaced - * @param resourceName name of the {@link Deployment} that will be replaced - * @param editor {@link Consumer} containing updates to the resource - */ - @Override - public void replaceInNamespace(String namespaceName, String resourceName, Consumer editor) { - Deployment toBeUpdated = client.inNamespace(namespaceName).withName(resourceName).get(); - editor.accept(toBeUpdated); - updateInNamespace(namespaceName, toBeUpdated); - } } diff --git a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/JobType.java b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/JobType.java index 30db1f9..1ea35ef 100644 --- a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/JobType.java +++ b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/JobType.java @@ -10,12 +10,12 @@ import io.fabric8.kubernetes.api.model.batch.v1.JobList; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.ScalableResource; -import io.skodjob.testframe.interfaces.NamespacedResourceType; +import io.skodjob.testframe.interfaces.ResourceType; /** * Implementation of ResourceType for specific kubernetes resource */ -public class JobType implements NamespacedResourceType { +public class JobType implements ResourceType { private final MixedOperation> client; @@ -46,54 +46,6 @@ public String getKind() { return client; } - /** - * Creates specific {@link Job} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be created - * @param resource {@link Job} resource - */ - @Override - public void createInNamespace(String namespaceName, Job resource) { - client.inNamespace(namespaceName).resource(resource).create(); - } - - /** - * Updates specific {@link Job} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be updated - * @param resource {@link Job} updated resource - */ - @Override - public void updateInNamespace(String namespaceName, Job resource) { - client.inNamespace(namespaceName).resource(resource).update(); - } - - /** - * Deletes {@link Job} resource from Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be deleted - * @param resourceName name of the {@link Job} that will be deleted - */ - @Override - public void deleteFromNamespace(String namespaceName, String resourceName) { - client.inNamespace(namespaceName).withName(resourceName).delete(); - } - - /** - * Replaces {@link Job} resource in Namespace specified by user, using {@link Consumer} - * from which is the current {@link Job} resource updated - * - * @param namespaceName Namespace, where the resource should be replaced - * @param resourceName name of the {@link Job} that will be replaced - * @param editor {@link Consumer} containing updates to the resource - */ - @Override - public void replaceInNamespace(String namespaceName, String resourceName, Consumer editor) { - Job toBeUpdated = client.inNamespace(namespaceName).withName(resourceName).get(); - editor.accept(toBeUpdated); - updateInNamespace(namespaceName, toBeUpdated); - } - /** * Creates specific {@link Job} resource * @@ -101,7 +53,7 @@ public void replaceInNamespace(String namespaceName, String resourceName, Consum */ @Override public void create(Job resource) { - client.resource(resource).create(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).create(); } /** @@ -111,29 +63,30 @@ public void create(Job resource) { */ @Override public void update(Job resource) { - client.resource(resource).update(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).update(); } /** * Deletes {@link Job} resource from Namespace in current context * - * @param resourceName name of the {@link Job} that will be deleted + * @param resource {@link Job} resource that will be deleted */ @Override - public void delete(String resourceName) { - client.withName(resourceName).delete(); + public void delete(Job resource) { + client.inNamespace(resource.getMetadata().getNamespace()).withName(resource.getMetadata().getName()).delete(); } /** * Replaces {@link Job} resource using {@link Consumer} * from which is the current {@link Job} resource updated * - * @param resourceName name of the {@link Job} that will be replaced - * @param editor {@link Consumer} containing updates to the resource + * @param resource {@link Job} resource that will be replaced + * @param editor {@link Consumer} containing updates to the resource */ @Override - public void replace(String resourceName, Consumer editor) { - Job toBeUpdated = client.withName(resourceName).get(); + public void replace(Job resource, Consumer editor) { + Job toBeUpdated = client.inNamespace(resource.getMetadata().getNamespace()) + .withName(resource.getMetadata().getName()).get(); editor.accept(toBeUpdated); update(toBeUpdated); } diff --git a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/LeaseType.java b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/LeaseType.java index 0d2c70c..6f4c950 100644 --- a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/LeaseType.java +++ b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/LeaseType.java @@ -10,12 +10,12 @@ import io.fabric8.kubernetes.api.model.coordination.v1.LeaseList; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.Resource; -import io.skodjob.testframe.interfaces.NamespacedResourceType; +import io.skodjob.testframe.interfaces.ResourceType; /** * Implementation of ResourceType for specific kubernetes resource */ -public class LeaseType implements NamespacedResourceType { +public class LeaseType implements ResourceType { private MixedOperation> client; @@ -53,7 +53,7 @@ public String getKind() { */ @Override public void create(Lease resource) { - client.resource(resource).create(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).create(); } /** @@ -63,29 +63,30 @@ public void create(Lease resource) { */ @Override public void update(Lease resource) { - client.resource(resource).update(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).update(); } /** * Deletes {@link Lease} resource from Namespace in current context * - * @param resourceName name of the {@link Lease} that will be deleted + * @param resource {@link Lease} resource that will be deleted */ @Override - public void delete(String resourceName) { - client.withName(resourceName).delete(); + public void delete(Lease resource) { + client.inNamespace(resource.getMetadata().getNamespace()).withName(resource.getMetadata().getName()).delete(); } /** * Replaces {@link Lease} resource using {@link Consumer} * from which is the current {@link Lease} resource updated * - * @param resourceName name of the {@link Lease} that will be replaced - * @param editor {@link Consumer} containing updates to the resource + * @param resource {@link Lease} resource that will be replaced + * @param editor {@link Consumer} containing updates to the resource */ @Override - public void replace(String resourceName, Consumer editor) { - Lease toBeUpdated = client.withName(resourceName).get(); + public void replace(Lease resource, Consumer editor) { + Lease toBeUpdated = client.inNamespace(resource.getMetadata().getNamespace()) + .withName(resource.getMetadata().getName()).get(); editor.accept(toBeUpdated); update(toBeUpdated); } @@ -111,52 +112,4 @@ public boolean isReady(Lease resource) { public boolean isDeleted(Lease resource) { return resource == null; } - - /** - * Creates specific {@link Lease} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be created - * @param resource {@link Lease} resource - */ - @Override - public void createInNamespace(String namespaceName, Lease resource) { - client.inNamespace(namespaceName).resource(resource).create(); - } - - /** - * Updates specific {@link Lease} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be updated - * @param resource {@link Lease} updated resource - */ - @Override - public void updateInNamespace(String namespaceName, Lease resource) { - client.inNamespace(namespaceName).resource(resource).update(); - } - - /** - * Deletes {@link Lease} resource from Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be deleted - * @param resourceName name of the {@link Lease} that will be deleted - */ - @Override - public void deleteFromNamespace(String namespaceName, String resourceName) { - client.inNamespace(namespaceName).withName(resourceName).delete(); - } - - /** - * Replaces {@link Lease} resource in Namespace specified by user, using {@link Consumer} - * from which is the current {@link Lease} resource updated - * - * @param namespaceName Namespace, where the resource should be replaced - * @param resourceName name of the {@link Lease} that will be replaced - * @param editor {@link Consumer} containing updates to the resource - */ - @Override - public void replaceInNamespace(String namespaceName, String resourceName, Consumer editor) { - Lease toBeReplaced = client.inNamespace(namespaceName).withName(resourceName).get(); - editor.accept(toBeReplaced); - updateInNamespace(namespaceName, toBeReplaced); - } } diff --git a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/NamespaceType.java b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/NamespaceType.java index 352e4d5..2fc19bb 100644 --- a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/NamespaceType.java +++ b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/NamespaceType.java @@ -85,23 +85,23 @@ public void update(Namespace resource) { /** * Deletes {@link Namespace} resource from Namespace in current context * - * @param resourceName name of the {@link Namespace} that will be deleted + * @param resource {@link Namespace} resource that will be deleted */ @Override - public void delete(String resourceName) { - client.withName(resourceName).delete(); + public void delete(Namespace resource) { + client.withName(resource.getMetadata().getName()).delete(); } /** * Replaces {@link Namespace} resource using {@link Consumer} * from which is the current {@link Namespace} resource updated * - * @param resourceName name of the {@link Namespace} that will be replaced - * @param editor {@link Consumer} containing updates to the resource + * @param resource {@link Namespace} resource that will be replaced + * @param editor {@link Consumer} containing updates to the resource */ @Override - public void replace(String resourceName, Consumer editor) { - Namespace toBeUpdated = client.withName(resourceName).get(); + public void replace(Namespace resource, Consumer editor) { + Namespace toBeUpdated = client.withName(resource.getMetadata().getName()).get(); editor.accept(toBeUpdated); update(toBeUpdated); } diff --git a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/NetworkPolicyType.java b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/NetworkPolicyType.java index 1fbd7bf..52ce85c 100644 --- a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/NetworkPolicyType.java +++ b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/NetworkPolicyType.java @@ -10,12 +10,12 @@ import io.fabric8.kubernetes.api.model.networking.v1.NetworkPolicyList; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.Resource; -import io.skodjob.testframe.interfaces.NamespacedResourceType; +import io.skodjob.testframe.interfaces.ResourceType; /** * Implementation of ResourceType for specific kubernetes resource */ -public class NetworkPolicyType implements NamespacedResourceType { +public class NetworkPolicyType implements ResourceType { private final MixedOperation> client; @@ -53,7 +53,7 @@ public String getKind() { */ @Override public void create(NetworkPolicy resource) { - client.resource(resource).create(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).create(); } /** @@ -63,29 +63,30 @@ public void create(NetworkPolicy resource) { */ @Override public void update(NetworkPolicy resource) { - client.resource(resource).update(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).update(); } /** * Deletes {@link NetworkPolicy} resource from Namespace in current context * - * @param resourceName name of the {@link NetworkPolicy} that will be deleted + * @param resource {@link NetworkPolicy} resource that will be deleted */ @Override - public void delete(String resourceName) { - client.withName(resourceName).delete(); + public void delete(NetworkPolicy resource) { + client.inNamespace(resource.getMetadata().getNamespace()).withName(resource.getMetadata().getName()).delete(); } /** * Replaces {@link NetworkPolicy} resource using {@link Consumer} * from which is the current {@link NetworkPolicy} resource updated * - * @param resourceName name of the {@link NetworkPolicy} that will be replaced - * @param editor {@link Consumer} containing updates to the resource + * @param resource {@link NetworkPolicy} resource that will be replaced + * @param editor {@link Consumer} containing updates to the resource */ @Override - public void replace(String resourceName, Consumer editor) { - NetworkPolicy toBeUpdated = client.withName(resourceName).get(); + public void replace(NetworkPolicy resource, Consumer editor) { + NetworkPolicy toBeUpdated = client.inNamespace(resource.getMetadata().getNamespace()) + .withName(resource.getMetadata().getName()).get(); editor.accept(toBeUpdated); update(toBeUpdated); } @@ -111,52 +112,4 @@ public boolean isReady(NetworkPolicy resource) { public boolean isDeleted(NetworkPolicy resource) { return resource == null; } - - /** - * Creates specific {@link NetworkPolicy} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be created - * @param resource {@link NetworkPolicy} resource - */ - @Override - public void createInNamespace(String namespaceName, NetworkPolicy resource) { - client.inNamespace(namespaceName).resource(resource).create(); - } - - /** - * Updates specific {@link NetworkPolicy} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be updated - * @param resource {@link NetworkPolicy} updated resource - */ - @Override - public void updateInNamespace(String namespaceName, NetworkPolicy resource) { - client.inNamespace(namespaceName).resource(resource).update(); - } - - /** - * Deletes {@link NetworkPolicy} resource from Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be deleted - * @param resourceName name of the {@link NetworkPolicy} that will be deleted - */ - @Override - public void deleteFromNamespace(String namespaceName, String resourceName) { - client.inNamespace(namespaceName).withName(resourceName).delete(); - } - - /** - * Replaces {@link NetworkPolicy} resource in Namespace specified by user, using {@link Consumer} - * from which is the current {@link NetworkPolicy} resource updated - * - * @param namespaceName Namespace, where the resource should be replaced - * @param resourceName name of the {@link NetworkPolicy} that will be replaced - * @param editor {@link Consumer} containing updates to the resource - */ - @Override - public void replaceInNamespace(String namespaceName, String resourceName, Consumer editor) { - NetworkPolicy toBeReplaced = client.inNamespace(namespaceName).withName(resourceName).get(); - editor.accept(toBeReplaced); - updateInNamespace(namespaceName, toBeReplaced); - } } diff --git a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/RoleBindingType.java b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/RoleBindingType.java index 42e4b76..d0ed64e 100644 --- a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/RoleBindingType.java +++ b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/RoleBindingType.java @@ -10,12 +10,12 @@ import io.fabric8.kubernetes.api.model.rbac.RoleBindingList; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.Resource; -import io.skodjob.testframe.interfaces.NamespacedResourceType; +import io.skodjob.testframe.interfaces.ResourceType; /** * Implementation of ResourceType for specific kubernetes resource */ -public class RoleBindingType implements NamespacedResourceType { +public class RoleBindingType implements ResourceType { private final MixedOperation> client; @@ -53,7 +53,7 @@ public String getKind() { */ @Override public void create(RoleBinding resource) { - client.resource(resource).create(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).create(); } /** @@ -63,29 +63,30 @@ public void create(RoleBinding resource) { */ @Override public void update(RoleBinding resource) { - client.resource(resource).update(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).update(); } /** * Deletes {@link RoleBinding} resource from Namespace in current context * - * @param resourceName name of the {@link RoleBinding} that will be deleted + * @param resource {@link RoleBinding} resource that will be deleted */ @Override - public void delete(String resourceName) { - client.withName(resourceName).delete(); + public void delete(RoleBinding resource) { + client.inNamespace(resource.getMetadata().getNamespace()).withName(resource.getMetadata().getName()).delete(); } /** * Replaces {@link RoleBinding} resource using {@link Consumer} * from which is the current {@link RoleBinding} resource updated * - * @param resourceName name of the {@link RoleBinding} that will be replaced - * @param editor {@link Consumer} containing updates to the resource + * @param resource {@link RoleBinding} resource that will be replaced + * @param editor {@link Consumer} containing updates to the resource */ @Override - public void replace(String resourceName, Consumer editor) { - RoleBinding toBeUpdated = client.withName(resourceName).get(); + public void replace(RoleBinding resource, Consumer editor) { + RoleBinding toBeUpdated = client.inNamespace(resource.getMetadata().getNamespace()) + .withName(resource.getMetadata().getName()).get(); editor.accept(toBeUpdated); update(toBeUpdated); } @@ -111,52 +112,4 @@ public boolean isReady(RoleBinding resource) { public boolean isDeleted(RoleBinding resource) { return resource == null; } - - /** - * Creates specific {@link RoleBinding} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be created - * @param resource {@link RoleBinding} resource - */ - @Override - public void createInNamespace(String namespaceName, RoleBinding resource) { - client.inNamespace(namespaceName).resource(resource).create(); - } - - /** - * Updates specific {@link RoleBinding} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be updated - * @param resource {@link RoleBinding} updated resource - */ - @Override - public void updateInNamespace(String namespaceName, RoleBinding resource) { - client.inNamespace(namespaceName).resource(resource).update(); - } - - /** - * Deletes {@link RoleBinding} resource from Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be deleted - * @param resourceName name of the {@link RoleBinding} that will be deleted - */ - @Override - public void deleteFromNamespace(String namespaceName, String resourceName) { - client.inNamespace(namespaceName).withName(resourceName).delete(); - } - - /** - * Replaces {@link RoleBinding} resource in Namespace specified by user, using {@link Consumer} - * from which is the current {@link RoleBinding} resource updated - * - * @param namespaceName Namespace, where the resource should be replaced - * @param resourceName name of the {@link RoleBinding} that will be replaced - * @param editor {@link Consumer} containing updates to the resource - */ - @Override - public void replaceInNamespace(String namespaceName, String resourceName, Consumer editor) { - RoleBinding toBeReplaced = client.inNamespace(namespaceName).withName(resourceName).get(); - editor.accept(toBeReplaced); - updateInNamespace(namespaceName, toBeReplaced); - } } diff --git a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/RoleType.java b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/RoleType.java index ed108ff..589cdb6 100644 --- a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/RoleType.java +++ b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/RoleType.java @@ -10,12 +10,12 @@ import io.fabric8.kubernetes.api.model.rbac.RoleList; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.Resource; -import io.skodjob.testframe.interfaces.NamespacedResourceType; +import io.skodjob.testframe.interfaces.ResourceType; /** * Implementation of ResourceType for specific kubernetes resource */ -public class RoleType implements NamespacedResourceType { +public class RoleType implements ResourceType { private final MixedOperation> client; @@ -43,7 +43,7 @@ public String getKind() { */ @Override public void create(Role resource) { - client.resource(resource).create(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).create(); } /** @@ -63,29 +63,30 @@ public void create(Role resource) { */ @Override public void update(Role resource) { - client.resource(resource).update(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).update(); } /** * Deletes {@link Role} resource from Namespace in current context * - * @param resourceName name of the {@link Role} that will be deleted + * @param resource {@link Role} resource that will be deleted */ @Override - public void delete(String resourceName) { - client.withName(resourceName).delete(); + public void delete(Role resource) { + client.inNamespace(resource.getMetadata().getNamespace()).withName(resource.getMetadata().getName()).delete(); } /** * Replaces {@link Role} resource using {@link Consumer} * from which is the current {@link Role} resource updated * - * @param resourceName name of the {@link Role} that will be replaced - * @param editor {@link Consumer} containing updates to the resource + * @param resource {@link Role} resource that will be replaced + * @param editor {@link Consumer} containing updates to the resource */ @Override - public void replace(String resourceName, Consumer editor) { - Role toBeUpdated = client.withName(resourceName).get(); + public void replace(Role resource, Consumer editor) { + Role toBeUpdated = client.inNamespace(resource.getMetadata().getNamespace()) + .withName(resource.getMetadata().getName()).get(); editor.accept(toBeUpdated); update(toBeUpdated); } @@ -111,52 +112,4 @@ public boolean isReady(Role resource) { public boolean isDeleted(Role resource) { return resource == null; } - - /** - * Creates specific {@link Role} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be created - * @param resource {@link Role} resource - */ - @Override - public void createInNamespace(String namespaceName, Role resource) { - client.inNamespace(namespaceName).resource(resource).create(); - } - - /** - * Updates specific {@link Role} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be updated - * @param resource {@link Role} updated resource - */ - @Override - public void updateInNamespace(String namespaceName, Role resource) { - client.inNamespace(namespaceName).resource(resource).update(); - } - - /** - * Deletes {@link Role} resource from Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be deleted - * @param resourceName name of the {@link Role} that will be deleted - */ - @Override - public void deleteFromNamespace(String namespaceName, String resourceName) { - client.inNamespace(namespaceName).withName(resourceName).delete(); - } - - /** - * Replaces {@link Role} resource in Namespace specified by user, using {@link Consumer} - * from which is the current {@link Role} resource updated - * - * @param namespaceName Namespace, where the resource should be replaced - * @param resourceName name of the {@link Role} that will be replaced - * @param editor {@link Consumer} containing updates to the resource - */ - @Override - public void replaceInNamespace(String namespaceName, String resourceName, Consumer editor) { - Role toBeReplaced = client.inNamespace(namespaceName).withName(resourceName).get(); - editor.accept(toBeReplaced); - updateInNamespace(namespaceName, toBeReplaced); - } } diff --git a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/SecretType.java b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/SecretType.java index c7fff03..cc8da5f 100644 --- a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/SecretType.java +++ b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/SecretType.java @@ -10,12 +10,12 @@ import io.fabric8.kubernetes.api.model.SecretList; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.Resource; -import io.skodjob.testframe.interfaces.NamespacedResourceType; +import io.skodjob.testframe.interfaces.ResourceType; /** * Implementation of ResourceType for specific kubernetes resource */ -public class SecretType implements NamespacedResourceType { +public class SecretType implements ResourceType { private final MixedOperation> client; @@ -43,7 +43,7 @@ public String getKind() { */ @Override public void create(Secret resource) { - client.resource(resource).create(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).create(); } /** @@ -56,17 +56,6 @@ public void create(Secret resource) { return client; } - /** - * Creates specific {@link Secret} resource in specified namespace - * - * @param namespaceName name of Namespace, where the {@link Secret} should be created - * @param resource {@link Secret} resource - */ - @Override - public void createInNamespace(String namespaceName, Secret resource) { - client.inNamespace(namespaceName).resource(resource).create(); - } - /** * Updates specific {@link Secret} resource * @@ -74,37 +63,27 @@ public void createInNamespace(String namespaceName, Secret resource) { */ @Override public void update(Secret resource) { - client.resource(resource).update(); - } - - /** - * Updates specific {@link Secret} resource in specified Namespace - * - * @param namespaceName name of Namespace, where the {@link Secret} should be updated - * @param resource {@link Secret} resource that will be updated - */ - @Override - public void updateInNamespace(String namespaceName, Secret resource) { - client.inNamespace(namespaceName).resource(resource).update(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).update(); } /** * Deletes {@link Secret} resource from Namespace in current context * - * @param resourceName name of the {@link Secret} that will be deleted + * @param resource {@link Secret} resource that will be deleted */ @Override - public void delete(String resourceName) { - client.withName(resourceName).delete(); + public void delete(Secret resource) { + client.inNamespace(resource.getMetadata().getNamespace()).withName(resource.getMetadata().getName()).delete(); } /** - * @param resourceName name - * @param editor modifier + * @param resource name + * @param editor modifier */ @Override - public void replace(String resourceName, Consumer editor) { - Secret toBeReplaced = client.withName(resourceName).get(); + public void replace(Secret resource, Consumer editor) { + Secret toBeReplaced = client.inNamespace(resource.getMetadata().getNamespace()) + .withName(resource.getMetadata().getName()).get(); editor.accept(toBeReplaced); update(toBeReplaced); } @@ -130,27 +109,4 @@ public boolean isReady(Secret resource) { public boolean isDeleted(Secret resource) { return false; } - - /** - * Deletes {@link Secret} resource from specified Namespace - * - * @param namespaceName name of Namespace, from where the {@link Secret} will be deleted - * @param resourceName name of the {@link Secret} resource - */ - @Override - public void deleteFromNamespace(String namespaceName, String resourceName) { - client.inNamespace(namespaceName).withName(resourceName).delete(); - } - - /** - * @param namespaceName namespace - * @param resourceName resource - * @param editor modifier - */ - @Override - public void replaceInNamespace(String namespaceName, String resourceName, Consumer editor) { - Secret toBeReplaced = client.inNamespace(namespaceName).withName(resourceName).get(); - editor.accept(toBeReplaced); - updateInNamespace(namespaceName, toBeReplaced); - } } diff --git a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ServiceAccountType.java b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ServiceAccountType.java index 85134ce..f88b1ac 100644 --- a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ServiceAccountType.java +++ b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ServiceAccountType.java @@ -10,12 +10,12 @@ import io.fabric8.kubernetes.api.model.ServiceAccountList; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.ServiceAccountResource; -import io.skodjob.testframe.interfaces.NamespacedResourceType; +import io.skodjob.testframe.interfaces.ResourceType; /** * Implementation of ResourceType for specific kubernetes resource */ -public class ServiceAccountType implements NamespacedResourceType { +public class ServiceAccountType implements ResourceType { private final MixedOperation client; @@ -43,7 +43,7 @@ public String getKind() { */ @Override public void create(ServiceAccount resource) { - client.resource(resource).create(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).create(); } /** @@ -63,29 +63,30 @@ public void create(ServiceAccount resource) { */ @Override public void update(ServiceAccount resource) { - client.resource(resource).update(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).update(); } /** * Deletes {@link ServiceAccount} resource from Namespace in current context * - * @param resourceName name of the {@link ServiceAccount} that will be deleted + * @param resource {@link ServiceAccount} resource that will be deleted */ @Override - public void delete(String resourceName) { - client.withName(resourceName).delete(); + public void delete(ServiceAccount resource) { + client.inNamespace(resource.getMetadata().getNamespace()).withName(resource.getMetadata().getName()).delete(); } /** * Replaces {@link ServiceAccount} resource using {@link Consumer} * from which is the current {@link ServiceAccount} resource updated * - * @param resourceName name of the {@link ServiceAccount} that will be replaced - * @param editor {@link Consumer} containing updates to the resource + * @param resource {@link ServiceAccount} resource that will be replaced + * @param editor {@link Consumer} containing updates to the resource */ @Override - public void replace(String resourceName, Consumer editor) { - ServiceAccount toBeReplaced = client.withName(resourceName).get(); + public void replace(ServiceAccount resource, Consumer editor) { + ServiceAccount toBeReplaced = client.inNamespace(resource.getMetadata().getNamespace()) + .withName(resource.getMetadata().getName()).get(); editor.accept(toBeReplaced); update(toBeReplaced); } @@ -111,52 +112,4 @@ public boolean isReady(ServiceAccount resource) { public boolean isDeleted(ServiceAccount resource) { return resource == null; } - - /** - * Creates specific {@link ServiceAccount} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be created - * @param resource {@link ServiceAccount} resource - */ - @Override - public void createInNamespace(String namespaceName, ServiceAccount resource) { - client.inNamespace(namespaceName).resource(resource).create(); - } - - /** - * Updates specific {@link ServiceAccount} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be updated - * @param resource {@link ServiceAccount} updated resource - */ - @Override - public void updateInNamespace(String namespaceName, ServiceAccount resource) { - client.inNamespace(namespaceName).resource(resource).update(); - } - - /** - * Deletes {@link ServiceAccount} resource from Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be deleted - * @param resourceName name of the {@link ServiceAccount} that will be deleted - */ - @Override - public void deleteFromNamespace(String namespaceName, String resourceName) { - client.inNamespace(namespaceName).withName(resourceName).delete(); - } - - /** - * Replaces {@link ServiceAccount} resource in Namespace specified by user, using {@link Consumer} - * from which is the current {@link ServiceAccount} resource updated - * - * @param namespaceName Namespace, where the resource should be replaced - * @param resourceName name of the {@link ServiceAccount} that will be replaced - * @param editor {@link Consumer} containing updates to the resource - */ - @Override - public void replaceInNamespace(String namespaceName, String resourceName, Consumer editor) { - ServiceAccount toBeReplaced = client.inNamespace(namespaceName).withName(resourceName).get(); - editor.accept(toBeReplaced); - updateInNamespace(namespaceName, toBeReplaced); - } } diff --git a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ServiceType.java b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ServiceType.java index 116815a..4fa5aa1 100644 --- a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ServiceType.java +++ b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ServiceType.java @@ -10,12 +10,12 @@ import io.fabric8.kubernetes.api.model.ServiceList; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.ServiceResource; -import io.skodjob.testframe.interfaces.NamespacedResourceType; +import io.skodjob.testframe.interfaces.ResourceType; /** * Implementation of ResourceType for specific kubernetes resource */ -public class ServiceType implements NamespacedResourceType { +public class ServiceType implements ResourceType { private final MixedOperation> client; @@ -43,7 +43,7 @@ public String getKind() { */ @Override public void create(Service resource) { - client.resource(resource).create(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).create(); } /** @@ -63,29 +63,30 @@ public void create(Service resource) { */ @Override public void update(Service resource) { - client.resource(resource).update(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).update(); } /** * Deletes {@link Service} resource from Namespace in current context * - * @param resourceName name of the {@link Service} that will be deleted + * @param resource {@link Service} resource that will be deleted */ @Override - public void delete(String resourceName) { - client.withName(resourceName).delete(); + public void delete(Service resource) { + client.inNamespace(resource.getMetadata().getNamespace()).withName(resource.getMetadata().getName()).delete(); } /** * Replaces {@link Service} resource using {@link Consumer} * from which is the current {@link Service} resource updated * - * @param resourceName name of the {@link Service} that will be replaced - * @param editor {@link Consumer} containing updates to the resource + * @param resource {@link Service} resource that will be replaced + * @param editor {@link Consumer} containing updates to the resource */ @Override - public void replace(String resourceName, Consumer editor) { - Service toBeReplaced = client.withName(resourceName).get(); + public void replace(Service resource, Consumer editor) { + Service toBeReplaced = client.inNamespace(resource.getMetadata().getNamespace()) + .withName(resource.getMetadata().getName()).get(); editor.accept(toBeReplaced); update(toBeReplaced); } @@ -111,52 +112,4 @@ public boolean isReady(Service resource) { public boolean isDeleted(Service resource) { return resource == null; } - - /** - * Creates specific {@link Service} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be created - * @param resource {@link Service} resource - */ - @Override - public void createInNamespace(String namespaceName, Service resource) { - client.inNamespace(namespaceName).resource(resource).create(); - } - - /** - * Updates specific {@link Service} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be updated - * @param resource {@link Service} updated resource - */ - @Override - public void updateInNamespace(String namespaceName, Service resource) { - client.inNamespace(namespaceName).resource(resource).update(); - } - - /** - * Deletes {@link Service} resource from Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be deleted - * @param resourceName name of the {@link Service} that will be deleted - */ - @Override - public void deleteFromNamespace(String namespaceName, String resourceName) { - client.inNamespace(namespaceName).withName(resourceName).delete(); - } - - /** - * Replaces {@link Service} resource in Namespace specified by user, using {@link Consumer} - * from which is the current {@link Service} resource updated - * - * @param namespaceName Namespace, where the resource should be replaced - * @param resourceName name of the {@link Service} that will be replaced - * @param editor {@link Consumer} containing updates to the resource - */ - @Override - public void replaceInNamespace(String namespaceName, String resourceName, Consumer editor) { - Service toBeReplaced = client.inNamespace(namespaceName).withName(resourceName).get(); - editor.accept(toBeReplaced); - updateInNamespace(namespaceName, toBeReplaced); - } } diff --git a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ValidatingWebhookConfigurationType.java b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ValidatingWebhookConfigurationType.java index b16001b..2591d57 100644 --- a/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ValidatingWebhookConfigurationType.java +++ b/test-frame-kubernetes/src/main/java/io/skodjob/testframe/resources/ValidatingWebhookConfigurationType.java @@ -74,23 +74,23 @@ public void update(ValidatingWebhookConfiguration resource) { /** * Deletes {@link ValidatingWebhookConfiguration} resource from Namespace in current context * - * @param resourceName name of the {@link ValidatingWebhookConfiguration} that will be deleted + * @param resource {@link ValidatingWebhookConfiguration} resource that will be deleted */ @Override - public void delete(String resourceName) { - client.withName(resourceName).delete(); + public void delete(ValidatingWebhookConfiguration resource) { + client.withName(resource.getMetadata().getName()).delete(); } /** * Replaces {@link ValidatingWebhookConfiguration} resource using {@link Consumer} * from which is the current {@link ValidatingWebhookConfiguration} resource updated * - * @param resourceName name of the {@link ValidatingWebhookConfiguration} that will be replaced - * @param editor {@link Consumer} containing updates to the resource + * @param resource {@link ValidatingWebhookConfiguration} resource that will be replaced + * @param editor {@link Consumer} containing updates to the resource */ @Override - public void replace(String resourceName, Consumer editor) { - ValidatingWebhookConfiguration toBeReplaced = client.withName(resourceName).get(); + public void replace(ValidatingWebhookConfiguration resource, Consumer editor) { + ValidatingWebhookConfiguration toBeReplaced = client.withName(resource.getMetadata().getName()).get(); editor.accept(toBeReplaced); update(toBeReplaced); } diff --git a/test-frame-openshift/src/main/java/io/skodjob/testframe/resources/InstallPlanType.java b/test-frame-openshift/src/main/java/io/skodjob/testframe/resources/InstallPlanType.java index 395b39d..2038f07 100644 --- a/test-frame-openshift/src/main/java/io/skodjob/testframe/resources/InstallPlanType.java +++ b/test-frame-openshift/src/main/java/io/skodjob/testframe/resources/InstallPlanType.java @@ -8,14 +8,14 @@ import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.openshift.api.model.operatorhub.v1alpha1.InstallPlan; import io.fabric8.openshift.api.model.operatorhub.v1alpha1.InstallPlanList; -import io.skodjob.testframe.interfaces.NamespacedResourceType; +import io.skodjob.testframe.interfaces.ResourceType; import java.util.function.Consumer; /** * Implementation of ResourceType for specific kubernetes resource */ -public class InstallPlanType implements NamespacedResourceType { +public class InstallPlanType implements ResourceType { private final MixedOperation> client; @@ -53,7 +53,7 @@ public String getKind() { */ @Override public void create(InstallPlan resource) { - client.resource(resource).create(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).create(); } /** @@ -63,29 +63,30 @@ public void create(InstallPlan resource) { */ @Override public void update(InstallPlan resource) { - client.resource(resource).update(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).update(); } /** * Deletes {@link InstallPlan} resource from Namespace in current context * - * @param resourceName name of the {@link InstallPlan} that will be deleted + * @param resource {@link InstallPlan} resource that will be deleted */ @Override - public void delete(String resourceName) { - client.withName(resourceName).delete(); + public void delete(InstallPlan resource) { + client.inNamespace(resource.getMetadata().getNamespace()).withName(resource.getMetadata().getName()).delete(); } /** * Replaces {@link InstallPlan} resource using {@link Consumer} * from which is the current {@link InstallPlan} resource updated * - * @param resourceName name of the {@link InstallPlan} that will be replaced + * @param resource {@link InstallPlan} resource that will be replaced * @param editor {@link Consumer} containing updates to the resource */ @Override - public void replace(String resourceName, Consumer editor) { - InstallPlan toBeReplaced = client.withName(resourceName).get(); + public void replace(InstallPlan resource, Consumer editor) { + InstallPlan toBeReplaced = client.inNamespace(resource.getMetadata().getNamespace()) + .withName(resource.getMetadata().getName()).get(); editor.accept(toBeReplaced); update(toBeReplaced); } @@ -111,52 +112,4 @@ public boolean isReady(InstallPlan resource) { public boolean isDeleted(InstallPlan resource) { return resource == null; } - - /** - * Creates specific {@link InstallPlan} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be created - * @param resource {@link InstallPlan} resource - */ - @Override - public void createInNamespace(String namespaceName, InstallPlan resource) { - client.inNamespace(namespaceName).resource(resource).create(); - } - - /** - * Updates specific {@link InstallPlan} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be updated - * @param resource {@link InstallPlan} updated resource - */ - @Override - public void updateInNamespace(String namespaceName, InstallPlan resource) { - client.inNamespace(namespaceName).resource(resource).update(); - } - - /** - * Deletes {@link InstallPlan} resource from Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be deleted - * @param resourceName name of the {@link InstallPlan} that will be deleted - */ - @Override - public void deleteFromNamespace(String namespaceName, String resourceName) { - client.inNamespace(namespaceName).withName(resourceName).delete(); - } - - /** - * Replaces {@link InstallPlan} resource in Namespace specified by user, using {@link Consumer} - * from which is the current {@link InstallPlan} resource updated - * - * @param namespaceName Namespace, where the resource should be replaced - * @param resourceName name of the {@link InstallPlan} that will be replaced - * @param editor {@link Consumer} containing updates to the resource - */ - @Override - public void replaceInNamespace(String namespaceName, String resourceName, Consumer editor) { - InstallPlan toBeReplaced = client.inNamespace(namespaceName).withName(resourceName).get(); - editor.accept(toBeReplaced); - updateInNamespace(namespaceName, toBeReplaced); - } } diff --git a/test-frame-openshift/src/main/java/io/skodjob/testframe/resources/OperatorGroupType.java b/test-frame-openshift/src/main/java/io/skodjob/testframe/resources/OperatorGroupType.java index bf6255e..0523323 100644 --- a/test-frame-openshift/src/main/java/io/skodjob/testframe/resources/OperatorGroupType.java +++ b/test-frame-openshift/src/main/java/io/skodjob/testframe/resources/OperatorGroupType.java @@ -8,14 +8,14 @@ import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.openshift.api.model.operatorhub.v1.OperatorGroup; import io.fabric8.openshift.api.model.operatorhub.v1.OperatorGroupList; -import io.skodjob.testframe.interfaces.NamespacedResourceType; +import io.skodjob.testframe.interfaces.ResourceType; import java.util.function.Consumer; /** * Implementation of ResourceType for specific kubernetes resource */ -public class OperatorGroupType implements NamespacedResourceType { +public class OperatorGroupType implements ResourceType { private final MixedOperation> client; @@ -53,7 +53,7 @@ public String getKind() { */ @Override public void create(OperatorGroup resource) { - client.resource(resource).create(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).create(); } /** @@ -63,29 +63,30 @@ public void create(OperatorGroup resource) { */ @Override public void update(OperatorGroup resource) { - client.resource(resource).update(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).update(); } /** * Deletes {@link OperatorGroup} resource from Namespace in current context * - * @param resourceName name of the {@link OperatorGroup} that will be deleted + * @param resource {@link OperatorGroup} resource that will be deleted */ @Override - public void delete(String resourceName) { - client.withName(resourceName).delete(); + public void delete(OperatorGroup resource) { + client.inNamespace(resource.getMetadata().getNamespace()).withName(resource.getMetadata().getName()).delete(); } /** * Replaces {@link OperatorGroup} resource using {@link Consumer} * from which is the current {@link OperatorGroup} resource updated * - * @param resourceName name of the {@link OperatorGroup} that will be replaced - * @param editor {@link Consumer} containing updates to the resource + * @param resource {@link OperatorGroup} resource that will be replaced + * @param editor {@link Consumer} containing updates to the resource */ @Override - public void replace(String resourceName, Consumer editor) { - OperatorGroup toBeReplaced = client.withName(resourceName).get(); + public void replace(OperatorGroup resource, Consumer editor) { + OperatorGroup toBeReplaced = client.inNamespace(resource.getMetadata().getNamespace()) + .withName(resource.getMetadata().getName()).get(); editor.accept(toBeReplaced); update(toBeReplaced); } @@ -111,52 +112,4 @@ public boolean isReady(OperatorGroup resource) { public boolean isDeleted(OperatorGroup resource) { return resource == null; } - - /** - * Creates specific {@link OperatorGroup} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be created - * @param resource {@link OperatorGroup} resource - */ - @Override - public void createInNamespace(String namespaceName, OperatorGroup resource) { - client.inNamespace(namespaceName).resource(resource).create(); - } - - /** - * Updates specific {@link OperatorGroup} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be updated - * @param resource {@link OperatorGroup} updated resource - */ - @Override - public void updateInNamespace(String namespaceName, OperatorGroup resource) { - client.inNamespace(namespaceName).resource(resource).update(); - } - - /** - * Deletes {@link OperatorGroup} resource from Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be deleted - * @param resourceName name of the {@link OperatorGroup} that will be deleted - */ - @Override - public void deleteFromNamespace(String namespaceName, String resourceName) { - client.inNamespace(namespaceName).withName(resourceName).delete(); - } - - /** - * Replaces {@link OperatorGroup} resource in Namespace specified by user, using {@link Consumer} - * from which is the current {@link OperatorGroup} resource updated - * - * @param namespaceName Namespace, where the resource should be replaced - * @param resourceName name of the {@link OperatorGroup} that will be replaced - * @param editor {@link Consumer} containing updates to the resource - */ - @Override - public void replaceInNamespace(String namespaceName, String resourceName, Consumer editor) { - OperatorGroup toBeReplaced = client.inNamespace(namespaceName).withName(resourceName).get(); - editor.accept(toBeReplaced); - updateInNamespace(namespaceName, toBeReplaced); - } } diff --git a/test-frame-openshift/src/main/java/io/skodjob/testframe/resources/SubscriptionType.java b/test-frame-openshift/src/main/java/io/skodjob/testframe/resources/SubscriptionType.java index 80494ea..8cdb7d0 100644 --- a/test-frame-openshift/src/main/java/io/skodjob/testframe/resources/SubscriptionType.java +++ b/test-frame-openshift/src/main/java/io/skodjob/testframe/resources/SubscriptionType.java @@ -8,14 +8,14 @@ import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.openshift.api.model.operatorhub.v1alpha1.Subscription; import io.fabric8.openshift.api.model.operatorhub.v1alpha1.SubscriptionList; -import io.skodjob.testframe.interfaces.NamespacedResourceType; +import io.skodjob.testframe.interfaces.ResourceType; import java.util.function.Consumer; /** * Implementation of ResourceType for specific kubernetes resource */ -public class SubscriptionType implements NamespacedResourceType { +public class SubscriptionType implements ResourceType { private final MixedOperation> client; @@ -53,7 +53,7 @@ public String getKind() { */ @Override public void create(Subscription resource) { - client.resource(resource).create(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).create(); } /** @@ -63,29 +63,30 @@ public void create(Subscription resource) { */ @Override public void update(Subscription resource) { - client.resource(resource).update(); + client.inNamespace(resource.getMetadata().getNamespace()).resource(resource).update(); } /** * Deletes {@link Subscription} resource from Namespace in current context * - * @param resourceName name of the {@link Subscription} that will be deleted + * @param resource {@link Subscription} resource that will be deleted */ @Override - public void delete(String resourceName) { - client.withName(resourceName).delete(); + public void delete(Subscription resource) { + client.inNamespace(resource.getMetadata().getNamespace()).withName(resource.getMetadata().getName()).delete(); } /** * Replaces {@link Subscription} resource using {@link Consumer} * from which is the current {@link Subscription} resource updated * - * @param resourceName name of the {@link Subscription} that will be replaced - * @param editor {@link Consumer} containing updates to the resource + * @param resource {@link Subscription} resource that will be replaced + * @param editor {@link Consumer} containing updates to the resource */ @Override - public void replace(String resourceName, Consumer editor) { - Subscription toBeReplaced = client.withName(resourceName).get(); + public void replace(Subscription resource, Consumer editor) { + Subscription toBeReplaced = client.inNamespace(resource.getMetadata().getNamespace()) + .withName(resource.getMetadata().getName()).get(); editor.accept(toBeReplaced); update(toBeReplaced); } @@ -111,52 +112,4 @@ public boolean isReady(Subscription resource) { public boolean isDeleted(Subscription resource) { return resource == null; } - - /** - * Creates specific {@link Subscription} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be created - * @param resource {@link Subscription} resource - */ - @Override - public void createInNamespace(String namespaceName, Subscription resource) { - client.inNamespace(namespaceName).resource(resource).create(); - } - - /** - * Updates specific {@link Subscription} resource in Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be updated - * @param resource {@link Subscription} updated resource - */ - @Override - public void updateInNamespace(String namespaceName, Subscription resource) { - client.inNamespace(namespaceName).resource(resource).update(); - } - - /** - * Deletes {@link Subscription} resource from Namespace specified by user - * - * @param namespaceName Namespace, where the resource should be deleted - * @param resourceName name of the {@link Subscription} that will be deleted - */ - @Override - public void deleteFromNamespace(String namespaceName, String resourceName) { - client.inNamespace(namespaceName).withName(resourceName).delete(); - } - - /** - * Replaces {@link Subscription} resource in Namespace specified by user, using {@link Consumer} - * from which is the current {@link Subscription} resource updated - * - * @param namespaceName Namespace, where the resource should be replaced - * @param resourceName name of the {@link Subscription} that will be replaced - * @param editor {@link Consumer} containing updates to the resource - */ - @Override - public void replaceInNamespace(String namespaceName, String resourceName, Consumer editor) { - Subscription toBeReplaced = client.inNamespace(namespaceName).withName(resourceName).get(); - editor.accept(toBeReplaced); - updateInNamespace(namespaceName, toBeReplaced); - } }