utils

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package utils contains shared data structures and functions.

Index

Constants

View Source
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
)
View Source
const (

	// DefaultBackendKey is the key used to transmit the defaultBackend
	// through a urlmap. It's not a valid subdomain, and it is a catch
	// all path.  TODO: Find a better way to transmit this, once we've
	// decided on default backend semantics (i.e do we want a default
	// per host, per lb etc).
	DefaultBackendKey = "DefaultBackend"
)

Variables

This section is empty.

Functions

func CompareLinks(l1, l2 string) bool

CompareLinks returns true if the 2 self links are equal.

func FakeGoogleAPIForbiddenErr

func FakeGoogleAPIForbiddenErr() *googleapi.Error

FakeGoogleAPIForbiddenErr creates a Forbidden error with type googleapi.Error

func FakeGoogleAPINotFoundErr

func FakeGoogleAPINotFoundErr() *googleapi.Error

FakeGoogleAPINotFoundErr creates a NotFound error with type googleapi.Error

func IgnoreHTTPNotFound

func IgnoreHTTPNotFound(err error) error

IgnoreHTTPNotFound returns the passed err if it's not a GoogleAPI error with a NotFound status code.

func IsForbiddenError

func IsForbiddenError(err error) bool

IsForbiddenError returns true if the operation was forbidden

func IsHTTPErrorCode

func IsHTTPErrorCode(err error, code int) bool

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

func IsInUsedByError(err error) bool

IsInUsedByError returns true if the resource is being used by another GCP resource

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError returns true if the resource does not exist

func NodeIsReady

func NodeIsReady(node *v1.Node) bool

Types

type FakeIngressRuleValueMap

type FakeIngressRuleValueMap map[string]string

FakeIngressRuleValueMap is a convenience type used by multiple submodules that share the same testing methods.

type GCEURLMap

type GCEURLMap map[string]map[string]*compute.BackendService

GCEURLMap is a nested map of hostname->path regex->backend

func (GCEURLMap) GetDefaultBackend

func (g GCEURLMap) GetDefaultBackend() *compute.BackendService

GetDefaultBackend performs a destructive read and returns the default backend of the urlmap.

func (GCEURLMap) PutDefaultBackend

func (g GCEURLMap) PutDefaultBackend(d *compute.BackendService)

PutDefaultBackend performs a destructive write replacing the default backend of the url map with the given backend.

func (GCEURLMap) String

func (g GCEURLMap) String() string

String implements the string interface for the GCEURLMap.

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 NewNamer

func NewNamer(clusterName, firewallName string) *Namer

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

func NewNamerWithPrefix

func NewNamerWithPrefix(prefix, clusterName, firewallName string) *Namer

NewNamerWithPrefix creates a new namer with a custom prefix.

func (*Namer) Backend

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

BeName constructs the name for a backend.

func (*Namer) BackendPort

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

BackendPort retrieves the port from the given backend name.

func (*Namer) Firewall

func (n *Namer) Firewall() string

GetFirewallName 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 string, protocol NamerProtocol) string

ForwardingRule returns the name of the forwarding rule prefix.

func (*Namer) InstanceGroup

func (n *Namer) InstanceGroup() string

InstanceGroup constructs the name for an Instance Group.

func (*Namer) IsCertUsedForLB added in v1.1.0

func (n *Namer) IsCertUsedForLB(lbName, 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 added in v1.1.0

func (n *Namer) IsLegacySSLCert(lbName string, 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.

func (*Namer) LoadBalancer

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

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

func (*Namer) NEG

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

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

{prefix}{version}-{clusterid}-{namespace}-{name}-{target 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, TargetProxy, SSLCert, ForwardingRule, UrlMap.

func (*Namer) SSLCertName added in v1.1.0

func (n *Namer) SSLCertName(lbName string, 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 string, 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.

func (*Namer) UrlMap

func (n *Namer) UrlMap(lbName string) 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 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 given sync function. The sync function is called for every element inserted into the queue.

func (*PeriodicTaskQueue) Enqueue

func (t *PeriodicTaskQueue) Enqueue(obj interface{})

Enqueue a key to the work queue.

func (*PeriodicTaskQueue) Run

func (t *PeriodicTaskQueue) Run(period time.Duration, stopCh <-chan struct{})

Run the task queue. This will block until the Shutdown() has been called. TODO: seems redundant to both have stopCh and Shutdown().

func (*PeriodicTaskQueue) Shutdown

func (t *PeriodicTaskQueue) Shutdown()

Shutdown shuts down the work queue and waits for the worker to ACK

type TaskQueue

type TaskQueue interface {
	Run(period time.Duration, stopCh <-chan struct{})
	Enqueue(obj interface{})
	Shutdown()
}

TaskQueue is a rate limited operation queue.

Jump to

Keyboard shortcuts

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