registry

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

The package registry simply implements the Kubernetes-based Registry

Index

Constants

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

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

Example Deployment:

apiVersion: apps/v1 kind: Deployment metadata:

name: nginx
labels:
  app: nginx

spec:

replicas: 5
selector:
  matchLabels:
    app: nginx
template:
  metadata:
    labels:
      app: nginx
      kratos-service-id: "56991810-c77f-4a95-8190-393efa9c1a61"
      kratos-service-app: "nginx"
      kratos-service-version: "v3.5.0"
    annotations:
      kratos-service-protocols: |
        {"80": "http"}
      kratos-service-metadata: |
        {"region": "sh", "zone": "sh001", "cluster": "pd"}
  spec:
    containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
          - containerPort: 80
View Source
const ServiceAccountNamespacePath = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"

ServiceAccountNamespacePath defines the location of the namespace file

Variables

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

ErrIteratorClosed defines the error that the iterator is closed

Functions

func GetNamespace

func GetNamespace() string

GetNamespace is used to get the namespace of the Pod where the current container is located

func GetPodName

func GetPodName() string

GetNamespace is used to get the name of the Pod where the current container is located

func LoadNamespace

func LoadNamespace() string

LoadNamespace is used to get the current namespace from the file

Types

type ErrorHandleResource

type ErrorHandleResource struct {
	Namespace string
	Name      string
	Reason    error
}

ErrorHandleResource defines the error that cannot handle K8S resources normally

func (*ErrorHandleResource) Error

func (err *ErrorHandleResource) Error() string

Error implements the error interface

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

NewIterator is used to initialize Iterator

func (*Iterator) Next

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

Next will block until ServiceInstance changes

func (*Iterator) Stop

func (iter *Iterator) Stop() error

Close is used to close the iterator

type Registry

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

The registry simply implements service discovery based on Kubernetes It has not been verified in the production environment and is currently for reference only

func NewRegistry

func NewRegistry(clientSet *kubernetes.Clientset) *Registry

NewRegistry is used to initialize the Registry

func (*Registry) Close

func (s *Registry) Close()

Close is used to close the Registry After closing, any callbacks generated by Watch will not be executed

func (*Registry) Deregister

func (s *Registry) Deregister(service *registry.ServiceInstance) error

Deregister the registration.

func (*Registry) Register

func (s *Registry) Register(service *registry.ServiceInstance) error

Register is used to register services Note that on Kubernetes, it can only be used to update the id/name/version/metadata/protocols of the current service, but it cannot be used to update node.

func (*Registry) Service

func (s *Registry) Service(name string) ([]*registry.ServiceInstance, error)

Service return the service instances in memory according to the service name.

func (*Registry) Start

func (s *Registry) Start()

Start is used to start the Registry It is non-blocking

func (*Registry) Watch

func (s *Registry) Watch(name string) (registry.Watcher, error)

Watch creates a watcher according to the service name.

Jump to

Keyboard shortcuts

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