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

add webhook port checker to e2e tests #268

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aobort
Copy link
Collaborator

@aobort aobort commented Sep 30, 2024

This PR adds additional check whether etcd-operator webhook is ready and accepts connections.

Summary by CodeRabbit

  • New Features

    • Introduced a new webhook-checker Pod to ensure the readiness of the etcd-operator webhook before running end-to-end tests.
    • Added a procedure in the test setup to wait for the webhook to become operational, enhancing test reliability.
  • Bug Fixes

    • Improved the robustness of end-to-end tests by ensuring the webhook is ready before executing test cases.

Signed-off-by: Artem Bortnikov <artem.bortnikov@telekom.com>
Copy link

coderabbitai bot commented Sep 30, 2024

Walkthrough

The changes introduce a new readiness check for the etcd-operator webhook in the end-to-end tests. This is achieved by adding a webhook-checker Pod that performs a curl request to ensure the webhook service is operational. The test suite is modified to include a wait step for this readiness before executing existing test scenarios, which include various deployment configurations.

Changes

Files Change Summary
test/e2e/e2e_test.go Added a step in the BeforeAll section to wait for the etcd-operator webhook readiness.
test/e2e/webhook-checker.yaml Introduced a new Pod configuration for webhook-checker with a readiness probe for the webhook.

Poem

In the garden where we play,
A webhook waits, no delay.
With curl in hand, we check the flow,
Ensuring all is set to go!
Hops of joy, the tests align,
In code we trust, our work will shine! 🐇✨


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.

CodeRabbit Configuration 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.

@aobort aobort marked this pull request as ready for review September 30, 2024 14:00
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: 3

🧹 Outside diff range and nitpick comments (1)
test/e2e/webhook-checker.yaml (1)

7-13: Consider reducing the sleep duration.

The container specification looks good overall, using an appropriate curl image for network checking. However, the sleep duration of 360 seconds (6 minutes) might be longer than necessary for e2e tests.

Consider reducing the sleep duration to a shorter time, such as 120 seconds (2 minutes). This should still provide ample time for the readiness probe to function while potentially speeding up the e2e test execution. For example:

      command:
        - sh
        - -c
-        - "sleep 360"
+        - "sleep 120"

This change could help optimize the test execution time without compromising the functionality of the webhook checker.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e00e6cb and 74a4e91.

📒 Files selected for processing (2)
  • test/e2e/e2e_test.go (1 hunks)
  • test/e2e/webhook-checker.yaml (1 hunks)
🔇 Additional comments (3)
test/e2e/webhook-checker.yaml (2)

1-5: LGTM: Metadata section is well-defined.

The metadata section correctly defines a Pod resource in the "etcd-operator-system" namespace, which aligns with the PR objectives of adding a webhook port checker to e2e tests.


1-20: Overall assessment: Good implementation with minor suggestions for improvement.

This new webhook-checker Pod configuration aligns well with the PR objectives of enhancing e2e tests for the etcd-operator webhook. The implementation is generally sound, providing a way to verify the webhook's readiness before proceeding with other tests.

Key points:

  1. The Pod is correctly defined in the etcd-operator-system namespace.
  2. It uses an appropriate curl image for network checking.
  3. The readiness probe is well-structured to check the webhook service availability.

Consider the suggestions in the previous comments to further optimize and secure this implementation:

  1. Reduce the sleep duration for potentially faster e2e test execution.
  2. Address the SSL certificate validation in the readiness probe.
  3. Add failureThreshold and successThreshold to the readiness probe for more precise control.

These improvements will enhance the robustness and efficiency of the webhook checking process in your e2e tests.

test/e2e/e2e_test.go (1)

65-75: Verify the necessity of the webhook for all tests.

The webhook readiness check has been added as a prerequisite step in the BeforeAll function. While this ensures the webhook is ready before any tests run, it's important to confirm that the webhook is indeed necessary for all the subsequent tests in this file.

Could you please clarify:

  1. Is the webhook required for all the test scenarios (PVC resizing, emptyDir deployment, and TLS with auth)?
  2. If not, would it be more appropriate to move this check to specific test contexts where it's needed?

This will help ensure that the tests are efficient and only perform necessary setup steps.

To help verify the webhook usage, please run the following command to search for webhook-related code in the project:

#!/bin/bash
# Search for webhook-related code in Go files
rg --type go "webhook" .

