3scale-ops / marin3r

Lightweight, CRD based envoy control plane for kubernetes
Apache License 2.0
58 stars 14 forks source link

feat/endpoint-discovery #179

Closed roivaz closed 1 year ago

roivaz commented 1 year ago

Description

With this PR, the discovery service gains the ability to discover and feed a list of Pod IPs to a subscribed consumer. The endpoints are discovered by watching the EndpointSlices resources in the namespace that match a given label selector.

An endpoint resource would have to be declared like

    - type: endpoint
      generateFromEndpointSlices:
        selector:
          matchLabels:
            kubernetes.io/service-name: test
        clusterName: test
        targetPort: http

This would make the discovery service watch the EndpointSlices generated by the k8s Service named test. Any other custom label selector can be used.

The (debug) logs in the discovery service show how the list of pod IPs is generated and feed to consumers:

2023-05-10T10:41:29Z    DEBUG   setup.xds.cache.v3  respond type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment[kuard] version "58f6d94cd" with version "57f9787477"
2023-05-10T10:41:29Z    DEBUG   setup.xds.server.v3 Discovery Response  {"TypeURL": "type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment", "NodeID": "kuard", "StreamID": 1, "Version": "57f9787477", "Resources": ["{\"@type\":\"type.googleapis.com/envoy.config.endpoint.v3.ClusterLoadAssignment\",\"cluster_name\":\"kuard\",\"endpoints\":[{\"lb_endpoints\":[{\"endpoint\":{\"address\":{\"socket_address\":{\"address\":\"10.244.0.14\",\"port_value\":8080}}},\"health_status\":\"HEALTHY\"},{\"endpoint\":{\"address\":{\"socket_address\":{\"address\":\"10.244.0.20\",\"port_value\":8080}}},\"health_status\":\"DRAINING\"}]}]}"], "Pod": "marin3r-envoydeployment-kuard-7578497bb-bbpdn"}

The health status of each endpoint is provided so the consumer can make appropriate load balancing decisions.

/kind feature /priority important-soon /assign

This PR depends on #177 being merged first.

How to test

make kind-create export KUBECONFIG=${PWD}/kubeconfig kubectl apply -f examples/e2e/deployment

Check the logs of the discovery service and the endpoint pod in the default namespace to see how the list of endpoints is updated each time the number of replicas in the nginx deployment is changed.

roivaz commented 1 year ago

/ok-to-test

slopezz commented 1 year ago

/lgtm

3scale-robot commented 1 year ago

LGTM label has been added.

Git tree hash: 81800917772288d9c3e16de13b4135d015d45522

slopezz commented 1 year ago

/lgtm

3scale-robot commented 1 year ago

LGTM label has been added.

Git tree hash: c10f7633594ff2bf58d1b7bbe2054d47596dd632

roivaz commented 1 year ago

/approve

3scale-robot commented 1 year ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: roivaz

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files: - ~~[OWNERS](https://github.com/3scale-ops/marin3r/blob/main/OWNERS)~~ [roivaz] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment