Skip to content

Commit

Permalink
feat: make KonnectExtension conditionally enabled (#738)
Browse files Browse the repository at this point in the history
* feat: make KonnectExtension conditionally enabled

The KonnectExtension functionality is enabled only in case the --enable-controller-konnect flag is set.

Signed-off-by: Mattia Lavacca <[email protected]>

* update CHANGELOG.md

Signed-off-by: Mattia Lavacca <[email protected]>

---------

Signed-off-by: Mattia Lavacca <[email protected]>
  • Loading branch information
mlavacca authored Oct 11, 2024
1 parent cc79fa9 commit 5cc7aee
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
- Apply Konnect-related customizations to `DataPlane`s that properly reference `KonnectExtension`
resources.
[#714](https://github.com/Kong/gateway-operator/pull/714)
- The KonnectExtension functionality is enabled only when the `--enable-controller-konnect`
flag or the `GATEWAY_OPERATOR_ENABLE_CONTROLLER_KONNECT` env var is set.
[#738](https://github.com/Kong/gateway-operator/pull/738)

### Fixed

Expand Down
3 changes: 2 additions & 1 deletion controller/dataplane/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Reconciler struct {
Callbacks DataPlaneCallbacks
ContextInjector ctxinjector.CtxInjector
DefaultImage string
KonnectEnabled bool
}

// SetupWithManager sets up the controller with the Manager.
Expand Down Expand Up @@ -91,7 +92,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
}

log.Trace(logger, "applying extensions", dataplane)
patched, requeue, err := applyExtensions(ctx, r.Client, logger, dataplane)
patched, requeue, err := applyExtensions(ctx, r.Client, logger, dataplane, r.KonnectEnabled)
if err != nil {
if !requeue {
log.Debug(logger, "failed to apply extensions", dataplane, "error:", err)
Expand Down
8 changes: 7 additions & 1 deletion controller/dataplane/controller_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,16 @@ func isDeploymentReady(deploymentStatus appsv1.DeploymentStatus) (metav1.Conditi
// - requeue: a boolean indicating if the dataplane should be requeued. If the error was unexpected (e.g., because of API server error), the dataplane should be requeued.
// In case the error is related to a misconfiguration, the dataplane does not need to be requeued, and feedback is provided into the dataplane status.
// - err: an error in case of failure.
func applyExtensions(ctx context.Context, cl client.Client, logger logr.Logger, dataplane *operatorv1beta1.DataPlane) (patched bool, requeue bool, err error) {
func applyExtensions(ctx context.Context, cl client.Client, logger logr.Logger, dataplane *operatorv1beta1.DataPlane, konnectEnabled bool) (patched bool, requeue bool, err error) {
if len(dataplane.Spec.Extensions) == 0 {
return false, false, nil
}

// the konnect extension is the only one implemented at the moment. In case konnect is not enabled, we return early.
if !konnectEnabled {
return false, false, nil
}

condition := k8sutils.NewConditionWithGeneration(consts.ResolvedRefsType, metav1.ConditionTrue, consts.ResolvedRefsReason, "", dataplane.GetGeneration())
err = applyKonnectExtension(ctx, cl, dataplane)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions modules/manager/controller_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ func SetupControllers(mgr manager.Manager, c *Config) (map[string]ControllerDef,
BeforeDeployment: dataplane.CreateCallbackManager(),
AfterDeployment: dataplane.CreateCallbackManager(),
},
DefaultImage: consts.DefaultDataPlaneImage,
DefaultImage: consts.DefaultDataPlaneImage,
KonnectEnabled: c.KonnectControllersEnabled,
},
},
// DataPlaneBlueGreen controller
Expand All @@ -317,6 +318,7 @@ func SetupControllers(mgr manager.Manager, c *Config) (map[string]ControllerDef,
BeforeDeployment: dataplane.CreateCallbackManager(),
AfterDeployment: dataplane.CreateCallbackManager(),
},
KonnectEnabled: c.KonnectControllersEnabled,
},
Callbacks: dataplane.DataPlaneCallbacks{
BeforeDeployment: dataplane.CreateCallbackManager(),
Expand Down Expand Up @@ -347,7 +349,7 @@ func SetupControllers(mgr manager.Manager, c *Config) (map[string]ControllerDef,
),
},
KonnectExtensionControllerName: {
Enabled: c.DataPlaneControllerEnabled || c.DataPlaneBlueGreenControllerEnabled,
Enabled: (c.DataPlaneControllerEnabled || c.DataPlaneBlueGreenControllerEnabled) && c.KonnectControllersEnabled,
Controller: &dataplane.KonnectExtensionReconciler{
Client: mgr.GetClient(),
DevelopmentMode: c.DevelopmentMode,
Expand Down

0 comments on commit 5cc7aee

Please sign in to comment.