[go: up one dir, main page]

Skip to content

Commit

Permalink
update envoy/go-control-plane
Browse files Browse the repository at this point in the history
Signed-off-by: Alice Wasko <alicewasko@datawire.io>
  • Loading branch information
Alice Wasko authored and Alice-Lilith committed May 28, 2024
1 parent 8d75fd4 commit 8b343d5
Show file tree
Hide file tree
Showing 38 changed files with 530 additions and 448 deletions.
2 changes: 2 additions & 0 deletions DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ following Free and Open Source software:
github.com/peterbourgon/diskv v2.0.1+incompatible MIT license
github.com/pjbgf/sha1cd v0.3.0 Apache License 2.0
github.com/pkg/errors v0.9.1 2-clause BSD license
github.com/planetscale/vtprotobuf v0.6.0 3-clause BSD license
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 3-clause BSD license
github.com/prometheus/client_golang v1.17.0 Apache License 2.0
github.com/prometheus/client_model v0.5.0 Apache License 2.0
Expand All @@ -123,6 +124,7 @@ following Free and Open Source software:
github.com/xlab/treeprint v1.2.0 MIT license
go.opentelemetry.io/proto/otlp v1.0.0 Apache License 2.0
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca 3-clause BSD license
go.uber.org/goleak v1.2.1 MIT license
go.uber.org/multierr v1.11.0 MIT license
go.uber.org/zap v1.26.0 MIT license
golang.org/x/crypto v0.21.0 3-clause BSD license
Expand Down
2 changes: 1 addition & 1 deletion _cxx/envoy.mk
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ENVOY_DOCKER_TAG ?= $(ENVOY_DOCKER_REPO):envoy-$(ENVOY_DOCKER_VERSION)
# which commits are ancestors, I added `make guess-envoy-go-control-plane-commit` to do that in an
# automated way! Still look at the commit yourself to make sure it seems sane; blindly trusting
# machines is bad, mmkay?
ENVOY_GO_CONTROL_PLANE_COMMIT = 6e4589f570e19a3d17087cf80d40bacdc6356de6
ENVOY_GO_CONTROL_PLANE_COMMIT = 57c85e1829e6fe6e73fb69b8a9d9f2d3780572a5

# Set ENVOY_DOCKER_REPO to the list of mirrors to check
ENVOY_DOCKER_REPOS = docker.io/emissaryingress/base-envoy
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ require (
github.com/envoyproxy/protoc-gen-validate v1.0.2
github.com/fsnotify/fsnotify v1.7.0
github.com/go-logr/zapr v1.2.4
github.com/golang/protobuf v1.5.3
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.5.0
github.com/gorilla/websocket v1.5.1
github.com/hashicorp/consul/api v1.26.1
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/pkg/errors v0.9.1
github.com/planetscale/vtprotobuf v0.6.0
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2
github.com/prometheus/client_model v0.5.0
github.com/sirupsen/logrus v1.9.3
Expand All @@ -105,6 +105,7 @@ require (
github.com/spf13/viper v1.7.0
github.com/stretchr/testify v1.8.4
go.opentelemetry.io/proto/otlp v1.0.0
go.uber.org/goleak v1.2.1
go.uber.org/zap v1.26.0
golang.org/x/mod v0.14.0
golang.org/x/sync v0.5.0
Expand Down Expand Up @@ -169,6 +170,7 @@ require (
github.com/gobuffalo/flect v1.0.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/cel-go v0.18.1 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/planetscale/vtprotobuf v0.6.0 h1:nBeETjudeJ5ZgBHUz1fVHvbqUKnYOXNhsIEabROxmNA=
github.com/planetscale/vtprotobuf v0.6.0/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down
5 changes: 3 additions & 2 deletions pkg/envoy-control-plane/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# control-plane

[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/envoyproxy/go-control-plane/badge)](https://api.securityscorecards.dev/projects/github.com/envoyproxy/go-control-plane)
![CI Status](https://github.com/envoyproxy/go-control-plane/actions/workflows/ci.yaml/badge.svg)
[![Go Report Card](https://goreportcard.com/badge/github.com/envoyproxy/go-control-plane)](https://goreportcard.com/report/github.com/envoyproxy/go-control-plane)
[![GoDoc](https://pkg.go.dev/badge/github.com/envoyproxy/go-control-plane.svg)](https://pkg.go.dev/github.com/envoyproxy/go-control-plane)
Expand Down Expand Up @@ -40,11 +41,11 @@ pre-defined hash function whose keys are based on the
At this moment, this repository will not tackle translating platform
specific representation of resources (e.g., services, instances of
services, etc.) into Envoy-style configuration. Based on usage and
feedback, we might decided to revisit this aspect at a later point in time.
feedback, we might decide to revisit this aspect at a later point in time.

## Requirements

1. Go 1.16+
1. Go 1.17+

## Quick start

Expand Down
8 changes: 4 additions & 4 deletions pkg/envoy-control-plane/cache/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ type ResponseType int
// ADS expects things to be returned in a specific order.
// See the following issue for details: https://github.com/envoyproxy/go-control-plane/issues/526
const (
Endpoint ResponseType = iota
Cluster
ScopedRoute
Cluster ResponseType = iota
Endpoint
Listener
Route
ScopedRoute
VirtualHost
Listener
Secret
Runtime
ExtensionConfig
Expand Down
33 changes: 20 additions & 13 deletions pkg/envoy-control-plane/cache/v3/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@ type RawDeltaResponse struct {
marshaledResponse atomic.Value
}

var _ Response = &RawResponse{}
var _ DeltaResponse = &RawDeltaResponse{}
var (
_ Response = &RawResponse{}
_ DeltaResponse = &RawDeltaResponse{}
)

// PassthroughResponse is a pre constructed xDS response that need not go through marshaling transformations.
type PassthroughResponse struct {
Expand All @@ -195,8 +197,10 @@ type DeltaPassthroughResponse struct {
ctx context.Context
}

var _ Response = &PassthroughResponse{}
var _ DeltaResponse = &DeltaPassthroughResponse{}
var (
_ Response = &PassthroughResponse{}
_ DeltaResponse = &DeltaPassthroughResponse{}
)

// GetDiscoveryResponse performs the marshaling the first time its called and uses the cached response subsequently.
// This is necessary because the marshaled response does not change across the calls.
Expand Down Expand Up @@ -225,7 +229,7 @@ func (r *RawResponse) GetDiscoveryResponse() (*discovery.DiscoveryResponse, erro
marshaledResponse = &discovery.DiscoveryResponse{
VersionInfo: r.Version,
Resources: marshaledResources,
TypeUrl: r.Request.TypeUrl,
TypeUrl: r.GetRequest().GetTypeUrl(),
}

r.marshaledResponse.Store(marshaledResponse)
Expand Down Expand Up @@ -256,7 +260,7 @@ func (r *RawDeltaResponse) GetDeltaDiscoveryResponse() (*discovery.DeltaDiscover
marshaledResources[i] = &discovery.Resource{
Name: name,
Resource: &anypb.Any{
TypeUrl: r.DeltaRequest.TypeUrl,
TypeUrl: r.GetDeltaRequest().GetTypeUrl(),
Value: marshaledResource,
},
Version: version,
Expand All @@ -266,7 +270,7 @@ func (r *RawDeltaResponse) GetDeltaDiscoveryResponse() (*discovery.DeltaDiscover
marshaledResponse = &discovery.DeltaDiscoveryResponse{
Resources: marshaledResources,
RemovedResources: r.RemovedResources,
TypeUrl: r.DeltaRequest.TypeUrl,
TypeUrl: r.GetDeltaRequest().GetTypeUrl(),
SystemVersionInfo: r.SystemVersionInfo,
}
r.marshaledResponse.Store(marshaledResponse)
Expand Down Expand Up @@ -322,14 +326,14 @@ func (r *RawResponse) maybeCreateTTLResource(resource types.ResourceWithTTL) (ty
if err != nil {
return nil, "", err
}
rsrc.TypeUrl = r.Request.TypeUrl
rsrc.TypeUrl = r.GetRequest().GetTypeUrl()
wrappedResource.Resource = rsrc
}

return wrappedResource, deltaResourceTypeURL, nil
}

return resource.Resource, r.Request.TypeUrl, nil
return resource.Resource, r.GetRequest().GetTypeUrl(), nil
}

// GetDiscoveryResponse returns the final passthrough Discovery Response.
Expand All @@ -354,19 +358,22 @@ func (r *DeltaPassthroughResponse) GetDeltaRequest() *discovery.DeltaDiscoveryRe

// GetVersion returns the response version.
func (r *PassthroughResponse) GetVersion() (string, error) {
if r.DiscoveryResponse != nil {
return r.DiscoveryResponse.VersionInfo, nil
discoveryResponse, _ := r.GetDiscoveryResponse()
if discoveryResponse != nil {
return discoveryResponse.GetVersionInfo(), nil
}
return "", fmt.Errorf("DiscoveryResponse is nil")
}

func (r *PassthroughResponse) GetContext() context.Context {
return r.ctx
}

// GetSystemVersion returns the response version.
func (r *DeltaPassthroughResponse) GetSystemVersion() (string, error) {
if r.DeltaDiscoveryResponse != nil {
return r.DeltaDiscoveryResponse.SystemVersionInfo, nil
deltaDiscoveryResponse, _ := r.GetDeltaDiscoveryResponse()
if deltaDiscoveryResponse != nil {
return deltaDiscoveryResponse.GetSystemVersionInfo(), nil
}
return "", fmt.Errorf("DeltaDiscoveryResponse is nil")
}
Expand Down
49 changes: 25 additions & 24 deletions pkg/envoy-control-plane/cache/v3/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
Expand All @@ -28,24 +29,24 @@ func TestResponseGetDiscoveryResponse(t *testing.T) {
}

discoveryResponse, err := resp.GetDiscoveryResponse()
assert.Nil(t, err)
assert.Equal(t, discoveryResponse.VersionInfo, resp.Version)
assert.Equal(t, len(discoveryResponse.Resources), 1)
require.NoError(t, err)
assert.Equal(t, discoveryResponse.GetVersionInfo(), resp.Version)
assert.Len(t, discoveryResponse.GetResources(), 1)

cachedResponse, err := resp.GetDiscoveryResponse()
assert.Nil(t, err)
require.NoError(t, err)
assert.Same(t, discoveryResponse, cachedResponse)

r := &route.RouteConfiguration{}
err = anypb.UnmarshalTo(discoveryResponse.Resources[0], r, proto.UnmarshalOptions{})
assert.Nil(t, err)
assert.Equal(t, r.Name, resourceName)
err = anypb.UnmarshalTo(discoveryResponse.GetResources()[0], r, proto.UnmarshalOptions{})
require.NoError(t, err)
assert.Equal(t, resourceName, r.GetName())
}

func TestPassthroughResponseGetDiscoveryResponse(t *testing.T) {
routes := []types.Resource{&route.RouteConfiguration{Name: resourceName}}
rsrc, err := anypb.New(routes[0])
assert.Nil(t, err)
require.NoError(t, err)
dr := &discovery.DiscoveryResponse{
TypeUrl: resource.RouteType,
Resources: []*anypb.Any{rsrc},
Expand All @@ -57,14 +58,14 @@ func TestPassthroughResponseGetDiscoveryResponse(t *testing.T) {
}

discoveryResponse, err := resp.GetDiscoveryResponse()
assert.Nil(t, err)
assert.Equal(t, discoveryResponse.VersionInfo, resp.DiscoveryResponse.VersionInfo)
assert.Equal(t, len(discoveryResponse.Resources), 1)
require.NoError(t, err)
assert.Equal(t, "v", discoveryResponse.GetVersionInfo())
assert.Len(t, discoveryResponse.GetResources(), 1)

r := &route.RouteConfiguration{}
err = anypb.UnmarshalTo(discoveryResponse.Resources[0], r, proto.UnmarshalOptions{})
assert.Nil(t, err)
assert.Equal(t, r.Name, resourceName)
err = anypb.UnmarshalTo(discoveryResponse.GetResources()[0], r, proto.UnmarshalOptions{})
require.NoError(t, err)
assert.Equal(t, resourceName, r.GetName())
assert.Equal(t, discoveryResponse, dr)
}

Expand All @@ -78,27 +79,27 @@ func TestHeartbeatResponseGetDiscoveryResponse(t *testing.T) {
}

discoveryResponse, err := resp.GetDiscoveryResponse()
assert.Nil(t, err)
assert.Equal(t, discoveryResponse.VersionInfo, resp.Version)
assert.Equal(t, len(discoveryResponse.Resources), 1)
assert.False(t, isTTLResource(discoveryResponse.Resources[0]))
require.NoError(t, err)
assert.Equal(t, discoveryResponse.GetVersionInfo(), resp.Version)
require.Len(t, discoveryResponse.GetResources(), 1)
assert.False(t, isTTLResource(discoveryResponse.GetResources()[0]))

cachedResponse, err := resp.GetDiscoveryResponse()
assert.Nil(t, err)
require.NoError(t, err)
assert.Same(t, discoveryResponse, cachedResponse)

r := &route.RouteConfiguration{}
err = anypb.UnmarshalTo(discoveryResponse.Resources[0], r, proto.UnmarshalOptions{})
assert.Nil(t, err)
assert.Equal(t, r.Name, resourceName)
err = anypb.UnmarshalTo(discoveryResponse.GetResources()[0], r, proto.UnmarshalOptions{})
require.NoError(t, err)
assert.Equal(t, resourceName, r.GetName())
}

func isTTLResource(resource *anypb.Any) bool {
wrappedResource := &discovery.Resource{}
err := protojson.Unmarshal(resource.Value, wrappedResource)
err := protojson.Unmarshal(resource.GetValue(), wrappedResource)
if err != nil {
return false
}

return wrappedResource.Resource == nil
return wrappedResource.GetResource() == nil
}
9 changes: 5 additions & 4 deletions pkg/envoy-control-plane/cache/v3/delta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/testing/protocmp"

core "github.com/emissary-ingress/emissary/v3/pkg/api/envoy/config/core/v3"
Expand All @@ -20,7 +21,7 @@ import (
"github.com/emissary-ingress/emissary/v3/pkg/envoy-control-plane/test/resource/v3"
)

func assertResourceMapEqual(t *testing.T, want map[string]types.Resource, got map[string]types.Resource) {
func assertResourceMapEqual(t *testing.T, want, got map[string]types.Resource) {
t.Helper()

if !cmp.Equal(want, got, protocmp.Transform()) {
Expand Down Expand Up @@ -240,7 +241,7 @@ func TestSnapshotDeltaCacheWatchTimeout(t *testing.T) {
defer cancel()

err := c.SetSnapshot(ctx, key, fixture.snapshot())
assert.EqualError(t, err, context.Canceled.Error())
require.EqualError(t, err, context.Canceled.Error())

// Now reset the snapshot with a consuming channel. This verifies that if setting the snapshot fails,
// we can retry by setting the same snapshot. In other words, we keep the watch open even if we failed
Expand All @@ -253,13 +254,13 @@ func TestSnapshotDeltaCacheWatchTimeout(t *testing.T) {
}()

err = c.SetSnapshot(context.WithValue(context.Background(), testKey{}, "bar"), key, fixture.snapshot())
assert.NoError(t, err)
require.NoError(t, err)

// The channel should get closed due to the watch trigger.
select {
case response := <-watchTriggeredCh:
// Verify that we pass the context through.
assert.Equal(t, response.GetContext().Value(testKey{}), "bar")
assert.Equal(t, "bar", response.GetContext().Value(testKey{}))
case <-time.After(time.Second):
t.Fatalf("timed out")
}
Expand Down
1 change: 0 additions & 1 deletion pkg/envoy-control-plane/cache/v3/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func (f *fixtureGenerator) snapshot() *cache.Snapshot {
rsrc.ExtensionConfigType: {testExtensionConfig},
},
)

if err != nil {
panic(err.Error())
}
Expand Down
Loading

0 comments on commit 8b343d5

Please sign in to comment.