Skip to content

Commit

Permalink
EnvoyFilter: match filter chains, http/network filters (istio#15639)
Browse files Browse the repository at this point in the history
* Match http/network filters

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

* insert before or after

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

* split into smaller files

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

* tests and lint

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

* test

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

* lint

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

* lots of tests

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

* lint1

* test fixes

* lint

* disable until resolution

* lint

* update gogo

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

* unskip tests

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

* lint

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

* integration test

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

* config fixes

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

* bug fix

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

* lint

Signed-off-by: Shriram Rajagopalan <[email protected]>
  • Loading branch information
rshriram authored and istio-testing committed Jul 27, 2019
1 parent 0554870 commit 7376339
Show file tree
Hide file tree
Showing 68 changed files with 6,140 additions and 3,959 deletions.
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ replace k8s.io/klog => github.com/istio/klog v0.0.0-20190424230111-fb7481ea8bcf

replace github.com/spf13/viper => github.com/istio/viper v1.3.3-0.20190515210538-2789fed3109c

replace github.com/gogo/protobuf => github.com/istio/gogo-protobuf v1.2.2-0.20190726125433-4c9abdb3090c

require (
cloud.google.com/go v0.37.4
contrib.go.opencensus.io/exporter/prometheus v0.1.0
Expand Down Expand Up @@ -78,7 +80,7 @@ require (
github.com/golang/sync v0.0.0-20180314180146-1d60e4601c6f
github.com/google/btree v1.0.0 // indirect
github.com/google/cel-go v0.2.0
github.com/google/go-cmp v0.2.0
github.com/google/go-cmp v0.3.0
github.com/google/go-github v15.0.0+incompatible
github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135 // indirect
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect
Expand Down Expand Up @@ -109,6 +111,7 @@ require (
github.com/howeyc/fsnotify v0.9.0
github.com/huandu/xstrings v1.0.0 // indirect
github.com/imdario/mergo v0.3.5 // indirect
github.com/istio/gogo-protobuf v1.2.2-0.20190726125433-4c9abdb3090c // indirect
github.com/jefferai/jsonx v1.0.0 // indirect
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8 // indirect
github.com/json-iterator/go v0.0.0-20180914014843-2433035e5132 // indirect
Expand All @@ -119,7 +122,7 @@ require (
github.com/kr/pretty v0.1.0 // indirect
github.com/lestrrat-go/jwx v0.9.0
github.com/lib/pq v1.1.1 // indirect
github.com/lukechampine/freeze v0.0.0-20160818180733-f514e08ae5a0
github.com/lukechampine/freeze v0.0.0-20160818180733-f514e08ae5a0 // indirect
github.com/mitchellh/copystructure v1.0.0
github.com/mitchellh/go-homedir v0.0.0-20161203194507-b8bc1bf76747
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
Expand Down
9 changes: 7 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ github.com/google/cel-go v0.2.0/go.mod h1:fTCVOuSN/Vn6d49zvRpr3fDAKFyfpLViE0gU+9
github.com/google/cel-spec v0.2.0/go.mod h1:MjQm800JAGhOZXI7vatnVpmIaFTR6L8FHcKk+piiKpI=
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-github v15.0.0+incompatible h1:jlPg2Cpsxb/FyEV/MFiIE9tW/2RAevQNZDPeHbf5a94=
github.com/google/go-github v15.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
github.com/google/go-querystring v0.0.0-20170111101155-53e6ce116135 h1:zLTLjkaOFEFIOxY5BWLFLwh+cL8vOBW4XJ2aqLE/Tf0=
Expand Down Expand Up @@ -286,6 +288,9 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/istio/glog v0.0.0-20190424172949-d7cfb6fa2ccd h1:AJnLAbRpHRy2stiICRI1hcp0f8EExPEiZLgeOmCGnuE=
github.com/istio/glog v0.0.0-20190424172949-d7cfb6fa2ccd/go.mod h1:gF8UB8w1Mqkddo9AqNOPkiduBosB3HHkpC5ra96cDzw=
github.com/istio/gogo-protobuf v1.2.1 h1:8CFvH2ygdNeWdQ7/PaA5ilexEJCO1okGNDL7cqP9Ldo=
github.com/istio/gogo-protobuf v1.2.2-0.20190726125433-4c9abdb3090c h1:nZ1jQm7wyjt21Zc6c1jtf3RVH375/Omgzq+INkXOkWg=
github.com/istio/gogo-protobuf v1.2.2-0.20190726125433-4c9abdb3090c/go.mod h1:vfjn3j3y5/f0PSoVc2mvjpkYi6onwEz0eC1iLQrg8yY=
github.com/istio/klog v0.0.0-20190424230111-fb7481ea8bcf h1:AshFubsUWsHMYfGoz5XLZOOF87wnop5O/Fjjnqjk8lY=
github.com/istio/klog v0.0.0-20190424230111-fb7481ea8bcf/go.mod h1:9gnFtvcm4y+2DZMNXbO8Q7Ke2kUDomg7HhR/mEs5wVA=
github.com/istio/viper v1.3.3-0.20190515210538-2789fed3109c h1:EFWADU43GY2T7NIYYbIHWdrG2hRiWyGSHeON57ZADBE=
Expand All @@ -309,6 +314,7 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
github.com/keybase/go-crypto v0.0.0-20190416182011-b785b22cc757 h1:rHXu79NFmin5AvIe4JsnfCBGb1qAIlMTX0vnpVnDn7s=
github.com/keybase/go-crypto v0.0.0-20190416182011-b785b22cc757/go.mod h1:ghbZscTyKdM07+Fw3KSi0hcJm+AlEUWj8QLlPtijN/M=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
Expand Down Expand Up @@ -547,6 +553,7 @@ golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxb
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c h1:vamGzbGri8IKo20MQncCuljcQ5uAO6kaCeawQPVblAI=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
Expand Down Expand Up @@ -611,8 +618,6 @@ 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-20190716182821-d90184ef5a47 h1:aTfqvytJfCKvZaIr/8jnqBM7uLWLVbyZQQplSL6glvA=
istio.io/api v0.0.0-20190716182821-d90184ef5a47/go.mod h1:hhLFQmpHia8zgaM37vb2ml9iS5NfNfqZGRt1pS9aVEo=
istio.io/api v0.0.0-20190718213450-0a0442bf8664 h1:6qd2tnoFRDkqIcuf7rBOAIoZ9F62nuT/k7xGBUMHfQ8=
istio.io/api v0.0.0-20190718213450-0a0442bf8664/go.mod h1:hhLFQmpHia8zgaM37vb2ml9iS5NfNfqZGRt1pS9aVEo=
istio.io/gogo-genproto v0.0.0-20190614210408-e88dc8b0e4db h1:a++JUbz/eKj16759379pFBhuoiSxUTmnut6ITM/9FEs=
Expand Down
21 changes: 18 additions & 3 deletions pilot/pkg/model/envoyfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
// EnvoyFilterWrapper is a wrapper for the EnvoyFilter api object with pre-processed data
type EnvoyFilterWrapper struct {
workloadSelector config.Labels
ConfigPatches []*EnvoyFilterConfigPatchWrapper
Patches map[networking.EnvoyFilter_ApplyTo][]*EnvoyFilterConfigPatchWrapper
}

// EnvoyFilterConfigPatchWrapper is a wrapper over the EnvoyFilter ConfigPatch api object
Expand All @@ -43,7 +43,7 @@ func convertToEnvoyFilterWrapper(local *Config) *EnvoyFilterWrapper {
if localEnvoyFilter.WorkloadSelector != nil {
out.workloadSelector = config.Labels(localEnvoyFilter.WorkloadSelector.Labels)
}
out.ConfigPatches = make([]*EnvoyFilterConfigPatchWrapper, 0, len(localEnvoyFilter.ConfigPatches))
out.Patches = make(map[networking.EnvoyFilter_ApplyTo][]*EnvoyFilterConfigPatchWrapper)
for _, cp := range localEnvoyFilter.ConfigPatches {
cpw := &EnvoyFilterConfigPatchWrapper{
ApplyTo: cp.ApplyTo,
Expand All @@ -52,7 +52,22 @@ func convertToEnvoyFilterWrapper(local *Config) *EnvoyFilterWrapper {
}
// there wont be an error here because validation catches mismatched types
cpw.Value, _ = config.BuildXDSObjectFromStruct(cp.ApplyTo, cp.Patch.Value)
out.ConfigPatches = append(out.ConfigPatches, cpw)
if cp.Match == nil {
// create a match all object
cpw.Match = &networking.EnvoyFilter_EnvoyConfigObjectMatch{Context: networking.EnvoyFilter_ANY}
}
if _, exists := out.Patches[cp.ApplyTo]; !exists {
out.Patches[cp.ApplyTo] = make([]*EnvoyFilterConfigPatchWrapper, 0)
}
if cpw.Operation == networking.EnvoyFilter_Patch_INSERT_AFTER ||
cpw.Operation == networking.EnvoyFilter_Patch_INSERT_BEFORE {
// insert_before or after is applicable only for network filter and http filter
// convert the rest to add
if cpw.ApplyTo != networking.EnvoyFilter_HTTP_FILTER && cpw.ApplyTo != networking.EnvoyFilter_NETWORK_FILTER {
cpw.Operation = networking.EnvoyFilter_Patch_ADD
}
}
out.Patches[cp.ApplyTo] = append(out.Patches[cp.ApplyTo], cpw)
}
return out
}
22 changes: 14 additions & 8 deletions pilot/pkg/networking/core/v1alpha3/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (

"istio.io/istio/pilot/pkg/features"
"istio.io/istio/pilot/pkg/model"
"istio.io/istio/pilot/pkg/networking/core/v1alpha3/envoyfilter"
"istio.io/istio/pilot/pkg/networking/core/v1alpha3/loadbalancer"
"istio.io/istio/pilot/pkg/networking/plugin"
"istio.io/istio/pilot/pkg/networking/util"
Expand Down Expand Up @@ -80,33 +81,38 @@ func (configgen *ConfigGeneratorImpl) BuildClusters(env *model.Environment, prox
clusters := make([]*apiv2.Cluster, 0)
instances := proxy.ServiceInstances

clusters = append(clusters, configgen.buildOutboundClusters(env, proxy, push)...)
outboundClusters := configgen.buildOutboundClusters(env, proxy, push)

if env.Mesh.LocalityLbSetting != nil {
// apply load balancer setting fot cluster endpoints
applyLocalityLBSetting(proxy.Locality, clusters, env.Mesh.LocalityLbSetting)
applyLocalityLBSetting(proxy.Locality, outboundClusters, env.Mesh.LocalityLbSetting)
}
// Add a blackhole and passthrough cluster for catching traffic to unresolved routes
// DO NOT CALL PLUGINS for these two clusters.
outboundClusters = append(outboundClusters, buildBlackHoleCluster(env), buildDefaultPassthroughCluster(env))

switch proxy.Type {
case model.SidecarProxy:
outboundClusters = envoyfilter.ApplyClusterPatches(networking.EnvoyFilter_SIDECAR_OUTBOUND, proxy, push, outboundClusters)
// Let ServiceDiscovery decide which IP and Port are used for management if
// there are multiple IPs
managementPorts := make([]*model.Port, 0)
for _, ip := range proxy.IPAddresses {
managementPorts = append(managementPorts, env.ManagementPorts(ip)...)
}
clusters = append(clusters, configgen.buildInboundClusters(env, proxy, push, instances, managementPorts)...)
inboundClusters := configgen.buildInboundClusters(env, proxy, push, instances, managementPorts)
inboundClusters = envoyfilter.ApplyClusterPatches(networking.EnvoyFilter_SIDECAR_INBOUND, proxy, push, inboundClusters)
clusters = append(clusters, outboundClusters...)
clusters = append(clusters, inboundClusters...)

default: // Gateways
if proxy.Type == model.Router && proxy.GetRouterMode() == model.SniDnatRouter {
clusters = append(clusters, configgen.buildOutboundSniDnatClusters(env, proxy, push)...)
outboundClusters = append(outboundClusters, configgen.buildOutboundSniDnatClusters(env, proxy, push)...)
}
outboundClusters = envoyfilter.ApplyClusterPatches(networking.EnvoyFilter_GATEWAY, proxy, push, outboundClusters)
clusters = outboundClusters
}

// 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)

return clusters, nil
Expand Down
4 changes: 2 additions & 2 deletions pilot/pkg/networking/core/v1alpha3/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestHTTPCircuitBreakerThresholds(t *testing.T) {
clusterIndex: 0,
}, {
direction: model.TrafficDirectionInbound,
clusterIndex: 1,
clusterIndex: 3,
},
}
settings := []*networking.ConnectionPoolSettings{
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestCommonHttpProtocolOptions(t *testing.T) {
clusterIndex: 0,
}, {
direction: model.TrafficDirectionInbound,
clusterIndex: 1,
clusterIndex: 3,
},
}
settings := &networking.ConnectionPoolSettings{
Expand Down
Loading

0 comments on commit 7376339

Please sign in to comment.