Skip to content

Commit

Permalink
[NET-7243] Stub APIGateway Controller for v2 (#3507)
Browse files Browse the repository at this point in the history
* stub api-gateway-controller

* Add setup to v2 controller
  • Loading branch information
jm96441n authored Feb 1, 2024
1 parent b38169a commit ac85721
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 2 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 @@ -102,6 +102,7 @@ rules:
- grpcroutes
- httproutes
- meshgateways
- apigateways
- tcproutes
- proxyconfigurations
verbs:
Expand All @@ -121,6 +122,7 @@ rules:
- grpcroutes/status
- httproutes/status
- meshgateways/status
- apigateways/status
- tcproutes/status
- proxyconfigurations/status
verbs:
Expand Down
3 changes: 2 additions & 1 deletion control-plane/api/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ const (
RouteAuthFilter string = "routeauthfilter"
GatewayPolicy string = "gatewaypolicy"

// V2 config entries.
// V2 resources.
TrafficPermissions string = "trafficpermissions"
GRPCRoute string = "grpcroute"
HTTPRoute string = "httproute"
TCPRoute string = "tcproute"
ProxyConfiguration string = "proxyconfiguration"
MeshGateway string = "meshgateway"
APIGateway string = "apigateway"
GatewayClass string = "gatewayclass"
GatewayClassConfig string = "gatewayclassconfig"
MeshConfiguration string = "meshconfiguration"
Expand Down
2 changes: 1 addition & 1 deletion control-plane/api/mesh/v2beta1/api_gateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const (
)

func init() {
MeshSchemeBuilder.Register(&GatewayClass{}, &GatewayClassList{})
MeshSchemeBuilder.Register(&GatewayClass{}, &GatewayClassList{}, &APIGateway{}, &APIGatewayList{})
}

// +kubebuilder:object:root=true
Expand Down
44 changes: 44 additions & 0 deletions control-plane/controllers/resources/api-gateway-controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package resources

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

// APIGatewayController reconciles a APIGateway object.
type APIGatewayController struct {
client.Client
Log logr.Logger
Scheme *runtime.Scheme
Controller *ConsulResourceController
}

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

func (r *APIGatewayController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
r.Logger(req.NamespacedName).Info("Reconciling APIGateway")
return r.Controller.ReconcileResource(ctx, r, req, &meshv2beta1.APIGateway{})
}

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

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

func (r *APIGatewayController) SetupWithManager(mgr ctrl.Manager) error {
return setupWithManager(mgr, &meshv2beta1.APIGateway{}, r)
}
10 changes: 10 additions & 0 deletions control-plane/subcommand/inject-connect/v2controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ func (c *Command) configureV2Controllers(ctx context.Context, mgr manager.Manage
return err
}

if err := (&resourceControllers.APIGatewayController{
Controller: consulResourceController,
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controller").WithName(common.APIGateway),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", common.APIGateway)
return err
}

if err := (&resourceControllers.GatewayClassConfigController{
Controller: consulResourceController,
Client: mgr.GetClient(),
Expand Down

0 comments on commit ac85721

Please sign in to comment.