Documentation
¶
Overview ¶
Package framework contains the upgraded remote resolution framework. It is equivalent to `pkg/resolution/resolver/framework`. This was necessary to ensure backwards compatibility with the existing framework.
This package is subject to further refactoring and changes.
Index ¶
- Constants
- Variables
- func DataFromConfigMap(config *corev1.ConfigMap) (map[string]string, error)
- func FilterResolutionRequestsBySelector(selector map[string]string) func(obj interface{}) bool
- func GetResolutionTimeout(timeout, defaultTimeout time.Duration) time.Duration
- func GetResolverConfigFromContext(ctx context.Context) map[string]string
- func InjectResolverConfigToContext(ctx context.Context, conf map[string]string) context.Context
- func LeaderAwareFuncs(lister rrlister.ResolutionRequestLister) reconciler.LeaderAwareFuncsdeprecated
- func LeaderAwareFuncsWithSelector(lister rrlister.ResolutionRequestLister, selector map[string]string) reconciler.LeaderAwareFuncs
- func NewController(ctx context.Context, resolver Resolver, modifiers ...ReconcilerModifier) func(context.Context, configmap.Watcher) *controller.Impl
- func ValidateParams(params []pipelinev1.Param) error
- func ValidateResolvedResource(resource ResolvedResource) error
- func ValidateResolver(ctx context.Context, sel map[string]string) error
- type ConfigStore
- type ConfigWatcher
- type FakeResolvedResource
- type FakeResolver
- func (r *FakeResolver) GetName(_ context.Context) string
- func (r *FakeResolver) GetResolutionTimeout(ctx context.Context, defaultTimeout time.Duration, params map[string]string) (time.Duration, error)
- func (r *FakeResolver) GetSelector(_ context.Context) map[string]string
- func (r *FakeResolver) Initialize(ctx context.Context) error
- func (r *FakeResolver) Resolve(_ context.Context, req *v1beta1.ResolutionRequestSpec) (ResolvedResource, error)
- func (r *FakeResolver) Validate(_ context.Context, req *v1beta1.ResolutionRequestSpec) error
- type Reconciler
- type ReconcilerModifier
- type ResolvedResource
- type Resolver
- type TimedResolution
Constants ¶
const ( // LabelValueFakeResolverType is the value to use for the // resolution.tekton.dev/type label on resource requests LabelValueFakeResolverType string = "fake" // FakeResolverName is the name that the fake resolver should be // associated with FakeResolverName string = "Fake" // FakeParamName is the name used for the fake resolver's single parameter. FakeParamName string = "fake-key" )
const FakeUrl string = "fake://url"
Variables ¶
var ErrMissingTypeSelector = fmt.Errorf("invalid resolver: minimum selector must include %q", common.LabelKeyResolverType)
ErrMissingTypeSelector is returned when a resolver does not return a selector with a type label from its GetSelector method.
Functions ¶
func DataFromConfigMap ¶ added in v1.17.0
DataFromConfigMap returns a copy of the contents of a configmap or an empty map if the configmap doesn't have any data.
func FilterResolutionRequestsBySelector ¶ added in v1.17.0
func GetResolutionTimeout ¶ added in v1.17.0
GetResolutionTimeout returns the input timeout if set to something greater than 0 or the default time.Duration if not configured.
func GetResolverConfigFromContext ¶ added in v1.17.0
GetResolverConfigFromContext returns any resolver-specific configuration that has been stored or an empty map if none exists.
func InjectResolverConfigToContext ¶ added in v1.17.0
InjectResolverConfigToContext returns a new context with a map stored in it for a resolvers config.
func LeaderAwareFuncs
deprecated
added in
v1.17.0
func LeaderAwareFuncs(lister rrlister.ResolutionRequestLister) reconciler.LeaderAwareFuncs
LeaderAwareFuncs returns the LeaderAwareFuncs for a resolver's reconciler, re-enqueueing every ResolutionRequest in the cluster on promotion.
Deprecated: use LeaderAwareFuncsWithSelector. Listing without a selector hands every resolver every ResolutionRequest, and since the reconciler has no label guard of its own the wrong resolver then fails requests never addressed to it. This signature is kept so that callers outside this repository keep compiling, and its behaviour is unchanged.
func LeaderAwareFuncsWithSelector ¶ added in v1.17.0
func LeaderAwareFuncsWithSelector(lister rrlister.ResolutionRequestLister, selector map[string]string) reconciler.LeaderAwareFuncs
LeaderAwareFuncsWithSelector returns the LeaderAwareFuncs for a resolver's reconciler. On promotion it re-enqueues only the ResolutionRequests this resolver is responsible for, matching the labels that FilterResolutionRequestsBySelector applies to the informer's event handler, so the two paths cannot drift.
An empty selector fails closed and enqueues nothing. labels.SelectorFromSet treats an empty set as labels.Everything(), which is the very bug this function exists to fix, so it must not be reachable by way of a resolver that returns no selector. Callers validate the selector with ValidateResolver, which rejects one without a resolution.tekton.dev/type label; failing closed here is the second line of defence.
func NewController ¶
func NewController(ctx context.Context, resolver Resolver, modifiers ...ReconcilerModifier) func(context.Context, configmap.Watcher) *controller.Impl
NewController returns a knative controller for a Tekton Resolver. This sets up a lot of the boilerplate that individual resolvers shouldn't need to be concerned with since it's common to all of them.
func ValidateParams ¶ added in v1.17.0
func ValidateParams(params []pipelinev1.Param) error
func ValidateResolvedResource ¶ added in v1.17.0
func ValidateResolvedResource(resource ResolvedResource) error
ValidateResolvedResource validates that the ResolvedResource's data is a kubernetes object and a Tekton kind. This ensures non-k8s data (e.g. tokens) or non-tekton k8s objects (e.g. Secrets) are not written into the unprivileged ResolutionRequest objects.
Types ¶
type ConfigStore ¶ added in v1.17.0
type ConfigStore struct {
*resolverconfig.Store
// contains filtered or unexported fields
}
ConfigStore wraps a knative untyped store and provides helper methods for working with a resolver's configuration data.
func NewConfigStore ¶ added in v1.17.0
func NewConfigStore(resolverConfigName string, logger configmap.Logger) *ConfigStore
NewConfigStore creates a new untyped store for the resolver's configuration and a config.Store for general Pipeline configuration.
func (*ConfigStore) GetResolverConfig ¶ added in v1.17.0
func (store *ConfigStore) GetResolverConfig() map[string]string
GetResolverConfig returns a copy of the resolver's current configuration or an empty map if the stored config is nil or invalid.
func (*ConfigStore) ToContext ¶ added in v1.17.0
func (store *ConfigStore) ToContext(ctx context.Context) context.Context
ToContext returns a new context with the resolver's configuration data stored in it.
func (*ConfigStore) WatchConfigs ¶ added in v1.17.0
func (store *ConfigStore) WatchConfigs(w configmap.Watcher)
WatchConfigs uses the provided configmap.Watcher to setup watches for the config names provided in the Constructors map
type ConfigWatcher ¶ added in v1.17.0
type ConfigWatcher interface {
// GetConfigName should return a string name for its
// configuration to be referenced by. This will map to the name
// of a ConfigMap in the same namespace as the resolver.
GetConfigName(ctx context.Context) string
}
ConfigWatcher is the interface to implement if your resolver accepts additional configuration from an admin. Examples of how this might be used: - your resolver might require an allow-list of repositories or registries - your resolver might allow request timeout settings to be configured - your resolver might need an API endpoint or base url to be set
When your resolver implements this interface it will be able to access configuration from the context it receives in calls to ValidateParams and Resolve.
type FakeResolvedResource ¶ added in v1.17.0
type FakeResolvedResource struct {
Content string
AnnotationMap map[string]string
ContentSource *pipelinev1.RefSource
ErrorWith string
WaitFor time.Duration
}
FakeResolvedResource is a framework.ResolvedResource implementation for use with the fake resolver. If it's the value in the FakeResolver's ForParam map for the key given as the fake param value, the FakeResolver will first check if it's got a value for ErrorWith. If so, that string will be returned as an error. Then, if WaitFor is greater than zero, the FakeResolver will wait that long before returning. And finally, the FakeResolvedResource will be returned.
func (*FakeResolvedResource) Annotations ¶ added in v1.17.0
func (f *FakeResolvedResource) Annotations() map[string]string
Annotations returns the FakeResolvedResource's AnnotationMap field.
func (*FakeResolvedResource) Data ¶ added in v1.17.0
func (f *FakeResolvedResource) Data() []byte
Data returns the FakeResolvedResource's Content field as bytes.
func (*FakeResolvedResource) RefSource ¶ added in v1.17.0
func (f *FakeResolvedResource) RefSource() *pipelinev1.RefSource
RefSource is the source reference of the remote data that records where the remote file came from including the url, digest and the entrypoint.
type FakeResolver ¶
type FakeResolver struct {
ForParam map[string]*FakeResolvedResource
Timeout time.Duration
}
FakeResolver implements a framework.Resolver that can fetch pre-configured strings based on a parameter value, or return resolution attempts with a configured error.
func (*FakeResolver) GetName ¶
func (r *FakeResolver) GetName(_ context.Context) string
GetName returns the string name that the fake resolver should be associated with.
func (*FakeResolver) GetResolutionTimeout ¶
func (r *FakeResolver) GetResolutionTimeout(ctx context.Context, defaultTimeout time.Duration, params map[string]string) (time.Duration, error)
GetResolutionTimeout returns the configured timeout for the reconciler, or the default time.Duration if not configured.
func (*FakeResolver) GetSelector ¶
func (r *FakeResolver) GetSelector(_ context.Context) map[string]string
GetSelector returns the labels that resource requests are required to have for the fake resolver to process them.
func (*FakeResolver) Initialize ¶
func (r *FakeResolver) Initialize(ctx context.Context) error
Initialize performs any setup required by the fake resolver.
func (*FakeResolver) Resolve ¶
func (r *FakeResolver) Resolve(_ context.Context, req *v1beta1.ResolutionRequestSpec) (ResolvedResource, error)
Resolve performs the work of fetching a file from the fake resolver given a map of parameters.
func (*FakeResolver) Validate ¶
func (r *FakeResolver) Validate(_ context.Context, req *v1beta1.ResolutionRequestSpec) error
Validate returns an error if the given parameter map is not valid for a resource request targeting the fake resolver.
type Reconciler ¶
type Reconciler struct {
// Implements reconciler.LeaderAware
reconciler.LeaderAwareFuncs
// Clock is used by the reconciler to track the passage of time
// and can be overridden for tests.
Clock clock.PassiveClock
// contains filtered or unexported fields
}
Reconciler handles ResolutionRequest objects, performs functionality common to all resolvers and delegates resolver-specific actions to its embedded type-specific Resolver object.
func (*Reconciler) MarkFailed ¶
func (r *Reconciler) MarkFailed(ctx context.Context, rr *v1beta1.ResolutionRequest, resolutionErr error) error
MarkFailed updates a ResolutionRequest as having failed. It returns errors that occur during the update process or nil if the update appeared to succeed.
func (*Reconciler) OnError ¶
func (r *Reconciler) OnError(ctx context.Context, rr *v1beta1.ResolutionRequest, err error) error
OnError is used to handle any situation where a ResolutionRequest has reached a terminal situation that cannot be recovered from.
func (*Reconciler) Reconcile ¶
func (r *Reconciler) Reconcile(ctx context.Context, key string) error
Reconcile receives the string key of a ResolutionRequest object, looks it up, checks it for common errors, and then delegates resolver-specific functionality to the reconciler's embedded type-specific resolver. Any errors that occur during validation or resolution are handled by updating or failing the ResolutionRequest.
type ReconcilerModifier ¶
type ReconcilerModifier = func(reconciler *Reconciler)
ReconcilerModifier is a func that can access and modify a reconciler in the moments before a resolver is started. It allows for things like injecting a test clock.
type ResolvedResource ¶ added in v1.17.0
type ResolvedResource interface {
Data() []byte
Annotations() map[string]string
RefSource() *pipelinev1.RefSource
}
ResolvedResource returns the data and annotations of a successful resource fetch.
This is a distinct named interface from the old resolution/resolver/framework.ResolvedResource. Resolver implementations returning the old type won’t satisfy the new framework.Resolver, even though the method sets are identical.
func Resolve ¶ added in v1.17.0
func Resolve(params []pipelinev1.Param, forParam map[string]*FakeResolvedResource) (ResolvedResource, error)
type Resolver ¶
type Resolver interface {
// Initialize is called at the moment the resolver controller is
// instantiated and is a good place to setup things like
// resource listers.
Initialize(ctx context.Context) error
// GetName should give back the name of the resolver. E.g. "Git"
GetName(ctx context.Context) string
// GetSelector returns the labels that are used to direct resolution
// requests to this resolver.
GetSelector(ctx context.Context) map[string]string
// Validate is given the ressolution request spec
// should return an error if the resolver cannot resolve it.
Validate(ctx context.Context, req *v1beta1.ResolutionRequestSpec) error
// ResolveRequest receives the resolution request spec
// and returns the resolved data along with any annotations
// to include in the response. If resolution fails then an error
// should be returned instead. If a resolution.Error
// is returned then its Reason and Message are used as part of the
// response to the request. If an error is returned which is transient,
// such as a kubernetes timeout or too many requests error, the
// ResolutionRequest will not be updated with a failed status.
// See github.com/tektoncd/pipeline/pkg/resolution/common/errors.go for
// the definition of a transient error.
//
// Note that the ResolvedResource returned by this function definition
// corresponds to remoteresolution/resolver/framework.ResolvedResource and
// not resolution/resolver/framework.ResolvedResource.
// Resolver implementations returning the old type won’t satisfy the new
// remoteresolution/resolver/framework.Resolver
Resolve(ctx context.Context, req *v1beta1.ResolutionRequestSpec) (ResolvedResource, error)
}
Resolver is the interface to implement for type-specific resource resolution. It fetches resources from a given type of remote location and returns their content along with any associated annotations.
type TimedResolution ¶ added in v1.17.0
type TimedResolution interface {
// GetResolutionTimeout receives the current request's context
// object, which includes any request-scoped data like
// resolver config and the request's originating namespace,
// along with a default.
GetResolutionTimeout(ctx context.Context, timeout time.Duration, params map[string]string) (time.Duration, error)
}
TimedResolution is an optional interface that a resolver can implement to override the default resolution request timeout.
There are two timeouts that a resolution request adheres to: First there is a global timeout that the core ResolutionRequest reconciler enforces on _all_ requests. This prevents zombie requests (such as those with a misconfigured `type`) sticking around in perpetuity. Second there are resolver-specific timeouts that default to 1 minute.
A resolver implementing the TimedResolution interface sets the maximum duration of any single request to this resolver.
The core ResolutionRequest reconciler's global timeout overrides any resolver-specific timeout.