test(e2e): add operator initData validation event test#7392
test(e2e): add operator initData validation event test#7392manmathbh wants to merge 1 commit intokarmada-io:masterfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the testing infrastructure for the Karmada operator by introducing an end-to-end test case. The goal is to ensure that the operator provides appropriate feedback, specifically through Kubernetes events and status conditions, when it encounters invalid configuration data during reconciliation. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new E2E test suite to verify that the Karmada operator correctly handles validation failures by emitting warning events and updating the resource status to a non-ready state. The review feedback identifies a potential nil pointer dereference when accessing nested spec fields and points out a discrepancy between the test implementation and the PR's stated scope regarding which fields are being validated.
| karmada, err := operatorClient.OperatorV1alpha1().Karmadas(testNamespace).Get(context.TODO(), karmadaName, metav1.GetOptions{}) | ||
| gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) | ||
|
|
||
| karmada.Spec.CRDTarball.HTTPSource.URL = "bad-url" |
There was a problem hiding this comment.
Potential nil pointer dereference. If karmada.Spec.CRDTarball or karmada.Spec.CRDTarball.HTTPSource is not initialized (e.g., by InitializeKarmadaInstance or via defaults), accessing the URL field directly will cause a panic. It is safer to ensure these nested pointers are initialized before assignment.
if karmada.Spec.CRDTarball == nil {
karmada.Spec.CRDTarball = &operatorv1alpha1.CRDTarball{}
}
if karmada.Spec.CRDTarball.HTTPSource == nil {
karmada.Spec.CRDTarball.HTTPSource = &operatorv1alpha1.HTTPSource{}
}
karmada.Spec.CRDTarball.HTTPSource.URL = "bad-url"| operatorresource "github.com/karmada-io/karmada/test/e2e/framework/resource/operator" | ||
| ) | ||
|
|
||
| var _ = ginkgo.Describe("Karmada validation event testing", func() { |
There was a problem hiding this comment.
The test implementation and its scope do not align with the PR title and description. The PR description states that the test verifies validation events for missing initData (such as spec.components.karmadaAPIServer or spec.hostCluster.networking.dnsDomain), but the code actually tests an update operation on spec.crdTarball.httpSource.url. Please update the PR description or the test cases to ensure consistency.
References
- It is acceptable to merge code with incomplete or placeholder logic for new features when it is an intentional part of the development process.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7392 +/- ##
==========================================
+ Coverage 42.03% 42.14% +0.10%
==========================================
Files 874 875 +1
Lines 53551 53603 +52
==========================================
+ Hits 22511 22590 +79
+ Misses 29349 29312 -37
- Partials 1691 1701 +10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks @manmathbh for the PR! Whenever you have it in a reviewable state, just ping me and I'll take a look as soon as I'm available |
b8bac34 to
519aa82
Compare
|
Hi @mohamedawnallah thanks for checking in! I have refactored the test based on the initial bot feedback:
The CI suite is completely green. This is now ready for your review. PTAL! |
There was a problem hiding this comment.
Pull request overview
Adds an operator E2E test case to verify that creating a Karmada instance with invalid CRD tarball init data triggers a ValidationError warning event and sets the Ready condition to False, improving event-related E2E coverage (Fixes #7252).
Changes:
- Introduce a new operator suite E2E test that creates a Karmada CR with an invalid
spec.crdTarball.httpSource.url. - Assert the operator updates
status.conditions[Ready]toFalsewith reasonValidationError. - Assert a Warning event with reason
ValidationErroris emitted containing the expected validation message substring.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| operatorresource.DeleteKarmadaInstance(operatorClient, testNamespace, karmadaName) | ||
| }) | ||
|
|
||
| ginkgo.It("should emit warning event and set Ready condition false when initData is invalid", func() { |
There was a problem hiding this comment.
The test case title mentions "initData" but the scenario being validated is an invalid CRD tarball HTTP URL (spec.crdTarball.httpSource.url). Consider renaming the It() description to match the actual invalid input so failures are self-explanatory in CI output.
| ginkgo.It("should emit warning event and set Ready condition false when initData is invalid", func() { | |
| ginkgo.It("should emit warning event and set Ready condition false when CRD tarball HTTP URL is invalid", func() { |
| if karmada.Spec.CRDTarball == nil { | ||
| karmada.Spec.CRDTarball = &operatorv1alpha1.CRDTarball{} | ||
| } | ||
| if karmada.Spec.CRDTarball.HTTPSource == nil { | ||
| karmada.Spec.CRDTarball.HTTPSource = &operatorv1alpha1.HTTPSource{} | ||
| } |
There was a problem hiding this comment.
helper.NewKarmada() already initializes Spec.CRDTarball and Spec.CRDTarball.HTTPSource as non-nil (test/helper/karmada.go). The nil-guard branches here are therefore redundant and add noise; you can simplify this step by directly setting karmada.Spec.CRDTarball.HTTPSource.URL.
| if karmada.Spec.CRDTarball == nil { | |
| karmada.Spec.CRDTarball = &operatorv1alpha1.CRDTarball{} | |
| } | |
| if karmada.Spec.CRDTarball.HTTPSource == nil { | |
| karmada.Spec.CRDTarball.HTTPSource = &operatorv1alpha1.HTTPSource{} | |
| } |
| ginkgo.By("Step 3: assert Warning ValidationError event is emitted", func() { | ||
| framework.WaitEventFitWith(hostClient, testNamespace, karmadaName, func(event corev1.Event) bool { | ||
| return event.Type == corev1.EventTypeWarning && | ||
| event.Reason == karmadacontroller.ValidationErrorReason && | ||
| strings.Contains(event.Message, validationErrorMessageSubstring) | ||
| }) |
There was a problem hiding this comment.
Step 2 uses the operator suite's configurable pollTimeout/pollInterval, but Step 3 calls framework.WaitEventFitWith(), which uses framework.PollTimeout/PollInterval (hard-coded 420s/5s). This makes the test's effective timeout inconsistent with the suite flags and can unnecessarily prolong failures. Prefer waiting for the event with the suite's pollTimeout/pollInterval (e.g., via a local Eventually) or extend the helper to accept timeout/interval.
519aa82 to
3e436ae
Compare
Signed-off-by: manmathbh <manmathcode@gmail.com>
3e436ae to
1bf3a88
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
mohamedawnallah
left a comment
There was a problem hiding this comment.
Thanks @manmathbh for the PR! Left some comments, otherwise LGTM
|
|
||
| # wait karmada-operator ready | ||
| kubectl --kubeconfig="${KUBECONFIG}" --context="${CONTEXT_NAME}" wait --for=condition=Ready --timeout=30s pods -l app.kubernetes.io/name=karmada-operator -n ${KARMADA_SYSTEM_NAMESPACE} | ||
| kubectl --kubeconfig="${KUBECONFIG}" --context="${CONTEXT_NAME}" rollout status deployment/karmada-operator --timeout=90s -n ${KARMADA_SYSTEM_NAMESPACE} |
There was a problem hiding this comment.
Do we need to make those changes?
| ) | ||
|
|
||
| var _ = ginkgo.Describe("Karmada validation event testing", func() { | ||
| const validationErrorMessageSubstring = "invalid CRDs remote URL" |
There was a problem hiding this comment.
Let's have a sentinel error perhaps with a concise name in
and we can reuse it here| ginkgo.It("should emit warning event and set Ready condition false when CRD tarball HTTP URL is invalid", func() { | ||
| ginkgo.By("Step 1: create the Karmada instance with an invalid CRD tarball URL", func() { | ||
| karmada := helper.NewKarmada(testNamespace, karmadaName) | ||
| karmada.Spec.CRDTarball.HTTPSource.URL = "bad-url" |
There was a problem hiding this comment.
nit:
| karmada.Spec.CRDTarball.HTTPSource.URL = "bad-url" | |
| karmada.Spec.CRDTarball.HTTPSource.URL = "invalid-url" |
What type of PR is this?
/kind feature
What this PR does / why we need it:
This PR introduces an End-to-End (E2E) test for the Karmada operator to verify validation events. Specifically, it asserts that the operator correctly emits a ValidationError event when initialized with invalid initData up front.
Note: Following review feedback, the test was refactored to validate failure at creation time with proper nil-pointer safeguards, rather than mutating the object post-readiness.
Which issue(s) this PR fixes:
Fixes #7252
Special notes for your reviewer:
Opening this initially as a Draft PR to leverage the CI pipeline's
kindcluster for E2E validation.Does this PR introduce a user-facing change?: