Skip to content

Commit

Permalink
Adds support for v1 versions of Tekton
Browse files Browse the repository at this point in the history
Signed-off-by: PuneetPunamiya <[email protected]>
  • Loading branch information
PuneetPunamiya committed Jun 10, 2024
1 parent 93a2f38 commit 76fe2f9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 38 deletions.
14 changes: 7 additions & 7 deletions pkg/linter/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"github.com/tektoncd/catlin/pkg/parser"
"github.com/tektoncd/catlin/pkg/validator"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
)

type taskLinter struct {
Expand Down Expand Up @@ -88,7 +88,7 @@ func NewScriptLinter(r *parser.Resource) *taskLinter {
}

// nolint: staticcheck
func (t *taskLinter) validateScript(taskName string, s v1beta1.Step, configs []config) validator.Result {
func (t *taskLinter) validateScript(taskName string, s v1.Step, configs []config) validator.Result {
result := validator.Result{}

// use /bin/sh by default if no shbang
Expand Down Expand Up @@ -148,7 +148,7 @@ func (t *taskLinter) validateScript(taskName string, s v1beta1.Step, configs []c
}

// nolint: staticcheck
func (t *taskLinter) collectOverSteps(steps []v1beta1.Step, name string, result *validator.Result) {
func (t *taskLinter) collectOverSteps(steps []v1.Step, name string, result *validator.Result) {
for _, step := range steps {
if step.Script != "" {
result.Append(t.validateScript(name, step, t.configs))
Expand All @@ -167,11 +167,11 @@ func (t *taskLinter) Validate() validator.Result {

switch strings.ToLower(t.res.Kind) {
case "task":
task := res.(*v1beta1.Task)
t.collectOverSteps(task.Spec.Steps, task.ObjectMeta.Name, &result)
case "clustertask":
task := res.(*v1beta1.ClusterTask)
task := res.(*v1.Task)
t.collectOverSteps(task.Spec.Steps, task.ObjectMeta.Name, &result)
// case "clustertask":
// task := res.(*v1beta1.ClusterTask)
// t.collectOverSteps(task.Spec.Steps, task.ObjectMeta.Name, &result)
}
return result
}
50 changes: 25 additions & 25 deletions pkg/linter/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ spec:
echo "hello world"
`

const clusterTaskTest = `
apiVersion: tekton.dev/v1beta1
kind: ClusterTask
metadata:
name: hello-moto
spec:
steps:
- name: nogood
image: image1
script: |
#!/usr/bin/env sh
'
`
// const clusterTaskTest = `
// apiVersion: tekton.dev/v1beta1
// kind: ClusterTask
// metadata:
// name: hello-moto
// spec:
// steps:
// - name: nogood
// image: image1
// script: |
// #!/usr/bin/env sh
// '
// `

const pipelineWithTaskRef = `
apiVersion: tekton.dev/v1beta1
Expand Down Expand Up @@ -141,17 +141,17 @@ func Test_Pipeline_skip(t *testing.T) {
assert.Assert(t, is.Nil(result.Lints))
}

func Test_ClusterTaskParse(t *testing.T) {
r := strings.NewReader(clusterTaskTest)
parser := parser.ForReader(r)
// func Test_ClusterTaskParse(t *testing.T) {
// r := strings.NewReader(clusterTaskTest)
// parser := parser.ForReader(r)

res, err := parser.Parse()
assert.NilError(t, err)
// res, err := parser.Parse()
// assert.NilError(t, err)

tl := &taskLinter{
res: res,
configs: configSh,
}
result := tl.Validate()
assert.Equal(t, 1, result.Errors)
}
// tl := &taskLinter{
// res: res,
// configs: configSh,
// }
// result := tl.Validate()
// assert.Equal(t, 1, result.Errors)
// }
7 changes: 4 additions & 3 deletions pkg/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ import (
"knative.dev/pkg/apis"

"github.com/tektoncd/catlin/pkg/consts"
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
)

func registerSchema() {
beta1 := runtime.NewSchemeBuilder(v1beta1.AddToScheme)
beta1 := runtime.NewSchemeBuilder(v1beta1.AddToScheme, v1.AddToScheme)
_ = beta1.AddToScheme(scheme.Scheme)
}

Expand Down Expand Up @@ -154,7 +155,7 @@ type tektonResource interface {
func typeForKind(kind string) (tektonResource, error) {
switch kind {
case "Task":
return &v1beta1.Task{}, nil
return &v1.Task{}, nil
case "ClusterTask":
return &v1beta1.ClusterTask{}, nil
case "Pipeline":
Expand All @@ -166,5 +167,5 @@ func typeForKind(kind string) (tektonResource, error) {

func isTektonKind(gvk *schema.GroupVersionKind) bool {
id := gvk.GroupVersion().Identifier()
return id == v1beta1.SchemeGroupVersion.Identifier()
return id == v1beta1.SchemeGroupVersion.Identifier() || id == v1.SchemeGroupVersion.Identifier()
}
6 changes: 3 additions & 3 deletions pkg/validator/task_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"strings"

"github.com/google/go-containerregistry/pkg/name"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"

"github.com/tektoncd/catlin/pkg/parser"
)
Expand Down Expand Up @@ -50,14 +50,14 @@ func (t *taskValidator) Validate() Result {
return result
}

task := res.(*v1beta1.Task)
task := res.(*v1.Task)
for _, step := range task.Spec.Steps {
result.Append(t.validateStep(step))
}
return result
}

func (t *taskValidator) validateStep(s v1beta1.Step) Result {
func (t *taskValidator) validateStep(s v1.Step) Result {
result := Result{}
step := s.Name
img := s.Image
Expand Down

0 comments on commit 76fe2f9

Please sign in to comment.