Documentation ¶
Overview ¶
Package common contains reconciliation helpers shared between target reconcilers.
Index ¶
- Constants
- Variables
- func ComponentName(o kmeta.OwnerRefable) string
- func CreateCloudEventAttributes(source string, eventTypes []string) []duckv1.CloudEventAttributes
- func EnqueueObjectsInNamespaceOf(inf cache.SharedInformer, resyncFn filteredGlobalResyncFunc, ...) func(interface{})
- func GetStatefulBridgeID(object metav1.Object) string
- func MTAdapterObjectName(o kmeta.OwnerRefable) string
- func MaybeAppendValueFromEnvVar(envs []corev1.EnvVar, key string, valueFrom v1alpha1.ValueFromField) []corev1.EnvVar
- func NewAdapterDeployment(rcl v1alpha1.Reconcilable, sinkURI *apis.URL, opts ...resource.ObjectOption) *appsv1.Deployment
- func NewAdapterKnService(rcl v1alpha1.Reconcilable, sinkURI *apis.URL, opts ...resource.ObjectOption) *servingv1.Service
- func NewMTAdapterDeployment(rcl v1alpha1.Reconcilable, opts ...resource.ObjectOption) *appsv1.Deployment
- func NewMTAdapterKnService(rcl v1alpha1.Reconcilable, opts ...resource.ObjectOption) *servingv1.Service
- func OwnByServiceAccount(obj metav1.Object, owner *corev1.ServiceAccount)
- func ServiceAccountName(rcl v1alpha1.Reconcilable) string
- func TMCommonObjectLabels(o kmeta.OwnerRefable) labels.Set
- type AdapterBuilder
- type GenericDeploymentReconciler
- type GenericRBACReconciler
- type GenericServiceReconciler
- func NewGenericServiceReconciler[T kmeta.OwnerRefable, L Lister[T]](ctx context.Context, gvk schema.GroupVersionKind, tracker tracker.Interface, ...) GenericServiceReconciler[T, L]
- func NewMTGenericServiceReconciler[T kmeta.OwnerRefable, L Lister[T]](ctx context.Context, typ kmeta.OwnerRefable, tracker tracker.Interface, ...) GenericServiceReconciler[T, L]
- type Lister
- type ListerGetter
Constants ¶
const ( EnvName = "NAME" EnvNamespace = "NAMESPACE" // Overrides for CloudEvents context attributes (only supported by a subset of components) EnvCESource = "CE_SOURCE" EnvCEType = "CE_TYPE" // Common AWS attributes EnvARN = "ARN" EnvAccessKeyID = "AWS_ACCESS_KEY_ID" EnvSecretAccessKey = "AWS_SECRET_ACCESS_KEY" //nolint:gosec EnvSessionToken = "AWS_SESSION_TOKEN" EnvEndpointURL = "AWS_ENDPOINT_URL" EnvAssumeIamRole = "AWS_ASSUME_ROLE_ARN" // Common Azure attributes EnvAADTenantID = "AZURE_TENANT_ID" EnvAADClientID = "AZURE_CLIENT_ID" EnvAADClientSecret = "AZURE_CLIENT_SECRET" // Azure Event Hub attributes // https://pkg.go.dev/github.com/Azure/azure-event-hubs-go/v3#readme-environment-variables EnvHubNamespace = "EVENTHUB_NAMESPACE" EnvHubName = "EVENTHUB_NAME" EnvHubKeyName = "EVENTHUB_KEY_NAME" EnvHubKeyValue = "EVENTHUB_KEY_VALUE" EnvHubConnStr = "EVENTHUB_CONNECTION_STRING" EnvHubResourceID = "EVENTHUB_RESOURCE_ID" EnvHubConsumerGroup = "EVENTHUB_CONSUMER_GROUP" EnvHubMessageTimeout = "EVENTHUB_MESSAGE_TIMEOUT" EnvHubMessageCountSize = "EVENTHUB_MESSAGE_COUNT_SIZE" // Azure Service Bus attributes EnvServiceBusKeyName = "SERVICEBUS_KEY_NAME" EnvServiceBusKeyValue = "SERVICEBUS_KEY_VALUE" EnvServiceBusConnStr = "SERVICEBUS_CONNECTION_STRING" EnvServiceBusEntityResourceID = "SERVICEBUS_ENTITY_RESOURCE_ID" EnvServiceBusWebSocketsEnable = "SERVICEBUS_WEBSOCKETS_ENABLE" EnvServiceBusMaxConcurrent = "SERVICEBUS_MAX_CONCURRENT" // Common Google Cloud attributes EnvGCloudSAKey = "GCLOUD_SERVICEACCOUNT_KEY" // Google Cloud Pub/Sub attributes EnvGCloudPubSubSubscription = "GCLOUD_PUBSUB_SUBSCRIPTION" )
Common environment variables propagated to adapters.
const ( // ReasonRBACCreate indicates that an RBAC object was successfully created. ReasonRBACCreate = "CreateRBAC" // ReasonRBACUpdate indicates that an RBAC object was successfully updated. ReasonRBACUpdate = "UpdateRBAC" // ReasonFailedRBACCreate indicates that the creation of an RBAC object failed. ReasonFailedRBACCreate = "FailedRBACCreate" // ReasonFailedRBACUpdate indicates that the update of an RBAC object failed. ReasonFailedRBACUpdate = "FailedRBACUpdate" // ReasonAdapterCreate indicates that an adapter object was successfully created. ReasonAdapterCreate = "CreateAdapter" // ReasonAdapterUpdate indicates that an adapter object was successfully updated. ReasonAdapterUpdate = "UpdateAdapter" // ReasonFailedAdapterCreate indicates that the creation of an adapter object failed. ReasonFailedAdapterCreate = "FailedAdapterCreate" // ReasonFailedAdapterUpdate indicates that the update of an adapter object failed. ReasonFailedAdapterUpdate = "FailedAdapterUpdate" // ReasonBadSinkURI indicates that the URI of a sink can't be determined. ReasonBadSinkURI = "BadSinkURI" // ReasonInvalidSpec indicates that spec of a reconciled object is invalid. ReasonInvalidSpec = "InvalidSpec" )
Reasons for API Events
const ( LabelBridgeUsedByPrefix = "flow.triggermesh.io/used-by." LabelValueBridgeDominant = "dominant" // Bridge identifier for stateful flows EnvBridgeID = "EVENTS_BRIDGE_IDENTIFIER" )
Stateful events related
Variables ¶
var CommonObjectLabels = TMCommonObjectLabels
CommonObjectLabels set of labels which are always applied to resource objects reconciled for the given component type.
Functions ¶
func ComponentName ¶
func ComponentName(o kmeta.OwnerRefable) string
ComponentName returns the component name for the given object.
func CreateCloudEventAttributes ¶
func CreateCloudEventAttributes(source string, eventTypes []string) []duckv1.CloudEventAttributes
CreateCloudEventAttributes returns CloudEvent attributes for the event types supported by the target.
func EnqueueObjectsInNamespaceOf ¶
func EnqueueObjectsInNamespaceOf(inf cache.SharedInformer, resyncFn filteredGlobalResyncFunc, logger *zap.SugaredLogger) func(interface{})
EnqueueObjectsInNamespaceOf accepts an object and triggers a global resync of all objects in the given informer matching that object's namespace. Intended to be used to resync objects when the state of their (common) multi-tenant adapter changes.
func GetStatefulBridgeID ¶
GetStatefulBridgeID returns the BridgeID based on an object metadata.
All bridge components controlled by Triggerflow have labels informing their relation with the bridges they are part of. A component can only have one dominant bridge, which is the one it synchronizes with. This function uses that label to retrieve the bridge name and use it as unique ID.
func MTAdapterObjectName ¶
func MTAdapterObjectName(o kmeta.OwnerRefable) string
MTAdapterObjectName returns a unique name to apply to all objects related to the given component's multi-tenant adapter (RBAC, Deployment/KnService, ...).
func MaybeAppendValueFromEnvVar ¶
func MaybeAppendValueFromEnvVar(envs []corev1.EnvVar, key string, valueFrom v1alpha1.ValueFromField) []corev1.EnvVar
MaybeAppendValueFromEnvVar conditionally appends an EnvVar to env based on the contents of valueFrom. ValueFromSecret takes precedence over Value in case the API didn't reject the object despite the CRD's schema validation
func NewAdapterDeployment ¶
func NewAdapterDeployment(rcl v1alpha1.Reconcilable, sinkURI *apis.URL, opts ...resource.ObjectOption) *appsv1.Deployment
NewAdapterDeployment is a wrapper around resource.NewDeployment which pre-populates attributes common to all adapters backed by a Deployment.
func NewAdapterKnService ¶
func NewAdapterKnService(rcl v1alpha1.Reconcilable, sinkURI *apis.URL, opts ...resource.ObjectOption) *servingv1.Service
NewAdapterKnService is a wrapper around resource.NewKnService which pre-populates attributes common to all adapters backed by a Knative Service.
func NewMTAdapterDeployment ¶
func NewMTAdapterDeployment(rcl v1alpha1.Reconcilable, opts ...resource.ObjectOption) *appsv1.Deployment
NewMTAdapterDeployment is a wrapper around resource.NewDeployment which pre-populates attributes common to all multi-tenant adapters backed by a Deployment.
func NewMTAdapterKnService ¶
func NewMTAdapterKnService(rcl v1alpha1.Reconcilable, opts ...resource.ObjectOption) *servingv1.Service
NewMTAdapterKnService is a wrapper around resource.NewKnService which pre-populates attributes common to all multi-tenant adapters backed by a Knative Service.
func OwnByServiceAccount ¶
func OwnByServiceAccount(obj metav1.Object, owner *corev1.ServiceAccount)
OwnByServiceAccount sets the owner of obj to the given ServiceAccount.
func ServiceAccountName ¶
func ServiceAccountName(rcl v1alpha1.Reconcilable) string
ServiceAccountName returns the name to set on the ServiceAccount associated with the given component instance.
func TMCommonObjectLabels ¶ added in v1.21.0
func TMCommonObjectLabels(o kmeta.OwnerRefable) labels.Set
TMCommonObjectLabels returns a set of labels which are always applied to TriggerMesh objects reconciled for the given component type.
Types ¶
type AdapterBuilder ¶ added in v1.18.0
type AdapterBuilder[T metav1.Object] interface { BuildAdapter(rcl v1alpha1.Reconcilable, sinkURI *apis.URL) (T, error) }
AdapterBuilder provides all the necessary information for building a component's adapter object.
type GenericDeploymentReconciler ¶
type GenericDeploymentReconciler[T kmeta.OwnerRefable, L Lister[T]] struct { // URI resolver for sinks SinkResolver *resolver.URIResolver // API clients Client k8sClientGetter[*appsv1.Deployment, appsclientv1.DeploymentInterface] // objects listers Lister func(namespace string) appslistersv1.DeploymentNamespaceLister PodLister func(namespace string) corelistersv1.PodNamespaceLister *GenericRBACReconciler[T, L] }
GenericDeploymentReconciler contains interfaces shared across Deployment reconcilers.
func NewGenericDeploymentReconciler ¶
func NewGenericDeploymentReconciler[T kmeta.OwnerRefable, L Lister[T]](ctx context.Context, gvk schema.GroupVersionKind, tracker tracker.Interface, adapterHandlerFn func(obj interface{}), ownersLister ListerGetter[T, L], ) GenericDeploymentReconciler[T, L]
NewGenericDeploymentReconciler creates a new GenericDeploymentReconciler and attaches a default event handler to its Deployment informer.
func (*GenericDeploymentReconciler[T, L]) ReconcileAdapter ¶
func (r *GenericDeploymentReconciler[T, L]) ReconcileAdapter(ctx context.Context, ab AdapterBuilder[*appsv1.Deployment]) reconciler.Event
ReconcileAdapter reconciles a receive adapter for a component instance.
type GenericRBACReconciler ¶
type GenericRBACReconciler[T kmeta.OwnerRefable, L Lister[T]] struct { // API clients SAClient func(namespace string) coreclientv1.ServiceAccountInterface RBClient func(namespace string) rbacclientv1.RoleBindingInterface // objects listers SALister func(namespace string) corelistersv1.ServiceAccountNamespaceLister RBLister func(namespace string) rbaclistersv1.RoleBindingNamespaceLister OwnersLister ListerGetter[T, L] }
GenericRBACReconciler reconciles RBAC objects for components adapters.
func NewGenericRBACReconciler ¶
func NewGenericRBACReconciler[T kmeta.OwnerRefable, L Lister[T]](ctx context.Context, ownersLister ListerGetter[T, L], ) *GenericRBACReconciler[T, L]
NewGenericRBACReconciler creates a new GenericRBACReconciler.
type GenericServiceReconciler ¶
type GenericServiceReconciler[T kmeta.OwnerRefable, L Lister[T]] struct { // URI resolver for sinks SinkResolver *resolver.URIResolver // API clients Client k8sClientGetter[*servingv1.Service, servingclientv1.ServiceInterface] // objects listers Lister func(namespace string) servinglistersv1.ServiceNamespaceLister *GenericRBACReconciler[T, L] }
GenericServiceReconciler contains interfaces shared across Service reconcilers.
func NewGenericServiceReconciler ¶
func NewGenericServiceReconciler[T kmeta.OwnerRefable, L Lister[T]](ctx context.Context, gvk schema.GroupVersionKind, tracker tracker.Interface, adapterHandlerFn func(obj interface{}), ownersLister ListerGetter[T, L], ) GenericServiceReconciler[T, L]
NewGenericServiceReconciler creates a new GenericServiceReconciler and attaches a default event handler to its Service informer.
func NewMTGenericServiceReconciler ¶
func NewMTGenericServiceReconciler[T kmeta.OwnerRefable, L Lister[T]](ctx context.Context, typ kmeta.OwnerRefable, tracker tracker.Interface, adapterHandlerFn func(obj interface{}), ownersLister ListerGetter[T, L], ) GenericServiceReconciler[T, L]
NewMTGenericServiceReconciler creates a new GenericServiceReconciler for a multi-tenant adapter and attaches a default event handler to its Service informer.
func (*GenericServiceReconciler[T, L]) ReconcileAdapter ¶
func (r *GenericServiceReconciler[T, L]) ReconcileAdapter(ctx context.Context, ab AdapterBuilder[*servingv1.Service]) reconciler.Event
ReconcileAdapter reconciles a receive adapter for a component instance.
type Lister ¶ added in v1.17.0
type Lister[T kmeta.OwnerRefable] interface { List(labels.Selector) ([]T, error) }
Lister is a partial generic version of a typed <Kind>NamespaceLister interface (usually generated by lister-gen).
type ListerGetter ¶ added in v1.17.0
type ListerGetter[T kmeta.OwnerRefable, L Lister[T]] func(namespace string) L
ListerGetter obtains a namespaced Lister.
We deliberately use the signature func[T, L Lister[T]] func(namespace string) L instead of func[T] func(namespace string) Lister[T] Although both are functionally equivalent, the second form doesn't allow us to instantiate GenericRBACReconciler structs directly using the typed <Kind>NamespaceLister interfaces generated by lister-gen. Attempting to do so yields the following compiler error: cannot use informer.Lister().<Kind> (value of type func(namespace string) v1alpha1.<Kind>NamespaceLister) as type ListerGetter[*v1alpha1.<Kind>] Callers can circumvent this limitation by wrapping a typed lister getter inside a function to make it generic: func(namespace string) common.Lister[*v1alpha1.<Kind>] { return informer.Lister().<Kind>(namespace) } but this places the burden on the caller instead of on the compiler, which is suboptimal. With the first form, however, <Kind>NamespaceLister interfaces are handled as generic types without requiring an explicit conversion by the caller.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package event contains functions for generating Kubernetes API events.
|
Package event contains functions for generating Kubernetes API events. |
Package resource contains helpers to generate Kubernetes API objects.
|
Package resource contains helpers to generate Kubernetes API objects. |
Package skip allows a Context to carry the intention to skip parts of the code execution.
|
Package skip allows a Context to carry the intention to skip parts of the code execution. |
Package testing contains test helpers for reconcilers.
|
Package testing contains test helpers for reconcilers. |