Skip to content

Simplify workload selectors#4917

Merged
tpapagian merged 4 commits into
mainfrom
pr/apapag/simplify_hostSelector
Apr 28, 2026
Merged

Simplify workload selectors#4917
tpapagian merged 4 commits into
mainfrom
pr/apapag/simplify_hostSelector

Conversation

@tpapagian
Copy link
Copy Markdown
Member

@tpapagian tpapagian commented Apr 27, 2026

#4814 added support for spec.hostSelector. The idea was to have by default spec.podSelector: {}, spec.containerSelector: {}, and spec.hostSelector: {}. But this has some unintended side effects that complicate our codebase (i.e. #4889 and #4896).

In order to fix that, we change the defaults of spec.{pod, container, host}Selector from {} to null. The new behaviour is described in the table below:

hostSelector podSelector containerSelector Result
null (default) null (default) null (default) Select all host, pod, and container workloads.
null (default) null (default) {...} Select all containers that match containerSelector across all pods. No host workloads are selected.
null (default) {...} null (default) Select all containers in pods that match podSelector. No host workloads are selected.
null (default) {...} {...} Select all containers that match containerSelector in pods that match podSelector. No host workloads are selected.
{} null (default) null (default) Select all host workloads.
{} null (default) {...} Select all host workloads, plus all containers that match containerSelector across all pods.
{} {...} null (default) Select all host workloads, plus all containers in pods that match podSelector.
{} {...} {...} Select all host workloads, plus all containers that match containerSelector in pods that match podSelector.

This change will also allow us to remove the code introduced in #4889 and be able to check the hostSelector value inside TracingPolicyNamespaced with a kubebuilder XValidation (i.e. #4896 (comment)).

@tpapagian tpapagian force-pushed the pr/apapag/simplify_hostSelector branch 2 times, most recently from 31e88ed to a968e08 Compare April 27, 2026 19:27
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 27, 2026

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit f8c6bab
🔍 Latest deploy log https://app.netlify.com/projects/tetragon/deploys/69f0a07e6fdcae0008c32b7b
😎 Deploy Preview https://deploy-preview-4917--tetragon.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@tpapagian tpapagian force-pushed the pr/apapag/simplify_hostSelector branch 2 times, most recently from 9d128c9 to c979dda Compare April 27, 2026 20:08
@tpapagian tpapagian added the release-note/minor This PR introduces a minor user-visible change label Apr 28, 2026
@tpapagian tpapagian force-pushed the pr/apapag/simplify_hostSelector branch 5 times, most recently from 254d510 to 4419375 Compare April 28, 2026 09:12
@tpapagian tpapagian changed the title Test Simplify workload selectors Apr 28, 2026
@tpapagian tpapagian marked this pull request as ready for review April 28, 2026 09:14
@tpapagian tpapagian requested review from a team and mtardy as code owners April 28, 2026 09:14
Copy link
Copy Markdown
Member

@mtardy mtardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feel reasonable and would simplify things, we discussed offline maybe merging the table because it's not obvious to me when I read this. Just another comment:

@tpapagian tpapagian force-pushed the pr/apapag/simplify_hostSelector branch from 4419375 to d1bcd95 Compare April 28, 2026 10:20
Copy link
Copy Markdown
Member

@mtardy mtardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's indeed better.

So as I understand you do not need to revert 564b89a as well?

Maybe we should highlight that the default null/null/null is a special case with a note or caution?

Should you also not merge #4918 and revert the PR now since you shouldn't be able to get any policy not respecting the validation?

@tpapagian
Copy link
Copy Markdown
Member Author

So as I understand you do not need to revert 564b89a as well?

Possibly part of that. I will check now. Not everything as this also contains fixes/changes for the policyfilter implementation to support the hostSelector (i.e. an entry in the policy_filter_map with all pod cgroup IDs).

Maybe we should highlight that the default null/null/null is a special case with a note or caution?

Yes, I can do that.

Should you also not merge #4918 and revert the PR now since you shouldn't be able to get any policy not respecting the validation?

I have closed #4918 as it does not make sense to merge it now. I have kept the check in the agent but now it is an error. Just in case somehow we overcome the XValidation check.

#4814 added support for spec.hostSelector.
The idea was to have by default `spec.podSelector: {}`, `spec.containerSelector: {}`,
and `spec.hostSelector: {}`. But this has some unintended side effects that
complicate our codebase (i.e. #4889 and
#4896).

In order to fix that, we change the defaults of `spec.{pod, container, host}Selector`
from `{}` to `null`.

This change will also allow us to remove the code introduced in
#4889 and be able to check the `hostSelector`
value inside `TracingPolicyNamespaced` with a `kubebuilder` `XValidation`
(i.e. #4896 (comment)).

This patch also reverts part of
564b89a
to reflect the new changes in the tests.

Signed-off-by: Anastasios Papagiannis <anastasios.papagiannis@isovalent.com>
Signed-off-by: Anastasios Papagiannis <anastasios.papagiannis@isovalent.com>
This reverts commit 6c6cd99.

We do not need to specify hostSelector to be null explicitly.

Signed-off-by: Anastasios Papagiannis <anastasios.papagiannis@isovalent.com>
This reverts commit 38a6543.

As we change the default value of workload selectors from {} to null
this code is not required now.

Signed-off-by: Anastasios Papagiannis <anastasios.papagiannis@isovalent.com>
@tpapagian tpapagian force-pushed the pr/apapag/simplify_hostSelector branch from d1bcd95 to f8c6bab Compare April 28, 2026 11:56
@tpapagian
Copy link
Copy Markdown
Member Author

So as I understand you do not need to revert 564b89a as well?

Possibly part of that. I will check now. Not everything as this also contains fixes/changes for the policyfilter implementation to support the hostSelector (i.e. an entry in the policy_filter_map with all pod cgroup IDs).

Most of that was already done in the first patch. I have added a comment in the first patch description.

Maybe we should highlight that the default null/null/null is a special case with a note or caution?

Yes, I can do that.

Done.

@tpapagian tpapagian merged commit c9978e4 into main Apr 28, 2026
66 of 67 checks passed
@tpapagian tpapagian deleted the pr/apapag/simplify_hostSelector branch April 28, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/minor This PR introduces a minor user-visible change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants