Skip to content

Commit

Permalink
TEP-0154: Enable concise resolver syntax
Browse files Browse the repository at this point in the history
This PR enables concise resolver syntax as per TEP 0154.
It allows users to pass a url like string to Taskref/name field. In turn, the Tekton controller passes the string to the Resolution Request under the name `resolutionName` which the resolvers can parse and resolve.
  • Loading branch information
chitrangpatel committed Apr 5, 2024
1 parent 118370d commit ecfa777
Show file tree
Hide file tree
Showing 48 changed files with 440 additions and 132 deletions.
2 changes: 2 additions & 0 deletions config/config-feature-flags.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,5 @@ data:
enable-artifacts: "false"
# Setting this flag to "true" will enable the built-in param input validation via param enum.
enable-param-enum: "false"
# Setting this flag to "true" will enable the use of concise resolver syntax
enable-concise-resolver-syntax: "false"
30 changes: 28 additions & 2 deletions docs/how-to-write-a-resolver.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,32 @@ func (r *resolver) ValidateParams(ctx context.Context, params map[string]string)
You'll also need to add the `"errors"` package to your list of imports at
the top of the file.

## The `ValidateResolutionName` method

The `ValidateResolutionName` method checks that the `resolutionName` submitted as part of
a resolution request is valid and can be parsed by the resolver. Our example resolver expects
format for the `resolutionName` to be `demoscheme://<path>` so we'll validate this format.

```go
// ValidateResolutionName ensures resolutionName from a request is as expected.
func (r *resolver) ValidateResolutionName(ctx context.Context, resolutionName string) error {
u, err := url.ParseRequestURI(resolutionName)
if err != nil {
return err
}
if u.Scheme != "demoscheme" {
return errors.New("Invalid Scheme. Want %s, Got %s", "demoscheme", u.Scheme)
}
if u.Path == "" {
return errors.New("Empty path.")
}
return nil
}
```

You'll also need to add the `net/url` and `"errors"` package to your list of imports at
the top of the file.

## The `Resolve` method

We implement the `Resolve` method to do the heavy lifting of fetching
Expand All @@ -233,8 +259,8 @@ The method signature we're implementing here has a
is another type we have to implement but it has a small footprint:

```go
// Resolve uses the given params to resolve the requested file or resource.
func (r *resolver) Resolve(ctx context.Context, params map[string]string) (framework.ResolvedResource, error) {
// Resolve uses the given resolutionName or params to resolve the requested file or resource.
func (r *resolver) Resolve(ctx context.Context, resolutionName string, params map[string]string) (framework.ResolvedResource, error) {
return &myResolvedResource{}, nil
}

Expand Down
4 changes: 4 additions & 0 deletions docs/pipeline-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3494,6 +3494,10 @@ Example: &ldquo;task/git-clone/0.8/git-clone.yaml&rdquo;</p>
</tr>
</tbody>
</table>
<h3 id="tekton.dev/v1.RemoteResolutionUrl">RemoteResolutionUrl
(<code>string</code> alias)</h3>
<div>
</div>
<h3 id="tekton.dev/v1.ResolverName">ResolverName
(<code>string</code> alias)</h3>
<p>
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/tektoncd/pipeline

go 1.19
go 1.21

toolchain go1.21.6

require (
github.com/Microsoft/go-winio v0.6.1 // indirect
Expand Down
20 changes: 20 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ecfa777

Please sign in to comment.