Skip to content

Commit

Permalink
Fix compilation issues
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Demeester <vdemeest@redhat.com>
  • Loading branch information
vdemeester committed Oct 9, 2023
1 parent 86fa206 commit 54c7e7b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 79 deletions.
50 changes: 25 additions & 25 deletions pkg/tekton/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ import (

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
corev1 "k8s.io/api/core/v1"
k8scheme "k8s.io/client-go/kubernetes/scheme"
)

type objects struct {
tasks []*v1beta1.Task
taskruns []*v1beta1.TaskRun
pipelines []*v1beta1.Pipeline
pipelineruns []*v1beta1.PipelineRun
tasks []*v1.Task
taskruns []*v1.TaskRun
pipelines []*v1.Pipeline
pipelineruns []*v1.PipelineRun
secrets []*corev1.Secret
configs []*corev1.ConfigMap
}

type TaskRun struct {
main *v1beta1.TaskRun
tasks map[string]*v1beta1.Task
main *v1.TaskRun
tasks map[string]*v1.Task
secrets map[string]*corev1.Secret
configs map[string]*corev1.ConfigMap
}

type PipelineRun struct {
main *v1beta1.PipelineRun
tasks map[string]*v1beta1.Task
pipelines map[string]*v1beta1.Pipeline
main *v1.PipelineRun
tasks map[string]*v1.Task
pipelines map[string]*v1.Pipeline
secrets map[string]*corev1.Secret
configs map[string]*corev1.ConfigMap
}
Expand All @@ -41,7 +41,7 @@ var (

func readResources(main string, additionals []string) (interface{}, error) {
s := k8scheme.Scheme
if err := v1beta1.AddToScheme(s); err != nil {
if err := v1.AddToScheme(s); err != nil {
return nil, err
}
objs, err := parseTektonYAMLs(main)
Expand All @@ -54,16 +54,16 @@ func readResources(main string, additionals []string) (interface{}, error) {
main: objs.taskruns[0],
secrets: secretsToMap(objs.secrets),
configs: configsToMap(objs.configs),
tasks: map[string]*v1beta1.Task{},
tasks: map[string]*v1.Task{},
}
return populateTaskRun(r, additionals)
case len(objs.taskruns) == 0 && len(objs.pipelineruns) == 1:
r := PipelineRun{
main: objs.pipelineruns[0],
secrets: secretsToMap(objs.secrets),
configs: configsToMap(objs.configs),
tasks: map[string]*v1beta1.Task{},
pipelines: map[string]*v1beta1.Pipeline{},
tasks: map[string]*v1.Task{},
pipelines: map[string]*v1.Pipeline{},
}
return populatePipelineRun(r, additionals)
case len(objs.taskruns) == 0 && len(objs.pipelineruns) == 0:
Expand All @@ -85,7 +85,7 @@ func populateTaskRun(r TaskRun, additionals []string) (TaskRun, error) {
return r, errors.Wrapf(err, "failed to unmarshal %v", doc)
}
switch o := obj.(type) {
case *v1beta1.Task:
case *v1.Task:
r.tasks[o.Name] = o
default:
logrus.Infof("Skipping document not looking like a tekton resource we can Resolve.")
Expand All @@ -103,9 +103,9 @@ func populatePipelineRun(r PipelineRun, additionals []string) (PipelineRun, erro
return r, errors.Wrapf(err, "failed to unmarshal %v", doc)
}
switch o := obj.(type) {
case *v1beta1.Task:
case *v1.Task:
r.tasks[o.Name] = o
case *v1beta1.Pipeline:
case *v1.Pipeline:
r.pipelines[o.Name] = o
default:
logrus.Infof("Skipping document not looking like a tekton resource we can Resolve.")
Expand All @@ -117,10 +117,10 @@ func populatePipelineRun(r PipelineRun, additionals []string) (PipelineRun, erro

func parseTektonYAMLs(s string) (*objects, error) {
r := &objects{
tasks: []*v1beta1.Task{},
taskruns: []*v1beta1.TaskRun{},
pipelines: []*v1beta1.Pipeline{},
pipelineruns: []*v1beta1.PipelineRun{},
tasks: []*v1.Task{},
taskruns: []*v1.TaskRun{},
pipelines: []*v1.Pipeline{},
pipelineruns: []*v1.PipelineRun{},
secrets: []*corev1.Secret{},
configs: []*corev1.ConfigMap{},
}
Expand All @@ -131,13 +131,13 @@ func parseTektonYAMLs(s string) (*objects, error) {
return r, errors.Wrapf(err, "failed to unmarshal %v", doc)
}
switch o := obj.(type) {
case *v1beta1.Task:
case *v1.Task:
r.tasks = append(r.tasks, o)
case *v1beta1.TaskRun:
case *v1.TaskRun:
r.taskruns = append(r.taskruns, o)
case *v1beta1.Pipeline:
case *v1.Pipeline:
r.pipelines = append(r.pipelines, o)
case *v1beta1.PipelineRun:
case *v1.PipelineRun:
r.pipelineruns = append(r.pipelineruns, o)
case *corev1.Secret:
r.secrets = append(r.secrets, o)
Expand Down
68 changes: 32 additions & 36 deletions pkg/tekton/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/moby/buildkit/client/llb"
"github.com/moby/buildkit/frontend/gateway/client"
"github.com/pkg/errors"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/resources"
"github.com/vdemeester/buildkit-tekton/pkg/tekton/files"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -24,18 +24,19 @@ func PipelineRunToLLB(ctx context.Context, c client.Client, r PipelineRun) (llb.
return llb.State{}, err
}

var ps *v1beta1.PipelineSpec
var ps *v1.PipelineSpec
var name string
if pr.Spec.PipelineSpec != nil {
ps = pr.Spec.PipelineSpec
name = "embedded"
} else if pr.Spec.PipelineRef != nil && pr.Spec.PipelineRef.Bundle != "" {
resolvedPipeline, err := resolvePipelineInBundle(ctx, c, *pr.Spec.PipelineRef)
if err != nil {
return llb.State{}, err
}
ps = &resolvedPipeline.Spec
name = pr.Spec.PipelineRef.Name
// FIXME: we need to support this
// } else if pr.Spec.PipelineRef != nil && pr.Spec.PipelineRef.Bundle != "" {
// resolvedPipeline, err := resolvePipelineInBundle(ctx, c, *pr.Spec.PipelineRef)
// if err != nil {
// return llb.State{}, err
// }
// ps = &resolvedPipeline.Spec
// name = pr.Spec.PipelineRef.Name
} else if pr.Spec.PipelineRef != nil && pr.Spec.PipelineRef.Name != "" {
p, ok := r.pipelines[pr.Spec.PipelineRef.Name]
if !ok {
Expand Down Expand Up @@ -96,31 +97,32 @@ func PipelineRunToLLB(ctx context.Context, c client.Client, r PipelineRun) (llb.
}
tasks := map[string][]llb.State{}
for _, t := range spec.Tasks {
var ts v1beta1.TaskSpec
var ts v1.TaskSpec
var name string
if t.TaskRef != nil {
name = t.TaskRef.Name
if t.TaskRef.Bundle != "" {
resolvedTask, err := resolveTaskInBundle(ctx, c, *t.TaskRef)
if err != nil {
return llb.State{}, err
}
ts = resolvedTask.Spec
} else {
task, ok := r.tasks[t.TaskRef.Name]
if !ok {
return llb.State{}, errors.Errorf("Taskref %s not found in context", t.TaskRef.Name)
}
task.SetDefaults(ctx)
ts = task.Spec
// FIXME: we need to support this
// if t.TaskRef.Bundle != "" {
// resolvedTask, err := resolveTaskInBundle(ctx, c, *t.TaskRef)
// if err != nil {
// return llb.State{}, err
// }
// ts = resolvedTask.Spec
// } else {
task, ok := r.tasks[t.TaskRef.Name]
if !ok {
return llb.State{}, errors.Errorf("Taskref %s not found in context", t.TaskRef.Name)
}
task.SetDefaults(ctx)
ts = task.Spec
// }
} else if t.TaskSpec != nil {
name = "embedded"
ts = t.TaskSpec.TaskSpec
}

ts, err = applyTaskRunSubstitution(ctx, &v1beta1.TaskRun{
Spec: v1beta1.TaskRunSpec{
ts, err = applyTaskRunSubstitution(ctx, &v1.TaskRun{
Spec: v1.TaskRunSpec{
Params: t.Params,
TaskSpec: &ts,
},
Expand Down Expand Up @@ -166,7 +168,7 @@ func PipelineRunToLLB(ctx context.Context, c client.Client, r PipelineRun) (llb.
return ft.File(fa, llb.WithCustomName("[tekton] buildking image from result (fake)"), llb.IgnoreCache), nil
}

func applyPipelineRunSubstitution(ctx context.Context, pr *v1beta1.PipelineRun, ps *v1beta1.PipelineSpec, pipelineName string) (v1beta1.PipelineSpec, error) {
func applyPipelineRunSubstitution(ctx context.Context, pr *v1.PipelineRun, ps *v1.PipelineSpec, pipelineName string) (v1.PipelineSpec, error) {
ps = resources.ApplyParameters(ctx, ps, pr)
ps = resources.ApplyContexts(ps, pipelineName, pr)
ps = resources.ApplyWorkspaces(ps, pr)
Expand All @@ -178,25 +180,22 @@ func applyPipelineRunSubstitution(ctx context.Context, pr *v1beta1.PipelineRun,
return *ps, nil
}

func validatePipelineRun(ctx context.Context, pr *v1beta1.PipelineRun) error {
func validatePipelineRun(ctx context.Context, pr *v1.PipelineRun) error {
if pr.Name == "" && pr.GenerateName != "" {
pr.Name = pr.GenerateName + "generated"
}
pr.SetDefaults(ctx)
if err := pr.Validate(ctx); err != nil {
return errors.Wrapf(err, "validation failed for PipelineRun %s", pr.Name)
}
if len(pr.Spec.Resources) > 0 {
return errors.New("PipelineResources are not supported")
}
// SilentlyIgnore ServiceAccountName
// SilentlyIgnore ServiceAccountNames
// SilentlyIgnore Status
if pr.Spec.Timeouts != nil {
return errors.New("Timeouts are not supported")
}
// We might be able to silently ignore
if pr.Spec.PodTemplate != nil {
if pr.Spec.TaskRunTemplate.PodTemplate != nil {
return errors.New("PodTemplate are not supported")
}
if pr.Spec.TaskRunSpecs != nil {
Expand All @@ -208,15 +207,12 @@ func validatePipelineRun(ctx context.Context, pr *v1beta1.PipelineRun) error {
return nil
}

func validatePipeline(ctx context.Context, p v1beta1.PipelineSpec) error {
if len(p.Resources) > 0 {
return errors.New("PipelineResources are not supported")
}
func validatePipeline(ctx context.Context, p v1.PipelineSpec) error {
if len(p.Finally) > 0 {
return errors.New("Finally are not supporte (yet)")
}
for _, pt := range p.Tasks {
if len(pt.WhenExpressions) > 0 {
if len(pt.When) > 0 {
return errors.Errorf("Task %s: WhenExpressions not supported", pt.Name)
}
// Silently ignore Retries
Expand Down
34 changes: 16 additions & 18 deletions pkg/tekton/taskrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/moby/buildkit/client/llb"
"github.com/moby/buildkit/frontend/gateway/client"
"github.com/pkg/errors"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources"
"github.com/vdemeester/buildkit-tekton/pkg/tekton/files"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -39,18 +39,19 @@ func TaskRunToLLB(ctx context.Context, c client.Client, r TaskRun) (llb.State, e
return llb.State{}, err
}

var ts *v1beta1.TaskSpec
var ts *v1.TaskSpec
var name string
if tr.Spec.TaskSpec != nil {
ts = tr.Spec.TaskSpec
name = "embedded"
} else if tr.Spec.TaskRef != nil && tr.Spec.TaskRef.Bundle != "" {
resolvedTask, err := resolveTaskInBundle(ctx, c, *tr.Spec.TaskRef)
if err != nil {
return llb.State{}, err
}
ts = &resolvedTask.Spec
name = tr.Spec.TaskRef.Name
// FIXME: we need to support this
// } else if tr.Spec.TaskRef != nil && tr.Spec.TaskRef.Bundle != "" {
// resolvedTask, err := resolveTaskInBundle(ctx, c, *tr.Spec.TaskRef)
// if err != nil {
// return llb.State{}, err
// }
// ts = &resolvedTask.Spec
// name = tr.Spec.TaskRef.Name
} else if tr.Spec.TaskRef != nil && tr.Spec.TaskRef.Name != "" {
t, ok := r.tasks[tr.Spec.TaskRef.Name]
if !ok {
Expand Down Expand Up @@ -89,8 +90,8 @@ func TaskRunToLLB(ctx context.Context, c client.Client, r TaskRun) (llb.State, e
return stepStates[len(stepStates)-1], nil
}

func applyTaskRunSubstitution(ctx context.Context, tr *v1beta1.TaskRun, ts *v1beta1.TaskSpec, taskName string) (v1beta1.TaskSpec, error) {
var defaults []v1beta1.ParamSpec
func applyTaskRunSubstitution(ctx context.Context, tr *v1.TaskRun, ts *v1.TaskSpec, taskName string) (v1.TaskSpec, error) {
var defaults []v1.ParamSpec
if len(ts.Params) > 0 {
defaults = append(defaults, ts.Params...)
}
Expand Down Expand Up @@ -124,10 +125,10 @@ func applyTaskRunSubstitution(ctx context.Context, tr *v1beta1.TaskRun, ts *v1be
return *ts, nil
}

func taskSpecToPSteps(ctx context.Context, c client.Client, t v1beta1.TaskSpec, name string, workspaces []mountOptionFn) ([]pstep, error) {
func taskSpecToPSteps(ctx context.Context, c client.Client, t v1.TaskSpec, name string, workspaces []mountOptionFn) ([]pstep, error) {
steps := make([]pstep, len(t.Steps))
cacheDirName := name + "/results"
mergedSteps, err := v1beta1.MergeStepsWithStepTemplate(t.StepTemplate, t.Steps)
mergedSteps, err := v1.MergeStepsWithStepTemplate(t.StepTemplate, t.Steps)
if err != nil {
return steps, errors.Wrap(err, "couldn't merge steps with StepTemplate")
}
Expand Down Expand Up @@ -218,7 +219,7 @@ func pstepToState(c client.Client, steps []pstep, resultState llb.State, additio
return stepStates, nil
}

func validateTaskRun(ctx context.Context, tr *v1beta1.TaskRun) error {
func validateTaskRun(ctx context.Context, tr *v1.TaskRun) error {
if tr.Name == "" && tr.GenerateName != "" {
tr.Name = tr.GenerateName + "generated"
}
Expand All @@ -235,10 +236,7 @@ func validateTaskRun(ctx context.Context, tr *v1beta1.TaskRun) error {
return nil
}

func validateTaskSpec(ctx context.Context, t v1beta1.TaskSpec) error {
if t.Resources != nil {
return errors.New("PipelineResources are not supported")
}
func validateTaskSpec(ctx context.Context, t v1.TaskSpec) error {
if len(t.Sidecars) > 0 {
return errors.New("Sidecars are not supported")
}
Expand Down

0 comments on commit 54c7e7b

Please sign in to comment.