Field selector is not applied even when resource fields are matching
See original GitHub issueAfter 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:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Could you please quickly check if this is still reproducible in #3562 🙏 ?
Maybe we can tackle the issue in scope of that PR.
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!