Skip to content

Commit

Permalink
NET-6536 Adds stub of GatewayClass controller into v2 controllers (#3245
Browse files Browse the repository at this point in the history
)

* Adds stub of GatewayClass controller into v2 controllers

* regen without weird spaces

* Update control-plane/config-entries/controllersv2/gateway_class_controller.go

---------

Co-authored-by: Nathan Coleman <[email protected]>
  • Loading branch information
2 people authored and jm96441n committed Nov 29, 2023
1 parent 13df14d commit 49d005a
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 3 deletions.
2 changes: 2 additions & 0 deletions charts/consul/templates/connect-inject-clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ rules:
- apiGroups:
- mesh.consul.hashicorp.com
resources:
- gatewayclasses
- grpcroutes
- httproutes
- meshgateways
Expand All @@ -112,6 +113,7 @@ rules:
- apiGroups:
- mesh.consul.hashicorp.com
resources:
- gatewayclasses/status
- grpcroutes/status
- httproutes/status
- meshgateways/status
Expand Down
1 change: 1 addition & 0 deletions control-plane/api/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
TCPRoute string = "tcproute"
ProxyConfiguration string = "proxyconfiguration"
MeshGateway string = "meshgateway"
GatewayClass string = "gatewayclass"

Global string = "global"
Mesh string = "mesh"
Expand Down
7 changes: 4 additions & 3 deletions control-plane/api/mesh/v2beta1/gateway_class_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/hashicorp/consul-k8s/control-plane/api/common"
inject "github.com/hashicorp/consul-k8s/control-plane/connect-inject/common"
"github.com/hashicorp/consul-k8s/control-plane/connect-inject/constants"
pbmesh "github.com/hashicorp/consul/proto-public/pbmesh/v2beta1"
"github.com/hashicorp/consul/proto-public/pbresource"
"google.golang.org/protobuf/testing/protocmp"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/hashicorp/consul-k8s/control-plane/api/common"
inject "github.com/hashicorp/consul-k8s/control-plane/connect-inject/common"
"github.com/hashicorp/consul-k8s/control-plane/connect-inject/constants"
)

const (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package controllersv2

import (
"context"

"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"

meshv2beta1 "github.com/hashicorp/consul-k8s/control-plane/api/mesh/v2beta1"
)

// GatewayClassController reconciles a MeshGateway object.
type GatewayClassController struct {
client.Client
Log logr.Logger
Scheme *runtime.Scheme
MeshConfigController *MeshConfigController
}

// +kubebuilder:rbac:groups=mesh.consul.hashicorp.com,resources=gatewayclass,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=mesh.consul.hashicorp.com,resources=gatewayclass/status,verbs=get;update;patch

func (r *GatewayClassController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
return r.MeshConfigController.ReconcileEntry(ctx, r, req, &meshv2beta1.GatewayClass{})
}

func (r *GatewayClassController) Logger(name types.NamespacedName) logr.Logger {
return r.Log.WithValues("request", name)
}

func (r *GatewayClassController) UpdateStatus(ctx context.Context, obj client.Object, opts ...client.SubResourceUpdateOption) error {
return r.Status().Update(ctx, obj, opts...)
}

func (r *GatewayClassController) SetupWithManager(mgr ctrl.Manager) error {
return setupWithManager(mgr, &meshv2beta1.GatewayClass{}, r)
}
20 changes: 20 additions & 0 deletions control-plane/config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,26 @@ rules:
- get
- patch
- update
- apiGroups:
- mesh.consul.hashicorp.com
resources:
- gatewayclass
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- mesh.consul.hashicorp.com
resources:
- gatewayclass/status
verbs:
- get
- patch
- update
- apiGroups:
- mesh.consul.hashicorp.com
resources:
Expand Down
9 changes: 9 additions & 0 deletions control-plane/subcommand/inject-connect/v2controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@ func (c *Command) configureV2Controllers(ctx context.Context, mgr manager.Manage
setupLog.Error(err, "unable to create controller", "controller", common.MeshGateway)
return err
}
if err := (&controllersv2.GatewayClassController{
MeshConfigController: meshConfigReconciler,
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controller").WithName(common.GatewayClass),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", common.GatewayClass)
return err
}

mgr.GetWebhookServer().CertDir = c.flagCertDir

Expand Down

0 comments on commit 49d005a

Please sign in to comment.