Skip to content

Commit

Permalink
feat: support multiple tekton pipeline versions
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
  • Loading branch information
eddycharly committed Aug 4, 2022
1 parent 682eb8d commit 79c5a0a
Show file tree
Hide file tree
Showing 10 changed files with 37,288 additions and 64 deletions.
37,136 changes: 37,136 additions & 0 deletions config/prow/cluster/prowjob-crd/prowjob_customresourcedefinition.yaml

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion prow/apis/prowjobs/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down Expand Up @@ -187,7 +188,12 @@ 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"`
PipelineRunSpecXXX *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
Expand Down Expand Up @@ -1060,6 +1066,12 @@ type JenkinsSpec struct {
GitHubBranchSourceJob bool `json:"github_branch_source_job,omitempty"`
}

// TektonPipelineRunSpec is optional parameters for Tekton pipeline jobs.
type TektonPipelineRunSpec struct {
V1Alpha1 *pipelinev1alpha1.PipelineRunSpec `json:"v1alpha1,omitempty"`
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
36 changes: 34 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.

30 changes: 23 additions & 7 deletions prow/cmd/pipeline/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (c *controller) hasSynced() bool {
c.pipelinesDone = map[string]bool{}
}
for n, cfg := range c.pipelines {
if !cfg.informer.Informer().HasSynced() {
if !cfg.informers.v1alpha1.Informer().HasSynced() {
if c.wait != n {
c.wait = n
logrus.Infof("Waiting on %s pipelines...", n)
Expand Down Expand Up @@ -179,7 +179,7 @@ func newController(opts controllerOptions) (*controller, error) {
for ctx, cfg := range opts.pipelineConfigs {
// Reconcile whenever a pipelinerun changes.
ctx := ctx // otherwise it will change
cfg.informer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
cfg.informers.v1alpha1.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
c.enqueueKey(ctx, obj)
},
Expand Down Expand Up @@ -304,7 +304,7 @@ func (c *controller) getPipelineRun(context, namespace, name string) (*pipelinev
if err != nil {
return nil, err
}
return p.informer.Lister().PipelineRuns(namespace).Get(name)
return p.informers.v1alpha1.Lister().PipelineRuns(namespace).Get(name)
}

func (c *controller) deletePipelineRun(pContext, namespace, name string) error {
Expand Down Expand Up @@ -393,6 +393,8 @@ func reconcile(c reconciler, key string) error {
}

var newPipelineRun bool
// TODO(eddycharly)
spec, _ := getPipelineRunSpec(*pj)
switch {
case !wantPipelineRun:
if !havePipelineRun {
Expand All @@ -415,7 +417,7 @@ func reconcile(c reconciler, key string) error {
case finalState(pj.Status.State):
logrus.Infof("Observed finished: %s", key)
return nil
case wantPipelineRun && pj.Spec.PipelineRunSpec == nil:
case wantPipelineRun && spec == nil:
return fmt.Errorf("nil PipelineRunSpec in ProwJob/%s", key)
case wantPipelineRun && !havePipelineRun:
id, url, err := c.pipelineID(*newpj)
Expand Down Expand Up @@ -588,24 +590,38 @@ func makePipelineGitResource(name string, refs prowjobv1.Refs, pj prowjobv1.Prow
return &pr
}

func getPipelineRunSpec(pj prowjobv1.ProwJob) (*pipelinev1alpha1.PipelineRunSpec, error) {
if pj.Spec.TektonPipelineRunSpec != nil {
if pj.Spec.PipelineRunSpecXXX != nil {
return nil, errors.New("both TektonPipelineRunSpec and PipelineRunSpec are defined")
}
return pj.Spec.TektonPipelineRunSpec.V1Alpha1, nil
}
return pj.Spec.PipelineRunSpecXXX, nil
}

// 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) {
// First validate.
if pj.Spec.PipelineRunSpec == nil {
spec, err := getPipelineRunSpec(pj)
if err != nil {
return nil, err
}
if spec == nil {
return nil, errors.New("no PipelineSpec defined")
}
buildID := pj.Status.BuildID
if buildID == "" {
return nil, errors.New("empty BuildID in status")
}
if err := config.ValidatePipelineRunSpec(pj.Spec.Type, pj.Spec.ExtraRefs, pj.Spec.PipelineRunSpec); err != nil {
if err := config.ValidatePipelineRunSpec(pj.Spec.Type, pj.Spec.ExtraRefs, spec); err != nil {
return nil, fmt.Errorf("invalid pipeline_run_spec: %w", err)
}

p := pipelinev1alpha1.PipelineRun{
ObjectMeta: pipelineMeta(pj.Name, pj),
Spec: *pj.Spec.PipelineRunSpec.DeepCopy(),
Spec: *spec.DeepCopy(),
}

// Add parameters instead of env vars.
Expand Down
Loading

0 comments on commit 79c5a0a

Please sign in to comment.