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

Change ResoruceCondition class to record type #76

Merged
merged 2 commits into from
May 16, 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
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@
*/
public class KubeResourceManager {
private static final Logger LOGGER = LogManager.getLogger(KubeResourceManager.class);

private static KubeResourceManager instance;
private static KubeClient client;
private static KubeCmdClient<?> kubeCmdClient;
private static ThreadLocal<ExtensionContext> testContext = new ThreadLocal<>();
private static final Map<String, Stack<ResourceItem<?>>> STORED_RESOURCES = new LinkedHashMap<>();
private ResourceType<?>[] resourceTypes;
private List<Consumer<HasMetadata>> createCallbacks = new LinkedList<>();
private List<Consumer<HasMetadata>> deleteCallbacks = new LinkedList<>();
private final List<Consumer<HasMetadata>> createCallbacks = new LinkedList<>();
private final List<Consumer<HasMetadata>> deleteCallbacks = new LinkedList<>();

private static final ThreadLocal<ExtensionContext> TEST_CONTEXT = new ThreadLocal<>();
private static final Map<String, Stack<ResourceItem<?>>> STORED_RESOURCES = new LinkedHashMap<>();

private KubeResourceManager() {
// Private constructor to prevent instantiation
Expand Down Expand Up @@ -90,15 +92,15 @@ public static KubeCmdClient<?> getKubeCmdClient() {
* @param context The extension context.
*/
public static void setTestContext(ExtensionContext context) {
testContext.set(context);
TEST_CONTEXT.set(context);
}

/**
* Retrieves the test context.
* @return The extension context.
*/
public static ExtensionContext getTestContext() {
return testContext.get();
return TEST_CONTEXT.get();
}

/**
Expand Down Expand Up @@ -348,11 +350,11 @@ public final <T extends HasMetadata> boolean waitResourceCondition(T resource, R
boolean[] resourceReady = new boolean[1];

Wait.until(String.format("Resource condition: %s to be fulfilled for resource %s/%s",
condition.getConditionName(), resource.getKind(), resource.getMetadata().getName()),
condition.conditionName(), resource.getKind(), resource.getMetadata().getName()),
TestFrameConstants.GLOBAL_POLL_INTERVAL_MEDIUM, TestFrameConstants.GLOBAL_TIMEOUT,
() -> {
T res = getKubeClient().getClient().resource(resource).get();
resourceReady[0] = condition.getPredicate().test(res);
resourceReady[0] = condition.predicate().test(res);
return resourceReady[0];
},
() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,11 @@
/**
* Represents a condition that can be applied to Kubernetes resources.
*
* @param predicate predicate function
* @param conditionName conditionName
* @param <T> Type of Kubernetes resource.
*/
public class ResourceCondition<T extends HasMetadata> {
private final Predicate<T> predicate;
private final String conditionName;

/**
* Constructs a ResourceCondition with the given predicate and condition name.
*
* @param predicate The predicate representing the condition.
* @param conditionName The name of the condition.
*/
public ResourceCondition(Predicate<T> predicate, String conditionName) {
this.predicate = predicate;
this.conditionName = conditionName;
}

/**
* Gets the name of the condition.
*
* @return The name of the condition.
*/
public String getConditionName() {
return conditionName;
}

/**
* Gets the predicate representing the condition.
*
* @return The predicate representing the condition.
*/
public Predicate<T> getPredicate() {
return predicate;
}
public record ResourceCondition<T extends HasMetadata>(Predicate<T> predicate, String conditionName) {

/**
* Creates a ResourceCondition representing readiness of a resource of the given type.
Expand Down
Loading