Skip to content

Commit

Permalink
Address PR review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ishustava committed Sep 1, 2023
1 parent ce33f4b commit c5b402d
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 148 deletions.
28 changes: 15 additions & 13 deletions agent/consul/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,15 @@ func NewServer(config *Config, flat Deps, externalGRPCServer *grpc.Server,
s.reportingManager = reporting.NewReportingManager(s.logger, getEnterpriseReportingDeps(flat), s, s.fsm.State())
go s.reportingManager.Run(&lib.StopChannelContext{StopCh: s.shutdownCh})

// Setup resource service clients.
if err := s.setupSecureResourceServiceClient(); err != nil {
return nil, err
}

if err := s.setupInsecureResourceServiceClient(flat.Registry, logger); err != nil {
return nil, err
}

// Initialize external gRPC server
s.setupExternalGRPC(config, flat, logger)

Expand All @@ -826,14 +835,6 @@ func NewServer(config *Config, flat Deps, externalGRPCServer *grpc.Server,
s.grpcHandler = newGRPCHandlerFromConfig(flat, config, s)
s.grpcLeaderForwarder = flat.LeaderForwarder

if err := s.setupSecureResourceServiceClient(); err != nil {
return nil, err
}

if err := s.setupInsecureResourceServiceClient(flat.Registry, logger); err != nil {
return nil, err
}

s.controllerManager = controller.NewManager(
s.insecureResourceServiceClient,
logger.Named(logging.ControllerRuntime),
Expand Down Expand Up @@ -1342,11 +1343,12 @@ func (s *Server) setupExternalGRPC(config *Config, deps Deps, logger hclog.Logge
s.externalConnectCAServer.Register(s.externalGRPCServer)

dataplane.NewServer(dataplane.Config{
GetStore: func() dataplane.StateStore { return s.FSM().State() },
Logger: logger.Named("grpc-api.dataplane"),
ACLResolver: s.ACLResolver,
Datacenter: s.config.Datacenter,
EnableV2: stringslice.Contains(deps.Experiments, catalogResourceExperimentName),
GetStore: func() dataplane.StateStore { return s.FSM().State() },
Logger: logger.Named("grpc-api.dataplane"),
ACLResolver: s.ACLResolver,
Datacenter: s.config.Datacenter,
EnableV2: stringslice.Contains(deps.Experiments, CatalogResourceExperimentName),
ResourceAPIClient: s.insecureResourceServiceClient,
}).Register(s.externalGRPCServer)

serverdiscovery.NewServer(serverdiscovery.Config{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ import (
"errors"
"strings"

"github.com/hashicorp/consul/internal/catalog"
"github.com/hashicorp/consul/internal/mesh"
pbcatalog "github.com/hashicorp/consul/proto-public/pbcatalog/v1alpha1"
pbmesh "github.com/hashicorp/consul/proto-public/pbmesh/v1alpha1"
"github.com/hashicorp/consul/proto-public/pbresource"
"github.com/hashicorp/go-hclog"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/structpb"

"github.com/hashicorp/consul/internal/catalog"
"github.com/hashicorp/consul/internal/mesh"
pbcatalog "github.com/hashicorp/consul/proto-public/pbcatalog/v1alpha1"
pbmesh "github.com/hashicorp/consul/proto-public/pbmesh/v1alpha1"
"github.com/hashicorp/consul/proto-public/pbresource"

"github.com/hashicorp/consul/acl"
"github.com/hashicorp/consul/agent/configentry"
"github.com/hashicorp/consul/agent/consul/state"
Expand Down Expand Up @@ -114,13 +115,12 @@ func (s *Server) GetEnvoyBootstrapParams(ctx context.Context, req *pbdataplane.G
accessLogs := makeAccessLogs(dynamicCfg.GetAccessLogs(), logger)

return &pbdataplane.GetEnvoyBootstrapParamsResponse{
ClusterName: workload.Identity,
Identity: workload.Identity,
Partition: workloadRsp.Resource.Id.Tenancy.Partition,
Namespace: workloadRsp.Resource.Id.Tenancy.Namespace,
BootstrapConfig: bootstrapCfg,
Datacenter: s.Datacenter,
NodeName: workload.NodeName,
NodeId: workloadRsp.Resource.Id.Name,
AccessLogs: accessLogs,
}, nil
}
Expand Down Expand Up @@ -181,15 +181,14 @@ func (s *Server) GetEnvoyBootstrapParams(ctx context.Context, req *pbdataplane.G
}

return &pbdataplane.GetEnvoyBootstrapParamsResponse{
ClusterName: serviceName,
Service: serviceName,
Partition: svc.EnterpriseMeta.PartitionOrDefault(),
Namespace: svc.EnterpriseMeta.NamespaceOrDefault(),
Config: bootstrapConfig,
Datacenter: s.Datacenter,
NodeName: svc.Node,
NodeId: string(svc.ID),
AccessLogs: accessLogs,
Identity: serviceName,
Service: serviceName,
Partition: svc.EnterpriseMeta.PartitionOrDefault(),
Namespace: svc.EnterpriseMeta.NamespaceOrDefault(),
Config: bootstrapConfig,
Datacenter: s.Datacenter,
NodeName: svc.Node,
AccessLogs: accessLogs,
}, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,29 @@ import (
"fmt"
"testing"

"github.com/hashicorp/go-hclog"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/structpb"

svctest "github.com/hashicorp/consul/agent/grpc-external/services/resource/testing"
"github.com/hashicorp/consul/internal/catalog"
"github.com/hashicorp/consul/internal/mesh"
"github.com/hashicorp/consul/internal/resource"
"github.com/hashicorp/consul/internal/resource/resourcetest"
pbcatalog "github.com/hashicorp/consul/proto-public/pbcatalog/v1alpha1"
pbmesh "github.com/hashicorp/consul/proto-public/pbmesh/v1alpha1"
"github.com/hashicorp/consul/proto-public/pbresource"
"github.com/hashicorp/consul/proto/private/prototest"
"github.com/hashicorp/go-hclog"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/structpb"

"github.com/hashicorp/consul/acl"
"github.com/hashicorp/consul/acl/resolver"
external "github.com/hashicorp/consul/agent/grpc-external"
"github.com/hashicorp/consul/agent/grpc-external/testutils"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/proto-public/pbdataplane"
"github.com/hashicorp/consul/types"
)

const (
Expand Down Expand Up @@ -79,7 +80,7 @@ func testRegisterRequestProxy(t *testing.T) *structs.RegisterRequest {

func testRegisterIngressGateway(t *testing.T) *structs.RegisterRequest {
registerReq := structs.TestRegisterIngressGateway(t)
registerReq.ID = types.NodeID("2980b72b-bd9d-9d7b-d4f9-951bf7508d95")
registerReq.ID = "2980b72b-bd9d-9d7b-d4f9-951bf7508d95"
registerReq.Service.ID = registerReq.Service.Service
registerReq.Service.Proxy.Config = map[string]interface{}{
proxyConfigKey: proxyConfigValue,
Expand Down Expand Up @@ -179,7 +180,6 @@ func TestGetEnvoyBootstrapParams_Success(t *testing.T) {
require.Equal(t, tc.registerReq.EnterpriseMeta.NamespaceOrDefault(), resp.Namespace)
requireConfigField(t, resp, proxyConfigKey, structpb.NewStringValue(proxyConfigValue))
require.Equal(t, tc.registerReq.Node, resp.NodeName)
require.Equal(t, string(tc.registerReq.ID), resp.NodeId)

if tc.serviceDefaults != nil && tc.proxyDefaults != nil {
// service-defaults take precedence over proxy-defaults
Expand Down Expand Up @@ -290,12 +290,14 @@ func TestGetEnvoyBootstrapParams_Success_EnableV2(t *testing.T) {
}
workloadResource := resourcetest.Resource(catalog.WorkloadType, "test-workload").
WithData(t, tc.workloadData).
WithTenancy(resource.DefaultNamespacedTenancy()).
Write(t, resourceClient)

// Create any proxy cfg resources.
for i, cfg := range tc.proxyCfgs {
resourcetest.Resource(mesh.ProxyConfigurationType, fmt.Sprintf("proxy-cfg-%d", i)).
WithData(t, cfg).
WithTenancy(resource.DefaultNamespacedTenancy()).
Write(t, resourceClient)
}

Expand All @@ -311,7 +313,7 @@ func TestGetEnvoyBootstrapParams_Success_EnableV2(t *testing.T) {
resp, err := client.GetEnvoyBootstrapParams(ctx, req)
require.NoError(t, err)

require.Equal(t, tc.workloadData.Identity, resp.ClusterName)
require.Equal(t, tc.workloadData.Identity, resp.Identity)
require.Equal(t, serverDC, resp.Datacenter)
require.Equal(t, workloadResource.Id.Tenancy.Partition, resp.Partition)
require.Equal(t, workloadResource.Id.Tenancy.Namespace, resp.Namespace)
Expand Down Expand Up @@ -527,8 +529,8 @@ func TestGetEnvoyBootstrapParams_Error_EnableV2(t *testing.T) {
} else {
req = pbdataplane.GetEnvoyBootstrapParamsRequest{
ProxyId: "not-found",
Namespace: "not-found",
Partition: "not-found",
Namespace: "default",
Partition: "default",
}
}

Expand All @@ -549,7 +551,9 @@ func TestGetEnvoyBootstrapParams_Error_EnableV2(t *testing.T) {
Ports: map[string]*pbcatalog.WorkloadPort{
"tcp": {Port: 8080},
},
}).Build()
}).
WithTenancy(resource.DefaultNamespacedTenancy()).
Build()

testCases := []testCase{
{
Expand Down
Loading

0 comments on commit c5b402d

Please sign in to comment.