trait

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2023 License: Apache-2.0 Imports: 94 Imported by: 20

Documentation

Overview

Package trait contains implementations of all available traits (features)

Index

Constants

View Source
const (
	True  = "true"
	False = "false"
)
View Source
const (
	// TraitOrderBeforeControllerCreation can be used to inject configuration such as properties and environment variables
	// into the running integration, before the actual controller is created.
	TraitOrderBeforeControllerCreation = 850
	// TraitOrderControllerSelection can be used if you intend to provide an alternative controller for the integration
	// (e.g. Deployment, CronJob, ...).
	TraitOrderControllerSelection = 950
	// TraitOrderPostProcessResources is executed after all other traits are executed (except for important core traits such as
	// the "owner" trait), so it can be used to post-process generated resources before their actual creation.
	TraitOrderPostProcessResources = 2450
)

A list of named orders, useful for correctly binding addons.

Variables

View Source
var FactoryList []Factory

FactoryList contains the default list of trait Factory.

Functions

func AddToTraits

func AddToTraits(factory Factory)

AddToTraits registers a trait Factory.

func AssertTraitsType added in v1.10.0

func AssertTraitsType(traits interface{}) error

AssertTraitsType asserts that traits is either v1.Traits or v1.IntegrationKitTraits. This function is provided because Go doesn't have Either nor union types.

func Equals added in v1.10.0

func Equals(i1 Options, i2 Options) bool

Equals return if traits are the same.

func ExtractSourceDependencies added in v1.11.0

func ExtractSourceDependencies(source v1.SourceSpec, catalog *camel.RuntimeCatalog) (*strset.Set, error)

ExtractSourceDependencies extracts dependencies from source.

func IntegrationAndBindingSameTraits added in v1.10.0

func IntegrationAndBindingSameTraits(i1 *v1.Integration, i2 *v1alpha1.KameletBinding) (bool, error)

IntegrationAndBindingSameTraits return if traits are the same. The comparison is done for the subset of traits defines on the binding as during the trait processing, some traits may be added to the Integration i.e. knative configuration in case of sink binding.

func IntegrationAndKitHaveSameTraits added in v1.10.0

func IntegrationAndKitHaveSameTraits(i1 *v1.Integration, i2 *v1.IntegrationKit) (bool, error)

IntegrationAndKitHaveSameTraits return if traits are the same.

func IntegrationKitsHaveSameTraits added in v1.10.0

func IntegrationKitsHaveSameTraits(i1 *v1.IntegrationKit, i2 *v1.IntegrationKit) (bool, error)

IntegrationKitsHaveSameTraits return if traits are the same.

func IntegrationsHaveSameTraits added in v1.10.0

func IntegrationsHaveSameTraits(i1 *v1.Integration, i2 *v1.Integration) (bool, error)

IntegrationsHaveSameTraits return if traits are the same.

func KameletBindingsHaveSameTraits added in v1.10.0

func KameletBindingsHaveSameTraits(i1 *v1alpha1.KameletBinding, i2 *v1alpha1.KameletBinding) (bool, error)

KameletBindingsHaveSameTraits return if traits are the same.

func MigrateLegacyConfiguration added in v1.10.0

func MigrateLegacyConfiguration(trait map[string]interface{}) error

MigrateLegacyConfiguration moves up the legacy configuration in a trait to the new top-level properties. Values of the new properties always take precedence over the ones from the legacy configuration with the same property names.

func ToAddonTrait added in v1.10.0

func ToAddonTrait(t *testing.T, config map[string]interface{}) v1.AddonTrait

func ToPropertyMap added in v1.10.0

func ToPropertyMap(trait interface{}) (map[string]interface{}, error)

ToPropertyMap accepts a trait and converts it to a map of trait properties.

func ToTrait added in v1.10.0

func ToTrait(trait map[string]interface{}, target interface{}) error

ToTrait unmarshals a map configuration to a target trait.

Types

type BaseTrait

type BaseTrait struct {
	TraitID        ID            `json:"-"`
	Client         client.Client `json:"-"`
	ExecutionOrder int           `json:"-"`
	L              log.Logger    `json:"-"`
}

BaseTrait is the root trait with noop implementations for hooks.

func NewBaseTrait

func NewBaseTrait(id string, order int) BaseTrait

func (*BaseTrait) ID

func (trait *BaseTrait) ID() ID

ID returns the identifier of the trait.

