Documentation ¶
Index ¶
- Constants
- func PerformUpdate(ctx context.Context, logger logr.Logger, client AdminAPIClient, config Config, ...) ([]byte, error)
- type AdminAPIClient
- type Config
- type ConfigError
- type ConfigErrorFields
- type ConfigService
- type ConfigurationChangeDetector
- type ConsumerGroupConsumerRelationship
- type ContentToDBLessConfigConverter
- type ContentWithHash
- type CustomEntitiesByType
- type DBLessConfig
- type DefaultConfigurationChangeDetector
- type DefaultContentToDBLessConfigConverter
- type DefaultUpdateStrategyResolver
- type FlatEntityError
- type FlatError
- type FlatErrorType
- type InMemoryClient
- type KonnectAwareClient
- type ResourceError
- type ResponseParsingError
- type StatusClient
- type UpdateClient
- type UpdateClientWithBackoff
- type UpdateError
- type UpdateSkippedDueToBackoffStrategyError
- type UpdateStrategy
- type UpdateStrategyDBMode
- func (s *UpdateStrategyDBMode) HandleEvents(ctx context.Context, events chan diff.EntityAction, ...)
- func (s *UpdateStrategyDBMode) MetricsProtocol() metrics.Protocol
- func (s *UpdateStrategyDBMode) Type() string
- func (s *UpdateStrategyDBMode) Update(ctx context.Context, targetContent ContentWithHash) (mo.Option[int], error)
- type UpdateStrategyInMemory
- type UpdateStrategyResolver
- type UpdateStrategyWithBackoff
Constants ¶
const (
// WellKnownInitialHash is the hash of an empty configuration.
WellKnownInitialHash = "00000000000000000000000000000000"
)
Variables ¶
This section is empty.
Functions ¶
func PerformUpdate ¶
func PerformUpdate( ctx context.Context, logger logr.Logger, client AdminAPIClient, config Config, targetContent *file.Content, customEntities CustomEntitiesByType, promMetrics metrics.Recorder, updateStrategyResolver UpdateStrategyResolver, configChangeDetector ConfigurationChangeDetector, diagnostic *diagnostics.ClientDiagnostic, isFallback bool, ) ([]byte, error)
PerformUpdate writes `targetContent` to Kong Admin API specified by `kongConfig`.
Types ¶
type AdminAPIClient ¶
type Config ¶
type Config struct { // Currently, this assumes that all underlying clients are using the same version // hence this shared field in here. Version semver.Version // InMemory tells whether a Kong Gateway Admin APIs should be communicated in DB-less mode. // It's not relevant for Konnect client. InMemory bool // Concurrency defines how many concurrent goroutines should be used when syncing configuration in DB-mode. Concurrency int // FilterTags are tags used to manage and filter entities in Kong. FilterTags []string // SkipCACertificates disables CA certificates, to avoid fighting over configuration in multi-workspace // environments. See https://github.com/Kong/deck/pull/617 SkipCACertificates bool // EnableReverseSync indicates that reverse sync should be enabled for // updates to the data-plane. EnableReverseSync bool // ExpressionRoutes indicates whether to use Kong's expression routes. ExpressionRoutes bool // SanitizeKonnectConfigDumps indicates whether to sanitize Konnect config dumps. SanitizeKonnectConfigDumps bool // FallbackConfiguration indicates whether to generate fallback configuration in the case of entity // errors returned by the Kong Admin API. FallbackConfiguration bool // UseLastValidConfigForFallback indicates whether to use the last valid config cache to backfill broken objects // when recovering from a config push failure. UseLastValidConfigForFallback bool }
Config gathers parameters that are needed for sending configuration to Kong Admin APIs.
type ConfigError ¶
type ConfigError struct { Code int `json:"code,omitempty" yaml:"code,omitempty"` Flattened []FlatEntityError `json:"flattened_errors,omitempty" yaml:"flattened_errors,omitempty"` Message string `json:"message,omitempty" yaml:"message,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty"` }
ConfigError is an error response from Kong's DB-less /config endpoint.
type ConfigErrorFields ¶
type ConfigErrorFields struct{}
ConfigErrorFields is the structure under the "fields" key in a /config error response.
type ConfigService ¶
type ConfigurationChangeDetector ¶
type ConfigurationChangeDetector interface { // HasConfigurationChanged verifies whether configuration has changed by comparing // old and new config's SHAs. // In case the SHAs are equal, it still can return true if a client is considered // crashed or just booted up based on its status. // In case the status indicates an empty config and the desired config is also empty // this will return false to prevent continuously sending empty configuration to Gateway. HasConfigurationChanged( ctx context.Context, oldSHA, newSHA []byte, targetConfig *file.Content, client KonnectAwareClient, statusClient StatusClient, ) (bool, error) }
type ConsumerGroupConsumerRelationship ¶
type ConsumerGroupConsumerRelationship struct { ConsumerGroup string `json:"consumer_group"` Consumer string `json:"consumer"` }
ConsumerGroupConsumerRelationship is a relationship between a ConsumerGroup and a Consumer.
type ContentToDBLessConfigConverter ¶
type ContentToDBLessConfigConverter interface { // Convert converts a decK's file.Content to a DBLessConfig. // Implementations are allowed to modify the input *file.Content. Make sure it's copied beforehand if needed. Convert(content *file.Content) DBLessConfig }
type ContentWithHash ¶
type ContentWithHash struct { Content *file.Content CustomEntities CustomEntitiesByType Hash []byte }
ContentWithHash encapsulates file.Content along with its precalculated hash.
type CustomEntitiesByType ¶ added in v3.2.0
CustomEntitiesByType stores all custom entities by types. The key is the type of the entity, and the corresponding slice stores the sorted list of custom entities with that type.
type DBLessConfig ¶
type DBLessConfig struct { file.Content ConsumerGroupConsumerRelationships []ConsumerGroupConsumerRelationship `json:"consumer_group_consumers,omitempty"` }
DBLessConfig is the configuration that is sent to Kong's data-plane via its `POST /config` endpoint after being marshalled to JSON. It uses file.Content as its base schema, but it also includes additional fields that are not part of decK's schema.
type DefaultConfigurationChangeDetector ¶
type DefaultConfigurationChangeDetector struct {
// contains filtered or unexported fields
}
func NewDefaultConfigurationChangeDetector ¶
func NewDefaultConfigurationChangeDetector(logger logr.Logger) *DefaultConfigurationChangeDetector
func (*DefaultConfigurationChangeDetector) HasConfigurationChanged ¶
func (d *DefaultConfigurationChangeDetector) HasConfigurationChanged( ctx context.Context, oldSHA, newSHA []byte, targetConfig *file.Content, client KonnectAwareClient, statusClient StatusClient, ) (bool, error)
type DefaultContentToDBLessConfigConverter ¶
type DefaultContentToDBLessConfigConverter struct{}
func (DefaultContentToDBLessConfigConverter) Convert ¶
func (DefaultContentToDBLessConfigConverter) Convert(content *file.Content) DBLessConfig
type DefaultUpdateStrategyResolver ¶
type DefaultUpdateStrategyResolver struct {
// contains filtered or unexported fields
}
func NewDefaultUpdateStrategyResolver ¶
func NewDefaultUpdateStrategyResolver(config Config, logger logr.Logger) DefaultUpdateStrategyResolver
func (DefaultUpdateStrategyResolver) ResolveUpdateStrategy ¶
func (r DefaultUpdateStrategyResolver) ResolveUpdateStrategy( client UpdateClient, diagnostic *diagnostics.ClientDiagnostic, ) UpdateStrategy
ResolveUpdateStrategy returns an UpdateStrategy based on the client and configuration. The UpdateStrategy can be either UpdateStrategyDBMode or UpdateStrategyInMemory. Both of them implement different ways to populate Kong instances with data-plane configuration. If the client implements UpdateClientWithBackoff interface, its strategy will be decorated with the backoff strategy it provides.
type FlatEntityError ¶
type FlatEntityError struct { // Name is the name of the Kong entity. Name string `json:"entity_name,omitempty" yaml:"entity_name,omitempty"` // ID is the ID of the Kong entity. ID string `json:"entity_id,omitempty" yaml:"entity_id,omitempty"` // Tags are the tags of the Kong entity. Tags []string `json:"entity_tags,omitempty" yaml:"entity_tags,omitempty"` // Type is the type of the Kong entity. Type string `json:"entity_type,omitempty" yaml:"entity_type,omitempty"` // Errors are the errors associated with the Kong entity. Errors []FlatError `json:"errors,omitempty" yaml:"errors,omitempty"` }
FlatEntityError represents a single Kong entity with one or more invalid fields.
type FlatError ¶
type FlatError struct { // Field is the name of the entity's field that has an error. // Optional: Field can be empty if the error is associated with the whole entity. Field string `json:"field,omitempty" yaml:"field,omitempty"` // Message is the error associated with Field (for single-value fields) or with a whole entity when Type is "entity". Message string `json:"message,omitempty" yaml:"message,omitempty"` // Messages are the errors associated with Field for multi-value fields. The array index in Messages matches the // array index in the input. Messages []string `json:"messages,omitempty" yaml:"messages,omitempty"` // Type tells whether the error is associated with a single field or a whole entity. Type FlatErrorType `json:"type,omitempty" yaml:"type,omitempty"` }
FlatError represents an error for a single field within a Kong entity or a whole entity.
type FlatErrorType ¶
type FlatErrorType string
FlatErrorType tells whether a FlatError is associated with a single field or a whole entity.
const ( // FlatErrorTypeField is an error associated with a single field. FlatErrorTypeField FlatErrorType = "field" // FlatErrorTypeEntity is an error associated with a whole entity. FlatErrorTypeEntity FlatErrorType = "entity" )
type InMemoryClient ¶
type KonnectAwareClient ¶
type KonnectAwareClient interface {
IsKonnect() bool
}
type ResourceError ¶
type ResourceError struct { Name string Namespace string Kind string APIVersion string UID string Problems map[string]string }
ResourceError is a Kong configuration error associated with a Kubernetes resource.
type ResponseParsingError ¶ added in v3.2.0
type ResponseParsingError struct {
// contains filtered or unexported fields
}
ResponseParsingError is an error type that is returned when the response from Kong is not in the expected format.
func NewResponseParsingError ¶ added in v3.2.0
func NewResponseParsingError(responseBody []byte) ResponseParsingError
func (ResponseParsingError) Error ¶ added in v3.2.0
func (e ResponseParsingError) Error() string
Error implements the Error interface.
func (ResponseParsingError) ResponseBody ¶ added in v3.2.0
func (e ResponseParsingError) ResponseBody() []byte
ResponseBody returns the raw HTTP response body from Kong that could not be parsed.
type UpdateClient ¶
type UpdateClientWithBackoff ¶
type UpdateClientWithBackoff interface { UpdateClient BackoffStrategy() adminapi.UpdateBackoffStrategy }
type UpdateError ¶ added in v3.2.0
type UpdateError struct {
// contains filtered or unexported fields
}
UpdateError wraps several pieces of error information relevant to a failed Kong update attempt.
func NewUpdateErrorWithResponseBody ¶ added in v3.2.0
func NewUpdateErrorWithResponseBody( rawResponseBody []byte, configSize mo.Option[int], resourceFailures []failures.ResourceFailure, err error, ) UpdateError
func NewUpdateErrorWithoutResponseBody ¶ added in v3.4.0
func NewUpdateErrorWithoutResponseBody(resourceFailures []failures.ResourceFailure, err error) UpdateError
func (UpdateError) ConfigSize ¶ added in v3.4.0
func (e UpdateError) ConfigSize() mo.Option[int]
ConfigSize returns the size of the configuration that was attempted to be sent to Kong. When it's not applicable, returned option type contains mo.None.
func (UpdateError) Error ¶ added in v3.2.0
func (e UpdateError) Error() string
Error implements the Error interface. It returns the string value of the err field.
func (UpdateError) RawResponseBody ¶ added in v3.2.0
func (e UpdateError) RawResponseBody() []byte
RawResponseBody returns the raw HTTP response body from Kong for the failed update if it was captured.
func (UpdateError) ResourceFailures ¶ added in v3.2.0
func (e UpdateError) ResourceFailures() []failures.ResourceFailure
ResourceFailures returns per-resource failures from a Kong configuration update attempt.
func (UpdateError) Unwrap ¶ added in v3.2.0
func (e UpdateError) Unwrap() error
type UpdateSkippedDueToBackoffStrategyError ¶
type UpdateSkippedDueToBackoffStrategyError struct {
// contains filtered or unexported fields
}
func NewUpdateSkippedDueToBackoffStrategyError ¶
func NewUpdateSkippedDueToBackoffStrategyError(explanation string) UpdateSkippedDueToBackoffStrategyError
func (UpdateSkippedDueToBackoffStrategyError) Error ¶
func (e UpdateSkippedDueToBackoffStrategyError) Error() string
type UpdateStrategy ¶
type UpdateStrategy interface { // Update applies targetConfig to the DataPlane. When the update is successful, it returns the number of // bytes sent to the DataPlane or mo.None when it's impossible to determine the number of bytes sent e.g. // for dbmode (deck) strategy. Update(ctx context.Context, targetContent ContentWithHash) (mo.Option[int], error) // MetricsProtocol returns a string describing the update strategy type to be used in metrics. MetricsProtocol() metrics.Protocol // Type returns a human-readable debug string representing the UpdateStrategy. Type() string }
UpdateStrategy is the way we approach updating data-plane's configuration, depending on its type.
type UpdateStrategyDBMode ¶
type UpdateStrategyDBMode struct {
// contains filtered or unexported fields
}
UpdateStrategyDBMode implements the UpdateStrategy interface. It updates Kong's data-plane configuration using decK's syncer.
func NewUpdateStrategyDBMode ¶
func NewUpdateStrategyDBMode( client *kong.Client, dumpConfig dump.Config, version semver.Version, concurrency int, diagnostic *diagnostics.ClientDiagnostic, logger logr.Logger, ) *UpdateStrategyDBMode
func NewUpdateStrategyDBModeKonnect ¶
func NewUpdateStrategyDBModeKonnect( client *kong.Client, dumpConfig dump.Config, version semver.Version, concurrency int, diagnostic *diagnostics.ClientDiagnostic, logger logr.Logger, ) *UpdateStrategyDBMode
func (*UpdateStrategyDBMode) HandleEvents ¶ added in v3.2.0
func (s *UpdateStrategyDBMode) HandleEvents( ctx context.Context, events chan diff.EntityAction, diagnostic *diagnostics.ClientDiagnostic, hash string, )
HandleEvents handles logging and error reporting for individual entity change events generated during a sync by looping over an event channel. It terminates when its context dies.
func (*UpdateStrategyDBMode) MetricsProtocol ¶
func (s *UpdateStrategyDBMode) MetricsProtocol() metrics.Protocol
func (*UpdateStrategyDBMode) Type ¶
func (s *UpdateStrategyDBMode) Type() string
func (*UpdateStrategyDBMode) Update ¶
func (s *UpdateStrategyDBMode) Update(ctx context.Context, targetContent ContentWithHash) (mo.Option[int], error)
type UpdateStrategyInMemory ¶
type UpdateStrategyInMemory struct {
// contains filtered or unexported fields
}
UpdateStrategyInMemory implements the UpdateStrategy interface. It updates Kong's data-plane configuration using its `POST /config` endpoint that is used by ConfigService.ReloadDeclarativeRawConfig.
func NewUpdateStrategyInMemory ¶
func NewUpdateStrategyInMemory( configService ConfigService, configConverter ContentToDBLessConfigConverter, logger logr.Logger, ) UpdateStrategyInMemory
func (UpdateStrategyInMemory) MetricsProtocol ¶
func (s UpdateStrategyInMemory) MetricsProtocol() metrics.Protocol
func (UpdateStrategyInMemory) Type ¶
func (s UpdateStrategyInMemory) Type() string
func (UpdateStrategyInMemory) Update ¶
func (s UpdateStrategyInMemory) Update(ctx context.Context, targetState ContentWithHash) (mo.Option[int], error)
type UpdateStrategyResolver ¶
type UpdateStrategyResolver interface {
ResolveUpdateStrategy(client UpdateClient, diagnostic *diagnostics.ClientDiagnostic) UpdateStrategy
}
type UpdateStrategyWithBackoff ¶
type UpdateStrategyWithBackoff struct {
// contains filtered or unexported fields
}
UpdateStrategyWithBackoff decorates any UpdateStrategy to respect a passed adminapi.UpdateBackoffStrategy.
func NewUpdateStrategyWithBackoff ¶
func NewUpdateStrategyWithBackoff( decorated UpdateStrategy, backoffStrategy adminapi.UpdateBackoffStrategy, logger logr.Logger, ) UpdateStrategyWithBackoff
func (UpdateStrategyWithBackoff) MetricsProtocol ¶
func (s UpdateStrategyWithBackoff) MetricsProtocol() metrics.Protocol
func (UpdateStrategyWithBackoff) Type ¶
func (s UpdateStrategyWithBackoff) Type() string
func (UpdateStrategyWithBackoff) Update ¶
func (s UpdateStrategyWithBackoff) Update(ctx context.Context, targetContent ContentWithHash) (n mo.Option[int], err error)
Update will ensure that the decorated UpdateStrategy.Update is called only when an underlying UpdateBackoffStrategy.CanUpdate is satisfied. In case it's not, it will return a predefined ErrUpdateSkippedDueToBackoffStrategy. In case it is, apart from calling UpdateStrategy.Update, it will also register a success or a failure of an update attempt so that the UpdateBackoffStrategy can keep track of it. When the update is successful, it returns the number of bytes sent to the DataPlane or mo.None when it's impossible to determine the number of bytes sent e.g. for dbmode (deck) strategy.