Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Unify namespaced and non namespaced ResoruceType API #161

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ public interface ResourceType<T extends HasMetadata> {
/**
* 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<T> editor);
void replace(T resource, Consumer<T> editor);

/**
* Confirms that {@link T} is ready (created/running)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -383,12 +382,7 @@ public final <T extends HasMetadata> 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<T>) {
((NamespacedResourceType<T>) 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()));
Expand Down Expand Up @@ -418,12 +412,7 @@ public final <T extends HasMetadata> void updateResource(T... resources) {
LoggerUtils.logResource("Updating", resource);
ResourceType<T> type = findResourceType(resource);
if (type != null) {
if (type instanceof NamespacedResourceType<T>) {
((NamespacedResourceType<T>) type).updateInNamespace(resource.getMetadata().getNamespace(),
resource);
} else {
type.update(resource);
}
type.update(resource);
} else {
client.getClient().resource(resource).update();
}
Expand Down Expand Up @@ -459,7 +448,7 @@ public final <T extends HasMetadata> boolean waitResourceCondition(T resource, R
if (type == null) {
client.getClient().resource(resource).delete();
} else {
type.delete(res.getMetadata().getName());
type.delete(res);
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClusterRoleBinding> editor) {
ClusterRoleBinding toBeUpdated = client.withName(resourceName).get();
public void replace(ClusterRoleBinding resource, Consumer<ClusterRoleBinding> editor) {
ClusterRoleBinding toBeUpdated = client.withName(resource.getMetadata().getName()).get();
editor.accept(toBeUpdated);
update(toBeUpdated);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClusterRole> editor) {
ClusterRole toBeUpdated = client.withName(resourceName).get();
public void replace(ClusterRole resource, Consumer<ClusterRole> editor) {
ClusterRole toBeUpdated = client.withName(resource.getMetadata().getName()).get();
editor.accept(toBeUpdated);
update(toBeUpdated);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConfigMap> {
public class ConfigMapType implements ResourceType<ConfigMap> {
private final MixedOperation<ConfigMap, ConfigMapList, Resource<ConfigMap>> client;

/**
Expand Down Expand Up @@ -45,96 +45,49 @@ 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<ConfigMap> editor) {
ConfigMap toBeUpdated = client.inNamespace(namespaceName).withName(resourceName).get();
editor.accept(toBeUpdated);
updateInNamespace(namespaceName, toBeUpdated);
}

/**
* Creates specific {@link ConfigMap} resource
*
* @param resource {@link ConfigMap} resource
*/
@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<ConfigMap> 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<ConfigMap> 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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CustomResourceDefinition> editor) {
CustomResourceDefinition toBeUpdated = client.withName(resourceName).get();
public void replace(CustomResourceDefinition resource, Consumer<CustomResourceDefinition> editor) {
CustomResourceDefinition toBeUpdated = client.withName(resource.getMetadata().getName()).get();
editor.accept(toBeUpdated);
update(toBeUpdated);
}
Expand Down
Loading
Loading