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

Hygiene: enable goconst, dogsled linters. #6262

Merged
merged 1 commit into from
Mar 3, 2023
Merged
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
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ linters:
- bodyclose
- decorder
- depguard
- dogsled
- dupword
- errcheck
- goconst
- gocritic
- gofmt
- goimports
Expand Down Expand Up @@ -61,6 +63,8 @@ issues:
exclude-rules:
- path: _test\.go
linters:
- goconst
- dogsled
- errcheck
- gosec
- path: test/pipelinerun_test\.go
Expand Down
7 changes: 3 additions & 4 deletions pkg/reconciler/pipelinerun/cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"strings"
"time"

"github.com/tektoncd/pipeline/pkg/apis/pipeline"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
clientset "github.com/tektoncd/pipeline/pkg/client/clientset/versioned"
Expand Down Expand Up @@ -201,11 +200,11 @@ func getChildObjectsFromPRStatusForTaskNames(ctx context.Context, prs v1beta1.Pi
for _, cr := range prs.ChildReferences {
if taskNames.Len() == 0 || taskNames.Has(cr.PipelineTaskName) {
switch cr.Kind {
case pipeline.TaskRunControllerName:
case taskRun:
trNames = append(trNames, cr.Name)
case pipeline.RunControllerName:
case run:
runNames = append(runNames, cr.Name)
case pipeline.CustomRunControllerName:
case customRun:
customRunNames = append(customRunNames, cr.Name)
default:
unknownChildKinds[cr.Name] = cr.Kind
Expand Down
47 changes: 23 additions & 24 deletions pkg/reconciler/pipelinerun/cancel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/tektoncd/pipeline/pkg/apis/config"
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
_ "github.com/tektoncd/pipeline/pkg/pipelinerunmetrics/fake" // Make sure the pipelinerunmetrics are setup
Expand Down Expand Up @@ -62,7 +61,7 @@ func TestCancelPipelineRun(t *testing.T) {
},
Status: v1beta1.PipelineRunStatus{PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{
ChildReferences: []v1beta1.ChildStatusReference{{
TypeMeta: runtime.TypeMeta{Kind: "TaskRun"},
TypeMeta: runtime.TypeMeta{Kind: taskRun},
Name: "t1",
PipelineTaskName: "task-1",
}},
Expand All @@ -80,11 +79,11 @@ func TestCancelPipelineRun(t *testing.T) {
},
Status: v1beta1.PipelineRunStatus{PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{
ChildReferences: []v1beta1.ChildStatusReference{{
TypeMeta: runtime.TypeMeta{Kind: "TaskRun"},
TypeMeta: runtime.TypeMeta{Kind: taskRun},
Name: "t1",
PipelineTaskName: "task-1",
}, {
TypeMeta: runtime.TypeMeta{Kind: "TaskRun"},
TypeMeta: runtime.TypeMeta{Kind: taskRun},
Name: "t2",
PipelineTaskName: "task-2",
}},
Expand All @@ -102,11 +101,11 @@ func TestCancelPipelineRun(t *testing.T) {
},
Status: v1beta1.PipelineRunStatus{PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{
ChildReferences: []v1beta1.ChildStatusReference{{
TypeMeta: runtime.TypeMeta{Kind: "TaskRun"},
TypeMeta: runtime.TypeMeta{Kind: taskRun},
Name: "t1",
PipelineTaskName: "task-1",
}, {
TypeMeta: runtime.TypeMeta{Kind: "TaskRun"},
TypeMeta: runtime.TypeMeta{Kind: taskRun},
Name: "t2",
PipelineTaskName: "task-2",
}},
Expand All @@ -125,11 +124,11 @@ func TestCancelPipelineRun(t *testing.T) {
},
Status: v1beta1.PipelineRunStatus{PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{
ChildReferences: []v1beta1.ChildStatusReference{{
TypeMeta: runtime.TypeMeta{Kind: "CustomRun"},
TypeMeta: runtime.TypeMeta{Kind: customRun},
Name: "t1",
PipelineTaskName: "task-1",
}, {
TypeMeta: runtime.TypeMeta{Kind: "CustomRun"},
TypeMeta: runtime.TypeMeta{Kind: customRun},
Name: "t2",
PipelineTaskName: "task-2",
}},
Expand All @@ -148,11 +147,11 @@ func TestCancelPipelineRun(t *testing.T) {
},
Status: v1beta1.PipelineRunStatus{PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{
ChildReferences: []v1beta1.ChildStatusReference{{
TypeMeta: runtime.TypeMeta{Kind: "CustomRun"},
TypeMeta: runtime.TypeMeta{Kind: customRun},
Name: "t1",
PipelineTaskName: "task-1",
}, {
TypeMeta: runtime.TypeMeta{Kind: "CustomRun"},
TypeMeta: runtime.TypeMeta{Kind: customRun},
Name: "t2",
PipelineTaskName: "task-2",
}},
Expand All @@ -171,22 +170,22 @@ func TestCancelPipelineRun(t *testing.T) {
Status: v1beta1.PipelineRunStatus{PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{
ChildReferences: []v1beta1.ChildStatusReference{
{
TypeMeta: runtime.TypeMeta{Kind: "TaskRun"},
TypeMeta: runtime.TypeMeta{Kind: taskRun},
Name: "t1",
PipelineTaskName: "task-1",
},
{
TypeMeta: runtime.TypeMeta{Kind: "TaskRun"},
TypeMeta: runtime.TypeMeta{Kind: taskRun},
Name: "t2",
PipelineTaskName: "task-2",
},
{
TypeMeta: runtime.TypeMeta{Kind: pipeline.RunControllerName},
TypeMeta: runtime.TypeMeta{Kind: run},
Name: "r1",
PipelineTaskName: "run-1",
},
{
TypeMeta: runtime.TypeMeta{Kind: pipeline.RunControllerName},
TypeMeta: runtime.TypeMeta{Kind: run},
Name: "r2",
PipelineTaskName: "run-2",
},
Expand All @@ -211,22 +210,22 @@ func TestCancelPipelineRun(t *testing.T) {
Status: v1beta1.PipelineRunStatus{PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{
ChildReferences: []v1beta1.ChildStatusReference{
{
TypeMeta: runtime.TypeMeta{Kind: "TaskRun"},
TypeMeta: runtime.TypeMeta{Kind: taskRun},
Name: "t1",
PipelineTaskName: "task-1",
},
{
TypeMeta: runtime.TypeMeta{Kind: "TaskRun"},
TypeMeta: runtime.TypeMeta{Kind: taskRun},
Name: "t2",
PipelineTaskName: "task-2",
},
{
TypeMeta: runtime.TypeMeta{Kind: pipeline.RunControllerName},
TypeMeta: runtime.TypeMeta{Kind: run},
Name: "r1",
PipelineTaskName: "run-1",
},
{
TypeMeta: runtime.TypeMeta{Kind: pipeline.RunControllerName},
TypeMeta: runtime.TypeMeta{Kind: run},
Name: "r2",
PipelineTaskName: "run-2",
},
Expand All @@ -249,22 +248,22 @@ func TestCancelPipelineRun(t *testing.T) {
Status: v1beta1.PipelineRunStatus{PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{
ChildReferences: []v1beta1.ChildStatusReference{
{
TypeMeta: runtime.TypeMeta{Kind: "TaskRun"},
TypeMeta: runtime.TypeMeta{Kind: taskRun},
Name: "t1",
PipelineTaskName: "task-1",
},
{
TypeMeta: runtime.TypeMeta{Kind: "TaskRun"},
TypeMeta: runtime.TypeMeta{Kind: taskRun},
Name: "t2",
PipelineTaskName: "task-2",
},
{
TypeMeta: runtime.TypeMeta{Kind: pipeline.CustomRunControllerName},
TypeMeta: runtime.TypeMeta{Kind: customRun},
Name: "cr1",
PipelineTaskName: "customrun-1",
},
{
TypeMeta: runtime.TypeMeta{Kind: pipeline.CustomRunControllerName},
TypeMeta: runtime.TypeMeta{Kind: customRun},
Name: "cr2",
PipelineTaskName: "customrun-2",
},
Expand Down Expand Up @@ -393,7 +392,7 @@ func TestGetChildObjectsFromPRStatusForTaskNames(t *testing.T) {
ChildReferences: []v1beta1.ChildStatusReference{{
TypeMeta: runtime.TypeMeta{
APIVersion: v1alpha1.SchemeGroupVersion.String(),
Kind: pipeline.RunControllerName,
Kind: run,
},
Name: "r1",
PipelineTaskName: "run-1",
Expand All @@ -409,7 +408,7 @@ func TestGetChildObjectsFromPRStatusForTaskNames(t *testing.T) {
ChildReferences: []v1beta1.ChildStatusReference{{
TypeMeta: runtime.TypeMeta{
APIVersion: v1beta1.SchemeGroupVersion.String(),
Kind: pipeline.CustomRunControllerName,
Kind: customRun,
},
Name: "r1",
PipelineTaskName: "run-1",
Expand Down
24 changes: 17 additions & 7 deletions pkg/reconciler/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ const (
ReasonResourceVerificationFailed = "ResourceVerificationFailed"
)

// constants used as kind descriptors for various types of runs; these constants
// match their corresponding controller names. Given that it's odd to use a
// "ControllerName" const in describing the type of run, we import these
// constants (for consistency) but rename them (for ergonomic semantics).
const (
Copy link
Member

Choose a reason for hiding this comment

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

👍

taskRun = pipeline.TaskRunControllerName
customRun = pipeline.CustomRunControllerName
run = pipeline.RunControllerName
)

// Reconciler implements controller.Reconciler for Configuration resources.
type Reconciler struct {
KubeClientSet kubernetes.Interface
Expand Down Expand Up @@ -1333,7 +1343,7 @@ func validateChildObjectsInPipelineRunStatus(ctx context.Context, prs v1beta1.Pi

for _, cr := range prs.ChildReferences {
switch cr.Kind {
case "TaskRun", "Run", "CustomRun":
case taskRun, run, customRun:
continue
default:
err = multierror.Append(err, fmt.Errorf("child with name %s has unknown kind %s", cr.Name, cr.Kind))
Expand Down Expand Up @@ -1379,16 +1389,16 @@ func filterRunsForPipelineRunStatus(logger *zap.SugaredLogger, pr *v1beta1.Pipel
names = append(names, runObj.GetObjectMeta().GetName())
taskLabels = append(taskLabels, runObj.GetObjectMeta().GetLabels()[pipeline.PipelineTaskLabelKey])

switch run := runObj.(type) {
switch r := runObj.(type) {
case *v1beta1.CustomRun:
statuses = append(statuses, &run.Status)
statuses = append(statuses, &r.Status)
// We can't just get the gvk from the run's TypeMeta because that isn't populated for resources created through the fake client.
gvks = append(gvks, v1beta1.SchemeGroupVersion.WithKind(pipeline.CustomRunControllerName))
gvks = append(gvks, v1beta1.SchemeGroupVersion.WithKind(customRun))
case *v1alpha1.Run:
crStatus := runv1beta1.FromRunStatus(run.Status)
crStatus := runv1beta1.FromRunStatus(r.Status)
statuses = append(statuses, &crStatus)
// We can't just get the gvk from the run's TypeMeta because that isn't populated for resources created through the fake client.
gvks = append(gvks, v1alpha1.SchemeGroupVersion.WithKind(pipeline.RunControllerName))
gvks = append(gvks, v1alpha1.SchemeGroupVersion.WithKind(run))
}
}

Expand Down Expand Up @@ -1425,7 +1435,7 @@ func updatePipelineRunStatusFromChildRefs(logger *zap.SugaredLogger, pr *v1beta1
childRefByName[tr.Name] = &v1beta1.ChildStatusReference{
TypeMeta: runtime.TypeMeta{
APIVersion: v1beta1.SchemeGroupVersion.String(),
Kind: pipeline.TaskRunControllerName,
Kind: taskRun,
},
Name: tr.Name,
PipelineTaskName: pipelineTaskName,
Expand Down
Loading