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

[WIP] Adds support for v1 versions of Tekton #47

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/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)
Comment on lines +172 to +174
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove this?

}
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
// '
// `
Comment on lines +62 to +74
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same


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)
// }
Comment on lines +144 to +157
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same or let's add t.Skip() if we need to keep it

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's rename the variable from beta1 to maybe builder

_ = 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add tests for both v1 and v1beta1 to ensure things are working for both API version ?

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