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, _ *registry.ServiceInstance) error
- func (s *Registry) GetService(_ 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 = "chaos-service-id" // LabelsKeyServiceName is used to define the name of the service LabelsKeyServiceName = "chaos-service-app" // LabelsKeyServiceVersion is used to define the version of the service LabelsKeyServiceVersion = "chaos-service-version" // AnnotationsKeyMetadata is used to define the metadata of the service AnnotationsKeyMetadata = "chaos-service-metadata" // AnnotationsKeyProtocolMap is used to define the protocols of the service // Through the value of this field, chaos can obtain the application layer protocol corresponding to the port // Example value: {"80": "http", "8081": "grpc"} AnnotationsKeyProtocolMap = "chaos-service-protocols" )
Defines the key name of specific fields chaos needs to cooperate with the following fields to run properly on Kubernetes: chaos-service-id: define the ID of the service chaos-service-app: define the name of the service chaos-service-version: define the version of the service chaos-service-metadata: define the metadata of the service chaos-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 chaos-service-id: "56991810-c77f-4a95-8190-393efa9c1a61" chaos-service-app: "nginx" chaos-service-version: "v3.5.0" annotations: chaos-service-protocols: | {"80": "http"} chaos-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 ¶
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.