Documentation ¶
Overview ¶
Package utils contains shared data structures and functions.
Index ¶
- Constants
- Variables
- func EqualMapping(a, b *GCEURLMap) bool
- func EqualResourceIDs(a, b string) bool
- func EqualResourcePaths(a, b string) bool
- func FakeGoogleAPIForbiddenErr() *googleapi.Error
- func FakeGoogleAPINotFoundErr() *googleapi.Error
- func GetNodeConditionPredicate() listers.NodeConditionPredicate
- func GetReadyNodeNames(lister listers.NodeLister) ([]string, error)
- func HasFinalizer(m meta_v1.ObjectMeta, key string) bool
- func IGLinks(igs []*compute.InstanceGroup) (igLinks []string)
- func IgnoreHTTPNotFound(err error) error
- func IngressKeyFunc(ing *extensions.Ingress) string
- func IsDeletionCandidate(m meta_v1.ObjectMeta, key string) bool
- func IsForbiddenError(err error) bool
- func IsGCEIngress(ing *extensions.Ingress) bool
- func IsGCEMultiClusterIngress(ing *extensions.Ingress) bool
- func IsGLBCIngress(ing *extensions.Ingress) bool
- func IsHTTPErrorCode(err error, code int) bool
- func IsInUsedByError(err error) bool
- func IsNotFoundError(err error) bool
- func JoinErrs(errs []error) error
- func KeyName(url string) (string, error)
- func NeedToAddFinalizer(m meta_v1.ObjectMeta, key string) bool
- func NewNamespaceIndexer() cache.Indexers
- func NodeIsReady(node *v1.Node) bool
- func PrettyJson(data interface{}) (string, error)
- func RelativeResourceName(url string) (string, error)
- func ResourcePath(url string) (string, error)
- func ServiceKeyFunc(namespace, name string) string
- func SplitAnnotation(annotation string) []string
- func StrategicMergePatchBytes(old, cur, refStruct interface{}) ([]byte, error)
- func ToNamespacedName(s string) (r types.NamespacedName, err error)
- func TraverseIngressBackends(ing *extensions.Ingress, process func(id ServicePortID) bool)
- func TrimFieldsEvenly(max int, fields ...string) []string
- type Description
- type GCEURLMap
- func (g *GCEURLMap) AllServicePorts() (svcPorts []ServicePort)
- func (g *GCEURLMap) HostExists(hostname string) bool
- func (g *GCEURLMap) PathExists(hostname, path string) (ServicePort, bool)
- func (g *GCEURLMap) PutPathRulesForHost(hostname string, pathRules []PathRule)
- func (g *GCEURLMap) String() string
- type HostRule
- type NameComponents
- type Namer
- func (n *Namer) Firewall() string
- func (n *Namer) FirewallRule() string
- func (n *Namer) ForwardingRule(lbName string, protocol NamerProtocol) string
- func (n *Namer) IGBackend(port int64) string
- func (n *Namer) IGBackendPort(beName string) (string, error)
- func (n *Namer) InstanceGroup() string
- func (n *Namer) IsCertUsedForLB(lbName, resourceName string) bool
- func (n *Namer) IsLegacySSLCert(lbName string, resourceName string) bool
- func (n *Namer) IsNEG(name string) bool
- func (n *Namer) LoadBalancer(key string) string
- func (n *Namer) NEG(namespace, name string, port int32) string
- func (n *Namer) NameBelongsToCluster(name string) bool
- func (n *Namer) NamedPort(port int64) string
- func (n *Namer) ParseName(name string) *NameComponents
- func (n *Namer) SSLCertName(lbName string, secretHash string) string
- func (n *Namer) SetFirewall(name string)
- func (n *Namer) SetUID(name string)
- func (n *Namer) TargetProxy(lbName string, protocol NamerProtocol) string
- func (n *Namer) UID() string
- func (n *Namer) UrlMap(lbName string) string
- type NamerProtocol
- type PathRule
- type PeriodicTaskQueue
- type ServicePort
- type ServicePortID
- type StoreToIngressLister
- func (s *StoreToIngressLister) GetServiceIngress(svc *api_v1.Service, systemDefaultBackend ServicePortID) (ings []extensions.Ingress, err error)
- func (s *StoreToIngressLister) ListAll() (ing extensions.IngressList, err error)
- func (s *StoreToIngressLister) ListGCEIngresses() (ing extensions.IngressList, err error)
- type TaskQueue
- type TimeTracker
Constants ¶
const ( // Add used to record additions in a sync pool. Add = iota // Remove used to record removals from a sync pool. Remove // Sync used to record syncs of a sync pool. Sync // Get used to record Get from a sync pool. Get // Create used to record creations in a sync pool. Create // Update used to record updates in a sync pool. Update // Delete used to record deltions from a sync pool. Delete // AddInstances used to record a call to AddInstances. AddInstances // RemoveInstances used to record a call to RemoveInstances. RemoveInstances // LabelNodeRoleMaster specifies that a node is a master // This is a duplicate definition of the constant in: // kubernetes/kubernetes/pkg/controller/service/service_controller.go LabelNodeRoleMaster = "node-role.kubernetes.io/master" // LabelNodeRoleExcludeBalancer specifies that a node should be excluded from load-balancing // This is a duplicate definition of the constant in: // kubernetes/kubernetes/pkg/controller/service/service_controller.go // This label is feature-gated in kubernetes/kubernetes but we do not have feature gates // This will need to be updated after the end of the alpha LabelNodeRoleExcludeBalancer = "alpha.service-controller.kubernetes.io/exclude-balancer" )
const FinalizerKeySuffix = "finalizer.cloud.google.com"
FinalizerKeySuffix is a suffix for finalizers added by the controller. A full key could be something like "ingress.finalizer.cloud.google.com"
Variables ¶
var (
KeyFunc = cache.DeletionHandlingMetaNamespaceKeyFunc
)
Functions ¶
func EqualMapping ¶ added in v1.2.2
EqualMapping returns true if both maps point to the same ServicePortIDs. ServicePort settings are *not* included in this comparison.
func EqualResourceIDs ¶ added in v1.2.2
EqualResourceIDs returns true if a and b have equal ResourceIDs which entail the project, location, resource type, and resource name.
func EqualResourcePaths ¶ added in v1.2.2
EqualResourcePaths returns true if a and b have equal ResourcePaths. Resource paths entail the location, resource type, and resource name.
func FakeGoogleAPIForbiddenErr ¶
FakeGoogleAPIForbiddenErr creates a Forbidden error with type googleapi.Error
func FakeGoogleAPINotFoundErr ¶
FakeGoogleAPINotFoundErr creates a NotFound error with type googleapi.Error
func GetNodeConditionPredicate ¶ added in v1.3.0
func GetNodeConditionPredicate() listers.NodeConditionPredicate
This is a duplicate definition of the function in: kubernetes/kubernetes/pkg/controller/service/service_controller.go
func GetReadyNodeNames ¶ added in v1.3.0
func GetReadyNodeNames(lister listers.NodeLister) ([]string, error)
GetReadyNodeNames returns names of schedulable, ready nodes from the node lister It also filters out masters and nodes excluded from load-balancing TODO(rramkumar): Add a test for this.
func HasFinalizer ¶ added in v1.4.0
func HasFinalizer(m meta_v1.ObjectMeta, key string) bool
HasFinalizer is true if the passed in meta has the specified finalizer.
func IGLinks ¶ added in v1.2.2
func IGLinks(igs []*compute.InstanceGroup) (igLinks []string)
IGLinks returns a list of links extracted from the passed in list of compute.InstanceGroup's.
func IgnoreHTTPNotFound ¶
IgnoreHTTPNotFound returns the passed err if it's not a GoogleAPI error with a NotFound status code.
func IngressKeyFunc ¶ added in v1.3.2
func IngressKeyFunc(ing *extensions.Ingress) string
func IsDeletionCandidate ¶ added in v1.4.0
func IsDeletionCandidate(m meta_v1.ObjectMeta, key string) bool
IsDeletionCandidate is true if the passed in meta contains the specified finalizer.
func IsForbiddenError ¶
IsForbiddenError returns true if the operation was forbidden
func IsGCEIngress ¶ added in v1.3.0
func IsGCEIngress(ing *extensions.Ingress) bool
IsGCEIngress returns true if the Ingress matches the class managed by this controller.
func IsGCEMultiClusterIngress ¶ added in v1.3.0
func IsGCEMultiClusterIngress(ing *extensions.Ingress) bool
IsGCEMultiClusterIngress returns true if the given Ingress has ingress.class annotation set to "gce-multi-cluster".
func IsGLBCIngress ¶ added in v1.3.2
func IsGLBCIngress(ing *extensions.Ingress) bool
IsGLBCIngress returns true if the given Ingress should be processed by GLBC
func IsHTTPErrorCode ¶
IsHTTPErrorCode checks if the given error matches the given HTTP Error code. For this to work the error must be a googleapi Error.
func IsInUsedByError ¶
IsInUsedByError returns true if the resource is being used by another GCP resource
func IsNotFoundError ¶
IsNotFoundError returns true if the resource does not exist
func JoinErrs ¶ added in v1.4.0
JoinErrs returns an aggregated error based on the passed in list of errors.
func KeyName ¶ added in v1.2.2
KeyName returns the name portion from a full or partial GCP resource URL. Example:
Input: https://googleapis.com/v1/compute/projects/my-project/global/backendServices/my-backend Output: my-backend
func NeedToAddFinalizer ¶ added in v1.4.0
func NeedToAddFinalizer(m meta_v1.ObjectMeta, key string) bool
NeedToAddFinalizer is true if the passed in meta does not contain the specified finalizer.
func NewNamespaceIndexer ¶ added in v1.3.0
NewNamespaceIndexer returns a new Indexer for use by SharedIndexInformers
func NodeIsReady ¶
func PrettyJson ¶ added in v1.2.2
PrettyJson marshals an object in a human-friendly format.
func RelativeResourceName ¶ added in v1.2.2
RelativeResourceName returns the project, location, resource, and name from a full/partial GCP resource URL. This removes the endpoint prefix and version. Example:
Input: https://googleapis.com/v1/compute/projects/my-project/global/backendServices/my-backend Output: projects/my-project/global/backendServices/my-backend
func ResourcePath ¶ added in v1.2.2
ResourcePath returns the location, resource and name portion from a full or partial GCP resource URL. This removes the endpoint prefix, version, and project. Example:
Input: https://googleapis.com/v1/compute/projects/my-project/global/backendServices/my-backend Output: global/backendServices/my-backend
func ServiceKeyFunc ¶ added in v1.4.0
func SplitAnnotation ¶ added in v1.4.0
SplitAnnotation splits annotation by separator and trims whitespace from each resulting token
func StrategicMergePatchBytes ¶ added in v1.4.0
StrategicMergePatchBytes returns a patch between the old and new object using a strategic merge patch. Note: refStruct is a empty struct of the type which the patch is being generated for.
func ToNamespacedName ¶ added in v1.2.2
func ToNamespacedName(s string) (r types.NamespacedName, err error)
ToNamespacedName returns a types.NamespacedName struct parsed from namespace/name.
func TraverseIngressBackends ¶ added in v1.3.2
func TraverseIngressBackends(ing *extensions.Ingress, process func(id ServicePortID) bool)
TraverseIngressBackends traverse thru all backends specified in the input ingress and call process If process return true, then return and stop traversing the backends
func TrimFieldsEvenly ¶ added in v1.4.0
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 Description ¶ added in v1.2.2
type Description struct { ServiceName string `json:"kubernetes.io/service-name"` ServicePort string `json:"kubernetes.io/service-port"` XFeatures []string `json:"x-features,omitempty"` }
Description stores the description for a BackendService.
func DescriptionFromString ¶ added in v1.2.2
func DescriptionFromString(descString string) *Description
DescriptionFromString gets a Description from string,
func (Description) String ¶ added in v1.2.2
func (desc Description) String() string
String returns the string representation of a Description.
type GCEURLMap ¶
type GCEURLMap struct { DefaultBackend *ServicePort // HostRules is an ordered list of hostnames, path rule tuples. HostRules []HostRule // contains filtered or unexported fields }
GCEURLMap is a simplified representation of a UrlMap somewhere in the middle of a compute.UrlMap and rules in an Ingress spec. This representation maintains three invariants/rules:
- All hostnames are unique
- All paths for a specific host are unique.
- Adding paths for a hostname replaces existing for that host.
func NewGCEURLMap ¶ added in v1.2.2
func NewGCEURLMap() *GCEURLMap
NewGCEURLMap returns an empty GCEURLMap
func (*GCEURLMap) AllServicePorts ¶ added in v1.2.2
func (g *GCEURLMap) AllServicePorts() (svcPorts []ServicePort)
AllServicePorts return a list of all ServicePorts contained in the GCEURLMap.
func (*GCEURLMap) HostExists ¶ added in v1.2.2
HostExists returns true if the given hostname is specified in the GCEURLMap.
func (*GCEURLMap) PathExists ¶ added in v1.2.2
func (g *GCEURLMap) PathExists(hostname, path string) (ServicePort, bool)
PathExists returns true if the given path exists for the given hostname. It will also return the backend associated with that path.
func (*GCEURLMap) PutPathRulesForHost ¶ added in v1.2.2
PutPathRulesForHost adds path rules for a single hostname. This function ensures the invariants of the GCEURLMap are maintained. It will log if an invariant violation was found and reconciled. TODO(rramkumar): Surface an error instead of logging.
type NameComponents ¶
type NameComponents struct {
ClusterName, Resource, Metadata 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
type Namer ¶
type Namer struct {
// contains filtered or unexported fields
}
Namer is the centralized naming policy for Ingress-related GCP resources.
func NewNamerWithPrefix ¶
NewNamerWithPrefix creates a new namer with a custom prefix.
func (*Namer) FirewallRule ¶
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 string, protocol NamerProtocol) string
ForwardingRule returns the name of the forwarding rule prefix.
func (*Namer) IGBackend ¶ added in v1.2.2
IGBackend constructs the name for a backend service targeting instance groups.
func (*Namer) IGBackendPort ¶ added in v1.2.2
IGBackendPort retrieves the port from the given backend name.
func (*Namer) InstanceGroup ¶
InstanceGroup constructs the name for an Instance Group.
func (*Namer) IsCertUsedForLB ¶ added in v1.1.0
IsCertUsedForLB returns true if the resourceName belongs to this cluster's ingress. It checks that the hashed lbName exists and
func (*Namer) IsLegacySSLCert ¶ added in v1.1.0
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 ¶
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) LoadBalancer ¶
LoadBalancer constructs a loadbalancer name from the given key. The key is usually the namespace/name of a Kubernetes Ingress.
func (*Namer) NEG ¶
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 ¶
NameBelongsToCluster checks if a given name is tagged with this cluster's UID.
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, TargetProxy, SSLCert, ForwardingRule, UrlMap.
func (*Namer) SSLCertName ¶ added in v1.1.0
SSLCertName returns the name of the certificate.
func (*Namer) SetFirewall ¶
SetFirewall sets the firewall name of this cluster.
func (*Namer) TargetProxy ¶
func (n *Namer) TargetProxy(lbName string, protocol NamerProtocol) string
TargetProxy returns the name for target proxy given the load balancer name and the protocol.
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 PathRule ¶ added in v1.2.2
type PathRule struct { Path string Backend ServicePort }
PathRule encapsulates the information for a single path -> backend mapping.
type PeriodicTaskQueue ¶
type PeriodicTaskQueue struct {
// contains filtered or unexported fields
}
PeriodicTaskQueue invokes the given sync function for every work item inserted. If the sync() function results in an error, the item is put on the work queue after a rate-limit.
func NewPeriodicTaskQueue ¶
func NewPeriodicTaskQueue(resource string, syncFn func(string) error) *PeriodicTaskQueue
NewPeriodicTaskQueue creates a new task queue with the default rate limiter.
func NewPeriodicTaskQueueWithLimiter ¶ added in v1.4.0
func NewPeriodicTaskQueueWithLimiter(resource string, syncFn func(string) error, rl workqueue.RateLimiter) *PeriodicTaskQueue
NewPeriodicTaskQueueWithLimiter creates a new task queue with the given sync function and rate limiter. The sync function is called for every element inserted into the queue.
func (*PeriodicTaskQueue) Enqueue ¶
func (t *PeriodicTaskQueue) Enqueue(objs ...interface{})
Enqueue one or more keys to the work queue.
func (*PeriodicTaskQueue) Run ¶
func (t *PeriodicTaskQueue) Run()
Run the task queue. This will block until the Shutdown() has been called.
func (*PeriodicTaskQueue) Shutdown ¶
func (t *PeriodicTaskQueue) Shutdown()
Shutdown shuts down the work queue and waits for the worker to ACK
type ServicePort ¶ added in v1.2.2
type ServicePort struct { // Ingress backend-specified service name and port ID ServicePortID NodePort int64 // Numerical port of the Service, retrieved from the Service Port int32 Protocol annotations.AppProtocol TargetPort string NEGEnabled bool BackendConfig *backendconfigv1beta1.BackendConfig }
ServicePort maintains configuration for a single backend.
func NewServicePortWithID ¶ added in v1.3.0
func NewServicePortWithID(svcName, svcNamespace string, port intstr.IntOrString) ServicePort
NewServicePortWithID returns a ServicePort with only ID.
func (ServicePort) BackendName ¶ added in v1.2.2
func (sp ServicePort) BackendName(namer *Namer) string
BackendName returns the name of the backend which would be used for this ServicePort.
func (ServicePort) GetDescription ¶ added in v1.2.2
func (sp ServicePort) GetDescription() Description
GetDescription returns a Description for this ServicePort.
type ServicePortID ¶ added in v1.2.2
type ServicePortID struct { Service types.NamespacedName Port intstr.IntOrString }
ServicePortID contains the Service and Port fields.
func BackendToServicePortID ¶ added in v1.2.2
func BackendToServicePortID(be extensions.IngressBackend, namespace string) ServicePortID
BackendToServicePortID creates a ServicePortID from a given IngressBackend and namespace.
func (ServicePortID) String ¶ added in v1.2.3
func (id ServicePortID) String() string
type StoreToIngressLister ¶ added in v1.3.0
StoreToIngressLister makes a Store that lists Ingress.
func (*StoreToIngressLister) GetServiceIngress ¶ added in v1.3.0
func (s *StoreToIngressLister) GetServiceIngress(svc *api_v1.Service, systemDefaultBackend ServicePortID) (ings []extensions.Ingress, err error)
GetServiceIngress gets all the Ingress' that have rules pointing to a service. Note that this ignores services without the right nodePorts.
func (*StoreToIngressLister) ListAll ¶ added in v1.3.0
func (s *StoreToIngressLister) ListAll() (ing extensions.IngressList, err error)
List lists all Ingress' in the store (both single and multi cluster ingresses).
func (*StoreToIngressLister) ListGCEIngresses ¶ added in v1.3.0
func (s *StoreToIngressLister) ListGCEIngresses() (ing extensions.IngressList, err error)
ListGCEIngresses lists all GCE Ingress' in the store.
type TaskQueue ¶
type TaskQueue interface { Run() Enqueue(objs ...interface{}) Shutdown() }
TaskQueue is a rate limited operation queue.
type TimeTracker ¶ added in v1.2.2
type TimeTracker struct {
// contains filtered or unexported fields
}
func NewTimeTracker ¶ added in v1.2.2
func NewTimeTracker() TimeTracker
func (*TimeTracker) Get ¶ added in v1.2.2
func (t *TimeTracker) Get() time.Time
Get returns previous recorded time
func (*TimeTracker) Set ¶ added in v1.2.2
func (t *TimeTracker) Set(timestamp time.Time)
Set records input timestamp
func (*TimeTracker) Track ¶ added in v1.2.2
func (t *TimeTracker) Track() time.Time
Track records the current time and returns it