Skip to content

Commit

Permalink
Remote Resolution Refactor
Browse files Browse the repository at this point in the history
This PR implements an updated resolver framework with slight updates. This is to avoid backwards incompatibility while implementing [TEP-0154](tektoncd/community#1138).

The current framework only works with Params. e.g. The interface has ValidateParams and Resolve which takes in Params. Now that we also need to pass in a `URL`, we need to add new methods and change function signatures which leads to API incompatibility with existing custom resolvers. As a result, when users upgrade to new version of Tekton Pipelines, they will be forced to be compatible with the new format because of the interface changes.

This PR tries to make it future proof such that if we add new fields to the ResolutionSpec, it will be handled without the need to break users.
  • Loading branch information
chitrangpatel committed May 1, 2024
1 parent b419b2c commit 1396119
Show file tree
Hide file tree
Showing 44 changed files with 5,370 additions and 436 deletions.
10 changes: 5 additions & 5 deletions cmd/resolvers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ func main() {
artifactHubURL := buildHubURL(os.Getenv("ARTIFACT_HUB_API"), hub.DefaultArtifactHubURL)

sharedmain.MainWithContext(ctx, "controller",
framework.NewController(ctx, &git.Resolver{}),
framework.NewController(ctx, &hub.Resolver{TektonHubURL: tektonHubURL, ArtifactHubURL: artifactHubURL}),
framework.NewController(ctx, &bundle.Resolver{}),
framework.NewController(ctx, &cluster.Resolver{}),
framework.NewController(ctx, &http.Resolver{}))
framework.NewControllerV2(ctx, &git.ResolverV2{}),
framework.NewControllerV2(ctx, &hub.ResolverV2{TektonHubURL: tektonHubURL, ArtifactHubURL: artifactHubURL}),
framework.NewControllerV2(ctx, &bundle.ResolverV2{}),
framework.NewControllerV2(ctx, &cluster.ResolverV2{}),
framework.NewControllerV2(ctx, &http.ResolverV2{}))
}

func buildHubURL(configAPI, defaultURL string) string {
Expand Down
20 changes: 11 additions & 9 deletions docs/how-to-write-a-resolver.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ weight: 104

# How to write a Resolver

**Note**: [Here](#old-resolver-framework/how-to-write-a-resolver.md) is the older version of the framework.

This how-to will outline the steps a developer needs to take when creating
a new (very basic) Resolver. Rather than focus on support for a particular version
control system or cloud platform this Resolver will simply respond with
Expand Down Expand Up @@ -108,7 +110,7 @@ import (

func main() {
sharedmain.Main("controller",
framework.NewController(context.Background(), &resolver{}),
framework.NewControllerV2(context.Background(), &resolver{}),
)
}

Expand Down Expand Up @@ -201,16 +203,16 @@ import (
)
```

## The `ValidateParams` method
## The `Validate` method

The `ValidateParams` method checks that the params submitted as part of
The `Validate` method checks that the resolution-spec submitted as part of
a resolution request are valid. Our example resolver doesn't expect
any params so we'll simply ensure that the given map is empty.
any params in the spec so we'll simply ensure that the there are no params.

```go
// ValidateParams ensures parameters from a request are as expected.
func (r *resolver) ValidateParams(ctx context.Context, params map[string]string) error {
if len(params) > 0 {
// Validate ensures that the resolution spec from a request is as expected.
func (r *resolver) Validate(ctx context.Context, req *v1beta1.ResolutionRequestSpec) error {
if len(req.Params) > 0 {
return errors.New("no params allowed")
}
return nil
Expand All @@ -233,8 +235,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 resolution spec to resolve the requested file or resource.
func (r *resolver) Resolve(ctx context.Context, req *v1beta1.ResolutionRequestSpec) (framework.ResolvedResource, error) {
return &myResolvedResource{}, nil
}

Expand Down

0 comments on commit 1396119

Please sign in to comment.