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

Add support for tektoncd/pipeline v1beta1 api version #26818

Closed
Closed
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions prow/apis/prowjobs/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"strings"
"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"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down Expand Up @@ -187,7 +187,7 @@ type ProwJobSpec struct {
// PipelineRunSpec provides the basis for running the test as
// a pipeline-crd resource
// https://github.com/tektoncd/pipeline
PipelineRunSpec *pipelinev1alpha1.PipelineRunSpec `json:"pipeline_run_spec,omitempty"`
PipelineRunSpec *pipelinev1beta1.PipelineRunSpec `json:"pipeline_run_spec,omitempty"`

// DecorationConfig holds configuration options for
// decorating PodSpecs that users provide
Expand Down
4 changes: 2 additions & 2 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.

22 changes: 11 additions & 11 deletions prow/cmd/checkconfig/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1295,21 +1295,21 @@ func TestVerifyOwnersPresence(t *testing.T) {
expected: "",
}, {
description: "org with blunderbuss enabled contains a repo without OWNERS",
cfg: &plugins.Configuration{Plugins: plugins.Plugins{"org": {Plugins: []string{"blunderbuss"}}}},
cfg: &plugins.Configuration{Plugins: plugins.Plugins{"org": plugins.OrgPlugins{Plugins: []string{"blunderbuss"}}}},
gh: fakeGH{files: fakeGHContent{"org": {"repo": {"NOOWNERS": true}}}},
expected: "the following orgs or repos enable at least one" +
" plugin that uses OWNERS files (approve, blunderbuss, owners-label), but" +
" its master branch does not contain a root level OWNERS file: [org/repo]",
}, {
description: "org with approve enable contains a repo without OWNERS",
cfg: &plugins.Configuration{Plugins: plugins.Plugins{"org": {Plugins: []string{"approve"}}}},
cfg: &plugins.Configuration{Plugins: plugins.Plugins{"org": plugins.OrgPlugins{Plugins: []string{"approve"}}}},
gh: fakeGH{files: fakeGHContent{"org": {"repo": {"NOOWNERS": true}}}},
expected: "the following orgs or repos enable at least one" +
" plugin that uses OWNERS files (approve, blunderbuss, owners-label), but" +
" its master branch does not contain a root level OWNERS file: [org/repo]",
}, {
description: "org with approve excluded contains a repo without OWNERS",
cfg: &plugins.Configuration{Plugins: plugins.Plugins{"org": {
cfg: &plugins.Configuration{Plugins: plugins.Plugins{"org": plugins.OrgPlugins{
Plugins: []string{"approve"},
ExcludedRepos: []string{"repo"},
}}},
Expand All @@ -1318,51 +1318,51 @@ func TestVerifyOwnersPresence(t *testing.T) {
}, {
description: "org with approve repo-enabled contains a repo without OWNERS",
cfg: &plugins.Configuration{Plugins: plugins.Plugins{
"org": {
"org": plugins.OrgPlugins{
Plugins: []string{"approve"},
ExcludedRepos: []string{"repo"},
},
"org/repo": {Plugins: []string{"approve"}},
"org/repo": plugins.OrgPlugins{Plugins: []string{"approve"}},
}},
gh: fakeGH{files: fakeGHContent{"org": {"repo": {"NOOWNERS": true}}}},
expected: "the following orgs or repos enable at least one" +
" plugin that uses OWNERS files (approve, blunderbuss, owners-label), but" +
" its master branch does not contain a root level OWNERS file: [org/repo]",
}, {
description: "org with owners-label enabled contains a repo without OWNERS",
cfg: &plugins.Configuration{Plugins: plugins.Plugins{"org": {Plugins: []string{"owners-label"}}}},
cfg: &plugins.Configuration{Plugins: plugins.Plugins{"org": plugins.OrgPlugins{Plugins: []string{"owners-label"}}}},
gh: fakeGH{files: fakeGHContent{"org": {"repo": {"NOOWNERS": true}}}},
expected: "the following orgs or repos enable at least one" +
" plugin that uses OWNERS files (approve, blunderbuss, owners-label), but" +
" its master branch does not contain a root level OWNERS file: [org/repo]",
}, {
description: "org with owners-label enabled contains an *archived* repo without OWNERS",
cfg: &plugins.Configuration{Plugins: plugins.Plugins{"org": {Plugins: []string{"owners-label"}}}},
cfg: &plugins.Configuration{Plugins: plugins.Plugins{"org": plugins.OrgPlugins{Plugins: []string{"owners-label"}}}},
gh: fakeGH{
files: fakeGHContent{"org": {"repo": {"NOOWNERS": true}}},
archived: map[string]bool{"org/repo": true},
},
expected: "",
}, {
description: "repo with owners-label enabled does not contain OWNERS",
cfg: &plugins.Configuration{Plugins: plugins.Plugins{"org/repo": {Plugins: []string{"owners-label"}}}},
cfg: &plugins.Configuration{Plugins: plugins.Plugins{"org/repo": plugins.OrgPlugins{Plugins: []string{"owners-label"}}}},
gh: fakeGH{files: fakeGHContent{"org": {"repo": {"NOOWNERS": true}}}},
expected: "the following orgs or repos enable at least one" +
" plugin that uses OWNERS files (approve, blunderbuss, owners-label), but" +
" its master branch does not contain a root level OWNERS file: [org/repo]",
}, {
description: "org with owners-label enabled contains only repos with OWNERS",
cfg: &plugins.Configuration{Plugins: plugins.Plugins{"org": {Plugins: []string{"owners-label"}}}},
cfg: &plugins.Configuration{Plugins: plugins.Plugins{"org": plugins.OrgPlugins{Plugins: []string{"owners-label"}}}},
gh: fakeGH{files: fakeGHContent{"org": {"repo": {"OWNERS": true}}}},
expected: "",
}, {
description: "repo with owners-label enabled contains OWNERS",
cfg: &plugins.Configuration{Plugins: plugins.Plugins{"org/repo": {Plugins: []string{"owners-label"}}}},
cfg: &plugins.Configuration{Plugins: plugins.Plugins{"org/repo": plugins.OrgPlugins{Plugins: []string{"owners-label"}}}},
gh: fakeGH{files: fakeGHContent{"org": {"repo": {"OWNERS": true}}}},
expected: "",
}, {
description: "repo with unrelated plugin enabled does not contain OWNERS",
cfg: &plugins.Configuration{Plugins: plugins.Plugins{"org/repo": {Plugins: []string{"cat"}}}},
cfg: &plugins.Configuration{Plugins: plugins.Plugins{"org/repo": plugins.OrgPlugins{Plugins: []string{"cat"}}}},
gh: fakeGH{files: fakeGHContent{"org": {"repo": {"NOOWNERS": true}}}},
expected: "",
},
Expand Down
2 changes: 1 addition & 1 deletion prow/cmd/deck/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ func TestHandleConfig(t *testing.T) {
func TestHandlePluginConfig(t *testing.T) {
c := plugins.Configuration{
Plugins: plugins.Plugins{
"org/repo": {Plugins: []string{
"org/repo": plugins.OrgPlugins{Plugins: []string{
"approve",
"lgtm",
}},
Expand Down
29 changes: 15 additions & 14 deletions prow/cmd/pipeline/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (

"github.com/sirupsen/logrus"
pipelinev1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
pipelinev1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
untypedcorev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -259,7 +260,7 @@ func (c *controller) enqueueKey(ctx string, obj interface{}) {
ns = o.Namespace
}
c.workqueue.AddRateLimited(toKey(ctx, ns, o.Name))
case *pipelinev1alpha1.PipelineRun:
case *pipelinev1beta1.PipelineRun:
c.workqueue.AddRateLimited(toKey(ctx, o.Namespace, o.Name))
default:
logrus.Warnf("cannot enqueue unknown type %T: %v", o, obj)
Expand All @@ -270,9 +271,9 @@ func (c *controller) enqueueKey(ctx string, obj interface{}) {
type reconciler interface {
getProwJob(name string) (*prowjobv1.ProwJob, error)
patchProwJob(pj *prowjobv1.ProwJob, newpj *prowjobv1.ProwJob) (*prowjobv1.ProwJob, error)
getPipelineRun(context, namespace, name string) (*pipelinev1alpha1.PipelineRun, error)
getPipelineRun(context, namespace, name string) (*pipelinev1beta1.PipelineRun, error)
deletePipelineRun(context, namespace, name string) error
createPipelineRun(context, namespace string, b *pipelinev1alpha1.PipelineRun) (*pipelinev1alpha1.PipelineRun, error)
createPipelineRun(context, namespace string, b *pipelinev1beta1.PipelineRun) (*pipelinev1beta1.PipelineRun, error)
pipelineID(prowjobv1.ProwJob) (string, string, error)
now() metav1.Time
}
Expand All @@ -299,7 +300,7 @@ func (c *controller) patchProwJob(pj *prowjobv1.ProwJob, newpj *prowjobv1.ProwJo
return pjutil.PatchProwjob(context.TODO(), c.pjc.ProwV1().ProwJobs(c.pjNamespace()), logrus.NewEntry(logrus.StandardLogger()), *pj, *newpj)
}

func (c *controller) getPipelineRun(context, namespace, name string) (*pipelinev1alpha1.PipelineRun, error) {
func (c *controller) getPipelineRun(context, namespace, name string) (*pipelinev1beta1.PipelineRun, error) {
p, err := c.getPipelineConfig(context)
if err != nil {
return nil, err
Expand All @@ -313,16 +314,16 @@ func (c *controller) deletePipelineRun(pContext, namespace, name string) error {
if err != nil {
return err
}
return p.client.TektonV1alpha1().PipelineRuns(namespace).Delete(context.TODO(), name, metav1.DeleteOptions{})
return p.client.TektonV1beta1().PipelineRuns(namespace).Delete(context.TODO(), name, metav1.DeleteOptions{})
}

func (c *controller) createPipelineRun(pContext, namespace string, p *pipelinev1alpha1.PipelineRun) (*pipelinev1alpha1.PipelineRun, error) {
func (c *controller) createPipelineRun(pContext, namespace string, p *pipelinev1beta1.PipelineRun) (*pipelinev1beta1.PipelineRun, error) {
logrus.Debugf("createPipelineRun(%s,%s,%s)", pContext, namespace, p.Name)
pc, err := c.getPipelineConfig(pContext)
if err != nil {
return nil, err
}
p, err = pc.client.TektonV1alpha1().PipelineRuns(namespace).Create(context.TODO(), p, metav1.CreateOptions{})
p, err = pc.client.TektonV1beta1().PipelineRuns(namespace).Create(context.TODO(), p, metav1.CreateOptions{})
if err != nil {
return p, err
}
Expand Down Expand Up @@ -504,7 +505,7 @@ const (
)

// prowJobStatus returns the desired state and description based on the pipeline status
func prowJobStatus(ps pipelinev1alpha1.PipelineRunStatus) (prowjobv1.ProwJobState, string) {
func prowJobStatus(ps pipelinev1beta1.PipelineRunStatus) (prowjobv1.ProwJobState, string) {
started := ps.StartTime
finished := ps.CompletionTime
pcond := ps.GetCondition(apis.ConditionSucceeded)
Expand Down Expand Up @@ -573,7 +574,7 @@ func makePipelineGitResource(name string, refs prowjobv1.Refs, pj prowjobv1.Prow
ObjectMeta: pipelineMeta(name, pj),
Spec: pipelinev1alpha1.PipelineResourceSpec{
Type: pipelinev1alpha1.PipelineResourceTypeGit,
qaifshaikh marked this conversation as resolved.
Show resolved Hide resolved
Params: []pipelinev1alpha1.ResourceParam{
Params: []pipelinev1beta1.ResourceParam{
{
Name: "url",
Value: sourceURL,
Expand All @@ -590,7 +591,7 @@ func makePipelineGitResource(name string, refs prowjobv1.Refs, pj prowjobv1.Prow

// makePipeline creates a PipelineRun and substitutes ProwJob managed pipeline resources with ResourceSpec instead of ResourceRef
// so that we don't have to take care of potentially dangling created pipeline resources.
func makePipelineRun(pj prowjobv1.ProwJob) (*pipelinev1alpha1.PipelineRun, error) {
func makePipelineRun(pj prowjobv1.ProwJob) (*pipelinev1beta1.PipelineRun, error) {
// First validate.
if pj.Spec.PipelineRunSpec == nil {
return nil, errors.New("no PipelineSpec defined")
Expand All @@ -603,7 +604,7 @@ func makePipelineRun(pj prowjobv1.ProwJob) (*pipelinev1alpha1.PipelineRun, error
return nil, fmt.Errorf("invalid pipeline_run_spec: %w", err)
}

p := pipelinev1alpha1.PipelineRun{
p := pipelinev1beta1.PipelineRun{
ObjectMeta: pipelineMeta(pj.Name, pj),
Spec: *pj.Spec.PipelineRunSpec.DeepCopy(),
}
Expand All @@ -616,10 +617,10 @@ func makePipelineRun(pj prowjobv1.ProwJob) (*pipelinev1alpha1.PipelineRun, error
for _, key := range sets.StringKeySet(env).List() {
val := env[key]
// TODO: make this handle existing values/substitutions.
p.Spec.Params = append(p.Spec.Params, pipelinev1alpha1.Param{
p.Spec.Params = append(p.Spec.Params, pipelinev1beta1.Param{
Name: key,
Value: pipelinev1alpha1.ArrayOrString{
Type: pipelinev1alpha1.ParamTypeString,
Value: pipelinev1beta1.ArrayOrString{
Type: pipelinev1beta1.ParamTypeString,
StringVal: val,
},
})
Expand Down
Loading