Comment on lines +14 to +20
readinessProbe:
exec:
command:
- sh
- -c
- "curl -k https://etcd-operator-webhook-service/mutate-etcd-aenix-io-v1alpha1-etcdcluster"
periodSeconds: 5
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding failureThreshold and successThreshold to the readiness probe.

The readiness probe checks every 5 seconds, which is a good interval. However, for more precise control over when the pod is considered ready or not ready, consider adding failureThreshold and successThreshold.

Add these fields to fine-tune the probe behavior:

      readinessProbe:
        exec:
          command:
            - sh
            - -c
            - "curl -k https://etcd-operator-webhook-service/mutate-etcd-aenix-io-v1alpha1-etcdcluster"
        periodSeconds: 5
+       failureThreshold: 3
+       successThreshold: 1

This configuration will consider the pod not ready after 3 consecutive failures and ready after 1 success, providing a balance between responsiveness and stability.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
readinessProbe:
exec:
command:
- sh
- -c
- "curl -k https://etcd-operator-webhook-service/mutate-etcd-aenix-io-v1alpha1-etcdcluster"
periodSeconds: 5
readinessProbe:
exec:
command:
- sh
- -c
- "curl -k https://etcd-operator-webhook-service/mutate-etcd-aenix-io-v1alpha1-etcdcluster"
periodSeconds: 5
failureThreshold: 3
successThreshold: 1

⚠️ Potential issue

Address SSL certificate validation in the readiness probe.

The readiness probe is well-structured to check the webhook service availability. However, the use of the -k flag with curl ignores SSL certificate validation, which could be a security concern.

Consider one of the following options:

  1. If this is intentional due to self-signed certificates in the test environment, add a comment explaining this decision.
  2. If possible, use proper SSL certificates and remove the -k flag for better security practices.

Example of adding a comment:

        exec:
          command:
            - sh
            - -c
-            - "curl -k https://etcd-operator-webhook-service/mutate-etcd-aenix-io-v1alpha1-etcdcluster"
+            - |
+              # Using -k flag due to self-signed certificates in the test environment
+              curl -k https://etcd-operator-webhook-service/mutate-etcd-aenix-io-v1alpha1-etcdcluster

Committable suggestion was skipped due to low confidence.

Comment on lines +65 to +75
By("wait until etcd-operator webhook is ready", func() {
cmd := exec.Command("kubectl", "apply", "-f", "test/e2e/webhook-checker.yaml")
_, err = utils.Run(cmd)
ExpectWithOffset(1, err).NotTo(HaveOccurred())

cmd = exec.Command("kubectl", "wait", "--namespace",
"etcd-operator-system", "pod/webhook-checker",
"--for", "jsonpath={.status.conditions[?(@.type==\"Ready\")].status}=True", "--timeout=5m")
_, err = utils.Run(cmd)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
})
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Webhook-checker.yaml file is missing or inaccessible.

The webhook-checker.yaml referenced in test/e2e/e2e_test.go does not exist or cannot be accessed based on the current context. This will cause the webhook readiness check to fail during the tests.

Recommendations:

  • Add the webhook-checker.yaml file to the test/e2e/ directory with the appropriate configuration for the webhook checker.

  • Verify the file path in the test to ensure it correctly points to the location of webhook-checker.yaml.

  • Update the shell script to accurately display the contents of the file once it is in place to facilitate future reviews.

🔗 Analysis chain

Approve the addition of webhook readiness check with suggestions for improvement.

The new step to check the readiness of the etcd-operator webhook is a valuable addition to the e2e tests, aligning well with the PR objectives. However, there are a few points to consider for improvement:

  1. The webhook-checker.yaml file is not provided in this context. Please include its contents for review to ensure it's correctly configured.

  2. Consider adding a cleanup step for the webhook-checker pod after the tests are complete. This can be done in the AfterAll function to ensure proper resource management.

  3. The error handling is minimal. Consider adding more detailed error logging to help diagnose issues if the webhook fails to become ready. For example:

if err != nil {
    fmt.Printf("Error waiting for webhook-checker pod: %v\n", err)
    ExpectWithOffset(1, err).NotTo(HaveOccurred())
}
  1. The timeout of 5 minutes seems reasonable, but you might want to make it configurable via an environment variable to allow for flexibility in different testing environments.

To verify the existence and contents of the webhook-checker.yaml file, please run:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
cat test/e2e/webhook-checker.yaml

Length of output: 3476

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