@@ -12,6 +12,7 @@ import (
12
12
ctrl "sigs.k8s.io/controller-runtime"
13
13
"sigs.k8s.io/controller-runtime/pkg/builder"
14
14
"sigs.k8s.io/controller-runtime/pkg/client"
15
+ "sigs.k8s.io/controller-runtime/pkg/event"
15
16
"sigs.k8s.io/controller-runtime/pkg/handler"
16
17
"sigs.k8s.io/controller-runtime/pkg/log"
17
18
"sigs.k8s.io/controller-runtime/pkg/manager"
@@ -33,18 +34,36 @@ const (
33
34
InferencePoolField = "inferencepool-index"
34
35
)
35
36
37
+ // ClassInfo describes the desired configuration for a GatewayClass.
38
+ type ClassInfo struct {
39
+ // Description is a human-readable description of the GatewayClass.
40
+ Description string
41
+ // Labels are the labels to be added to the GatewayClass.
42
+ Labels map [string ]string
43
+ // Annotations are the annotations to be added to the GatewayClass.
44
+ Annotations map [string ]string
45
+ // ParametersRef is the reference to the GatewayParameters object.
46
+ ParametersRef * apiv1.ParametersReference
47
+ }
48
+
36
49
// TODO [danehans]: Refactor so controller config is organized into shared and Gateway/InferencePool-specific controllers.
37
50
type GatewayConfig struct {
38
51
Mgr manager.Manager
39
-
40
- Dev bool
52
+ // Dev enables development mode for the controller.
53
+ Dev bool
54
+ // ControllerName is the name of the controller. Any GatewayClass objects
55
+ // managed by this controller must have this name as their ControllerName.
41
56
ControllerName string
42
- AutoProvision bool
43
-
44
- ControlPlane deployer.ControlPlaneInfo
57
+ // AutoProvision enables auto-provisioning of GatewayClasses.
58
+ AutoProvision bool
59
+ // ControlPlane sets the default control plane information the deployer will use.
60
+ ControlPlane deployer.ControlPlaneInfo
61
+ // IstioIntegrationEnabled enables Istio integration for the controller.
45
62
IstioIntegrationEnabled bool
46
-
63
+ // ImageInfo sets the default image information the deployer will use.
47
64
ImageInfo * deployer.ImageInfo
65
+ // ClassInfo sets the default configuration for GatewayClasses managed by this controller.
66
+ ClassInfo map [string ]* ClassInfo
48
67
}
49
68
50
69
func NewBaseGatewayController (ctx context.Context , cfg GatewayConfig ) error {
@@ -59,7 +78,8 @@ func NewBaseGatewayController(ctx context.Context, cfg GatewayConfig) error {
59
78
},
60
79
}
61
80
62
- return run (ctx ,
81
+ return run (
82
+ ctx ,
63
83
controllerBuilder .watchGwClass ,
64
84
controllerBuilder .watchGw ,
65
85
controllerBuilder .addIndexes ,
@@ -384,24 +404,27 @@ func shouldIgnoreStatusChild(gvk schema.GroupVersionKind) bool {
384
404
385
405
func (c * controllerBuilder ) watchGwClass (_ context.Context ) error {
386
406
return ctrl .NewControllerManagedBy (c .cfg .Mgr ).
407
+ For (& apiv1.GatewayClass {}, builder .WithPredicates (predicate.Funcs {
408
+ CreateFunc : func (e event.CreateEvent ) bool { return true },
409
+ DeleteFunc : func (e event.DeleteEvent ) bool { return false },
410
+ UpdateFunc : func (e event.UpdateEvent ) bool { return true },
411
+ GenericFunc : func (e event.GenericEvent ) bool { return false },
412
+ })).
387
413
WithEventFilter (predicate.GenerationChangedPredicate {}).
388
414
WithEventFilter (predicate .NewPredicateFuncs (func (object client.Object ) bool {
389
415
// we only care about GatewayClasses that use our controller name
390
- if gwClass , ok := object .(* apiv1.GatewayClass ); ok {
391
- return gwClass .Spec .ControllerName == apiv1 .GatewayController (c .cfg .ControllerName )
392
- }
393
- return false
416
+ gwClass , ok := object .(* apiv1.GatewayClass )
417
+ return ok && gwClass .Spec .ControllerName == apiv1 .GatewayController (c .cfg .ControllerName )
394
418
})).
395
- For (& apiv1.GatewayClass {}).
396
- Complete (reconcile .Func (c .reconciler .ReconcileGatewayClasses ))
419
+ Complete (c .reconciler )
397
420
}
398
421
399
422
type controllerReconciler struct {
400
423
cli client.Client
401
424
scheme * runtime.Scheme
402
425
}
403
426
404
- func (r * controllerReconciler ) ReconcileGatewayClasses (ctx context.Context , req ctrl.Request ) (ctrl.Result , error ) {
427
+ func (r * controllerReconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (ctrl.Result , error ) {
405
428
log := log .FromContext (ctx ).WithValues ("gwclass" , req .NamespacedName )
406
429
407
430
gwclass := & apiv1.GatewayClass {}
@@ -415,24 +438,21 @@ func (r *controllerReconciler) ReconcileGatewayClasses(ctx context.Context, req
415
438
416
439
log .Info ("reconciling gateway class" )
417
440
418
- // mark it as accepted:
419
- acceptedCondition := metav1.Condition {
441
+ meta .SetStatusCondition (& gwclass .Status .Conditions , metav1.Condition {
420
442
Type : string (apiv1 .GatewayClassConditionStatusAccepted ),
421
443
Status : metav1 .ConditionTrue ,
422
444
Reason : string (apiv1 .GatewayClassReasonAccepted ),
423
445
ObservedGeneration : gwclass .Generation ,
424
446
// no need to set LastTransitionTime, it will be set automatically by SetStatusCondition
425
- }
426
- meta .SetStatusCondition (& gwclass .Status .Conditions , acceptedCondition )
447
+ })
427
448
428
449
// TODO: This should actually check the version of the CRDs in the cluster to be 100% sure
429
- supportedVersionCondition := metav1.Condition {
450
+ meta . SetStatusCondition ( & gwclass . Status . Conditions , metav1.Condition {
430
451
Type : string (apiv1 .GatewayClassConditionStatusSupportedVersion ),
431
452
Status : metav1 .ConditionTrue ,
432
453
ObservedGeneration : gwclass .Generation ,
433
454
Reason : string (apiv1 .GatewayClassReasonSupportedVersion ),
434
- }
435
- meta .SetStatusCondition (& gwclass .Status .Conditions , supportedVersionCondition )
455
+ })
436
456
437
457
if err := r .cli .Status ().Update (ctx , gwclass ); err != nil {
438
458
return ctrl.Result {}, err
0 commit comments