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

Add dynamic Runtime layer to bootstrap #4387

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 9 additions & 11 deletions internal/envoy/v3/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ import (
"github.com/golang/protobuf/ptypes/any"
"github.com/projectcontour/contour/internal/envoy"
"github.com/projectcontour/contour/internal/protobuf"
"google.golang.org/protobuf/types/known/structpb"
)

const (
maxRegexProgramSizeError = 1 << 20
maxRegexProgramSizeWarn = 1000
)

// WriteBootstrap writes bootstrap configuration to files.
Expand Down Expand Up @@ -167,11 +161,15 @@ func bootstrapConfig(c *envoy.BootstrapConfig) *envoy_bootstrap_v3.Bootstrap {
{
Name: "base",
LayerSpecifier: &envoy_bootstrap_v3.RuntimeLayer_StaticLayer{
StaticLayer: &structpb.Struct{
Fields: map[string]*structpb.Value{
"re2.max_program_size.error_level": {Kind: &structpb.Value_NumberValue{NumberValue: maxRegexProgramSizeError}},
"re2.max_program_size.warn_level": {Kind: &structpb.Value_NumberValue{NumberValue: maxRegexProgramSizeWarn}},
},
StaticLayer: baseRuntimeLayer(),
},
},
{
Name: "dynamic",
LayerSpecifier: &envoy_bootstrap_v3.RuntimeLayer_RtdsLayer_{
RtdsLayer: &envoy_bootstrap_v3.RuntimeLayer_RtdsLayer{
Name: DynamicRuntimeLayerName,
RtdsConfig: ConfigSource("contour"),
},
},
},
Expand Down
180 changes: 180 additions & 0 deletions internal/envoy/v3/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,26 @@ func TestBootstrap(t *testing.T) {
"re2.max_program_size.warn_level": 1000
}
},
{
"name": "dynamic",
"rtds_layer": {
"name": "dynamic",
"rtds_config": {
"api_config_source": {
"api_type": "GRPC",
"transport_api_version": "V3",
"grpc_services": [
{
"envoy_grpc": {
"cluster_name": "contour"
}
}
]
},
"resource_api_version": "V3"
}
}
},
{
"name": "admin",
"admin_layer": {}
Expand Down Expand Up @@ -338,6 +358,26 @@ func TestBootstrap(t *testing.T) {
"re2.max_program_size.warn_level": 1000
}
},
{
"name": "dynamic",
"rtds_layer": {
"name": "dynamic",
"rtds_config": {
"api_config_source": {
"api_type": "GRPC",
"transport_api_version": "V3",
"grpc_services": [
{
"envoy_grpc": {
"cluster_name": "contour"
}
}
]
},
"resource_api_version": "V3"
}
}
},
{
"name": "admin",
"admin_layer": {}
Expand Down Expand Up @@ -495,6 +535,26 @@ func TestBootstrap(t *testing.T) {
"re2.max_program_size.warn_level": 1000
}
},
{
"name": "dynamic",
"rtds_layer": {
"name": "dynamic",
"rtds_config": {
"api_config_source": {
"api_type": "GRPC",
"transport_api_version": "V3",
"grpc_services": [
{
"envoy_grpc": {
"cluster_name": "contour"
}
}
]
},
"resource_api_version": "V3"
}
}
},
{
"name": "admin",
"admin_layer": {}
Expand Down Expand Up @@ -653,6 +713,26 @@ func TestBootstrap(t *testing.T) {
"re2.max_program_size.warn_level": 1000
}
},
{
"name": "dynamic",
"rtds_layer": {
"name": "dynamic",
"rtds_config": {
"api_config_source": {
"api_type": "GRPC",
"transport_api_version": "V3",
"grpc_services": [
{
"envoy_grpc": {
"cluster_name": "contour"
}
}
]
},
"resource_api_version": "V3"
}
}
},
{
"name": "admin",
"admin_layer": {}
Expand Down Expand Up @@ -811,6 +891,26 @@ func TestBootstrap(t *testing.T) {
"re2.max_program_size.warn_level": 1000
}
},
{
"name": "dynamic",
"rtds_layer": {
"name": "dynamic",
"rtds_config": {
"api_config_source": {
"api_type": "GRPC",
"transport_api_version": "V3",
"grpc_services": [
{
"envoy_grpc": {
"cluster_name": "contour"
}
}
]
},
"resource_api_version": "V3"
}
}
},
{
"name": "admin",
"admin_layer": {}
Expand Down Expand Up @@ -969,6 +1069,26 @@ func TestBootstrap(t *testing.T) {
"re2.max_program_size.warn_level": 1000
}
},
{
"name": "dynamic",
"rtds_layer": {
"name": "dynamic",
"rtds_config": {
"api_config_source": {
"api_type": "GRPC",
"transport_api_version": "V3",
"grpc_services": [
{
"envoy_grpc": {
"cluster_name": "contour"
}
}
]
},
"resource_api_version": "V3"
}
}
},
{
"name": "admin",
"admin_layer": {}
Expand Down Expand Up @@ -1129,6 +1249,26 @@ func TestBootstrap(t *testing.T) {
"re2.max_program_size.warn_level": 1000
}
},
{
"name": "dynamic",
"rtds_layer": {
"name": "dynamic",
"rtds_config": {
"api_config_source": {
"api_type": "GRPC",
"transport_api_version": "V3",
"grpc_services": [
{
"envoy_grpc": {
"cluster_name": "contour"
}
}
]
},
"resource_api_version": "V3"
}
}
},
{
"name": "admin",
"admin_layer": {}
Expand Down Expand Up @@ -1323,6 +1463,26 @@ func TestBootstrap(t *testing.T) {
"re2.max_program_size.warn_level": 1000
}
},
{
"name": "dynamic",
"rtds_layer": {
"name": "dynamic",
"rtds_config": {
"api_config_source": {
"api_type": "GRPC",
"transport_api_version": "V3",
"grpc_services": [
{
"envoy_grpc": {
"cluster_name": "contour"
}
}
]
},
"resource_api_version": "V3"
}
}
},
{
"name": "admin",
"admin_layer": {}
Expand Down Expand Up @@ -1511,6 +1671,26 @@ func TestBootstrap(t *testing.T) {
"re2.max_program_size.warn_level": 1000
}
},
{
"name": "dynamic",
"rtds_layer": {
"name": "dynamic",
"rtds_config": {
"api_config_source": {
"api_type": "GRPC",
"transport_api_version": "V3",
"grpc_services": [
{
"envoy_grpc": {
"cluster_name": "contour"
}
}
]
},
"resource_api_version": "V3"
}
}
},
{
"name": "admin",
"admin_layer": {}
Expand Down
43 changes: 43 additions & 0 deletions internal/envoy/v3/runtime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright Project Contour Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v3

import (
envoy_service_runtime_v3 "github.com/envoyproxy/go-control-plane/envoy/service/runtime/v3"
"google.golang.org/protobuf/types/known/structpb"
)

const (
DynamicRuntimeLayerName = "dynamic"
maxRegexProgramSizeError = 1 << 20
maxRegexProgramSizeWarn = 1000
)

func RuntimeLayers() []*envoy_service_runtime_v3.Runtime {
return []*envoy_service_runtime_v3.Runtime{
{
Name: DynamicRuntimeLayerName,
Layer: baseRuntimeLayer(),
},
}
}

func baseRuntimeLayer() *structpb.Struct {
return &structpb.Struct{
Fields: map[string]*structpb.Value{
"re2.max_program_size.error_level": {Kind: &structpb.Value_NumberValue{NumberValue: maxRegexProgramSizeError}},
"re2.max_program_size.warn_level": {Kind: &structpb.Value_NumberValue{NumberValue: maxRegexProgramSizeWarn}},
},
}
}
36 changes: 36 additions & 0 deletions internal/envoy/v3/runtime_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright Project Contour Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package v3

import (
"testing"

envoy_service_runtime_v3 "github.com/envoyproxy/go-control-plane/envoy/service/runtime/v3"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/structpb"
)

func TestRuntimeLayers(t *testing.T) {
require.Equal(t, []*envoy_service_runtime_v3.Runtime{
{
Name: "dynamic",
Layer: &structpb.Struct{
Fields: map[string]*structpb.Value{
"re2.max_program_size.error_level": {Kind: &structpb.Value_NumberValue{NumberValue: 1 << 20}},
"re2.max_program_size.warn_level": {Kind: &structpb.Value_NumberValue{NumberValue: 1000}},
},
},
},
}, RuntimeLayers())
}
13 changes: 10 additions & 3 deletions internal/xdscache/v3/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,27 @@ import (
"github.com/golang/protobuf/proto"
"github.com/projectcontour/contour/internal/contour"
"github.com/projectcontour/contour/internal/dag"
envoy_v3 "github.com/projectcontour/contour/internal/envoy/v3"
"github.com/projectcontour/contour/internal/protobuf"
)

// RuntimeCache manages the contents of the gRPC RTDS cache.
type RuntimeCache struct {
contour.Cond
}

// Contents returns an empty set of layers for now.
// Contents returns all Runtime layers.
func (c *RuntimeCache) Contents() []proto.Message {
return []proto.Message{}
return protobuf.AsMessages(envoy_v3.RuntimeLayers())
}

// Query returns an empty set of layers for now.
// Query returns only the "dynamic" layer if requested, otherwise empty.
func (c *RuntimeCache) Query(names []string) []proto.Message {
for _, name := range names {
if name == envoy_v3.DynamicRuntimeLayerName {
return protobuf.AsMessages(envoy_v3.RuntimeLayers())
}
}
return []proto.Message{}
}

Expand Down
Loading