Skip to content

Commit

Permalink
[NET-6420] Add MeshConfiguration Controller stub (#19745)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Thomas Eckert authored Nov 28, 2023
1 parent 5107764 commit 419677c
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 3 deletions.
1 change: 1 addition & 0 deletions agent/consul/testdata/v2-resource-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions internal/mesh/internal/controllers/meshconfiguration/controller.go
Original file line number Diff line number Diff line change
@@ -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")
}
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 2 additions & 0 deletions internal/mesh/internal/controllers/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
}
22 changes: 22 additions & 0 deletions internal/mesh/internal/types/mesh_configuration.go
Original file line number Diff line number Diff line change
@@ -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
})
}
6 changes: 3 additions & 3 deletions internal/mesh/internal/types/mesh_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
1 change: 1 addition & 0 deletions internal/mesh/internal/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 419677c

Please sign in to comment.