Skip to content

Commit

Permalink
initialize httproute controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdiramen committed Jan 25, 2024
1 parent bd407d5 commit 699f065
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 4 deletions.
7 changes: 6 additions & 1 deletion PROJECT

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,13 @@ func runController(ctx context.Context, opts managerOpts) error {
os.Exit(1)
}
}
if err = (&gatewaycontroller.HTTPRouteReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "HTTPRoute")
os.Exit(1)
}
//+kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Expand Down
89 changes: 89 additions & 0 deletions internal/controller/gateway/httproute_controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
MIT License
Copyright (c) 2022 ngrok, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package gateway

import (
"context"

"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"

"github.com/go-logr/logr"
)

// HTTPRouteReconciler reconciles a HTTPRoute object
type HTTPRouteReconciler struct {
client.Client

Log logr.Logger
Scheme *runtime.Scheme
}

//+kubebuilder:rbac:groups=networking.k8s.io,resources=httproutes,verbs=get;list;watch
//+kubebuilder:rbac:groups=networking.k8s.io,resources=httproutes/status,verbs=get

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
func (r *HTTPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := r.Log.WithValues("GatewayV1HTTPRoute", req.NamespacedName)

httproute := new(gatewayv1.HTTPRoute)
if err := r.Get(ctx, req.NamespacedName, httproute); err != nil {
if errors.IsNotFound(err) {
log.V(1).Info("reconciliation triggered but httproute does not exist, ignoring")
return ctrl.Result{Requeue: false}, nil // do some logic here

}

return ctrl.Result{Requeue: true}, nil
}


return ctrl.Result{}, nil
}

// SetupWithManager sets up the controller with the Manager.
func (r *HTTPRouteReconciler) SetupWithManager(mgr ctrl.Manager) error {
c, err := controller.New("httproute-controller", mgr, controller.Options{
Reconciler: r,
LogConstructor: func(_ *reconcile.Request) logr.Logger {
return r.Log
},
})
if err != nil {
return err
}
return c.Watch(
source.Kind(mgr.GetCache(), &gatewayv1.HTTPRoute{}),
&handler.EnqueueRequestForObject{},
)
}
6 changes: 3 additions & 3 deletions internal/controller/ingress/httpsedge_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
Expand Down Expand Up @@ -342,7 +342,7 @@ func (r *HTTPSEdgeReconciler) setEdgeTLSTermination(ctx context.Context, edge *n
_, err := client.Replace(ctx, &ngrok.EdgeTLSTerminationAtEdgeReplace{
ID: edge.ID,
Module: ngrok.EndpointTLSTerminationAtEdge{
MinVersion: pointer.String(tlsTermination.MinVersion),
MinVersion: ptr.To(tlsTermination.MinVersion),
},
})
return err
Expand Down Expand Up @@ -605,7 +605,7 @@ func (u *edgeRouteModuleUpdater) setEdgeRouteCompression(ctx context.Context, ro
EdgeID: route.EdgeID,
ID: route.ID,
Module: ngrok.EndpointCompression{
Enabled: pointer.Bool(routeSpec.Compression.Enabled),
Enabled: ptr.To(routeSpec.Compression.Enabled),
},
})
return err
Expand Down

0 comments on commit 699f065

Please sign in to comment.