translator

package
v1.16.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: Apache-2.0 Imports: 37 Imported by: 4

Documentation

Index

Constants

View Source
const AggregateTranslatorName = "aggregate"
View Source
const HttpTranslatorName = "http"
View Source
const HybridTranslatorName = "hybrid"
View Source
const IsolateVirtualHostsAnnotation = "gateway.solo.io/isolate_vhost"

IsolateVirtualHostsAnnotation is the annotation that can be applied to a Gateway resource to determine how a Gateway will be converted into a Listener All truthy values are accepted, using `strconv.ParseBool` to determine the value If the value of this annotation is invalid or not provided, the behavior will fallback to the global configuration that is defined in Settings (gateway.isolateVirtualHostsBySslConfig)

View Source
const TcpTranslatorName = "tcp"

Variables

View Source
var (
	NoActionErr          = errors.New("invalid route: route must specify an action")
	MatcherCountErr      = errors.New("invalid route: routes with delegate actions must omit or specify a single matcher")
	MissingPrefixErr     = errors.New("invalid route: routes with delegate actions must use a prefix matcher")
	InvalidPrefixErr     = errors.New("invalid route: route table matchers must begin with the prefix of their parent route's matcher")
	InvalidPathMatchErr  = errors.New("invalid route: route table matchers must have the same case sensitivity of their parent route's matcher")
	InvalidHeaderErr     = errors.New("invalid route: route table matchers must have all headers that were specified on their parent route's matcher")
	InvalidQueryParamErr = errors.New("invalid route: route table matchers must have all query params that were specified on their parent route's matcher")
	InvalidMethodErr     = errors.New("invalid route: route table matchers must have all methods that were specified on their parent route's matcher")

	UnnamedRoute = func(index int) string {
		return fmt.Sprintf("<unnamed-%d>", index)
	}
	DelegationCycleErr = func(cycleInfo string) error {
		return errors.Errorf("invalid route: delegation cycle detected: %s", cycleInfo)
	}
	InvalidRouteTableForDelegatePrefixWarning = func(delegatePrefix, prefixString string) error {
		return errors.Wrapf(InvalidPrefixErr, "required prefix: %v, prefix: %v", delegatePrefix, prefixString)
	}
	InvalidRouteTableForDelegateHeadersWarning = func(delegateHeaders, childHeaders []*matchersv1.HeaderMatcher) error {
		return errors.Wrapf(InvalidHeaderErr, "required headers: %v, headers: %v", delegateHeaders, childHeaders)
	}
	InvalidRouteTableForDelegateQueryParamsWarning = func(delegateQueryParams, childQueryParams []*matchersv1.QueryParameterMatcher) error {
		return errors.Wrapf(InvalidQueryParamErr, "required query params: %v, query params: %v", delegateQueryParams, childQueryParams)
	}
	InvalidRouteTableForDelegateMethodsWarning = func(delegateMethods, childMethods []string) error {
		return errors.Wrapf(InvalidMethodErr, "required methods: %v, methods: %v", delegateMethods, childMethods)
	}
	TopLevelVirtualResourceErr = func(rtRef *core.Metadata, err error) error {
		return errors.Wrapf(err, "on sub route table %s", rtRef.Ref().Key())
	}

	InvalidRouteTableForDelegateCaseSensitivePathMatchWarning = func(delegateMatchCaseSensitive, matchCaseSensitive *wrappers.BoolValue) error {
		return errors.Wrapf(InvalidPathMatchErr, "required caseSensitive: %v, caseSensitive: %v", delegateMatchCaseSensitive, matchCaseSensitive)
	}
)
View Source
var (
	RouteTableMissingWarning = func(ref core.ResourceRef) error {
		return errors.Errorf("route table %v.%v missing", ref.GetNamespace(), ref.GetName())
	}
	NoMatchingRouteTablesWarning = errors.New("no route table matches the given selector")
	MissingRefAndSelectorWarning = errors.New("cannot determine delegation target: you must specify a route table " +
		"either via a resource reference or a selector")
	RouteTableSelectorExpressionsAndLabelsWarning = errors.New("cannot use both labels and expressions within the " +
		"same selector")
	RouteTableSelectorInvalidExpressionWarning = errors.New("the route table selector expression is invalid")

	// Map connecting Gloo Route Tables expression operator values and Kubernetes expression operator string values.
	RouteTableExpressionOperatorValues = map[gatewayv1.RouteTableSelector_Expression_Operator]selection.Operator{
		gatewayv1.RouteTableSelector_Expression_Equals:       selection.Equals,
		gatewayv1.RouteTableSelector_Expression_DoubleEquals: selection.DoubleEquals,
		gatewayv1.RouteTableSelector_Expression_NotEquals:    selection.NotEquals,
		gatewayv1.RouteTableSelector_Expression_In:           selection.In,
		gatewayv1.RouteTableSelector_Expression_NotIn:        selection.NotIn,
		gatewayv1.RouteTableSelector_Expression_Exists:       selection.Exists,
		gatewayv1.RouteTableSelector_Expression_DoesNotExist: selection.DoesNotExist,
		gatewayv1.RouteTableSelector_Expression_GreaterThan:  selection.GreaterThan,
		gatewayv1.RouteTableSelector_Expression_LessThan:     selection.LessThan,
	}
)
View Source
var (
	NoVirtualHostErr = func(vs *v1.VirtualService) error {
		return errors.Errorf("virtual service [%s] does not specify a virtual host", vs.GetMetadata().Ref().Key())
	}
	InvalidRegexErr = func(vsRef, regexErr string) error {
		return errors.Errorf("virtual service [%s] has a regex matcher with invalid regex, %s",
			vsRef, regexErr)
	}
	DomainInOtherVirtualServicesErr = func(domain string, conflictingVsRefs []string) error {
		if domain == "" {
			return errors.Errorf("domain conflict: other virtual services that belong to the same Gateway"+
				" as this one don't specify a domain (and thus default to '*'): %v", conflictingVsRefs)
		}
		return errors.Errorf("domain conflict: the [%s] domain is present in other virtual services "+
			"that belong to the same Gateway as this one: %v", domain, conflictingVsRefs)
	}
	GatewayHasConflictingVirtualServicesErr = func(conflictingDomains []string) error {
		var loggedDomains []string
		for _, domain := range conflictingDomains {
			if domain == "" {
				domain = "EMPTY_DOMAIN"
			}
			loggedDomains = append(loggedDomains, domain)
		}
		return errors.Errorf("domain conflict: the following domains are present in more than one of the "+
			"virtual services associated with this gateway: %v", loggedDomains)
	}
	ConflictingMatcherErr = func(vh string, matcher *matchers.Matcher) error {
		return errors.Errorf("virtual host [%s] has conflicting matcher: %v", vh, matcher)
	}
	UnorderedPrefixErr = func(vh, prefix string, matcher *matchers.Matcher) error {
		return errors.Errorf("virtual host [%s] has unordered prefix routes, earlier prefix [%s] short-circuited "+
			"later route [%v]", vh, prefix, matcher)
	}
	UnorderedRegexErr = func(vh, regex string, matcher *matchers.Matcher) error {
		return errors.Errorf("virtual host [%s] has unordered regex routes, earlier regex [%s] short-circuited "+
			"later route [%v]", vh, regex, matcher)
	}

	VirtualServiceSelectorInvalidExpressionWarning = errors.New("the virtual service selector expression is invalid")
	// Map connecting Gloo Virtual Services expression operator values and Kubernetes expression operator string values.
	VirtualServiceExpressionOperatorValues = map[v1.VirtualServiceSelectorExpressions_Expression_Operator]selection.Operator{
		v1.VirtualServiceSelectorExpressions_Expression_Equals:       selection.Equals,
		v1.VirtualServiceSelectorExpressions_Expression_DoubleEquals: selection.DoubleEquals,
		v1.VirtualServiceSelectorExpressions_Expression_NotEquals:    selection.NotEquals,
		v1.VirtualServiceSelectorExpressions_Expression_In:           selection.In,
		v1.VirtualServiceSelectorExpressions_Expression_NotIn:        selection.NotIn,
		v1.VirtualServiceSelectorExpressions_Expression_Exists:       selection.Exists,
		v1.VirtualServiceSelectorExpressions_Expression_DoesNotExist: selection.DoesNotExist,
		v1.VirtualServiceSelectorExpressions_Expression_GreaterThan:  selection.GreaterThan,
		v1.VirtualServiceSelectorExpressions_Expression_LessThan:     selection.LessThan,
	}
)
View Source
var (
	EmptyHybridGatewayMessage = "hybrid gateway does not have any populated matched gateways"
)
View Source
var MissingGatewayTypeErr = errors.New("invalid gateway: gateway must contain gatewayType")

Functions

func FilterGateways added in v1.9.25

func FilterGateways(gateways v1.GatewayList, predicate Predicate) v1.GatewayList

FilterGateways filters a GatewayList based on a Predicate, and returns a new list

func ForEachSource added in v1.0.0

func ForEachSource(obj ObjectWithMetadata, fn func(source SourceRef) error) error

func GroupVirtualServicesBySslConfig added in v1.14.0

func GroupVirtualServicesBySslConfig(virtualServices []*v1.VirtualService) ([]*ssl.SslConfig, map[*ssl.SslConfig][]*v1.VirtualService)

GroupVirtualServicesBySslConfig returning a stable order of sslConfigs and a map of sslconfigs to their associated Virtual service lists to use on.

func HttpGatewayContainsVirtualService added in v1.9.25

func HttpGatewayContainsVirtualService(httpGateway *v1.HttpGateway, virtualService *v1.VirtualService, ssl bool) (bool, error)

HttpGatewayContainsVirtualService determines whether the VS has the same selector/expression matching and the same namespace so that the two resources can co-exist. A VS must match on these terms. Else see if the VS matches the same refs that are currently on the gateway.

func ListenerName added in v1.0.0

func ListenerName(gateway *v1.Gateway) string

func NewHttpGatewaySelector added in v1.9.25

