Skip to content

Commit

Permalink
Merge branch 'main' into fix_altdomain_dcname_overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
shamil committed Jun 6, 2023
2 parents 10cef2d + f9d9d4d commit 683a771
Show file tree
Hide file tree
Showing 84 changed files with 3,960 additions and 767 deletions.
3 changes: 3 additions & 0 deletions .changelog/17566.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
xds: Fixed a bug where modifying ACLs on a token being actively used for an xDS connection caused all xDS updates to fail.
```
3 changes: 3 additions & 0 deletions .changelog/17581.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
gateways: **(Enterprise only)** Fixed a bug in API gateways where gateway configuration objects in non-default partitions did not reconcile properly.
```
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ override.tf.json
# Ignore CLI configuration files
.terraformrc
terraform.rc
/go.work
/go.work.sum
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ linters-settings:
- github.com/hashicorp/go-msgpack:
recommendations:
- github.com/hashicorp/consul-net-rpc/go-msgpack
- github.com/golang/protobuf:
recommendations:
- google.golang.org/protobuf

depguard:
list-type: denylist
Expand All @@ -101,7 +104,9 @@ linters-settings:
# Default: []
packages-with-error-message:
- net/rpc: "only use forked copy in github.com/hashicorp/consul-net-rpc/net/rpc"
- github.com/golang/protobuf: "only use google.golang.org/protobuf"

run:
timeout: 10m
concurrency: 4
skip-dirs-use-default: false
61 changes: 34 additions & 27 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

SHELL = bash

GO_MODULES := $(shell find . -name go.mod -exec dirname {} \; | grep -v "proto-gen-rpc-glue/e2e" | sort)

###
# These version variables can either be a valid string for "go install <module>@<version>"
# or the string @DEV to imply use what is currently installed locally.
Expand Down Expand Up @@ -249,19 +251,13 @@ cov: other-consul dev-build

test: other-consul dev-build lint test-internal

go-mod-tidy:
@echo "--> Running go mod tidy"
@cd sdk && go mod tidy
@cd api && go mod tidy
@go mod tidy
@cd test/integration/consul-container && go mod tidy
@cd test/integration/connect/envoy/test-sds-server && go mod tidy
@cd proto-public && go mod tidy
@cd internal/tools/proto-gen-rpc-glue && go mod tidy
@cd internal/tools/proto-gen-rpc-glue/e2e && go mod tidy
@cd internal/tools/proto-gen-rpc-glue/e2e/consul && go mod tidy
@cd internal/tools/protoc-gen-consul-rate-limit && go mod tidy
.PHONY: go-mod-tidy
go-mod-tidy: $(foreach mod,$(GO_MODULES),go-mod-tidy/$(mod))

.PHONY: mod-tidy/%
go-mod-tidy/%:
@echo "--> Running go mod tidy ($*)"
@cd $* && go mod tidy

test-internal:
@echo "--> Running go test"
Expand Down Expand Up @@ -292,6 +288,12 @@ test-internal:
@grep '^FAIL' test.log || true
@if [ "$$(cat exit-code)" == "0" ] ; then echo "PASS" ; exit 0 ; else exit 1 ; fi

test-all: other-consul dev-build lint $(foreach mod,$(GO_MODULES),test-module/$(mod))

test-module/%:
@echo "--> Running go test ($*)"
cd $* && go test $(GOTEST_FLAGS) -tags '$(GOTAGS)' ./...

test-race:
$(MAKE) GOTEST_FLAGS=-race

Expand Down Expand Up @@ -328,21 +330,26 @@ other-consul:
echo "Found other running consul agents. This may affect your tests." ; \
exit 1 ; \
fi

lint: -lint-main lint-container-test-deps

.PHONY: -lint-main
-lint-main: lint-tools
@echo "--> Running golangci-lint"
@golangci-lint run --build-tags '$(GOTAGS)' && \
(cd api && golangci-lint run --build-tags '$(GOTAGS)') && \
(cd sdk && golangci-lint run --build-tags '$(GOTAGS)')
@echo "--> Running golangci-lint (container tests)"
@cd test/integration/consul-container && golangci-lint run --build-tags '$(GOTAGS)'
@echo "--> Running lint-consul-retry"
@lint-consul-retry
@echo "--> Running enumcover"
@enumcover ./...

.PHONY: fmt
fmt: $(foreach mod,$(GO_MODULES),fmt/$(mod))

.PHONY: fmt/%
fmt/%:
@echo "--> Running go fmt ($*)"
@cd $* && go fmt ./...

.PHONY: lint
lint: $(foreach mod,$(GO_MODULES),lint/$(mod)) lint-container-test-deps

