servregistry

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package servregistry holds code and types that are useful/implemented by service registries.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrServRegNotProvided is returned when the broker has no service
	// registry and, thus, cannot make any changes
	ErrServRegNotProvided error = errors.New("no service registry is provided")
	// ErrNotFound is returned when the resource does not exist
	ErrNotFound error = errors.New("resource not found")
	// ErrAlreadyExists is returned when the resource already exists
	ErrAlreadyExists error = errors.New("resource already exists")
	// ErrServNotProvided is returned when the service is missing, i.e. is nil
	ErrServNotProvided error = errors.New("service is empty")
	// ErrServNoMetadata is returned when the provided service has no metadata
	ErrServNoMetadata error = errors.New("service has no metadata")
	// ErrNsNotProvided is returned when the namespace is missing, i.e. is nil
	ErrNsNotProvided error = errors.New("namespace is empty")
	// ErrServNameNotProvided is returned when the service name is empty
	ErrServNameNotProvided error = errors.New("service name is empty")
	// ErrNsNameNotProvided is returned when the namespace name is empty
	ErrNsNameNotProvided error = errors.New("namespace name is empty")
	// ErrNoEndpoints is returned when a service has no endpoints
	ErrNoEndpoints error = errors.New("service has no endpoints")
	// ErrNsNotEmpty is returned when trying to delete a namespace that is not
	// empty
	ErrNsNotEmpty error = errors.New("namespace is not empty")
	// ErrServNotEmpty is returned when trying to delete a service that is not
	// empty
	ErrServNotEmpty error = errors.New("service is not empty")
	// ErrNsNotOwnedServs is returned when trying to delete a namespace that
	// has services that are not owned by the operator
	ErrNsNotOwnedServs error = errors.New("namespace contains services not owned by the operator")
	// ErrServNotOwnedEndps is returned when trying to delete a service that
	// has endpoints that are not owned by the operator
	ErrServNotOwnedEndps error = errors.New("service contains endpoints not owned by the operator")
	// ErrNsNotOwnedByOp is returned when a namespace is not owned by the
	// cnwan operator and therefore the action cannot be performed
	ErrNsNotOwnedByOp error = errors.New("namespace is not owned by the cnwan operator")
	// ErrServNotOwnedByOp is returned when a service is not owned by the
	// cnwan operator and therefore the action cannot be performed
	ErrServNotOwnedByOp error = errors.New("service is not owned by the cnwan operator")
	// ErrEndpNotOwnedByOp is returned when an endpoint is not owned by the
	// cnwan operator and therefore the action cannot be performed
	ErrEndpNotOwnedByOp error = errors.New("endpoint is not owned by the cnwan operator")
	// ErrTimeOutExpired is returned when the timeout of a context is expired
	ErrTimeOutExpired error = errors.New("timeout expired while waiting for service registry to reply")
	// ErrEndpNameNotProvided is returned when the endpoint name is empty
	ErrEndpNameNotProvided error = errors.New("endpoint name not provided")
	// ErrEndpNotProvided is returned when the endpoint is missing, i.e. is nil
	ErrEndpNotProvided error = errors.New("endpoint is empty")
)

Functions

This section is empty.

Types

type Broker

type Broker struct {
	Reg ServiceRegistry
	// contains filtered or unexported fields
}

Broker is a structure that acts as an intermediary, setting up data - i.e. namespaces, services and endpoints - and performing checks before calling the appropriate functions of the service registry.

Its functions are split on namespace.go, service.go and endpoint.go to make the package more readable.

func NewBroker

func NewBroker(reg ServiceRegistry, opKey, opVal string) (*Broker, error)

NewBroker returns a new instance of service registry broker.

An error is returned in case no service registry where to perform operations is provided.

func (*Broker) ManageNs

func (b *Broker) ManageNs(nsData *Namespace) (regNs *Namespace, err error)

ManageNs takes data of a namespace and performs the necessary steps to reflect that data to the service registry.

For example: create a namespace in service registry or update it properly.

func (*Broker) ManageServ

func (b *Broker) ManageServ(servData *Service) (regServ *Service, err error)

ManageServ takes data from a service and peforms all necessary operations to reflect that data to the service registry

For example: create a service in service registry or update it properly.

func (*Broker) ManageServEndps

func (b *Broker) ManageServEndps(nsName, servName string, endpsData []*Endpoint) (endpErrs map[string]error, err error)

ManageServEndps updates the endpoints of the provided service with the provided endpoints. Additionally, it removes endpoints from the service registry if they have been removed from the Kubernetes service. The first returned value is a key-value map where the key is the name of the endpoint and value the error occurred in case the endpoint failed to update/delete. The second error value is only returned if the function could not perform any operation at all, such as when some data is invalid or it could not load the endpoints from the service registry.

NOTE: if the array is empty, then *all* the endpoints will be removed from the service registry, apart from those not owned by the cnwan operator. NOTE: NsName and ServName in endpsData will be ignored by the function, as only the first two arguments will be considered. This is because endpoints must all belong to the same service.

For example: updates the metadata, address and/or of the endpoints.

func (*Broker) RemoveNs

func (b *Broker) RemoveNs(nsName string, forceNotEmpty bool) (err error)

RemoveNs checks if a namespace can be safely deleted from the service registry before actually delete it. The second parameter forces the function to delete the namespace even if it is not empty. NOTE: setting forceNotEmpty to true will have no effect if the namespace contains services not owned by the operator, and therefore the namespace will not be deleted. NOTE: this function does *not* check if one of the contained services has endpoints not owned by the cnwan operator!

For example: it checks if the namespace is actually owned by us.

func (*Broker) RemoveServ

func (b *Broker) RemoveServ(nsName, servName string, forceNotEmpty bool) (err error)

RemoveServ checks if a service can be safely deleted from the service registry before actually delete it. The second parameter forces the function to delete the service even if it is not empty. NOTE: setting forceNotEmpty to true will have no effect if the service contains endpoints not owned by the operator, and therefore the service will not be deleted.

For example: it checks if the service is actually owned by us.

type Endpoint

type Endpoint struct {
	// Name of the endpoint
	Name string
	// ServName is the name of the service that contains this endpoint
	ServName string
	// NsName is the name of the namespace that contains the service this
	// endpoint belongs to
	NsName string
	// Metadata is a key-value map with metadata of this endpoint
	Metadata map[string]string
	// Address, i.e. IPv4 or IPv6, of this endpoint
	Address string
	// Port of this endpoint
	Port int32
}

Endpoint holds data about an endpoint

type Namespace

type Namespace struct {
	// Name of the namespace
	Name string
	// Metadata is a key-value map with metadata of the namespace
	Metadata map[string]string
}

Namespace holds data about a namespace

type Service

type Service struct {
	// Name of the service
	Name string
	// NsName is the name of the namespace that contains this service
	NsName string
	// Metadata is a key-value map with metadata of this service
	Metadata map[string]string
}

Service holds data about a service

type ServiceRegistry

type ServiceRegistry interface {
	// GetNs returns the namespace if exists.
	GetNs(name string) (*Namespace, error)
	// ListNs returns a list of all namespaces.
	ListNs() ([]*Namespace, error)
	// CreateNs creates the namespace.
	CreateNs(ns *Namespace) (*Namespace, error)
	// UpdateNs updates the namespace.
	UpdateNs(ns *Namespace) (*Namespace, error)
	// DeleteNs deletes the namespace.
	DeleteNs(name string) error
	// GetServ returns the service if exists.
	GetServ(nsName, servName string) (*Service, error)
	// ListServ returns a list of services inside the provided namespace.
	ListServ(nsName string) ([]*Service, error)
	// CreateServ creates the service.
	CreateServ(serv *Service) (*Service, error)
	// UpdateServ updates the service.
	UpdateServ(serv *Service) (*Service, error)
	// DeleteServ deletes the service.
	DeleteServ(nsName, servName string) error
	// GetEndp returns the endpoint if exists.
	GetEndp(nsName, servName, endpName string) (*Endpoint, error)
	// ListEndp returns a list of endpoints belonging to the provided namespace and service.
	ListEndp(nsName, servName string) ([]*Endpoint, error)
	// CreateEndp creates the endpoint.
	CreateEndp(endp *Endpoint) (*Endpoint, error)
	// UpdateEndp updates the endpoint.
	UpdateEndp(endp *Endpoint) (*Endpoint, error)
	// DeleteEndp deletes the endpoint.
	DeleteEndp(nsName, servName, endpName string) error
	// ExtractData extracts relevant data from the provided Kubernetes namespace and service
	// and returns a namespace, service and an array of endpoints with data relevant to this
	// specific service registry.
	ExtractData(ns *corev1.Namespace, serv *corev1.Service) (*Namespace, *Service, []*Endpoint, error)
}

ServiceRegistry is an interface containing functions that are implemented by a service registry.

Directories

Path Synopsis
gcloud
servicedirectory
Package servicedirectory contains code that connects to Google Cloud Service Directory and performs some actions with specific resources.
Package servicedirectory contains code that connects to Google Cloud Service Directory and performs some actions with specific resources.

Jump to

Keyboard shortcuts

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