From ead23ae01b4f5b137008523a144e708fcb5a456f Mon Sep 17 00:00:00 2001 From: Jose Angel Morena Date: Mon, 16 Mar 2026 18:18:28 +0100 Subject: [PATCH] feat: add 'disabled' field to IntegrationTestScenario Add a boolean 'disabled' field to the IntegrationTestScenarioSpec that allows users to skip a scenario without deleting it. When set to true, the scenario is filtered out before any context matching occurs. This provides a first-class mechanism to temporarily disable integration tests, replacing the workaround of using unrecognized context names. Closes #1501 Signed-off-by: Jose Angel Morena --- api/v1beta2/integrationtestscenario_types.go | 4 ++++ ...tudio.redhat.com_integrationtestscenarios.yaml | 5 +++++ gitops/snapshot.go | 4 ++++ gitops/snapshot_test.go | 15 ++++++++++++++- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/api/v1beta2/integrationtestscenario_types.go b/api/v1beta2/integrationtestscenario_types.go index fe7eb85b7d..bd563f73a8 100644 --- a/api/v1beta2/integrationtestscenario_types.go +++ b/api/v1beta2/integrationtestscenario_types.go @@ -54,6 +54,10 @@ type IntegrationTestScenarioSpec struct { Params []PipelineParameter `json:"params,omitempty"` // Contexts where this IntegrationTestScenario can be applied, for specific component for example Contexts []TestContext `json:"contexts,omitempty"` + // Disabled indicates whether the IntegrationTestScenario should be skipped. + // When set to true, the scenario will not be triggered for any Snapshot. + // +optional + Disabled bool `json:"disabled,omitempty"` // List of IntegrationTestScenario which are blocked by the successful completion of this IntegrationTestScenario Dependents []string `json:"dependents,omitempty"` } diff --git a/config/crd/bases/appstudio.redhat.com_integrationtestscenarios.yaml b/config/crd/bases/appstudio.redhat.com_integrationtestscenarios.yaml index b5f0a3de51..b609c5c993 100644 --- a/config/crd/bases/appstudio.redhat.com_integrationtestscenarios.yaml +++ b/config/crd/bases/appstudio.redhat.com_integrationtestscenarios.yaml @@ -519,6 +519,11 @@ spec: items: type: string type: array + disabled: + description: |- + Disabled indicates whether the IntegrationTestScenario should be skipped. + When set to true, the scenario will not be triggered for any Snapshot. + type: boolean params: description: Params to pass to the pipeline items: diff --git a/gitops/snapshot.go b/gitops/snapshot.go index 08f3fe74a1..4e870ed842 100644 --- a/gitops/snapshot.go +++ b/gitops/snapshot.go @@ -1256,6 +1256,10 @@ func IsContextValidForSnapshot(scenarioContextName string, snapshot *application // IsScenarioApplicableToSnapshotsContext checks the contexts list for a given IntegrationTestScenario and // compares it against the Snapshot to determine if the scenario applies to it func IsScenarioApplicableToSnapshotsContext(scenario *v1beta2.IntegrationTestScenario, snapshot *applicationapiv1alpha1.Snapshot) bool { + // If the scenario is disabled, it should not be triggered for any Snapshot + if scenario.Spec.Disabled { + return false + } // If the contexts list is empty, we assume that the scenario applies to all contexts by default if len(scenario.Spec.Contexts) == 0 { return true diff --git a/gitops/snapshot_test.go b/gitops/snapshot_test.go index fd8d08ceeb..4f696e334a 100644 --- a/gitops/snapshot_test.go +++ b/gitops/snapshot_test.go @@ -1095,9 +1095,12 @@ var _ = Describe("Gitops functions for managing Snapshots", Ordered, func() { unsupportedScenario := integrationTestScenario.DeepCopy() unsupportedScenario.Spec.Contexts = []v1beta2.TestContext{{Name: "n/a"}} + disabledScenario := integrationTestScenario.DeepCopy() + disabledScenario.Spec.Disabled = true + allScenarios := []v1beta2.IntegrationTestScenario{*integrationTestScenario, *applicationScenario, *componentScenario, *componentSampleScenario, *componentSample2Scenario, *pullRequestScenario, - *pushScenario, *groupScenario, *componentAndGroupScenario, *unsupportedScenario} + *pushScenario, *groupScenario, *componentAndGroupScenario, *unsupportedScenario, *disabledScenario} It("Returns only the scenarios matching the context for a given kind of Snapshot", func() { // A component Snapshot for a push event referencing the component-sample @@ -1127,6 +1130,16 @@ var _ = Describe("Gitops functions for managing Snapshots", Ordered, func() { Expect(*filteredScenarios).To(HaveLen(3)) }) + It("Filters out disabled scenarios regardless of context or snapshot type", func() { + Expect(gitops.IsScenarioApplicableToSnapshotsContext(disabledScenario, hasSnapshot)).To(BeFalse()) + + // Also ensure a disabled scenario with explicit contexts is still filtered out + disabledWithContext := integrationTestScenario.DeepCopy() + disabledWithContext.Spec.Disabled = true + disabledWithContext.Spec.Contexts = []v1beta2.TestContext{{Name: "application"}} + Expect(gitops.IsScenarioApplicableToSnapshotsContext(disabledWithContext, hasSnapshot)).To(BeFalse()) + }) + It("Testing annotating snapshot", func() { hasSnapshot.Labels[gitops.PipelineAsCodeEventTypeLabel] = gitops.PipelineAsCodePullRequestType componentSnapshotInfos := []gitops.ComponentSnapshotInfo{