expose

package
v0.7.87 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrExposeResourceCode is generated while exposing the kubernetes resource
	ErrExposeResourceCode = "meshkit-11205"

	// ErrGettingResourceCode is generated when there is an error getting the kubernetes resource
	ErrGettingResourceCode = "meshkit-11206"

	// ErrTraverserCode is a collection of errors generated during traversing the resources
	ErrTraverserCode = "meshkit-11207"

	// ErrResourceCannotBeExposedCode is generated when the given resource cannot be exposed
	ErrResourceCannotBeExposedCode = "meshkit-11208"

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

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

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

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

	// ErrGenerateServiceCode is generated when a service cannot be generated
	// for the given resource
	ErrGenerateServiceCode = "meshkit-11213"

	// ErrConstructingRestHelperCode is generated when a rest helper cannot be generated
	// for the generated service
	ErrConstructingRestHelperCode = "meshkit-11214"

	// ErrCreatingServiceCode is generated when there is an error deploying the service
	ErrCreatingServiceCode = "meshkit-11215"

	// ErrPodHasNoLabelsCode is generated when there is an error
	ErrPodHasNoLabelsCode = "meshkit-11216"

	// ErrServiceHasNoSelectorsCode is generated when there is an error
	ErrServiceHasNoSelectorsCode = "meshkit-11217"

	// ErrInvalidDeploymentNoSelectorsLabelsCode is generated when there is an error
	ErrInvalidDeploymentNoSelectorsLabelsCode = "meshkit-11218"

	// ErrInvalidDeploymentNoSelectorsCode is generated when there is an error
	ErrInvalidDeploymentNoSelectorsCode = "meshkit-11219"

	// ErrInvalidReplicaNoSelectorsLabelsCode is generated when there is an error
	ErrInvalidReplicaNoSelectorsLabelsCode = "meshkit-11220"

	// ErrInvalidReplicaSetNoSelectorsCode is generated when there is an error
	ErrInvalidReplicaSetNoSelectorsCode = "meshkit-11221"

	// ErrNoPortsFoundForHeadlessResourceCode is generated when there is an error
	ErrNoPortsFoundForHeadlessResourceCode = "meshkit-11222"

	// ErrUnknownSessionAffinityErrCode is generated when there is an error
	ErrUnknownSessionAffinityErrCode = "meshkit-11223"

	// ErrMatchExpressionsConvertionErrCode is generated when there is an error
	ErrMatchExpressionsConvertionErrCode = "meshkit-11224"

	// ErrFailedToExtractPodSelectorErrCode is generated when there is an error
	ErrFailedToExtractPodSelectorErrCode = "meshkit-11225"

	// ErrFailedToExtractPortsCode is generated when there is an error
	ErrFailedToExtractPortsCode = "meshkit-11226"

	// ErrFailedToExtractProtocolsErrCode is generated when there is an error
	ErrFailedToExtractProtocolsErrCode = "meshkit-11227"

	// ErrCannotExposeObjectErrCode is generated when there is an error
	ErrCannotExposeObjectErrCode = "meshkit-11228"
)
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 occurred 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