Documentation ¶
Overview ¶
Package kuberegistry registry simply implements the Kubernetes-based Registry
Index ¶
- Constants
- Variables
- func GetNamespace() string
- func GetPodName() string
- func LoadNamespace() string
- type ErrorHandleResource
- type Iterator
- type Registry
- func (s *Registry) Close()
- func (s *Registry) Deregister(ctx context.Context, service *registry.ServiceInstance) error
- func (s *Registry) GetService(ctx context.Context, name string) ([]*registry.ServiceInstance, error)
- func (s *Registry) Register(ctx context.Context, service *registry.ServiceInstance) error
- func (s *Registry) Start()
- func (s *Registry) Watch(ctx context.Context, name string) (registry.Watcher, error)
Constants ¶
const ( // LabelsKeyServiceID is used to define the ID of the service LabelsKeyServiceID = "mars-service-id" // LabelsKeyServiceName is used to define the name of the service LabelsKeyServiceName = "mars-service-app" // LabelsKeyServiceVersion is used to define the version of the service LabelsKeyServiceVersion = "mars-service-version" // AnnotationsKeyMetadata is used to define the metadata of the service AnnotationsKeyMetadata = "mars-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 = "mars-service-protocols" )
Defines the key name of specific fields Kratos needs to cooperate with the following fields to run properly on Kubernetes: mars-service-id: define the ID of the service mars-service-app: define the name of the service mars-service-version: define the version of the service mars-service-metadata: define the metadata of the service mars-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 mars-service-id: "56991810-c77f-4a95-8190-393efa9c1a61" mars-service-app: "nginx" mars-service-version: "v3.5.0" annotations: mars-service-protocols: | {"80": "http"} mars-service-metadata: | {"region": "sh", "zone": "sh001", "cluster": "pd"} spec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80
const ServiceAccountNamespacePath = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"
ServiceAccountNamespacePath defines the location of the namespace file
Variables ¶
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
GetPodName 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 ¶
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
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 ¶
Deregister the registration.
func (*Registry) GetService ¶
func (s *Registry) GetService(ctx context.Context, name string) ([]*registry.ServiceInstance, error)
GetService return the service instances in memory according to the service name.
func (*Registry) Register ¶
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.