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 10, 2024
1 parent b419b2c commit bd2b8aa
Show file tree
Hide file tree
Showing 70 changed files with 6,824 additions and 790 deletions.
15 changes: 8 additions & 7 deletions cmd/resolvers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ 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/remoteresolution/resolver/bundle"
"github.com/tektoncd/pipeline/pkg/remoteresolution/resolver/cluster"
"github.com/tektoncd/pipeline/pkg/remoteresolution/resolver/framework"
"github.com/tektoncd/pipeline/pkg/remoteresolution/resolver/git"
"github.com/tektoncd/pipeline/pkg/remoteresolution/resolver/http"
"github.com/tektoncd/pipeline/pkg/remoteresolution/resolver/hub"
hubv1 "github.com/tektoncd/pipeline/pkg/resolution/resolver/hub"
filteredinformerfactory "knative.dev/pkg/client/injection/kube/informers/factory/filtered"
"knative.dev/pkg/injection/sharedmain"
"knative.dev/pkg/signals"
Expand All @@ -35,7 +36,7 @@ import (
func main() {
ctx := filteredinformerfactory.WithSelectors(signals.NewContext(), v1alpha1.ManagedByLabelKey)
tektonHubURL := buildHubURL(os.Getenv("TEKTON_HUB_API"), "")
artifactHubURL := buildHubURL(os.Getenv("ARTIFACT_HUB_API"), hub.DefaultArtifactHubURL)
artifactHubURL := buildHubURL(os.Getenv("ARTIFACT_HUB_API"), hubv1.DefaultArtifactHubURL)

sharedmain.MainWithContext(ctx, "controller",
framework.NewController(ctx, &git.Resolver{}),
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
Loading

0 comments on commit bd2b8aa

Please sign in to comment.