-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dataclients/kubernetes: add metadata route
Adds a special route with a predefined id `kube__metadata` that contains `False` predicate and no filters. The first argument of `False` predicate (which it ignores anyway) contains endpoint metadata encoded as JSON. Example (formatted): ``` kube__metadata: False("{ \"addresses\":[ { \"address\":\"1.2.3.4\", \"zone\":\"zoneA\", \"nodeName\":\"node1\", \"targetRef\":{ \"kind\":\"Pod\", \"name\":\"foo-app\", \"namespace\":\"default\", \"uid\":\"83a6408f-8a5b-405c-93f4-1199f7712956\" } }, ... ]") ``` This route could be used to obtain zone, node and pod names for a given address. E.g. EndpointRegistry postprocessor may check this route and store zone, node and pod name for each endpoint. TODO: - [ ] add flag to enable metadata route - [ ] tests Fixes #1559 Signed-off-by: Alexander Yastrebov <[email protected]>
- Loading branch information
1 parent
4d76a05
commit b773b22
Showing
7 changed files
with
95 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package kubernetes | ||
|
||
import ( | ||
"encoding/json" | ||
"strings" | ||
|
||
"github.com/zalando/skipper/eskip" | ||
"github.com/zalando/skipper/predicates" | ||
) | ||
|
||
type kubeRouteMetadata struct { | ||
Addresses []kubeRouteMetadataAddress `json:"addresses"` | ||
} | ||
|
||
type kubeRouteMetadataAddress struct { | ||
Address string `json:"address"` | ||
Zone string `json:"zone"` | ||
NodeName string `json:"nodeName"` | ||
TargetRef *objectReference `json:"targetRef"` | ||
} | ||
|
||
// metadataRoute creates a route with [MetadataRouteID] id that matches no requests and | ||
// contains metadata for each endpoint address used by Ingresses and RouteGroups. | ||
func metadataRoute(s *clusterState) *eskip.Route { | ||
var metadata kubeRouteMetadata | ||
for id := range s.cachedEndpoints { | ||
if s.enableEndpointSlices { | ||
if eps, ok := s.endpointSlices[id.ResourceID]; ok { | ||
for _, ep := range eps.Endpoints { | ||
metadata.Addresses = append(metadata.Addresses, kubeRouteMetadataAddress{ | ||
Address: ep.Address, | ||
Zone: ep.Zone, | ||
NodeName: ep.NodeName, | ||
TargetRef: ep.TargetRef, | ||
}) | ||
} | ||
} | ||
} else { | ||
if ep, ok := s.endpoints[id.ResourceID]; ok { | ||
for _, subset := range ep.Subsets { | ||
for _, addr := range subset.Addresses { | ||
metadata.Addresses = append(metadata.Addresses, kubeRouteMetadataAddress{ | ||
Address: addr.IP, | ||
NodeName: addr.NodeName, | ||
TargetRef: addr.TargetRef, | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
var b strings.Builder | ||
_ = json.NewEncoder(&b).Encode(&metadata) | ||
|
||
return &eskip.Route{ | ||
Id: MetadataRouteID, | ||
Predicates: []*eskip.Predicate{{Name: predicates.FalseName, Args: []any{b.String()}}}, | ||
BackendType: eskip.ShuntBackend, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters