Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add stepaction as a valid kind in the hub resolver #8635

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/apis/pipeline/v1/pipelinerun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,10 @@ type PipelineTaskRunSpec struct {

// Compute resources to use for this TaskRun
ComputeResources *corev1.ResourceRequirements `json:"computeResources,omitempty"`

// Timeout is the Time duration to wait for the TaskRun associated with the PipelineTask to complete.
// +optional
Timeout *metav1.Duration `json:"timeout,omitempty"`
}

// GetTaskRunSpec returns the task specific spec for a given
Expand All @@ -678,6 +682,7 @@ func (pr *PipelineRun) GetTaskRunSpec(pipelineTaskName string) PipelineTaskRunSp
s.SidecarSpecs = task.SidecarSpecs
s.Metadata = task.Metadata
s.ComputeResources = task.ComputeResources
s.Timeout = task.Timeout
}
}
return s
Expand Down
27 changes: 26 additions & 1 deletion pkg/apis/pipeline/v1/pipelinerun_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,23 @@
wsNames[ws.Name] = idx
}
}

// Validate task-specific timeouts in taskRunSpecs
for _, trs := range ps.TaskRunSpecs {
if trs.Timeout != nil {
if trs.Timeout.Duration < 0 {
errs = errs.Also(apis.ErrInvalidValue(fmt.Sprintf("%s should be >= 0", trs.Timeout.Duration.String()), fmt.Sprintf("taskRunSpecs[%s].timeout", trs.PipelineTaskName)))

Check failure on line 125 in pkg/apis/pipeline/v1/pipelinerun_validation.go

View workflow job for this annotation

GitHub Actions / lint

fmt.Sprintf can be replaced with string concatenation (perfsprint)
}
if ps.Timeouts != nil && ps.Timeouts.Pipeline != nil && trs.Timeout.Duration > ps.Timeouts.Pipeline.Duration {
errs = errs.Also(apis.ErrInvalidValue(fmt.Sprintf("%s should be <= pipeline duration", trs.Timeout.Duration.String()), fmt.Sprintf("taskRunSpecs[%s].timeout", trs.PipelineTaskName)))

Check failure on line 128 in pkg/apis/pipeline/v1/pipelinerun_validation.go

View workflow job for this annotation

GitHub Actions / lint

fmt.Sprintf can be replaced with string concatenation (perfsprint)
}
}
}

for idx, trs := range ps.TaskRunSpecs {
errs = errs.Also(validateTaskRunSpec(ctx, trs).ViaIndex(idx).ViaField("taskRunSpecs"))
if err := validateTaskRunSpec(ctx, trs); err != nil {
errs = errs.Also(err.ViaFieldIndex("taskRunSpecs", idx))
}
}

if ps.TaskRunTemplate.PodTemplate != nil {
Expand Down Expand Up @@ -310,6 +325,16 @@
errs = errs.Also(apis.ErrInvalidValue(fmt.Sprintf("%s + %s %s", ps.Timeouts.Tasks.Duration.String(), ps.Timeouts.Finally.Duration.String(), errorMsg), "timeouts.finally"))
}
}

// Validate task-specific timeouts in taskRunSpecs
for _, trs := range ps.TaskRunSpecs {
if trs.Timeout != nil {
if trs.Timeout.Duration > timeout && timeout != config.NoTimeoutDuration {
errs = errs.Also(apis.ErrInvalidValue(fmt.Sprintf("%s should be <= pipeline duration", trs.Timeout.Duration.String()), fmt.Sprintf("taskRunSpecs[%s].timeout", trs.PipelineTaskName)))

Check failure on line 333 in pkg/apis/pipeline/v1/pipelinerun_validation.go

View workflow job for this annotation

GitHub Actions / lint

fmt.Sprintf can be replaced with string concatenation (perfsprint)
}
}
}

return errs
}

