sendconfig

package
v2.10.4 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2023 License: Apache-2.0 Imports: 29 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,
	log logrus.FieldLogger,
	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 added in v2.10.0

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

	IsKonnect() bool
	KonnectRuntimeGroup() string
}

type Config added in v2.9.0

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

	// DeckFileFormatVersion indicates the version of the Kong configuration format to use when using DB-mode.
	DeckFileFormatVersion string
}

Config gathers parameters that are needed for sending configuration to Kong Admin APIs.

func (*Config) Init added in v2.9.0

func (c *Config) Init(
	ctx context.Context,
	logger logr.Logger,
	kongClients []*adminapi.Client,
)

Init sets up variables that need external calls.

type ConfigError added in v2.9.0

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 added in v2.9.0

type ConfigErrorFields struct {
}

ConfigErrorFields is the structure under the "fields" key in a /config error response.

type ConfigService added in v2.9.0

type ConfigService interface {
	ReloadDeclarativeRawConfig(
		ctx context.Context,
		config io.Reader,
		checkHash bool,
		flattenErrors bool,
	) ([]byte, error)
}

type ConfigurationChangeDetector added in v2.9.0

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 ContentWithHash added in v2.10.0

type ContentWithHash struct {
	Content *file.Content
	Hash    []byte
}

ContentWithHash encapsulates file.Content along with its precalculated hash.

type DefaultConfigurationChangeDetector added in v2.9.0

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

func NewDefaultClientConfigurationChangeDetector added in v2.9.0

func NewDefaultClientConfigurationChangeDetector(log logrus.FieldLogger) *DefaultConfigurationChangeDetector

func (*DefaultConfigurationChangeDetector) HasConfigurationChanged added in v2.9.0

func (d *DefaultConfigurationChangeDetector) HasConfigurationChanged(
	ctx context.Context,
	oldSHA, newSHA []byte,
	targetConfig *file.Content,
	client KonnectAwareClient,
	statusClient StatusClient,
) (bool, error)

type DefaultUpdateStrategyResolver added in v2.9.0

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

func NewDefaultUpdateStrategyResolver added in v2.9.0

func NewDefaultUpdateStrategyResolver(config Config, log logrus.FieldLogger) DefaultUpdateStrategyResolver

func (DefaultUpdateStrategyResolver) ResolveUpdateStrategy added in v2.9.0

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 added in v2.9.0

type FlatEntityError struct {
	Name   string           `json:"entity_name,omitempty" yaml:"entity_name,omitempty"`
	ID     string           `json:"entity_id,omitempty" yaml:"entity_id,omitempty"`
	Tags   []string         `json:"entity_tags,omitempty" yaml:"entity_tags,omitempty"`
	Errors []FlatFieldError `json:"errors,omitempty" yaml:"errors,omitempty"`
}

FlatEntityError represents a single Kong entity with one or more invalid fields.

type FlatFieldError added in v2.9.0

type FlatFieldError struct {
	Field string `json:"field,omitempty" yaml:"field,omitempty"`
	// Message is the error associated with Field for single-value fields.
	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"`
}

FlatFieldError represents an error for a single field within a Kong entity.

type InMemoryClient added in v2.9.0

type InMemoryClient interface {
	BaseRootURL() string
	ReloadDeclarativeRawConfig(ctx context.Context, config io.Reader, checkHash bool, flattenErrors bool) ([]byte, error)
}

type KonnectAwareClient added in v2.9.0

type KonnectAwareClient interface {
	IsKonnect() bool
}

type ResourceError added in v2.9.0

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 added in v2.9.0

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

type UpdateClient added in v2.9.0

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

type UpdateClientWithBackoff added in v2.10.0

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

type UpdateSkippedDueToBackoffStrategyError added in v2.10.1

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

func NewUpdateSkippedDueToBackoffStrategyError added in v2.10.1

func NewUpdateSkippedDueToBackoffStrategyError(explanation string) UpdateSkippedDueToBackoffStrategyError

func (UpdateSkippedDueToBackoffStrategyError) Error added in v2.10.1

type UpdateStrategy added in v2.9.0

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 added in v2.9.0

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 added in v2.9.0

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

func NewUpdateStrategyDBModeKonnect added in v2.10.4

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

func (UpdateStrategyDBMode) MetricsProtocol added in v2.9.0

func (s UpdateStrategyDBMode) MetricsProtocol() metrics.Protocol

func (UpdateStrategyDBMode) Type added in v2.10.0

func (s UpdateStrategyDBMode) Type() string

func (UpdateStrategyDBMode) Update added in v2.9.0

func (s UpdateStrategyDBMode) Update(ctx context.Context, targetContent ContentWithHash) (
	err error,
	resourceErrors []ResourceError,
	resourceErrorsParseErr error,
)

type UpdateStrategyInMemory added in v2.9.0

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 added in v2.9.0

func NewUpdateStrategyInMemory(
	configService ConfigService,
	log logrus.FieldLogger,
	version semver.Version,
) UpdateStrategyInMemory

func (UpdateStrategyInMemory) MetricsProtocol added in v2.9.0

func (s UpdateStrategyInMemory) MetricsProtocol() metrics.Protocol

func (UpdateStrategyInMemory) Type added in v2.10.0

func (s UpdateStrategyInMemory) Type() string

func (UpdateStrategyInMemory) Update added in v2.9.0

func (s UpdateStrategyInMemory) Update(ctx context.Context, targetState ContentWithHash) (
	err error,
	resourceErrors []ResourceError,
	resourceErrorsParseErr error,
)

type UpdateStrategyResolver added in v2.9.0

type UpdateStrategyResolver interface {
	ResolveUpdateStrategy(client UpdateClient) UpdateStrategy
}

type UpdateStrategyWithBackoff added in v2.10.0

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

UpdateStrategyWithBackoff decorates any UpdateStrategy to respect a passed adminapi.UpdateBackoffStrategy.

func NewUpdateStrategyWithBackoff added in v2.10.0

func NewUpdateStrategyWithBackoff(
	decorated UpdateStrategy,
	backoffStrategy adminapi.UpdateBackoffStrategy,
	log logrus.FieldLogger,
) UpdateStrategyWithBackoff

func (UpdateStrategyWithBackoff) MetricsProtocol added in v2.10.0

func (s UpdateStrategyWithBackoff) MetricsProtocol() metrics.Protocol

func (UpdateStrategyWithBackoff) Type added in v2.10.0

func (UpdateStrategyWithBackoff) Update added in v2.10.0

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