func NewHttpGatewaySelector(gwList v1.MatchableHttpGatewayList) *httpGatewaySelector

func NewTcpGatewaySelector added in v1.14.4

func NewTcpGatewaySelector(gwList v1.MatchableTcpGatewayList) *tcpGatewaySelector

func RouteTableLabelsMatchesExpressionRequirements added in v1.5.0

func RouteTableLabelsMatchesExpressionRequirements(requirements labels.Requirements, rtLabels labels.Set) bool

Asserts that the route table labels matches all of the expression requirements (logical AND).

func RouteTablesForSelector added in v1.3.2

func RouteTablesForSelector(routeTables gatewayv1.RouteTableList, selector *gatewayv1.RouteTableSelector, ownerNamespace string) (gatewayv1.RouteTableList, error)

Returns the subset of `routeTables` that matches the given `selector`. Search will be restricted to the `ownerNamespace` if the selector does not specify any namespaces.

func VirtualHostName added in v1.0.0

func VirtualHostName(vs *v1.VirtualService) string

Types

type AggregateTranslator added in v1.9.25

type AggregateTranslator struct {
	VirtualServiceTranslator *VirtualServiceTranslator
	TcpTranslator            *TcpTranslator
}

AggregateTranslator is responsible for translating a Gateway into a Gloo Listener It attempts to use Gateways as a storage for shared filterchain options. Therefore it splits gateways into appropriate filterchains based on the sni options.

func (*AggregateTranslator) ComputeListener added in v1.9.25

func (a *AggregateTranslator) ComputeListener(params Params, proxyName string, gateway *v1.Gateway) *gloov1.Listener

type AllNamespacesPredicate added in v1.9.25

type AllNamespacesPredicate struct {
}

AllNamespacesPredicate returns true for all Gateways, independent of their namespace When this predicate is used, Gloo will read gateways from all namespaces, not just the one it is configured to write to

func (*AllNamespacesPredicate) ReadGateway added in v1.9.25

func (a *AllNamespacesPredicate) ReadGateway(_ *v1.Gateway) bool

type GwTranslator added in v1.9.25

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

func NewDefaultTranslator added in v0.19.0

