Skip to content

Commit

Permalink
Merge pull request #27034 from eddycharly/tkn-beta
Browse files Browse the repository at this point in the history
feat: add tekton v1beta1 support
  • Loading branch information
k8s-ci-robot committed Jan 11, 2023
2 parents bc7ab92 + 2adf64c commit cd1b3ca
Show file tree
Hide file tree
Showing 13 changed files with 23,200 additions and 142 deletions.
22,314 changes: 22,314 additions & 0 deletions config/prow/cluster/prowjob-crd/prowjob_customresourcedefinition.yaml

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions prow/apis/prowjobs/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1

import (
"context"
"encoding/json"
"errors"
"fmt"
Expand All @@ -26,6 +27,7 @@ import (
"time"

pipelinev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -193,6 +195,11 @@ type ProwJobSpec struct {
// https://github.com/tektoncd/pipeline
PipelineRunSpec *pipelinev1alpha1.PipelineRunSpec `json:"pipeline_run_spec,omitempty"`

// TektonPipelineRunSpec provides the basis for running the test as
// a pipeline-crd resource
// https://github.com/tektoncd/pipeline
TektonPipelineRunSpec *TektonPipelineRunSpec `json:"tekton_pipeline_run_spec,omitempty"`

// DecorationConfig holds configuration options for
// decorating PodSpecs that users provide
DecorationConfig *DecorationConfig `json:"decoration_config,omitempty"`
Expand Down Expand Up @@ -224,6 +231,34 @@ type ProwJobSpec struct {
JobQueueName string `json:"job_queue_name,omitempty"`
}

func (pjs ProwJobSpec) HasPipelineRunSpec() bool {
if pjs.TektonPipelineRunSpec != nil && pjs.TektonPipelineRunSpec.V1Beta1 != nil {
return true
}
if pjs.PipelineRunSpec != nil {
return true
}
return false
}

func (pjs ProwJobSpec) GetPipelineRunSpec() (*pipelinev1beta1.PipelineRunSpec, error) {
var found *pipelinev1beta1.PipelineRunSpec
if pjs.TektonPipelineRunSpec != nil {
found = pjs.TektonPipelineRunSpec.V1Beta1
}
if found == nil && pjs.PipelineRunSpec != nil {
var spec pipelinev1beta1.PipelineRunSpec
if err := pjs.PipelineRunSpec.ConvertTo(context.TODO(), &spec); err != nil {
return nil, err
}
found = &spec
}
if found == nil {
return nil, errors.New("pipeline run spec not found")
}
return found, nil
}

type GitHubTeamSlug struct {
Slug string `json:"slug"`
Org string `json:"org"`
Expand Down Expand Up @@ -1080,6 +1115,11 @@ type JenkinsSpec struct {
GitHubBranchSourceJob bool `json:"github_branch_source_job,omitempty"`
}

// TektonPipelineRunSpec is optional parameters for Tekton pipeline jobs.
type TektonPipelineRunSpec struct {
V1Beta1 *pipelinev1beta1.PipelineRunSpec `json:"v1beta1,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ProwJobList is a list of ProwJob resources
Expand Down
180 changes: 180 additions & 0 deletions prow/apis/prowjobs/v1/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ limitations under the License.
package v1

import (
"reflect"
"strconv"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
fuzz "github.com/google/gofuzz"
pipelinev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
)

func pStr(str string) *string {
Expand Down Expand Up @@ -662,3 +665,180 @@ func TestParsePath(t *testing.T) {
})
}
}

func TestProwJobSpec_HasPipelineRunSpec(t *testing.T) {
type fields struct {
PipelineRunSpec *pipelinev1alpha1.PipelineRunSpec
TektonPipelineRunSpec *TektonPipelineRunSpec
}
tests := []struct {
name string
fields fields
want bool
}{{
name: "none set",
want: false,
}, {
name: "PipelineRunSpec set",
fields: fields{
PipelineRunSpec: &pipelinev1alpha1.PipelineRunSpec{},
},
want: true,
}, {
name: "TektonPipelineRunSpec set",
fields: fields{
TektonPipelineRunSpec: &TektonPipelineRunSpec{},
},
want: false,
}, {
name: "TektonPipelineRunSpec.V1VBeta1 set",
fields: fields{
TektonPipelineRunSpec: &TektonPipelineRunSpec{
V1Beta1: &pipelinev1beta1.PipelineRunSpec{},
},
},
want: true,
}, {
name: "both set",
fields: fields{
PipelineRunSpec: &pipelinev1alpha1.PipelineRunSpec{},
TektonPipelineRunSpec: &TektonPipelineRunSpec{
V1Beta1: &pipelinev1beta1.PipelineRunSpec{},
},
},
want: true,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
pjs := ProwJobSpec{
PipelineRunSpec: tt.fields.PipelineRunSpec,
TektonPipelineRunSpec: tt.fields.TektonPipelineRunSpec,
}
if got := pjs.HasPipelineRunSpec(); got != tt.want {
t.Errorf("ProwJobSpec.HasPipelineRunSpec() = %v, want %v", got, tt.want)
}
})
}
}

func TestProwJobSpec_GetPipelineRunSpec(t *testing.T) {
type fields struct {
PipelineRunSpec *pipelinev1alpha1.PipelineRunSpec
TektonPipelineRunSpec *TektonPipelineRunSpec
}
tests := []struct {
name string
fields fields
want *pipelinev1beta1.PipelineRunSpec
wantErr bool
}{
{
name: "none set",
fields: fields{
PipelineRunSpec: nil,
TektonPipelineRunSpec: nil,
},
wantErr: true,
},
{
name: "only PipelineRunSpec set",
fields: fields{
PipelineRunSpec: &pipelinev1alpha1.PipelineRunSpec{
ServiceAccountName: "robot",
Resources: []pipelinev1alpha1.PipelineResourceBinding{
{
Name: "implicit git resource",
ResourceRef: &pipelinev1alpha1.PipelineResourceRef{Name: "abc"},
},
},
},
TektonPipelineRunSpec: nil,
},
want: &pipelinev1beta1.PipelineRunSpec{
ServiceAccountName: "robot",
Resources: []pipelinev1beta1.PipelineResourceBinding{
{
Name: "implicit git resource",
ResourceRef: &pipelinev1beta1.PipelineResourceRef{Name: "abc"},
},
},
},
},
{
name: "only TektonPipelineRunSpec set",
fields: fields{
PipelineRunSpec: nil,
TektonPipelineRunSpec: &TektonPipelineRunSpec{
V1Beta1: &pipelinev1beta1.PipelineRunSpec{
ServiceAccountName: "robot",
Resources: []pipelinev1beta1.PipelineResourceBinding{
{
Name: "implicit git resource",
ResourceRef: &pipelinev1beta1.PipelineResourceRef{Name: "abc"},
},
},
},
},
},
want: &pipelinev1beta1.PipelineRunSpec{
ServiceAccountName: "robot",
Resources: []pipelinev1beta1.PipelineResourceBinding{
{
Name: "implicit git resource",
ResourceRef: &pipelinev1beta1.PipelineResourceRef{Name: "abc"},
},
},
},
},
{
name: "PipelineRunSpec and TektonPipelineRunSpec set",
fields: fields{
PipelineRunSpec: &pipelinev1alpha1.PipelineRunSpec{
ServiceAccountName: "robot",
Resources: []pipelinev1alpha1.PipelineResourceBinding{
{
Name: "implicit git resource",
ResourceRef: &pipelinev1alpha1.PipelineResourceRef{Name: "abc"},
},
},
},
TektonPipelineRunSpec: &TektonPipelineRunSpec{
V1Beta1: &pipelinev1beta1.PipelineRunSpec{
ServiceAccountName: "robot",
Resources: []pipelinev1beta1.PipelineResourceBinding{
{
Name: "implicit git resource",
ResourceRef: &pipelinev1beta1.PipelineResourceRef{Name: "def"},
},
},
},
},
},
want: &pipelinev1beta1.PipelineRunSpec{
ServiceAccountName: "robot",
Resources: []pipelinev1beta1.PipelineResourceBinding{
{
Name: "implicit git resource",
ResourceRef: &pipelinev1beta1.PipelineResourceRef{Name: "def"},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
pjs := ProwJobSpec{
PipelineRunSpec: tt.fields.PipelineRunSpec,
TektonPipelineRunSpec: tt.fields.TektonPipelineRunSpec,
}
got, err := pjs.GetPipelineRunSpec()
if (err != nil) != tt.wantErr {
t.Errorf("ProwJobSpec.GetPipelineRunSpec() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("ProwJobSpec.GetPipelineRunSpec() = %v, want %v", got, tt.want)
}
})
}
}
27 changes: 27 additions & 0 deletions prow/apis/prowjobs/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cd1b3ca

Please sign in to comment.