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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 ignore namespace key when getting cluster-scoped resources #1326

Conversation

joelanford
Copy link
Member

This PR makes the controller-runtime cache consistent with the behavior of the client when working with cluster-scoped resources.

Closes #1323

Current behavior:
When fetching a cluster-scoped resource using a direct client (e.g. mgr.GetAPIReader), the namespace in the object key is ignored. When fetching a cluster-scoped resource via the cache, the namespace key MUST be set to an empty string. Otherwise the cache will return a not found error.

Expected behavior:
When fetching a cluster-scoped resource via the cache, the namespace key is ignored, just like with a direct client. The APIReader and Cache behavior should be consistent.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 10, 2021
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 10, 2021
@joelanford
Copy link
Member Author

/retest

By("listing all namespaces - should still be able to get a cluster-scoped resource")
namespaceList := &unstructured.UnstructuredList{}
namespaceList.SetGroupVersionKind(schema.GroupVersionKind{
By("listing all nodes - should still be able to list a cluster-scoped resource")
Copy link
Member

Choose a reason for hiding this comment

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

Why did you change this from Namespace to Node?

Copy link
Member Author

Choose a reason for hiding this comment

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

Mainly to avoid confusion of trying to explain "setting a namespace key on a namespace"

namespaceList := &unstructured.UnstructuredList{}
namespaceList.SetGroupVersionKind(schema.GroupVersionKind{
By("listing all nodes - should still be able to list a cluster-scoped resource")
nodeList := &kmetav1.PartialObjectMetadataList{}
Copy link
Member

Choose a reason for hiding this comment

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

This needs to remain an unstructured.UnstructuredList, otherwise the two testcases are identical

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! That was an accidental copy/paste error.

@joelanford joelanford force-pushed the bug/ignore-namespace-cluster-scoped-get branch from 90d071d to f6f9ff4 Compare January 11, 2021 17:09
@joelanford joelanford force-pushed the bug/ignore-namespace-cluster-scoped-get branch from f6f9ff4 to 2c0bd8f Compare January 11, 2021 17:11
Copy link
Member

@alvaroaleman alvaroaleman left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 11, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, joelanford

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [alvaroaleman,joelanford]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit 63e597b into kubernetes-sigs:master Jan 11, 2021
@joelanford joelanford deleted the bug/ignore-namespace-cluster-scoped-get branch January 11, 2021 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cached client doesn't support Get for cluster scoped resources if namespace is given
3 participants