Skip to content

Commit

Permalink
reconcile merged service and deployment
Browse files Browse the repository at this point in the history
Signed-off-by: Karol Szwaj <karol.szwaj@gmail.com>
  • Loading branch information
cnvergence committed Oct 13, 2023
1 parent ee1fbab commit 6e6d2e1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions internal/gatewayapi/testdata/multiple-gateways.out.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions internal/provider/kubernetes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type gatewayAPIReconciler struct {
namespace string
namespaceLabels []string
envoyGateway *egv1a1.EnvoyGateway
mergeGateways bool

resources *message.ProviderResources
extGVKs []schema.GroupVersionKind
Expand Down Expand Up @@ -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
}

Check warning on line 337 in internal/provider/kubernetes/controller.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/controller.go#L336-L337

Added lines #L336 - L337 were not covered by tests

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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions internal/provider/kubernetes/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 6e6d2e1

Please sign in to comment.