Skip to content

test(e2e): add operator initData validation event test#7392

Open
manmathbh wants to merge 1 commit intokarmada-io:masterfrom
manmathbh:test/operator-validation-events-e2e
Open

test(e2e): add operator initData validation event test#7392
manmathbh wants to merge 1 commit intokarmada-io:masterfrom
manmathbh:test/operator-validation-events-e2e

Conversation

@manmathbh
Copy link
Copy Markdown
Contributor

@manmathbh manmathbh commented Apr 15, 2026

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 kind cluster for E2E validation.

Does this PR introduce a user-facing change?:

NONE

@karmada-bot karmada-bot added kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Apr 15, 2026
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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

  • New E2E Test Suite: Added a new Ginkgo-based test suite to verify validation event handling in the Karmada operator.
  • Validation Logic Verification: Implemented a test case that mutates the CRD tarball URL to an invalid value, ensuring the operator correctly updates the Ready condition and emits a warning event.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@karmada-bot karmada-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 15, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

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() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

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
  1. 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-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 15, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 42.14%. Comparing base (3424bc7) to head (1bf3a88).
⚠️ Report is 66 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

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     
Flag Coverage Δ
unittests 42.14% <ø> (+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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mohamedawnallah
Copy link
Copy Markdown
Member

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

@manmathbh manmathbh force-pushed the test/operator-validation-events-e2e branch from b8bac34 to 519aa82 Compare April 15, 2026 07:05
@manmathbh manmathbh marked this pull request as ready for review April 15, 2026 08:35
Copilot AI review requested due to automatic review settings April 15, 2026 08:35
@karmada-bot karmada-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 15, 2026
@manmathbh
Copy link
Copy Markdown
Contributor Author

Hi @mohamedawnallah thanks for checking in!

I have refactored the test based on the initial bot feedback:

  • Added proper nil-pointer safeguards.
  • Restructured the test to assert invalid initData during the initial object creation, rather than doing a post-readiness mutation (which better aligns with the PR's intent).

The CI suite is completely green. This is now ready for your review. PTAL!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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] to False with reason ValidationError.
  • Assert a Warning event with reason ValidationError is 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() {
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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() {

Copilot uses AI. Check for mistakes.
Comment on lines +52 to +57
if karmada.Spec.CRDTarball == nil {
karmada.Spec.CRDTarball = &operatorv1alpha1.CRDTarball{}
}
if karmada.Spec.CRDTarball.HTTPSource == nil {
karmada.Spec.CRDTarball.HTTPSource = &operatorv1alpha1.HTTPSource{}
}
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
if karmada.Spec.CRDTarball == nil {
karmada.Spec.CRDTarball = &operatorv1alpha1.CRDTarball{}
}
if karmada.Spec.CRDTarball.HTTPSource == nil {
karmada.Spec.CRDTarball.HTTPSource = &operatorv1alpha1.HTTPSource{}
}

Copilot uses AI. Check for mistakes.
Comment on lines +84 to +89
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)
})
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@manmathbh manmathbh force-pushed the test/operator-validation-events-e2e branch from 519aa82 to 3e436ae Compare April 15, 2026 08:49
Signed-off-by: manmathbh <manmathcode@gmail.com>
@manmathbh manmathbh force-pushed the test/operator-validation-events-e2e branch from 3e436ae to 1bf3a88 Compare April 15, 2026 09:03
@karmada-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign ikaven1024, xishanyongye-chang for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Copy Markdown
Member

@mohamedawnallah mohamedawnallah left a comment

Choose a reason for hiding this comment

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

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}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to make those changes?

)

var _ = ginkgo.Describe("Karmada validation event testing", func() {
const validationErrorMessageSubstring = "invalid CRDs remote URL"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
karmada.Spec.CRDTarball.HTTPSource.URL = "bad-url"
karmada.Spec.CRDTarball.HTTPSource.URL = "invalid-url"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Categorizes issue or PR as related to a new feature. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Test] Improve E2E test coverage for Karmada controller events

5 participants