Skip to content

Commit a7f05fb

Browse files
committed
update api
Signed-off-by: Shiming Zhang <[email protected]>
1 parent 6adc9d1 commit a7f05fb

File tree

9 files changed

+175
-185
lines changed

9 files changed

+175
-185
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/ferryproxy/ferry
33
go 1.18
44

55
require (
6-
github.com/ferryproxy/api v0.4.2
6+
github.com/ferryproxy/api v0.4.3-0.20220929110018-87b27802e21a
77
github.com/ferryproxy/client-go v0.4.0
88
github.com/go-logr/logr v1.2.3
99
github.com/go-logr/zapr v1.2.3

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ github.com/evanphx/json-patch/v5 v5.0.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2Vvl
140140
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
141141
github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ=
142142
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
143-
github.com/ferryproxy/api v0.4.2 h1:2SBq/ljIzL6TeyoiM3OjO0Bnx0J2f5g+CUjoLWWyano=
144-
github.com/ferryproxy/api v0.4.2/go.mod h1:vFqYueEfIwpU2o3Y8/ryKKn5S3WBR4wVgHgh21zwpeQ=
143+
github.com/ferryproxy/api v0.4.3-0.20220929110018-87b27802e21a h1:FwMc7CdF8u+EWEnJMiZXEeDu3pqsjSfLn65Iun6iuuE=
144+
github.com/ferryproxy/api v0.4.3-0.20220929110018-87b27802e21a/go.mod h1:vFqYueEfIwpU2o3Y8/ryKKn5S3WBR4wVgHgh21zwpeQ=
145145
github.com/ferryproxy/client-go v0.4.0 h1:pTlCUc7Q77d99yNru01WbKe8Ie8sBSpDO/h4ZmMW5gk=
146146
github.com/ferryproxy/client-go v0.4.0/go.mod h1:A0DBMIJFYM4j+qvgHxTamZH3m56xfmuDnC+8E2gOtto=
147147
github.com/flowstack/go-jsonschema v0.1.1/go.mod h1:yL7fNggx1o8rm9RlgXv7hTBWxdBM0rVwpMwimd3F3N0=

pkg/controllers/route/mapping_controller.go

+2-20
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package route
1818

1919
import (
2020
"context"
21-
"fmt"
2221
"strings"
2322
"sync"
2423
"time"
@@ -38,8 +37,6 @@ import (
3837
)
3938

4039
type HubInterface interface {
41-
GetService(hubName string, namespace, name string) (*corev1.Service, bool)
42-
ListServices(name string) []*corev1.Service
4340
GetHub(name string) *v1alpha2.Hub
4441
GetHubGateway(hubName string, forHub string) v1alpha2.HubSpecGateway
4542
GetAuthorized(name string) string
@@ -420,15 +417,7 @@ func (m *MappingController) Close() {
420417
}
421418

422419
func (m *MappingController) updatePort(f *v1alpha2.Route) error {
423-
svc, ok := m.hubInterface.GetService(f.Spec.Export.HubName, f.Spec.Export.Service.Namespace, f.Spec.Export.Service.Name)
424-
if !ok {
425-
return fmt.Errorf("not found export service")
426-
}
427-
428-
for _, port := range svc.Spec.Ports {
429-
if port.Protocol != corev1.ProtocolTCP {
430-
continue
431-
}
420+
for _, port := range f.Spec.Import.Ports {
432421
_, err := m.hubInterface.GetPortPeer(f.Spec.Import.HubName,
433422
f.Spec.Export.HubName, f.Spec.Export.Service.Namespace, f.Spec.Export.Service.Name, port.Port)
434423
if err != nil {
@@ -439,14 +428,7 @@ func (m *MappingController) updatePort(f *v1alpha2.Route) error {
439428
}
440429

441430
func (m *MappingController) deletePort(f *v1alpha2.Route) error {
442-
svc, ok := m.hubInterface.GetService(f.Spec.Export.HubName, f.Spec.Export.Service.Namespace, f.Spec.Export.Service.Name)
443-
if !ok {
444-
return fmt.Errorf("not found export service")
445-
}
446-
for _, port := range svc.Spec.Ports {
447-
if port.Protocol != corev1.ProtocolTCP {
448-
continue
449-
}
431+
for _, port := range f.Spec.Import.Ports {
450432
_, err := m.hubInterface.DeletePortPeer(f.Spec.Import.HubName,
451433
f.Spec.Export.HubName, f.Spec.Export.Service.Namespace, f.Spec.Export.Service.Name, port.Port)
452434
if err == nil {

pkg/controllers/route_policy/mirror_tunnel.go

+12
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,25 @@ func buildMirrorTunnelRoute(hub *v1alpha2.Hub, importHubName string) *v1alpha2.R
5757
Namespace: "ferry-tunnel-system",
5858
Name: "ferry-tunnel",
5959
},
60+
Ports: []v1alpha2.RouteSpecRulePort{
61+
{
62+
Name: "http",
63+
Port: 8080,
64+
},
65+
},
6066
},
6167
Import: v1alpha2.RouteSpecRule{
6268
HubName: importHubName,
6369
Service: v1alpha2.RouteSpecRuleService{
6470
Namespace: "ferry-tunnel-system",
6571
Name: hub.Name + "-ferry-tunnel",
6672
},
73+
Ports: []v1alpha2.RouteSpecRulePort{
74+
{
75+
Name: "http",
76+
Port: 8080,
77+
},
78+
},
6779
},
6880
},
6981
}

pkg/controllers/route_policy/route_policy_controller.go

+12
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,16 @@ func policiesToRoutes(hubInterface HubInterface, policies []*v1alpha2.RoutePolic
365365

366366
policy := match.Policy
367367

368+
var ports []v1alpha2.RouteSpecRulePort
369+
for _, port := range svc.Spec.Ports {
370+
if port.Protocol == "" || port.Protocol == corev1.ProtocolTCP {
371+
ports = append(ports, v1alpha2.RouteSpecRulePort{
372+
Name: port.Name,
373+
Port: port.Port,
374+
})
375+
}
376+
}
377+
368378
suffix := hash(fmt.Sprintf("%s|%s|%s|%s|%s|%s",
369379
exportHubName, exportNamespace, exportName,
370380
importHubName, importNamespace, importName))
@@ -390,13 +400,15 @@ func policiesToRoutes(hubInterface HubInterface, policies []*v1alpha2.RoutePolic
390400
Name: importName,
391401
Namespace: importNamespace,
392402
},
403+
Ports: ports,
393404
},
394405
Export: v1alpha2.RouteSpecRule{
395406
HubName: exportHubName,
396407
Service: v1alpha2.RouteSpecRuleService{
397408
Name: exportName,
398409
Namespace: exportNamespace,
399410
},
411+
Ports: ports,
400412
},
401413
},
402414
})

pkg/ferryctl/control_plane/init_crd.yaml

+34
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,23 @@ spec:
554554
hubName:
555555
description: HubName is specifies the name of the Hub
556556
type: string
557+
ports:
558+
description: The list of ports that are exposed by export service.
559+
items:
560+
description: RouteSpecRulePort contains information on service's
561+
port.
562+
properties:
563+
name:
564+
description: The name of this port within the service.
565+
type: string
566+
port:
567+
description: The port that will be exposed by this service.
568+
format: int32
569+
type: integer
570+
required:
571+
- port
572+
type: object
573+
type: array
557574
service:
558575
description: Service is the service
559576
properties:
@@ -577,6 +594,23 @@ spec:
577594
hubName:
578595
description: HubName is specifies the name of the Hub
579596
type: string
597+
ports:
598+
description: The list of ports that are exposed by export service.
599+
items:
600+
description: RouteSpecRulePort contains information on service's
601+
port.
602+
properties:
603+
name:
604+
description: The name of this port within the service.
605+
type: string
606+
port:
607+
description: The port that will be exposed by this service.
608+
format: int32
609+
type: integer
610+
required:
611+
- port
612+
type: object
613+
type: array
580614
service:
581615
description: Service is the service
582616
properties:

pkg/router/manual.go

+10-24
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package router
1919
import (
2020
"github.com/ferryproxy/api/apis/traffic/v1alpha2"
2121
"github.com/ferryproxy/ferry/pkg/utils/objref"
22-
corev1 "k8s.io/api/core/v1"
2322
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2423
)
2524

@@ -86,29 +85,6 @@ func (f *dateSource) GetPortPeer(importHubName string, cluster, namespace, name
8685
return f.bindPort, nil
8786
}
8887

89-
func (f *dateSource) ListServices(name string) []*corev1.Service {
90-
if name != f.exportHubName {
91-
return nil
92-
}
93-
svc := &corev1.Service{
94-
95-
ObjectMeta: metav1.ObjectMeta{
96-
Name: f.exportName,
97-
Namespace: f.exportNamespace,
98-
},
99-
Spec: corev1.ServiceSpec{
100-
Ports: []corev1.ServicePort{
101-
{
102-
Port: f.port,
103-
Protocol: corev1.ProtocolTCP,
104-
},
105-
},
106-
},
107-
}
108-
return []*corev1.Service{
109-
svc,
110-
}
111-
}
11288
func (f *dateSource) GetHubGateway(hubName string, forHub string) v1alpha2.HubSpecGateway {
11389
if hubName == f.importHubName {
11490
return f.importGateway
@@ -156,13 +132,23 @@ func (f *Manual) BuildResource() (out map[string][]objref.KMetadata, err error)
156132
Name: f.dateSource.importName,
157133
Namespace: f.dateSource.importNamespace,
158134
},
135+
Ports: []v1alpha2.RouteSpecRulePort{
136+
{
137+
Port: f.dateSource.port,
138+
},
139+
},
159140
},
160141
Export: v1alpha2.RouteSpecRule{
161142
HubName: f.dateSource.exportHubName,
162143
Service: v1alpha2.RouteSpecRuleService{
163144
Name: f.dateSource.exportName,
164145
Namespace: f.dateSource.exportNamespace,
165146
},
147+
Ports: []v1alpha2.RouteSpecRulePort{
148+
{
149+
Port: f.dateSource.port,
150+
},
151+
},
166152
},
167153
},
168154
},

0 commit comments

Comments
 (0)