-
Notifications
You must be signed in to change notification settings - Fork 15
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Artem Bortnikov <artem.bortnikov@telekom.com>
WalkthroughThe changes introduce a new readiness check for the Changes
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
📒 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:
- The Pod is correctly defined in the etcd-operator-system namespace.
- It uses an appropriate curl image for network checking.
- 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:
- Reduce the sleep duration for potentially faster e2e test execution.
- Address the SSL certificate validation in the readiness probe.
- 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:
- Is the webhook required for all the test scenarios (PVC resizing, emptyDir deployment, and TLS with auth)?
- 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" .
readinessProbe: | ||
exec: | ||
command: | ||
- sh | ||
- -c | ||
- "curl -k https://etcd-operator-webhook-service/mutate-etcd-aenix-io-v1alpha1-etcdcluster" | ||
periodSeconds: 5 |
There was a problem hiding this comment.
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.
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 |
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:
- If this is intentional due to self-signed certificates in the test environment, add a comment explaining this decision.
- 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.
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()) | ||
}) |
There was a problem hiding this comment.
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 thetest/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:
-
The
webhook-checker.yaml
file is not provided in this context. Please include its contents for review to ensure it's correctly configured. -
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. -
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())
}
- 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
This PR adds additional check whether etcd-operator webhook is ready and accepts connections.
Summary by CodeRabbit
New Features
webhook-checker
Pod to ensure the readiness of theetcd-operator
webhook before running end-to-end tests.Bug Fixes