Documentation ¶
Overview ¶
Package utils contains shared data structures and functions.
Index ¶
- Constants
- Variables
- func BetaToAlphaHealthCheck(hc *computebeta.HealthCheck) (*computealpha.HealthCheck, error)
- func EqualMapping(a, b *GCEURLMap) bool
- func EqualResourceIDs(a, b string) bool
- func EqualResourcePaths(a, b string) bool
- func EqualStringSets(x, y []string) bool
- func FakeGoogleAPIForbiddenErr() *googleapi.Error
- func FakeGoogleAPINotFoundErr() *googleapi.Error
- func GetNodePrimaryIP(inputNode *api_v1.Node) string
- func GetPortRanges(ports []int) (ranges []string)
- func GetPortsAndProtocol(svcPorts []api_v1.ServicePort) (ports []string, portRanges []string, protocol api_v1.Protocol)
- func GetReadyNodeNames(lister listers.NodeLister) ([]string, error)
- func HasVIP(ing *v1beta1.Ingress) bool
- func IGLinks(igs []*compute.InstanceGroup) (igLinks []string)
- func IgnoreHTTPNotFound(err error) error
- func IsForbiddenError(err error) bool
- func IsGCEIngress(ing *v1beta1.Ingress) bool
- func IsGCEL7ILBIngress(ing *v1beta1.Ingress) bool
- func IsGCEMultiClusterIngress(ing *v1beta1.Ingress) bool
- func IsGLBCIngress(ing *v1beta1.Ingress) bool
- func IsHTTPErrorCode(err error, code int) bool
- func IsInUsedByError(err error) bool
- func IsLegacyL4ILBService(svc *api_v1.Service) bool
- func IsNotFoundError(err error) bool
- func JoinErrs(errs []error) error
- func KeyName(url string) (string, error)
- func ListWithPredicate(nodeLister listers.NodeLister, predicate NodeConditionPredicate) ([]*api_v1.Node, error)
- func MakeL4ILBServiceDescription(svcName, ip string, version meta.Version) (string, error)
- func MergePatchBytes(old, cur interface{}) ([]byte, error)
- func NeedsCleanup(ing *v1beta1.Ingress) bool
- func NewInt64Pointer(i int64) *int64
- func NewNamespaceIndexer() cache.Indexers
- func NewStringPointer(s string) *string
- func NodeIsReady(node *api_v1.Node) bool
- func NumEndpoints(ep *api_v1.Endpoints) (result int)
- 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 ToBetaHealthCheck(hc *computealpha.HealthCheck) (*computebeta.HealthCheck, error)
- func ToNamespacedName(s string) (r types.NamespacedName, err error)
- func ToV1HealthCheck(hc *computealpha.HealthCheck) (*compute.HealthCheck, error)
- func TranslateAffinityType(affinityType string) string
- func TraverseIngressBackends(ing *v1beta1.Ingress, process func(id ServicePortID) bool)
- func V1ToAlphaHealthCheck(hc *compute.HealthCheck) (*computealpha.HealthCheck, error)
- type Description
- type FrontendGCAlgorithm
- 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 L4ILBResourceDescription
- type NegDescription
- type NodeConditionPredicate
- type PathRule
- type PeriodicTaskQueue
- type ServicePort
- type ServicePortID
- 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" // ToBeDeletedTaint is the taint that the autoscaler adds when a node is scheduled to be deleted // https://github.com/kubernetes/autoscaler/blob/cluster-autoscaler-0.5.2/cluster-autoscaler/utils/deletetaint/delete.go#L33 ToBeDeletedTaint = "ToBeDeletedByClusterAutoscaler" L4ILBServiceDescKey = "networking.gke.io/service-name" // ServiceNodeExclusionFeature is the feature gate name that // enables nodes to exclude themselves from service load balancers // originated from: https://github.com/kubernetes/kubernetes/blob/28e800245e/pkg/features/kube_features.go#L178 ServiceNodeExclusionFeature = "ServiceNodeExclusion" // LabelAlphaNodeRoleExcludeBalancer specifies that the node should be // exclude from load balancers created by a cloud provider. This label is deprecated and will // be removed in 1.18. LabelAlphaNodeRoleExcludeBalancer = "alpha.service-controller.kubernetes.io/exclude-balancer" // LegacyNodeRoleBehaviorFeature is the feature gate name that enables legacy // behavior to vary cluster functionality on the node-role.kubernetes.io // labels. LegacyNodeRoleBehaviorFeature = "LegacyNodeRoleBehavior" )
Variables ¶
var (
KeyFunc = cache.DeletionHandlingMetaNamespaceKeyFunc
)
Functions ¶
func BetaToAlphaHealthCheck ¶ added in v1.10.0
func BetaToAlphaHealthCheck(hc *computebeta.HealthCheck) (*computealpha.HealthCheck, error)
BetaToAlphaHealthCheck converts beta health check to alpha health check. There should be no information lost after conversion.
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 EqualStringSets ¶ added in v1.9.0
EqualStringSets returns true if 2 given string slices contain the same elements, in any order.
func FakeGoogleAPIForbiddenErr ¶
FakeGoogleAPIForbiddenErr creates a Forbidden error with type googleapi.Error
func FakeGoogleAPINotFoundErr ¶
FakeGoogleAPINotFoundErr creates a NotFound error with type googleapi.Error
func GetNodePrimaryIP ¶ added in v1.9.0
GetNodePrimaryIP returns a primary internal IP address of the node.
func GetPortRanges ¶ added in v1.9.0
GetPortRanges returns a list of port ranges, given a list of ports.
func GetPortsAndProtocol ¶ added in v1.9.0
func GetPortsAndProtocol(svcPorts []api_v1.ServicePort) (ports []string, portRanges []string, protocol api_v1.Protocol)
GetPortsAndProtocol returns the list of ports, list of port ranges and the protocol given the list of k8s port info.
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 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 IsForbiddenError ¶
IsForbiddenError returns true if the operation was forbidden
func IsGCEIngress ¶ added in v1.3.0
IsGCEIngress returns true if the Ingress matches the class managed by this controller.
func IsGCEL7ILBIngress ¶ added in v1.7.0
IsGCEL7ILBIngress returns true if the given Ingress has ingress.class annotation set to "gce-l7-ilb"
func IsGCEMultiClusterIngress ¶ added in v1.3.0
IsGCEMultiClusterIngress returns true if the given Ingress has ingress.class annotation set to "gce-multi-cluster".
func IsGLBCIngress ¶ added in v1.3.2
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 IsLegacyL4ILBService ¶ added in v1.9.0
IsLegacyL4ILBService returns true if the given LoadBalancer service is managed by service controller.
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 ListWithPredicate ¶ added in v1.10.0
func ListWithPredicate(nodeLister listers.NodeLister, predicate NodeConditionPredicate) ([]*api_v1.Node, error)
ListWithPredicate gets nodes that matches predicate function.
func MakeL4ILBServiceDescription ¶ added in v1.9.0
func MergePatchBytes ¶ added in v1.10.0
MergePatchBytes 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 NeedsCleanup ¶ added in v1.7.0
NeedsCleanup returns true if the ingress needs to have its associated resources deleted.
func NewInt64Pointer ¶ added in v1.9.9
NewInt64Pointer returns a pointer to the provided int64 literal
func NewNamespaceIndexer ¶ added in v1.3.0
NewNamespaceIndexer returns a new Indexer for use by SharedIndexInformers
func NewStringPointer ¶ added in v1.9.0
NewStringPointer returns a pointer to the provided string literal
func NodeIsReady ¶
NodeIsReady returns true if a node contains at least one condition of type "Ready"
func NumEndpoints ¶ added in v1.9.0
NumEndpoints returns the count of endpoints in the given endpoints object.
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 ToBetaHealthCheck ¶ added in v1.10.0
func ToBetaHealthCheck(hc *computealpha.HealthCheck) (*computebeta.HealthCheck, error)
ToBetaHealthCheck converts alpha health check to beta health check.
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 ToV1HealthCheck ¶ added in v1.10.0
func ToV1HealthCheck(hc *computealpha.HealthCheck) (*compute.HealthCheck, error)
ToV1HealthCheck converts alpha health check to v1 health check. WARNING: alpha health check has a additional PORT_SPECIFICATION field. This field will be omitted after conversion.
func TranslateAffinityType ¶ added in v1.9.0
TranslateAffinityType converts the k8s affinity type to the GCE affinity type.
func TraverseIngressBackends ¶ added in v1.3.2
func TraverseIngressBackends(ing *v1beta1.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 V1ToAlphaHealthCheck ¶ added in v1.10.0
func V1ToAlphaHealthCheck(hc *compute.HealthCheck) (*computealpha.HealthCheck, error)
V1ToAlphaHealthCheck converts v1 health check to alpha health check. There should be no information lost after conversion.
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 FrontendGCAlgorithm ¶ added in v1.8.0
type FrontendGCAlgorithm int
FrontendGCAlgorithm species GC algorithm used for ingress frontend resources.
const ( // NoCleanUpNeeded specifies that frontend resources need not be deleted. NoCleanUpNeeded FrontendGCAlgorithm = iota // CleanupV1FrontendResources specifies that frontend resources for ingresses // that use v1 naming scheme need to be deleted. CleanupV1FrontendResources // CleanupV2FrontendResources specifies that frontend resources for ingresses // that use v2 naming scheme need to be deleted. CleanupV2FrontendResources // CleanupV2FrontendResourcesScopeChange specifies that frontend resources for ingresses // that use v2 naming scheme and have changed their LB scope (e.g. ILB -> ELB or vice versa) // need to be deleted CleanupV2FrontendResourcesScopeChange )
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 L4ILBResourceDescription ¶ added in v1.9.0
type L4ILBResourceDescription struct { // ServiceName indicates the name of the service the resource is for. ServiceName string `json:"networking.gke.io/service-name"` // APIVersion stores the version og the compute API used to create this resource. APIVersion meta.Version `json:"networking.gke.io/api-version,omitempty"` ServiceIP string `json:"networking.gke.io/service-ip,omitempty"` }
L4ILBResourceDescription stores the description fields for L4 ILB resources. This is useful to indetify which resources correspond to which L4 ILB service.
func (*L4ILBResourceDescription) Marshal ¶ added in v1.9.0
func (d *L4ILBResourceDescription) Marshal() (string, error)
Marshal returns the description as a JSON-encoded string.
func (*L4ILBResourceDescription) Unmarshal ¶ added in v1.9.0
func (d *L4ILBResourceDescription) Unmarshal(desc string) error
Unmarshal converts the JSON-encoded description string into the struct.
type NegDescription ¶ added in v1.10.0
type NegDescription struct { ClusterUID string `json:"cluster-uid,omitempty"` Namespace string `json:"namespace,omitempty"` ServiceName string `json:"service-name,omitempty"` Port string `json:"port,omitempty"` }
Description stores the description for a BackendService.
func NegDescriptionFromString ¶ added in v1.10.0
func NegDescriptionFromString(descString string) (*NegDescription, error)
DescriptionFromString gets a Description from string,
func (NegDescription) String ¶ added in v1.10.0
func (desc NegDescription) String() string
String returns the string representation of a Description.
type NodeConditionPredicate ¶ added in v1.10.0
NodeConditionPredicate is a function that indicates whether the given node's conditions meet some set of criteria defined by the function.
func GetNodeConditionPredicate ¶ added in v1.3.0
func GetNodeConditionPredicate() NodeConditionPredicate
This is a duplicate definition of the function in: kubernetes/kubernetes/pkg/controller/service/service_controller.go
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(name, 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(name, 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 VMIPNEGEnabled bool L7ILBEnabled bool BackendConfig *backendconfigv1.BackendConfig BackendNamer namer.BackendNamer }
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() 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.
func (ServicePort) IGName ¶ added in v1.8.0
func (sp ServicePort) IGName() string
IGName returns the name of the instance group which would be used 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 v1beta1.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 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