config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxChanges is the maximum number of changes tracked by ChangeTracker.
	MaxChanges = 128
	// MaxResourcesPerChange is the maximum number of resource that
	// ChangeTracker will record for a specific change.
	MaxResourcesPerChange = 128
)
View Source
const KongGatewayCompatibilityVersion = "3.0.0"

Variables

View Source
var ChangeRegistry = newCompatChangeRegistry()

ChangeRegistry holds all changes.

View Source
var ErrRegistryEntryNotFound = errors.New("not found")

Functions

func CompressPayload

func CompressPayload(payload []byte) ([]byte, error)

func UncompressPayload

func UncompressPayload(payload []byte) ([]byte, error)

Types

type Change

type Change struct {
	// Metadata holds metadata associated with a change.
	Metadata ChangeMetadata
	// SemverRange is the version range for which this change must be executed to
	// guarantee compatibility.
	SemverRange string
	// Update holds a declarative definition of the change that must be
	// applied to a specific schema.
	Update ConfigTableUpdates
}

Change is a configuration change that is done automatically by the control-plane in order to achieve compatibility with a Kong data-plane.

type ChangeDetail

type ChangeDetail struct {
	ID        ChangeID
	Resources []ResourceInfo
}

ChangeDetail is a change ID that applies to multiple resources.

type ChangeID

type ChangeID string

ChangeID is a globally unique identifier for each compatibility change definition.

func (ChangeID) Valid

func (c ChangeID) Valid() error

type ChangeMetadata

type ChangeMetadata struct {
	// ID identifies a change uniquely. Required.
	ID ChangeID
	// Severity identifies the severity of a change. Required.
	// Read Severities defined in this package for more details.
	Severity ChangeSeverity
	// Description is a human-readable sentence describing the impact of the
	// change. Required.
	Description string
	// Resolution is a human-readable sentence describing the path to
	// resolution. Required.
	Resolution string
	// DocumentationURL is an optional web URL that further details the
	// change or its resolution.
	DocumentationURL string
}

ChangeMetadata holds metadata for a specific change.

type ChangeSeverity

type ChangeSeverity string
const (
	// ChangeSeverityWarning is a configuration warning.
	// This is used to highlight the use of a deprecated configuration field.
	// This severity implies that there is no change in functionality of the
	// gateway.
	ChangeSeverityWarning ChangeSeverity = "warning"
	// ChangeSeverityError is a configuration error.
	// This is used to highlight a compatibility change that result in the
	// behavior of the gateway to be different from what the intention of the
	// user.
	ChangeSeverityError ChangeSeverity = "error"
)

type ChangeTracker

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

ChangeTracker tracks changes for a given configuration. Tracking is bounded i.e. it there is an upper limits to the amount of changes that are tracked. Tracking changes or resources beyond MaxChanges or MaxResourcesPerChange is a no-op. Duplicated changes are de-duplicated. ChangeTracker is not thread-safe.

func NewChangeTracker

func NewChangeTracker() *ChangeTracker

NewChangeTracker returns a new ChangeTracker.

func (*ChangeTracker) Get

func (c *ChangeTracker) Get() TrackedChanges

Get returns all the changes tracked up until this point. The response is sorted alphabetically and deterministic.

func (*ChangeTracker) Track

func (c *ChangeTracker) Track(id ChangeID) error

Track tracks a change with id. The change is not associated with any resource. If ChangeTracker's capacity has been reached, the call is a no-op.

func (*ChangeTracker) TrackForResource

func (c *ChangeTracker) TrackForResource(id ChangeID, r ResourceInfo) error

TrackForResource tracks a change with id for resource referenced by r. If ChangeTracker's capacity has been reached, the call is a no-op.

type CompatChangeRegistry

type CompatChangeRegistry interface {
	// Register registers a change.
	// If a change is already registers or if a change is invalid,
	// it returns an error.
	Register(c Change) error
	// GetMetadata returns ChangeMetadata for an id.
	// It returns ErrRegistryEntryNotFound if a change with id has not been previously
	// registered.
	GetMetadata(id ChangeID) (ChangeMetadata, error)
	// GetUpdates returns configuration updates for all registered
	// changes. The order of updates within a version is not deterministic.
	GetUpdates() VersionedConfigUpdates
}

CompatChangeRegistry holds compatibility changes. Implementations may not be thread safe.

type ConfigTableFieldCondition

type ConfigTableFieldCondition struct {
	// Field is a top-level or nested field; use dot notation for nested fields.
	Field string
	// Condition is an expression for matching criteria.
	// uses gjson path syntax; https://github.com/tidwall/gjson#path-syntax
	Condition string
	// Updates is an array of updates to perform based on the matched criteria.
	Updates []ConfigTableFieldUpdate
}

type ConfigTableFieldUpdate

type ConfigTableFieldUpdate struct {
	// Field to perform update or delete operation on; if Value is nil or
	// ValueFromField is empty the field will be removed.
	Field string
	// Value when specified is the value applied to the key referenced in the
	// member Field.
	Value interface{}
	// ValueFromField when specified represents the name of the key whose value is
	// retrieved and applied to the key referenced in the member Field.
	ValueFromField string
}

type ConfigTableUpdates

type ConfigTableUpdates struct {
	// Name is the name of the configuration or field depending on UpdateType.
	Name string
	// UpdateType is the type of update being performed; currently plugins only.
	Type UpdateType
	// RemoveFields will remove fields from the configuration table.
	//
	// Values contained within this array are associated with a field name inside
	// the configuration table. The value can be a top-level field or a nested
	// field which is separated using the dot notation.
	RemoveFields []string
	// RemoveElementsFromArray will remove an array element from a field in the
	// configuration table.
	//
	// Values contained within this array are associated with a field and a
	// condition. If the condition matches for the given field, the array in which
	// the match occurred (e.g. index) will be removed from  the configuration
	// table.
	RemoveElementsFromArray []ConfigTableFieldCondition
	// FieldUpdates will create/update a field to a new value in the configuration
	// table.
	//
	// Values contained within this array are associated with a field, a
	// condition, and an array of updates to perform. New fields can be created,
	// original fields can be updated, and specific fields can be removed
	// depending on the version compatibility requirement of the data plane
	// version being targeted.
	FieldUpdates []ConfigTableFieldCondition
	// Remove indicates whether the whole entity should be removed or not.
	Remove bool

	// ChangeID is a unique identifier for every schema update.
	ChangeID ChangeID

	// DisableChangeTracking takes in JSON encoded string representation of
	// UpdateType denoted by Type defined above.
	// This callback gives an opportunity to the change to dynamically disable
	// change tracking.
	//
	// An example use-case is when a newly added field with a backwards-compatible
	// default value is dropped from the configuration. In this case, the user
	// doesn't need to be notified of a benign change.
	// When unspecified, the change is always emitted.
	DisableChangeTracking func(rawJSON string) bool
}

type Content

type Content struct {
	CompressedPayload []byte
	Hash              string
	GranularHashes    map[string]string
}

func ReconfigurePayload

func ReconfigurePayload(c DataPlaneConfig) (Content, error)

type DataPlaneConfig

type DataPlaneConfig Map

type KongCACertificateLoader

type KongCACertificateLoader struct {
	Client admin.CACertificateServiceClient
}

func (*KongCACertificateLoader) Mutate

func (KongCACertificateLoader) Name

type KongCertificateLoader

type KongCertificateLoader struct {
	Client admin.CertificateServiceClient
}

func (*KongCertificateLoader) Mutate

func (l *KongCertificateLoader) Mutate(ctx context.Context,
	opts MutatorOpts, config DataPlaneConfig,
) error

func (KongCertificateLoader) Name

func (l KongCertificateLoader) Name() string

type KongConfigurationLoader

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

func (*KongConfigurationLoader) Load

func (l *KongConfigurationLoader) Load(ctx context.Context, clusterID string) (Content, error)

func (*KongConfigurationLoader) Register

func (l *KongConfigurationLoader) Register(mutator Mutator) error

type KongConsumerLoader

type KongConsumerLoader struct {
	Client admin.ConsumerServiceClient
}

func (*KongConsumerLoader) Mutate

func (l *KongConsumerLoader) Mutate(ctx context.Context,
	opts MutatorOpts, config DataPlaneConfig,
) error

Mutate reads the Consumer data from CP persistence store and populates the read data into config.

func (KongConsumerLoader) Name

func (l KongConsumerLoader) Name() string

type KongPluginLoader

type KongPluginLoader struct {
	Client admin.PluginServiceClient
}

func (*KongPluginLoader) Mutate

func (l *KongPluginLoader) Mutate(ctx context.Context,
	opts MutatorOpts, config DataPlaneConfig,
) error

func (KongPluginLoader) Name

func (l KongPluginLoader) Name() string

type KongRouteLoader

type KongRouteLoader struct {
	Client admin.RouteServiceClient
}

func (*KongRouteLoader) Mutate

func (l *KongRouteLoader) Mutate(ctx context.Context,
	opts MutatorOpts, config DataPlaneConfig,
) error

func (KongRouteLoader) Name

func (l KongRouteLoader) Name() string

type KongSNILoader

type KongSNILoader struct {
	Client admin.SNIServiceClient
}

func (*KongSNILoader) Mutate

func (l *KongSNILoader) Mutate(ctx context.Context,
	opts MutatorOpts, config DataPlaneConfig,
) error

