Skip to content
This repository has been archived by the owner on Aug 12, 2020. It is now read-only.

Commit

Permalink
Add Linkerd l5d headers
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprodan committed Oct 29, 2019
1 parent 8a4e3b1 commit 89444a4
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions pkg/discovery/envoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type EnvoyConfig struct {
type Upstream struct {
Name string
Host string
Port uint32
Domain string
Prefix string
Retries uint32
Expand Down Expand Up @@ -69,9 +70,10 @@ func (e *EnvoyConfig) Sync() {
return true
}

cluster := serviceToCluster(service, portName, 5000)
cluster, port := serviceToCluster(service, portName, 5000)
if cluster != nil {
upstream.Name = cluster.Name
upstream.Port = port
clusters = append(clusters, cluster)
domains[cluster.Name] = upstream
} else {
Expand All @@ -96,19 +98,19 @@ func (e *EnvoyConfig) Sync() {
}
}

func serviceToCluster(svc corev1.Service, portName string, timeout int) *ev2.Cluster {
var port uint32
func serviceToCluster(svc corev1.Service, portName string, timeout int) (cluster *ev2.Cluster, port uint32) {
for _, p := range svc.Spec.Ports {
if p.Name == portName {
port = uint32(p.Port)
}
}
if port == 0 {
return nil
return
}
name := fmt.Sprintf("%s-%s-%d", svc.Name, svc.Namespace, port)
address := fmt.Sprintf("%s.%s", svc.Name, svc.Namespace)
return makeCluster(name, address, port, timeout)
cluster = makeCluster(name, address, port, timeout)
return
}

func makeCluster(name string, address string, port uint32, timeout int) *ev2.Cluster {
Expand Down Expand Up @@ -155,6 +157,15 @@ func makeVirtualHost(name string, upstream Upstream) route.VirtualHost {
Domains: []string{upstream.Domain},
Routes: []*route.Route{r},
RetryPolicy: makeRetryPolicy(upstream.Retries),
RequestHeadersToAdd: []*ecore.HeaderValueOption{
{
Header: &ecore.HeaderValue{
Key: "l5d-dst-override",
Value: fmt.Sprintf("%s.svc.cluster.local:%d", upstream.Host, upstream.Port),
},
},
},
RequestHeadersToRemove: []string{"l5d-remote-ip", "l5d-server-id"},
}
}

Expand Down

0 comments on commit 89444a4

Please sign in to comment.