Skip to content

test: add a precheck system for e2e tests#2269

Open
hardcoretime wants to merge 9 commits intomainfrom
test/preckeck
Open

test: add a precheck system for e2e tests#2269
hardcoretime wants to merge 9 commits intomainfrom
test/preckeck

Conversation

@hardcoretime
Copy link
Copy Markdown
Contributor

@hardcoretime hardcoretime commented Apr 24, 2026

Description

This PR adds a precheck system for e2e tests that validates cluster configuration before running tests.

Changes:

  • Added precheck infrastructure in test/e2e/internal/precheck/
    • common.go - core precheck framework with registration, validation, and execution
    • labels.go - precheck label constants
    • context.go - context for precheck execution
  • Added Module API for deckhouse v1alpha1 to check module status
  • Added common prechecks (run for all tests):
    • storageclass - verifies default StorageClass exists
    • virtualization - verifies virtualization module is Ready
    • vmc - verifies default VirtualMachineClass exists (uses v1alpha3)
  • Added specific prechecks (require explicit label):
    • sdn - verifies SDN module is Ready and required ClusterNetworks (VLAN 4006, 4007) exist
    • svdm - verifies SVDM module is Ready
    • snapshot - verifies snapshot-controller module is Ready and VolumeSnapshotClass exists
    • usb - verifies dummy_hcd USB device is configured
  • Added precheck labels to all e2e tests
  • Refactored legacy package to support lazy initialization via Init() called from NewBeforeProcess1Body()
  • Integrated prechecks into e2e_test.go SynchronizedBeforeSuite (runs after resource initialization to avoid panic in SynchronizedAfterSuite)

Why do we need it, and what problem does it solve?

Previously, e2e tests would fail with unclear errors when required cluster configuration was missing (e.g., no default StorageClass, module not ready, missing ClusterNetworks). This PR adds a precheck system that:

  1. Validates cluster configuration before test execution
  2. Provides clear error messages with instructions on how to fix issues
  3. Allows tests to be skipped or disabled via environment variables
  4. Prevents panic in SynchronizedAfterSuite when prechecks fail

What is the expected result?

When running e2e tests:

  1. Ginkgo dry-run collects test labels
  2. Prechecks validate cluster configuration based on test labels
  3. Tests run only if all required prechecks pass
  4. Clear error messages guide users to fix missing configuration

Example output:

Running common precheck: storageclass-precheck
Running common precheck: virtualization-precheck
Running common precheck: vmc-precheck
Running precheck: sdn-precheck

Checklist

  • The code is covered by unit tests.
  • e2e tests passed.
  • Documentation updated according to the changes.
  • Changes were tested in the Kubernetes cluster manually.

Changelog entries

section: test
type: feature
summary: "Add precheck system for e2e tests that validates cluster configuration before test execution."
impact_level: low

@hardcoretime hardcoretime changed the title Test/preckeck test: add a precheck system for e2e tests Apr 24, 2026
@hardcoretime hardcoretime added this to the v1.9.0 milestone Apr 24, 2026
Roman Sysoev added 7 commits April 27, 2026 02:15
This script runs ginkgo dry-run with --json-report flag to generate
a JSON report containing all test specs with their labels. The report
is used by the precheck system in SynchronizedBeforeSuite to determine
which prechecks to run based on test labels.

Changes:
- Add precheck-prepare.sh script that runs 'go tool ginkgo --dry-run
  --json-report=/tmp/e2e-specs.json' with FOCUS and LABELS filters

Signed-off-by: Roman Sysoev <roman.sysoev@flant.com>
Add Module CRD type definition to check module status in prechecks.
The precheck system needs to verify that modules like virtualization,
sdn, snapshot-controller, and svdm are enabled and ready before
running tests that depend on them.

Changes:
- Add module.go with Module struct definition and deep copy methods
- Update register.go to register the new Module type in the scheme
- Regenerate deep_copy.go to include the new type

Signed-off-by: Roman Sysoev <roman.sysoev@flant.com>
Add precheck system that validates cluster configuration before running
e2e tests. This prevents test failures due to missing prerequisites.

Components:
- common.go: core logic for loading spec labels from JSON report,
  filtering by FOCUS/LABELS, and running prechecks. Includes common
  IsModuleEnabled() function to check if a module is enabled.
- labels.go: precheck label constants (precheck.USB, precheck.SDN, etc.)
- context.go: context helper for precheck execution
- Individual prechecks:
  * storageclass.go: checks default StorageClass exists
  * virtualization.go: checks virtualization module is enabled and ready
  * vmc.go: checks VMClass exists and is set as default
  * sdn.go: checks SDN module is enabled and ClusterNetworks exist
  * svdm.go: checks SVDM module is enabled and ready
  * snapshot.go: checks snapshot-controller is enabled and VolumeSnapshotClasses exist
  * usb.go: checks dummy_hcd USB device is configured

Precheck types:
- Common prechecks: run for all tests (storageclass, virtualization, vmc)
- Specific prechecks: run only for tests with matching label (sdn, svdm, snapshot, usb)

Features:
- Prechecks can be disabled via environment variables (e.g., USB_PRECHECK=no)
- All prechecks can be disabled with PRECHECK=no
- Each precheck provides clear error messages with instructions

Signed-off-by: Roman Sysoev <roman.sysoev@flant.com>
Add precheck:prepare task that runs before e2e tests to generate JSON
report with spec labels. This task is added as a dependency to the
run task so it executes automatically.

Changes:
- Add precheck:prepare task that runs precheck-prepare.sh script
- Add precheck:prepare as dependency to run task

Signed-off-by: Roman Sysoev <roman.sysoev@flant.com>
Add precheck validation and execution in SynchronizedBeforeSuite.
The execution order is:
1. First initialize test resources (controller.NewBeforeProcess1Body,
   legacy.NewBeforeProcess1Body) - must run before prechecks
2. Validate all specs have precheck labels (fail fast if missing)
3. Load spec labels from JSON report (generated by precheck:prepare)
4. Run prechecks based on loaded labels before tests start

This ensures cluster is properly configured before any test runs.

Changes:
- Import precheck package
- Add precheck.ValidateFromJSONFile() call to validate labels
- Add precheck.LoadSpecLabelsFromFile() to load labels from report
- Add precheck.Run() to execute required prechecks

Signed-off-by: Roman Sysoev <roman.sysoev@flant.com>
Add GetModuleConfig method to retrieve Deckhouse module configurations.
This is used by prechecks to verify modules are enabled and ready.

Changes:
- Add GetModuleConfig(moduleName string) (*Module, error) method to Framework
- The method retrieves module configuration from the deckhouse API group
- Used by prechecks to check if modules like sdn, svdm, virtualization, snapshot are enabled

Signed-off-by: Roman Sysoev <roman.sysoev@flant.com>
Add required precheck labels to all e2e tests. Each test must declare
its dependencies using Label(precheck.XXX) or Label(precheck.NoPrecheck).

This ensures precheck system can validate cluster configuration before
running tests that require specific modules or resources.

Changes:
- Add Label(precheck.NoPrecheck) to tests that don't require any prechecks
- Add Label(precheck.PrecheckXXX) to tests that require specific prechecks:
  * precheck.PrecheckSDN - requires SDN module
  * precheck.PrecheckSVDM - requires SVDM module
  * precheck.PrecheckSnapshot - requires snapshot-controller
  * precheck.PrecheckUSB - requires dummy_hcd USB device

Signed-off-by: Roman Sysoev <roman.sysoev@flant.com>
Fix golangci-lint warnings:
- errcheck: ignore return value of GinkgoWriter.Write()
- SA4009: fix labelFilter parameter shadowing issue
- ST1005: remove trailing punctuation from error messages
- QF1012: use fmt.Fprintf instead of Write with fmt.Sprintf

Changes:
- Add _, _ = prefix to GinkgoWriter.Write() calls
- Rename parameter to avoid shadowing in LoadSpecLabelsFromFile()
- Fix error message in usb.go (remove trailing period)
- Revert to fmt.Fprintf for GinkgoWriter (standard pattern in Ginkgo)

Signed-off-by: Roman Sysoev <roman.sysoev@flant.com>
Fix contextcheck lint warnings by adding context.Context parameter
to functions that use it internally.

Changes:
- Add ctx parameter to IsModuleEnabled(f, moduleName) -> IsModuleEnabled(ctx, f, moduleName)
- Add ctx parameter to IsClusterNetworkExists(f, vlanID) -> IsClusterNetworkExists(ctx, f, vlanID)
- Add ctx parameter to checkDummyHCDConfigured(f) -> checkDummyHCDConfigured(ctx, f)
- Add ctx parameter to GetModuleConfig(name) -> GetModuleConfig(ctx, name)
- Add ctx parameter to GetVirtualizationModuleConfig() -> GetVirtualizationModuleConfig(ctx)
- Add ctx parameter to UntilConditionReason, UntilConditionStatus, UntilConditionState
- Update all call sites to pass context

Signed-off-by: Roman Sysoev <roman.sysoev@flant.com>
@hardcoretime hardcoretime marked this pull request as ready for review April 27, 2026 08:55
@hardcoretime hardcoretime requested a review from Isteb4k as a code owner April 27, 2026 08:55
@hardcoretime hardcoretime requested a review from danilrwx April 27, 2026 08:55

// NewContext creates a background context for precheck execution.
func NewContext() context.Context {
return context.Background()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why not just use direct call?

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