Skip to content

Conversation

@antcybersec
Copy link
Contributor

Adds spec.schema.scope (Namespaced|Cluster, immutable, default Namespaced) to ResourceGraphDefinition. CRD synthesis now sets scope accordingly, and instance reconciler handles cluster-scoped instances without requiring a namespace. Includes unit tests and docs note.

image

Fixes: #806

Adds spec.schema.scope (Namespaced|Cluster, immutable, default Namespaced) to
ResourceGraphDefinition. CRD synthesis now sets scope accordingly, and instance
reconciler handles cluster-scoped instances without requiring a namespace.
Includes unit tests and docs note.

Fixes: kubernetes-sigs#806
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: antcybersec
Once this PR has been reviewed and has the lgtm label, please assign elmiko for approval. For more information see the Code Review Process.

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

Needs approval from an approver in each of these files:

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 added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Dec 5, 2025
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Dec 5, 2025
@k8s-ci-robot k8s-ci-robot requested a review from jlbutler December 5, 2025 10:57
@k8s-ci-robot
Copy link
Contributor

Hi @antcybersec. Thanks for your PR.

I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Dec 5, 2025
@a-hilaly
Copy link
Member

a-hilaly commented Dec 5, 2025

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 5, 2025
Copy link
Member

@a-hilaly a-hilaly left a comment

Choose a reason for hiding this comment

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

Thank you @antcybersec! i do have one comment on the implementation. however I do think that this feature deserves a KREP-XXX document that shares benefits, tradeoffs and (maybe) potential impact.

Comment on lines 561 to 563
if ns := obj.GetNamespace(); ns != "" {
namespacedClient = instanceClient.Namespace(ns)
}
Copy link
Member

Choose a reason for hiding this comment

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

runtime, has already information about the resource scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback! Just to confirm — are you suggesting that instead of checking obj.GetNamespace() here, I should pull the scope from the runtime (via RESTMapper / GVK mapping) and choose the correct client accordingly?

If runtime scope is authoritative in this context, I can update the implementation to rely on it and remove this namespaced check.

Copy link
Member

Choose a reason for hiding this comment

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

Since we already know the scope at RGD compile time, we can store that information in https://github.com/kubernetes-sigs/kro/blob/main/pkg/graph/graph.go#L30-L31 - which has a namespaced bool https://github.com/kubernetes-sigs/kro/blob/main/pkg/graph/resource.go#L60-L63.

Later we can just retrieve from runtime using https://github.com/kubernetes-sigs/kro/blob/main/pkg/runtime/interfaces.go#L113-L115

@a-hilaly
Copy link
Member

a-hilaly commented Dec 5, 2025

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 5, 2025
@antcybersec antcybersec requested a review from a-hilaly December 6, 2025 12:54
@a-hilaly
Copy link
Member

a-hilaly commented Dec 7, 2025

@antcybersec can you please write up a KREP document (doesn't have to be large) that shares benefits, tradeoffs and (maybe) potential impact. Just documenting decisions here.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 8, 2025
Comment on lines 582 to 590
descriptor := igr.runtime.ResourceDescriptor(resourceID)
gvr := descriptor.GetGroupVersionResource()

var dynResource dynamic.ResourceInterface
if restMapping.Scope.Name() == meta.RESTScopeNameNamespace {
if descriptor.IsNamespaced() {
namespace := igr.getResourceNamespace(resourceID)
dynResource = igr.client.Resource(restMapping.Resource).Namespace(namespace)
dynResource = igr.client.Resource(gvr).Namespace(namespace)
} else {
dynResource = igr.client.Resource(restMapping.Resource)
dynResource = igr.client.Resource(gvr)
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this change related to allowing cluster-scoped RGDs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hey @tjamet I have added a KREP document (
docs/design/proposals/resource-descriptor-scope-resolution.md
) in the latest commit that details the motivation and design for this change.

Comment on lines 519 to 523
instanceClient := igr.client.Resource(igr.gvr)
var namespacedClient dynamic.ResourceInterface = instanceClient
if ns := obj.GetNamespace(); ns != "" {
namespacedClient = instanceClient.Namespace(ns)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

namespacedClient name is misleading IMO It could be cluster-scoped or namespaced client depending on the resource

I would suggest defining a getGVRClient used here, in the setUnmanaged and in the getResourceClient function to ensure namespacing is well-managed everywhere

@antcybersec antcybersec requested a review from tjamet December 8, 2025 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for RGDs to manage Cluster Scoped CRDs

4 participants