func NewDefaultTranslator(opts Opts) *GwTranslator

func (*GwTranslator) Translate added in v1.9.25

func (t *GwTranslator) Translate(ctx context.Context, proxyName string, snap *gloov1snap.ApiSnapshot, gateways v1.GatewayList) (*gloov1.Proxy, reporter.ResourceReports)

Translate converts a set of Gateways into a Proxy, with the provided proxyName

type HttpGatewaySelector added in v1.9.25

type HttpGatewaySelector interface {
	SelectMatchableHttpGateways(selector *v1.DelegatedHttpGateway, onError func(err error)) v1.MatchableHttpGatewayList
}

type HttpTranslator added in v0.18.0

type HttpTranslator struct {
	VirtualServiceTranslator *VirtualServiceTranslator
}

func (*HttpTranslator) ComputeListener added in v1.9.25

func (t *HttpTranslator) ComputeListener(params Params, proxyName string, gateway *v1.Gateway) *gloov1.Listener

type HybridTranslator added in v1.9.25

type HybridTranslator struct {
	VirtualServiceTranslator *VirtualServiceTranslator
	TcpTranslator            *TcpTranslator
}

func (*HybridTranslator) ComputeListener added in v1.9.25

func (t *HybridTranslator) ComputeListener(params Params, proxyName string, gateway *v1.Gateway) *gloov1.Listener

type InvalidGatewayTypeTranslator added in v1.9.25

type InvalidGatewayTypeTranslator struct{}

func (InvalidGatewayTypeTranslator) ComputeListener added in v1.9.25

func (n InvalidGatewayTypeTranslator) ComputeListener(params Params, proxyName string, gateway *v1.Gateway) *gloov1.Listener

type ListenerTranslator added in v1.9.25

type ListenerTranslator interface {
	ComputeListener(params Params, proxyName string, gateway *v1.Gateway) *gloov1.Listener
}

ListenerTranslator converts a Gateway into a Listener

type ObjectWithMetadata added in v1.0.0

type ObjectWithMetadata interface {
	GetMetadata() *structpb.Struct
	GetMetadataStatic() *v1.SourceMetadata
}

type Opts added in v1.0.0

type Opts struct {
	GlooNamespace                  string
	WriteNamespace                 string
	StatusReporterNamespace        string
	WatchNamespaces                []string
	Gateways                       factory.ResourceClientFactory
	MatchableHttpGateways          factory.ResourceClientFactory
	MatchableTcpGateways           factory.ResourceClientFactory
	VirtualServices                factory.ResourceClientFactory
	RouteTables                    factory.ResourceClientFactory
	Proxies                        factory.ResourceClientFactory
	RouteOptions                   factory.ResourceClientFactory
	VirtualHostOptions             factory.ResourceClientFactory
	WatchOpts                      clients.WatchOpts
	ValidationServerAddress        string
	DevMode                        bool
	ReadGatewaysFromAllNamespaces  bool
	Validation                     *ValidationOpts
	ConfigStatusMetricOpts         map[string]*metrics.MetricLabels
	IsolateVirtualHostsBySslConfig bool
}

type Params added in v1.9.25

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

func NewTranslatorParams added in v1.9.25

func NewTranslatorParams(ctx context.Context, snapshot *gloov1snap.ApiSnapshot, reports reporter.ResourceReports) Params

type Predicate added in v1.9.25

type Predicate interface {
	// ReadGateway returns true if a Gateway should be processed during translation, false otherwise
	ReadGateway(gw *v1.Gateway) bool
}

Predicate is used to determine how to reduce a list of Gateways

func GetPredicate added in v1.9.25

func GetPredicate(writeNamespace string, readGatewaysFromAllNamespaces bool) Predicate

GetPredicate returns a Predicate for determining which Gateways to process

type RouteConverter added in v1.2.15

type RouteConverter interface {
	// Converts a VirtualService to a set of Gloo API routes (i.e. routes on a Proxy resource).
	// Since virtual services and route tables are often owned by different teams, it breaks multitenancy if
	// this function cannot return successfully; thus ALL ERRORS are added to the resource reports
	ConvertVirtualService(virtualService *gatewayv1.VirtualService, gateway *gatewayv1.Gateway, proxyName string, snapshot *gloov1snap.ApiSnapshot, reports reporter.ResourceReports) []*gloov1.Route
}

func NewRouteConverter added in v1.2.15

func NewRouteConverter(selector RouteTableSelector, indexer RouteTableIndexer) RouteConverter

type RouteTableIndexer added in v1.3.5

type RouteTableIndexer interface {
	// Indexes the given route tables by weight and returns them as a map.
	// The map key set is also returned as a sorted array so the client can range over the map in the desired order.
	// The error slice contain warning about route tables with duplicated weights.
	IndexByWeight(routeTables v1.RouteTableList) (map[int32]v1.RouteTableList, []int32)
}

func NewRouteTableIndexer added in v1.3.5

func NewRouteTableIndexer() RouteTableIndexer

type RouteTableSelector added in v1.3.4

type RouteTableSelector interface {
	SelectRouteTables(action *gatewayv1.DelegateAction, parentNamespace string) (gatewayv1.RouteTableList, error)
}

func NewRouteTableSelector added in v1.3.4

func NewRouteTableSelector(allRouteTables gatewayv1.RouteTableList) RouteTableSelector

type SingleNamespacePredicate added in v1.9.25

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

SingleNamespacePredicate returns true if a Gateway is in the same namespace as the one Gloo controllers are configured to write to. When this predicate is used, Gloo will only read gateways from the same namespace that it writes to

func (*SingleNamespacePredicate) ReadGateway added in v1.9.25

func (s *SingleNamespacePredicate) ReadGateway(gw *v1.Gateway) bool

type SourceMetadata added in v1.0.0

type SourceMetadata struct {
	Sources []SourceRef `json:"sources"`
}

func GetSourceMeta added in v1.0.0

func GetSourceMeta(obj ObjectWithMetadata) (*SourceMetadata, error)

type SourceRef added in v0.18.41

type SourceRef struct {
	*core.ResourceRef
	ResourceKind       string `json:"kind"`
	ObservedGeneration int64  `json:"observedGeneration"`
}

type TcpGatewaySelector added in v1.14.4

type TcpGatewaySelector interface {
	SelectMatchableTcpGateways(selector *v1.DelegatedTcpGateway, onError func(err error)) v1.MatchableTcpGatewayList
}

type TcpTranslator added in v0.18.0

type TcpTranslator struct{}

func (*TcpTranslator) ComputeListener added in v1.9.25

func (t *TcpTranslator) ComputeListener(params Params, proxyName string, gateway *v1.Gateway) *gloov1.Listener

func (*TcpTranslator) ComputeTcpListener added in v1.9.25

func (t *TcpTranslator) ComputeTcpListener(tcpGateway *v1.TcpGateway) *gloov1.TcpListener

type Translator added in v0.18.0

type Translator interface {
	Translate(ctx context.Context, proxyName string, snap *gloov1snap.ApiSnapshot, filteredGateways v1.GatewayList) (*gloov1.Proxy, reporter.ResourceReports)
}

Translator converts a set of Gateways into a Proxy, with the provided proxyName

type ValidationOpts added in v1.0.0

type ValidationOpts struct {
	ProxyValidationServerAddress string
	ValidatingWebhookPort        int
	ValidatingWebhookCertPath    string
	ValidatingWebhookKeyPath     string
	AlwaysAcceptResources        bool
	AllowWarnings                bool
	WarnOnRouteShortCircuiting   bool
}

type VirtualServiceTranslator added in v1.9.25

type VirtualServiceTranslator struct {
	WarnOnRouteShortCircuiting bool
}

VirtualServiceTranslator converts a set of VirtualServices for a particular Gateway into a corresponding set of VirtualHosts

func (*VirtualServiceTranslator) ComputeVirtualHosts added in v1.9.25

func (v *VirtualServiceTranslator) ComputeVirtualHosts(
	params Params,
	parentGateway *v1.Gateway,
	virtualServicesForHttpGateway v1.VirtualServiceList,
	proxyName string,
) []*gloov1.VirtualHost

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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