framework

package
v0.62.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2024 License: Apache-2.0 Imports: 28 Imported by: 12

Documentation

Index

Constants

View Source
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

View Source
var (
	// ErrMissingTypeSelector is returned when a resolver does not return
	// a selector with a type label from its GetSelector method.
	ErrMissingTypeSelector = fmt.Errorf("invalid resolver: minimum selector must include %q", common.LabelKeyResolverType)

	// ErrorMissingTypeSelector is an alias to ErrMissingTypeSelector
	//
	// Deprecated: use ErrMissingTypeSelector instead.
	ErrorMissingTypeSelector = ErrMissingTypeSelector
)

Functions

func DataFromConfigMap

func DataFromConfigMap(config *corev1.ConfigMap) (map[string]string, error)

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 v0.60.0

func FilterResolutionRequestsBySelector(selector map[string]string) func(obj interface{}) bool

func GetResolutionTimeout added in v0.60.0

func GetResolutionTimeout(timeout, defaultTimeout time.Duration) time.Duration

GetResolutionTimeout returns the input timeout if set to something greater than 0 or the default time.Duration if not configured.

func GetResolverConfigFromContext

func GetResolverConfigFromContext(ctx context.Context) map[string]string

GetResolverConfigFromContext returns any resolver-specific configuration that has been stored or an empty map if none exists.

func InjectResolverConfigToContext

func InjectResolverConfigToContext(ctx context.Context, conf map[string]string) context.Context

InjectResolverConfigToContext returns a new context with a map stored in it for a resolvers config.

func LeaderAwareFuncs added in v0.60.0

TODO(sbwsg): I don't really understand the LeaderAwareness types beyond the fact that the controller crashes if they're missing. It looks like this is bucketing based on labels. Should we use the filter selector from above in the call to lister.List here?

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 v0.60.0

func ValidateParams(params []pipelinev1.Param) error

func ValidateResolver added in v0.60.0

func ValidateResolver(ctx context.Context, sel map[string]string) error

Types

type ConfigStore

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

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

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

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

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

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

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

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.

func (*FakeResolvedResource) RefSource added in v0.47.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) 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 []pipelinev1.Param) (ResolvedResource, error)

Resolve performs the work of fetching a file from the fake resolver given a map of parameters.

func (*FakeResolver) ValidateParams

func (r *FakeResolver) ValidateParams(_ context.Context, params []pipelinev1.Param) error

ValidateParams returns an error if the given parameter map is not valid for a resource request targeting the fake resolver.

type Reconciler deprecated

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.

Deprecated: Use github.com/tektoncd/pipeline/pkg/remoteresolution/resolver/framework.Reconciler instead.

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

type ResolvedResource interface {
	Data() []byte
	Annotations() map[string]string
	RefSource() *pipelinev1.RefSource
}

ResolvedResource returns the data and annotations of a successful resource fetch.

func Resolve added in v0.60.0

func Resolve(params []pipelinev1.Param, forParam map[string]*FakeResolvedResource) (ResolvedResource, error)

type Resolver deprecated

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

	// ValidateParams is given the parameters from a resource
	// request and should return an error if any are missing or invalid.
	ValidateParams(ctx context.Context, params []pipelinev1.Param) 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(ctx context.Context, params []pipelinev1.Param) (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.

Deprecated: Use github.com/tektoncd/pipeline/pkg/remoteresolution/resolver/framework.Resolver instead.

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(ctx context.Context, timeout 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL