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

CE port of enterprise extension #18572

Merged
merged 1 commit into from
Aug 24, 2023
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
10 changes: 6 additions & 4 deletions agent/envoyextensions/registered_extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ var extensionConstructors = map[string]extensionConstructor{
// given config. Returns an error if the extension does not exist, or if the extension fails
// to be constructed properly.
func ConstructExtension(ext api.EnvoyExtension) (extensioncommon.EnvoyExtender, error) {
constructor, ok := extensionConstructors[ext.Name]
if !ok {
return nil, fmt.Errorf("name %q is not a built-in extension", ext.Name)
if constructor, ok := extensionConstructors[ext.Name]; ok {
return constructor(ext)
}
return constructor(ext)
if constructor, ok := enterpriseExtensionConstructors[ext.Name]; ok {
return constructor(ext)
}
return nil, fmt.Errorf("name %q is not a built-in extension", ext.Name)
}

// ValidateExtensions will attempt to construct each instance of the given envoy extension configurations
Expand Down
8 changes: 8 additions & 0 deletions agent/envoyextensions/registered_extensions_ce.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1

//go:build !consulent

package envoyextensions

var enterpriseExtensionConstructors = map[string]extensionConstructor{}
10 changes: 6 additions & 4 deletions envoyextensions/extensioncommon/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ func getSNI(chain *envoy_listener_v3.FilterChain) string {
}

// GetHTTPConnectionManager returns the Envoy HttpConnectionManager filter from the list of network filters.
// It also returns the index within the list of filters where the connection manager was found in case the caller
// needs this information.
// It also returns the index within the list of filters where the connection manager was found in case the
// caller needs to overwrite the original filter.
// It returns a non-nil error if the HttpConnectionManager is not found.
func GetHTTPConnectionManager(filters ...*envoy_listener_v3.Filter) (*envoy_http_v3.HttpConnectionManager, int, error) {
for idx, filter := range filters {
Expand Down Expand Up @@ -491,9 +491,11 @@ func InsertHTTPFilter(filters []*envoy_listener_v3.Filter, filter *envoy_http_v3
if err != nil {
return filters, errors.New("failed to insert new HTTP connection manager filter")
}
filters[idx] = newHttpConMan
filtersCopy := make([]*envoy_listener_v3.Filter, len(filters))
copy(filtersCopy, filters)
filtersCopy[idx] = newHttpConMan

return filters, nil
return filtersCopy, nil
}

// InsertNetworkFilter inserts the given network filter into the filter chain in the location
Expand Down
4 changes: 2 additions & 2 deletions proto/private/prototest/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ type TestingT interface {
Fatalf(string, ...any)
}

func AssertDeepEqual(t TestingT, x, y interface{}, opts ...cmp.Option) {
func AssertDeepEqual(t TestingT, exp, got interface{}, opts ...cmp.Option) {
t.Helper()

opts = append(opts, protocmp.Transform())

if diff := cmp.Diff(x, y, opts...); diff != "" {
if diff := cmp.Diff(exp, got, opts...); diff != "" {
t.Fatalf("assertion failed: values are not equal\n--- expected\n+++ actual\n%v", diff)
}
}
Expand Down