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

Conceptual bug: Wrong resource names used #2694

Closed
dlorenc opened this issue May 26, 2020 · 5 comments · Fixed by #2808
Closed

Conceptual bug: Wrong resource names used #2694

dlorenc opened this issue May 26, 2020 · 5 comments · Fixed by #2808
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@dlorenc
Copy link
Contributor

dlorenc commented May 26, 2020

This is a conceptual bug in the way resource names are handled in Tekton today. I'm working on a fix, but wanted to discuss the actual issue here first.

PipelineResources right now can be referred to by two different names:

  1. The PipelineResourceSpec.Params.Name field. This is not a top-level field in PipelineResources, but (almost?) all of the existing PipelineResource types take a parameter called "Name" that is then set on the object itself after unmarshalling.
    This name can be thought of as a way to refer to the external object the PipelineResource refers to.
  2. The TaskRun.Inputs|Outputs.Resources.Name field. This is a field on the ResourceBinding. This can be thought of as an internal "name" the TaskRun will use to refer to the resource.

Right now, we pass the external 'Name' field to the resource containers via the 'TEKTON_RESOURCE_NAME' env var. This is only used in a few locations right now:

  • substitutions
  • results ( to indicate which resource the result corresponds to )

We should be using the 'internal' name field here - the external names are not always set and can change/not be unique. Internal names are unique within a Task/TaskRun.

dlorenc added a commit to dlorenc/build-pipeline that referenced this issue May 26, 2020
This commit changes the names used throughout PipelineResource handling.
PipelineResources have two names when used in a TaskRun:
- The name of the PipelineResource entity
- The name given to the resource inside the Task definition

Task code is currently using the external names everywhere, but should be using
the internal names.

Ref: tektoncd#2694
@afrittoli
Copy link
Member

I'm trying to understand but I'm not sure I understood the problem fully.
So here is my understanding of what the problem is.

The struct that holds all PipelineResource types has a field called "Name". That field is not a PipelineResource parameter. For instance for the git resource, the struct includes name:

type Resource struct {
Name string `json:"name"`
Type resource.PipelineResourceType `json:"type"`
URL string `json:"url"`
// Git revision (branch, tag, commit SHA) to clone, and optionally the refspec to fetch from.
//See https://git-scm.com/docs/gitrevisions#_specifying_revisions for more information.
Revision string `json:"revision"`
Refspec string `json:"refspec"`
Submodules bool `json:"submodules"`
Depth uint `json:"depth"`
SSLVerify bool `json:"sslVerify"`
HTTPProxy string `json:"httpProxy"`
HTTPSProxy string `json:"httpsProxy"`
NOProxy string `json:"noProxy"`
GitImage string `json:"-"`
}

Name is not parsed from parameters:

