fix(api): skip OpenAPI post-processor for non-apps group versions#2212
Conversation
The OpenAPI PostProcessSpec callback is invoked for every group-version (apps, core, version, etc.), but the Application schema cloning logic only applies to apps.cozystack.io. When called for other GVs the base Application schemas are absent, causing a spurious error log on every API server start. Return early instead of erroring when the base schemas are not found. Co-Authored-By: Claude <[email protected]> Signed-off-by: Andrei Kvapil <[email protected]>
📝 WalkthroughWalkthroughThe OpenAPI post-processors for v3 and v2 schemas in the server command now return early without patching when essential base schemas are absent, instead of raising an error. This simplifies the error handling logic while maintaining the unchanged patching flow for other scenarios. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a recurring spurious error log during the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request fixes a spurious error message logged during API server startup. The error occurs because the OpenAPI post-processor, which is designed for the apps.cozystack.io group version, was also being executed for other group versions where the necessary base schemas are not present. The fix is to make the post-processor return early without an error if the base schemas are not found. The change is correct in fixing the log spam. However, I've added a couple of comments pointing out that this approach could potentially mask a real problem if the base schemas were missing for the apps group version itself, leading to a silent failure. This is a trade-off between log noise and error reporting robustness.
| stat, ok3 := doc.Components.Schemas[baseStatusRef] | ||
| if !(ok1 && ok2 && ok3) && len(kindSchemas) > 0 { | ||
| return doc, fmt.Errorf("base Application* schemas not found") | ||
| if !(ok1 && ok2 && ok3) { |
There was a problem hiding this comment.
This change effectively silences the error when base schemas are not found, which fixes the issue for non-apps group versions. However, this introduces a potential for silent failures. If the base schemas are missing for the apps group version due to an underlying issue (e.g., a code generation problem), this will no longer be reported as an error. The server would start, but the OpenAPI specification for all dynamic application kinds would be incorrect. This could make issues harder to debug in the future.
| stat, ok3 := defs[baseStatusRef] | ||
| if !(ok1 && ok2 && ok3) && len(kindSchemas) > 0 { | ||
| return sw, fmt.Errorf("base Application* schemas not found") | ||
| if !(ok1 && ok2 && ok3) { |
There was a problem hiding this comment.
When dependencies are not ready the reconciler returned without requeueing, relying solely on watch events to re-trigger. If a watch event was missed (controller restart, race condition, dependency already ready before watch setup), the package would stay stuck in DependenciesNotReady forever. Add RequeueAfter: 30s so dependencies are periodically rechecked. Co-Authored-By: Claude <[email protected]> Signed-off-by: Andrei Kvapil <[email protected]>
This reverts commit f906a0d. Signed-off-by: Andrei Kvapil <[email protected]>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/cmd/server/openapi.go (1)
227-229: Differentiate “non-apps GV” from “partially broken base schemas.”Good direction to no-op for non-apps group-versions, but the current guard also silently skips when only some base Application schemas are present. That can hide malformed apps OpenAPI state. Consider: all missing ⇒ no-op; partial missing ⇒ return error.
Suggested guard split (v3 + v2)
- if !(ok1 && ok2 && ok3) { - return doc, nil // not the apps GV — nothing to patch - } + if !ok1 && !ok2 && !ok3 { + return doc, nil // not the apps GV — nothing to patch + } + if !(ok1 && ok2 && ok3) { + return nil, fmt.Errorf("incomplete base Application schemas: Application=%t, ApplicationList=%t, ApplicationStatus=%t", ok1, ok2, ok3) + }- if !(ok1 && ok2 && ok3) { - return sw, nil // not the apps GV — nothing to patch - } + if !ok1 && !ok2 && !ok3 { + return sw, nil // not the apps GV — nothing to patch + } + if !(ok1 && ok2 && ok3) { + return nil, fmt.Errorf("incomplete base Application schemas: Application=%t, ApplicationList=%t, ApplicationStatus=%t", ok1, ok2, ok3) + }Also applies to: 342-344
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/cmd/server/openapi.go` around lines 227 - 229, The current guard (using ok1, ok2, ok3) treats any missing base Application schema the same as the apps group-version being absent; change it so that if all three (ok1, ok2, ok3) are false you still return doc, nil (no-op), but if at least one is true and not all are true then return a descriptive error about partially missing base schemas to surface malformed OpenAPI state; update the same logic at the other occurrence (the block around the 342-344 equivalent) and ensure the error message names the missing pieces so callers can diagnose which of ok1/ok2/ok3 (the base Application schemas) are absent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@pkg/cmd/server/openapi.go`:
- Around line 227-229: The current guard (using ok1, ok2, ok3) treats any
missing base Application schema the same as the apps group-version being absent;
change it so that if all three (ok1, ok2, ok3) are false you still return doc,
nil (no-op), but if at least one is true and not all are true then return a
descriptive error about partially missing base schemas to surface malformed
OpenAPI state; update the same logic at the other occurrence (the block around
the 342-344 equivalent) and ensure the error message names the missing pieces so
callers can diagnose which of ok1/ok2/ok3 (the base Application schemas) are
absent.
|
Successfully created backport PR for |
|
Successfully created backport PR for |
What this PR does
The OpenAPI
PostProcessSpeccallback is invoked for every registeredgroup-version (apps, core, version, etc.), but the Application schema
cloning logic only applies to
apps.cozystack.io. When called for otherGVs the base Application schemas are absent, producing a spurious error
on every API server start:
This PR changes the post-processor (both v2 and v3) to return early
when the base schemas are not found, instead of returning an error.
Release note
Summary by CodeRabbit