func (*BaseTrait) InfluencesKit

func (trait *BaseTrait) InfluencesKit() bool

InfluencesKit determines if the trait has any influence on Integration Kits.

func (*BaseTrait) InjectClient

func (trait *BaseTrait) InjectClient(c client.Client)

InjectClient implements client.ClientInject and allows to inject a client into the trait.

func (*BaseTrait) IsAllowedInProfile

func (trait *BaseTrait) IsAllowedInProfile(v1.TraitProfile) bool

IsAllowedInProfile returns true for any profile by default.

func (*BaseTrait) IsPlatformTrait

func (trait *BaseTrait) IsPlatformTrait() bool

IsPlatformTrait marks all fundamental traits that allow the platform to work.

func (*BaseTrait) Order

func (trait *BaseTrait) Order() int

Order contains the order value provided during initialization.

func (*BaseTrait) RequiresIntegrationPlatform

func (trait *BaseTrait) RequiresIntegrationPlatform() bool

RequiresIntegrationPlatform indicates that the trait cannot work without an integration platform set.

type Catalog

type Catalog struct {
	L log.Logger
	// contains filtered or unexported fields
}

Catalog collects all information about traits in one place.

func NewCatalog

func NewCatalog(c client.Client) *Catalog

NewCatalog creates a new trait Catalog.

func (*Catalog) AllTraits added in v1.7.0

func (c *Catalog) AllTraits() []Trait

func (*Catalog) ComputeTraitsProperties

func (c *Catalog) ComputeTraitsProperties() []string

ComputeTraitsProperties returns all key/value configuration properties that can be used to configure traits.

func (*Catalog) Configure added in v1.10.0

func (c *Catalog) Configure(env *Environment) error

Configure reads trait configurations from environment and applies them to catalog.

func (*Catalog) GetTrait

func (c *Catalog) GetTrait(id string) Trait

GetTrait returns the trait with the given ID.

func (*Catalog) TraitsForProfile

func (c *Catalog) TraitsForProfile(profile v1.TraitProfile) []Trait

TraitsForProfile returns all traits associated with a given profile.

Traits may depend on the result of previously executed ones, so care must be taken while changing the lists order.

type Comparable added in v1.7.0

type Comparable interface {
	Matches(Trait) bool
}

type ComparableTrait added in v1.7.0

type ComparableTrait interface {
	Trait
	Comparable
}

type ControllerStrategy

type ControllerStrategy string

ControllerStrategy is used to determine the kind of controller that needs to be created for the integration.

const (
	ControllerStrategyDeployment     ControllerStrategy = "deployment"
	ControllerStrategyKnativeService ControllerStrategy = "knative-service"
	ControllerStrategyCronJob        ControllerStrategy = "cron-job"

	DefaultControllerStrategy = ControllerStrategyDeployment
)

List of controller strategies.

type ControllerStrategySelector

type ControllerStrategySelector interface {
	// SelectControllerStrategy tells if the trait with current configuration can select a specific controller to use
	SelectControllerStrategy(*Environment) (*ControllerStrategy, error)
	// ControllerStrategySelectorOrder returns the order (priority) of the controller strategy selector
	ControllerStrategySelectorOrder() int
}

ControllerStrategySelector is the interface for traits that can determine the kind of controller that will run the integration.

type Environment

type Environment struct {
	CamelCatalog   *camel.RuntimeCatalog
	RuntimeVersion string
	Catalog        *Catalog
	// The Go standard context for the traits execution
	Ctx context.Context
	// The client to the API server
	Client client.Client
	// The active Platform
	Platform *v1.IntegrationPlatform
	// The current Integration
	Integration *v1.Integration
	// The IntegrationKit associated to the Integration
	IntegrationKit *v1.IntegrationKit
	// The IntegrationKits to be created for the Integration
	IntegrationKits []v1.IntegrationKit
	// The resources owned by the Integration that are applied to the API server
	Resources             *kubernetes.Collection
	PostActions           []func(*Environment) error
	PostStepProcessors    []func(*Environment) error
	PostProcessors        []func(*Environment) error
	BuildTasks            []v1.Task
	ConfiguredTraits      []Trait
	ExecutedTraits        []Trait
	EnvVars               []corev1.EnvVar
	ApplicationProperties map[string]string
	Interceptors          []string
	ServiceBindingSecret  string
}

An Environment provides the context for the execution of the traits. nolint: containedctx

