-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Mock KubernetesServer not performing cleanup #3461
Comments
What version is this on? Older versions of the mock logic had an issue with inferring the namespace of the object created. That was addressed by #3156. This works fine on latest from what I can tell. |
5.6.0 of the fabric8 client |
Would it be possible to provide a reproducer? |
I'm not able to reproduce this. I tried adding a new test case to PodCrudTest like this but it is passing for me: @Test
void testDeleteActuallyRemovesPods() {
// Given
Pod pod1 = new PodBuilder().withNewMetadata().withName("pod1").addToLabels("testKey", "testValue").endMetadata().build();
// When
client.pods().inNamespace("foo").create(pod1);
client.pods().inNamespace("foo").withName("pod1").delete();
// Then
assertNull(client.pods().inNamespace("foo").withName("pod1").get());
} Would appreciate it if we could get some more information. |
@rohanKanojia does your example use the mock server? It looks like it's using the actual client |
PodCrudTest is using kubernetes-client/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/PodCrudTest.java Lines 41 to 45 in 2dbfe29
|
Thanks @rohanKanojia The main difference I see is that I didn't delete a specific pod, but all pods with:
Is that the problem? I need to delete the pods by name? |
Under the covers pods().delete() will perform a list and delete each individually. |
Is there a problem with how I create the pod? I've used |
If you don't specify namespace Kubernetes Mock Server assumes namespace to be test(This is done in order to mock default context behavior we have in Lines 77 to 85 in 2dbfe29
Anyway, even if I trim namespace test is passing: @Test
void testDeleteActuallyRemovesPods() {
// Given
Pod pod1 = new PodBuilder().withNewMetadata().withName("pod1").addToLabels("testKey", "testValue").endMetadata().build();
// When
client.pods().create(pod1);
client.pods().delete();
// Then
assertNull(client.pods().withName("pod1").get());
} I think if you check logs of test maybe they can provide some insight on what namespace is getting picked by tests:
|
@Test
void testDeleteAllPodsInDifferentNamespaces() {
// Given
Pod pod1 = new PodBuilder().withNewMetadata().withName("p1").addToLabels("testKey", "testValue").endMetadata().build();
Pod pod2 = new PodBuilder().withNewMetadata().withName("p2").addToLabels("testKey", "testValue").endMetadata().build();
Pod pod3 = new PodBuilder().withNewMetadata().withName("p3").addToLabels("testKey", "testValue").endMetadata().build();
client.pods().inNamespace("ns1").create(pod1);
client.pods().inNamespace("ns2").create(pod2);
client.pods().inNamespace("ns3").create(pod3);
// When
client.pods().delete();
PodList ns1Pods = client.pods().inNamespace("ns1").list();
PodList ns2Pods = client.pods().inNamespace("ns2").list();
PodList ns3Pods = client.pods().inNamespace("ns3").list();
// Then
assertTrue(ns1Pods.getItems().isEmpty());
assertTrue(ns2Pods.getItems().isEmpty());
assertTrue(ns3Pods.getItems().isEmpty());
} |
Sorry, false alarm. contexts:
- context:
cluster: api-sandbox-test-com:6443
namespace: rokumar-dev
user: rokumar/api-sandbox-test-com:6443
name: rokumar-dev/api-sandbox-test-com:6443/rokumar
current-context: rokumar-dev/api-sandbox-test-com:6443/rokumar In the case of mockwebserver, the namespace set would be always client.pods().inAnyNamespace().delete(); @kenfinnigan : Would it be possible for you to try specifying |
@rohanKanojia that seems to work for most tests, but I did hit one error. I happened to notice that any watcher I installed with Is there a way to remove a watcher? |
Watches require an explicit close. If the client is closed that should do it as well. |
By "explicit close", do you mean calling |
I think he's referring to watcher.close() method. Something like this: kubernetes-client/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/WatchTest.java Lines 148 to 158 in 04e0b2e
|
Thank you! I'd completely missed there was a All seems good now, thanks again for the help |
When creating pods in the mock server with
mockServer.getClient().pods().create(pod1)
, deleting them at the end of a test withmockServer.getClient().pods().delete()
does not result in the pods being removed in subsequent tests.The text was updated successfully, but these errors were encountered: