common

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KuadrantRateLimitClusterName       = "kuadrant-rate-limiting-service"
	HTTPRouteKind                      = "HTTPRoute"
	RateLimitPoliciesBackRefAnnotation = "kuadrant.io/ratelimitpolicies"
	RateLimitPolicyBackRefAnnotation   = "kuadrant.io/ratelimitpolicy"
	AuthPoliciesBackRefAnnotation      = "kuadrant.io/authpolicies"
	AuthPolicyBackRefAnnotation        = "kuadrant.io/authpolicy"
	KuadrantNamespaceLabel             = "kuadrant.io/namespace"
	NamespaceSeparator                 = '/'
	LimitadorName                      = "limitador"
)

TODO: move the const to a proper place, or get it from config

View Source
const (
	DeleteTagAnnotation      = "kuadrant.io/delete"
	ReadyStatusConditionType = "Ready"
)

Variables

This section is empty.

Functions

func AnnotateObject added in v0.2.0

func AnnotateObject(obj client.Object, namespace string)

func ConditionMarshal

func ConditionMarshal(conditions []metav1.Condition) ([]byte, error)

ConditionMarshal marshals the set of conditions as a JSON array, sorted by condition type.

func Contains added in v0.2.0

func Contains(slice []string, target string) bool

func ContainsObjectKey added in v0.2.0

func ContainsObjectKey(a []client.ObjectKey, x client.ObjectKey) bool

ContainsObjectKey tells whether a contains x

func CopyConditions

func CopyConditions(conditions []metav1.Condition) []metav1.Condition

CopyConditions copies the set of conditions

func DecodeFile

func DecodeFile(ctx context.Context, fileData []byte, scheme *runtime.Scheme, cb DecodeCallback) error

func DeleteKuadrantAnnotationFromGateway added in v0.2.0

func DeleteKuadrantAnnotationFromGateway(gw *gatewayapiv1alpha2.Gateway, namespace string)

func FetchEnv

func FetchEnv(key string, def string) string

func Find added in v0.3.0

func Find[T any](slice []T, match func(T) bool) (*T, bool)

func FindAuthorinoStatusCondition

func FindAuthorinoStatusCondition(conditions []authorinov1beta1.Condition, conditionType string) *authorinov1beta1.Condition

func FindDeploymentStatusCondition

func FindDeploymentStatusCondition(conditions []appsv1.DeploymentCondition, conditionType string) *appsv1.DeploymentCondition

func FindObjectKey added in v0.2.0

func FindObjectKey(a []client.ObjectKey, x client.ObjectKey) int

FindObjectKey returns the smallest index i at which x == a[i], or len(a) if there is no such index.

func GetDefaultIfNil added in v0.2.0

func GetDefaultIfNil[T any](val *T, def T) T

func GetEmptySliceIfNil added in v0.3.0

func GetEmptySliceIfNil[T any](val []T) []T

func GetGatewayWorkloadSelector added in v0.3.0

func GetGatewayWorkloadSelector(ctx context.Context, cli client.Client, gateway *gatewayapiv1alpha2.Gateway) (map[string]string, error)

func GetKuadrantNamespace added in v0.2.0

func GetKuadrantNamespace(obj client.Object) (string, error)

func GetNamespaceFromPolicy added in v0.2.0

func GetNamespaceFromPolicy(policy KuadrantPolicy) (string, bool)

func GetNamespaceFromPolicyTargetRef added in v0.2.0

func GetNamespaceFromPolicyTargetRef(ctx context.Context, cli client.Client, policy KuadrantPolicy) (string, error)

func GetService added in v0.3.0

func GetService(ctx context.Context, k8sClient client.Client, serviceKey client.ObjectKey) (*corev1.Service, error)

func GetServicePortNumber added in v0.2.0

func GetServicePortNumber(ctx context.Context, k8sClient client.Client, serviceKey client.ObjectKey, servicePort string) (int32, error)

GetServicePortNumber returns the port number from the referenced key and port info the port info can be named port or already a number.

func GetServiceWorkloadSelector added in v0.3.0

func GetServiceWorkloadSelector(ctx context.Context, k8sClient client.Client, serviceKey client.ObjectKey) (map[string]string, error)

func HostnamesToStrings added in v0.2.0

func HostnamesToStrings(hostnames []gatewayapiv1alpha2.Hostname) []string

HostnamesToStrings converts []gatewayapi_v1alpha2.Hostname to []string

func IsKuadrantManaged added in v0.2.0

func IsKuadrantManaged(obj client.Object) bool

func IsObjectTaggedToDelete

func IsObjectTaggedToDelete(obj client.Object) bool

func IsOwnedBy

func IsOwnedBy(owned, owner client.Object) bool

func IsTargetRefGateway added in v0.2.0

func IsTargetRefGateway(targetRef gatewayapiv1alpha2.PolicyTargetReference) bool

func IsTargetRefHTTPRoute added in v0.2.0

func IsTargetRefHTTPRoute(targetRef gatewayapiv1alpha2.PolicyTargetReference) bool

func IstioWorkloadSelectorFromGateway added in v0.3.0

func IstioWorkloadSelectorFromGateway(ctx context.Context, k8sClient client.Client, gateway *gatewayapiv1alpha2.Gateway) *istiocommon.WorkloadSelector

func Map added in v0.3.0

func Map[T, U any](slice []T, f func(T) U) []U

func MarshallNamespace added in v0.2.0

func MarshallNamespace(gwKey client.ObjectKey, domain string) string

MarshallNamespace serializes limit namespace with format "gwNS/gwName#domain"

func MergeMapStringString added in v0.2.0

func MergeMapStringString(existing *map[string]string, desired map[string]string) bool

MergeMapStringString Merge desired into existing. Not Thread-Safe. Does it matter?

func NamespacedNameToObjectKey added in v0.2.0

func NamespacedNameToObjectKey(namespacedName, defaultNamespace string) client.ObjectKey

NamespacedNameToObjectKey converts <namespace/name> format string to k8s object key. It's common for K8s to reference an object using this format. For e.g. gateways in VirtualService.

func ObjectInfo

func ObjectInfo(obj client.Object) string

func ObjectKeyListDifference

func ObjectKeyListDifference(a, b []client.ObjectKey) []client.ObjectKey

ObjectKeyListDifference computest a - b

func ReadAnnotationsFromObject added in v0.3.0

func ReadAnnotationsFromObject(obj client.Object) map[string]string

func ReverseSlice added in v0.3.0

func ReverseSlice[T any](input []T) []T

func RouteHTTPMethodToRuleMethod added in v0.2.0

func RouteHTTPMethodToRuleMethod(httpMethod *gatewayapiv1alpha2.HTTPMethod) []string

func RouteHostnames added in v0.2.0

func RouteHostnames(route *gatewayapiv1alpha2.HTTPRoute) []string

func SliceCopy added in v0.3.0

func SliceCopy[T any](s1 []T) []T

func StatusConditionsMarshalJSON added in v0.2.0

func StatusConditionsMarshalJSON(input []metav1.Condition) ([]byte, error)

StatusConditionsMarshalJSON marshals the list of conditions as a JSON array, sorted by condition type.

func TagObjectToDelete

func TagObjectToDelete(obj client.Object)

func TargetHostnames added in v0.3.0

func TargetHostnames(targetNetworkObject client.Object) ([]string, error)

TargetHostnames returns an array of hostnames coming from the network object (HTTPRoute, Gateway)

func UnMarshallLimitNamespace added in v0.2.0

func UnMarshallLimitNamespace(ns string) (client.ObjectKey, string, error)

UnMarshallLimitNamespace parses limit namespace with format "gwNS/gwName#domain"

func UnMarshallObjectKey added in v0.2.0

func UnMarshallObjectKey(keyStr string) (client.ObjectKey, error)

func ValidSubdomains added in v0.2.0

func ValidSubdomains(domains, subdomains []string) (bool, string)

ValidSubdomains returns (true, "") when every single subdomains item is a subset of at least one of the domains. Domains and subdomains may be prefixed with a wildcard label (*.). The wildcard label must appear by itself as the first label. When one of the subdomains is not a subset of any of the domains, it returns false and the subdomain not being subset of any of the domains

func ValidateHierarchicalRules added in v0.3.0

func ValidateHierarchicalRules(policy KuadrantPolicy, targetNetworkObject client.Object) error

ValidateHierarchicalRules returns error if the policy rules hostnames fail to match the target network hosts

Types

type DecodeCallback

type DecodeCallback = func(runtime.Object) error

type GatewayWrapper added in v0.3.0

type GatewayWrapper struct {
	*gatewayapiv1alpha2.Gateway
	PolicyRefsConfig
}

GatewayWrapper wraps a Gateway API Gateway adding methods and configs to manage policy references in annotations

func GatewaysMissingPolicyRef added in v0.3.0

func GatewaysMissingPolicyRef(gwList *gatewayapiv1alpha2.GatewayList, policyKey client.ObjectKey, policyGwKeys []client.ObjectKey, config PolicyRefsConfig) []GatewayWrapper

func GatewaysWithInvalidPolicyRef added in v0.3.0

func GatewaysWithInvalidPolicyRef(gwList *gatewayapiv1alpha2.GatewayList, policyKey client.ObjectKey, policyGwKeys []client.ObjectKey, config PolicyRefsConfig) []GatewayWrapper

func GatewaysWithValidPolicyRef added in v0.3.0

func GatewaysWithValidPolicyRef(gwList *gatewayapiv1alpha2.GatewayList, policyKey client.ObjectKey, policyGwKeys []client.ObjectKey, config PolicyRefsConfig) []GatewayWrapper

func (GatewayWrapper) AddPolicy added in v0.3.0

func (g GatewayWrapper) AddPolicy(policyKey client.ObjectKey) bool

AddPolicy tries to add a policy to the existing ref list. Returns true if policy was added, false otherwise

func (GatewayWrapper) ContainsPolicy added in v0.3.0

func (g GatewayWrapper) ContainsPolicy(policyKey client.ObjectKey) bool

func (GatewayWrapper) DeletePolicy added in v0.3.0

func (g GatewayWrapper) DeletePolicy(policyKey client.ObjectKey) bool

DeletePolicy tries to delete a policy from the existing ref list. Returns true if the policy was deleted, false otherwise

func (GatewayWrapper) Hostnames added in v0.3.0

func (g GatewayWrapper) Hostnames() []string

Hostnames builds a list of hostnames from the listeners.

func (GatewayWrapper) Key added in v0.3.0

func (GatewayWrapper) PolicyRefs added in v0.3.0

func (g GatewayWrapper) PolicyRefs() []client.ObjectKey

type HTTPRouteRule added in v0.2.0

type HTTPRouteRule struct {
	Paths   []string
	Methods []string
	Hosts   []string
}

func RulesFromHTTPRoute added in v0.2.0

func RulesFromHTTPRoute(route *gatewayapiv1alpha2.HTTPRoute) []HTTPRouteRule

RulesFromHTTPRoute computes a list of rules from the HTTPRoute object

type KuadrantAuthPolicyRefsConfig added in v0.3.0

type KuadrantAuthPolicyRefsConfig struct{}

func (*KuadrantAuthPolicyRefsConfig) PolicyRefsAnnotation added in v0.3.0

func (c *KuadrantAuthPolicyRefsConfig) PolicyRefsAnnotation() string

type KuadrantPolicy added in v0.2.0

type KuadrantPolicy interface {
	client.Object
	GetTargetRef() gatewayapiv1alpha2.PolicyTargetReference
	GetWrappedNamespace() gatewayapiv1alpha2.Namespace
	GetRulesHostnames() []string
}

type KuadrantRateLimitPolicyRefsConfig added in v0.3.0

type KuadrantRateLimitPolicyRefsConfig struct{}

func (*KuadrantRateLimitPolicyRefsConfig) PolicyRefsAnnotation added in v0.3.0

func (c *KuadrantRateLimitPolicyRefsConfig) PolicyRefsAnnotation() string

type Name added in v0.2.0

type Name string

Name describes a (possibly wildcarded) hostname

func (Name) IsWildCarded added in v0.2.0

func (n Name) IsWildCarded() bool

func (Name) String added in v0.2.0

func (n Name) String() string

func (Name) SubsetOf added in v0.2.0

func (n Name) SubsetOf(o Name) bool

SubsetOf returns true if this hostname is a valid subset of the other hostname. The semantics are the same as "Matches", but only in one direction (i.e., h is covered by o).

type PolicyRefsConfig added in v0.3.0

type PolicyRefsConfig interface {
	PolicyRefsAnnotation() string
}

Jump to

Keyboard shortcuts

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