From a5c170a47816e50bce4b39b7d7b54764d92acb71 Mon Sep 17 00:00:00 2001 From: Peter Kurfer Date: Fri, 17 Jan 2025 15:03:13 +0100 Subject: [PATCH] refactor(gateway): make node name explicitly configurable in spec --- api/v1alpha1/apigateway_types.go | 4 ++++ internal/controller/apigateway_controller.go | 2 +- internal/webhook/v1alpha1/apigateway_webhook_defaulter.go | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/api/v1alpha1/apigateway_types.go b/api/v1alpha1/apigateway_types.go index 3d54f01..782679a 100644 --- a/api/v1alpha1/apigateway_types.go +++ b/api/v1alpha1/apigateway_types.go @@ -38,6 +38,10 @@ type ControlPlaneSpec struct { } type EnvoySpec struct { + // NodeName - identifies the Envoy cluster within the current namespace + // if not set, the name of the APIGateway resource will be used + // The primary use case is to make the assignment of multiple supabase instances in a single namespace explicit. + NodeName string `json:"nodeName,omitempty"` // ControlPlane - configure the control plane where Envoy will retrieve its configuration from ControlPlane *ControlPlaneSpec `json:"controlPlane"` // WorkloadTemplate - customize the Envoy deployment diff --git a/internal/controller/apigateway_controller.go b/internal/controller/apigateway_controller.go index 733bd09..a598687 100644 --- a/internal/controller/apigateway_controller.go +++ b/internal/controller/apigateway_controller.go @@ -191,7 +191,7 @@ func (r *APIGatewayReconciler) reconcileEnvoyConfig( Port uint16 } - instance := fmt.Sprintf("%s:%s", gateway.Name, gateway.Namespace) + instance := fmt.Sprintf("%s:%s", gateway.Spec.Envoy.NodeName, gateway.Namespace) tmplData := struct { Node nodeSpec diff --git a/internal/webhook/v1alpha1/apigateway_webhook_defaulter.go b/internal/webhook/v1alpha1/apigateway_webhook_defaulter.go index f94bf34..5619448 100644 --- a/internal/webhook/v1alpha1/apigateway_webhook_defaulter.go +++ b/internal/webhook/v1alpha1/apigateway_webhook_defaulter.go @@ -69,6 +69,10 @@ func (d *APIGatewayCustomDefaulter) Default(ctx context.Context, obj runtime.Obj apiGateway.Spec.Envoy = new(supabasev1alpha1.EnvoySpec) } + if apiGateway.Spec.Envoy.NodeName == "" { + apiGateway.Spec.Envoy.NodeName = apiGateway.Name + } + if apiGateway.Spec.Envoy.ControlPlane == nil { if d.CurrentNamespace == defaultManagerNamespace { d.Recorder.Event(