From db6ba848e775ec89369fdde134158267c2653806 Mon Sep 17 00:00:00 2001 From: Johnny Bieren Date: Wed, 17 Jul 2024 16:09:26 -0400 Subject: [PATCH] feat(RELEASE-971): add timeouts field to InternalRequests This commit adds the timeouts field to InternalRequests so that we can pass new timeout values to use in the InteralRequest pipelineRuns. Signed-off-by: Johnny Bieren --- api/v1alpha1/internalrequest_types.go | 5 +++++ api/v1alpha1/zz_generated.deepcopy.go | 1 + ...appstudio.redhat.com_internalrequests.yaml | 18 +++++++++++++++++ tekton/pipeline_run.go | 4 ++++ tekton/pipeline_run_test.go | 20 +++++++++++++++++++ 5 files changed, 48 insertions(+) diff --git a/api/v1alpha1/internalrequest_types.go b/api/v1alpha1/internalrequest_types.go index ae06482..50c6982 100644 --- a/api/v1alpha1/internalrequest_types.go +++ b/api/v1alpha1/internalrequest_types.go @@ -22,6 +22,7 @@ import ( "github.com/konflux-ci/operator-toolkit/conditions" "github.com/konflux-ci/internal-services/metrics" + tektonv1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -37,6 +38,10 @@ type InternalRequestSpec struct { // kubebuilder:pruning:PreserveUnknownFields // +optional Params map[string]string `json:"params,omitempty"` + + // Timeouts defines the different Timeouts to use in the InternalRequest PipelineRun execution + // +optional + Timeouts tektonv1beta1.TimeoutFields `json:"timeouts,omitempty"` } // InternalRequestStatus defines the observed state of InternalRequest. diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 6d5a959..06847c2 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -95,6 +95,7 @@ func (in *InternalRequestSpec) DeepCopyInto(out *InternalRequestSpec) { (*out)[key] = val } } + in.Timeouts.DeepCopyInto(&out.Timeouts) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new InternalRequestSpec. diff --git a/config/crd/bases/appstudio.redhat.com_internalrequests.yaml b/config/crd/bases/appstudio.redhat.com_internalrequests.yaml index 02c2f61..79f4cf0 100644 --- a/config/crd/bases/appstudio.redhat.com_internalrequests.yaml +++ b/config/crd/bases/appstudio.redhat.com_internalrequests.yaml @@ -53,6 +53,24 @@ spec: will be translated into a Tekton pipeline pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$ type: string + timeouts: + description: Timeouts defines the different Timeouts to use in the + InternalRequest PipelineRun execution + properties: + finally: + description: Finally sets the maximum allowed duration of this + pipeline's finally + type: string + pipeline: + description: Pipeline sets the maximum allowed duration for execution + of the entire pipeline. The sum of individual timeouts for tasks + and finally must not exceed this value. + type: string + tasks: + description: Tasks sets the maximum allowed duration of this pipeline's + tasks + type: string + type: object required: - request type: object diff --git a/tekton/pipeline_run.go b/tekton/pipeline_run.go index f51a111..7f37355 100644 --- a/tekton/pipeline_run.go +++ b/tekton/pipeline_run.go @@ -89,6 +89,10 @@ func (i *InternalRequestPipelineRun) WithInternalRequest(internalRequest *v1alph metadata.PipelinesTypeLabel: PipelineTypeRelease, } + if internalRequest.Spec.Timeouts != (tektonv1beta1.TimeoutFields{}) { + i.Spec.Timeouts = &internalRequest.Spec.Timeouts + } + return i } diff --git a/tekton/pipeline_run_test.go b/tekton/pipeline_run_test.go index 391f1e2..98719bc 100644 --- a/tekton/pipeline_run_test.go +++ b/tekton/pipeline_run_test.go @@ -20,6 +20,8 @@ import ( "strings" "github.com/konflux-ci/internal-services/api/v1alpha1" + "time" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/operator-framework/operator-lib/handler" @@ -91,6 +93,19 @@ var _ = Describe("PipelineRun", Ordered, func() { Expect(newInternalRequestPipelineRun.Labels[InternalRequestNameLabel]).To(Equal(internalRequest.Name)) Expect(newInternalRequestPipelineRun.Labels[InternalRequestNamespaceLabel]).To(Equal(internalRequest.Namespace)) }) + + It("should contain the timeout values", func() { + + newInternalRequestPipelineRun := NewInternalRequestPipelineRun(internalServicesConfig) + newInternalRequestPipelineRun.WithInternalRequest(internalRequest) + timeouts := &tektonv1beta1.TimeoutFields{ + Pipeline: &metav1.Duration{Duration: 1 * time.Hour}, + Tasks: &metav1.Duration{Duration: 1 * time.Hour}, + Finally: &metav1.Duration{Duration: 1 * time.Hour}, + } + + Expect(newInternalRequestPipelineRun.Spec.Timeouts).To(Equal(timeouts)) + }) }) Context("When calling WithOwner", func() { @@ -175,6 +190,11 @@ var _ = Describe("PipelineRun", Ordered, func() { "foo": "bar", "baz": "qux", }, + Timeouts: tektonv1beta1.TimeoutFields{ + Pipeline: &metav1.Duration{Duration: 1 * time.Hour}, + Tasks: &metav1.Duration{Duration: 1 * time.Hour}, + Finally: &metav1.Duration{Duration: 1 * time.Hour}, + }, }, } internalRequest.Kind = "InternalRequest"