.PHONY: lint/%
lint/%:
@echo "--> Running golangci-lint ($*)"
@cd $* && GOWORK=off golangci-lint run --build-tags '$(GOTAGS)'
@echo "--> Running lint-consul-retry ($*)"
@cd $* && GOWORK=off lint-consul-retry
@echo "--> Running enumcover ($*)"
@cd $* && GOWORK=off enumcover ./...

.PHONY: lint-container-test-deps
lint-container-test-deps:
Expand Down
16 changes: 11 additions & 5 deletions agent/consul/gateways/controller_gateways.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (r *apiGatewayReconciler) enqueueCertificateReferencedGateways(store *state
logger.Trace("certificate changed, enqueueing dependent gateways")
defer logger.Trace("finished enqueuing gateways")

_, entries, err := store.ConfigEntriesByKind(nil, structs.APIGateway, acl.WildcardEnterpriseMeta())
_, entries, err := store.ConfigEntriesByKind(nil, structs.APIGateway, wildcardMeta())
if err != nil {
logger.Warn("error retrieving api gateways", "error", err)
return err
Expand Down Expand Up @@ -564,11 +564,11 @@ type gatewayMeta struct {
// tuples based on the state coming from the store. Any gateway that does not have
// a corresponding bound-api-gateway config entry will be filtered out.
func getAllGatewayMeta(store *state.Store) ([]*gatewayMeta, error) {
_, gateways, err := store.ConfigEntriesByKind(nil, structs.APIGateway, acl.WildcardEnterpriseMeta())
_, gateways, err := store.ConfigEntriesByKind(nil, structs.APIGateway, wildcardMeta())
if err != nil {
return nil, err
}
_, boundGateways, err := store.ConfigEntriesByKind(nil, structs.BoundAPIGateway, acl.WildcardEnterpriseMeta())
_, boundGateways, err := store.ConfigEntriesByKind(nil, structs.BoundAPIGateway, wildcardMeta())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1074,12 +1074,12 @@ func requestToResourceRef(req controller.Request) structs.ResourceReference {

// retrieveAllRoutesFromStore retrieves all HTTP and TCP routes from the given store
func retrieveAllRoutesFromStore(store *state.Store) ([]structs.BoundRoute, error) {
_, httpRoutes, err := store.ConfigEntriesByKind(nil, structs.HTTPRoute, acl.WildcardEnterpriseMeta())
_, httpRoutes, err := store.ConfigEntriesByKind(nil, structs.HTTPRoute, wildcardMeta())
if err != nil {
return nil, err
}

_, tcpRoutes, err := store.ConfigEntriesByKind(nil, structs.TCPRoute, acl.WildcardEnterpriseMeta())
_, tcpRoutes, err := store.ConfigEntriesByKind(nil, structs.TCPRoute, wildcardMeta())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1141,3 +1141,9 @@ func routeLogger(logger hclog.Logger, route structs.ConfigEntry) hclog.Logger {
meta := route.GetEnterpriseMeta()
return logger.With("route.kind", route.GetKind(), "route.name", route.GetName(), "route.namespace", meta.NamespaceOrDefault(), "route.partition", meta.PartitionOrDefault())
}

func wildcardMeta() *acl.EnterpriseMeta {
meta := acl.WildcardEnterpriseMeta()
meta.OverridePartition(acl.WildcardPartitionName)
return meta
}
2 changes: 1 addition & 1 deletion agent/consul/leader_peering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1921,7 +1921,7 @@ func Test_Leader_PeeringSync_ServerAddressUpdates(t *testing.T) {
require.True(r, found)
// We assert for this error to be set which would indicate that we iterated
// through a bad address.
require.Contains(r, status.LastSendErrorMessage, "transport: Error while dialing dial tcp: address bad: missing port in address")
require.Contains(r, status.LastSendErrorMessage, "transport: Error while dialing: dial tcp: address bad: missing port in address")
require.False(r, status.Connected)
})
})
Expand Down
4 changes: 3 additions & 1 deletion agent/envoyextensions/builtin/ext-authz/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (c extAuthzConfig) isHTTP() bool {
//
// If the extension is configured with the ext_authz service as an upstream there is no need to insert
// a new cluster so this method returns nil.
func (c *extAuthzConfig) toEnvoyCluster(cfg *cmn.RuntimeConfig) (*envoy_cluster_v3.Cluster, error) {
func (c *extAuthzConfig) toEnvoyCluster(_ *cmn.RuntimeConfig) (*envoy_cluster_v3.Cluster, error) {
var target *Target
if c.isHTTP() {
target = c.HttpService.Target
Expand Down Expand Up @@ -678,8 +678,10 @@ type TransportApiVersion string
func (t TransportApiVersion) toEnvoy() envoy_core_v3.ApiVersion {
switch strings.ToLower(string(t)) {
case "v2":
//nolint:staticcheck
return envoy_core_v3.ApiVersion_V2
case "auto":
//nolint:staticcheck
return envoy_core_v3.ApiVersion_AUTO
default:
return envoy_core_v3.ApiVersion_V3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
envoy_http_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
envoy_type_v3 "github.com/envoyproxy/go-control-plane/envoy/type/v3"
envoy_resource_v3 "github.com/envoyproxy/go-control-plane/pkg/resource/v3"
"github.com/golang/protobuf/ptypes/wrappers"
"github.com/hashicorp/go-multierror"
"github.com/mitchellh/mapstructure"
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/wrapperspb"

"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/envoyextensions/extensioncommon"
Expand Down Expand Up @@ -125,7 +125,7 @@ func (r ratelimit) PatchFilter(p extensioncommon.FilterPayload) (*envoy_listener
tokenBucket := envoy_type_v3.TokenBucket{}

if r.TokensPerFill != nil {
tokenBucket.TokensPerFill = &wrappers.UInt32Value{
tokenBucket.TokensPerFill = &wrapperspb.UInt32Value{
Value: uint32(*r.TokensPerFill),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ type MockPatcher[K proto.Message] struct {
appliedPatches []Patch
}

//nolint:unparam
func (m *MockPatcher[K]) applyPatch(k K, p Patch, _ bool) (result K, e error) {
m.appliedPatches = append(m.appliedPatches, p)
return k, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ package propertyoverride

import (
"fmt"
"testing"

envoy_cluster_v3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3"
corev3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
envoy_endpoint_v3 "github.com/envoyproxy/go-control-plane/envoy/config/endpoint/v3"
envoy_listener_v3 "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
envoy_route_v3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
_struct "github.com/golang/protobuf/ptypes/struct"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/testing/protocmp"
_struct "google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/wrapperspb"
"testing"
)

func TestPatchStruct(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion agent/grpc-internal/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (s *ServerResolverBuilder) Build(target resolver.Target, cc resolver.Client
}

//nolint:staticcheck
serverType, datacenter, err := parseEndpoint(target.Endpoint)
serverType, datacenter, err := parseEndpoint(target.Endpoint())
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion agent/grpc-internal/resolver/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package resolver
import (
"fmt"
"net"
"net/url"
"strings"
"testing"

Expand Down Expand Up @@ -40,7 +41,7 @@ func TestServerResolverBuilder(t *testing.T) {
_, err := rs.Build(resolver.Target{
Scheme: "consul",
Authority: rs.Authority(),
Endpoint: endpoint,
URL: url.URL{Opaque: endpoint},
}, cc, resolver.BuildOptions{})
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion agent/grpc-middleware/testutil/testservice/simple.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions agent/local/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ import (
"sync/atomic"
"time"

"github.com/hashicorp/consul/acl"
"github.com/hashicorp/consul/acl/resolver"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/agent/token"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/lib"
"github.com/hashicorp/consul/lib/stringslice"
"github.com/hashicorp/consul/types"

"github.com/armon/go-metrics"
"github.com/armon/go-metrics/prometheus"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-multierror"
"github.com/mitchellh/copystructure"

"github.com/hashicorp/consul/acl"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/agent/token"
"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/lib"
"github.com/hashicorp/consul/types"
)

var StateCounters = []prometheus.CounterDefinition{
Expand Down Expand Up @@ -1252,6 +1252,7 @@ func (l *State) SyncChanges() error {
}
}

var errs error
// Sync the services
// (logging happens in the helper methods)
for id, s := range l.services {
Expand All @@ -1265,7 +1266,7 @@ func (l *State) SyncChanges() error {
l.logger.Debug("Service in sync", "service", id.String())
}
if err != nil {
return err
errs = multierror.Append(errs, err)
}
}

Expand All @@ -1286,10 +1287,10 @@ func (l *State) SyncChanges() error {
l.logger.Debug("Check in sync", "check", id.String())
}
if err != nil {
return err
errs = multierror.Append(errs, err)
}
}
return nil
return errs
}

// deleteService is used to delete a service from the server
Expand Down
7 changes: 7 additions & 0 deletions agent/proxycfg-glue/glue.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package proxycfgglue

import (
"context"
"errors"

"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-memdb"
Expand Down Expand Up @@ -141,6 +142,12 @@ func newUpdateEvent(correlationID string, result any, err error) proxycfg.Update
if acl.IsErrNotFound(err) {
err = proxycfg.TerminalError(err)
}
// these are also errors where we should mark them
// as terminal for the sake of proxycfg, since they require
// a resubscribe.
if errors.Is(err, stream.ErrSubForceClosed) || errors.Is(err, stream.ErrShuttingDown) {
err = proxycfg.TerminalError(err)
}
return proxycfg.UpdateEvent{
CorrelationID: correlationID,
Result: result,
Expand Down
Loading

0 comments on commit 683a771

Please sign in to comment.