Expand Down
37 changes: 37 additions & 0 deletions pkg/apis/pipeline/v1/pipelinerun_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,43 @@ func TestPipelineRun_InvalidTimeouts(t *testing.T) {
},
},
want: apis.ErrInvalidValue("-48h0m0s should be >= 0", "spec.timeouts.pipeline"),
}, {
name: "negative task-specific timeout",
pr: v1.PipelineRun{
ObjectMeta: metav1.ObjectMeta{
Name: "pipelinelinename",
},
Spec: v1.PipelineRunSpec{
PipelineRef: &v1.PipelineRef{
Name: "prname",
},
TaskRunSpecs: []v1.PipelineTaskRunSpec{{
PipelineTaskName: "task1",
Timeout: &metav1.Duration{Duration: -1 * time.Hour},
}},
},
},
want: apis.ErrInvalidValue("-1h0m0s should be >= 0", "spec.taskRunSpecs[task1].timeout"),
}, {
name: "task-specific timeout exceeds pipeline timeout",
pr: v1.PipelineRun{
ObjectMeta: metav1.ObjectMeta{
Name: "pipelinelinename",
},
Spec: v1.PipelineRunSpec{
PipelineRef: &v1.PipelineRef{
Name: "prname",
},
Timeouts: &v1.TimeoutFields{
Pipeline: &metav1.Duration{Duration: 1 * time.Hour},
},
TaskRunSpecs: []v1.PipelineTaskRunSpec{{
PipelineTaskName: "task1",
Timeout: &metav1.Duration{Duration: 2 * time.Hour},
}},
},
},
want: apis.ErrInvalidValue("2h0m0s should be <= pipeline duration", "spec.taskRunSpecs[task1].timeout"),
}, {
name: "negative pipeline tasks Timeout",
pr: v1.PipelineRun{
Expand Down
13 changes: 11 additions & 2 deletions pkg/remoteresolution/resolver/hub/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,16 @@ func TestValidate(t *testing.T) {
version: "bar",
catalog: "baz",
hubType: ArtifactHubType,
}, {
},
{
testName: "stepaction validation",
kind: "stepaction",
resourceName: "foo",
version: "bar",
catalog: "baz",
hubType: ArtifactHubType,
},
{
testName: "tekton type validation",
kind: "task",
resourceName: "foo",
Expand Down Expand Up @@ -134,7 +143,7 @@ func TestValidateConflictingKindName(t *testing.T) {
hubType string
}{
{
kind: "not-taskpipeline",
kind: "not-taskpipelineorstepaction",
name: "foo",
version: "bar",
catalog: "baz",
Expand Down
4 changes: 2 additions & 2 deletions pkg/resolution/resolver/hub/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ func validateParams(ctx context.Context, paramsMap map[string]string, tektonHubU
missingParams = append(missingParams, ParamVersion)
}
if kind, ok := paramsMap[ParamKind]; ok {
if kind != "task" && kind != "pipeline" {
return errors.New("kind param must be task or pipeline")
if kind != "task" && kind != "pipeline" && kind != "stepaction" {
return errors.New("kind param must be either a task, pipeline or a stepaction")
Comment on lines +362 to +363
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional suggestion: I like they way this was addressed in the Cluster Resolver, with a const list of supportedKinds. Any objection to following that pattern?

}
}
if hubType, ok := paramsMap[ParamType]; ok {
Expand Down
13 changes: 11 additions & 2 deletions pkg/resolution/resolver/hub/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,16 @@ func TestValidateParams(t *testing.T) {
version: "bar",
catalog: "baz",
hubType: ArtifactHubType,
}, {
},
{
testName: "stepaction validation",
kind: "stepaction",
resourceName: "foo",
version: "bar",
catalog: "baz",
hubType: ArtifactHubType,
},
{
testName: "tekton type validation",
kind: "task",
resourceName: "foo",
Expand Down Expand Up @@ -148,7 +157,7 @@ func TestValidateParamsConflictingKindName(t *testing.T) {
hubType string
}{
{
kind: "not-taskpipeline",
kind: "not-taskpipelineorstepaction",
name: "foo",
version: "bar",
catalog: "baz",
Expand Down
Loading