namer

package
v1.30.1 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// V1NamingScheme is v1 frontend naming scheme.
	V1NamingScheme = Scheme("v1")
	// V2NamingScheme is v2 frontend naming scheme.
	V2NamingScheme = Scheme("v2")
)

Variables

This section is empty.

Functions

func FinalizerForNamingScheme

func FinalizerForNamingScheme(scheme Scheme) (string, error)

FinalizerForNamingScheme returns finalizer corresponding to given frontend naming scheme.

func GetSuffixedName added in v1.22.0

func GetSuffixedName(name string, suffix string) string

func TrimFieldsEvenly

func TrimFieldsEvenly(max int, fields ...string) []string

TrimFieldsEvenly trims the fields evenly and keeps the total length <= max. Truncation is spread in ratio with their original length, meaning smaller fields will be truncated less than longer ones.

Types

type BackendNamer

type BackendNamer interface {
	// IGBackend constructs the name for a backend service targeting instance groups.
	IGBackend(nodePort int64) string
	// NEG returns the gce neg name based on the service namespace, name
	// and target port.
	NEG(namespace, name string, Port int32) string
	// RXLBBackendName returns the Regional External Ingress backend name,
	// based on the service namespace, name and target port.
	RXLBBackendName(namespace, name string, port int32) string
	// L4Backend returns the name for L4 LB backend resources, based on the service namespace and name.
	// It supports ILB with subsetting enabled (VM_IP_NEGs) and NetLB with RBS enabled.
	// The second output parameter indicates if the namer is supported.
	L4Backend(namespace, name string) string
	// InstanceGroup constructs the name for an Instance Group.
	InstanceGroup() string
	// NamedPort returns the name for a named port.
	NamedPort(port int64) string
	// NameBelongsToCluster checks if a given backend resource name is tagged with
	// this cluster's UID.
	NameBelongsToCluster(resourceName string) bool
}

BackendNamer is an interface to name GCE backend resources. It wraps backend naming policy of namer.Namer.

type FrontendNamerFactory

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

FrontendNamerFactory implements IngressFrontendNamerFactory.

func (*FrontendNamerFactory) Namer

Namer implements IngressFrontendNamerFactory.

func (*FrontendNamerFactory) NamerForLoadBalancer added in v1.9.0

func (rn *FrontendNamerFactory) NamerForLoadBalancer(lbName LoadBalancerName) IngressFrontendNamer

NamerForLoadBalancer implements IngressFrontendNamerFactory.

type IngressFrontendNamer

type IngressFrontendNamer interface {
	// ForwardingRule returns the name of the gce forwarding rule for given protocol.
	ForwardingRule(protocol NamerProtocol) string
	// TargetProxy returns the name of the gce target proxy for given protocol.
	TargetProxy(protocol NamerProtocol) string
	// UrlMap returns the name of the URL Map.
	UrlMap() string
	// RedirectUrlMap returns the name of the URL Map and if the namer supports naming redirectUrlMap
	RedirectUrlMap() (string, bool)
	// SSLCertName returns the SSL certificate name given secret hash.
	SSLCertName(secretHash string) string
	// IsCertNameForLB returns true if certName belongs to this ingress.
	IsCertNameForLB(certName string) bool
	// IsLegacySSLCert returns true if certName follows the older naming convention
	// and cert is managed by this ingress.
	// old naming convention is of the form k8s-ssl-<lbName> or k8s-ssl-1-<lbName>.
	IsLegacySSLCert(certName string) bool
	// LoadBalancer returns load-balancer name for the ingress.
	LoadBalancer() LoadBalancerName
	// IsValidLoadBalancer returns if the derived loadbalancer is valid.
	IsValidLoadBalancer() bool
}

IngressFrontendNamer is an interface to name GCE frontend resources.

type IngressFrontendNamerFactory

type IngressFrontendNamerFactory interface {
	// Namer returns IngressFrontendNamer for given ingress.
	Namer(ing *v1.Ingress) IngressFrontendNamer
	// NamerForLoadBalancer returns IngressFrontendNamer given a load-balancer
	// name. This used only for v1 naming scheme.
	NamerForLoadBalancer(loadBalancer LoadBalancerName) IngressFrontendNamer
}

IngressFrontendNamerFactory is an interface to create a front namer for an Ingress a load balancer.

func NewFrontendNamerFactory

func NewFrontendNamerFactory(namer *Namer, kubeSystemUID types.UID, logger klog.Logger) IngressFrontendNamerFactory

NewFrontendNamerFactory returns IngressFrontendNamerFactory given a v1 namer and kube-system uid.

type L4Namer added in v1.10.4

type L4Namer struct {
	// Namer is needed to implement all methods required by BackendNamer interface.
	*Namer
	// contains filtered or unexported fields
}

L4Namer implements naming scheme for L4 LoadBalancer resources. This uses the V2 Naming scheme Example: For Service - namespace/svc, clusterUID/clusterName - uid01234, prefix - k8s2, protocol TCP Assume that hash("uid01234;svc;namespace") = cysix1wq The resource names are - TCP Forwarding Rule : k8s2-tcp-uid01234-namespace-svc-cysix1wq UDP Forwarding Rule : k8s2-udp-uid01234-namespace-svc-cysix1wq All other resources : k8s2-uid01234-namespace-svc-cysix1wq The "namespace-svc" part of the string will be trimmed as needed.

func NewL4Namer added in v1.10.4

func NewL4Namer(kubeSystemUID string, namer *Namer) *L4Namer

func (*L4Namer) IsNEG added in v1.10.4

func (namer *L4Namer) IsNEG(name string) bool

IsNEG indicates if the given name is a NEG following the L4 naming convention.

func (*L4Namer) L4Backend added in v1.15.0

func (namer *L4Namer) L4Backend(namespace, name string) string

L4Backend returns the gce L4 Backend name based on the service namespace and name Naming convention:

k8s2-{uid}-{ns}-{name}-{suffix}

Output name is at most 63 characters.

func (*L4Namer) L4Firewall added in v1.20.0

func (namer *L4Namer) L4Firewall(namespace, name string) string

L4Firewall returns the gce Firewall name based on the service namespace and name Naming convention:

k8s2-{uid}-{ns}-{name}-{suffix}

Output name is at most 63 characters. This name is identical to L4Backend.

func (*L4Namer) L4ForwardingRule added in v1.10.4

func (namer *L4Namer) L4ForwardingRule(namespace, name, protocol string) string

L4ForwardingRule returns the name of the L4 forwarding rule name based on the service namespace, name and protocol. Naming convention:

k8s2-{protocol}-{uid}-{ns}-{name}-{suffix}

Output name is at most 63 characters.

func (*L4Namer) L4HealthCheck added in v1.10.4

func (namer *L4Namer) L4HealthCheck(namespace, name string, shared bool) string

L4HealthCheck returns the name of the L4 LB Healthcheck

func (*L4Namer) L4HealthCheckFirewall added in v1.20.0

func (namer *L4Namer) L4HealthCheckFirewall(namespace, name string, shared bool) string

L4HealthCheckFirewall returns the name of the L4 LB Healthcheck Firewall

func (*L4Namer) L4IPv6Firewall added in v1.21.0

func (namer *L4Namer) L4IPv6Firewall(namespace, name string) string

L4IPv6Firewall returns the gce IPv6 Firewall name based on the service namespace and name Naming convention:

k8s2-{uid}-{ns}-{name}-{suffix}-ipv6

Output name is at most 63 characters.

func (*L4Namer) L4IPv6ForwardingRule added in v1.21.0

func (namer *L4Namer) L4IPv6ForwardingRule(namespace, name, protocol string) string

L4IPv6ForwardingRule returns the name of the L4 forwarding rule name based on the service namespace, name and protocol. Naming convention:

k8s2-{protocol}-{uid}-{ns}-{name}-{suffix}

Output name is at most 63 characters.

func (*L4Namer) L4IPv6HealthCheckFirewall added in v1.21.0

func (namer *L4Namer) L4IPv6HealthCheckFirewall(namespace, name string, shared bool) string

L4IPv6HealthCheckFirewall returns the name of the IPv6 L4 LB health check firewall rule.

type L4ResourcesNamer added in v1.10.4

type L4ResourcesNamer interface {
	// BackendNamer is included so implementations of this interface can be used along with backendPools for linking VM_IP_NEGs.
	BackendNamer
	// L4ForwardingRule returns the name of the forwarding rule for the given service and protocol.
	L4ForwardingRule(namespace, name, protocol string) string
	// L4Firewall returns the name of the firewall rule for the given service
	L4Firewall(namespace, name string) string
	// L4IPv6Firewall returns the name of the ipv6 firewall rule for the given service
	L4IPv6Firewall(namespace, name string) string
	// L4HealthCheck returns the names of the Healthcheck
	L4HealthCheck(namespace, name string, shared bool) string
	// L4HealthCheckFirewall returns the names of the Healthcheck Firewall
	L4HealthCheckFirewall(namespace, name string, shared bool) string
	// L4IPv6ForwardingRule returns the name of the IPv6 forwarding rule for the given service and protocol.
	L4IPv6ForwardingRule(namespace, name, protocol string) string
	// L4IPv6HealthCheckFirewall returns the name of the IPv6 L4 LB health check firewall rule.
	L4IPv6HealthCheckFirewall(namespace, name string, shared bool) string
	// IsNEG returns if the given name is a VM_IP_NEG name.
	IsNEG(name string) bool
}

