Skip to content

Commit

Permalink
kind/misc: introduce feature flag to guard artifacts feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ericzzzzzzz authored and tekton-robot committed Feb 29, 2024
1 parent a9d8a9b commit 5b38046
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 1 deletion.
3 changes: 3 additions & 0 deletions config/config-feature-flags.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,8 @@ data:
# Setting this flag to "true" will enable the use of StepActions in Steps
# This feature is in preview mode and not implemented yet. Please check #7259 for updates.
enable-step-actions: "false"
# Setting this flag to "true" will enable the use of Artifacts in Steps
# This feature is in preview mode and not implemented yet. Please check #7693 for updates.
enable-artifacts: "false"
# Setting this flag to "true" will enable the built-in param input validation via param enum.
enable-param-enum: "false"
11 changes: 10 additions & 1 deletion pkg/apis/config/feature_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ const (
EnableCELInWhenExpression = "enable-cel-in-whenexpression"
// EnableStepActions is the flag to enable the use of StepActions in Steps
EnableStepActions = "enable-step-actions"
// DefaultEnableStepActions is the default value for EnableStepActions

// EnableArtifacts is the flag to enable the use of Artifacts in Steps
EnableArtifacts = "enable-artifacts"
// DefaultEnableArtifacts is the default value for EnableStepActions
DefaultEnableArtifacts = false
// EnableParamEnum is the flag to enabled enum in params
EnableParamEnum = "enable-param-enum"

Expand Down Expand Up @@ -183,6 +187,7 @@ type FeatureFlags struct {
EnableCELInWhenExpression bool
EnableStepActions bool
EnableParamEnum bool
EnableArtifacts bool
}

// GetFeatureFlagsConfigName returns the name of the configmap containing all
Expand Down Expand Up @@ -277,6 +282,10 @@ func NewFeatureFlagsFromMap(cfgMap map[string]string) (*FeatureFlags, error) {
if err := setPerFeatureFlag(EnableParamEnum, DefaultEnableParamEnum, &tc.EnableParamEnum); err != nil {
return nil, err
}

if err := setFeature(EnableStepActions, DefaultEnableArtifacts, &tc.EnableArtifacts); err != nil {
return nil, err
}
// Given that they are alpha features, Tekton Bundles and Custom Tasks should be switched on if
// enable-api-fields is "alpha". If enable-api-fields is not "alpha" then fall back to the value of
// each feature's individual flag.
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/config/feature_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func TestNewFeatureFlagsFromConfigMap(t *testing.T) {
Coschedule: config.CoscheduleDisabled,
EnableCELInWhenExpression: true,
EnableStepActions: true,
EnableArtifacts: true,
EnableParamEnum: true,
},
fileName: "feature-flags-all-flags-set",
Expand Down Expand Up @@ -303,6 +304,9 @@ func TestNewFeatureFlagsConfigMapErrors(t *testing.T) {
}, {
fileName: "feature-flags-invalid-enable-param-enum",
want: `failed parsing feature flags config "invalid": strconv.ParseBool: parsing "invalid": invalid syntax for feature enable-param-enum`,
}, {
fileName: "feature-flags-invalid-enable-artifacts",
want: `failed parsing feature flags config "invalid": strconv.ParseBool: parsing "invalid": invalid syntax for feature enable-artifacts`,
}} {
t.Run(tc.fileName, func(t *testing.T) {
cm := test.ConfigMapFromTestFile(t, tc.fileName)
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/config/testdata/feature-flags-all-flags-set.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ data:
enable-cel-in-whenexpression: "true"
enable-step-actions: "true"
enable-param-enum: "true"
enable-artifacts: "true"
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 The Tekton Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: v1
kind: ConfigMap
metadata:
name: feature-flags
namespace: tekton-pipelines
data:
enable-artifacts: "invalid"
1 change: 1 addition & 0 deletions test/e2e-tests-kind-prow-alpha.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ RESULTS_FROM=sidecar-logs
ENABLE_STEP_ACTIONS=true
ENABLE_CEL_IN_WHENEXPRESSION=true
ENABLE_PARAM_ENUM=true
ENABLE_ARTIFACTS=true
14 changes: 14 additions & 0 deletions test/e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ RESULTS_FROM=${RESULTS_FROM:-termination-message}
ENABLE_STEP_ACTIONS=${ENABLE_STEP_ACTIONS:="false"}
ENABLE_CEL_IN_WHENEXPRESSION=${ENABLE_CEL_IN_WHENEXPRESSION:="false"}
ENABLE_PARAM_ENUM=${ENABLE_PARAM_ENUM:="false"}
ENABLE_ARTIFACTS=${ENABLE_ARTIFACTS:="false"}
failed=0

# Script entry point.
Expand Down Expand Up @@ -116,6 +117,18 @@ function set_enable_param_enum() {
kubectl patch configmap feature-flags -n tekton-pipelines -p "$jsonpatch"
}

function set_enable_artifacts() {
local method="$1"
if [ "$method" != "false" ] && [ "$method" != "true" ]; then
printf "Invalid value for enable-artifacts %s\n" ${method}
exit 255
fi
printf "Setting enable-artifacts to %s\n", ${method}
jsonpatch=$(printf "{\"data\": {\"enable-artifacts\": \"%s\"}}" $1)
echo "feature-flags ConfigMap patch: ${jsonpatch}"
kubectl patch configmap feature-flags -n tekton-pipelines -p "$jsonpatch"
}

function run_e2e() {
# Run the integration tests
header "Running Go e2e tests"
Expand All @@ -142,6 +155,7 @@ set_result_extraction_method "$RESULTS_FROM"
set_enable_step_actions "$ENABLE_STEP_ACTIONS"
set_cel_in_whenexpression "$ENABLE_CEL_IN_WHENEXPRESSION"
set_enable_param_enum "$ENABLE_PARAM_ENUM"
set_enable_artifacts "$ENABLE_ARTIFACTS"
run_e2e

(( failed )) && fail_test
Expand Down
1 change: 1 addition & 0 deletions test/featureflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func getFeatureFlagsBaseOnAPIFlag(t *testing.T) *config.FeatureFlags {
"enable-step-actions": "true",
"enable-cel-in-whenexpression": "true",
"enable-param-enum": "true",
"enable-artifacts": "true",
})
if err != nil {
t.Fatalf("error creating alpha feature flags configmap: %v", err)
Expand Down

0 comments on commit 5b38046

Please sign in to comment.