Skip to content

fix native resource discovery. - #132

Merged
shaked-bouktus merged 17 commits into
mainfrom
native-crd-discovery
Jul 12, 2026
Merged

shaked-bouktus merged 17 commits into
mainfrom
native-crd-discovery

Conversation

@shaked-bouktus

@shaked-bouktus shaked-bouktus commented Jul 1, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

The reconciler previously only marked a Karta's CRDExists condition True when a CustomResourceDefinition backed the root GVK. Native/built-in types (e.g. apps/v1 Deployment) have no CRD, so they never became Ready.

This PR discovers built-in served GVKs at controller setup via the discovery API and caches them on the Reconciler. The existence check (renamed crdExistsForGVK → checkGVKServed) now returns True if the GVK is either native or CRD-backed. Discovery skips subresources and virtual/imperative-only kinds (requires list+watch), excludes CRD-backed GKs, and tolerates partial group-discovery failures.

Also adds operator/go.sum to CI caching and runs make check for the operator.

Tests
Unit tests for discoverNativeGVKs (keeps built-in list+watch kinds, drops subresources/virtual/CRD-backed, tolerates partial discovery failure, fails on generic errors).
Envtest scenario asserting CRDExists=True and Ready=True for a built-in GVK with no backing CRD.

Related issue(s)

Fixes #

Checklist

  • All commits are signed off with DCO (git commit -s)
  • New/modified files have SPDX license and copyright headers
  • Documentation updated (if applicable)
  • Tests pass (make check)
  • No proprietary or internal information included

Summary by CodeRabbit

  • Bug Fixes
    • Improved detection of native Kubernetes resources by precomputing supported GroupVersionKinds, ensuring resources without associated CustomResourceDefinitions are handled correctly.
    • Updated condition logic so native resources transition to the expected readiness outcomes (e.g., CRD-exists and Ready conditions become True when applicable).
  • Tests
    • Added an integration (envtest) scenario for a built-in workload GVK (apps/v1 Deployment) to verify conditions reach True without an associated CRD.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

The reconciler now discovers built-in Kubernetes GVKs during setup and skips CRD lookups for those types. A new integration test covers a built-in Deployment GVK that has no CRD in envtest. Indirect golang.org/x module versions were also updated.

Changes

Native GVK Discovery

Layer / File(s) Summary
Imports and Reconciler field additions
operator/pkg/controller.go
Adds discovery-related imports, a native API group suffix constant, and a nativeGVKs cache on Reconciler.
Discovery client wiring in SetupWithManager
operator/pkg/controller.go
SetupWithManager creates a discovery client from manager config, discovers native GVKs, and stores the resulting map or returns setup errors.
discoverNativeGVKs and crdExistsForGVK logic
operator/pkg/controller.go
Implements discovery-based native GVK collection from server resources and updates crdExistsForGVK to return true for cached native GVKs before CRD lookup.
Integration test for built-in GVK reconciliation
operator/test/integration/controller_test.go
Adds an envtest scenario verifying that a Karta referencing apps/v1 Deployment without a CRD reaches ConditionCRDExists=True and ConditionReady=True.

Module Dependency Updates

Layer / File(s) Summary
go.mod dependency bumps
operator/go.mod
Bumps indirect golang.org/x module versions in the require block.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested reviewers: AviadHayumi, rogirun

Poem

A rabbit hopped through API trees, 🐰
Sniffing out GVKs with ease,
“No CRD? No need to fret,
Built-in kinds are ready yet!”
Thump thump — tests pass, conditions true,
And tidy modules shine anew.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing native resource discovery in the controller.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch native-crd-discovery

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@operator/pkg/controller.go`:
- Around line 237-243: The partial-discovery path in controller.go is caching
incomplete native discovery, which can cause built-in GVKs to be treated as
missing CRDs later. Update the discovery handling around
ServerGroupsAndResources and the cache lookup path used by the GVK short-circuit
so that partial results for core/native groups do not become authoritative:
either fail setup when built-in discovery is incomplete or re-run discovery on a
cache miss before falling back to CRD listing. Make sure the logic in the
controller’s discovery/cache flow clearly distinguishes built-in resources from
CRD-backed ones.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Enterprise

Run ID: 4af17767-20c7-44ec-8747-51845f95daa0

📥 Commits

Reviewing files that changed from the base of the PR and between 1f8cdfd and a347cba.

📒 Files selected for processing (2)
  • operator/pkg/controller.go
  • operator/test/integration/controller_test.go

Comment thread operator/pkg/controller.go Resolved
Comment thread operator/pkg/controller.go Resolved
}, eventuallyTimeout, eventuallyInterval).Should(Succeed())
})

It("sets CRDExists=True for a built-in GVK with no backing CRD", func() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Semi-Random location for this comment, there are 2 fundamental issues:

  1. This PR doesn't compile
  2. The tests never actually run in the CI.

Really easy to miss any code issue that way, can we add that? (add an operator step to make check (or a matrix/second job))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yes ill add it in the makefile pr

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Im OK with not blocking as long as nothing else get's pushed into the operator before ci integration?
This is really risky and harder to review, creates tech depth

Comment thread operator/pkg/controller.go Resolved
Comment thread operator/pkg/controller.go Resolved
Comment on lines +260 to +262
if r.nativeGVKs[gvk] {
return true, nil
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

crdExistsForGVK misleading function name - nativeGVKs doesn't belong here or modify name, It's not a CRD 👀 maybe gvkServed

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

agreed, servedGvk is more appropriate, i will also change the condition name.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

reviewing it now and it still here
I think gvkExists it fine
I don't think we need to deal with "served" it's not our responsibility.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

will be done in another pr.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@ronlv10 I like even better :)
@shaked-bouktus why not in this PR? seems a bit peculiar to defer this

Comment thread operator/pkg/controller.go Resolved
shaked-bouktus and others added 8 commits July 1, 2026 19:17
Co-authored-by: isan_rivkin <irivkin@nvidia.com>
Signed-off-by: shaked-bouktus <157353909+shaked-bouktus@users.noreply.github.com>
Signed-off-by: shaked-bouktus <157353909+shaked-bouktus@users.noreply.github.com>
Comment thread operator/pkg/controller.go Resolved
Comment thread operator/pkg/controller.go Outdated
return fmt.Errorf("create discovery client: %w", err)
}

native, err := discoverNativeGVKs(context.Background(), dc, mgr.GetAPIReader(), mgr.GetLogger())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

natives

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

changed

Comment thread operator/pkg/controller.go Outdated
}
crdBackedGroupKinds := make(map[schema.GroupKind]bool, len(crds.Items))
for i := range crds.Items {
crdBackedGroupKinds[schema.GroupKind{Group: crds.Items[i].Spec.Group, Kind: crds.Items[i].Spec.Names.Kind}] = true

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

extract crds.Items[i].Spec to var and use it

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

for _, list := range resourceLists {
gv, err := schema.ParseGroupVersion(list.GroupVersion)
if err != nil {
logger.Info("Skipping malformed GroupVersion from discovery", "groupVersion", list.GroupVersion, "error", err.Error())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

is it a use case ? why did you add it ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I thought ParseGroupVersion could return error on 3rd party GVK, but after quick investigation you cant register a GVK to your cluster.
a buggy aggregated apiserver might fail in here, but its pretty rare usecase.
I can skip the error check, but IMO its a cheap check. wdyt?

Comment thread operator/pkg/controller.go Outdated
if strings.Contains(res.Name, "/") {
continue // subresource, e.g. deployments/scale
}
if crdBackedGroupKinds[schema.GroupKind{Group: gv.Group, Kind: res.Kind}] {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

crdBackedGroupKinds -> crdGKs

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ore without backed

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

Comment on lines +260 to +262
if r.nativeGVKs[gvk] {
return true, nil
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

reviewing it now and it still here
I think gvkExists it fine
I don't think we need to deal with "served" it's not our responsibility.


Eventually(func(g Gomega) {
conds := getKarta(k.Name).Status.Conditions
crd := apimeta.FindStatusCondition(conds, string(kartav1alpha1.ConditionCRDExists))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

didn't we agree to rename the condition ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

will be handled in another pr.

Comment on lines +260 to +262
if r.nativeGVKs[gvk] {
return true, nil
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@ronlv10 I like even better :)
@shaked-bouktus why not in this PR? seems a bit peculiar to defer this

}, eventuallyTimeout, eventuallyInterval).Should(Succeed())
})

It("sets CRDExists=True for a built-in GVK with no backing CRD", func() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Im OK with not blocking as long as nothing else get's pushed into the operator before ci integration?
This is really risky and harder to review, creates tech depth

Comment thread operator/pkg/controller.go Outdated

natives := make(map[schema.GroupVersionKind]bool)
for _, list := range resourceLists {
gv, _ := schema.ParseGroupVersion(list.GroupVersion)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

check if error

Comment thread operator/pkg/controller.go Outdated
Comment on lines +243 to +250
if !ok {
return nil, fmt.Errorf("list server resources: %w", err)
}
for gv, cause := range failed {
var stale discovery.StaleGroupVersionError
if !stderrors.As(cause, &stale) {
return nil, fmt.Errorf("discover group %s: %w", gv, cause)
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There's a problem with exiting on any error that is not stale.

Think of scenario:

  1. helm install metrics-server
  2. Later, helm uninstall metrics-server but the APIService object (v1beta1.metrics.k8s.io) is NOT deleted
  3. At startup the API layer tries to forward metrics.k8s.io/v1beta1 to the now-dead metrics-server backend. Returns 503

Because the APIService object exists and the aggregation layer keeps trying to proxy to a dead backend on every request.
Permanent failure for the Karta Controller.

Suggestion:
Only fail hard if the API server itself is unreachable (if !ok). Per-group failures should be warnings, not fatal

Comment thread operator/pkg/controller.go Outdated
Comment on lines +274 to +285
func supportsListWatch(verbs metav1.Verbs) bool {
var list, watch bool
for _, v := range verbs {
switch v {
case "list":
list = true
case "watch":
watch = true
}
}
return list && watch
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Two passes instead of one, but the slice is tiny so it doesn't matter. Clean and obvious

Suggested change
func supportsListWatch(verbs metav1.Verbs) bool {
var list, watch bool
for _, v := range verbs {
switch v {
case "list":
list = true
case "watch":
watch = true
}
}
return list && watch
}
import "slices"
func supportsListWatch(verbs metav1.Verbs) bool {
return slices.Contains(verbs, "list") && slices.Contains(verbs, "watch")
}

Side-Note: I don't think that current suggestion 1 liner suggests a dedicated function since it's not re-used and single line:

isSupportedVerbs := return slices.Contains(res.Verbs, "list") && slices.Contains(verbs, "watch")

Signed-off-by: shaked-bouktus <157353909+shaked-bouktus@users.noreply.github.com>
@shaked-bouktus
shaked-bouktus merged commit a967010 into main Jul 12, 2026
1 check passed
@shaked-bouktus
shaked-bouktus deleted the native-crd-discovery branch July 12, 2026 09:55
AviadHayumi added a commit that referenced this pull request Jul 13, 2026
main #132 (native resource discovery) makes the operator recognize built-in
Kubernetes kinds as served, so BatchJob now reports CRDExists=True and Ready=True
like any CRD-backed workload. Drop the builtin special-case in the harness (and the
now-dead builtin field) and remove the two stale known-findings (built-in
CRDExists=False, and the old v1 MPIJob mapping wart - the sample is v2beta1 now).

Verified on a fresh cluster with the #132 operator: JobSet + BatchJob pass 4/4.

Signed-off-by: aviadh <aviad.hayumi@gmail.com>
AviadHayumi added a commit that referenced this pull request Jul 13, 2026
main #132 (native resource discovery) makes the operator recognize built-in
Kubernetes kinds as served, so BatchJob now reports CRDExists=True and Ready=True
like any CRD-backed workload. Drop the builtin special-case in the harness (and the
now-dead builtin field) and remove the two stale known-findings (built-in
CRDExists=False, and the old v1 MPIJob mapping wart - the sample is v2beta1 now).

Verified on a fresh cluster with the #132 operator: JobSet + BatchJob pass 4/4.

Signed-off-by: aviadh <aviad.hayumi@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants