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

fix: namespace was not found but working #468

Merged
merged 4 commits into from
Jul 5, 2024

Conversation

mojtaba-esk
Copy link
Contributor

@mojtaba-esk mojtaba-esk commented Jul 1, 2024

Closes #463

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling for namespace operations, ensuring more accurate feedback on errors.
  • Tests

    • Enhanced test cases for namespace operations, including more robust error assertions and simplified mocking setups.

@mojtaba-esk mojtaba-esk requested a review from a team July 1, 2024 14:39
@mojtaba-esk mojtaba-esk self-assigned this Jul 1, 2024
Copy link
Contributor

coderabbitai bot commented Jul 1, 2024

Warning

Rate limit exceeded

@mojtaba-esk has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 16 minutes and 53 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 1206cc1 and 989af11.

Walkthrough

The primary change in pkg/k8s/k8s_namespace.go involves enhancing the GetNamespace and NamespaceExists functions for better error handling. Corresponding modifications were made in pkg/k8s/k8s_namespace_test.go to update test cases, streamline mocking, and improve error assertions. These changes aim to resolve issues where namespaces were reported as not found even though they existed.

Changes

Files Change Summary
pkg/k8s/k8s_namespace.go Modified GetNamespace function for direct result return and restructured NamespaceExists error handling.
pkg/k8s/k8s_namespace_test.go Updated test cases, simplified mocking, and revised error assertions using a new assertErr function.

Assessment against linked issues

