[NET-6420] Add MeshConfiguration Controller stub (#19745)

* Add meshconfiguration/controller

* Add MeshConfiguration Registration function

* Fix the TODOs on the RegisterMeshGateway function

* Call RegisterMeshConfiguration

* Add comment to MeshConfigurationRegistration

* Add a test for Reconcile and some comments
This commit is contained in:
Thomas Eckert 2023-11-28 13:56:07 -05:00 committed by GitHub
parent 5107764115
commit 419677cc9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 88 additions and 3 deletions

View File

@ -34,6 +34,7 @@ flowchart TD
mesh/v2beta1/destinations mesh/v2beta1/destinations
mesh/v2beta1/grpcroute mesh/v2beta1/grpcroute
mesh/v2beta1/httproute mesh/v2beta1/httproute
mesh/v2beta1/meshconfiguration
mesh/v2beta1/meshgateway mesh/v2beta1/meshgateway
mesh/v2beta1/proxyconfiguration mesh/v2beta1/proxyconfiguration
mesh/v2beta1/proxystatetemplate --> auth/v2beta1/computedtrafficpermissions mesh/v2beta1/proxystatetemplate --> auth/v2beta1/computedtrafficpermissions

View File

@ -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")
}

View File

@ -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)
}

View File

@ -5,6 +5,7 @@ package controllers
import ( import (
"context" "context"
"github.com/hashicorp/consul/internal/mesh/internal/controllers/meshconfiguration"
"github.com/hashicorp/consul/agent/leafcert" "github.com/hashicorp/consul/agent/leafcert"
"github.com/hashicorp/consul/internal/controller" "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(explicitdestinations.Controller(mapper.New()))
mgr.Register(meshgateways.Controller()) mgr.Register(meshgateways.Controller())
mgr.Register(meshconfiguration.Controller())
} }

View File

@ -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
})
}

View File

@ -13,8 +13,8 @@ func RegisterMeshGateway(r resource.Registry) {
Type: pbmesh.MeshGatewayType, Type: pbmesh.MeshGatewayType,
Proto: &pbmesh.MeshGateway{}, Proto: &pbmesh.MeshGateway{},
Scope: resource.ScopePartition, Scope: resource.ScopePartition,
ACLs: nil, // TODO NET-6423 ACLs: nil, // TODO NET-6416
Mutate: nil, // TODO NET-6425 Mutate: nil, // TODO NET-6418
Validate: nil, // TODO NET-6424 Validate: nil, // TODO NET-6417
}) })
} }

View File

@ -19,6 +19,7 @@ func Register(r resource.Registry) {
RegisterDestinationPolicy(r) RegisterDestinationPolicy(r)
RegisterComputedRoutes(r) RegisterComputedRoutes(r)
RegisterMeshGateway(r) RegisterMeshGateway(r)
RegisterMeshConfiguration(r)
// todo (v2): uncomment once we implement it. // todo (v2): uncomment once we implement it.
//RegisterDestinationsConfiguration(r) //RegisterDestinationsConfiguration(r)
} }