diff --git a/agent/consul/testdata/v2-resource-dependencies.md b/agent/consul/testdata/v2-resource-dependencies.md index edc7263299..822b01c8f9 100644 --- a/agent/consul/testdata/v2-resource-dependencies.md +++ b/agent/consul/testdata/v2-resource-dependencies.md @@ -34,6 +34,7 @@ flowchart TD mesh/v2beta1/destinations mesh/v2beta1/grpcroute mesh/v2beta1/httproute + mesh/v2beta1/meshconfiguration mesh/v2beta1/meshgateway mesh/v2beta1/proxyconfiguration mesh/v2beta1/proxystatetemplate --> auth/v2beta1/computedtrafficpermissions diff --git a/internal/mesh/internal/controllers/meshconfiguration/controller.go b/internal/mesh/internal/controllers/meshconfiguration/controller.go new file mode 100644 index 0000000000..93c0cb0d5f --- /dev/null +++ b/internal/mesh/internal/controllers/meshconfiguration/controller.go @@ -0,0 +1,29 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + +package meshconfiguration + +import ( + "context" + "errors" + + "github.com/hashicorp/consul/internal/controller" + pbmesh "github.com/hashicorp/consul/proto-public/pbmesh/v2beta1" +) + +// Controller instantiates a new Controller for managing MeshConfiguration resources. +func Controller() controller.Controller { + r := &reconciler{} + + return controller.ForType(pbmesh.MeshConfigurationType).WithReconciler(r) +} + +// reconciler implements the Reconciler interface to modify runtime state based +// on requests passed into it. +type reconciler struct{} + +// Reconcile takes in the current controller request and updates the runtime state based on +// the request received. +func (r *reconciler) Reconcile(ctx context.Context, rt controller.Runtime, req controller.Request) error { + return errors.New("not implemented") +} diff --git a/internal/mesh/internal/controllers/meshconfiguration/controller_test.go b/internal/mesh/internal/controllers/meshconfiguration/controller_test.go new file mode 100644 index 0000000000..900d654cbc --- /dev/null +++ b/internal/mesh/internal/controllers/meshconfiguration/controller_test.go @@ -0,0 +1,30 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + +package meshconfiguration + +import ( + "context" + "github.com/hashicorp/consul/internal/controller" + "github.com/stretchr/testify/require" + "testing" +) + +// TestReconciliation ensures that the Reconcile method for the Controller +// correctly updates the runtime state based on the given request. +func TestReconcile(t *testing.T) { + // This test should be continually updated as we build out the MeshConfiguration controller. + // At time of writing, it simply returns a not-implemented error. + + ctx := context.Background() + rt := controller.Runtime{ + Client: nil, + Logger: nil, + } + req := controller.Request{} + + rec := reconciler{} + + err := rec.Reconcile(ctx, rt, req) + require.Error(t, err) +} diff --git a/internal/mesh/internal/controllers/register.go b/internal/mesh/internal/controllers/register.go index 99209d5ea4..2416c5615f 100644 --- a/internal/mesh/internal/controllers/register.go +++ b/internal/mesh/internal/controllers/register.go @@ -5,6 +5,7 @@ package controllers import ( "context" + "github.com/hashicorp/consul/internal/mesh/internal/controllers/meshconfiguration" "github.com/hashicorp/consul/agent/leafcert" "github.com/hashicorp/consul/internal/controller" @@ -51,4 +52,5 @@ func Register(mgr *controller.Manager, deps Dependencies) { mgr.Register(explicitdestinations.Controller(mapper.New())) mgr.Register(meshgateways.Controller()) + mgr.Register(meshconfiguration.Controller()) } diff --git a/internal/mesh/internal/types/mesh_configuration.go b/internal/mesh/internal/types/mesh_configuration.go new file mode 100644 index 0000000000..323c86e544 --- /dev/null +++ b/internal/mesh/internal/types/mesh_configuration.go @@ -0,0 +1,22 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: BUSL-1.1 + +package types + +import ( + "github.com/hashicorp/consul/internal/resource" + pbmesh "github.com/hashicorp/consul/proto-public/pbmesh/v2beta1" +) + +// RegisterMeshConfiguration takes the resource registry and registers +// the MeshConfiguration resource to it. +func RegisterMeshConfiguration(r resource.Registry) { + r.Register(resource.Registration{ + Type: pbmesh.MeshConfigurationType, + Proto: &pbmesh.MeshConfiguration{}, + Scope: resource.ScopePartition, + ACLs: nil, // TODO NET-6423 + Mutate: nil, // TODO NET-6425 + Validate: nil, // TODO NET-6424 + }) +} diff --git a/internal/mesh/internal/types/mesh_gateway.go b/internal/mesh/internal/types/mesh_gateway.go index 3c652bcc79..2583b4dcc0 100644 --- a/internal/mesh/internal/types/mesh_gateway.go +++ b/internal/mesh/internal/types/mesh_gateway.go @@ -13,8 +13,8 @@ func RegisterMeshGateway(r resource.Registry) { Type: pbmesh.MeshGatewayType, Proto: &pbmesh.MeshGateway{}, Scope: resource.ScopePartition, - ACLs: nil, // TODO NET-6423 - Mutate: nil, // TODO NET-6425 - Validate: nil, // TODO NET-6424 + ACLs: nil, // TODO NET-6416 + Mutate: nil, // TODO NET-6418 + Validate: nil, // TODO NET-6417 }) } diff --git a/internal/mesh/internal/types/types.go b/internal/mesh/internal/types/types.go index 69f99c8984..d98e820e82 100644 --- a/internal/mesh/internal/types/types.go +++ b/internal/mesh/internal/types/types.go @@ -19,6 +19,7 @@ func Register(r resource.Registry) { RegisterDestinationPolicy(r) RegisterComputedRoutes(r) RegisterMeshGateway(r) + RegisterMeshConfiguration(r) // todo (v2): uncomment once we implement it. //RegisterDestinationsConfiguration(r) }