Skip to content

Commit

Permalink
avoid setting activeDeadlineSeconds for notimeouts
Browse files Browse the repository at this point in the history
PR tektoncd#4217 introduced better handline of the resource quota by adding
support for activeDeadlineSeconds. activeDeadlineSeconds is calculated
based on this formula:

int64(taskRun.GetTimeout(ctx).Seconds() * 1.5)

In case when a timeout on a task is set to 0s i.e. no timeout, the taskrun
fails with ambiguous message "Invalid value: 0: must be between 1 and
2147483647, inclusive." This is happening because activeDeadlineSeconds is
getting set to 0 in case of a 0s timeout but in this case activeDeadlineSeconds
is getting set to a value out of the permitted range.

This commit is changing the way activeDeadlineSeconds is set such that its not
set at all for a task with 0s timeout.
  • Loading branch information
pritidesai committed Jan 4, 2022
1 parent 02d4f7e commit aacdbb1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,12 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1beta1.TaskRun, taskSpec
if shouldAddReadyAnnotationOnPodCreate(ctx, taskSpec.Sidecars) {
podAnnotations[readyAnnotation] = readyAnnotationValue
}
activeDeadlineSeconds := int64(taskRun.GetTimeout(ctx).Seconds() * deadlineFactor)

var activeDeadlineSeconds *int64
if taskRun.GetTimeout(ctx) != config.NoTimeoutDuration {
activeDeadlineSeconds = new(int64)
*activeDeadlineSeconds = int64(taskRun.GetTimeout(ctx).Seconds() * deadlineFactor)
}

podNameSuffix := "-pod"
if taskRunRetries := len(taskRun.Status.RetriesStatus); taskRunRetries > 0 {
Expand Down Expand Up @@ -342,7 +347,7 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1beta1.TaskRun, taskSpec
PriorityClassName: priorityClassName,
ImagePullSecrets: podTemplate.ImagePullSecrets,
HostAliases: podTemplate.HostAliases,
ActiveDeadlineSeconds: &activeDeadlineSeconds, // Set ActiveDeadlineSeconds to mark the pod as "terminating" (like a Job)
ActiveDeadlineSeconds: activeDeadlineSeconds, // Set ActiveDeadlineSeconds to mark the pod as "terminating" (like a Job)
},
}

Expand Down
49 changes: 49 additions & 0 deletions pkg/pod/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,55 @@ _EOF_
}),
ActiveDeadlineSeconds: &defaultActiveDeadlineSeconds,
},
}, {
desc: "step-with-no-timeout-equivalent-to-0-second-timeout",
ts: v1beta1.TaskSpec{
Steps: []v1beta1.Step{{Container: corev1.Container{
Name: "name",
Image: "image",
Command: []string{"cmd"}, // avoid entrypoint lookup.
},
Timeout: &metav1.Duration{Duration: 0 * time.Second},
}},
},
trs: v1beta1.TaskRunSpec{
Timeout: &metav1.Duration{Duration: 0 * time.Second},
},
want: &corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyNever,
InitContainers: []corev1.Container{placeToolsInit, tektonDirInit(images.EntrypointImage, []v1beta1.Step{{Container: corev1.Container{Name: "name"}}})},
Containers: []corev1.Container{{
Name: "step-name",
Image: "image",
Command: []string{"/tekton/bin/entrypoint"},
Args: []string{
"-wait_file",
"/tekton/downward/ready",
"-wait_file_content",
"-post_file",
"/tekton/run/0/out",
"-termination_path",
"/tekton/termination",
"-step_metadata_dir",
"/tekton/run/0/status",
"-timeout",
"0s",
"-entrypoint",
"cmd",
"--",
},
VolumeMounts: append([]corev1.VolumeMount{binROMount, runMount(0, false), downwardMount, {
Name: "tekton-creds-init-home-0",
MountPath: "/tekton/creds",
}}, implicitVolumeMounts...),
TerminationMessagePath: "/tekton/termination",
}},
Volumes: append(implicitVolumes, binVolume, runVolume(0), downwardVolume, corev1.Volume{
Name: "tekton-creds-init-home-0",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}),
ActiveDeadlineSeconds: nil,
},
}, {
desc: "task-with-creds-init-disabled",
featureFlags: map[string]string{
Expand Down

0 comments on commit aacdbb1

Please sign in to comment.