From fa8538cc48bd271bf1c69fd62c9fd0bfda980930 Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Mon, 4 Dec 2023 10:58:47 +0100 Subject: [PATCH] Do not require `enable-api-fields: alpha` for entrypoint cancellation This commit removes the need for `enable-api-fields: alpha` to enable the entrypoint cancellation. This feature should only behind the `keep-pod-on-cancel: true` feature-flag. Signed-off-by: Vincent Demeester (cherry picked from commit 1b075fb1f56f22abba058f59aaa9efbdfe37ac75) Signed-off-by: Vincent Demeester --- pkg/pod/pod.go | 2 +- pkg/pod/pod_test.go | 2 +- pkg/reconciler/taskrun/taskrun.go | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/pod/pod.go b/pkg/pod/pod.go index cfc7d69d683..26c21109275 100644 --- a/pkg/pod/pod.go +++ b/pkg/pod/pod.go @@ -151,7 +151,7 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1.TaskRun, taskSpec v1.Ta defaultForbiddenEnv := config.FromContextOrDefaults(ctx).Defaults.DefaultForbiddenEnv alphaAPIEnabled := featureFlags.EnableAPIFields == config.AlphaAPIFields sidecarLogsResultsEnabled := config.FromContextOrDefaults(ctx).FeatureFlags.ResultExtractionMethod == config.ResultExtractionMethodSidecarLogs - enableKeepPodOnCancel := alphaAPIEnabled && featureFlags.EnableKeepPodOnCancel + enableKeepPodOnCancel := featureFlags.EnableKeepPodOnCancel setSecurityContext := config.FromContextOrDefaults(ctx).FeatureFlags.SetSecurityContext // Add our implicit volumes first, so they can be overridden by the user if they prefer. diff --git a/pkg/pod/pod_test.go b/pkg/pod/pod_test.go index 70dc7752b3f..fbfbd2019cd 100644 --- a/pkg/pod/pod_test.go +++ b/pkg/pod/pod_test.go @@ -2184,7 +2184,7 @@ _EOF_ FieldRef: &corev1.ObjectFieldSelector{ FieldPath: fmt.Sprintf("metadata.annotations['%s']", readyAnnotation), }, - }}, + }, downwardCancelVolumeItem}, }, }, }, corev1.Volume{ diff --git a/pkg/reconciler/taskrun/taskrun.go b/pkg/reconciler/taskrun/taskrun.go index a72f278eab4..1904dc2d074 100644 --- a/pkg/reconciler/taskrun/taskrun.go +++ b/pkg/reconciler/taskrun/taskrun.go @@ -488,7 +488,6 @@ func (c *Reconciler) reconcile(ctx context.Context, tr *v1.TaskRun, rtr *resourc // current labels may not be set on a previously created Pod. labelSelector := labels.Set{pipeline.TaskRunLabelKey: tr.Name} pos, err := c.podLister.Pods(tr.Namespace).List(labelSelector.AsSelector()) - if err != nil { logger.Errorf("Error listing pods: %v", err) return err @@ -688,8 +687,7 @@ func (c *Reconciler) failTaskRun(ctx context.Context, tr *v1.TaskRun, reason v1. } var err error - if reason == v1.TaskRunReasonCancelled && - (config.FromContextOrDefaults(ctx).FeatureFlags.EnableKeepPodOnCancel && config.FromContextOrDefaults(ctx).FeatureFlags.EnableAPIFields == config.AlphaAPIFields) { + if reason == v1.TaskRunReasonCancelled && (config.FromContextOrDefaults(ctx).FeatureFlags.EnableKeepPodOnCancel) { logger.Infof("canceling task run %q by entrypoint", tr.Name) err = podconvert.CancelPod(ctx, c.KubeClientSet, tr.Namespace, tr.Status.PodName) } else {