Skip to content

Commit

Permalink
The gateway can forward traffic from extra source cidrs
Browse files Browse the repository at this point in the history
  • Loading branch information
珩轩 committed Mar 26, 2024
1 parent e2d6795 commit f4c3dca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func (r *ReconcileGateway) Reconcile(ctx context.Context, req reconcile.Request)
}
sort.Slice(nodes, func(i, j int) bool { return nodes[i].NodeName < nodes[j].NodeName })
gw.Status.Nodes = nodes
r.addExtraAllowedSubnet(&gw)

Check warning on line 192 in pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_controller.go#L192

Added line #L192 was not covered by tests
err = r.Status().Update(ctx, &gw)
if err != nil {
if apierrs.IsConflict(err) {
Expand Down Expand Up @@ -372,3 +373,23 @@ func (r *ReconcileGateway) configEndpoints(ctx context.Context, gw *ravenv1beta1
}
return
}

func (r *ReconcileGateway) addExtraAllowedSubnet(gw *ravenv1beta1.Gateway) {
if gw.Annotations == nil || gw.Annotations[util.ExtraAllowedSourceCIDRs] == "" {
return
}
subnets := strings.Split(gw.Annotations[util.ExtraAllowedSourceCIDRs], ",")
var gatewayName string
for _, aep := range gw.Status.ActiveEndpoints {
if aep.Type == ravenv1beta1.Tunnel {
gatewayName = aep.NodeName
break

Check warning on line 386 in pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_controller.go#L377-L386

Added lines #L377 - L386 were not covered by tests
}
}
for idx, node := range gw.Status.Nodes {
if node.NodeName == gatewayName {
gw.Status.Nodes[idx].Subnets = append(gw.Status.Nodes[idx].Subnets, subnets...)
break

Check warning on line 392 in pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/yurtmanager/controller/raven/gatewaypickup/gateway_pickup_controller.go#L389-L392

Added lines #L389 - L392 were not covered by tests
}
}
}
1 change: 1 addition & 0 deletions pkg/yurtmanager/controller/raven/util/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
GatewayProxyInternalService = "x-raven-proxy-internal-svc"
GatewayProxyServiceNamePrefix = "x-raven-proxy-svc"
GatewayTunnelServiceNamePrefix = "x-raven-tunnel-svc"
ExtraAllowedSourceCIDRs = "raven.openyurt.io/extra-allowed-source-cidrs"

RavenProxyNodesConfig = "edge-tunnel-nodes"
ProxyNodesKey = "tunnel-nodes"
Expand Down

0 comments on commit f4c3dca

Please sign in to comment.