From 6e6d2e130fb2c88e0c8d848d7efbca5b65a49988 Mon Sep 17 00:00:00 2001 From: Karol Szwaj Date: Fri, 13 Oct 2023 18:00:04 +0200 Subject: [PATCH] reconcile merged service and deployment Signed-off-by: Karol Szwaj --- .../merge-invalid-multiple-gateways.out.yaml | 15 +++++++++++++++ .../merge-valid-multiple-gateways.out.yaml | 10 ++++++++++ .../testdata/multiple-gateways.out.yaml | 10 ++++++++++ internal/provider/kubernetes/controller.go | 15 ++++++++------- internal/provider/kubernetes/predicates.go | 8 ++++---- 5 files changed, 47 insertions(+), 11 deletions(-) diff --git a/internal/gatewayapi/testdata/merge-invalid-multiple-gateways.out.yaml b/internal/gatewayapi/testdata/merge-invalid-multiple-gateways.out.yaml index 67f52c83c43f..5f3918bda179 100755 --- a/internal/gatewayapi/testdata/merge-invalid-multiple-gateways.out.yaml +++ b/internal/gatewayapi/testdata/merge-invalid-multiple-gateways.out.yaml @@ -25,6 +25,11 @@ gateways: reason: Accepted status: "True" type: Accepted + - lastTransitionTime: null + message: Listener references have been resolved + reason: ResolvedRefs + status: "True" + type: ResolvedRefs name: http supportedKinds: - group: gateway.networking.k8s.io @@ -60,6 +65,11 @@ gateways: reason: Invalid status: "False" type: Programmed + - lastTransitionTime: null + message: Listener references have been resolved + reason: ResolvedRefs + status: "True" + type: ResolvedRefs name: http supportedKinds: - group: gateway.networking.k8s.io @@ -78,6 +88,11 @@ gateways: reason: Accepted status: "True" type: Accepted + - lastTransitionTime: null + message: Listener references have been resolved + reason: ResolvedRefs + status: "True" + type: ResolvedRefs name: udp supportedKinds: - group: gateway.networking.k8s.io diff --git a/internal/gatewayapi/testdata/merge-valid-multiple-gateways.out.yaml b/internal/gatewayapi/testdata/merge-valid-multiple-gateways.out.yaml index 9f68963a4fbd..57521ce77dd6 100755 --- a/internal/gatewayapi/testdata/merge-valid-multiple-gateways.out.yaml +++ b/internal/gatewayapi/testdata/merge-valid-multiple-gateways.out.yaml @@ -28,6 +28,11 @@ gateways: reason: Accepted status: "True" type: Accepted + - lastTransitionTime: null + message: Listener references have been resolved + reason: ResolvedRefs + status: "True" + type: ResolvedRefs name: http supportedKinds: - group: gateway.networking.k8s.io @@ -63,6 +68,11 @@ gateways: reason: Accepted status: "True" type: Accepted + - lastTransitionTime: null + message: Listener references have been resolved + reason: ResolvedRefs + status: "True" + type: ResolvedRefs name: http-2 supportedKinds: - group: gateway.networking.k8s.io diff --git a/internal/gatewayapi/testdata/multiple-gateways.out.yaml b/internal/gatewayapi/testdata/multiple-gateways.out.yaml index 5b0689026094..62d0bde4d55e 100644 --- a/internal/gatewayapi/testdata/multiple-gateways.out.yaml +++ b/internal/gatewayapi/testdata/multiple-gateways.out.yaml @@ -28,6 +28,11 @@ gateways: reason: Accepted status: "True" type: Accepted + - lastTransitionTime: null + message: Listener references have been resolved + reason: ResolvedRefs + status: "True" + type: ResolvedRefs name: http supportedKinds: - group: gateway.networking.k8s.io @@ -63,6 +68,11 @@ gateways: reason: Accepted status: "True" type: Accepted + - lastTransitionTime: null + message: Listener references have been resolved + reason: ResolvedRefs + status: "True" + type: ResolvedRefs name: http-2 supportedKinds: - group: gateway.networking.k8s.io diff --git a/internal/provider/kubernetes/controller.go b/internal/provider/kubernetes/controller.go index e3a3fde5c765..070426e9eb2f 100644 --- a/internal/provider/kubernetes/controller.go +++ b/internal/provider/kubernetes/controller.go @@ -69,6 +69,7 @@ type gatewayAPIReconciler struct { namespace string namespaceLabels []string envoyGateway *egv1a1.EnvoyGateway + mergeGateways bool resources *message.ProviderResources extGVKs []schema.GroupVersionKind @@ -331,6 +332,10 @@ func (r *gatewayAPIReconciler) Reconcile(ctx context.Context, _ reconcile.Reques return reconcile.Result{}, err } + if resourceTree.EnvoyProxy != nil && resourceTree.EnvoyProxy.Spec.MergeGateways != nil { + r.mergeGateways = *resourceTree.EnvoyProxy.Spec.MergeGateways + } + if err := r.gatewayClassUpdater(ctx, acceptedGC, true, string(gwapiv1b1.GatewayClassReasonAccepted), status.MsgValidGatewayClass); err != nil { r.log.Error(err, "unable to update GatewayClass status") return reconcile.Result{}, err @@ -403,20 +408,16 @@ func (r *gatewayAPIReconciler) statusUpdateForGateway(ctx context.Context, gtw * if r.statusUpdater == nil { return } - var merged bool - res, _ := r.resources.GatewayAPIResources.Load(string(gtw.Spec.GatewayClassName)) - if res.EnvoyProxy != nil && res.EnvoyProxy.Spec.MergeGateways != nil && *res.EnvoyProxy.Spec.MergeGateways { - merged = true - } + // Get deployment - deploy, err := r.envoyDeploymentForGateway(ctx, gtw, merged) + deploy, err := r.envoyDeploymentForGateway(ctx, gtw) if err != nil { r.log.Info("failed to get Deployment for gateway", "namespace", gtw.Namespace, "name", gtw.Name) } // Get service - svc, err := r.envoyServiceForGateway(ctx, gtw, merged) + svc, err := r.envoyServiceForGateway(ctx, gtw) if err != nil { r.log.Info("failed to get Service for gateway", "namespace", gtw.Namespace, "name", gtw.Name) diff --git a/internal/provider/kubernetes/predicates.go b/internal/provider/kubernetes/predicates.go index b00da15bf0f1..ecace7b3bec8 100644 --- a/internal/provider/kubernetes/predicates.go +++ b/internal/provider/kubernetes/predicates.go @@ -411,10 +411,10 @@ func (r *gatewayAPIReconciler) filterHTTPRoutesByNamespaceLabels(httpRoutes []gw } // envoyDeploymentForGateway returns the Envoy Deployment, returning nil if the Deployment doesn't exist. -func (r *gatewayAPIReconciler) envoyDeploymentForGateway(ctx context.Context, gateway *gwapiv1b1.Gateway, merged bool) (*appsv1.Deployment, error) { +func (r *gatewayAPIReconciler) envoyDeploymentForGateway(ctx context.Context, gateway *gwapiv1b1.Gateway) (*appsv1.Deployment, error) { key := types.NamespacedName{ Namespace: r.namespace, - Name: infraDeploymentName(gateway, merged), + Name: infraDeploymentName(gateway, r.mergeGateways), } deployment := new(appsv1.Deployment) if err := r.client.Get(ctx, key, deployment); err != nil { @@ -427,10 +427,10 @@ func (r *gatewayAPIReconciler) envoyDeploymentForGateway(ctx context.Context, ga } // envoyServiceForGateway returns the Envoy service, returning nil if the service doesn't exist. -func (r *gatewayAPIReconciler) envoyServiceForGateway(ctx context.Context, gateway *gwapiv1b1.Gateway, merged bool) (*corev1.Service, error) { +func (r *gatewayAPIReconciler) envoyServiceForGateway(ctx context.Context, gateway *gwapiv1b1.Gateway) (*corev1.Service, error) { key := types.NamespacedName{ Namespace: r.namespace, - Name: infraServiceName(gateway, merged), + Name: infraServiceName(gateway, r.mergeGateways), } svc := new(corev1.Service) if err := r.client.Get(ctx, key, svc); err != nil {