kuberegister

package
v0.0.0-...-9eed78a Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package kuberegister registry simply implements the kubernetes-base Registry

Index

Constants

View Source
const (
	LabelsKeyServiceID      = "rushgo-service-id"       // LabelsKeyServiceID is used to define the ID of the service
	LabelsKeyServiceName    = "rushgo-service-name"     // LabelsKeyServiceName is used to define the name of the service
	LabelsKeyServiceVersion = "rushgo-service-version"  // LabelsKeyServiceVersion is used to define the version of the service
	AnnotationsKeyMetadata  = "rushgo-service-metadata" // AnnotationsKeyMetadata is used to define the metadata of the service
	// AnnotationsKeyProtocolMap is used to define the protocols of the service
	// Through the value of this field, we can obtain the application layer protocol corresponding to the port.
	// example value: {"80": "http", "8081": "grpc"}
	AnnotationsKeyProtocolMap = "rushgo-service-protocols"
)

Defines the key name of specific fields rushgo needs to cooperate with the following fields to run properly on kubernetes: rushgo-service-id: define the ID of the service rushgo-service-name: define the name of the service rushgo-service-version: define the version of the service rushgo-service-metadata: define the metadata of the service rushgo-service-protocols: define the protocols of the service

Example Deployment:

apiVersion: apps/v1 kind: Deployment metadata:

name: nginx
labels:
	app: nginx

spec:

replicas: 2
selector:
	matchLabels:
		app: nginx
template:
	metadata:
		labels:
			app: nginx
			rushgo-service-id: "da5c8329-29ac-411d-b1f0-d9364b313f3e"
			rushgo-service-name: "nginx"
			rushgo-service-version: "v1.27.0"
		annotations:
			rushgo-service-metadata: |
				{"region": "sh", "zone": "sh001", "cluster": "pd"}
			rushgo-service-protocols: |
				{"80": "http", "8081": "grpc"}
	spec:
		containers:
			- name: nginx
			  image: nginx:1.27.0
			  ports:
			    - containerPort: 80
View Source
const ServiceAccountNamespacePath = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"

Variables

View Source
var ErrIteratorClosed = errors.New("iterator closed")

ErrIteratorClosed defines the error that the iterator is closed

Functions

func GetNamespace

func GetNamespace() string

func GetPodName

func GetPodName() string

func LoadNamespace

func LoadNamespace() string

Types

type ErrorHandleResource

type ErrorHandleResource struct {
	Namespace string
	Name      string
	Reason    error
}

ErrorHandleResource defines the error that failed to handle kubernetes resources

func (*ErrorHandleResource) Error

func (err *ErrorHandleResource) Error() string

type Iterator

type Iterator struct {
	// contains filtered or unexported fields
}

Iterator performs the conversion from channel to iterator. It reads the latest changes from the `chan []*registry.ServiceInstance` and the outside can sense the closure of Iterator through stopCh.

func NewIterator

func NewIterator(channel chan []*registry.ServiceInstance, stopCh chan struct{}) *Iterator

func (*Iterator) Next

func (iter *Iterator) Next() ([]*registry.ServiceInstance, error)

func (*Iterator) Stop

func (iter *Iterator) Stop() error

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

func NewRegistry

func NewRegistry(clientSet *kubernetes.Clientset) *Registry

NewRegistry initialize the Registry

func (*Registry) Close

func (r *Registry) Close()

func (*Registry) Deregister

func (r *Registry) Deregister(ctx context.Context, _ *registry.ServiceInstance) error

func (*Registry) GetService

func (r *Registry) GetService(_ context.Context, serviceName string) ([]*registry.ServiceInstance, error)

func (*Registry) Register

func (r *Registry) Register(ctx context.Context, service *registry.ServiceInstance) error

func (*Registry) Start

func (r *Registry) Start()

func (*Registry) Watch

func (r *Registry) Watch(ctx context.Context, serviceName string) (registry.Watcher, error)

Jump to

Keyboard shortcuts

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