Skip to content

fix(substrate): degrade gracefully when ate.dev CRDs are absent#2023

Open
QuentinBisson wants to merge 3 commits into
kagent-dev:mainfrom
QuentinBisson:fix/substrate-status-no-match-error
Open

fix(substrate): degrade gracefully when ate.dev CRDs are absent#2023
QuentinBisson wants to merge 3 commits into
kagent-dev:mainfrom
QuentinBisson:fix/substrate-status-no-match-error

Conversation

@QuentinBisson

Copy link
Copy Markdown

What

GET /api/substrate/status returns 500 on clusters that don't have the
agent-substrate CRDs installed (ate.dev/v1alpha1 WorkerPool / ActorTemplate).

listSubstrateCRs calls KubeClient.List on both types unconditionally. When the
CRDs are absent the REST mapper returns *meta.NoKindMatchError, which propagates as
HTTP 500. Since substrate is optional and Enabled is already gated on AteClient != nil, the correct behaviour is to return an empty list.

Fix

Guard both List calls with meta.IsNoMatchError and return nil, nil, nil (empty
result, no error) so the handler responds 200 with Enabled: false and empty slices.

A regression test (TestHandleGetSubstrateStatus_NoCRDs) covers the no-CRD path using
a stub client that returns *meta.NoKindMatchError, asserting HTTP 200 with
Enabled: false and empty resource slices.

Reported in giantswarm/giantswarm#36845.

GET /api/substrate/status returned 500 on clusters without the ate.dev CRDs
installed because listSubstrateCRs listed WorkerPool/ActorTemplate
unconditionally, propagating the REST mapper NoKindMatchError as a server
error.

Gate the CRD listing loop on AteClient != nil. When substrate is not
configured (the common case), there is nothing to list and no CRD calls
are made. When substrate is configured, a missing CRD is a legitimate
misconfiguration and the error is surfaced as before.

Reported in giantswarm/giantswarm#36845.

Signed-off-by: QuentinBisson <quentin@giantswarm.io>
@QuentinBisson QuentinBisson force-pushed the fix/substrate-status-no-match-error branch from a96374e to d32223c Compare June 15, 2026 22:04
@QuentinBisson QuentinBisson marked this pull request as ready for review June 15, 2026 22:06
Copilot AI review requested due to automatic review settings June 15, 2026 22:06

Copilot AI 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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR updates the substrate status endpoint to avoid listing Kubernetes substrate CRs when the substrate isn’t configured (i.e., AteClient is nil), and adds a regression test for that behavior.

Changes:

  • Guard Kubernetes CR listing behind h.AteClient != nil in HandleGetSubstrateStatus.
  • Add a new test asserting the “substrate not configured” response shape.
  • Introduce a minimal client.Client stub intended to simulate missing CRDs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
go/core/internal/httpserver/handlers/substrate.go Skips listing substrate CRs unless AteClient is configured.
go/core/internal/httpserver/handlers/substrate_test.go Adds a “not configured” test and a kube client stub for simulating missing CRDs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +28 to +49
// noMatchKubeClient is a minimal client.Client stub whose List always returns
// a *meta.NoKindMatchError, simulating a cluster where the ate.dev CRDs are absent.
type noMatchKubeClient struct {
client.Client
}

func (noMatchKubeClient) List(_ context.Context, _ client.ObjectList, _ ...client.ListOption) error {
return &apimeta.NoKindMatchError{}
}

// TestHandleGetSubstrateStatus_SubstrateNotConfigured verifies that when AteClient is nil
// (substrate not configured), the endpoint returns 200 with Enabled:false and empty slices
// without making any CRD List calls.
func TestHandleGetSubstrateStatus_SubstrateNotConfigured(t *testing.T) {
t.Parallel()

scheme := runtime.NewScheme()
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
fakeClient := fake.NewClientBuilder().WithScheme(scheme).Build()

base := &handlers.Base{KubeClient: fakeClient, Authorizer: &auth.NoopAuthorizer{}}
h := handlers.NewSubstrateHandler(base, nil)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed.

Comment on lines 65 to 78
if h.AteClient != nil {
for _, ns := range namespaces {
wpEntries, tmplEntries, err := h.listSubstrateCRs(r.Context(), ns)
if err != nil {
log.Error(err, "list substrate CRs", "namespace", ns)
w.RespondWithError(errors.NewInternalServerError("Failed to list substrate resources from Kubernetes", err))
return
}
resp.WorkerPools = append(resp.WorkerPools, wpEntries...)
resp.ActorTemplates = append(resp.ActorTemplates, tmplEntries...)
}
resp.WorkerPools = append(resp.WorkerPools, wpEntries...)
resp.ActorTemplates = append(resp.ActorTemplates, tmplEntries...)
}

if h.AteClient != nil {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed.

Comment on lines +65 to 68
}


type stubAteControl struct {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed.

- Merge the two consecutive AteClient != nil blocks into one
- Use noMatchKubeClient in the not-configured test so the test
  would fail if the gate were removed (the error would propagate
  as 500 rather than the guarded nil path)
- Remove extra blank line before stubAteControl

Signed-off-by: QuentinBisson <quentin@giantswarm.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants