test: add a precheck system for e2e tests#2269
Open
hardcoretime wants to merge 9 commits intomainfrom
Open
Conversation
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>
1e06ff1 to
e4892f8
Compare
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>
e4892f8 to
3dbdf6b
Compare
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>
danilrwx
requested changes
Apr 28, 2026
|
|
||
| // NewContext creates a background context for precheck execution. | ||
| func NewContext() context.Context { | ||
| return context.Background() |
Contributor
There was a problem hiding this comment.
why not just use direct call?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds a precheck system for e2e tests that validates cluster configuration before running tests.
Changes:
test/e2e/internal/precheck/common.go- core precheck framework with registration, validation, and executionlabels.go- precheck label constantscontext.go- context for precheck executionstorageclass- verifies default StorageClass existsvirtualization- verifies virtualization module is Readyvmc- verifies default VirtualMachineClass exists (uses v1alpha3)sdn- verifies SDN module is Ready and required ClusterNetworks (VLAN 4006, 4007) existsvdm- verifies SVDM module is Readysnapshot- verifies snapshot-controller module is Ready and VolumeSnapshotClass existsusb- verifies dummy_hcd USB device is configuredWhy 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:
What is the expected result?
When running e2e tests:
Example output:
Checklist
Changelog entries