expose

package
v0.2.35 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrExposeResourceCode is generated while exposing the kubernetes resource
	ErrExposeResourceCode = "11032"

	// ErrGettingResourceCode is generated when there is an error getting the kubernetes resource
	ErrGettingResourceCode = "11033"

	// ErrTraverserCode is a collection of errors generated during traversing the resources
	ErrTraverserCode = "11034"

	// ErrResourceCannotBeExposedCode is generated when the given resource cannot be exposed
	ErrResourceCannotBeExposedCode = "11035"

	// ErrSelectorBasedMapCode is generated when the given resource's selectors can't
	// be parsed to a map
	ErrSelectorBasedMapCode = "11036"

	// ErrProtocolBasedMapCode is generated when the given resource's protocol can't
	// be parsed to a map
	ErrProtocolBasedMapCode = "11037"

	// ErrLableBasedMapCode is generated when the given resource's protocol can't
	// be parsed to a map
	ErrLableBasedMapCode = "11038"

	// ErrPortParsingCode is generated when the given resource's ports can't
	// be parsed to a slice
	ErrPortParsingCode = "11039"

	// ErrGenerateServiceCode is generated when a service cannot be generated
	// for the given resource
	ErrGenerateServiceCode = "11040"

	// ErrConstructingRestHelperCode is generated when a rest helper cannot be generated
	// for the generated service
	ErrConstructingRestHelperCode = "11041"

	// ErrCreatingServiceCode is generated when there is an error deploying the service
	ErrCreatingServiceCode = "11042"

	// ErrPodHasNoLabelsCode is generated when there is an error
	ErrPodHasNoLabelsCode = "11058"

	// ErrServiceHasNoSelectorsCode is generated when there is an error
	ErrServiceHasNoSelectorsCode = "11059"

	// ErrInvalidDeploymentNoSelectorsLabelsCode is generated when there is an error
	ErrInvalidDeploymentNoSelectorsLabelsCode = "11060"

	// ErrInvalidDeploymentNoSelectorsCode is generated when there is an error
	ErrInvalidDeploymentNoSelectorsCode = "11061"

	// ErrInvalidReplicaNoSelectorsLabelsCode is generated when there is an error
	ErrInvalidReplicaNoSelectorsLabelsCode = "11062"

	// ErrInvalidReplicaSetNoSelectorsCode is generated when there is an error
	ErrInvalidReplicaSetNoSelectorsCode = "11063"

	// ErrNoPortsFoundForHeadlessResourceCode is generated when there is an error
	ErrNoPortsFoundForHeadlessResourceCode = "11064"

	// ErrUnknownSessionAffinityErrCode is generated when there is an error
	ErrUnknownSessionAffinityErrCode = "11065"

	// ErrMatchExpressionsConvertionErrCode is generated when there is an error
	ErrMatchExpressionsConvertionErrCode = "11066"

	// ErrFailedToExtractPodSelectorErrCode is generated when there is an error
	ErrFailedToExtractPodSelectorErrCode = "11067"

	// ErrFailedToExtractPortsCode is generated when there is an error
	ErrFailedToExtractPortsCode = "11068"

	// ErrFailedToExtractProtocolsErrCode is generated when there is an error
	ErrFailedToExtractProtocolsErrCode = "11069"

	// ErrCannotExposeObjectErrCode is generated when there is an error
	ErrCannotExposeObjectErrCode = "11070"
)
View Source
var (
	// ErrPodHasNoLabels is the error for pods with no labels
	ErrPodHasNoLabels = errors.New(ErrPodHasNoLabelsCode, errors.Alert, []string{"the pod has no labels and cannot be exposed"}, []string{}, []string{}, []string{})

	// ErrServiceHasNoSelectors is the error for service with no selectors
	ErrServiceHasNoSelectors = errors.New(ErrServiceHasNoSelectorsCode, errors.Alert, []string{"the service has no pod selector set"}, []string{}, []string{}, []string{})

	// ErrInvalidDeploymentNoSelectorsLabels is the error for deployment (v1beta1) with no selectors and labels
	ErrInvalidDeploymentNoSelectorsLabels = errors.New(ErrInvalidDeploymentNoSelectorsLabelsCode, errors.Alert, []string{"the deployment has no labels or selectors and cannot be exposed"}, []string{}, []string{}, []string{})

	// ErrInvalidDeploymentNoSelectors is the error for deployment (v1) with no selectors
	ErrInvalidDeploymentNoSelectors = errors.New(ErrInvalidDeploymentNoSelectorsCode, errors.Alert, []string{"invalid deployment: no selectors, therefore cannot be exposed"}, []string{}, []string{}, []string{})

	// ErrInvalidReplicaNoSelectorsLabels is the error for replicaset (v1beta1) with no selectors and labels
	ErrInvalidReplicaNoSelectorsLabels = errors.New(ErrInvalidReplicaNoSelectorsLabelsCode, errors.Alert, []string{"the replica set has no labels or selectors and cannot be exposed"}, []string{}, []string{}, []string{})

	// ErrInvalidReplicaSetNoSelectors is the error for replicaset (v1) with no selectors
	ErrInvalidReplicaSetNoSelectors = errors.New(ErrInvalidReplicaSetNoSelectorsCode, errors.Alert, []string{"invalid replicaset: no selectors, therefore cannot be exposed"}, []string{}, []string{}, []string{})

	// ErrNoPortsFoundForHeadlessResource is the error when no ports are found for non headless resource
	ErrNoPortsFoundForHeadlessResource = errors.New(ErrNoPortsFoundForHeadlessResourceCode, errors.Alert, []string{"no ports found for the non headless resource"}, []string{}, []string{}, []string{})
)

