Skip to content

Commit

Permalink
EnvoyFilter: patch/add/remove clusters and virtual hosts (istio#15515)
Browse files Browse the repository at this point in the history
* first cut

Signed-off-by: Shriram Rajagopalan <[email protected]>

* simplify

Signed-off-by: Shriram Rajagopalan <[email protected]>

* refactor

Signed-off-by: Shriram Rajagopalan <[email protected]>

* lint

Signed-off-by: Shriram Rajagopalan <[email protected]>

* adding vhost support

Signed-off-by: Shriram Rajagopalan <[email protected]>

* tests

Signed-off-by: Shriram Rajagopalan <[email protected]>

* lint

Signed-off-by: Shriram Rajagopalan <[email protected]>

* update api

Signed-off-by: Shriram Rajagopalan <[email protected]>

* update api

Signed-off-by: Shriram Rajagopalan <[email protected]>
  • Loading branch information
rshriram authored and istio-testing committed Jul 17, 2019
1 parent 515956c commit 58e63d6
Show file tree
Hide file tree
Showing 33 changed files with 2,660 additions and 702 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ require (
gopkg.in/stack.v1 v1.7.0 // indirect
gopkg.in/yaml.v2 v2.2.2
gotest.tools v2.2.0+incompatible // indirect
istio.io/api v0.0.0-20190708200418-70f6e4eada00
istio.io/pkg v0.0.0-20190710182420-c26792dead42
istio.io/api v0.0.0-20190716171133-115cae561388
istio.io/gogo-genproto v0.0.0-20190614210408-e88dc8b0e4db
istio.io/pkg v0.0.0-20190710182420-c26792dead42
k8s.io/api v0.0.0-20190222213804-5cb15d344471
k8s.io/apiextensions-apiserver v0.0.0-20190221221350-bfb440be4b87
k8s.io/apimachinery v0.0.0-20190221213512-86fb29eff628
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,8 @@ honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
istio.io/api v0.0.0-20190515205759-982e5c3888c6/go.mod h1:hhLFQmpHia8zgaM37vb2ml9iS5NfNfqZGRt1pS9aVEo=
istio.io/api v0.0.0-20190708200418-70f6e4eada00 h1:ai5OOuzb6/ehXsHPleANbXfezeq/Lasod/1Qm/SI4Cg=
istio.io/api v0.0.0-20190708200418-70f6e4eada00/go.mod h1:hhLFQmpHia8zgaM37vb2ml9iS5NfNfqZGRt1pS9aVEo=
istio.io/api v0.0.0-20190716171133-115cae561388 h1:6ZanA/X/ulO3qz4HHHhe9vyqbwih+jrCIkdzeTLo8wc=
istio.io/api v0.0.0-20190716171133-115cae561388/go.mod h1:hhLFQmpHia8zgaM37vb2ml9iS5NfNfqZGRt1pS9aVEo=
istio.io/gogo-genproto v0.0.0-20190614210408-e88dc8b0e4db h1:a++JUbz/eKj16759379pFBhuoiSxUTmnut6ITM/9FEs=
istio.io/gogo-genproto v0.0.0-20190614210408-e88dc8b0e4db/go.mod h1:eIDJ6jNk/IeJz6ODSksHl5Aiczy5JUq6vFhJWI5OtiI=
istio.io/pkg v0.0.0-20190710182420-c26792dead42 h1:2GOb5IEH8Q4tbv4sw6OabHV/xcRK4qQD5lLieiYe64s=
Expand Down
21 changes: 21 additions & 0 deletions pilot/pkg/model/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package model

import (
"fmt"
"strconv"
"strings"

networking "istio.io/api/networking/v1alpha3"
Expand Down Expand Up @@ -292,6 +293,26 @@ func gatewayRDSRouteName(server *networking.Server, config Config) string {
return ""
}

// ParseGatewayRDSRouteName is used by the EnvoyFilter patching logic to match
// a specific route configuration to patch.
func ParseGatewayRDSRouteName(name string) (portNumber int, portName, gateway string) {
parts := strings.Split(name, ".")
if strings.HasPrefix(name, "http.") {
// this is a http gateway. Parse port number and return empty string for rest
if len(parts) == 2 {
portNumber, _ = strconv.Atoi(parts[1])
}
} else if strings.HasPrefix(name, "https.") {
if len(parts) == 5 {
portNumber, _ = strconv.Atoi(parts[1])
portName = parts[2]
// gateway name should be ns/name
gateway = parts[4] + "/" + parts[3]
}
}
return
}

// convert ./host to currentNamespace/Host
// */host to just host
// */* to just *
Expand Down
49 changes: 49 additions & 0 deletions pilot/pkg/model/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,52 @@ func makeConfig(name, namespace, host, portName, portProtocol string, portNumber
}
return c
}

func TestParseGatewayRDSRouteName(t *testing.T) {
type args struct {
name string
}
tests := []struct {
name string
args args
wantPortNumber int
wantPortName string
wantGateway string
}{
{
name: "invalid rds name",
args: args{"https.scooby.dooby.doo"},
wantPortNumber: 0,
wantPortName: "",
wantGateway: "",
},
{
name: "gateway http rds name",
args: args{"http.80"},
wantPortNumber: 80,
wantPortName: "",
wantGateway: "",
},
{
name: "https rds name",
args: args{"https.443.app1.gw1.ns1"},
wantPortNumber: 443,
wantPortName: "app1",
wantGateway: "ns1/gw1",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotPortNumber, gotPortName, gotGateway := ParseGatewayRDSRouteName(tt.args.name)
if gotPortNumber != tt.wantPortNumber {
t.Errorf("ParseGatewayRDSRouteName() gotPortNumber = %v, want %v", gotPortNumber, tt.wantPortNumber)
}
if gotPortName != tt.wantPortName {
t.Errorf("ParseGatewayRDSRouteName() gotPortName = %v, want %v", gotPortName, tt.wantPortName)
}
if gotGateway != tt.wantGateway {
t.Errorf("ParseGatewayRDSRouteName() gotGateway = %v, want %v", gotGateway, tt.wantGateway)
}
})
}
}
3 changes: 1 addition & 2 deletions pilot/pkg/networking/core/v1alpha3/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ func (configgen *ConfigGeneratorImpl) BuildClusters(env *model.Environment, prox
// Add a blackhole and passthrough cluster for catching traffic to unresolved routes
// DO NOT CALL PLUGINS for these two clusters.
clusters = append(clusters, buildBlackHoleCluster(env), buildDefaultPassthroughCluster(env))

clusters = applyClusterPatches(env, proxy, push, clusters)
clusters = normalizeClusters(push, proxy, clusters)
clusters = applyClusterConfigPatches(clusters, env, proxy.WorkloadLabels)

return clusters, nil
}
Expand Down
Loading

0 comments on commit 58e63d6

Please sign in to comment.