diff --git a/test/custom_task_test.go b/test/custom_task_test.go index 3b557ce3f64..da2bf259a42 100644 --- a/test/custom_task_test.go +++ b/test/custom_task_test.go @@ -20,10 +20,8 @@ limitations under the License. package test import ( - "bytes" "context" "fmt" - "os" "os/exec" "strings" "sync" @@ -32,7 +30,6 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/pipeline" v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" @@ -725,63 +722,3 @@ func resetConfigMap(ctx context.Context, t *testing.T, c *clients, namespace, co t.Log(err) } } - -func getFeatureFlagsBaseOnAPIFlag(t *testing.T) *config.FeatureFlags { - t.Helper() - alphaFeatureFlags, err := config.NewFeatureFlagsFromMap(map[string]string{ - "enable-api-fields": "alpha", - "results-from": "sidecar-logs", - "enable-tekton-oci-bundles": "true", - "enable-step-actions": "true", - "enable-cel-in-whenexpression": "true", - "enable-param-enum": "true", - }) - if err != nil { - t.Fatalf("error creating alpha feature flags configmap: %v", err) - } - betaFeatureFlags, err := config.NewFeatureFlagsFromMap(map[string]string{ - "enable-api-fields": "beta", - }) - if err != nil { - t.Fatalf("error creating beta feature flags configmap: %v", err) - } - stableFeatureFlags, err := config.NewFeatureFlagsFromMap(map[string]string{ - "enable-api-fields": "stable", - }) - if err != nil { - t.Fatalf("error creating stable feature flags configmap: %v", err) - } - enabledFeatureGate, err := getAPIFeatureGate() - if err != nil { - t.Fatalf("error reading enabled feature gate: %v", err) - } - switch enabledFeatureGate { - case "alpha": - return alphaFeatureFlags - case "beta": - return betaFeatureFlags - default: - return stableFeatureFlags - } -} - -// getAPIFeatureGate queries the tekton pipelines namespace for the -// current value of the "enable-api-fields" feature gate. -func getAPIFeatureGate() (string, error) { - ns := os.Getenv("SYSTEM_NAMESPACE") - if ns == "" { - ns = "tekton-pipelines" - } - - cmd := exec.Command("kubectl", "get", "configmap", "feature-flags", "-n", ns, "-o", `jsonpath="{.data['enable-api-fields']}"`) - output, err := cmd.Output() - if err != nil { - return "", fmt.Errorf("error getting feature-flags configmap: %w", err) - } - output = bytes.TrimSpace(output) - output = bytes.Trim(output, "\"") - if len(output) == 0 { - output = []byte("stable") - } - return string(output), nil -} diff --git a/test/featureflags.go b/test/featureflags.go index 071a45ee083..5304f1e190f 100644 --- a/test/featureflags.go +++ b/test/featureflags.go @@ -17,8 +17,11 @@ limitations under the License. package test import ( + "bytes" "context" "fmt" + "os" + "os/exec" "strings" "testing" @@ -104,3 +107,63 @@ func requireAllGates(gates map[string]string) func(context.Context, *testing.T, } } } + +func getFeatureFlagsBaseOnAPIFlag(t *testing.T) *config.FeatureFlags { + t.Helper() + alphaFeatureFlags, err := config.NewFeatureFlagsFromMap(map[string]string{ + "enable-api-fields": "alpha", + "results-from": "sidecar-logs", + "enable-tekton-oci-bundles": "true", + "enable-step-actions": "true", + "enable-cel-in-whenexpression": "true", + "enable-param-enum": "true", + }) + if err != nil { + t.Fatalf("error creating alpha feature flags configmap: %v", err) + } + betaFeatureFlags, err := config.NewFeatureFlagsFromMap(map[string]string{ + "enable-api-fields": "beta", + }) + if err != nil { + t.Fatalf("error creating beta feature flags configmap: %v", err) + } + stableFeatureFlags, err := config.NewFeatureFlagsFromMap(map[string]string{ + "enable-api-fields": "stable", + }) + if err != nil { + t.Fatalf("error creating stable feature flags configmap: %v", err) + } + enabledFeatureGate, err := getAPIFeatureGate() + if err != nil { + t.Fatalf("error reading enabled feature gate: %v", err) + } + switch enabledFeatureGate { + case "alpha": + return alphaFeatureFlags + case "beta": + return betaFeatureFlags + default: + return stableFeatureFlags + } +} + +// getAPIFeatureGate queries the tekton pipelines namespace for the +// current value of the "enable-api-fields" feature gate. +func getAPIFeatureGate() (string, error) { + ns := os.Getenv("SYSTEM_NAMESPACE") + if ns == "" { + ns = "tekton-pipelines" + } + + cmd := exec.Command("kubectl", "get", "configmap", "feature-flags", "-n", ns, "-o", `jsonpath="{.data['enable-api-fields']}"`) + output, err := cmd.Output() + if err != nil { + return "", fmt.Errorf("error getting feature-flags configmap: %w", err) + } + output = bytes.TrimSpace(output) + output = bytes.Trim(output, "\"") + if len(output) == 0 { + output = []byte("stable") + } + return string(output), nil +}