Skip to content

Commit 3d72b24

Browse files
committed
NE-1954: Implement GatewayAPIController feature gate
Skipped starting the gatewayclass and service dns controllers when the GatewayAPIController feature gate is disabled.
1 parent d9cf3df commit 3d72b24

File tree

4 files changed

+51
-16
lines changed

4 files changed

+51
-16
lines changed

pkg/operator/controller/gatewayapi/controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ func New(mgr manager.Manager, config Config) (controller.Controller, error) {
7676
type Config struct {
7777
// GatewayAPIEnabled indicates that the "GatewayAPI" featuregate is enabled.
7878
GatewayAPIEnabled bool
79+
// GatewayAPIControllerEnabled indicates that the "GatewayAPIController" featuregate is enabled.
80+
GatewayAPIControllerEnabled bool
7981

8082
// DependentControllers is a list of controllers that watch Gateway API
8183
// resources. The gatewayapi controller starts these controllers once
@@ -105,6 +107,10 @@ func (r *reconciler) Reconcile(ctx context.Context, request reconcile.Request) (
105107
return reconcile.Result{}, err
106108
}
107109

110+
if !r.config.GatewayAPIControllerEnabled {
111+
return reconcile.Result{}, nil
112+
}
113+
108114
r.startControllers.Do(func() {
109115
for i := range r.config.DependentControllers {
110116
c := &r.config.DependentControllers[i]

pkg/operator/controller/gatewayapi/controller_test.go

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ func Test_Reconcile(t *testing.T) {
3535
}
3636
}
3737
tests := []struct {
38-
name string
39-
gatewayAPIEnabled bool
40-
existingObjects []runtime.Object
41-
expectCreate []client.Object
42-
expectUpdate []client.Object
43-
expectDelete []client.Object
44-
expectStartCtrl bool
38+
name string
39+
gatewayAPIEnabled bool
40+
gatewayAPIControllerEnabled bool
41+
existingObjects []runtime.Object
42+
expectCreate []client.Object
43+
expectUpdate []client.Object
44+
expectDelete []client.Object
45+
expectStartCtrl bool
4546
}{
4647
{
4748
name: "gateway API disabled",
@@ -52,8 +53,9 @@ func Test_Reconcile(t *testing.T) {
5253
expectStartCtrl: false,
5354
},
5455
{
55-
name: "gateway API enabled",
56-
gatewayAPIEnabled: true,
56+
name: "gateway API enabled",
57+
gatewayAPIEnabled: true,
58+
gatewayAPIControllerEnabled: true,
5759
expectCreate: []client.Object{
5860
crd("gatewayclasses.gateway.networking.k8s.io"),
5961
crd("gateways.gateway.networking.k8s.io"),
@@ -64,6 +66,20 @@ func Test_Reconcile(t *testing.T) {
6466
expectDelete: []client.Object{},
6567
expectStartCtrl: true,
6668
},
69+
{
70+
name: "gateway API enabled, gateway API controller disabled",
71+
gatewayAPIEnabled: true,
72+
gatewayAPIControllerEnabled: false,
73+
expectCreate: []client.Object{
74+
crd("gatewayclasses.gateway.networking.k8s.io"),
75+
crd("gateways.gateway.networking.k8s.io"),
76+
crd("httproutes.gateway.networking.k8s.io"),
77+
crd("referencegrants.gateway.networking.k8s.io"),
78+
},
79+
expectUpdate: []client.Object{},
80+
expectDelete: []client.Object{},
81+
expectStartCtrl: false,
82+
},
6783
}
6884

6985
scheme := runtime.NewScheme()
@@ -81,8 +97,9 @@ func Test_Reconcile(t *testing.T) {
8197
reconciler := &reconciler{
8298
client: cl,
8399
config: Config{
84-
GatewayAPIEnabled: tc.gatewayAPIEnabled,
85-
DependentControllers: []controller.Controller{ctrl},
100+
GatewayAPIEnabled: tc.gatewayAPIEnabled,
101+
GatewayAPIControllerEnabled: tc.gatewayAPIControllerEnabled,
102+
DependentControllers: []controller.Controller{ctrl},
86103
},
87104
}
88105
req := reconcile.Request{
@@ -131,8 +148,9 @@ func TestReconcileOnlyStartsControllerOnce(t *testing.T) {
131148
reconciler := &reconciler{
132149
client: cl,
133150
config: Config{
134-
GatewayAPIEnabled: true,
135-
DependentControllers: []controller.Controller{ctrl},
151+
GatewayAPIEnabled: true,
152+
GatewayAPIControllerEnabled: true,
153+
DependentControllers: []controller.Controller{ctrl},
136154
},
137155
}
138156
req := reconcile.Request{NamespacedName: types.NamespacedName{Name: "cluster"}}

pkg/operator/operator.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ func New(config operatorconfig.Config, kubeConfig *rest.Config) (*Operator, erro
132132
azureWorkloadIdentityEnabled := featureGates.Enabled(features.FeatureGateAzureWorkloadIdentity)
133133
sharedVPCEnabled := featureGates.Enabled(features.FeatureGatePrivateHostedZoneAWS)
134134
gatewayAPIEnabled := featureGates.Enabled(features.FeatureGateGatewayAPI)
135+
gatewayAPIControllerEnabled := featureGates.Enabled(features.FeatureGateGatewayAPIController)
135136
routeExternalCertificateEnabled := featureGates.Enabled(features.FeatureGateRouteExternalCertificate)
136137
ingressControllerLBSubnetsAWSEnabled := featureGates.Enabled(features.FeatureGateIngressControllerLBSubnetsAWS)
137138
ingressControllerEIPAllocationsAWSEnabled := featureGates.Enabled(features.FeatureGateSetEIPForNLBIngressController)
@@ -311,7 +312,8 @@ func New(config operatorconfig.Config, kubeConfig *rest.Config) (*Operator, erro
311312

312313
// Set up the gatewayapi controller.
313314
if _, err := gatewayapicontroller.New(mgr, gatewayapicontroller.Config{
314-
GatewayAPIEnabled: gatewayAPIEnabled,
315+
GatewayAPIEnabled: gatewayAPIEnabled,
316+
GatewayAPIControllerEnabled: gatewayAPIControllerEnabled,
315317
DependentControllers: []controller.Controller{
316318
gatewayClassController,
317319
gatewayServiceDNSController,

test/e2e/gateway_api_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ func TestGatewayAPI(t *testing.T) {
6060
t.Skip("Gateway API not enabled, skipping TestGatewayAPI")
6161
}
6262

63+
gatewayAPIControllerEnabled, err := isFeatureGateEnabled(features.FeatureGateGatewayAPIController)
64+
if err != nil {
65+
t.Fatalf("error checking controller feature gate enabled status: %v", err)
66+
}
67+
6368
// Defer the cleanup of the test gateway.
6469
t.Cleanup(func() {
6570
testGateway := gatewayapiv1.Gateway{ObjectMeta: metav1.ObjectMeta{Name: testGatewayName, Namespace: operatorcontroller.DefaultOperandNamespace}}
@@ -73,8 +78,12 @@ func TestGatewayAPI(t *testing.T) {
7378
})
7479

7580
t.Run("testGatewayAPIResources", testGatewayAPIResources)
76-
t.Run("testGatewayAPIObjects", testGatewayAPIObjects)
77-
t.Run("testGatewayAPIIstioInstallation", testGatewayAPIIstioInstallation)
81+
if gatewayAPIControllerEnabled {
82+
t.Run("testGatewayAPIObjects", testGatewayAPIObjects)
83+
t.Run("testGatewayAPIIstioInstallation", testGatewayAPIIstioInstallation)
84+
} else {
85+
t.Log("Gateway API Controller not enabled, skipping testGatewayAPIObjects and testGatewayAPIIstioInstallation")
86+
}
7887
}
7988

8089
// testGatewayAPIResources tests that Gateway API Custom Resource Definitions are available.

0 commit comments

Comments
 (0)