Functions

func ErrCannotExposeObjectErr

func ErrCannotExposeObjectErr(kind schema.GroupKind) error

ErrCannotExposeObjectErr is the error if the given object cannot be exposed

func ErrConstructingRestHelper

func ErrConstructingRestHelper(err error) error

ErrConstructingRestHelper is the error when a rest helper cannot be generated for the generated service

func ErrCreatingService

func ErrCreatingService(err error) error

ErrCreatingService is the error when there is an error deploying the service

func ErrExposeResource

func ErrExposeResource(err error) error

ErrExposeResource is the error when there is an error exposing the kubernetes resource

func ErrFailedToExtractPodSelectorErr

func ErrFailedToExtractPodSelectorErr(object runtime.Object) error

ErrFailedToExtractPodSelectorErr is the error for failed to extract pod selector

func ErrFailedToExtractPorts

func ErrFailedToExtractPorts(object runtime.Object) error

ErrFailedToExtractPorts is the error for failed to extract ports

func ErrFailedToExtractProtocolsErr

func ErrFailedToExtractProtocolsErr(object runtime.Object) error

ErrFailedToExtractProtocolsErr is the error for extracting ports

func ErrGenerateService

func ErrGenerateService(err error) error

ErrGenerateService is the error when a service cannot be generated for the given resource

func ErrGettingResource

func ErrGettingResource(err error) error

ErrGettingResource is the error when there is an error getting the kubernetes resource

func ErrLabelBasedMap

func ErrLabelBasedMap(err error) error

ErrLabelBasedMap is the error when the given resource's labels can't be parsed to a map

func ErrMatchExpressionsConvertionErr

func ErrMatchExpressionsConvertionErr(me []metav1.LabelSelectorRequirement) error

ErrMatchExpressionsConvertionErr is the error for failed match expression conversion

func ErrPortParsing

func ErrPortParsing(err error) error

ErrPortParsing is the error when the given resource's ports can't be parsed to a slice

func ErrProtocolBasedMap

func ErrProtocolBasedMap(err error) error

ErrProtocolBasedMap is the error when the given resource's protocols can't be parsed to a map

func ErrResourceCannotBeExposed

func ErrResourceCannotBeExposed(err error, resourceKind string) error

ErrResourceCannotBeExposed is the error if the given resource cannot be exposed

func ErrSelectorBasedMap

func ErrSelectorBasedMap(err error) error

ErrSelectorBasedMap is the error when the given resource's selectors can't be parsed to a map

func ErrTraverser

func ErrTraverser(err error) error

ErrTraverser is the error is collection of error generated while traversing the resources

func ErrUnknownSessionAffinityErr

func ErrUnknownSessionAffinityErr(sa SessionAffinity) error

ErrUnknownSessionAffinityErr is the error for unknown session affinity

func Expose

func Expose(
	clientSet *kubernetes.Clientset,
	restConfig rest.Config,
	config Config,
	resources []Resource,
) ([]*v1.Service, error)

Expose exposes the given kubernetes resource

func Remove

func Remove(svc, ns string, client *kubernetes.Clientset) error

Remove deletes the given service

Types

type Config

type Config struct {
	// Type is the type of the service
	// could be either ClusterIP, NodePort
	// or LoadBalancer. If an empty is string
	// is provided then "ClusterIP" type service
	// is created
	Type ServiceType

	// LoadBalancerIP is the IP address that would
	// be used if the service type is "loadBalancer"
	// based. This IP address should be a valid
	// IP address which can be provisioned by
	// the service provider
	LoadBalancerIP string

	// ClusterIP is the IP address that would be
	// used if the service type is "ClusterIP" or
	// an empty string. This IP address should be
	// a valid clusterIP.
	ClusterIP string

	// Namespace where the service should be created
	// ideally this should be the same as the service
	// that needs to be exposed
	//
	// It defaults to the namespace of the target resource
	Namespace string

	// SessionAffinity of the service
	// could be "None" or "ClientIP"
	SessionAffinity SessionAffinity

	// Name of the service
	Name string

	// Annotations will be used to annotate the generated service
	//
	// It will not effect the target resource
	Annotations map[string]string

	// Log is the logger that would be used for logging
	Log logger.Handler
}

Config is a the struct for Expose configuration

type Object

type Object interface {
	runtime.Object
	GetNamespace() string
	GetName() string
}

Object is the interface extending kubernetes' runtime object interface

type Resource

type Resource struct {
	Namespace string
	Type      string
	Name      string
}

Resource defines the structure for the resource definition used by the traverser to locate the kubernetes resources

type ServiceType

type ServiceType string

ServiceType us the type for Kubernetes resources' Type

const (
	ClusterIP    ServiceType = "ClusterIP"
	NodePort     ServiceType = "NodePort"
	LoadBalancer ServiceType = "LoadBalancer"
)

Supported service type

type SessionAffinity

type SessionAffinity string

SessionAffinity is the type for Kubernetes resources' SessionAffinity

const (
	// None is the "None" type SessionAffinity
	None SessionAffinity = "None"

	// ClientIP is the "ClientIP" type SessionAffinity
	ClientIP SessionAffinity = "ClientIP"
)

type Traverser

type Traverser struct {
	Resources []Resource

	Client *kubernetes.Clientset

	Logger logger.Handler
}

Traverser can be used to traverse resources in the cluster

func (*Traverser) Visit

func (traverser *Traverser) Visit(f VisitCB, continueOnError bool) ([]*v1.Service, error)

Visit function traverses each of the resource mentioned in the Traverser struct

type VisitCB

type VisitCB = func(Object, error) (*v1.Service, error)

VisitCB is the type for callback function that is invoked when the traverser reaches one of the given kubernetes resource

The first argument for the VisitCB is the kubernetes resource itself while the other is the error that may have occured in the traverser in case this error is not nil, then this callbac function may return without executing the code

Jump to

Keyboard shortcuts

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