Skip to content

Commit

Permalink
EnvoyFilter: http Route match (istio#16146)
Browse files Browse the repository at this point in the history
* add names to http routes

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

* vendor

* adding HTTP_ROUTES

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

* lint and fixes

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

* compile fixes

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

* fixes

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

* more fixes

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

* fixes

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

* final fix

Signed-off-by: Shriram Rajagopalan <[email protected]>
  • Loading branch information
rshriram authored Aug 9, 2019
1 parent 5f8c1fb commit fc69f3d
Show file tree
Hide file tree
Showing 36 changed files with 2,166 additions and 642 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ 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-20190802144653-982935ba456e
istio.io/api v0.0.0-20190808183217-0e77ec002365
istio.io/gogo-genproto v0.0.0-20190731221249-06e20ada0df2
istio.io/pkg v0.0.0-20190731230704-fcbac27d69d5
k8s.io/api v0.0.0-20190222213804-5cb15d344471
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,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-20190802144653-982935ba456e h1:h+7PT/63ylxoseX8SMw8XxvsyVexDBmySZvPRVMDppA=
istio.io/api v0.0.0-20190802144653-982935ba456e/go.mod h1:42cBjnu/rTJcCaKi8nLdIvq0n71RcLrkgZ9IQSvDdSQ=
istio.io/api v0.0.0-20190808183217-0e77ec002365 h1:5k7vp472JbTIyQlYNz/RsdOxLb2LcnrSThblIxJjAOc=
istio.io/api v0.0.0-20190808183217-0e77ec002365/go.mod h1:42cBjnu/rTJcCaKi8nLdIvq0n71RcLrkgZ9IQSvDdSQ=
istio.io/gogo-genproto v0.0.0-20190731221249-06e20ada0df2 h1:AZ+aTgKSBmBc6KtZU+P+Wr2dOdPriJu09cU8wGMG+/M=
istio.io/gogo-genproto v0.0.0-20190731221249-06e20ada0df2/go.mod h1:IjvrbUlRbbw4JCpsgvgihcz9USUwEoNTL/uwMtyV5yk=
istio.io/pkg v0.0.0-20190731230704-fcbac27d69d5 h1:HcASpvj/fuuABkYH9YbsTGEOT75YHyWvvFnTe229zXs=
Expand Down
4 changes: 2 additions & 2 deletions install/kubernetes/helm/istio/files/injection-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ containers:
{{- end }}
{{- if .Values.global.proxy.envoyMetricsService.enabled }}
- --envoyMetricsServiceAddress
- "{{ .ProxyConfig.EnvoyMetricsServiceAddress }}"
- "{{ .ProxyConfig.GetEnvoyMetricsService.GetAddress }}"
{{- end }}
{{- if .Values.global.proxy.envoyAccessLogService.enabled }}
- --envoyAccessLogServiceAddress
- "{{ .ProxyConfig.EnvoyAccessLogServiceAddress }}"
- "{{ .ProxyConfig.GetEnvoyAccessLogService.GetAddress }}"
{{- end }}
- --proxyAdminPort
- "{{ .ProxyConfig.ProxyAdminPort }}"
Expand Down
6 changes: 4 additions & 2 deletions install/kubernetes/helm/istio/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,15 @@ data:
{{- if .Values.global.proxy.envoyMetricsService.enabled }}
#
# Envoy's Metrics Service stats sink pushes Envoy metrics to a remote collector via the Metrics Service gRPC API.
envoyMetricsServiceAddress: {{ .Values.global.proxy.envoyMetricsService.host }}:{{ .Values.global.proxy.envoyMetricsService.port }}
envoyMetricsService:
address: {{ .Values.global.proxy.envoyMetricsService.host }}:{{ .Values.global.proxy.envoyMetricsService.port }}
{{- end}}

{{- if .Values.global.proxy.envoyAccessLogService.enabled }}
#
# Envoy's AccessLog Service pushes access logs to a remote collector via the Access Log Service gRPC API.
envoyAccessLogServiceAddress: {{ .Values.global.proxy.envoyAccessLogService.host }}:{{ .Values.global.proxy.envoyAccessLogService.port }}
envoyAccessLogService:
address: {{ .Values.global.proxy.envoyAccessLogService.host }}:{{ .Values.global.proxy.envoyAccessLogService.port }}
{{- end}}

{{- $defPilotHostname := printf "istio-pilot.%s" .Release.Namespace }}
Expand Down
8 changes: 4 additions & 4 deletions pilot/cmd/pilot-agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ var (
proxyConfig.DiscoveryAddress = discoveryAddress
proxyConfig.ConnectTimeout = types.DurationProto(connectTimeout)
proxyConfig.StatsdUdpAddress = statsdUDPAddress
proxyConfig.EnvoyMetricsServiceAddress = envoyMetricsServiceAddress
proxyConfig.EnvoyAccessLogServiceAddress = envoyAccessLogServiceAddress
proxyConfig.EnvoyMetricsService = &meshconfig.RemoteService{Address: envoyMetricsServiceAddress}
proxyConfig.EnvoyAccessLogService = &meshconfig.RemoteService{Address: envoyAccessLogServiceAddress}
proxyConfig.ProxyAdminPort = int32(proxyAdminPort)
proxyConfig.Concurrency = int32(concurrency)

Expand Down Expand Up @@ -596,9 +596,9 @@ func init() {
"Connection timeout used by Envoy for supporting services")
proxyCmd.PersistentFlags().StringVar(&statsdUDPAddress, "statsdUdpAddress", values.StatsdUdpAddress,
"IP Address and Port of a statsd UDP listener (e.g. 10.75.241.127:9125)")
proxyCmd.PersistentFlags().StringVar(&envoyMetricsServiceAddress, "envoyMetricsServiceAddress", values.EnvoyMetricsServiceAddress,
proxyCmd.PersistentFlags().StringVar(&envoyMetricsServiceAddress, "envoyMetricsServiceAddress", values.EnvoyMetricsService.Address,
"Host and Port of an Envoy Metrics Service API implementation (e.g. metrics-service:15000)")
proxyCmd.PersistentFlags().StringVar(&envoyAccessLogServiceAddress, "envoyAccessLogServiceAddress", values.EnvoyAccessLogServiceAddress,
proxyCmd.PersistentFlags().StringVar(&envoyAccessLogServiceAddress, "envoyAccessLogServiceAddress", values.EnvoyAccessLogService.Address,
"Host and Port of an Envoy gRPC Access Log Service API implementation (e.g. accesslog-service.istio-system:15000)")
proxyCmd.PersistentFlags().Uint16Var(&proxyAdminPort, "proxyAdminPort", uint16(values.ProxyAdminPort),
"Port on which Envoy should listen for administrative commands")
Expand Down
1 change: 1 addition & 0 deletions pilot/pkg/model/envoyfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func convertToEnvoyFilterWrapper(local *Config) *EnvoyFilterWrapper {
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
// TODO: insert before/after is also applicable to http_routes
// convert the rest to add
if cpw.ApplyTo != networking.EnvoyFilter_HTTP_FILTER && cpw.ApplyTo != networking.EnvoyFilter_NETWORK_FILTER {
cpw.Operation = networking.EnvoyFilter_Patch_ADD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func ApplyClusterPatches(patchContext networking.EnvoyFilter_PatchContext, proxy
for _, cp := range efw.Patches[networking.EnvoyFilter_CLUSTER] {
if cp.Operation == networking.EnvoyFilter_Patch_ADD {
if commonConditionMatch(proxy, patchContext, cp) {
clusters = append(clusters, cp.Value.(*xdsapi.Cluster))
clusters = append(clusters, proto.Clone(cp.Value).(*xdsapi.Cluster))
}
}
}
Expand Down
34 changes: 18 additions & 16 deletions pilot/pkg/networking/core/v1alpha3/envoyfilter/listener_patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ func doListenerListOperation(proxy *model.Proxy, patchContext networking.EnvoyFi
continue
}

listeners = append(listeners, cp.Value.(*xdsapi.Listener))
// clone before append. Otherwise, subsequent operations on this listener will corrupt
// the master value stored in CP..
listeners = append(listeners, proto.Clone(cp.Value).(*xdsapi.Listener))
}
}
}
Expand Down Expand Up @@ -115,7 +117,7 @@ func doFilterChainListOperation(proxy *model.Proxy, patchContext networking.Envo
!listenerMatch(listener, cp) {
continue
}
listener.FilterChains = append(listener.FilterChains, cp.Value.(*xdslistener.FilterChain))
listener.FilterChains = append(listener.FilterChains, proto.Clone(cp.Value).(*xdslistener.FilterChain))
}
}
if filterChainsRemoved {
Expand Down Expand Up @@ -169,11 +171,11 @@ func doNetworkFilterListOperation(proxy *model.Proxy, patchContext networking.En
}

if cp.Operation == networking.EnvoyFilter_Patch_ADD {
fc.Filters = append(fc.Filters, cp.Value.(*xdslistener.Filter))
fc.Filters = append(fc.Filters, proto.Clone(cp.Value).(*xdslistener.Filter))
} else if cp.Operation == networking.EnvoyFilter_Patch_INSERT_AFTER {
// Insert after without a filter match is same as ADD in the end
if !hasNetworkFilterMatch(cp) {
fc.Filters = append(fc.Filters, cp.Value.(*xdslistener.Filter))
fc.Filters = append(fc.Filters, proto.Clone(cp.Value).(*xdslistener.Filter))
continue
}
// find the matching filter first
Expand All @@ -189,15 +191,15 @@ func doNetworkFilterListOperation(proxy *model.Proxy, patchContext networking.En
continue
}

fc.Filters = append(fc.Filters, cp.Value.(*xdslistener.Filter))
fc.Filters = append(fc.Filters, proto.Clone(cp.Value).(*xdslistener.Filter))
if insertPosition < len(fc.Filters)-1 {
copy(fc.Filters[insertPosition+1:], fc.Filters[insertPosition:])
fc.Filters[insertPosition] = cp.Value.(*xdslistener.Filter)
fc.Filters[insertPosition] = proto.Clone(cp.Value).(*xdslistener.Filter)
}
} else if cp.Operation == networking.EnvoyFilter_Patch_INSERT_BEFORE {
// insert before without a filter match is same as insert in the beginning
if !hasNetworkFilterMatch(cp) {
fc.Filters = append([]*xdslistener.Filter{cp.Value.(*xdslistener.Filter)}, fc.Filters...)
fc.Filters = append([]*xdslistener.Filter{proto.Clone(cp.Value).(*xdslistener.Filter)}, fc.Filters...)
continue
}
// find the matching filter first
Expand All @@ -212,9 +214,9 @@ func doNetworkFilterListOperation(proxy *model.Proxy, patchContext networking.En
if insertPosition == -1 {
continue
}
fc.Filters = append(fc.Filters, cp.Value.(*xdslistener.Filter))
fc.Filters = append(fc.Filters, proto.Clone(cp.Value).(*xdslistener.Filter))
copy(fc.Filters[insertPosition+1:], fc.Filters[insertPosition:])
fc.Filters[insertPosition] = cp.Value.(*xdslistener.Filter)
fc.Filters[insertPosition] = proto.Clone(cp.Value).(*xdslistener.Filter)
}
}
if networkFiltersRemoved {
Expand Down Expand Up @@ -284,11 +286,11 @@ func doHTTPFilterListOperation(proxy *model.Proxy, patchContext networking.Envoy
}

if cp.Operation == networking.EnvoyFilter_Patch_ADD {
hcm.HttpFilters = append(hcm.HttpFilters, cp.Value.(*http_conn.HttpFilter))
hcm.HttpFilters = append(hcm.HttpFilters, proto.Clone(cp.Value).(*http_conn.HttpFilter))
} else if cp.Operation == networking.EnvoyFilter_Patch_INSERT_AFTER {
// Insert after without a filter match is same as ADD in the end
if !hasHTTPFilterMatch(cp) {
hcm.HttpFilters = append(hcm.HttpFilters, cp.Value.(*http_conn.HttpFilter))
hcm.HttpFilters = append(hcm.HttpFilters, proto.Clone(cp.Value).(*http_conn.HttpFilter))
continue
}

Expand All @@ -305,15 +307,15 @@ func doHTTPFilterListOperation(proxy *model.Proxy, patchContext networking.Envoy
continue
}

hcm.HttpFilters = append(hcm.HttpFilters, cp.Value.(*http_conn.HttpFilter))
hcm.HttpFilters = append(hcm.HttpFilters, proto.Clone(cp.Value).(*http_conn.HttpFilter))
if insertPosition < len(hcm.HttpFilters)-1 {
copy(hcm.HttpFilters[insertPosition+1:], hcm.HttpFilters[insertPosition:])
hcm.HttpFilters[insertPosition] = cp.Value.(*http_conn.HttpFilter)
hcm.HttpFilters[insertPosition] = proto.Clone(cp.Value).(*http_conn.HttpFilter)
}
} else if cp.Operation == networking.EnvoyFilter_Patch_INSERT_BEFORE {
// insert before without a filter match is same as insert in the beginning
if !hasHTTPFilterMatch(cp) {
hcm.HttpFilters = append([]*http_conn.HttpFilter{cp.Value.(*http_conn.HttpFilter)}, hcm.HttpFilters...)
hcm.HttpFilters = append([]*http_conn.HttpFilter{proto.Clone(cp.Value).(*http_conn.HttpFilter)}, hcm.HttpFilters...)
continue
}

Expand All @@ -329,9 +331,9 @@ func doHTTPFilterListOperation(proxy *model.Proxy, patchContext networking.Envoy
if insertPosition == -1 {
continue
}
hcm.HttpFilters = append(hcm.HttpFilters, cp.Value.(*http_conn.HttpFilter))
hcm.HttpFilters = append(hcm.HttpFilters, proto.Clone(cp.Value).(*http_conn.HttpFilter))
copy(hcm.HttpFilters[insertPosition+1:], hcm.HttpFilters[insertPosition:])
hcm.HttpFilters[insertPosition] = cp.Value.(*http_conn.HttpFilter)
hcm.HttpFilters[insertPosition] = proto.Clone(cp.Value).(*http_conn.HttpFilter)
}
}
if httpFiltersRemoved {
Expand Down
Loading

0 comments on commit fc69f3d

Please sign in to comment.