question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Field selector is not applied even when resource fields are matching

See original GitHub issue

After upgrading from 4.9.2 to 5.9.0, I have observed that one of our unit tests (which is using KubernetesServer) is failing. It seems that object are not returned when using the Event API with field selectors. I did not yet checked other API’s neither whether it’s limited to the KubernetesServer.

Following a small reproduction unit test which illustrates the problem:

import io.fabric8.kubernetes.api.model.Event;
import io.fabric8.kubernetes.api.model.ObjectMeta;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.server.mock.KubernetesServer;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

import java.util.List;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

@RunWith(MockitoJUnitRunner.class)
public class KubernetesClientTest {

    @Rule
    public KubernetesServer server = new KubernetesServer(true, true);

    @Test
    public void shouldReturnEventMatchingFieldSelector() {
        // given
        KubernetesClient kubernetesClient = server.getClient();
        Event kubernetesEvent = createKubernetesEventWithReason();
        kubernetesClient.v1().events().create(kubernetesEvent);

        // when
        List<Event> kubernetesEvents = kubernetesClient.v1().events().inAnyNamespace().withField("reason", "Rebooted").list().getItems();

        // then
        assertThat(kubernetesEvents.size()).isEqualTo(1);
    }

    private Event createKubernetesEventWithReason() {
        Event  event = new Event();
        ObjectMeta metaData = new ObjectMeta();
        metaData.setName("EventName");
        event.setMetadata(metaData);
        event.setReason("Rebooted");
        return event;
    }
}

Logs from the test execution:

Nov 08, 2021 9:37:39 AM okhttp3.mockwebserver.MockWebServer$2 execute
INFO: MockWebServer[58829] starting to accept connections
Nov 08, 2021 9:37:40 AM okhttp3.mockwebserver.MockWebServer$3 processOneRequest
INFO: MockWebServer[58829] received request: POST /api/v1/namespaces/test/events HTTP/1.1 and responded: HTTP/1.1 200 OK
Nov 08, 2021 9:37:40 AM okhttp3.mockwebserver.MockWebServer$3 processOneRequest
INFO: MockWebServer[58829] received request: GET /api/v1/events?fieldSelector=reason%3DRebooted HTTP/1.1 and responded: HTTP/1.1 200 OK
Nov 08, 2021 9:37:40 AM okhttp3.mockwebserver.MockWebServer$2 acceptConnections
INFO: MockWebServer[58829] done accepting connections: Socket closed

org.opentest4j.AssertionFailedError: 
Expecting:
 <[]>
to be equal to:
 <1>
but was not.
Expected :1
Actual   :[]

Please let me know if further information are required.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
manusacommented, Nov 8, 2021

Could you please quickly check if this is still reproducible in #3562 🙏 ?

Maybe we can tackle the issue in scope of that PR.

0reactions
stale[bot]commented, Feb 27, 2022

This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Kubernetes Label Selector and Field Selector - MayaData Blog
In this blog, I will explain how label and field selectors will help you in understanding how they work and how they can...
Read more >
How can I find the list of field selectors supported by kubectl ...
1. A successful job returns "succeeded":1 in the status json, so is it a bug that the field selector doesn't match the name...
Read more >
Field Selectors - Kubernetes
Field selectors let you select Kubernetes resources based on the value of one or more resource fields. Here are some examples of field...
Read more >
[BUG] Kyverno policy match selector doesn't work · Issue #1328
I run kubectl kyverno apply resources/nodepolicy.yaml --resource ... I try remove the selector as below, the policy still not work.
Read more >
Using KubeAssert Effectively | by MorningSpace - Medium
KubeAssert is a kubectl plugin to make assertions against Kubernetes resources on your cluster from command line.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found