Documentation ¶
Index ¶
- Constants
- Variables
- func DataFromConfigMap(config *corev1.ConfigMap) (map[string]string, error)
- func GetResolverConfigFromContext(ctx context.Context) map[string]string
- func InjectResolverConfigToContext(ctx context.Context, conf map[string]string) context.Context
- func NewController(ctx context.Context, resolver Resolver, modifiers ...ReconcilerModifier) func(context.Context, configmap.Watcher) *controller.Impl
- 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) time.Duration
- func (r *FakeResolver) GetSelector(_ context.Context) map[string]string
- func (r *FakeResolver) Initialize(ctx context.Context) error
- func (r *FakeResolver) Resolve(_ context.Context, params map[string]string) (ResolvedResource, error)
- func (r *FakeResolver) ValidateParams(_ context.Context, params map[string]string) 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" )
Variables ¶
var ErrorMissingTypeSelector = fmt.Errorf("invalid resolver: minimum selector must include %q", common.LabelKeyResolverType)
ErrorMissingTypeSelector is returned when a resolver does not return a selector with a type label from its GetSelector method.
Functions ¶
func DataFromConfigMap ¶
DataFromConfigMap returns a copy of the contents of a configmap or an empty map if the configmap doesn't have any data.
func GetResolverConfigFromContext ¶
GetResolverConfigFromContext returns any resolver-specific configuration that has been stored or an empty map if none exists.
func InjectResolverConfigToContext ¶
InjectResolverConfigToContext returns a new context with a map stored in it for a resolvers config.
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.
Types ¶
type ConfigStore ¶
type ConfigStore struct {
// contains filtered or unexported fields
}
ConfigStore wraps a knative untyped store and provides helper methods for working with a resolver's configuration data.
func (*ConfigStore) GetResolverConfig ¶
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.
type ConfigWatcher ¶
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(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 ¶
type FakeResolvedResource struct { Content string AnnotationMap map[string]string 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 ¶
func (f *FakeResolvedResource) Annotations() map[string]string
Annotations returns the FakeResolvedResource's AnnotationMap field.
func (*FakeResolvedResource) Data ¶
func (f *FakeResolvedResource) Data() []byte
Data returns the FakeResolvedResource's Content field as bytes.
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) time.Duration
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, params map[string]string) (ResolvedResource, error)
Resolve performs the work of fetching a file from the fake resolver given a map of parameters.
func (*FakeResolver) ValidateParams ¶
ValidateParams 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 *v1alpha1.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 *v1alpha1.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 ¶
ResolvedResource returns the data and annotations of a successful resource fetch.
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(context.Context) error // GetName should give back the name of the resolver. E.g. "Git" GetName(context.Context) string // GetSelector returns the labels that are used to direct resolution // requests to this resolver. GetSelector(context.Context) map[string]string // ValidateParams is given the parameters from a resource // request and should return an error if any are missing or invalid. ValidateParams(context.Context, map[string]string) error // Resolve receives the parameters passed via a resource request // 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. Resolve(context.Context, map[string]string) (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 ¶
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(context.Context, time.Duration) time.Duration }
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 implemeting 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.