func (KongSNILoader) Name

func (l KongSNILoader) Name() string

type KongServiceLoader

type KongServiceLoader struct {
	Client admin.ServiceServiceClient
}

func (*KongServiceLoader) Mutate

func (l *KongServiceLoader) Mutate(ctx context.Context,
	opts MutatorOpts, config DataPlaneConfig,
) error

func (KongServiceLoader) Name

func (l KongServiceLoader) Name() string

type KongTargetLoader

type KongTargetLoader struct {
	Client admin.TargetServiceClient
}

func (*KongTargetLoader) Mutate

func (l *KongTargetLoader) Mutate(ctx context.Context,
	opts MutatorOpts, config DataPlaneConfig,
) error

func (KongTargetLoader) Name

func (l KongTargetLoader) Name() string

type KongUpstreamLoader

type KongUpstreamLoader struct {
	Client admin.UpstreamServiceClient
}

func (*KongUpstreamLoader) Mutate

func (l *KongUpstreamLoader) Mutate(ctx context.Context,
	opts MutatorOpts, config DataPlaneConfig,
) error

func (KongUpstreamLoader) Name

func (l KongUpstreamLoader) Name() string

type Loader

type Loader interface {
	Load(ctx context.Context, clusterID string) (Content, error)
}

type Map

type Map map[string]interface{}

type Mutator

type Mutator interface {
	Name() string
	Mutate(context.Context, MutatorOpts, DataPlaneConfig) error
}

type MutatorOpts

type MutatorOpts struct {
	ClusterID string
}

type ParametersLoader

type ParametersLoader struct {
	ClusterID string
}

func NewParametersLoader

func NewParametersLoader(clusterID string) (*ParametersLoader, error)

NewParametersLoader creates a parameters configuration loader. It requires a valid UUID.

func (*ParametersLoader) Mutate

Mutate updates the config parameters, a map of key:value pairs.

func (ParametersLoader) Name

func (l ParametersLoader) Name() string

Name returns the name of the loader.

type Processor

type Processor func(uncompressedPayload string, dataPlaneVersion versioning.Version,
	tracker *ChangeTracker, logger *zap.Logger) (string, error)

type ResourceInfo

type ResourceInfo struct {
	Type string
	ID   string
}

ResourceInfo serves as a pointer to a resource of Type and ID within the entire configuration of Kong gateway.

func (ResourceInfo) Valid

func (r ResourceInfo) Valid() error

type TrackedChanges

type TrackedChanges struct {
	// Changes are resource-specific changes.
	ChangeDetails []ChangeDetail
}

TrackedChanges contains all changes recorded by ChangeTracker.

type UpdateType

type UpdateType uint8
const (
	// Plugin is the UpdateType referring to plugins' config schema updates
	// e.g.: `$.config_table.plugins[?(@.name == '(PLUGIN_NAME)')].config`.
	Plugin UpdateType = iota
	// CorePlugin is the UpdateType referring to plugins's core schema updates
	// e.g.: `$.config_table.plugins[?(@.name == '(PLUGIN_NAME)')]`.
	CorePlugin

	Service
	Route
	Upstream
)

func (UpdateType) ConfigTableKey

func (u UpdateType) ConfigTableKey() string

func (UpdateType) String

func (u UpdateType) String() string

type VersionCompatibility

type VersionCompatibility interface {
	AddConfigTableUpdates(configTableUpdates VersionedConfigUpdates) error
	ProcessConfigTableUpdates(dataPlaneVersionStr string, compressedPayload []byte) ([]byte, TrackedChanges, error)
}

type VersionCompatibilityOpts

type VersionCompatibilityOpts struct {
	Logger         *zap.Logger
	KongCPVersion  string
	ExtraProcessor Processor
}

type VersionLoader

type VersionLoader struct{}

func (*VersionLoader) Mutate

func (l *VersionLoader) Mutate(_ context.Context,
	_ MutatorOpts, config DataPlaneConfig,
) error

func (VersionLoader) Name

func (l VersionLoader) Name() string

type VersionedConfigUpdates

type VersionedConfigUpdates map[string][]ConfigTableUpdates

type WSVersionCompatibility

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

func NewVersionCompatibilityProcessor

func NewVersionCompatibilityProcessor(opts VersionCompatibilityOpts) (*WSVersionCompatibility, error)

func (*WSVersionCompatibility) AddConfigTableUpdates

func (vc *WSVersionCompatibility) AddConfigTableUpdates(payloadUpdates VersionedConfigUpdates) error

func (*WSVersionCompatibility) ProcessConfigTableUpdates

func (vc *WSVersionCompatibility) ProcessConfigTableUpdates(dataPlaneVersionStr string,
	compressedPayload []byte,
) ([]byte, TrackedChanges, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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