func Apply

func Apply(ctx context.Context, c client.Client, integration *v1.Integration, kit *v1.IntegrationKit) (*Environment, error)

func (*Environment) DetermineCatalogNamespace added in v1.4.0

func (e *Environment) DetermineCatalogNamespace() string

func (*Environment) DetermineControllerStrategy

func (e *Environment) DetermineControllerStrategy() (ControllerStrategy, error)

DetermineControllerStrategy determines the type of controller that should be used for the integration.

func (*Environment) DetermineProfile

func (e *Environment) DetermineProfile() v1.TraitProfile

DetermineProfile determines the TraitProfile of the environment. First looking at the Integration.Spec for a Profile, next looking at the IntegrationKit.Spec and lastly the Platform Profile.

func (*Environment) GetIntegrationContainer added in v1.7.0

func (e *Environment) GetIntegrationContainer() *corev1.Container

func (*Environment) GetIntegrationContainerName added in v1.8.0

func (e *Environment) GetIntegrationContainerName() string

func (*Environment) GetIntegrationPodSpec added in v1.4.0

func (e *Environment) GetIntegrationPodSpec() *corev1.PodSpec

GetIntegrationPodSpec return the Integration Template Pod Specification, regardless of the deployment strategy.

func (*Environment) GetTrait

func (e *Environment) GetTrait(id ID) Trait

func (*Environment) InPhase

func (*Environment) IntegrationInPhase

func (e *Environment) IntegrationInPhase(phases ...v1.IntegrationPhase) bool

func (*Environment) IntegrationInRunningPhases added in v1.6.1

func (e *Environment) IntegrationInRunningPhases() bool

func (*Environment) IntegrationKitInPhase

func (e *Environment) IntegrationKitInPhase(phases ...v1.IntegrationKitPhase) bool

func (*Environment) PlatformInPhase added in v1.11.0

func (e *Environment) PlatformInPhase(phases ...v1.IntegrationPlatformPhase) bool

type Factory

type Factory = func() Trait

Factory is a generic factory for a trait.

type Finder added in v1.8.0

type Finder interface {
	GetTrait(id string) Trait
}

type ID

type ID string

ID uniquely identifies a trait.

type Identifiable

type Identifiable interface {
	ID() ID
}

Identifiable represent an identifiable type.

type Options added in v1.10.0

type Options map[string]map[string]interface{}

func FromAnnotations added in v1.10.0

func FromAnnotations(meta *metav1.ObjectMeta) (Options, error)

func NewTraitsOptionsForIntegration added in v1.10.0

func NewTraitsOptionsForIntegration(i *v1.Integration) (Options, error)

func NewTraitsOptionsForIntegrationKit added in v1.10.0

func NewTraitsOptionsForIntegrationKit(i *v1.IntegrationKit) (Options, error)

func NewTraitsOptionsForIntegrationPlatform added in v1.10.0

func NewTraitsOptionsForIntegrationPlatform(i *v1.IntegrationPlatform) (Options, error)

func NewTraitsOptionsForKameletBinding added in v1.10.0

func NewTraitsOptionsForKameletBinding(i *v1alpha1.KameletBinding) (Options, error)

func ToTraitMap added in v1.10.0

func ToTraitMap(traits interface{}) (Options, error)

ToTraitMap accepts either v1.Traits or v1.IntegrationKitTraits and converts it to a map of traits.

func (Options) Get added in v1.10.0

func (u Options) Get(id string) (map[string]interface{}, bool)

type Trait

type Trait interface {
	Identifiable
	client.Injectable

	// Configure the trait
	Configure(environment *Environment) (bool, error)

	// Apply executes a customization of the Environment
	Apply(environment *Environment) error

	// InfluencesKit determines if the trait has any influence on Integration Kits
	InfluencesKit() bool

	// IsPlatformTrait marks all fundamental traits that allow the platform to work
	IsPlatformTrait() bool

	// RequiresIntegrationPlatform indicates that the trait cannot work without an integration platform set
	RequiresIntegrationPlatform() bool

	// IsAllowedInProfile tells if the trait supports the given profile
	IsAllowedInProfile(v1.TraitProfile) bool

	// Order is the order in which the trait should be executed in the normal flow
	Order() int
}

Trait is the interface of all traits.

func NewInitTrait added in v1.8.0

func NewInitTrait() Trait

Jump to

Keyboard shortcuts

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