Repository navigation
fix native resource discovery. - #132
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughThe 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 ChangesNative GVK Discovery
Module Dependency Updates
Estimated code review effort: 3 (Moderate) | ~25 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
operator/pkg/controller.gooperator/test/integration/controller_test.go
| }, eventuallyTimeout, eventuallyInterval).Should(Succeed()) | ||
| }) | ||
|
|
||
| It("sets CRDExists=True for a built-in GVK with no backing CRD", func() { |
There was a problem hiding this comment.
Semi-Random location for this comment, there are 2 fundamental issues:
- This PR doesn't compile
- 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))
There was a problem hiding this comment.
yes ill add it in the makefile pr
There was a problem hiding this comment.
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
| if r.nativeGVKs[gvk] { | ||
| return true, nil | ||
| } |
There was a problem hiding this comment.
crdExistsForGVK misleading function name - nativeGVKs doesn't belong here or modify name, It's not a CRD 👀 maybe gvkServed
There was a problem hiding this comment.
agreed, servedGvk is more appropriate, i will also change the condition name.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
will be done in another pr.
There was a problem hiding this comment.
@ronlv10 I like even better :)
@shaked-bouktus why not in this PR? seems a bit peculiar to defer this
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>
| return fmt.Errorf("create discovery client: %w", err) | ||
| } | ||
|
|
||
| native, err := discoverNativeGVKs(context.Background(), dc, mgr.GetAPIReader(), mgr.GetLogger()) |
| } | ||
| 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 |
There was a problem hiding this comment.
extract crds.Items[i].Spec to var and use it
| 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()) |
There was a problem hiding this comment.
is it a use case ? why did you add it ?
There was a problem hiding this comment.
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?
| if strings.Contains(res.Name, "/") { | ||
| continue // subresource, e.g. deployments/scale | ||
| } | ||
| if crdBackedGroupKinds[schema.GroupKind{Group: gv.Group, Kind: res.Kind}] { |
There was a problem hiding this comment.
crdBackedGroupKinds -> crdGKs
| if r.nativeGVKs[gvk] { | ||
| return true, nil | ||
| } |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
didn't we agree to rename the condition ?
There was a problem hiding this comment.
will be handled in another pr.
| if r.nativeGVKs[gvk] { | ||
| return true, nil | ||
| } |
There was a problem hiding this comment.
@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() { |
There was a problem hiding this comment.
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
|
|
||
| natives := make(map[schema.GroupVersionKind]bool) | ||
| for _, list := range resourceLists { | ||
| gv, _ := schema.ParseGroupVersion(list.GroupVersion) |
| 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) | ||
| } |
There was a problem hiding this comment.
There's a problem with exiting on any error that is not stale.
Think of scenario:
- helm install
metrics-server - Later,
helm uninstall metrics-serverbut the APIService object (v1beta1.metrics.k8s.io) is NOT deleted - At startup the API layer tries to forward
metrics.k8s.io/v1beta1to 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
| 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 | ||
| } |
There was a problem hiding this comment.
Two passes instead of one, but the slice is tiny so it doesn't matter. Clean and obvious
| 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>
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>
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>
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
git commit -s)make check)Summary by CodeRabbit
Truewhen applicable).Truewithout an associated CRD.