Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(*) drop deprecated Envoy options #2143

Merged
merged 3 commits into from
Jun 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/xds/envoy/clusters/configurers.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,9 @@ func Http2() ClusterBuilderOpt {
config.AddV3(&v3.Http2Configurer{})
})
}

func Http() ClusterBuilderOpt {
return ClusterBuilderOptFunc(func(config *ClusterBuilderConfig) {
config.AddV3(&v3.HttpConfigurer{})
})
}
33 changes: 12 additions & 21 deletions pkg/xds/envoy/clusters/v3/http2_configurer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package clusters
import (
envoy_cluster "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
envoy_core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
envoy_upstream_http "github.com/envoyproxy/go-control-plane/envoy/extensions/upstreams/http/v3"
)

type Http2Configurer struct {
Expand All @@ -11,25 +12,15 @@ type Http2Configurer struct {
var _ ClusterConfigurer = &Http2Configurer{}

func (p *Http2Configurer) Configure(c *envoy_cluster.Cluster) error {
// nolint:staticcheck // keep deprecated options to be compatible with Envoy 1.16.x in Kuma 1.0.x
c.Http2ProtocolOptions = &envoy_core.Http2ProtocolOptions{}

// options := &envoy_upstream_http.HttpProtocolOptions{
// UpstreamProtocolOptions: &envoy_upstream_http.HttpProtocolOptions_ExplicitHttpConfig_{
// ExplicitHttpConfig: &envoy_upstream_http.HttpProtocolOptions_ExplicitHttpConfig{
// ProtocolConfig: &envoy_upstream_http.HttpProtocolOptions_ExplicitHttpConfig_Http2ProtocolOptions{
// Http2ProtocolOptions: &envoy_core.Http2ProtocolOptions{},
// },
// },
// },
// }
//
// pbst, err := proto.MarshalAnyDeterministic(options)
// if err != nil {
// return err
// }
// c.TypedExtensionProtocolOptions = map[string]*any.Any{
// "envoy.extensions.upstreams.http.v3.HttpProtocolOptions": pbst,
// }
return nil
return UpdateCommonHttpProtocolOptions(c, func(options *envoy_upstream_http.HttpProtocolOptions) {
if options.UpstreamProtocolOptions == nil {
options.UpstreamProtocolOptions = &envoy_upstream_http.HttpProtocolOptions_ExplicitHttpConfig_{
ExplicitHttpConfig: &envoy_upstream_http.HttpProtocolOptions_ExplicitHttpConfig{
ProtocolConfig: &envoy_upstream_http.HttpProtocolOptions_ExplicitHttpConfig_Http2ProtocolOptions{
Http2ProtocolOptions: &envoy_core.Http2ProtocolOptions{},
},
},
}
}
})
}
7 changes: 6 additions & 1 deletion pkg/xds/envoy/clusters/v3/http2_configurer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ var _ = Describe("Http2Configurer", func() {

It("should generate proper Envoy config", func() {
// given
expected := `http2ProtocolOptions: {}`
expected := `
typedExtensionProtocolOptions:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
'@type': type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
explicitHttpConfig:
http2ProtocolOptions: {}`

// when
cluster, err := clusters.NewClusterBuilder(envoy.APIV3).
Expand Down
26 changes: 26 additions & 0 deletions pkg/xds/envoy/clusters/v3/http_configurer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package clusters

import (
envoy_cluster "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
envoy_config_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
envoy_upstream_http "github.com/envoyproxy/go-control-plane/envoy/extensions/upstreams/http/v3"
)

type HttpConfigurer struct {
}

var _ ClusterConfigurer = &HttpConfigurer{}

func (p *HttpConfigurer) Configure(c *envoy_cluster.Cluster) error {
return UpdateCommonHttpProtocolOptions(c, func(options *envoy_upstream_http.HttpProtocolOptions) {
if options.UpstreamProtocolOptions == nil {
options.UpstreamProtocolOptions = &envoy_upstream_http.HttpProtocolOptions_ExplicitHttpConfig_{
ExplicitHttpConfig: &envoy_upstream_http.HttpProtocolOptions_ExplicitHttpConfig{
ProtocolConfig: &envoy_upstream_http.HttpProtocolOptions_ExplicitHttpConfig_HttpProtocolOptions{
HttpProtocolOptions: &envoy_config_core_v3.Http1ProtocolOptions{},
},
},
}
}
})
}
35 changes: 35 additions & 0 deletions pkg/xds/envoy/clusters/v3/http_configurer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package clusters_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

util_proto "github.com/kumahq/kuma/pkg/util/proto"
"github.com/kumahq/kuma/pkg/xds/envoy"
"github.com/kumahq/kuma/pkg/xds/envoy/clusters"
)

var _ = Describe("HttpConfigurer", func() {

It("should generate proper Envoy config", func() {
// given
expected := `
typedExtensionProtocolOptions:
envoy.extensions.upstreams.http.v3.HttpProtocolOptions:
'@type': type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions
explicitHttpConfig:
httpProtocolOptions: {}`

// when
cluster, err := clusters.NewClusterBuilder(envoy.APIV3).
Configure(clusters.Http()).
Build()

// then
Expect(err).ToNot(HaveOccurred())

actual, err := util_proto.ToYAML(cluster)
Expect(err).ToNot(HaveOccurred())
Expect(actual).To(MatchYAML(expected))
})
})
49 changes: 17 additions & 32 deletions pkg/xds/envoy/clusters/v3/timeout_configurer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

envoy_cluster "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
envoy_core "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
envoy_upstream_http "github.com/envoyproxy/go-control-plane/envoy/extensions/upstreams/http/v3"
"github.com/golang/protobuf/ptypes"

mesh_proto "github.com/kumahq/kuma/api/mesh/v1alpha1"
Expand All @@ -24,42 +25,26 @@ func (t *TimeoutConfigurer) Configure(cluster *envoy_cluster.Cluster) error {
cluster.ConnectTimeout = ptypes.DurationProto(t.Conf.GetConnectTimeoutOrDefault(defaultConnectTimeout))
switch t.Protocol {
case mesh_core.ProtocolHTTP, mesh_core.ProtocolHTTP2:
// nolint:staticcheck // keep deprecated options to be compatible with Envoy 1.16.x in Kuma 1.0.x
cluster.CommonHttpProtocolOptions = &envoy_core.HttpProtocolOptions{
IdleTimeout: ptypes.DurationProto(t.Conf.GetHttp().GetIdleTimeout().AsDuration()),
err := UpdateCommonHttpProtocolOptions(cluster, func(options *envoy_upstream_http.HttpProtocolOptions) {
if options.CommonHttpProtocolOptions == nil {
options.CommonHttpProtocolOptions = &envoy_core.HttpProtocolOptions{}
}
options.CommonHttpProtocolOptions.IdleTimeout = ptypes.DurationProto(t.Conf.GetHttp().GetIdleTimeout().AsDuration())
})
if err != nil {
return err
}

// options := &envoy_upstream_http.HttpProtocolOptions{
// CommonHttpProtocolOptions: &envoy_core.HttpProtocolOptions{
// IdleTimeout: ptypes.DurationProto(t.Conf.GetHttp().GetIdleTimeout().AsDuration()),
// },
// }
// pbst, err := proto.MarshalAnyDeterministic(options)
// if err != nil {
// return err
// }
// cluster.TypedExtensionProtocolOptions = map[string]*any.Any{
// "envoy.extensions.upstreams.http.v3.HttpProtocolOptions": pbst,
// }
case mesh_core.ProtocolGRPC:
if maxStreamDuration := t.Conf.GetGrpc().GetMaxStreamDuration().AsDuration(); maxStreamDuration != 0 {
// nolint:staticcheck // keep deprecated options to be compatible with Envoy 1.16.x in Kuma 1.0.x
cluster.CommonHttpProtocolOptions = &envoy_core.HttpProtocolOptions{
MaxStreamDuration: ptypes.DurationProto(maxStreamDuration),
err := UpdateCommonHttpProtocolOptions(cluster, func(options *envoy_upstream_http.HttpProtocolOptions) {
if options.CommonHttpProtocolOptions == nil {
options.CommonHttpProtocolOptions = &envoy_core.HttpProtocolOptions{}
}
options.CommonHttpProtocolOptions.MaxStreamDuration = ptypes.DurationProto(maxStreamDuration)
})
if err != nil {
return err
}

// options := &envoy_upstream_http.HttpProtocolOptions{
// CommonHttpProtocolOptions: &envoy_core.HttpProtocolOptions{
// MaxStreamDuration: ptypes.DurationProto(maxStreamDuration),
// },
// }
// pbst, err := proto.MarshalAnyDeterministic(options)
// if err != nil {
// return err
// }
// cluster.TypedExtensionProtocolOptions = map[string]*any.Any{
// "envoy.extensions.upstreams.http.v3.HttpProtocolOptions": pbst,
// }
}
}
return nil
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package clusters

import (
envoy_cluster "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
envoy_upstream_http "github.com/envoyproxy/go-control-plane/envoy/extensions/upstreams/http/v3"
"github.com/golang/protobuf/ptypes/any"
proto2 "google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"

"github.com/kumahq/kuma/pkg/util/proto"
)

func UpdateCommonHttpProtocolOptions(cluster *envoy_cluster.Cluster, fn func(*envoy_upstream_http.HttpProtocolOptions)) error {
if cluster.TypedExtensionProtocolOptions == nil {
cluster.TypedExtensionProtocolOptions = map[string]*any.Any{}
}
options := &envoy_upstream_http.HttpProtocolOptions{}
if any := cluster.TypedExtensionProtocolOptions["envoy.extensions.upstreams.http.v3.HttpProtocolOptions"]; any != nil {
if err := anypb.UnmarshalTo(any, options, proto2.UnmarshalOptions{}); err != nil {
return err
}
}

fn(options)

pbst, err := proto.MarshalAnyDeterministic(options)
if err != nil {
return err
}
cluster.TypedExtensionProtocolOptions["envoy.extensions.upstreams.http.v3.HttpProtocolOptions"] = pbst
return nil
}
24 changes: 10 additions & 14 deletions pkg/xds/envoy/listeners/v3/access_log_configurer.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,16 @@ func fileAccessLog(format *accesslog.AccessLogFormat, cfgStr *structpb.Struct) (
}

fileAccessLog := &access_loggers_file.FileAccessLog{
// AccessLogFormat: &access_loggers_file.FileAccessLog_LogFormat{
// LogFormat: &envoy_core.SubstitutionFormatString{
// Format: &envoy_core.SubstitutionFormatString_TextFormatSource{
// TextFormatSource: &envoy_core.DataSource{
// Specifier: &envoy_core.DataSource_InlineString{
// InlineString: format.String(),
// },
// },
// },
// },
// },
AccessLogFormat: &access_loggers_file.FileAccessLog_Format{
// nolint:staticcheck // keep deprecated options to be compatible with Envoy 1.16.x in Kuma 1.0.x
Format: format.String(),
AccessLogFormat: &access_loggers_file.FileAccessLog_LogFormat{
LogFormat: &envoy_core.SubstitutionFormatString{
Format: &envoy_core.SubstitutionFormatString_TextFormatSource{
TextFormatSource: &envoy_core.DataSource{
Specifier: &envoy_core.DataSource_InlineString{
InlineString: format.String(),
},
},
},
},
},
Path: cfg.Path,
}
Expand Down
11 changes: 6 additions & 5 deletions pkg/xds/envoy/listeners/v3/http_access_log_configurer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,17 @@ var _ = Describe("HttpAccessLogConfigurer", func() {
- name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
format: |+
[%START_TIME%] demo "%REQ(:method)% %REQ(x-envoy-original-path?:path)% %PROTOCOL%" %RESPONSE_CODE% %RESPONSE_FLAGS% %BYTES_RECEIVED% %BYTES_SENT% %DURATION% %RESP(x-envoy-upstream-service-time)% "%REQ(x-forwarded-for)%" "%REQ(user-agent)%" "%REQ(x-request-id)%" "%REQ(:authority)%" "web" "backend" "192.168.0.1" "%UPSTREAM_HOST%"

logFormat:
textFormatSource:
inlineString: |+
[%START_TIME%] demo "%REQ(:method)% %REQ(x-envoy-original-path?:path)% %PROTOCOL%" %RESPONSE_CODE% %RESPONSE_FLAGS% %BYTES_RECEIVED% %BYTES_SENT% %DURATION% %RESP(x-envoy-upstream-service-time)% "%REQ(x-forwarded-for)%" "%REQ(user-agent)%" "%REQ(x-request-id)%" "%REQ(:authority)%" "web" "backend" "192.168.0.1" "%UPSTREAM_HOST%"

path: /tmp/log
httpFilters:
- name: envoy.filters.http.router
statPrefix: backend
name: outbound:127.0.0.1:27070
trafficDirection: OUTBOUND
`,
trafficDirection: OUTBOUND`,
}),
Entry("basic http_connection_manager with tcp access log", testCase{
listenerName: "outbound:127.0.0.1:27070",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,16 @@ var _ = Describe("NetworkAccessLogConfigurer", func() {
- name: envoy.access_loggers.file
typedConfig:
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
format: |+
[%START_TIME%] %RESPONSE_FLAGS% demo 192.168.0.1(backend)->%UPSTREAM_HOST%(db) took %DURATION%ms, sent %BYTES_SENT% bytes, received: %BYTES_RECEIVED% bytes

logFormat:
textFormatSource:
inlineString: |+
[%START_TIME%] %RESPONSE_FLAGS% demo 192.168.0.1(backend)->%UPSTREAM_HOST%(db) took %DURATION%ms, sent %BYTES_SENT% bytes, received: %BYTES_RECEIVED% bytes

path: /tmp/log
cluster: db
statPrefix: db
name: outbound:127.0.0.1:5432
trafficDirection: OUTBOUND
`,
trafficDirection: OUTBOUND`,
}),
Entry("basic tcp_proxy with tcp access log", testCase{
listenerName: "outbound:127.0.0.1:5432",
Expand Down
2 changes: 2 additions & 0 deletions pkg/xds/generator/outbound_proxy_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ func (o OutboundProxyGenerator) generateCDS(ctx xds_context.Context, proxy *mode
proxy.Dataplane.IsIPv6())).
Configure(envoy_clusters.ClientSideTLS(proxy.Routing.OutboundTargets[serviceName]))
switch protocol {
case mesh_core.ProtocolHTTP:
edsClusterBuilder.Configure(envoy_clusters.Http())
case mesh_core.ProtocolHTTP2, mesh_core.ProtocolGRPC:
edsClusterBuilder.Configure(envoy_clusters.Http2())
default:
Expand Down
Loading