Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
80f8ac1
Fix: Update admission decoder type from pointer to value in handlers
vishal210893 Jun 18, 2025
2faa336
Chore: Upgrade controller-gen version to v0.18.0 and refactor decoder…
vishal210893 Jun 18, 2025
7886d41
Chore: Upgrade ginkgo to v2 and update import paths in test files
vishal210893 Jun 19, 2025
83b0e66
Chore: Refactor feature gate handling in workflow tests
vishal210893 Jun 22, 2025
8d90f36
Chore: Remove unused done channel from BeforeSuite in test files
vishal210893 Jun 22, 2025
daa557e
Chore: Refactor feature gate handling in workflow tests
vishal210893 Jun 22, 2025
f71dce2
Chore: Update decoder handling in test files for consistency
vishal210893 Jun 22, 2025
958a403
Chore: Upgrade Kubernetes version to v1.31.10 in unit-test.yaml
vishal210893 Jun 23, 2025
e21c63a
Chore: Removed KIND version from unit-test.yaml
vishal210893 Jun 23, 2025
3dc1ad0
Chore: Update backport action to use korthout/backport-action@v3
vishal210893 Jun 23, 2025
45af50b
Chore: Upgrade Kubernetes dependencies to v0.31.10 in go.mod
vishal210893 Jun 23, 2025
082b465
Chore: Upgrade K3D image version to v1.31.10 and refactor feature gat…
vishal210893 Jun 23, 2025
6a3d9c7
Chore: Downgrade controller-tools version to v0.16 in dependency.mk
vishal210893 Jun 23, 2025
d0d893d
Chore: Update K3D image version to v1.31 in e2e.yaml
vishal210893 Jun 23, 2025
302f81a
Chore: Downgrade go-cmp and ginkgo/gomega versions in go.mod and go.sum
vishal210893 Jun 23, 2025
787e718
chore: sets timeout in beforeeach nodes
roguepikachu Jun 25, 2025
764a727
chore: updates controller runtime version
roguepikachu Jun 25, 2025
aad3834
chore: fixes linter warnings
roguepikachu Jun 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Chore: Refactor feature gate handling in workflow tests
Signed-off-by: vishal210893 <[email protected]>
Signed-off-by: semmet95 <[email protected]>
  • Loading branch information
vishal210893 authored and semmet95 committed Jun 25, 2025
commit 83b0e662574a1073aa61dec6a48eaedb97c1ce15
38 changes: 32 additions & 6 deletions pkg/executor/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ package executor
import (
"context"
"encoding/json"
"fmt"
"github.com/kubevela/workflow/pkg/features"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/component-base/featuregate"
"math"
"testing"
"time"

"cuelang.org/go/cue/cuecontext"
Expand All @@ -33,16 +36,13 @@ import (
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
utilfeature "k8s.io/apiserver/pkg/util/feature"
featuregatetesting "k8s.io/component-base/featuregate/testing"
"k8s.io/utils/ptr"
"sigs.k8s.io/yaml"

monitorContext "github.com/kubevela/pkg/monitor/context"
"github.com/kubevela/workflow/api/v1alpha1"
wfContext "github.com/kubevela/workflow/pkg/context"
"github.com/kubevela/workflow/pkg/cue/process"
"github.com/kubevela/workflow/pkg/features"
"github.com/kubevela/workflow/pkg/providers"
"github.com/kubevela/workflow/pkg/tasks/builtin"
"github.com/kubevela/workflow/pkg/tasks/custom"
Expand Down Expand Up @@ -895,7 +895,8 @@ var _ = Describe("Test Workflow", func() {

It("Workflow test for failed after retries with suspend", func() {
By("Test failed-after-retries in StepByStep mode with suspend")
defer featuregatetesting.SetFeatureGateDuringTest(&testing.T{}, utilfeature.DefaultFeatureGate, features.EnableSuspendOnFailure, true)
cleanup := setFeatureGateForTest(utilfeature.DefaultFeatureGate, features.EnableSuspendOnFailure, true)
defer cleanup()
instance, runners := makeTestCase([]v1alpha1.WorkflowStep{
{
WorkflowStepBase: v1alpha1.WorkflowStepBase{
Expand Down Expand Up @@ -1469,7 +1470,8 @@ var _ = Describe("Test Workflow", func() {

It("Test failed after retries with sub steps", func() {
By("Test failed-after-retries with step group in StepByStep mode")
defer featuregatetesting.SetFeatureGateDuringTest(&testing.T{}, utilfeature.DefaultFeatureGate, features.EnableSuspendOnFailure, true)
cleanup := setFeatureGateForTest(utilfeature.DefaultFeatureGate, features.EnableSuspendOnFailure, true)
defer cleanup()
instance, runners := makeTestCase([]v1alpha1.WorkflowStep{
{
WorkflowStepBase: v1alpha1.WorkflowStepBase{
Expand Down Expand Up @@ -2441,6 +2443,30 @@ func cleanStepTimeStamp(wfStatus *v1alpha1.WorkflowRunStatus) {
}
}

func setFeatureGateForTest(gate featuregate.FeatureGate, f featuregate.Feature, value bool) func() {
// The Kubernetes feature gate interface requires a MutableVersionedFeatureGate for setting/resetting.
mutableGate, ok := gate.(featuregate.MutableVersionedFeatureGate)
Expect(ok).To(BeTrue(), "The provided feature gate must be a MutableVersionedFeatureGate to be modified in tests")

originalValue := mutableGate.Enabled(f)
originalExplicitlySet := mutableGate.ExplicitlySet(f)

// Set the desired value for the test.
err := mutableGate.Set(fmt.Sprintf("%s=%v", f, value))
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Failed to set feature gate %q to %v: %v", f, value, err))

// Return a cleanup function to restore the original state.
return func() {
if originalExplicitlySet {
err := mutableGate.Set(fmt.Sprintf("%s=%v", f, originalValue))
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Failed to restore feature gate %q to original value %v: %v", f, originalValue, err))
} else {
err := mutableGate.ResetFeatureValueToDefault(f)
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Failed to reset feature gate %q to default: %v", f, err))
}
}
}

const cmYaml = `apiVersion: v1
data:
components: '{"server":"{\"Scopes\":null,\"StandardWorkload\":\"{\\\"apiVersion\\\":\\\"v1\\\",\\\"kind\\\":\\\"Pod\\\",\\\"metadata\\\":{\\\"labels\\\":{\\\"app\\\":\\\"nginx\\\"}},\\\"spec\\\":{\\\"containers\\\":[{\\\"env\\\":[{\\\"name\\\":\\\"APP\\\",\\\"value\\\":\\\"nginx\\\"}],\\\"image\\\":\\\"nginx:1.14.2\\\",\\\"imagePullPolicy\\\":\\\"IfNotPresent\\\",\\\"name\\\":\\\"main\\\",\\\"ports\\\":[{\\\"containerPort\\\":8080,\\\"protocol\\\":\\\"TCP\\\"}]}]}}\",\"Traits\":[\"{\\\"apiVersion\\\":\\\"v1\\\",\\\"kind\\\":\\\"Service\\\",\\\"metadata\\\":{\\\"name\\\":\\\"my-service\\\"},\\\"spec\\\":{\\\"ports\\\":[{\\\"port\\\":80,\\\"protocol\\\":\\\"TCP\\\",\\\"targetPort\\\":8080}],\\\"selector\\\":{\\\"app\\\":\\\"nginx\\\"}}}\"]}"}'
Expand Down