Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NET-6536 Adds stub of GatewayClass controller into v2 controllers #3245

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,42 @@
// 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"
nathancoleman marked this conversation as resolved.
Show resolved Hide resolved

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