From 1915220b23b843b4686a7856941f08dda27b94c3 Mon Sep 17 00:00:00 2001 From: Yongxuan Zhang Date: Wed, 5 Apr 2023 17:50:24 +0000 Subject: [PATCH] [TEP-114] Remove the feature flag custom-task-version This commit closes #5837. It removes the feature flag custom-task-version to stop supporting v1alpha1.Run as planed in TEP-114. There will be a separate PR to remove the v1alpha1.Run tracking by #6498. Signed-off-by: Yongxuan Zhang yongxuanzhang@google.com --- config/config-feature-flags.yaml | 4 - docs/additional-configs.md | 6 - docs/pipelines.md | 3 +- pkg/apis/config/feature_flags.go | 29 - pkg/apis/config/feature_flags_test.go | 10 - .../testdata/feature-flags-all-flags-set.yaml | 1 - ...ure-flags-invalid-custom-task-version.yaml | 21 - .../v1beta1/pipelinerun_conversion_test.go | 1 - .../v1beta1/taskrun_conversion_test.go | 1 - pkg/reconciler/pipelinerun/cancel_test.go | 8 - pkg/reconciler/pipelinerun/pipelinerun.go | 80 +-- .../pipelinerun/pipelinerun_test.go | 193 +----- pkg/reconciler/pipelinerun/timeout_test.go | 8 - pkg/reconciler/taskrun/taskrun_test.go | 1 - test/custom_task_test.go | 560 +----------------- 15 files changed, 30 insertions(+), 896 deletions(-) delete mode 100644 pkg/apis/config/testdata/feature-flags-invalid-custom-task-version.yaml diff --git a/config/config-feature-flags.yaml b/config/config-feature-flags.yaml index a91a08a9b7d..2baa580b8f9 100644 --- a/config/config-feature-flags.yaml +++ b/config/config-feature-flags.yaml @@ -86,10 +86,6 @@ data: # in the TaskRun/PipelineRun such as the source from where a remote Task/Pipeline # definition was fetched. enable-provenance-in-status: "false" - # Setting this flag will determine the version for custom tasks created by PipelineRuns. - # Acceptable values are "v1beta1" and "v1alpha1". - # The default is "v1beta1". - custom-task-version: "v1beta1" # Setting this flag will determine how Tekton pipelines will handle non-falsifiable provenance. # If set to "spire", then SPIRE will be used to ensure non-falsifiable provenance. # If set to "none", then Tekton will not have non-falsifiable provenance. diff --git a/docs/additional-configs.md b/docs/additional-configs.md index e4b8ab0c928..f0f3021d3e7 100644 --- a/docs/additional-configs.md +++ b/docs/additional-configs.md @@ -250,12 +250,6 @@ Defaults to "ignore". field contains metadata about resources used in the TaskRun/PipelineRun such as the source from where a remote Task/Pipeline definition was fetched. -- `custom-task-version`: set this flag to "v1beta1" to have `PipelineRuns` create `CustomRuns` - from Custom Tasks. Set it to "v1alpha1" to have `PipelineRuns` create the legacy alpha - `Runs`. This may be needed if you are using legacy Custom Tasks that listen for `*v1alpha1.Run` - instead of `*v1beta1.CustomRun`. For more information, see [Runs](runs.md) and [CustomRuns](customruns.md). - Flag defaults to "v1beta1". - For example: ```yaml diff --git a/docs/pipelines.md b/docs/pipelines.md index c45b4ef9409..75a1ac61bd0 100644 --- a/docs/pipelines.md +++ b/docs/pipelines.md @@ -1618,7 +1618,8 @@ no `runAfter` can be specified in `finally` tasks. ## Using Custom Tasks -Custom Tasks have been promoted from `v1alpha1` to `v1beta1`. Starting from `v0.43.0`, Pipeline Controller is able to create either `v1alpha1` or `v1beta1` Custom Task gated by a feature flag `custom-task-version`, defaulting to `v1beta1`. You can set `custom-task-version` to `v1alpha1` or `v1beta1` to control which version to create. +Custom Tasks have been promoted from `v1alpha1` to `v1beta1`. Starting from `v0.43.0` to `v0.46.0`, Pipeline Controller is able to create either `v1alpha1` or `v1beta1` Custom Task gated by a feature flag `custom-task-version`, defaulting to `v1beta1`. You can set `custom-task-version` to `v1alpha1` or `v1beta1` to control which version to create. +Starting from `v0.47.0`, feature flag `custom-task-version` is removed and only `v1beta1` Custom Task will be supported. We'll remove the flag `custom-task-version` and the entire alpha Custom Task in release v0.47.0 (tracked in the issue #5837). See the [migration doc](migrating-v1alpha1.Run-to-v1beta1.CustomRun.md) for details. diff --git a/pkg/apis/config/feature_flags.go b/pkg/apis/config/feature_flags.go index 4b28b309116..aa532fafdf9 100644 --- a/pkg/apis/config/feature_flags.go +++ b/pkg/apis/config/feature_flags.go @@ -46,12 +46,6 @@ const ( ResultExtractionMethodTerminationMessage = "termination-message" // ResultExtractionMethodSidecarLogs is the value used for "results-from" as a way to extract results from tasks using sidecar logs. ResultExtractionMethodSidecarLogs = "sidecar-logs" - // CustomTaskVersionAlpha is the value used for "custom-task-version" when the PipelineRun reconciler should create - // v1alpha1.Runs. - CustomTaskVersionAlpha = "v1alpha1" - // CustomTaskVersionBeta is the value used for "custom-task-version" when the PipelineRun reconciler should create - // v1beta1.CustomRuns. - CustomTaskVersionBeta = "v1beta1" // DefaultDisableAffinityAssistant is the default value for "disable-affinity-assistant". DefaultDisableAffinityAssistant = false // DefaultDisableCredsInit is the default value for "disable-creds-init". @@ -82,8 +76,6 @@ const ( DefaultResultExtractionMethod = ResultExtractionMethodTerminationMessage // DefaultMaxResultSize is the default value in bytes for the size of a result DefaultMaxResultSize = 4096 - // DefaultCustomTaskVersion is the default value for "custom-task-version" - DefaultCustomTaskVersion = CustomTaskVersionBeta disableAffinityAssistantKey = "disable-affinity-assistant" disableCredsInitKey = "disable-creds-init" @@ -98,7 +90,6 @@ const ( enableProvenanceInStatus = "enable-provenance-in-status" resultExtractionMethod = "results-from" maxResultSize = "max-result-size" - customTaskVersion = "custom-task-version" ) // FeatureFlags holds the features configurations @@ -123,7 +114,6 @@ type FeatureFlags struct { EnableProvenanceInStatus bool ResultExtractionMethod string MaxResultSize int - CustomTaskVersion string } // GetFeatureFlagsConfigName returns the name of the configmap containing all @@ -200,9 +190,6 @@ func NewFeatureFlagsFromMap(cfgMap map[string]string) (*FeatureFlags, error) { if err := setMaxResultSize(cfgMap, DefaultMaxResultSize, &tc.MaxResultSize); err != nil { return nil, err } - if err := setCustomTaskVersion(cfgMap, DefaultCustomTaskVersion, &tc.CustomTaskVersion); 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 @@ -263,22 +250,6 @@ func setResultExtractionMethod(cfgMap map[string]string, defaultValue string, fe return nil } -// setCustomTaskVersion sets the "custom-task-version" flag based on the content of a given map. -// If the feature gate is invalid or missing then an error is returned. -func setCustomTaskVersion(cfgMap map[string]string, defaultValue string, feature *string) error { - value := defaultValue - if cfg, ok := cfgMap[customTaskVersion]; ok { - value = strings.ToLower(cfg) - } - switch value { - case CustomTaskVersionAlpha, CustomTaskVersionBeta: - *feature = value - default: - return fmt.Errorf("invalid value for feature flag %q: %q", customTaskVersion, value) - } - return nil -} - // setMaxResultSize sets the "max-result-size" flag based on the content of a given map. // If the feature gate is invalid or missing then an error is returned. func setMaxResultSize(cfgMap map[string]string, defaultValue int, feature *int) error { diff --git a/pkg/apis/config/feature_flags_test.go b/pkg/apis/config/feature_flags_test.go index 7f05a345074..c63d7d8a922 100644 --- a/pkg/apis/config/feature_flags_test.go +++ b/pkg/apis/config/feature_flags_test.go @@ -51,7 +51,6 @@ func TestNewFeatureFlagsFromConfigMap(t *testing.T) { EnableProvenanceInStatus: config.DefaultEnableProvenanceInStatus, ResultExtractionMethod: config.DefaultResultExtractionMethod, MaxResultSize: config.DefaultMaxResultSize, - CustomTaskVersion: config.DefaultCustomTaskVersion, }, fileName: config.GetFeatureFlagsConfigName(), }, @@ -69,7 +68,6 @@ func TestNewFeatureFlagsFromConfigMap(t *testing.T) { EnableProvenanceInStatus: true, ResultExtractionMethod: "termination-message", MaxResultSize: 4096, - CustomTaskVersion: "v1beta1", }, fileName: "feature-flags-all-flags-set", }, @@ -89,7 +87,6 @@ func TestNewFeatureFlagsFromConfigMap(t *testing.T) { VerificationNoMatchPolicy: config.DefaultNoMatchPolicyConfig, ResultExtractionMethod: config.DefaultResultExtractionMethod, MaxResultSize: config.DefaultMaxResultSize, - CustomTaskVersion: config.DefaultCustomTaskVersion, }, fileName: "feature-flags-enable-api-fields-overrides-bundles-and-custom-tasks", }, @@ -107,7 +104,6 @@ func TestNewFeatureFlagsFromConfigMap(t *testing.T) { VerificationNoMatchPolicy: config.DefaultNoMatchPolicyConfig, ResultExtractionMethod: config.DefaultResultExtractionMethod, MaxResultSize: config.DefaultMaxResultSize, - CustomTaskVersion: config.DefaultCustomTaskVersion, }, fileName: "feature-flags-bundles-and-custom-tasks", }, @@ -125,7 +121,6 @@ func TestNewFeatureFlagsFromConfigMap(t *testing.T) { VerificationNoMatchPolicy: config.DefaultNoMatchPolicyConfig, ResultExtractionMethod: config.DefaultResultExtractionMethod, MaxResultSize: config.DefaultMaxResultSize, - CustomTaskVersion: config.DefaultCustomTaskVersion, }, fileName: "feature-flags-beta-api-fields", }, @@ -139,7 +134,6 @@ func TestNewFeatureFlagsFromConfigMap(t *testing.T) { AwaitSidecarReadiness: config.DefaultAwaitSidecarReadiness, ResultExtractionMethod: config.DefaultResultExtractionMethod, MaxResultSize: config.DefaultMaxResultSize, - CustomTaskVersion: config.DefaultCustomTaskVersion, }, fileName: "feature-flags-enforce-nonfalsifiability-spire", }, @@ -151,7 +145,6 @@ func TestNewFeatureFlagsFromConfigMap(t *testing.T) { AwaitSidecarReadiness: config.DefaultAwaitSidecarReadiness, ResultExtractionMethod: config.ResultExtractionMethodSidecarLogs, MaxResultSize: 8192, - CustomTaskVersion: config.DefaultCustomTaskVersion, }, fileName: "feature-flags-results-via-sidecar-logs", }, @@ -182,7 +175,6 @@ func TestNewFeatureFlagsFromEmptyConfigMap(t *testing.T) { EnableProvenanceInStatus: config.DefaultEnableProvenanceInStatus, ResultExtractionMethod: config.DefaultResultExtractionMethod, MaxResultSize: config.DefaultMaxResultSize, - CustomTaskVersion: config.DefaultCustomTaskVersion, } verifyConfigFileWithExpectedFeatureFlagsConfig(t, FeatureFlagsConfigEmptyName, expectedConfig) } @@ -229,8 +221,6 @@ func TestNewFeatureFlagsConfigMapErrors(t *testing.T) { fileName: "feature-flags-invalid-max-result-size-too-large", }, { fileName: "feature-flags-invalid-max-result-size-bad-value", - }, { - fileName: "feature-flags-invalid-custom-task-version", }, { fileName: "feature-flags-enforce-nonfalsifiability-bad-flag", }, { diff --git a/pkg/apis/config/testdata/feature-flags-all-flags-set.yaml b/pkg/apis/config/testdata/feature-flags-all-flags-set.yaml index 664c4c9cbe0..07f5f33a9de 100644 --- a/pkg/apis/config/testdata/feature-flags-all-flags-set.yaml +++ b/pkg/apis/config/testdata/feature-flags-all-flags-set.yaml @@ -29,4 +29,3 @@ data: enforce-nonfalsifiability: "spire" trusted-resources-verification-no-match-policy: "fail" enable-provenance-in-status: "true" - custom-task-version: "v1beta1" diff --git a/pkg/apis/config/testdata/feature-flags-invalid-custom-task-version.yaml b/pkg/apis/config/testdata/feature-flags-invalid-custom-task-version.yaml deleted file mode 100644 index 3c2595ba365..00000000000 --- a/pkg/apis/config/testdata/feature-flags-invalid-custom-task-version.yaml +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright 2021 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: - custom-task-version: "im-not-a-valid-feature-gate" diff --git a/pkg/apis/pipeline/v1beta1/pipelinerun_conversion_test.go b/pkg/apis/pipeline/v1beta1/pipelinerun_conversion_test.go index 664282b1c19..9d062ebd78a 100644 --- a/pkg/apis/pipeline/v1beta1/pipelinerun_conversion_test.go +++ b/pkg/apis/pipeline/v1beta1/pipelinerun_conversion_test.go @@ -317,7 +317,6 @@ func TestPipelineRunConversion(t *testing.T) { VerificationNoMatchPolicy: config.DefaultNoMatchPolicyConfig, ResultExtractionMethod: config.DefaultResultExtractionMethod, MaxResultSize: config.DefaultMaxResultSize, - CustomTaskVersion: config.DefaultCustomTaskVersion, }, }, }, diff --git a/pkg/apis/pipeline/v1beta1/taskrun_conversion_test.go b/pkg/apis/pipeline/v1beta1/taskrun_conversion_test.go index 724479a858f..85b777c8b2e 100644 --- a/pkg/apis/pipeline/v1beta1/taskrun_conversion_test.go +++ b/pkg/apis/pipeline/v1beta1/taskrun_conversion_test.go @@ -244,7 +244,6 @@ func TestTaskRunConversion(t *testing.T) { VerificationNoMatchPolicy: config.DefaultNoMatchPolicyConfig, ResultExtractionMethod: config.DefaultResultExtractionMethod, MaxResultSize: config.DefaultMaxResultSize, - CustomTaskVersion: config.DefaultCustomTaskVersion, }, }}, }, diff --git a/pkg/reconciler/pipelinerun/cancel_test.go b/pkg/reconciler/pipelinerun/cancel_test.go index c15a5c59011..0f024c2de81 100644 --- a/pkg/reconciler/pipelinerun/cancel_test.go +++ b/pkg/reconciler/pipelinerun/cancel_test.go @@ -438,14 +438,6 @@ func TestGetChildObjectsFromPRStatusForTaskNames(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { ctx, _ := ttesting.SetupFakeContext(t) - cfg := config.NewStore(logtesting.TestLogger(t)) - cm := newFeatureFlagsConfigMap() - if tc.useV1Beta1CustomTask { - cm = withCustomTaskVersion(cm, config.CustomTaskVersionBeta) - } - cfg.OnConfigChanged(cm) - ctx = cfg.ToContext(ctx) - trNames, customRunNames, runNames, err := getChildObjectsFromPRStatusForTaskNames(ctx, tc.prStatus, tc.taskNames) if tc.hasError { diff --git a/pkg/reconciler/pipelinerun/pipelinerun.go b/pkg/reconciler/pipelinerun/pipelinerun.go index 5be60d5af97..4cc2f12ea68 100644 --- a/pkg/reconciler/pipelinerun/pipelinerun.go +++ b/pkg/reconciler/pipelinerun/pipelinerun.go @@ -334,21 +334,6 @@ func (c *Reconciler) resolvePipelineState( return r, nil } - cfg := config.FromContextOrDefaults(ctx) - if cfg.FeatureFlags.CustomTaskVersion == config.CustomTaskVersionAlpha { - getRunObjectFunc = func(name string) (v1beta1.RunObject, error) { - r, err := c.runLister.Runs(pr.Namespace).Get(name) - if err != nil { - return nil, err - } - // If we just return c.runLister.Runs(...).Get(...) and there is no run, we end up returning - // a v1beta1.RunObject that won't == nil, so do an explicit check. - if r == nil { - return nil, nil - } - return r, nil - } - } resolvedTask, err := resources.ResolvePipelineTask(ctx, *pr, fn, @@ -904,7 +889,6 @@ func (c *Reconciler) createRunObject(ctx context.Context, runName string, params ctx, span := c.tracerProvider.Tracer(TracerName).Start(ctx, "createRunObject") defer span.End() logger := logging.FromContext(ctx) - cfg := config.FromContextOrDefaults(ctx) taskRunSpec := pr.GetTaskRunSpec(rpt.PipelineTask.Name) params = append(params, rpt.PipelineTask.Params...) @@ -925,44 +909,6 @@ func (c *Reconciler) createRunObject(ctx context.Context, runName string, params Annotations: getTaskrunAnnotations(pr), } - if cfg.FeatureFlags.CustomTaskVersion == config.CustomTaskVersionAlpha { - r := &v1alpha1.Run{ - ObjectMeta: objectMeta, - Spec: v1alpha1.RunSpec{ - Retries: rpt.PipelineTask.Retries, - Ref: rpt.PipelineTask.TaskRef, - Params: params, - ServiceAccountName: taskRunSpec.TaskServiceAccountName, - Timeout: taskTimeout, - Workspaces: workspaces, - }, - } - if rpt.PipelineTask.TaskSpec != nil { - j, err := json.Marshal(rpt.PipelineTask.TaskSpec.Spec) - if err != nil { - return nil, err - } - r.Spec.Spec = &v1alpha1.EmbeddedRunSpec{ - TypeMeta: runtime.TypeMeta{ - APIVersion: rpt.PipelineTask.TaskSpec.APIVersion, - Kind: rpt.PipelineTask.TaskSpec.Kind, - }, - Metadata: rpt.PipelineTask.TaskSpec.Metadata, - Spec: runtime.RawExtension{ - Raw: j, - }, - } - } - // Set the affinity assistant annotation in case the custom task creates TaskRuns or Pods - // that can take advantage of it. - if !c.isAffinityAssistantDisabled(ctx) && pipelinePVCWorkspaceName != "" { - r.Annotations[workspace.AnnotationAffinityAssistantName] = getAffinityAssistantName(pipelinePVCWorkspaceName, pr.Name) - } - - logger.Infof("Creating a new Run object %s", runName) - return c.PipelineClientSet.TektonV1alpha1().Runs(pr.Namespace).Create(ctx, r, metav1.CreateOptions{}) - } - r := &v1beta1.CustomRun{ ObjectMeta: objectMeta, Spec: v1beta1.CustomRunSpec{ @@ -1279,7 +1225,6 @@ func (c *Reconciler) updatePipelineRunStatusFromInformer(ctx context.Context, pr ctx, span := c.tracerProvider.Tracer(TracerName).Start(ctx, "updatePipelineRunStatusFromInformer") defer span.End() logger := logging.FromContext(ctx) - cfg := config.FromContextOrDefaults(ctx) // Get the pipelineRun label that is set on each TaskRun. Do not include the propagated labels from the // Pipeline and PipelineRun. The user could change them during the lifetime of the PipelineRun so the @@ -1292,24 +1237,13 @@ func (c *Reconciler) updatePipelineRunStatusFromInformer(ctx context.Context, pr } var runObjects []v1beta1.RunObject - if cfg.FeatureFlags.CustomTaskVersion == config.CustomTaskVersionAlpha { - legacyRuns, err := c.runLister.Runs(pr.Namespace).List(k8slabels.SelectorFromSet(pipelineRunLabels)) - if err != nil { - logger.Errorf("could not list Runs %#v", err) - return err - } - for _, lr := range legacyRuns { - runObjects = append(runObjects, lr) - } - } else { - customRuns, err := c.customRunLister.CustomRuns(pr.Namespace).List(k8slabels.SelectorFromSet(pipelineRunLabels)) - if err != nil { - logger.Errorf("could not list CustomRuns %#v", err) - return err - } - for _, cr := range customRuns { - runObjects = append(runObjects, cr) - } + customRuns, err := c.customRunLister.CustomRuns(pr.Namespace).List(k8slabels.SelectorFromSet(pipelineRunLabels)) + if err != nil { + logger.Errorf("could not list CustomRuns %#v", err) + return err + } + for _, cr := range customRuns { + runObjects = append(runObjects, cr) } return updatePipelineRunStatusFromChildObjects(ctx, logger, pr, taskRuns, runObjects) diff --git a/pkg/reconciler/pipelinerun/pipelinerun_test.go b/pkg/reconciler/pipelinerun/pipelinerun_test.go index 4192380e60d..1c0ff4faf3b 100644 --- a/pkg/reconciler/pipelinerun/pipelinerun_test.go +++ b/pkg/reconciler/pipelinerun/pipelinerun_test.go @@ -105,7 +105,6 @@ const ( apiFieldsFeatureFlag = "enable-api-fields" ociBundlesFeatureFlag = "enable-tekton-oci-bundles" maxMatrixCombinationsCountFlag = "default-max-matrix-combinations-count" - customTaskVersionFlag = "custom-task-version" ) type PipelineRunTest struct { @@ -366,188 +365,8 @@ spec: verifyTaskRunStatusesNames(t, reconciledRun.Status, tr1Name, tr2Name) } -// TestReconcile_CustomTask runs "Reconcile" on a PipelineRun with one Custom -// Task reference that has not been run yet. It verifies that the Run is -// created, it checks the resulting API actions, status and events. -func TestReconcile_CustomTask(t *testing.T) { - names.TestingSeed() - const pipelineRunName = "test-pipelinerun" - const namespace = "namespace" - - simpleCustomTaskPRYAML := `metadata: - name: test-pipelinerun - namespace: namespace -spec: - pipelineSpec: - tasks: - - name: custom-task - params: - - name: param1 - value: value1 - retries: 3 - taskRef: - apiVersion: example.dev/v0 - kind: Example -` - simpleCustomTaskWantRunYAML := `metadata: - annotations: {} - labels: - tekton.dev/memberOf: tasks - tekton.dev/pipeline: test-pipelinerun - tekton.dev/pipelineRun: test-pipelinerun - tekton.dev/pipelineTask: custom-task - name: test-pipelinerun-custom-task - namespace: namespace - ownerReferences: - - apiVersion: tekton.dev/v1beta1 - blockOwnerDeletion: true - controller: true - kind: PipelineRun - name: test-pipelinerun -spec: - params: - - name: param1 - value: value1 - ref: - apiVersion: example.dev/v0 - kind: Example - retries: 3 - serviceAccountName: default -` - - tcs := []struct { - name string - pr *v1beta1.PipelineRun - wantRun *v1alpha1.Run - }{{ - name: "simple custom task with taskRef", - pr: parse.MustParseV1beta1PipelineRun(t, simpleCustomTaskPRYAML), - wantRun: parse.MustParseRun(t, simpleCustomTaskWantRunYAML), - }, { - name: "simple custom task with taskSpec", - pr: parse.MustParseV1beta1PipelineRun(t, ` -metadata: - name: test-pipelinerun - namespace: namespace -spec: - pipelineSpec: - tasks: - - name: custom-task - params: - - name: param1 - value: value1 - taskSpec: - apiVersion: example.dev/v0 - kind: Example - metadata: - labels: - test-label: test - spec: - field1: 123 - field2: value -`), - wantRun: mustParseRunWithObjectMeta(t, - taskRunObjectMeta("test-pipelinerun-custom-task", "namespace", "test-pipelinerun", "test-pipelinerun", "custom-task", false), - ` -spec: - params: - - name: param1 - value: value1 - serviceAccountName: default - spec: - apiVersion: example.dev/v0 - kind: Example - metadata: - labels: - test-label: test - spec: - field1: 123 - field2: value -`), - }, { - name: "custom task with workspace", - pr: parse.MustParseV1beta1PipelineRun(t, ` -metadata: - name: test-pipelinerun - namespace: namespace -spec: - pipelineSpec: - tasks: - - name: custom-task - taskRef: - apiVersion: example.dev/v0 - kind: Example - workspaces: - - name: taskws - subPath: bar - workspace: pipelinews - workspaces: - - name: pipelinews - workspaces: - - name: pipelinews - persistentVolumeClaim: - claimName: myclaim - subPath: foo -`), - wantRun: mustParseRunWithObjectMeta(t, - taskRunObjectMetaWithAnnotations("test-pipelinerun-custom-task", "namespace", "test-pipelinerun", - "test-pipelinerun", "custom-task", false, map[string]string{ - "pipeline.tekton.dev/affinity-assistant": getAffinityAssistantName("pipelinews", pipelineRunName), - }), - ` -spec: - ref: - apiVersion: example.dev/v0 - kind: Example - serviceAccountName: default - workspaces: - - name: taskws - persistentVolumeClaim: - claimName: myclaim - subPath: foo/bar -`), - }} - - for _, tc := range tcs { - t.Run(tc.name, func(t *testing.T) { - cms := []*corev1.ConfigMap{withCustomTaskVersion(newFeatureFlagsConfigMap(), "v1alpha1")} - - d := test.Data{ - PipelineRuns: []*v1beta1.PipelineRun{tc.pr}, - ConfigMaps: cms, - } - prt := newPipelineRunTest(t, d) - defer prt.Cancel() - - wantEvents := []string{ - "Normal Started", - "Normal Running Tasks Completed: 0", - } - reconciledRun, clients := prt.reconcileRun(namespace, pipelineRunName, wantEvents, false) - - actions := clients.Pipeline.Actions() - if len(actions) < 2 { - t.Fatalf("Expected client to have at least two action implementation but it has %d", len(actions)) - } - - // Check that the expected Run was created. - actual := actions[0].(ktesting.CreateAction).GetObject() - // Ignore the TypeMeta field, because parse.MustParseRun automatically populates it but the "actual" Run won't have it. - if d := cmp.Diff(tc.wantRun, actual, cmpopts.IgnoreFields(v1alpha1.Run{}, "TypeMeta")); d != "" { - t.Errorf("expected to see Run created: %s", diff.PrintWantGot(d)) - } - - // This PipelineRun is in progress now and the status should reflect that - checkPipelineRunConditionStatusAndReason(t, reconciledRun, corev1.ConditionUnknown, v1beta1.PipelineRunReasonRunning.String()) - - verifyCustomRunOrRunStatusesCount(t, run, reconciledRun.Status, 1) - verifyCustomRunOrRunStatusesNames(t, run, reconciledRun.Status, tc.wantRun.Name) - }) - } -} - // TestReconcile_V1Beta1CustomTask runs "Reconcile" on a PipelineRun with one Custom -// Task reference that has not been run yet, with the custom-task-version feature flag set to "v1beta1". +// Task reference that has not been run yet // It verifies that the CustomRun is created, it checks the resulting API actions, status and events. func TestReconcile_V1Beta1CustomTask(t *testing.T) { names.TestingSeed() @@ -690,11 +509,8 @@ spec: for _, tc := range tcs { t.Run(tc.name, func(t *testing.T) { - cms := []*corev1.ConfigMap{withCustomTaskVersion(newFeatureFlagsConfigMap(), "v1beta1")} - d := test.Data{ PipelineRuns: []*v1beta1.PipelineRun{tc.pr}, - ConfigMaps: cms, } prt := newPipelineRunTest(t, d) defer prt.Cancel() @@ -1377,12 +1193,6 @@ func withOCIBundles(cm *corev1.ConfigMap) *corev1.ConfigMap { return newCM } -func withCustomTaskVersion(cm *corev1.ConfigMap, flagVal string) *corev1.ConfigMap { - newCM := cm.DeepCopy() - newCM.Data[customTaskVersionFlag] = flagVal - return newCM -} - func withMaxMatrixCombinationsCount(cm *corev1.ConfigMap, count int) *corev1.ConfigMap { newCM := cm.DeepCopy() newCM.Data[maxMatrixCombinationsCountFlag] = strconv.Itoa(count) @@ -4836,7 +4646,6 @@ metadata: EnableProvenanceInStatus: true, ResultExtractionMethod: config.DefaultResultExtractionMethod, MaxResultSize: config.DefaultMaxResultSize, - CustomTaskVersion: config.DefaultCustomTaskVersion, }, }, }, diff --git a/pkg/reconciler/pipelinerun/timeout_test.go b/pkg/reconciler/pipelinerun/timeout_test.go index 461168fc527..39e09f408db 100644 --- a/pkg/reconciler/pipelinerun/timeout_test.go +++ b/pkg/reconciler/pipelinerun/timeout_test.go @@ -17,7 +17,6 @@ import ( "context" "testing" - "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" _ "github.com/tektoncd/pipeline/pkg/pipelinerunmetrics/fake" // Make sure the pipelinerunmetrics are setup @@ -238,13 +237,6 @@ func TestTimeoutPipelineRun(t *testing.T) { Runs: tc.runs, } ctx, _ := ttesting.SetupFakeContext(t) - cfg := config.NewStore(logtesting.TestLogger(t)) - cm := newFeatureFlagsConfigMap() - if tc.useV1Beta1CustomTasks { - cm = withCustomTaskVersion(cm, config.CustomTaskVersionBeta) - } - cfg.OnConfigChanged(cm) - ctx = cfg.ToContext(ctx) ctx, cancel := context.WithCancel(ctx) defer cancel() c, _ := test.SeedTestData(t, ctx, d) diff --git a/pkg/reconciler/taskrun/taskrun_test.go b/pkg/reconciler/taskrun/taskrun_test.go index 6cd098ca0d6..65bb2e93bd7 100644 --- a/pkg/reconciler/taskrun/taskrun_test.go +++ b/pkg/reconciler/taskrun/taskrun_test.go @@ -3776,7 +3776,6 @@ spec: EnableProvenanceInStatus: true, ResultExtractionMethod: config.DefaultResultExtractionMethod, MaxResultSize: config.DefaultMaxResultSize, - CustomTaskVersion: config.DefaultCustomTaskVersion, }, }, }, diff --git a/test/custom_task_test.go b/test/custom_task_test.go index 5daacc32031..b26af1f0817 100644 --- a/test/custom_task_test.go +++ b/test/custom_task_test.go @@ -30,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" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" @@ -44,7 +43,6 @@ import ( "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" v1 "knative.dev/pkg/apis/duck/v1" - "knative.dev/pkg/system" knativetest "knative.dev/pkg/test" "knative.dev/pkg/test/helpers" ) @@ -70,7 +68,7 @@ func TestCustomTask(t *testing.T) { ctx := context.Background() ctx, cancel := context.WithCancel(ctx) defer cancel() - c, namespace := setUpCustomTask(ctx, t) + c, namespace := setup(ctx, t) knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf) defer tearDown(ctx, t, c, namespace) @@ -138,7 +136,7 @@ spec: // Get the Run name. var runNames []string for _, cr := range pr.Status.ChildReferences { - if cr.Kind == pipeline.RunControllerName { + if cr.Kind == pipeline.CustomRunControllerName { runNames = append(runNames, cr.Name) } } @@ -147,7 +145,7 @@ spec: } for _, runName := range runNames { // Get the Run. - cr, err := c.V1alpha1RunClient.Get(ctx, runName, metav1.GetOptions{}) + cr, err := c.V1beta1CustomRunClient.Get(ctx, runName, metav1.GetOptions{}) if err != nil { t.Fatalf("Failed to get Run %q: %v", runName, err) } @@ -156,36 +154,36 @@ spec: } // Simulate a Custom Task controller updating the CustomRun to done/successful. - cr.Status = v1alpha1.RunStatus{ + cr.Status = v1beta1.CustomRunStatus{ Status: duckv1.Status{ Conditions: duckv1.Conditions{{ Type: apis.ConditionSucceeded, Status: corev1.ConditionTrue, }}, }, - RunStatusFields: v1alpha1.RunStatusFields{ - Results: []v1alpha1.RunResult{{ + CustomRunStatusFields: v1beta1.CustomRunStatusFields{ + Results: []v1beta1.CustomRunResult{{ Name: "runResult", Value: "aResultValue", }}, }, } - if _, err := c.V1alpha1RunClient.UpdateStatus(ctx, cr, metav1.UpdateOptions{}); err != nil { + if _, err := c.V1beta1CustomRunClient.UpdateStatus(ctx, cr, metav1.UpdateOptions{}); err != nil { t.Fatalf("Failed to update Run to successful: %v", err) } // Get the Run. - cr, err = c.V1alpha1RunClient.Get(ctx, runName, metav1.GetOptions{}) + cr, err = c.V1beta1CustomRunClient.Get(ctx, runName, metav1.GetOptions{}) if err != nil { t.Fatalf("Failed to get Run %q: %v", runName, err) } if strings.Contains(runName, "custom-task-spec") { - if d := cmp.Diff(customTaskRawSpec, cr.Spec.Spec.Spec.Raw); d != "" { + if d := cmp.Diff(customTaskRawSpec, cr.Spec.CustomSpec.Spec.Raw); d != "" { t.Fatalf("Unexpected value of Spec.Raw: %s", diff.PrintWantGot(d)) } - if d := cmp.Diff(metadataLabel, cr.Spec.Spec.Metadata.Labels); d != "" { + if d := cmp.Diff(metadataLabel, cr.Spec.CustomSpec.Metadata.Labels); d != "" { t.Fatalf("Unexpected value of Metadata.Labels: %s", diff.PrintWantGot(d)) } } @@ -260,11 +258,11 @@ func WaitForRunSpecCancelled(ctx context.Context, c *clients, name string, desc defer span.End() return pollImmediateWithContext(ctx, func() (bool, error) { - cr, err := c.V1alpha1RunClient.Get(ctx, name, metav1.GetOptions{}) + cr, err := c.V1beta1CustomRunClient.Get(ctx, name, metav1.GetOptions{}) if err != nil { return true, err } - return cr.Spec.Status == v1alpha1.RunSpecStatusCancelled, nil + return cr.Spec.Status == v1beta1.CustomRunSpecStatusCancelled, nil }) } @@ -274,7 +272,7 @@ func TestPipelineRunCustomTaskTimeout(t *testing.T) { // cancel the context after we have waited a suitable buffer beyond the given deadline. ctx, cancel := context.WithTimeout(context.Background(), timeout+2*time.Minute) defer cancel() - c, namespace := setUpCustomTask(ctx, t) + c, namespace := setup(ctx, t) knativetest.CleanupOnInterrupt(func() { tearDown(context.Background(), t, c, namespace) }, t.Logf) defer tearDown(context.Background(), t, c, namespace) @@ -324,7 +322,7 @@ spec: runName = pr.Status.ChildReferences[0].Name // Get the Run. - cr, err := c.V1alpha1RunClient.Get(ctx, runName, metav1.GetOptions{}) + cr, err := c.V1beta1CustomRunClient.Get(ctx, runName, metav1.GetOptions{}) if err != nil { t.Fatalf("Failed to get Run %q: %v", runName, err) } @@ -334,8 +332,8 @@ spec: // Simulate a Custom Task controller updating the Run to be started/running, // because, a Run that has not started cannot timeout. - cr.Status = v1alpha1.RunStatus{ - RunStatusFields: v1alpha1.RunStatusFields{ + cr.Status = v1beta1.CustomRunStatus{ + CustomRunStatusFields: v1beta1.CustomRunStatusFields{ StartTime: &metav1.Time{Time: time.Now()}, }, Status: duckv1.Status{ @@ -345,7 +343,7 @@ spec: }}, }, } - if _, err := c.V1alpha1RunClient.UpdateStatus(ctx, cr, metav1.UpdateOptions{}); err != nil { + if _, err := c.V1beta1CustomRunClient.UpdateStatus(ctx, cr, metav1.UpdateOptions{}); err != nil { t.Fatalf("Failed to update CustomRun to successful: %v", err) } @@ -354,7 +352,7 @@ spec: t.Errorf("Error waiting for PipelineRun %s to finish: %s", pipelineRun.Name, err) } - runList, err := c.V1alpha1RunClient.List(ctx, metav1.ListOptions{LabelSelector: fmt.Sprintf("tekton.dev/pipelineRun=%s", pipelineRun.Name)}) + runList, err := c.V1beta1CustomRunClient.List(ctx, metav1.ListOptions{LabelSelector: fmt.Sprintf("tekton.dev/pipelineRun=%s", pipelineRun.Name)}) if err != nil { t.Fatalf("Error listing Runs for PipelineRun %s: %s", pipelineRun.Name, err) } @@ -378,17 +376,6 @@ spec: } } -func applyController(t *testing.T) { - t.Helper() - t.Log("Creating Wait Custom Task Controller...") - cmd := exec.Command("ko", "apply", "-f", "./config/controller.yaml") - cmd.Dir = waitTaskDir - out, err := cmd.CombinedOutput() - if err != nil { - t.Fatalf("Failed to create Wait Custom Task Controller: %s, Output: %s", err, out) - } -} - func applyV1Beta1Controller(t *testing.T) { t.Helper() t.Log("Creating Wait v1beta1.CustomRun Custom Task Controller...") @@ -400,17 +387,6 @@ func applyV1Beta1Controller(t *testing.T) { } } -func cleanUpController(t *testing.T) { - t.Helper() - t.Log("Tearing down Wait Custom Task Controller...") - cmd := exec.Command("ko", "delete", "-f", "./config/controller.yaml") - cmd.Dir = waitTaskDir - out, err := cmd.CombinedOutput() - if err != nil { - t.Fatalf("Failed to tear down Wait Custom Task Controller: %s, Output: %s", err, out) - } -} - func cleanUpV1Beta1Controller(t *testing.T) { t.Helper() t.Log("Tearing down Wait v1beta1.CustomRun Custom Task Controller...") @@ -422,466 +398,14 @@ func cleanUpV1Beta1Controller(t *testing.T) { } } -func TestWaitCustomTask_Run(t *testing.T) { - ctx := context.Background() - ctx, cancel := context.WithCancel(ctx) - defer cancel() - c, namespace := setUpCustomTask(ctx, t) - knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf) - defer tearDown(ctx, t, c, namespace) - - // Create a custom task controller - applyController(t) - // Cleanup the controller after finishing the test - defer cleanUpController(t) - - for _, tc := range []struct { - name string - duration string - timeout *metav1.Duration - retries int - conditionAccessorFn func(string) ConditionAccessorFn - wantCondition apis.Condition - wantRetriesStatus []v1alpha1.RunStatus - }{{ - name: "Wait Task Has Passed", - duration: "1s", - conditionAccessorFn: Succeed, - wantCondition: apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - Reason: "DurationElapsed", - }, - }, { - name: "Wait Task Is Running", - duration: "2s", - conditionAccessorFn: Running, - wantCondition: apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionUnknown, - Reason: "Running", - }, - }, { - name: "Wait Task Timed Out", - duration: "2s", - timeout: &metav1.Duration{Duration: time.Second}, - conditionAccessorFn: Failed, - wantCondition: apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionFalse, - Reason: "TimedOut", - }, - }, { - name: "Wait Task Retries on Timed Out", - duration: "2s", - timeout: &metav1.Duration{Duration: time.Second}, - retries: 2, - conditionAccessorFn: Failed, - wantCondition: apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionFalse, - Reason: "TimedOut", - }, - wantRetriesStatus: []v1alpha1.RunStatus{ - { - Status: v1.Status{ - Conditions: []apis.Condition{ - { - Type: apis.ConditionSucceeded, - Status: corev1.ConditionFalse, - Reason: "TimedOut", - }, - }, - ObservedGeneration: 1, - }, - }, - { - Status: v1.Status{ - Conditions: []apis.Condition{ - { - Type: apis.ConditionSucceeded, - Status: corev1.ConditionFalse, - Reason: "TimedOut", - }, - }, - ObservedGeneration: 1, - }, - }, - }, - }} { - t.Run(tc.name, func(t *testing.T) { - runName := helpers.ObjectNameForTest(t) - - run := &v1alpha1.Run{ - ObjectMeta: metav1.ObjectMeta{ - Name: runName, - }, - Spec: v1alpha1.RunSpec{ - Timeout: tc.timeout, - Retries: tc.retries, - Ref: &v1beta1.TaskRef{ - APIVersion: apiVersion, - Kind: kind, - }, - Params: v1beta1.Params{{Name: "duration", Value: v1beta1.ParamValue{Type: "string", StringVal: tc.duration}}}, - }, - } - - if _, err := c.V1alpha1RunClient.Create(ctx, run, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Run %q: %v", runName, err) - } - - // Wait for the Run - if err := WaitForRunState(ctx, c, runName, time.Minute, tc.conditionAccessorFn(runName), tc.wantCondition.Reason); err != nil { - t.Fatalf("Waiting for Run to reach status %s: %v", string(tc.wantCondition.Type), err) - } - - // Get the actual Run - gotRun, err := c.V1alpha1RunClient.Get(ctx, runName, metav1.GetOptions{}) - if err != nil { - t.Fatalf("%v", err) - } - - gotCondition := gotRun.GetStatus().GetCondition(apis.ConditionSucceeded) - if gotCondition == nil { - t.Fatal("The Run failed to succeed") - } - - // Compose the expected Run - wantRun := &v1alpha1.Run{ - ObjectMeta: metav1.ObjectMeta{ - Name: runName, - Namespace: namespace, - }, - Spec: v1alpha1.RunSpec{ - Timeout: tc.timeout, - Retries: tc.retries, - Ref: &v1beta1.TaskRef{ - APIVersion: apiVersion, - Kind: kind, - }, - Params: v1beta1.Params{{Name: "duration", Value: v1beta1.ParamValue{Type: "string", StringVal: tc.duration}}}, - ServiceAccountName: "default", - }, - Status: v1alpha1.RunStatus{ - Status: v1.Status{ - Conditions: []apis.Condition{tc.wantCondition}, - ObservedGeneration: 1, - }, - RunStatusFields: v1alpha1.RunStatusFields{ - RetriesStatus: tc.wantRetriesStatus, - }, - }, - } - - if d := cmp.Diff(wantRun, gotRun, - filterTypeMeta, - filterObjectMeta, - filterCondition, - filterRunStatus, - ); d != "" { - t.Errorf("-want +got: %v", d) - } - }) - } -} - -func TestWaitCustomTask_PipelineRun(t *testing.T) { +func TestWaitCustomTask_V1Beta1_PipelineRun(t *testing.T) { ctx := context.Background() ctx, cancel := context.WithCancel(ctx) defer cancel() - c, namespace := setUpCustomTask(ctx, t) + c, namespace := setup(ctx, t) knativetest.CleanupOnInterrupt(func() { tearDown(ctx, t, c, namespace) }, t.Logf) defer tearDown(ctx, t, c, namespace) - // Create a custom task controller - applyController(t) - // Cleanup the controller after finishing the test - defer cleanUpController(t) - - for _, tc := range []struct { - name string - runDuration string - runTimeout *metav1.Duration - runRetries int - prTimeout *metav1.Duration - prConditionAccessorFn func(string) ConditionAccessorFn - wantPrCondition apis.Condition - wantRunStatus v1alpha1.RunStatus - wantRetriesStatus []v1alpha1.RunStatus - }{{ - name: "Wait Task Has Succeeded", - runDuration: "1s", - prTimeout: &metav1.Duration{Duration: time.Minute}, - prConditionAccessorFn: Succeed, - wantPrCondition: apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - Reason: "Succeeded", - }, - wantRunStatus: v1alpha1.RunStatus{ - Status: v1.Status{ - Conditions: []apis.Condition{ - { - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, - Reason: "DurationElapsed", - }, - }, - ObservedGeneration: 1, - }, - }, - }, { - name: "Wait Task Is Running", - runDuration: "2s", - prTimeout: &metav1.Duration{Duration: time.Second * 5}, - prConditionAccessorFn: Running, - wantPrCondition: apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionUnknown, - Reason: "Running", - }, - wantRunStatus: v1alpha1.RunStatus{ - Status: v1.Status{ - Conditions: []apis.Condition{ - { - Type: apis.ConditionSucceeded, - Status: corev1.ConditionUnknown, - Reason: "Running", - }, - }, - ObservedGeneration: 1, - }, - }, - }, { - name: "Wait Task Failed When PipelineRun Is Timeout", - runDuration: "2s", - prTimeout: &metav1.Duration{Duration: time.Second}, - prConditionAccessorFn: Failed, - wantPrCondition: apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionFalse, - Reason: "PipelineRunTimeout", - }, - wantRunStatus: v1alpha1.RunStatus{ - Status: v1.Status{ - Conditions: []apis.Condition{ - { - Type: apis.ConditionSucceeded, - Status: corev1.ConditionFalse, - Reason: "Cancelled", - }, - }, - ObservedGeneration: 2, - }, - }, - }, { - name: "Wait Task Failed on Timeout", - runDuration: "2s", - runTimeout: &metav1.Duration{Duration: time.Second}, - prConditionAccessorFn: Failed, - wantPrCondition: apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionFalse, - Reason: "Failed", - }, - wantRunStatus: v1alpha1.RunStatus{ - Status: v1.Status{ - Conditions: []apis.Condition{ - { - Type: apis.ConditionSucceeded, - Status: corev1.ConditionFalse, - Reason: "TimedOut", - }, - }, - ObservedGeneration: 1, - }, - }, - }, { - name: "Wait Task Retries on Timeout", - runDuration: "2s", - runTimeout: &metav1.Duration{Duration: time.Second}, - runRetries: 1, - prConditionAccessorFn: Failed, - wantPrCondition: apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionFalse, - Reason: "Failed", - }, - wantRunStatus: v1alpha1.RunStatus{ - Status: v1.Status{ - Conditions: []apis.Condition{ - { - Type: apis.ConditionSucceeded, - Status: corev1.ConditionFalse, - Reason: "TimedOut", - }, - }, - ObservedGeneration: 1, - }, - }, - wantRetriesStatus: []v1alpha1.RunStatus{ - { - Status: v1.Status{ - Conditions: []apis.Condition{ - { - Type: apis.ConditionSucceeded, - Status: corev1.ConditionFalse, - Reason: "TimedOut", - }, - }, - ObservedGeneration: 1, - }, - }, - }, - }} { - t.Run(tc.name, func(t *testing.T) { - if tc.prTimeout == nil { - tc.prTimeout = &metav1.Duration{Duration: time.Minute} - } - p := &v1beta1.Pipeline{ - ObjectMeta: metav1.ObjectMeta{ - Name: helpers.ObjectNameForTest(t), - Namespace: namespace, - }, - Spec: v1beta1.PipelineSpec{ - Tasks: []v1beta1.PipelineTask{{ - Name: "wait", - Timeout: tc.runTimeout, - Retries: tc.runRetries, - TaskRef: &v1beta1.TaskRef{ - APIVersion: apiVersion, - Kind: kind, - }, - Params: v1beta1.Params{{Name: "duration", Value: v1beta1.ParamValue{Type: "string", StringVal: tc.runDuration}}}, - }}, - }, - } - pipelineRun := &v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: helpers.ObjectNameForTest(t), - Namespace: namespace, - }, - Spec: v1beta1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{ - Name: p.Name, - }, - Timeout: tc.prTimeout, - }, - } - if _, err := c.V1beta1PipelineClient.Create(ctx, p, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create Pipeline %q: %v", p.Name, err) - } - if _, err := c.V1beta1PipelineRunClient.Create(ctx, pipelineRun, metav1.CreateOptions{}); err != nil { - t.Fatalf("Failed to create PipelineRun %q: %v", pipelineRun.Name, err) - } - - // Wait for the PipelineRun to the desired state - if err := WaitForPipelineRunState(ctx, c, pipelineRun.Name, timeout, tc.prConditionAccessorFn(pipelineRun.Name), string(tc.wantPrCondition.Type), v1beta1Version); err != nil { - t.Fatalf("Error waiting for PipelineRun %q to reach %s: %s", pipelineRun.Name, tc.wantPrCondition.Type, err) - } - - // Get actual pipelineRun - gotPipelineRun, err := c.V1beta1PipelineRunClient.Get(ctx, pipelineRun.Name, metav1.GetOptions{}) - if err != nil { - t.Fatalf("Failed to get PipelineRun %q: %v", pipelineRun.Name, err) - } - - // Start to compose expected PipelineRun - wantPipelineRun := &v1beta1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: pipelineRun.Name, - Namespace: pipelineRun.Namespace, - Labels: map[string]string{ - "tekton.dev/pipeline": p.Name, - }, - }, - Spec: v1beta1.PipelineRunSpec{ - ServiceAccountName: "default", - PipelineRef: &v1beta1.PipelineRef{Name: p.Name}, - Timeout: tc.prTimeout, - }, - Status: v1beta1.PipelineRunStatus{ - Status: duckv1.Status{ - Conditions: []apis.Condition{ - tc.wantPrCondition, - }, - }, - PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - PipelineSpec: &v1beta1.PipelineSpec{ - Tasks: []v1beta1.PipelineTask{ - { - Name: "wait", - Timeout: tc.runTimeout, - Retries: tc.runRetries, - TaskRef: &v1beta1.TaskRef{ - APIVersion: apiVersion, - Kind: kind, - }, - Params: v1beta1.Params{{ - Name: "duration", - Value: v1beta1.ParamValue{Type: "string", StringVal: tc.runDuration}, - }}, - }, - }, - }, - }, - }, - } - - // Compose wantStatus and wantChildStatusReferences. - // We will look in the PipelineRunStatus.ChildReferences for wantChildStatusReferences, and will look at - // the actual CustomRun's status for wantStatus. - if len(gotPipelineRun.Status.ChildReferences) != 1 { - t.Fatalf("PipelineRun had unexpected .status.childReferences; got %d, want 1", len(gotPipelineRun.Status.ChildReferences)) - } - wantRunName := gotPipelineRun.Status.ChildReferences[0].Name - wantPipelineRun.Status.PipelineRunStatusFields.ChildReferences = []v1beta1.ChildStatusReference{{ - TypeMeta: runtime.TypeMeta{ - APIVersion: v1alpha1.SchemeGroupVersion.String(), - Kind: pipeline.RunControllerName, - }, - Name: wantRunName, - PipelineTaskName: "wait", - }} - - wantStatus := tc.wantRunStatus - if tc.wantRetriesStatus != nil { - wantStatus.RetriesStatus = tc.wantRetriesStatus - } - - // Get the Run. - gotRun, err := c.V1alpha1RunClient.Get(ctx, wantRunName, metav1.GetOptions{}) - if err != nil { - t.Fatalf("Failed to get Run %q: %v", wantRunName, err) - } - - if d := cmp.Diff(wantPipelineRun, gotPipelineRun, - filterTypeMeta, - filterObjectMeta, - filterCondition, - filterCustomRunStatus, - filterPipelineRunStatus, - ); d != "" { - t.Errorf("PipelineRun differed. -want, +got: %v", d) - } - - // Compare the Run's status to what we're expecting. - if d := cmp.Diff(wantStatus, gotRun.Status, filterCondition, filterRunStatus); d != "" { - t.Errorf("Run status differed. -want, +got: %v", d) - } - }) - } -} - -func TestWaitCustomTask_V1Beta1_PipelineRun(t *testing.T) { - ctx := context.Background() - ctx, cancel := context.WithCancel(ctx) - defer cancel() - c, namespace := setUpV1Beta1CustomTask(ctx, t) - knativetest.CleanupOnInterrupt(func() { tearDownV1Beta1CustomTask(ctx, t, c, namespace) }, t.Logf) - defer tearDownV1Beta1CustomTask(ctx, t, c, namespace) - // Create a custom task controller applyV1Beta1Controller(t) // Cleanup the controller after finishing the test @@ -1162,50 +686,6 @@ func TestWaitCustomTask_V1Beta1_PipelineRun(t *testing.T) { } } -func setUpCustomTask(ctx context.Context, t *testing.T, fn ...func(context.Context, *testing.T, *clients, string)) (*clients, string) { - t.Helper() - c, ns := setup(ctx, t, fn...) - // Note that this may not work if we run e2e tests in parallel since this feature flag forces custom tasks to be - // created as v1alpha1.Run with this value. i.e. Don't add t.Parallel() for this test. - configMapData := map[string]string{ - "custom-task-version": "v1alpha1", - } - - if err := updateConfigMap(ctx, c.KubeClient, system.Namespace(), config.GetFeatureFlagsConfigName(), configMapData); err != nil { - t.Fatal(err) - } - - return c, ns -} - -func setUpV1Beta1CustomTask(ctx context.Context, t *testing.T, fn ...func(context.Context, *testing.T, *clients, string)) (*clients, string) { - t.Helper() - c, ns := setup(ctx, t, fn...) - // Note that this may not work if we run e2e tests in parallel since this feature flag forces custom tasks to be - // created as v1beta1.CustomRuns i.e. Don't add t.Parallel() for this test. - configMapData := map[string]string{ - "custom-task-version": "v1beta1", - } - - if err := updateConfigMap(ctx, c.KubeClient, system.Namespace(), config.GetFeatureFlagsConfigName(), configMapData); err != nil { - t.Fatal(err) - } - - return c, ns -} - -func tearDownV1Beta1CustomTask(ctx context.Context, t *testing.T, c *clients, namespace string) { - t.Helper() - configMapData := map[string]string{ - "custom-task-version": "v1alpha1", - } - if err := updateConfigMap(ctx, c.KubeClient, system.Namespace(), config.GetFeatureFlagsConfigName(), configMapData); err != nil { - t.Fatal(err) - } - - tearDown(ctx, t, c, namespace) -} - // updateConfigMap updates the config map for specified @name with values. We can't use the one from knativetest because // it assumes that Data is already a non-nil map, and by default, it isn't! func updateConfigMap(ctx context.Context, client kubernetes.Interface, name string, configName string, values map[string]string) error {