L4ResourcesNamer is an interface to name L4 LoadBalancing resources.

type LoadBalancerName added in v1.9.0

type LoadBalancerName string

LoadBalancerName is the name of a GCE load-balancer for an ingress.

func (LoadBalancerName) String added in v1.9.0

func (lbName LoadBalancerName) String() string

String typecasts LoadBalancerName to string type.

type NameComponents

type NameComponents struct {
	ClusterName, Resource, Metadata, LbNamePrefix string
}

NameComponents is a struct representing the components of a a GCE resource name constructed by the namer. The format of such a name is: k8s-resource-<metadata, eg port>--uid Note that the LbNamePrefix field is empty if the resource is a BackendService.

type Namer

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

Namer is the centralized naming policy for Ingress-related GCP resources.

func NewNamer

func NewNamer(clusterName, firewallName string, logger klog.Logger) *Namer

NewNamer creates a new namer with a Cluster and Firewall name.

func NewNamerWithPrefix

func NewNamerWithPrefix(prefix, clusterName, firewallName string, logger klog.Logger) *Namer

NewNamerWithPrefix creates a new namer with a custom prefix.

func (*Namer) Firewall

func (n *Namer) Firewall() string

Firewall returns the firewall name of this cluster.

func (*Namer) FirewallRule

func (n *Namer) FirewallRule() string

FirewallRule constructs the full firewall rule name, this is the name assigned by the cloudprovider lib + suffix from glbc, so we don't mix this rule with a rule created for L4 loadbalancing.

func (*Namer) ForwardingRule

func (n *Namer) ForwardingRule(lbName LoadBalancerName, protocol NamerProtocol) string

ForwardingRule returns the name of the forwarding rule prefix.

func (*Namer) IGBackend

func (n *Namer) IGBackend(port int64) string

IGBackend constructs the name for a backend service targeting instance groups.

func (*Namer) IGBackendPort

func (n *Namer) IGBackendPort(beName string) (string, error)

IGBackendPort retrieves the port from the given backend name.

func (*Namer) InstanceGroup

func (n *Namer) InstanceGroup() string

InstanceGroup constructs the name for an Instance Group.

func (*Namer) IsCertUsedForLB

func (n *Namer) IsCertUsedForLB(lbName LoadBalancerName, resourceName string) bool

IsCertUsedForLB returns true if the resourceName belongs to this cluster's ingress. It checks that the hashed lbName exists and

func (*Namer) IsLegacySSLCert

func (n *Namer) IsLegacySSLCert(lbName LoadBalancerName, resourceName string) bool

IsLegacySSLCert returns true if certName is an Ingress managed name following the older naming convention. The check also ensures that the cert is managed by the specific ingress instance - lbName

func (*Namer) IsNEG

func (n *Namer) IsNEG(name string) bool

IsNEG returns true if the name is a NEG owned by this cluster. It checks that the UID is present and a substring of the cluster uid, since the NEG naming schema truncates it to 8 characters. This is only valid for NEGs, BackendServices and Healthchecks for NEG.

func (*Namer) L4Backend added in v1.15.0

func (namer *Namer) L4Backend(namespace, name string) string

L4Backend is only supported by L4Namer.

func (*Namer) LoadBalancer

func (n *Namer) LoadBalancer(key string) LoadBalancerName

LoadBalancer constructs a loadbalancer name from the given key. The key is usually the namespace/name of a Kubernetes Ingress.

func (*Namer) LoadBalancerForURLMap added in v1.9.0

func (n *Namer) LoadBalancerForURLMap(urlMap string) LoadBalancerName

LoadBalancerForURLMap returns the loadbalancer name for given URL map.

func (*Namer) NEG

func (n *Namer) NEG(namespace, name string, port int32) string

NEG returns the gce neg name based on the service namespace, name and target port. NEG naming convention:

{prefix}{version}-{clusterid}-{namespace}-{name}-{service port}-{hash}

Output name is at most 63 characters. NEG tries to keep as much information as possible.

WARNING: Controllers depend on the naming pattern to get the list of all NEGs associated with the current cluster. Any modifications must be backward compatible.

func (*Namer) NameBelongsToCluster

func (n *Namer) NameBelongsToCluster(name string) bool

NameBelongsToCluster checks if a given name is tagged with this cluster's UID.

func (*Namer) NamedPort

func (n *Namer) NamedPort(port int64) string

NamedPort returns the name for a named port.

func (*Namer) ParseName

func (n *Namer) ParseName(name string) *NameComponents

ParseName parses the name of a resource generated by the namer. This is only valid for the following resources:

Backend, InstanceGroup, UrlMap.

func (*Namer) RXLBBackendName added in v1.29.0

func (n *Namer) RXLBBackendName(namespace, name string, port int32) string

RXLBBackendName returns the gce Backend name based on the service namespace, name and target port. Naming convention:

{prefix}{version}-{clusterid}-e-{namespace}-{name}-{service port}-{hash}

Output name is at most 63 characters.

func (*Namer) RedirectUrlMap added in v1.10.0

func (n *Namer) RedirectUrlMap(lbName LoadBalancerName) string

RedirectUrlMap returns the name for the UrlMap for a given load balancer.

func (*Namer) SSLCertName

func (n *Namer) SSLCertName(lbName LoadBalancerName, secretHash string) string

SSLCertName returns the name of the certificate.

func (*Namer) SetFirewall

func (n *Namer) SetFirewall(name string)

SetFirewall sets the firewall name of this cluster.

func (*Namer) SetUID

func (n *Namer) SetUID(name string)

SetUID sets the UID/name of this cluster.

func (*Namer) TargetProxy

func (n *Namer) TargetProxy(lbName LoadBalancerName, protocol NamerProtocol) string

TargetProxy returns the name for target proxy given the load balancer name and the protocol.

func (*Namer) UID

func (n *Namer) UID() string

UID returns the UID/name of this cluster. WARNING: Use KubeSystemUID instead

func (*Namer) UrlMap

func (n *Namer) UrlMap(lbName LoadBalancerName) string

UrlMap returns the name for the UrlMap for a given load balancer.

type NamerProtocol

type NamerProtocol string

NamerProtocol is an enum for the different protocols given as parameters to Namer.

const (
	HTTPProtocol  NamerProtocol = "HTTP"
	HTTPSProtocol NamerProtocol = "HTTPS"
)

type Scheme

type Scheme string

Scheme is ingress frontend name scheme.

func FrontendNamingScheme

func FrontendNamingScheme(ing *v1.Ingress, logger klog.Logger) Scheme

FrontendNamingScheme returns naming scheme for given ingress based on its finalizer.

type ServiceAttachmentNamer added in v1.11.0

type ServiceAttachmentNamer interface {
	// ServiceAttachment returns the name of the GCE Service Attachment resource for the given namespace,
	// name, and Service Attachment CR UID
	ServiceAttachment(namespace, name, saUID string) string
}

func NewServiceAttachmentNamer added in v1.11.0

func NewServiceAttachmentNamer(namer *Namer, kubeSystemUID string) ServiceAttachmentNamer

NewServiceAttachmentNamer returns a v1 namer for Service Attachments

type V1FrontendNamer

type V1FrontendNamer interface {
	// LoadBalancer constructs a loadbalancer name from the given ingress key.
	LoadBalancer(ingKey string) LoadBalancerName
	// LoadBalancerForURLMap returns the loadbalancer name for given URL map.
	LoadBalancerForURLMap(urlMap string) LoadBalancerName
	// NameBelongsToCluster checks if a given frontend resource name is tagged with
	// this cluster's UID.
	NameBelongsToCluster(resourceName string) bool
}

V1FrontendNamer wraps frontend naming policy helper functions of namer.Namer.

type V1IngressFrontendNamer

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

V1IngressFrontendNamer implements IngressFrontendNamer. This is a wrapper on top of namer.Namer.

func (*V1IngressFrontendNamer) ForwardingRule

func (ln *V1IngressFrontendNamer) ForwardingRule(protocol NamerProtocol) string

ForwardingRule implements IngressFrontendNamer.

func (*V1IngressFrontendNamer) IsCertNameForLB

func (ln *V1IngressFrontendNamer) IsCertNameForLB(certName string) bool

IsCertNameForLB implements IngressFrontendNamer.

func (*V1IngressFrontendNamer) IsLegacySSLCert

func (ln *V1IngressFrontendNamer) IsLegacySSLCert(certName string) bool

IsLegacySSLCert implements IngressFrontendNamer.

func (*V1IngressFrontendNamer) IsValidLoadBalancer added in v1.11.0

func (ln *V1IngressFrontendNamer) IsValidLoadBalancer() bool

IsValidLoadBalancer implements IngressFrontendNamer.

func (*V1IngressFrontendNamer) LoadBalancer added in v1.9.0

func (ln *V1IngressFrontendNamer) LoadBalancer() LoadBalancerName

LoadBalancer implements IngressFrontendNamer.

func (*V1IngressFrontendNamer) RedirectUrlMap added in v1.10.0

func (ln *V1IngressFrontendNamer) RedirectUrlMap() (string, bool)

RedirectUrlMap implements IngressFrontendNamer.

func (*V1IngressFrontendNamer) SSLCertName

func (ln *V1IngressFrontendNamer) SSLCertName(secretHash string) string

SSLCertName implements IngressFrontendNamer.

func (*V1IngressFrontendNamer) TargetProxy

func (ln *V1IngressFrontendNamer) TargetProxy(protocol NamerProtocol) string

TargetProxy implements IngressFrontendNamer.

func (*V1IngressFrontendNamer) UrlMap

func (ln *V1IngressFrontendNamer) UrlMap() string

UrlMap implements IngressFrontendNamer.

type V1ServiceAttachmentNamer added in v1.11.0

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

V1ServiceAttachment implements ServiceAttachmentNamer. This is a wrapper on top of namer.Namer.

func (*V1ServiceAttachmentNamer) ServiceAttachment added in v1.11.0

func (n *V1ServiceAttachmentNamer) ServiceAttachment(namespace, name, saUID string) string

ServiceAttachment returns the gce ServiceAttachment name based on the service attachment name, and namespace. Service Attachment naming convention:

k8s{naming version}-sa-{cluster-uid}-{namespace}-{name}-{hash} Output name is at most 63 characters. Hash is generated from the KubeSystemUID, Namespace, Name, and Service Attachment UID Cluster UID will be 8 characters, hash suffix will be 8 characters

WARNING: Controllers will use the naming convention to correlate between the Service Attachment CR and service attachment resource in GCE, so modifications must be backwards compatible.

type V2IngressFrontendNamer

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

V2IngressFrontendNamer implements IngressFrontendNamer.

func (*V2IngressFrontendNamer) ForwardingRule

func (vn *V2IngressFrontendNamer) ForwardingRule(protocol NamerProtocol) string

ForwardingRule returns the name of forwarding rule based on given protocol.

func (*V2IngressFrontendNamer) IsCertNameForLB

func (vn *V2IngressFrontendNamer) IsCertNameForLB(certName string) bool

IsCertNameForLB returns true if the certName belongs to this cluster's ingress. It checks that the hashed lbName exists.

func (*V2IngressFrontendNamer) IsLegacySSLCert

func (vn *V2IngressFrontendNamer) IsLegacySSLCert(certName string) bool

IsLegacySSLCert always return false as v2 naming scheme does not use legacy certs.

func (*V2IngressFrontendNamer) IsValidLoadBalancer added in v1.11.0

func (vn *V2IngressFrontendNamer) IsValidLoadBalancer() bool

IsValidLoadBalancer implements IngressFrontendNamer.

func (*V2IngressFrontendNamer) LoadBalancer added in v1.9.0

func (vn *V2IngressFrontendNamer) LoadBalancer() LoadBalancerName

LoadBalancer returns loadbalancer name. Note that this is used for generating GCE resource names.

func (*V2IngressFrontendNamer) RedirectUrlMap added in v1.10.0

func (vn *V2IngressFrontendNamer) RedirectUrlMap() (string, bool)

RedirectUrlMap returns the name of Redirect URL map.

func (*V2IngressFrontendNamer) SSLCertName

func (vn *V2IngressFrontendNamer) SSLCertName(secretHash string) string

SSLCertName returns the name of the certificate.

func (*V2IngressFrontendNamer) TargetProxy

func (vn *V2IngressFrontendNamer) TargetProxy(protocol NamerProtocol) string

TargetProxy returns the name of target proxy based on given protocol.

func (*V2IngressFrontendNamer) UrlMap

func (vn *V2IngressFrontendNamer) UrlMap() string

UrlMap returns the name of URL map.

Jump to

Keyboard shortcuts

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