Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: check CoreDNS #84

Merged

Conversation

c3y1huang
Copy link
Contributor

Which issue(s) this PR fixes:

Issue longhorn/longhorn#9752

What this PR does / why we need it:

Add GetDeployment.

Special notes for your reviewer:

None

Additional documentation or context

None

@c3y1huang c3y1huang self-assigned this Nov 14, 2024
Copy link

coderabbitai bot commented Nov 14, 2024

Walkthrough

A new function GetDeployment has been added to the kubernetes package, allowing retrieval of a Kubernetes Deployment resource by name and namespace. This function logs the operation and uses the Kubernetes client to fetch the deployment. Additionally, a corresponding test function TestGetDeployment has been introduced to validate the behavior of GetDeployment, including scenarios for successful retrieval and handling of "not found" errors.

Changes

File Change Summary
kubernetes/deployment.go Added function GetDeployment(kubeClient, namespace, name string) (*appsv1.Deployment, error)
kubernetes/deployment_test.go Added test function TestGetDeployment(c *C) to validate GetDeployment behavior with various test cases.

Assessment against linked issues

Objective Addressed Explanation
The DR volume should reattach to an available node and continue the restore process without entering a faulted state (#9752). The changes do not address the DR volume issue.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between cffd797 and 6c1c43e.

📒 Files selected for processing (2)
  • kubernetes/deployment.go (1 hunks)
  • kubernetes/deployment_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • kubernetes/deployment.go
  • kubernetes/deployment_test.go

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@c3y1huang c3y1huang force-pushed the 9752-dr-volume-faulted-after-node-reboot branch 3 times, most recently from 6000072 to baee524 Compare November 14, 2024 02:59
@c3y1huang
Copy link
Contributor Author

@coderabbitai review

Copy link

coderabbitai bot commented Nov 14, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

codecov bot commented Nov 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.69%. Comparing base (a58ee3e) to head (6c1c43e).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #84      +/-   ##
==========================================
+ Coverage   77.58%   77.69%   +0.10%     
==========================================
  Files          35       36       +1     
  Lines        1932     1941       +9     
==========================================
+ Hits         1499     1508       +9     
  Misses        317      317              
  Partials      116      116              
Flag Coverage Δ
unittests 77.69% <100.00%> (+0.10%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (3)
kubernetes/deployment.go (1)

20-20: Consider using Info level for resource operations.

Since this function is crucial for DR operations, consider using log.Info instead of log.Trace. This will provide better visibility into resource operations during critical scenarios.

-    log.Trace("Getting resource")
+    log.Info("Getting resource")
kubernetes/deployment_test.go (2)

24-42: Fix inconsistent test case naming.

The test case key "GetDeployment(...):" has a trailing colon which is inconsistent with typical test case naming conventions.

Consider this improvement:

 testCases := map[string]testCase{
-    "GetDeployment(...):": {
+    "should get existing deployment": {
     // ...
     },
-    "GetDeployment(...): not found": {
+    "should handle non-existent deployment": {
     // ...
     },
 }

16-42: Consider adding more test cases for better coverage.

The current test cases only cover basic success and not-found scenarios. Consider adding test cases for:

  • Different namespaces
  • Invalid namespace names
  • Invalid deployment names
  • Context cancellation scenarios
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 614ae31 and baee524.

📒 Files selected for processing (2)
  • kubernetes/deployment.go (1 hunks)
  • kubernetes/deployment_test.go (1 hunks)
🔇 Additional comments (4)
kubernetes/deployment.go (2)

1-11: LGTM! Well-organized imports and package declaration.

The imports are properly organized and include all necessary dependencies for Kubernetes client operations and logging.


13-23: Verify CoreDNS-specific usage of this function.

Since this PR is titled "feat: check CoreDNS", let's verify how this function is used in relation to CoreDNS operations.

kubernetes/deployment_test.go (2)

1-14: LGTM! Imports are well-organized and necessary.

The package name and imports are appropriate for a Kubernetes deployment test file.


53-53: Verify the GetDeployment function implementation.

The test assumes the existence of a GetDeployment function. Let's verify its implementation.

✅ Verification successful

GetDeployment function is properly implemented

The function is correctly implemented in kubernetes/deployment.go:

  • Takes the required parameters: kubeClient, namespace, and name
  • Uses the Kubernetes client's AppsV1 API to get the deployment
  • Returns the deployment object and error as expected
  • Includes appropriate logging
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the GetDeployment function implementation
ast-grep --pattern 'func GetDeployment($_, $_, $_) {
  $$$
}'

Length of output: 63


Script:

#!/bin/bash
# Let's try a broader search for GetDeployment using ripgrep
rg "GetDeployment" -A 5

Length of output: 2042


Script:

#!/bin/bash
# Let's see the full implementation of GetDeployment function
cat kubernetes/deployment.go

Length of output: 672

kubernetes/deployment.go Show resolved Hide resolved
kubernetes/deployment_test.go Outdated Show resolved Hide resolved
@c3y1huang c3y1huang force-pushed the 9752-dr-volume-faulted-after-node-reboot branch from baee524 to e111713 Compare November 14, 2024 03:12
@c3y1huang
Copy link
Contributor Author

@coderabbitai review

Copy link

coderabbitai bot commented Nov 14, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
kubernetes/deployment_test.go (2)

16-23: Consider enhancing test coverage with additional test case fields.

The test structure is good, but consider adding fields to test more scenarios:

  • Different deployment specifications (replicas, labels, etc.)
  • Various metadata annotations
  • Update scenarios

Example enhancement:

 type testCase struct {
     deployment     *appsv1.Deployment
     expectNotFound bool
+    // Additional fields for better coverage
+    expectedReplicas *int32
+    withLabels      map[string]string
+    withAnnotations map[string]string
 }

43-61: Consider adding cleanup between test cases.

The test execution is well-structured, but consider adding cleanup between test cases to ensure complete isolation.

 for testName, testCase := range testCases {
     c.Logf("testing kubernetes.%v", testName)
+    // Clean up any existing resources
+    if err := kubeClient.AppsV1().Deployments(testCase.deployment.Namespace).Delete(
+        ctx, testCase.deployment.Name, metav1.DeleteOptions{}); err != nil {
+        if !apierrors.IsNotFound(err) {
+            c.Assert(err, IsNil, Commentf(test.ErrErrorFmt, testName))
+        }
+    }

     // ... rest of the test case ...
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between baee524 and e111713.

📒 Files selected for processing (1)
  • kubernetes/deployment_test.go (1 hunks)
🔇 Additional comments (2)
kubernetes/deployment_test.go (2)

1-14: LGTM! Imports are well-organized and appropriate.

All necessary dependencies are properly imported for testing Kubernetes deployments.


16-61: Verify test coverage for DR volume scenario.

While the test coverage for the GetDeployment function is good, please ensure that this change adequately tests the DR volume reattachment scenario mentioned in issue longhorn/longhorn#9752.

kubernetes/deployment_test.go Show resolved Hide resolved
Copy link
Member

@derekbit derekbit left a comment

Choose a reason for hiding this comment

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

LGTM

@derekbit derekbit force-pushed the 9752-dr-volume-faulted-after-node-reboot branch from e111713 to cffd797 Compare November 17, 2024 04:06
longhorn/longhorn-9752

Signed-off-by: Chin-Ya Huang <[email protected]>
longhorn/longhorn-9752

Signed-off-by: Chin-Ya Huang <[email protected]>
@derekbit derekbit force-pushed the 9752-dr-volume-faulted-after-node-reboot branch from cffd797 to 6c1c43e Compare November 24, 2024 03:49
@derekbit derekbit merged commit d622157 into longhorn:main Nov 24, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants