-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcarrot.go
73 lines (60 loc) · 2.13 KB
/
carrot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package carrot
import (
"context"
"github.com/pkg/errors"
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
pipelinesclientset "github.com/tektoncd/pipeline/pkg/client/clientset/versioned"
pipelineclient "github.com/tektoncd/pipeline/pkg/client/injection/client"
"github.com/tektoncd/pipeline/pkg/resolution/common"
"github.com/tektoncd/pipeline/pkg/resolution/resolver/framework"
)
const jsonContentType = "application/json"
func New() framework.Resolver {
return &resolver{}
}
type resolver struct {
// The clientset used to look up tasks and pipelines from the
// clusterresolver's private namespace.
Pipelineclientset pipelinesclientset.Interface
}
// Initialize creates an instance of the pipelines clientset so that
// tasks and pipelines can be looked up.
func (r *resolver) Initialize(ctx context.Context) error {
r.Pipelineclientset = pipelineclient.Get(ctx)
return nil
}
// GetName returns a string name to refer to this resolver by.
func (r *resolver) GetName(context.Context) string {
return "Potato"
}
// GetSelector returns a map of labels to match requests to this resolver.
func (r *resolver) GetSelector(context.Context) map[string]string {
return map[string]string{
common.LabelKeyResolverType: "carrot",
}
}
// ValidateParams ensures parameters from a request are as expected.
// Only "kind" and "name" are needed.
func (r *resolver) ValidateParams(ctx context.Context, params []v1.Param) error {
return nil
}
// Resolve uses the given params to resolve the requested file or resource.
func (r *resolver) Resolve(ctx context.Context, params []v1.Param) (framework.ResolvedResource, error) {
return nil, errors.New("Not implemented")
}
// resolvedResource wraps the data we want to return to Pipelines
type resolvedResource struct {
data []byte
}
// Data returns the bytes of the task or pipeline resolved from the
// private namespace.
func (r *resolvedResource) Data() []byte {
return r.data
}
// Annotations returns a content-type of json since the data is
// serialized as json.
func (r *resolvedResource) Annotations() map[string]string {
return map[string]string{
common.AnnotationKeyContentType: jsonContentType,
}
}