sendconfig

package
v3.1.4 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
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,
	promMetrics *metrics.CtrlFuncMetrics,
	updateStrategyResolver UpdateStrategyResolver,
	configChangeDetector ConfigurationChangeDetector,
) ([]byte, []failures.ResourceFailure, error)

PerformUpdate writes `targetContent` to Kong Admin API specified by `kongConfig`.

Types

type AdminAPIClient

type AdminAPIClient interface {
	AdminAPIClient() *kong.Client
	LastConfigSHA() []byte
	SetLastConfigSHA([]byte)
	BaseRootURL() string
	PluginSchemaStore() *util.PluginSchemaStore

	IsKonnect() bool
	KonnectControlPlane() string
}

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
}

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 ConfigService interface {
	ReloadDeclarativeRawConfig(
		ctx context.Context,
		config io.Reader,
		checkHash bool,
		flattenErrors bool,
	) ([]byte, error)
}

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
	Hash    []byte
}

ContentWithHash encapsulates file.Content along with its precalculated hash.

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

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,
) 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 InMemoryClient interface {
	BaseRootURL() string
	ReloadDeclarativeRawConfig(ctx context.Context, config io.Reader, checkHash bool, flattenErrors bool) ([]byte, error)
}

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 StatusClient

type StatusClient interface {
	Status(context.Context) (*kong.Status, error)
}

type UpdateClient

type UpdateClient interface {
	IsKonnect() bool
	KonnectControlPlane() string
	AdminAPIClient() *kong.Client
}

type UpdateClientWithBackoff

type UpdateClientWithBackoff interface {
	UpdateClient
	BackoffStrategy() adminapi.UpdateBackoffStrategy
}

type UpdateSkippedDueToBackoffStrategyError

type UpdateSkippedDueToBackoffStrategyError struct {
	// contains filtered or unexported fields
}

func NewUpdateSkippedDueToBackoffStrategyError

func NewUpdateSkippedDueToBackoffStrategyError(explanation string) UpdateSkippedDueToBackoffStrategyError

func (UpdateSkippedDueToBackoffStrategyError) Error

type UpdateStrategy

type UpdateStrategy interface {
	// Update applies targetConfig to the data-plane.
	Update(ctx context.Context, targetContent ContentWithHash) (
		err error,
		resourceErrors []ResourceError,
		resourceErrorsParseErr 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,
) UpdateStrategyDBMode

func NewUpdateStrategyDBModeKonnect

func NewUpdateStrategyDBModeKonnect(
	client *kong.Client,
	dumpConfig dump.Config,
	version semver.Version,
	concurrency int,
) UpdateStrategyDBMode

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) (
	err error,
	resourceErrors []ResourceError,
	resourceErrorsParseErr 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) (
	err error,
	resourceErrors []ResourceError,
	resourceErrorsParseErr error,
)

type UpdateStrategyResolver

type UpdateStrategyResolver interface {
	ResolveUpdateStrategy(client UpdateClient) 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 (UpdateStrategyWithBackoff) Update

func (s UpdateStrategyWithBackoff) Update(ctx context.Context, targetContent ContentWithHash) (
	err error,
	resourceErrors []ResourceError,
	resourceErrorsParseErr 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.

Jump to

Keyboard shortcuts

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