kaito icon indicating copy to clipboard operation
kaito copied to clipboard

chore: simplify the manifests generation code and add ut

Open cvvz opened this issue 8 months ago • 9 comments

Reason for Change:

chore: clean up the code and add ut for generating manifests Requirements

  • [x] added unit tests and e2e tests (if applicable).

Issue Fixed:

Notes for Reviewers:

cvvz avatar Apr 25 '25 14:04 cvvz

Title

(Describe updated until commit https://github.com/kaito-project/kaito/commit/04e5f1f07b636a8bc37e38854c520e89de1279b6)

Simplify Manifest Generation and Enhance Unit Tests


Description

  • Simplified manifest generation code by removing unused ctx parameters

  • Added comprehensive unit tests for manifest generation functions

  • Enhanced owner reference verification in tests


Changes walkthrough 📝

Relevant files
Enhancement
8 files
preset-rag.go
Removed unused ctx parameter                                                         
+1/-1     
ragengine_controller.go
Removed unused ctx parameter                                                         
+1/-1     
manifests.go
Removed unused ctx parameter and controller variable         
+4/-20   
workspace_controller.go
Removed unused ctx parameter                                                         
+2/-2     
preset-inferences.go
Removed unused ctx parameter                                                         
+2/-2     
template_inference.go
Removed unused ctx parameter                                                         
+1/-1     
manifests.go
Removed unused ctx parameter and controller variable         
+12/-51 
preset-tuning.go
Removed unused ctx parameter                                                         
+1/-1     
Tests
3 files
manifests_test.go
Updated tests to remove ctx parameter and verify owner references
+88/-2   
testUtils.go
Added UID to mock objects for testing                                       
+3/-0     
manifests_test.go
Updated tests to remove ctx parameter and verify owner references
+46/-6   

Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • kaito-pr-agent[bot] avatar Apr 25 '25 14:04 kaito-pr-agent[bot]

    PR Reviewer Guide 🔍

    (Review updated until commit https://github.com/kaito-project/kaito/commit/04e5f1f07b636a8bc37e38854c520e89de1279b6)

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Possible Issue

    The GenerateRAGServiceManifest function does not set any ports for the service. This might lead to a service that cannot route traffic correctly.

    		accessSecret := ragEngineObj.Spec.Embedding.Local.ModelAccessSecret
    		accessSecretEnv := corev1.EnvVar{
    			Name:  "ACCESS_SECRET",
    			Value: accessSecret,
    		}
    		envs = append(envs, accessSecretEnv)
    	}
    } else if ragEngineObj.Spec.Embedding.Remote != nil {
    	embeddingType = "remote"
    
    Possible Issue

    The GenerateServiceManifest function sets a fixed port configuration (http, 80, 5000) which might not be suitable for all use cases. Consider making this configurable.

    	Namespace: workspaceObj.Namespace,
    	OwnerReferences: []v1.OwnerReference{
    		*v1.NewControllerRef(workspaceObj, kaitov1beta1.GroupVersion.WithKind("Workspace")),
    	},
    },
    Spec: appsv1.StatefulSetSpec{
    	Replicas:            lo.ToPtr(int32(replicas)),
    	PodManagementPolicy: appsv1.ParallelPodManagement,
    

    kaito-pr-agent[bot] avatar Apr 25 '25 14:04 kaito-pr-agent[bot]

    PR Code Suggestions ✨

    Latest suggestions up to 343b5b0

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Check for nil ragObj

    Ensure that ragObj is not nil before creating the controller reference to prevent
    potential runtime errors.

    pkg/ragengine/manifests/manifests.go [45]

    -*v1.NewControllerRef(ragObj, kaitov1alpha1.GroupVersion.WithKind("RAGEngine")),
    +if ragObj != nil {
    +    *v1.NewControllerRef(ragObj, kaitov1alpha1.GroupVersion.WithKind("RAGEngine"))
    +} else {
    +    // Handle the case where ragObj is nil
    +}
    
    Suggestion importance[1-10]: 8

    __

    Why: Ensuring ragObj is not nil prevents potential runtime errors when creating the controller reference, which is critical for maintaining the stability of the application.

    Medium
    Check for nil workspaceObj

    Ensure that workspaceObj is not nil before creating the controller reference to
    prevent potential runtime errors.

    pkg/workspace/manifests/manifests.go [130]

    -*v1.NewControllerRef(workspaceObj, kaitov1beta1.GroupVersion.WithKind("Workspace")),
    +if workspaceObj != nil {
    +    *v1.NewControllerRef(workspaceObj, kaitov1beta1.GroupVersion.WithKind("Workspace"))
    +} else {
    +    // Handle the case where workspaceObj is nil
    +}
    
    Suggestion importance[1-10]: 8

    __

    Why: Ensuring workspaceObj is not nil prevents potential runtime errors when creating the controller reference, which is critical for maintaining the stability of the application.

    Medium

    Previous suggestions

    Suggestions up to commit 9a62b70
    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Check for nil ragObj

    Ensure that ragObj is not nil before creating the controller reference.

    pkg/ragengine/manifests/manifests.go [45]

    -*v1.NewControllerRef(ragObj, kaitov1alpha1.GroupVersion.WithKind("RAGEngine")),
    +if ragObj != nil {
    +    *v1.NewControllerRef(ragObj, kaitov1alpha1.GroupVersion.WithKind("RAGEngine"))
    +} else {
    +    // Handle the case where ragObj is nil
    +}
    
    Suggestion importance[1-10]: 3

    __

    Why: While checking for nil ragObj is a good practice, the current context does not suggest that ragObj can be nil. This check might be unnecessary unless there is a specific scenario where ragObj could be nil, which is not evident from the provided code diff.

    Low
    Check for nil workspaceObj

    Ensure that workspaceObj is not nil before creating the controller reference.

    pkg/workspace/manifests/manifests.go [130]

    -*v1.NewControllerRef(workspaceObj, kaitov1beta1.GroupVersion.WithKind("Workspace")),
    +if workspaceObj != nil {
    +    *v1.NewControllerRef(workspaceObj, kaitov1beta1.GroupVersion.WithKind("Workspace"))
    +} else {
    +    // Handle the case where workspaceObj is nil
    +}
    
    Suggestion importance[1-10]: 3

    __

    Why: Similar to the first suggestion, checking for nil workspaceObj is a good practice but does not seem necessary based on the current context. The code does not indicate any scenario where workspaceObj could be nil.

    Low
    Suggestions
    CategorySuggestion                                                                                                                                    Impact
    General
    Remove unused variable

    Remove unused variable controller.

    pkg/ragengine/manifests/manifests.go [13]

    -var controller = true
    +...
    
    Suggestion importance[1-10]: 5

    __

    Why: The variable controller is declared but never used in the code. Removing it improves code cleanliness and maintainability.

    Low

    kaito-pr-agent[bot] avatar Apr 25 '25 14:04 kaito-pr-agent[bot]

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Remove unused variable

    Remove unused variable controller.

    pkg/ragengine/manifests/manifests.go [13]

    -var controller = true
    +...
    
    Suggestion importance[1-10]: 5

    __

    Why: The variable controller is declared but never used in the code. Removing it improves code cleanliness and maintainability.

    Low

    kaito-pr-agent[bot] avatar Apr 25 '25 14:04 kaito-pr-agent[bot]

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Remove unused variable

    Remove unused variable controller.

    pkg/ragengine/manifests/manifests.go [13]

    -var controller = true
    +...
    
    Suggestion importance[1-10]: 5

    __

    Why: The variable controller is declared but never used in the code. Removing it improves code cleanliness and maintainability.

    Low

    kaito-pr-agent[bot] avatar Apr 25 '25 14:04 kaito-pr-agent[bot]

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Remove unused variable

    Remove unused variable controller.

    pkg/ragengine/manifests/manifests.go [13]

    -var controller = true
    +...
    
    Suggestion importance[1-10]: 5

    __

    Why: The variable controller is declared but never used in the code. Removing it improves code cleanliness and maintainability.

    Low

    kaito-pr-agent[bot] avatar Apr 26 '25 03:04 kaito-pr-agent[bot]

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Remove unused variable

    Remove unused variable controller.

    pkg/ragengine/manifests/manifests.go [13]

    -var controller = true
    +...
    
    Suggestion importance[1-10]: 5

    __

    Why: The variable controller is declared but never used in the code. Removing it improves code cleanliness and maintainability.

    Low

    kaito-pr-agent[bot] avatar Apr 27 '25 00:04 kaito-pr-agent[bot]

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Remove unused variable

    Remove unused variable controller.

    pkg/ragengine/manifests/manifests.go [13]

    -var controller = true
    +...
    
    Suggestion importance[1-10]: 5

    __

    Why: The variable controller is declared but never used in the code. Removing it improves code cleanliness and maintainability.

    Low

    kaito-pr-agent[bot] avatar Apr 27 '25 01:04 kaito-pr-agent[bot]

    PR Code Suggestions ✨

    No code suggestions found for the PR.

    kaito-pr-agent[bot] avatar Apr 27 '25 02:04 kaito-pr-agent[bot]

    Merging is blocked Commits must have verified signatures.

    Unable to merge, can you check this? Make sure all of your commits are verified.

    ref https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification

    zhuangqh avatar Apr 29 '25 02:04 zhuangqh

    @zhuangqh I've squashed the commits, please take another look.

    cvvz avatar Apr 29 '25 03:04 cvvz

    PR Code Suggestions ✨

    No code suggestions found for the PR.

    kaito-pr-agent[bot] avatar Apr 29 '25 03:04 kaito-pr-agent[bot]