Skip to content

Commit

Permalink
feat: update gateway for nat traversal (#1762)
Browse files Browse the repository at this point in the history
Signed-off-by: Liang Deng <283304489@qq.com>
  • Loading branch information
YTGhost authored Oct 31, 2023
1 parent 5d14338 commit ea8392b
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 46 deletions.
20 changes: 20 additions & 0 deletions charts/yurt-manager/crds/raven.openyurt.io_gateways.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ spec:
additionalProperties:
type: string
type: object
natType:
type: string
nodeName:
description: NodeName is the Node hosting this endpoint.
type: string
publicIP:
type: string
publicPort:
type: integer
underNAT:
type: boolean
required:
Expand Down Expand Up @@ -104,11 +108,15 @@ spec:
additionalProperties:
type: string
type: object
natType:
type: string
nodeName:
description: NodeName is the Node hosting this endpoint.
type: string
publicIP:
type: string
publicPort:
type: integer
underNAT:
type: boolean
required:
Expand Down Expand Up @@ -165,6 +173,9 @@ spec:
type: string
description: Config is a map to record config for the raven agent of node
type: object
natType:
description: NATType is the NAT type of the node
type: string
nodeName:
description: NodeName is the Node hosting this endpoint.
type: string
Expand All @@ -174,6 +185,9 @@ spec:
publicIP:
description: PublicIP is the exposed IP of the node
type: string
publicPort:
description: PublicPort is the port used for NAT traversal
type: integer
type:
description: Type is the service type of the node, proxy or tunnel
type: string
Expand Down Expand Up @@ -256,6 +270,9 @@ spec:
type: string
description: Config is a map to record config for the raven agent of node
type: object
natType:
description: NATType is the NAT type of the node
type: string
nodeName:
description: NodeName is the Node hosting this endpoint.
type: string
Expand All @@ -265,6 +282,9 @@ spec:
publicIP:
description: PublicIP is the exposed IP of the node
type: string
publicPort:
description: PublicPort is the port used for NAT traversal
type: integer
type:
description: Type is the service type of the node, proxy or tunnel
type: string
Expand Down
26 changes: 4 additions & 22 deletions pkg/apis/calico/v3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 28 additions & 20 deletions pkg/apis/raven/v1alpha1/gateway_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ func (src *Gateway) ConvertTo(dstRaw conversion.Hub) error {
dst.Spec.ProxyConfig.Replicas = 1
for _, eps := range src.Spec.Endpoints {
dst.Spec.Endpoints = append(dst.Spec.Endpoints, v1beta1.Endpoint{
NodeName: eps.NodeName,
PublicIP: eps.PublicIP,
UnderNAT: eps.UnderNAT,
Config: eps.Config,
Type: v1beta1.Tunnel,
Port: v1beta1.DefaultTunnelServerExposedPort,
NodeName: eps.NodeName,
PublicIP: eps.PublicIP,
UnderNAT: eps.UnderNAT,
PublicPort: eps.PublicPort,
NATType: eps.NATType,
Config: eps.Config,
Type: v1beta1.Tunnel,
Port: v1beta1.DefaultTunnelServerExposedPort,
})
}
for _, node := range src.Status.Nodes {
Expand All @@ -67,12 +69,14 @@ func (src *Gateway) ConvertTo(dstRaw conversion.Hub) error {
if src.Status.ActiveEndpoint != nil {
dst.Status.ActiveEndpoints = []*v1beta1.Endpoint{
{
NodeName: src.Status.ActiveEndpoint.NodeName,
PublicIP: src.Status.ActiveEndpoint.PublicIP,
UnderNAT: src.Status.ActiveEndpoint.UnderNAT,
Config: src.Status.ActiveEndpoint.Config,
Type: v1beta1.Tunnel,
Port: v1beta1.DefaultTunnelServerExposedPort,
NodeName: src.Status.ActiveEndpoint.NodeName,
PublicIP: src.Status.ActiveEndpoint.PublicIP,
UnderNAT: src.Status.ActiveEndpoint.UnderNAT,
PublicPort: src.Status.ActiveEndpoint.PublicPort,
NATType: src.Status.ActiveEndpoint.NATType,
Config: src.Status.ActiveEndpoint.Config,
Type: v1beta1.Tunnel,
Port: v1beta1.DefaultTunnelServerExposedPort,
},
}
}
Expand All @@ -91,10 +95,12 @@ func (dst *Gateway) ConvertFrom(srcRaw conversion.Hub) error {
dst.Spec.ExposeType = ExposeType(src.Spec.ExposeType)
for _, eps := range src.Spec.Endpoints {
dst.Spec.Endpoints = append(dst.Spec.Endpoints, Endpoint{
NodeName: eps.NodeName,
PublicIP: eps.PublicIP,
UnderNAT: eps.UnderNAT,
Config: eps.Config,
NodeName: eps.NodeName,
PublicIP: eps.PublicIP,
UnderNAT: eps.UnderNAT,
PublicPort: eps.PublicPort,
NATType: eps.NATType,
Config: eps.Config,
})
}
for _, node := range src.Status.Nodes {
Expand All @@ -112,10 +118,12 @@ func (dst *Gateway) ConvertFrom(srcRaw conversion.Hub) error {
dst.Status.ActiveEndpoint = nil
} else {
dst.Status.ActiveEndpoint = &Endpoint{
NodeName: src.Status.ActiveEndpoints[0].NodeName,
PublicIP: src.Status.ActiveEndpoints[0].PublicIP,
UnderNAT: src.Status.ActiveEndpoints[0].UnderNAT,
Config: src.Status.ActiveEndpoints[0].Config,
NodeName: src.Status.ActiveEndpoints[0].NodeName,
PublicIP: src.Status.ActiveEndpoints[0].PublicIP,
UnderNAT: src.Status.ActiveEndpoints[0].UnderNAT,
PublicPort: src.Status.ActiveEndpoints[0].PublicPort,
NATType: src.Status.ActiveEndpoints[0].NATType,
Config: src.Status.ActiveEndpoints[0].Config,
}
}
klog.Infof("convert from v1beta1 to v1alpha1 for %s", dst.Name)
Expand Down
10 changes: 6 additions & 4 deletions pkg/apis/raven/v1alpha1/gateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ type GatewaySpec struct {
// TODO add priority field?
type Endpoint struct {
// NodeName is the Node hosting this endpoint.
NodeName string `json:"nodeName"`
UnderNAT bool `json:"underNAT,omitempty"`
PublicIP string `json:"publicIP,omitempty"`
Config map[string]string `json:"config,omitempty"`
NodeName string `json:"nodeName"`
UnderNAT bool `json:"underNAT,omitempty"`
NATType string `json:"natType,omitempty"`
PublicIP string `json:"publicIP,omitempty"`
PublicPort int `json:"publicPort,omitempty"`
Config map[string]string `json:"config,omitempty"`
}

// NodeInfo stores information of node managed by Gateway.
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/raven/v1beta1/gateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@ type Endpoint struct {
Port int `json:"port,omitempty"`
// UnderNAT indicates whether node is under NAT
UnderNAT bool `json:"underNAT,omitempty"`
// NATType is the NAT type of the node
NATType string `json:"natType,omitempty"`
// PublicIP is the exposed IP of the node
PublicIP string `json:"publicIP,omitempty"`
// PublicPort is the port used for NAT traversal
PublicPort int `json:"publicPort,omitempty"`
// Config is a map to record config for the raven agent of node
Config map[string]string `json:"config,omitempty"`
}
Expand Down

0 comments on commit ea8392b

Please sign in to comment.