Objective Addressed Explanation
Error that namespace was not found but namespace exists (#463)

Poem

🐇 In code's embrace, namespaces hide,
Changes made with testing as our guide.
Errors caught, assertions tight,
Bugs are vanquished in the night.
K8s sings a smoother tune,
With fixes dawned by code's bright moon. 🌙


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@celestia-bot celestia-bot requested review from tty47, MSevey and smuu July 1, 2024 14:39
@mojtaba-esk mojtaba-esk enabled auto-merge July 1, 2024 14:41
Copy link
Contributor

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 73b30c8 and 9304b86.

Files selected for processing (2)
  • pkg/k8s/k8s_namespace.go (1 hunks)
  • pkg/k8s/k8s_namespace_test.go (6 hunks)
Additional comments not posted (8)
pkg/k8s/k8s_namespace.go (4)

Line range hint 8-15: LGTM!

The CreateNamespace function correctly handles the creation of a namespace and accounts for the case where the namespace already exists.


Line range hint 17-22: LGTM!

The DeleteNamespace function correctly handles the deletion of a namespace and wraps errors appropriately.


Line range hint 24-24: LGTM!

The GetNamespace function correctly returns the namespace using the Kubernetes client.


42-54: LGTM!

The NamespaceExists function correctly checks for the existence of a namespace and logs different error conditions appropriately.

pkg/k8s/k8s_namespace_test.go (4)

Line range hint 11-46: LGTM!

The TestCreateNamespace function correctly tests various scenarios for namespace creation, including successful creation, namespace already existing, and client errors.


Line range hint 48-82: LGTM!

The TestDeleteNamespace function correctly tests various scenarios for namespace deletion, including successful deletion, namespace not found, and client errors.


Line range hint 130-187: LGTM!

The TestGetNamespace function correctly tests various scenarios for namespace retrieval, including successful retrieval, namespace not found, and client errors. The use of the assertErr function improves error handling and assertions.


Line range hint 189-218: LGTM!

The TestNamespaceExists function correctly tests various scenarios for checking namespace existence, including namespace existing, namespace not existing, and client errors.

MSevey
MSevey previously approved these changes Jul 1, 2024
Copy link
Member

@MSevey MSevey left a comment

Choose a reason for hiding this comment

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

For the future, when the issue itself doesn't have much info, please add some more context to the PR description around the reason for the bug and update logic change to help with the review.

From my review I'm assuming the issue was that all errors were being treated as the namespace not existing and this PR separates those error conditions.

If my assumption is wrong, please lmk.

@mojtaba-esk
Copy link
Contributor Author

For the future, when the issue itself doesn't have much info, please add some more context to the PR description around the reason for the bug and update logic change to help with the review.

From my review I'm assuming the issue was that all errors were being treated as the namespace not existing and this PR separates those error conditions.

If my assumption is wrong, please lmk.

The issue was when the namespace does not exist, the error was wrapped and could not be matched using k8s api error package therefore it returned the error. It was working, but it was showing that error.
Now the error returned by GetNamespace is not wrapped, so it can be matched.

tty47
tty47 previously approved these changes Jul 2, 2024
@smuu smuu disabled auto-merge July 5, 2024 08:30
@mojtaba-esk mojtaba-esk dismissed stale reviews from tty47 and MSevey via 1206cc1 July 5, 2024 08:33
Copy link
Contributor

@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: 4

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9304b86 and 1206cc1.

Files selected for processing (2)
  • pkg/k8s/k8s_namespace.go (1 hunks)
  • pkg/k8s/k8s_namespace_test.go (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • pkg/k8s/k8s_namespace_test.go
Additional context used
GitHub Check: test (./e2e/bittwister, 60m)
pkg/k8s/k8s_namespace.go

[failure] 46-46:
not enough return values


[failure] 49-49:
undefined: errors


[failure] 51-51:
not enough return values


[failure] 55-55:
not enough return values

GitHub Check: test (./e2e/system, 15m)
pkg/k8s/k8s_namespace.go

[failure] 46-46:
not enough return values


[failure] 49-49:
undefined: errors


[failure] 51-51:
not enough return values


[failure] 55-55:
not enough return values

GitHub Check: Run govulncheck
pkg/k8s/k8s_namespace.go

[failure] 46-46:
not enough return values


[failure] 49-49:
undefined: errors


[failure] 51-51:
not enough return values


[failure] 55-55:
not enough return values

GitHub Check: test (./e2e/basic, 15m)
pkg/k8s/k8s_namespace.go

[failure] 46-46:
not enough return values


[failure] 49-49:
undefined: errors


[failure] 51-51:
not enough return values


[failure] 55-55:
not enough return values

GitHub Check: test (./pkg/..., 10m)
pkg/k8s/k8s_namespace.go

[failure] 46-46:
not enough return values


[failure] 49-49:
undefined: errors


[failure] 51-51:
not enough return values


[failure] 55-55:
not enough return values


[failure] 46-46:
not enough return values


[failure] 49-49:
undefined: errors


[failure] 51-51:
not enough return values


[failure] 55-55:
not enough return values

GitHub Check: golangci-lint
pkg/k8s/k8s_namespace.go

[failure] 46-46:
not enough return values


[failure] 49-49:
undefined: errors


[failure] 51-51:
not enough return values


[failure] 55-55:
not enough return values


[failure] 46-46:
not enough return values


[failure] 49-49:
undefined: errors


[failure] 51-51:
not enough return values


[failure] 55-55:
not enough return values

Additional comments not posted (1)
pkg/k8s/k8s_namespace.go (1)

Line range hint 38-40:
LGTM!

The simplification of the GetNamespace function to directly return the result of the client call is appropriate and aligns with the PR objectives.

Tools
GitHub Check: test (./e2e/bittwister, 60m)

[failure] 46-46:
not enough return values


[failure] 49-49:
undefined: errors


[failure] 51-51:
not enough return values


[failure] 55-55:
not enough return values

GitHub Check: test (./e2e/system, 15m)

[failure] 46-46:
not enough return values


[failure] 49-49:
undefined: errors


[failure] 51-51:
not enough return values


[failure] 55-55:
not enough return values

GitHub Check: Run govulncheck

[failure] 46-46:
not enough return values


[failure] 49-49:
undefined: errors


[failure] 51-51:
not enough return values


[failure] 55-55:
not enough return values

GitHub Check: test (./e2e/basic, 15m)

[failure] 46-46:
not enough return values


[failure] 49-49:
undefined: errors


[failure] 51-51:
not enough return values


[failure] 55-55:
not enough return values

GitHub Check: test (./pkg/..., 10m)

[failure] 46-46:
not enough return values


[failure] 49-49:
undefined: errors


[failure] 51-51:
not enough return values


[failure] 55-55:
not enough return values


[failure] 46-46:
not enough return values


[failure] 49-49:
undefined: errors


[failure] 51-51:
not enough return values


[failure] 55-55:
not enough return values

GitHub Check: golangci-lint

[failure] 46-46:
not enough return values


[failure] 49-49:
undefined: errors


[failure] 51-51:
not enough return values


[failure] 55-55:
not enough return values


[failure] 46-46:
not enough return values


[failure] 49-49:
undefined: errors


[failure] 51-51:
not enough return values


[failure] 55-55:
not enough return values

pkg/k8s/k8s_namespace.go Outdated Show resolved Hide resolved
pkg/k8s/k8s_namespace.go Outdated Show resolved Hide resolved
pkg/k8s/k8s_namespace.go Outdated Show resolved Hide resolved
pkg/k8s/k8s_namespace.go Outdated Show resolved Hide resolved
@smuu smuu merged commit 553c855 into main Jul 5, 2024
6 of 11 checks passed
@smuu smuu deleted the mojtaba/463-namespace-was-not-found branch July 5, 2024 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Error that namespace was not found but namespace exists and test is able to run
4 participants