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 Apr 29, 2024
1 parent b419b2c commit 7d0c732
Show file tree
Hide file tree
Showing 75 changed files with 10,283 additions and 102 deletions.
12 changes: 6 additions & 6 deletions cmd/resolvers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import (
"strings"

"github.com/tektoncd/pipeline/pkg/apis/resolution/v1alpha1"
"github.com/tektoncd/pipeline/pkg/resolution/resolver/bundle"
"github.com/tektoncd/pipeline/pkg/resolution/resolver/cluster"
"github.com/tektoncd/pipeline/pkg/resolution/resolver/framework"
"github.com/tektoncd/pipeline/pkg/resolution/resolver/git"
"github.com/tektoncd/pipeline/pkg/resolution/resolver/http"
"github.com/tektoncd/pipeline/pkg/resolution/resolver/hub"
"github.com/tektoncd/pipeline/pkg/resolution/v2/resolver/bundle"
"github.com/tektoncd/pipeline/pkg/resolution/v2/resolver/cluster"
"github.com/tektoncd/pipeline/pkg/resolution/v2/resolver/framework"
"github.com/tektoncd/pipeline/pkg/resolution/v2/resolver/git"
"github.com/tektoncd/pipeline/pkg/resolution/v2/resolver/http"
"github.com/tektoncd/pipeline/pkg/resolution/v2/resolver/hub"
filteredinformerfactory "knative.dev/pkg/client/injection/kube/informers/factory/filtered"
"knative.dev/pkg/injection/sharedmain"
"knative.dev/pkg/signals"
Expand Down
28 changes: 15 additions & 13 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 @@ -102,7 +104,7 @@ package main

import (
"context"
"github.com/tektoncd/pipeline/pkg/resolution/resolver/framework"
"github.com/tektoncd/pipeline/pkg/resolution/v2/resolver/framework"
"knative.dev/pkg/injection/sharedmain"
)

Expand Down Expand Up @@ -137,7 +139,7 @@ type framework.Resolver in argument to framework.NewController:

We've already defined our own `resolver` type but in order to get the
resolver running you'll need to add the methods defined in [the
`framework.Resolver` interface](../pkg/resolution/resolver/framework/interface.go)
`framework.Resolver` interface](../pkg/resolution/v2/resolver/framework/interface.go)
to your `main.go` file. Going through each method in turn:

## The `Initialize` method
Expand Down Expand Up @@ -194,23 +196,23 @@ import (
"context"

// Add this one; it defines LabelKeyResolverType we use in GetSelector
"github.com/tektoncd/pipeline/pkg/resolution/common"
"github.com/tektoncd/pipeline/pkg/resolution/resolver/framework"
"github.com/tektoncd/pipeline/pkg/resolution/v2/common"
"github.com/tektoncd/pipeline/pkg/resolution/v2/resolver/framework"
"knative.dev/pkg/injection/sharedmain"
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
)
```

## 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 Expand Up @@ -450,7 +452,7 @@ Resolver to fetch data from your storage backend of choice.

Or if you prefer to take a look at a more fully-realized example of a
Resolver, see the [code for the `gitresolver` hosted in the Tekton
Pipeline repo](https://github.com/tektoncd/pipeline/tree/main/pkg/resolution/resolver/git/).
Pipeline repo](https://github.com/tektoncd/pipeline/tree/main/pkg/resolution/v2/resolver/git/).

Finally, another direction you could take this would be to try writing a
`PipelineRun` for Tekton Pipelines that speaks to your Resolver. Can
Expand Down

0 comments on commit 7d0c732

Please sign in to comment.