Skip to content

Commit

Permalink
Don't require pointer to binding
Browse files Browse the repository at this point in the history
Seems like bumping the golangci version
(tektoncd/plumbing#430) revealed some new
linting issues.

Pointers to items being ranged over are reused, so if this pointer is
stored anywhere and used later, it can lead to bugs.

I didn't see any reason why this needed to be a pointer so passing
around the value instead.
  • Loading branch information
bobcatfish committed Jun 18, 2020
1 parent 648cff3 commit 67f5476
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ type GetTaskRun func(name string) (*v1beta1.TaskRun, error)
func GetResourcesFromBindings(pr *v1beta1.PipelineRun, getResource resources.GetResource) (map[string]*resourcev1alpha1.PipelineResource, error) {
rs := map[string]*resourcev1alpha1.PipelineResource{}
for _, resource := range pr.Spec.Resources {
r, err := resources.GetResourceFromBinding(&resource, getResource)
r, err := resources.GetResourceFromBinding(resource, getResource)
if err != nil {
return rs, fmt.Errorf("error following resource reference for %s: %w", resource.Name, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/taskrun/resources/image_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func AddOutputImageDigestExporter(
return fmt.Errorf("failed to get bound resource: %w while adding output image digest exporter", err)
}

resource, err := GetResourceFromBinding(&boundResource.PipelineResourceBinding, gr)
resource, err := GetResourceFromBinding(boundResource.PipelineResourceBinding, gr)
if err != nil {
return fmt.Errorf("failed to get output pipeline Resource for taskRun %q resource %v; error: %w while adding output image digest exporter", tr.Name, boundResource, err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/reconciler/taskrun/resources/taskresourceresolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func ResolveTaskResources(ts *v1beta1.TaskSpec, taskName string, kind v1beta1.Ta
}

for _, r := range inputs {
rr, err := GetResourceFromBinding(&r.PipelineResourceBinding, gr)
rr, err := GetResourceFromBinding(r.PipelineResourceBinding, gr)
if err != nil {
return nil, fmt.Errorf("couldn't retrieve referenced input PipelineResource: %w", err)
}
Expand All @@ -64,7 +64,7 @@ func ResolveTaskResources(ts *v1beta1.TaskSpec, taskName string, kind v1beta1.Ta
}

for _, r := range outputs {
rr, err := GetResourceFromBinding(&r.PipelineResourceBinding, gr)
rr, err := GetResourceFromBinding(r.PipelineResourceBinding, gr)

if err != nil {
return nil, fmt.Errorf("couldn't retrieve referenced output PipelineResource: %w", err)
Expand All @@ -77,7 +77,7 @@ func ResolveTaskResources(ts *v1beta1.TaskSpec, taskName string, kind v1beta1.Ta

// GetResourceFromBinding will return an instance of a PipelineResource to use for r, either by getting it with getter or by
// instantiating it from the embedded spec.
func GetResourceFromBinding(r *v1beta1.PipelineResourceBinding, getter GetResource) (*resourcev1alpha1.PipelineResource, error) {
func GetResourceFromBinding(r v1beta1.PipelineResourceBinding, getter GetResource) (*resourcev1alpha1.PipelineResource, error) {
if (r.ResourceRef != nil && r.ResourceRef.Name != "") && r.ResourceSpec != nil {
return nil, errors.New("Both ResourseRef and ResourceSpec are defined. Expected only one")
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/reconciler/taskrun/resources/taskresourceresolution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func TestGetResourceFromBinding_Ref(t *testing.T) {
Name: "git-repo",
},
}
binding := &v1beta1.PipelineResourceBinding{
binding := v1beta1.PipelineResourceBinding{
ResourceRef: &v1beta1.PipelineResourceRef{
Name: "foo-resource",
},
Expand All @@ -292,7 +292,7 @@ func TestGetResourceFromBinding_Ref(t *testing.T) {
}

func TestGetResourceFromBinding_Spec(t *testing.T) {
binding := &v1beta1.PipelineResourceBinding{
binding := v1beta1.PipelineResourceBinding{
ResourceSpec: &resourcev1alpha1.PipelineResourceSpec{
Type: resourcev1alpha1.PipelineResourceTypeGit,
Params: []resourcev1alpha1.ResourceParam{{
Expand All @@ -318,7 +318,7 @@ func TestGetResourceFromBinding_Spec(t *testing.T) {
}

func TestGetResourceFromBinding_NoNameOrSpec(t *testing.T) {
binding := &v1beta1.PipelineResourceBinding{}
binding := v1beta1.PipelineResourceBinding{}
gr := func(n string) (*resourcev1alpha1.PipelineResource, error) {
return nil, nil
}
Expand All @@ -330,7 +330,7 @@ func TestGetResourceFromBinding_NoNameOrSpec(t *testing.T) {
}

func TestGetResourceFromBinding_NameAndSpec(t *testing.T) {
binding := &v1beta1.PipelineResourceBinding{
binding := v1beta1.PipelineResourceBinding{
ResourceSpec: &resourcev1alpha1.PipelineResourceSpec{
Type: resourcev1alpha1.PipelineResourceTypeGit,
Params: []resourcev1alpha1.ResourceParam{{
Expand All @@ -353,7 +353,7 @@ func TestGetResourceFromBinding_NameAndSpec(t *testing.T) {
}

func TestGetResourceFromBinding_ErrorGettingResource(t *testing.T) {
binding := &v1beta1.PipelineResourceBinding{
binding := v1beta1.PipelineResourceBinding{
ResourceRef: &v1beta1.PipelineResourceRef{
Name: "foo-resource",
},
Expand Down

0 comments on commit 67f5476

Please sign in to comment.