diff --git a/charts/consul/templates/connect-inject-clusterrole.yaml b/charts/consul/templates/connect-inject-clusterrole.yaml index 4cc749a0e6..ff181720fd 100644 --- a/charts/consul/templates/connect-inject-clusterrole.yaml +++ b/charts/consul/templates/connect-inject-clusterrole.yaml @@ -96,6 +96,7 @@ rules: - apiGroups: - mesh.consul.hashicorp.com resources: + - gatewayclasses - grpcroutes - httproutes - meshgateways @@ -112,6 +113,7 @@ rules: - apiGroups: - mesh.consul.hashicorp.com resources: + - gatewayclasses/status - grpcroutes/status - httproutes/status - meshgateways/status diff --git a/control-plane/api/common/common.go b/control-plane/api/common/common.go index c9f461bd87..a9758e0b9e 100644 --- a/control-plane/api/common/common.go +++ b/control-plane/api/common/common.go @@ -30,6 +30,7 @@ const ( TCPRoute string = "tcproute" ProxyConfiguration string = "proxyconfiguration" MeshGateway string = "meshgateway" + GatewayClass string = "gatewayclass" Global string = "global" Mesh string = "mesh" diff --git a/control-plane/api/mesh/v2beta1/gateway_class_types.go b/control-plane/api/mesh/v2beta1/gateway_class_types.go index 6fc42ffed5..fac8535ae5 100644 --- a/control-plane/api/mesh/v2beta1/gateway_class_types.go +++ b/control-plane/api/mesh/v2beta1/gateway_class_types.go @@ -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 ( diff --git a/control-plane/config-entries/controllersv2/gateway_class_controller.go b/control-plane/config-entries/controllersv2/gateway_class_controller.go new file mode 100644 index 0000000000..2e9572e16c --- /dev/null +++ b/control-plane/config-entries/controllersv2/gateway_class_controller.go @@ -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) +} diff --git a/control-plane/config/rbac/role.yaml b/control-plane/config/rbac/role.yaml index c4fb15f80f..52be967944 100644 --- a/control-plane/config/rbac/role.yaml +++ b/control-plane/config/rbac/role.yaml @@ -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: diff --git a/control-plane/subcommand/inject-connect/v2controllers.go b/control-plane/subcommand/inject-connect/v2controllers.go index ac2f0831a0..f33d863da5 100644 --- a/control-plane/subcommand/inject-connect/v2controllers.go +++ b/control-plane/subcommand/inject-connect/v2controllers.go @@ -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