fix: add nodeclass informer
Reason for Change:
add NodeClass informer to avoid calling apiserver Requirements
- [ ] added unit tests and e2e tests (if applicable).
Issue Fixed:
Notes for Reviewers:
Title
(Describe updated until commit https://github.com/kaito-project/kaito/commit/a8dc670aadd53ff3ee4f3fcf3b179e076cc38445)
Add NodeClass informer and validate cloud provider
Description
-
Added NodeClass informer based on cloud provider
-
Validated cloud provider environment variable
-
Refactored informer setup into separate methods
Changes walkthrough 📝
| Relevant files | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Enhancement |
|
Need help?
Type /help how to ...in the comments thread for any questions about PR-Agent usage.Check out the documentation for more information.
PR Reviewer Guide 🔍
(Review updated until commit https://github.com/kaito-project/kaito/commit/a8dc670aadd53ff3ee4f3fcf3b179e076cc38445)
Here are some key observations to aid the review process:
| ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪ |
| 🧪 No relevant tests |
| 🔒 No security concerns identified |
⚡ Recommended focus areas for reviewEnvironment Variable Check
CLOUD_PROVIDER environment variable is checked in multiple places. Ensure that this check is consistent across the application and that the environment variable is properly documented and set in all deployment environments. |
PR Code Suggestions ✨
Latest suggestions up to a8dc670
Explore these optional code suggestions:
| Category | Suggestion | Impact |
| General |
Log error before returningEnsure consistent error handling by logging the error before returning. pkg/ragengine/controllers/ragengine_controller.go [588-590]
Suggestion importance[1-10]: 6__ Why: Logging the error before returning provides better visibility into what went wrong, improving debugging and monitoring. However, it doesn't fix a functional issue, so the impact is moderate. | Low |
Handle unset environment variableCheck if cmd/ragengine/main.go [122-125]
Suggestion importance[1-10]: 5__ Why: The suggestion adds a check for an empty string before validation, which is a good practice but not strictly necessary since | Low |
Previous suggestions
Suggestions up to commit b6bedf8
| Category | Suggestion | Impact |
| General |
Improve error handlingHandle missing pkg/ragengine/controllers/ragengine_controller.go [588-589]
Suggestion importance[1-10]: 7__ Why: The suggestion improves error handling by using | Medium |
| Possible issue |
Verify exit functionEnsure cmd/ragengine/main.go [122-126]
Suggestion importance[1-10]: 2__ Why: The suggestion asks to verify the implementation of | Low |
Suggestions up to commit aafd16b
| Category | Suggestion | Impact |
| General |
Remove duplicate functionRemove this function as it duplicates the functionality of cmd/ragengine/main.go [187-196]
Suggestion importance[1-10]: 8__ Why: The function | Medium |
Use consistent validationValidate cloud provider using pkg/workspace/controllers/workspace_controller.go [778-780]
Suggestion importance[1-10]: 7__ Why: Using | Medium |
Suggestions up to commit 7b008bd
| Category | Suggestion | Impact |
| General |
Improve error loggingEnsure cmd/ragengine/main.go [123-125]
Suggestion importance[1-10]: 5__ Why: The suggestion enhances the error logging by providing a clear message before calling | Low |
Enhance error message clarityUse a more descriptive error message. pkg/workspace/controllers/workspace_controller.go [778-780]
Suggestion importance[1-10]: 5__ Why: The suggestion improves the clarity of the error message by using | Low |
Suggestions up to commit 7b008bd
| Category | Suggestion | Impact |
| General |
Improve error loggingEnsure cmd/ragengine/main.go [123-125]
Suggestion importance[1-10]: 5__ Why: The suggestion enhances the error logging by providing a clear message before calling | Low |
Enhance error message clarityUse a more descriptive error message. pkg/workspace/controllers/workspace_controller.go [778-780]
Suggestion importance[1-10]: 5__ Why: The suggestion improves the clarity of the error message by using | Low |
Abandon https://github.com/kaito-project/kaito/pull/1059 and file this one, which removed CLOUD_PROVIDER env related change according to the suggestion.
PR Reviewer Guide 🔍
(Review updated until commit 7b008bd)
Here are some key observations to aid the review process:
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪ 🧪 No relevant tests 🔒 No security concerns identified ⚡ Recommended focus areas for review
Possible Issue The
validCloudProviderfunction is duplicated in bothmain.gofiles. It would be better to move this function to a shared utility file to avoid code duplication.Possible Issue The
validCloudProviderfunction is duplicated in bothmain.gofiles. It would be better to move this function to a shared utility file to avoid code duplication.Error Handling The
setupInformersmethod returns an error if theCLOUD_PROVIDERenvironment variable is not set. However, it does not log the error before returning. Consider adding a log statement to provide more context.
@cvvz Can you adopt this AI suggestion? The validCloudProvider function is duplicated in both main.go files. It would be better to move this function to a shared utility file to avoid code duplication. I think pkg/utils/consts is a good place for this.
Added ValidCloudProvider function in utils.common
TBH, I don't think we need an informer for nodeclass for now. It is almost a static configuration and we just read once during controller startup? There is no value to build a watcher for it. And it is only used when we integrate with Karpenter. However, the "FeatureFlagEnsureNodeClass" feature flag is off by default. Even if you want to add an informer, this code needs to be guarded by the feature flag.
we just read once during controller startup
The nodeclass get request is sent as long as it needs to create nodeclaim. The code path is CreateNodeClaim -> CheckNodeClass -> IsNodeClassAvailable -> kubeClient.Get
Also, I agree to apply nodeclass automatically once enable Karpenter rather than check it before create nodeclaim
Should not check nodeclass everytime before creating nodeclaim, instead, check and create node class before reconciliation start. Thus no need for nodeclass informer. I will file another pr for better solution.
Check nodeclass before controller startup to avoid keep checking nodeclass before creating nodeclaim. https://github.com/kaito-project/kaito/pull/1088