Documentation
¶
Overview ¶
Copyright 2020 The Knative Authors
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- func ConfigWatcherFromContext(ctx context.Context) configmap.Watcher
- func ContextWithMetricTag(ctx context.Context, metric *MetricTag) context.Context
- func GetConfigMapByPolling(ctx context.Context, name string) (cm *corev1.ConfigMap, err error)
- func GetSinkTimeout(logger *zap.SugaredLogger) int
- func HealthProbesDisabled(ctx context.Context) bool
- func IsConfigWatcherEnabled(ctx context.Context) bool
- func IsHAEnabled(ctx context.Context) bool
- func IsInjectorEnabled(ctx context.Context) bool
- func LeaderElectionComponentConfigToJSON(cfg *kle.ComponentConfig) (string, error)
- func Main(component string, ector EnvConfigConstructor, ctor AdapterConstructor)
- func MainMessageAdapter(component string, ector EnvConfigConstructor, ctor MessageAdapterConstructor)
- func MainMessageAdapterWithContext(ctx context.Context, component string, ector EnvConfigConstructor, ...)
- func MainWithContext(ctx context.Context, component string, ector EnvConfigConstructor, ...)
- func MainWithEnv(ctx context.Context, component string, env EnvConfigAccessor, ...)
- func MainWithInformers(ctx context.Context, component string, env EnvConfigAccessor, ...)
- func NamespaceFromContext(ctx context.Context) string
- func SetupConfigMapWatch(ctx context.Context, opts ...ConfigMapWatchOption) configmap.Watcher
- func SetupInformers(ctx context.Context, logger *zap.SugaredLogger) (context.Context, []controller.Informer)
- func SetupLoggerFromConfig(config *logging.Config, component string) (*zap.SugaredLogger, zap.AtomicLevel)
- func StartInformers(ctx context.Context, informers []controller.Informer)
- func WithConfigWatcher(ctx context.Context, cmw configmap.Watcher) context.Context
- func WithConfigWatcherEnabled(ctx context.Context) context.Context
- func WithConfiguratorOptions(ctx context.Context, opts []ConfiguratorOption) context.Context
- func WithController(ctx context.Context, ctor ControllerConstructor) context.Context
- func WithHAEnabled(ctx context.Context) context.Context
- func WithHealthProbesDisabled(ctx context.Context) context.Context
- func WithInjectorEnabled(ctx context.Context) context.Context
- func WithNamespace(ctx context.Context, namespace string) context.Context
- type Adapter
- type AdapterConfigurator
- type AdapterConstructor
- type Client
- func NewClient(cfg ClientConfig) (Client, error)
- func NewClientHTTPObserved(topt []http.Option, copt []ceclient.Option) (Client, error)
- func NewCloudEventsClient(target string, ceOverrides *duckv1.CloudEventOverrides, ...) (Client, error)
- func NewCloudEventsClientCRStatus(env EnvConfigAccessor, reporter source.StatsReporter, ...) (Client, error)
- func NewCloudEventsClientWithOptions(ceOverrides *duckv1.CloudEventOverrides, reporter source.StatsReporter, ...) (Client, error)
- type ClientConfig
- type CloudEventsStatusReporterConfigurator
- type CloudEventsStatusReporterConfiguratorFromConfigMapOption
- type ConfigMapWatchOption
- type ConfigMapWatchOptions
- type ConfiguratorOption
- func ConfiguratorOptionsFromContext(ctx context.Context) []ConfiguratorOption
- func WithCloudEventsStatusReporterConfigurator(c CloudEventsStatusReporterConfigurator) ConfiguratorOption
- func WithLoggerConfigurator(c LoggerConfigurator) ConfiguratorOption
- func WithObservabilityConfigurator(c ObservabilityConfigurator) ConfiguratorOption
- type ControllerConstructor
- type EnvConfig
- func (e *EnvConfig) GetAudience() *string
- func (e *EnvConfig) GetCACerts() *string
- func (e *EnvConfig) GetCloudEventOverrides() (*duckv1.CloudEventOverrides, error)
- func (e *EnvConfig) GetLeaderElectionConfig() (*kle.ComponentConfig, error)
- func (e *EnvConfig) GetLogger() *zap.SugaredLogger
- func (e *EnvConfig) GetName() string
- func (e *EnvConfig) GetNamespace() string
- func (e *EnvConfig) GetOIDCServiceAccountName() *types.NamespacedName
- func (e *EnvConfig) GetObservabilityConfig() (*observability.Config, error)
- func (e *EnvConfig) GetSink() string
- func (e *EnvConfig) GetSinktimeout() int
- func (e *EnvConfig) SetComponent(component string)
- type EnvConfigAccessor
- type EnvConfigConstructor
- type LoggerConfigurator
- type LoggerConfiguratorFromConfigMapOption
- type MessageAdapter
- type MessageAdapterConstructor
- type MetricTag
- type ObservabilityConfigurator
- type ObservabilityConfiguratorFromConfigMapOption
- type ProfilerConfigurator
Constants ¶
const ( EnvConfigComponent = "K_COMPONENT" EnvConfigNamespace = "NAMESPACE" EnvConfigName = "NAME" EnvConfigResourceGroup = "K_RESOURCE_GROUP" EnvConfigSink = "K_SINK" EnvConfigAudience = "K_AUDIENCE" EnvConfigOIDCServiceAccount = "K_OIDC_SERVICE_ACCOUNT" EnvConfigCACert = "K_CA_CERTS" EnvConfigCEOverrides = "K_CE_OVERRIDES" EnvConfigLoggingConfig = "K_LOGGING_CONFIG" EnvConfigObservabilityConfig = "K_OBSERVABILITY_CONFIG" EnvConfigLeaderElectionConfig = "K_LEADER_ELECTION_CONFIG" EnvSinkTimeout = "K_SINK_TIMEOUT" )
Variables ¶
This section is empty.
Functions ¶
func ConfigWatcherFromContext ¶ added in v0.31.0
ConfigWatcherFromContext retrieves a ConfigMap Watcher from the context.
func ContextWithMetricTag ¶
ContextWithMetricTag returns a copy of parent context in which the value associated with metric key is the supplied metric tag.
func GetConfigMapByPolling ¶ added in v0.31.0
GetConfigMapByPolling retrieves a ConfigMap. If an error other than NotFound is returned, the operation will be repeated each second up to 5 seconds. These timeout and retry interval are set by heuristics. e.g. istio sidecar needs a few seconds to configure the pod network.
The context is expected to be initialized with injection and namespace.
func GetSinkTimeout ¶ added in v0.18.1
func GetSinkTimeout(logger *zap.SugaredLogger) int
func HealthProbesDisabled ¶ added in v0.44.0
func IsConfigWatcherEnabled ¶ added in v0.31.0
IsConfigWatcherEnabled indicates whether the ConfigMapWatcher is required or not.
func IsHAEnabled ¶ added in v0.17.0
IsHAEnabled checks the context for the desire to enable leader elector.
func IsInjectorEnabled ¶ added in v0.17.0
IsInjectorEnabled checks the context for the desire to enable injectors TODO: deprecated.
func LeaderElectionComponentConfigToJSON ¶ added in v0.19.0
func LeaderElectionComponentConfigToJSON(cfg *kle.ComponentConfig) (string, error)
LeaderElectionComponentConfigToJSON converts a ComponentConfig to a json string.
func Main ¶
func Main(component string, ector EnvConfigConstructor, ctor AdapterConstructor)
func MainMessageAdapter ¶ added in v0.15.0
func MainMessageAdapter(component string, ector EnvConfigConstructor, ctor MessageAdapterConstructor)
func MainMessageAdapterWithContext ¶ added in v0.15.0
func MainMessageAdapterWithContext(ctx context.Context, component string, ector EnvConfigConstructor, ctor MessageAdapterConstructor)
func MainWithContext ¶
func MainWithContext(ctx context.Context, component string, ector EnvConfigConstructor, ctor AdapterConstructor)
func MainWithEnv ¶ added in v0.17.0
func MainWithEnv(ctx context.Context, component string, env EnvConfigAccessor, ctor AdapterConstructor)
func MainWithInformers ¶ added in v0.17.0
func MainWithInformers(ctx context.Context, component string, env EnvConfigAccessor, ctor AdapterConstructor)
func NamespaceFromContext ¶ added in v0.31.0
NamespaceFromContext gets the working namespace from the context
func SetupConfigMapWatch ¶ added in v0.31.0
func SetupConfigMapWatch(ctx context.Context, opts ...ConfigMapWatchOption) configmap.Watcher
SetupConfigMapWatch establishes a watch on a namespace's configmaps.
func SetupInformers ¶ added in v0.17.0
func SetupInformers(ctx context.Context, logger *zap.SugaredLogger) (context.Context, []controller.Informer)
func SetupLoggerFromConfig ¶ added in v0.31.0
func SetupLoggerFromConfig(config *logging.Config, component string) (*zap.SugaredLogger, zap.AtomicLevel)
SetupLoggerFromConfig sets up the logger using the provided config and returns a logger and atomic level, or dies by calling log.Fatalf.
func StartInformers ¶ added in v0.17.0
func StartInformers(ctx context.Context, informers []controller.Informer)
func WithConfigWatcher ¶ added in v0.31.0
WithConfigWatcher adds a ConfigMap Watcher informer to the context.
func WithConfigWatcherEnabled ¶ added in v0.31.0
WithConfigWatcherEnabled flags the ConfigMapWatcher to be configured.
func WithConfiguratorOptions ¶ added in v0.31.0
func WithConfiguratorOptions(ctx context.Context, opts []ConfiguratorOption) context.Context
WithConfiguratorOptions sets custom options on the adapter configurator.
func WithController ¶ added in v0.18.0
func WithController(ctx context.Context, ctor ControllerConstructor) context.Context
WithController signals to MainWithContext that it should create and configure a controller notifying the adapter when a resource is ready and removed
func WithHAEnabled ¶ added in v0.17.0
WithHAEnabled signals to MainWithContext that it should set up an appropriate leader elector for this component.
func WithHealthProbesDisabled ¶ added in v0.44.0
WithHealthProbesDisabled signals to MainWithContext that it should disable default probes (readiness and liveness).
func WithInjectorEnabled ¶ added in v0.17.0
WithInjectorEnabled signals to MainWithInjectors that it should try to run injectors. TODO: deprecated. Use WithController instead
Types ¶
type AdapterConfigurator ¶ added in v0.31.0
type AdapterConfigurator interface {
LoggerConfigurator
ObservabilityConfigurator
CloudEventsStatusReporterConfigurator
}
AdapterConfigurator exposes methods for configuring the adapter.
type AdapterConstructor ¶
type AdapterConstructor func(ctx context.Context, env EnvConfigAccessor, client cloudevents.Client) Adapter
type Client ¶ added in v0.38.0
type Client interface {
cloudevents.Client
// contains filtered or unexported methods
}
func NewClient ¶ added in v0.38.0
func NewClient(cfg ClientConfig) (Client, error)
func NewClientHTTPObserved ¶ added in v0.29.0
func NewCloudEventsClient ¶
func NewCloudEventsClient(target string, ceOverrides *duckv1.CloudEventOverrides, reporter source.StatsReporter) (Client, error)
NewCloudEventsClient returns a client that will apply the ceOverrides to outbound events and report outbound event counts.
func NewCloudEventsClientCRStatus ¶ added in v0.17.0
func NewCloudEventsClientCRStatus(env EnvConfigAccessor, reporter source.StatsReporter, crStatusEventClient *crstatusevent.CRStatusEventClient) (Client, error)
NewCloudEventsClientCRStatus returns a client CR status
func NewCloudEventsClientWithOptions ¶ added in v0.24.0
func NewCloudEventsClientWithOptions(ceOverrides *duckv1.CloudEventOverrides, reporter source.StatsReporter, opts ...http.Option) (Client, error)
NewCloudEventsClientWithOptions returns a client created with provided options
type ClientConfig ¶ added in v0.38.0
type ClientConfig struct {
Env EnvConfigAccessor
CeOverrides *duckv1.CloudEventOverrides
Reporter source.StatsReporter
CrStatusEventClient *crstatusevent.CRStatusEventClient
Options []http.Option
TokenProvider *auth.OIDCTokenProvider
MeterProvider metric.MeterProvider
TraceProvider trace.TracerProvider
TrustBundleConfigMapLister corev1listers.ConfigMapNamespaceLister
}
func GetClientConfig ¶ added in v0.38.0
func GetClientConfig(ctx context.Context) ClientConfig
type CloudEventsStatusReporterConfigurator ¶ added in v0.31.0
type CloudEventsStatusReporterConfigurator interface {
CreateCloudEventsStatusReporter(ctx context.Context) *crstatusevent.CRStatusEventClient
}
CloudEventsStatusReporterConfigurator configures the CloudEvents client reporting settings for an adapter.
func NewCloudEventsReporterConfiguratorFromConfigMap ¶ added in v0.31.0
func NewCloudEventsReporterConfiguratorFromConfigMap(opts ...CloudEventsStatusReporterConfiguratorFromConfigMapOption) CloudEventsStatusReporterConfigurator
NewCloudEventsReporterConfiguratorFromConfigMap returns a ConfigMap based CloudEvents status reporter configurator.
func NewCloudEventsStatusReporterConfiguratorFromEnvironment ¶ added in v0.31.0
func NewCloudEventsStatusReporterConfiguratorFromEnvironment(env EnvConfigAccessor) CloudEventsStatusReporterConfigurator
NewCloudEventsStatusReporterConfiguratorFromEnvironment returns an environment based CloudEvents status reporter configurator.
type CloudEventsStatusReporterConfiguratorFromConfigMapOption ¶ added in v0.31.0
type CloudEventsStatusReporterConfiguratorFromConfigMapOption func(*cloudEventsStatusReporterConfiguratorFromConfigMap)
CloudEventsStatusReporterConfiguratorFromConfigMapOption for teawking the CloudEvents status reporter configurator.
func WithCloudEventsStatusReporterConfiguratorConfigMapName ¶ added in v0.31.0
func WithCloudEventsStatusReporterConfiguratorConfigMapName(name string) CloudEventsStatusReporterConfiguratorFromConfigMapOption
WithCloudEventsStatusReporterConfiguratorConfigMapName sets the ConfigMap name for the CloudEvents status reporter configuration.
type ConfigMapWatchOption ¶ added in v0.31.0
type ConfigMapWatchOption func(*ConfigMapWatchOptions)
ConfigMapWatchOption modifies setup for a ConfigMap informer.
func ConfigMapWatchWithLabels ¶ added in v0.31.0
func ConfigMapWatchWithLabels(ls []labels.Requirement) ConfigMapWatchOption
ConfigMapWatchWithLabels sets the labels filter to be configured at the ConfigMap watcher informer.
type ConfigMapWatchOptions ¶ added in v0.31.0
type ConfigMapWatchOptions struct {
LabelsFilter []labels.Requirement
}
ConfigMapWatchOptions are the options that can be set for the ConfigMapWatch informer.
type ConfiguratorOption ¶ added in v0.31.0
type ConfiguratorOption func(*adapterConfigurator)
ConfiguratorOption enables customizing the adapter configuration.
func ConfiguratorOptionsFromContext ¶ added in v0.31.0
func ConfiguratorOptionsFromContext(ctx context.Context) []ConfiguratorOption
ConfiguratorOptionsFromContext retrieves adapter configurator options.
func WithCloudEventsStatusReporterConfigurator ¶ added in v0.31.0
func WithCloudEventsStatusReporterConfigurator(c CloudEventsStatusReporterConfigurator) ConfiguratorOption
WithCloudEventsStatusReporterConfigurator sets the adapter configurator with a CloudEvents status reporter option.
func WithLoggerConfigurator ¶ added in v0.31.0
func WithLoggerConfigurator(c LoggerConfigurator) ConfiguratorOption
WithLoggerConfigurator sets the adapter configurator with a custom logger option.
func WithObservabilityConfigurator ¶ added in v0.46.0
func WithObservabilityConfigurator(c ObservabilityConfigurator) ConfiguratorOption
type ControllerConstructor ¶ added in v0.18.0
type ControllerConstructor func(ctx context.Context, adapter Adapter) *controller.Impl
ControllerConstructor is the function signature for creating controllers synchronizing the multi-tenant receive adapter state
func ControllerFromContext ¶ added in v0.18.0
func ControllerFromContext(ctx context.Context) ControllerConstructor
ControllerFromContext gets the controller constructor from the context
type EnvConfig ¶
type EnvConfig struct {
// Component is the kind of this adapter.
Component string `envconfig:"K_COMPONENT"`
// Environment variable containing the namespace of the adapter.
Namespace string `envconfig:"NAMESPACE"`
// Environment variable containing the name of the adapter.
Name string `envconfig:"NAME" default:"adapter"`
// Environment variable containing the resource group of the adapter for metrics.
ResourceGroup string `envconfig:"K_RESOURCE_GROUP" default:"adapter.sources.knative.dev"`
// Sink is the URI messages will be sent.
Sink string `envconfig:"K_SINK"`
// Audience is the audience of the target sink.
Audience *string `envconfig:"K_AUDIENCE"`
// OIDCServiceAccount Name is the name of the service account to use for the adapter.
OIDCServiceAccountName *string `envconfig:"K_OIDC_SERVICE_ACCOUNT"`
// CACerts are the Certification Authority (CA) certificates in PEM format
// according to https://www.rfc-editor.org/rfc/rfc7468.
// +optional
CACerts *string `envconfig:"K_CA_CERTS"`
// CEOverrides are the CloudEvents overrides to be applied to the outbound event.
CEOverrides string `envconfig:"K_CE_OVERRIDES"`
// LoggingConfigJson is a json string of logging.Config.
// This is used to configure the logging config, the config is stored in
// a config map inside the controllers namespace and copied here.
LoggingConfigJson string `envconfig:"K_LOGGING_CONFIG" default:"{}"`
// ObservabilityConfigJson is a json string of observability.Config.
// This is used to configure the observability config, the config is stored in
// a config map inside the controllers namespace and copied here.
ObservabilityConfigJson string `envconfig:"K_OBSERVABILITY_CONFIG" default:"{}"`
// LeaderElectionConfigJson is the leader election component configuration.
LeaderElectionConfigJson string `envconfig:"K_LEADER_ELECTION_CONFIG"`
// Time in seconds to wait for sink to respond
EnvSinkTimeout string `envconfig:"K_SINK_TIMEOUT"`
// contains filtered or unexported fields
}
EnvConfig is the minimal set of configuration parameters source adapters should support.
func (*EnvConfig) GetAudience ¶ added in v0.40.0
func (*EnvConfig) GetCACerts ¶ added in v0.37.0
func (*EnvConfig) GetCloudEventOverrides ¶
func (e *EnvConfig) GetCloudEventOverrides() (*duckv1.CloudEventOverrides, error)
func (*EnvConfig) GetLeaderElectionConfig ¶ added in v0.16.0
func (e *EnvConfig) GetLeaderElectionConfig() (*kle.ComponentConfig, error)
func (*EnvConfig) GetLogger ¶
func (e *EnvConfig) GetLogger() *zap.SugaredLogger
func (*EnvConfig) GetNamespace ¶
func (*EnvConfig) GetOIDCServiceAccountName ¶ added in v0.40.0
func (e *EnvConfig) GetOIDCServiceAccountName() *types.NamespacedName
func (*EnvConfig) GetObservabilityConfig ¶ added in v0.46.0
func (e *EnvConfig) GetObservabilityConfig() (*observability.Config, error)
func (*EnvConfig) GetSinktimeout ¶ added in v0.18.1
func (*EnvConfig) SetComponent ¶
type EnvConfigAccessor ¶
type EnvConfigAccessor interface {
// Set the component name.
SetComponent(string)
// Get the URI where messages will be forwarded to.
GetSink() string
// GetCACerts gets the CACerts of the Sink.
GetCACerts() *string
// GetAudience gets the audience of the target sink.
GetAudience() *string
// GetOIDCServiceAccountName gets the service account name to use for the adapter.
GetOIDCServiceAccountName() *types.NamespacedName
// Get the namespace of the adapter.
GetNamespace() string
// Get the name of the adapter.
GetName() string
// Get the parsed logger.
GetLogger() *zap.SugaredLogger
GetCloudEventOverrides() (*duckv1.CloudEventOverrides, error)
GetObservabilityConfig() (*observability.Config, error)
// GetLeaderElectionConfig returns leader election configuration.
GetLeaderElectionConfig() (*kle.ComponentConfig, error)
// Get the timeout to apply on a request to a sink
GetSinktimeout() int
}
EnvConfigAccessor defines accessors for the minimal set of source adapter configuration parameters.
func ConstructEnvOrDie ¶ added in v0.17.0
func ConstructEnvOrDie(ector EnvConfigConstructor) EnvConfigAccessor
type EnvConfigConstructor ¶
type EnvConfigConstructor func() EnvConfigAccessor
type LoggerConfigurator ¶ added in v0.31.0
type LoggerConfigurator interface {
CreateLogger(ctx context.Context) *zap.SugaredLogger
}
LoggerConfigurator configures the logger for an adapter.
func NewLoggerConfiguratorFromConfigMap ¶ added in v0.31.0
func NewLoggerConfiguratorFromConfigMap(component string, opts ...LoggerConfiguratorFromConfigMapOption) LoggerConfigurator
NewLoggerConfiguratorFromConfigMap returns a ConfigMap based logger configurator.
func NewLoggerConfiguratorFromEnvironment ¶ added in v0.31.0
func NewLoggerConfiguratorFromEnvironment(env EnvConfigAccessor) LoggerConfigurator
NewLoggerConfiguratorFromEnvironment returns an environment based logger configurator.
type LoggerConfiguratorFromConfigMapOption ¶ added in v0.31.0
type LoggerConfiguratorFromConfigMapOption func(*loggerConfiguratorFromConfigMap)
LoggerConfiguratorFromConfigMapOption for teawking the logger configurator.
func WithLoggerConfiguratorConfigMapName ¶ added in v0.31.0
func WithLoggerConfiguratorConfigMapName(name string) LoggerConfiguratorFromConfigMapOption
WithLoggerConfiguratorConfigMapName sets the ConfigMap name for the logger configuration.
type MessageAdapter ¶ added in v0.15.0
type MessageAdapterConstructor ¶ added in v0.15.0
type MessageAdapterConstructor func(ctx context.Context, env EnvConfigAccessor, sink duckv1.Addressable, reporter source.StatsReporter) MessageAdapter
type MetricTag ¶
MetricTag context
func MetricTagFromContext ¶
MetricTagFromContext returns the metric tag stored in context. Returns nil if no metric tag is set in context, or if the stored value is not of correct type.
type ObservabilityConfigurator ¶ added in v0.31.0
type ObservabilityConfigurator interface {
SetupObservabilityOrDie(ctx context.Context, component string, logger *zap.SugaredLogger, pprof *k8sruntime.ProfilingServer) (metric.MeterProvider, trace.TracerProvider)
}
ObservabilityConfigurator groups the observability related methods that configure an adapter.
func NewObservabilityConfiguratorFromConfigMap ¶ added in v0.46.0
func NewObservabilityConfiguratorFromConfigMap(opts ...ObservabilityConfiguratorFromConfigMapOption) ObservabilityConfigurator
func NewObservabilityConfiguratorFromEnvironment ¶ added in v0.46.0
func NewObservabilityConfiguratorFromEnvironment(env EnvConfigAccessor) ObservabilityConfigurator
type ObservabilityConfiguratorFromConfigMapOption ¶ added in v0.46.0
type ObservabilityConfiguratorFromConfigMapOption func(*observabilityConfiguratorFromConfigMap)
func WithObservabilityConfiguratorConfigMapName ¶ added in v0.46.0
func WithObservabilityConfiguratorConfigMapName(name string) ObservabilityConfiguratorFromConfigMapOption