for _, param := range r.Spec.Params {
switch {
case strings.EqualFold(param.Name, "URL"):
gitResource.URL = param.Value
case strings.EqualFold(param.Name, "Revision"):
gitResource.Revision = param.Value
case strings.EqualFold(param.Name, "Refspec"):
gitResource.Refspec = param.Value
case strings.EqualFold(param.Name, "Submodules"):
gitResource.Submodules = toBool(param.Value, true)
case strings.EqualFold(param.Name, "Depth"):
gitResource.Depth = toUint(param.Value, 1)
case strings.EqualFold(param.Name, "SSLVerify"):
gitResource.SSLVerify = toBool(param.Value, true)
case strings.EqualFold(param.Name, "HTTPProxy"):
gitResource.HTTPProxy = param.Value
case strings.EqualFold(param.Name, "HTTPSProxy"):
gitResource.HTTPSProxy = param.Value
case strings.EqualFold(param.Name, "NOProxy"):
gitResource.NOProxy = param.Value

Name is taken instead from the PipelineResource CRD "Name" field. I think this is what you refer to as the "external" name.

A Task defines its own resource names, and a TaskRun binds the "external" name of a resource to the task resource. The code in the TaskRun controller should use the bound resource name only for fetching the resource spec, and the task resource name otherwise.

The git pipeline resource uses the TEKTON_RESOURCE_NAME to report results.
The image resource a CLI flag instead to report results.

In both cases, a v1beta1.PipelineResourceResult is created, which holds a v1beta1.PipelineResourceRef. The resource ref points to the resource name and kind.
Finally, the PipelineResourceRef is added to the list of results in the TaskRun.Status:

taskRun.Status.ResourcesResult = append(taskRun.Status.ResourcesResult, pipelineResourceResults...)
}

I think your point is that the results in the TaskRun status should refer to the task resource and not to the bound resource, because that is not necessarily unique.

It makes sense to me. I think fixing that would imply changing the v1beta1.PipelineResourceResult to store a task resource name instead of a Ref to a PipelineResource. The pipeline resource would need to have knowledge of the task resource name, so that it could pass it down to the container and ultimately write it in the termination message for the TaskRun controller to pick up.

@afrittoli
Copy link
Member

/kind bug

@tekton-robot tekton-robot added the kind/bug Categorizes issue or PR as related to a bug. label May 27, 2020
dlorenc added a commit to dlorenc/build-pipeline that referenced this issue May 27, 2020
This commit changes the names used throughout PipelineResource handling.
PipelineResources have two names when used in a TaskRun:
- The name of the PipelineResource entity
- The name given to the resource inside the Task definition

Task code is currently using the external names everywhere, but should be using
the internal names.

Ref: tektoncd#2694
@dlorenc
Copy link
Contributor Author

dlorenc commented May 27, 2020

I think your point is that the results in the TaskRun status should refer to the task resource and not to the bound resource, because that is not necessarily unique.

It makes sense to me. I think fixing that would imply changing the v1beta1.PipelineResourceResult to store a task resource name instead of a Ref to a PipelineResource. The pipeline resource would need to have knowledge of the task resource name, so that it could pass it down to the container and ultimately write it in the termination message for the TaskRun controller to pick up.

Yes, that's exactly correct, and a much more succinct way of putting it. I left this as a Ref, but since it's no longer a Ref you're probably right that we should change this to just be a Name.

@dlorenc
Copy link
Contributor Author

dlorenc commented May 27, 2020

I'll also add that it's not only because they are not necessarily unique - the resources referred to by the resourceRefs may not actually exist at all! They could have been defined inline in the TaskRun/PipelineRun. Our handling here gets a little funky...

@dlorenc
Copy link
Contributor Author

dlorenc commented May 27, 2020

I just added a second commit that stores the name in a ResourcesResult.ResourceName field, in addition to the resourceRef.

This is an API addition, although it really should be a break since we should delete the resourceRef (it doesn't make semantic sense).

Any thoughts on how to stage this? My suggestion is to add the new field, then remove the old one the next time we change the API version.

dlorenc added a commit to dlorenc/build-pipeline that referenced this issue May 29, 2020
This commit changes the names used throughout PipelineResource handling.
PipelineResources have two names when used in a TaskRun:
- The name of the PipelineResource entity
- The name given to the resource inside the Task definition

Task code is currently using the external names everywhere, but should be using
the internal names.

Ref: tektoncd#2694
dlorenc added a commit to dlorenc/build-pipeline that referenced this issue Jun 4, 2020
This commit changes the names used throughout PipelineResource handling.
PipelineResources have two names when used in a TaskRun:
- The name of the PipelineResource entity
- The name given to the resource inside the Task definition

Task code is currently using the external names everywhere, but should be using
the internal names.

Ref: tektoncd#2694
dlorenc added a commit to dlorenc/build-pipeline that referenced this issue Jun 4, 2020
This commit changes the names used throughout PipelineResource handling.
PipelineResources have two names when used in a TaskRun:
- The name of the PipelineResource entity (external name)
- The name given to the resource inside the Task definition (internal name)

Task code is currently using the external names everywhere, but should be using
the internal names.

This adds a new field for the internal name to PipelineResourceResult, and deprecates
the existing PipelineResourceResult.ResourceRef field.

Ref: tektoncd#2694
dlorenc added a commit to dlorenc/build-pipeline that referenced this issue Jun 5, 2020
This commit changes the names used throughout PipelineResource handling.
PipelineResources have two names when used in a TaskRun:
- The name of the PipelineResource entity (external name)
- The name given to the resource inside the Task definition (internal name)

Task code is currently using the external names everywhere, but should be using
the internal names.

This adds a new field for the internal name to PipelineResourceResult, and deprecates
the existing PipelineResourceResult.ResourceRef field.

Ref: tektoncd#2694
dlorenc added a commit to dlorenc/build-pipeline that referenced this issue Jun 9, 2020
This commit changes the names used throughout PipelineResource handling.
PipelineResources have two names when used in a TaskRun:
- The name of the PipelineResource entity (external name)
- The name given to the resource inside the Task definition (internal name)

Task code is currently using the external names everywhere, but should be using
the internal names.

This adds a new field for the internal name to PipelineResourceResult, and deprecates
the existing PipelineResourceResult.ResourceRef field.

Ref: tektoncd#2694
dlorenc added a commit to dlorenc/build-pipeline that referenced this issue Jun 10, 2020
This commit changes the names used throughout PipelineResource handling.
PipelineResources have two names when used in a TaskRun:
- The name of the PipelineResource entity (external name)
- The name given to the resource inside the Task definition (internal name)

Task code is currently using the external names everywhere, but should be using
the internal names.

This adds a new field for the internal name to PipelineResourceResult, and deprecates
the existing PipelineResourceResult.ResourceRef field.

Ref: tektoncd#2694
tekton-robot pushed a commit that referenced this issue Jun 11, 2020
This commit changes the names used throughout PipelineResource handling.
PipelineResources have two names when used in a TaskRun:
- The name of the PipelineResource entity (external name)
- The name given to the resource inside the Task definition (internal name)

Task code is currently using the external names everywhere, but should be using
the internal names.

This adds a new field for the internal name to PipelineResourceResult, and deprecates
the existing PipelineResourceResult.ResourceRef field.

Ref: #2694
dlorenc added a commit to dlorenc/build-pipeline that referenced this issue Jun 11, 2020
…release.

This is a cleanup commit that should go in after 0.14.0 is cut. It was introduced
in tektoncd#2697, to fix tektoncd#2694.
tekton-robot pushed a commit that referenced this issue Jul 6, 2020
…release.

This is a cleanup commit that should go in after 0.14.0 is cut. It was introduced
in #2697, to fix #2694.
abayer added a commit to abayer/tektoncd-pipeline that referenced this issue Jun 15, 2022
See tektoncd#2694.

The `TaskRun.Status.ResourceResults.ResourceRef` field was only ever used for its own `Name` field, and as part of tektoncd#2694, a new field, `TaskRun.Status.ResourceResults.ResourceName` was added to replace `...ResourceRef.Name`. This change finishes the work by removing the deprecated `TaskRun.Status.ResourceResults.ResourceRef`.

This has been scheduled for removal since April 2021.

Signed-off-by: Andrew Bayer <[email protected]>
abayer added a commit to abayer/tektoncd-pipeline that referenced this issue Jun 15, 2022
See tektoncd#2694.

The `TaskRun.Status.ResourceResults.ResourceRef` field was only ever used for its own `Name` field, and as part of tektoncd#2694, a new field, `TaskRun.Status.ResourceResults.ResourceName` was added to replace `...ResourceRef.Name` with a more semantically appropriate field. This change finishes the work by removing the deprecated `TaskRun.Status.ResourceResults.ResourceRef`.

This has been scheduled for removal since April 2021.

Signed-off-by: Andrew Bayer <[email protected]>
tekton-robot pushed a commit that referenced this issue Jun 15, 2022
See #2694.

The `TaskRun.Status.ResourceResults.ResourceRef` field was only ever used for its own `Name` field, and as part of #2694, a new field, `TaskRun.Status.ResourceResults.ResourceName` was added to replace `...ResourceRef.Name` with a more semantically appropriate field. This change finishes the work by removing the deprecated `TaskRun.Status.ResourceResults.ResourceRef`.

This has been scheduled for removal since April 2021.

Signed-off-by: Andrew Bayer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants