Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update api #142

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/ferryproxy/ferry
go 1.18

require (
github.com/ferryproxy/api v0.4.2
github.com/ferryproxy/api v0.4.3-0.20220929110018-87b27802e21a
github.com/ferryproxy/client-go v0.4.0
github.com/go-logr/logr v1.2.3
github.com/go-logr/zapr v1.2.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ github.com/evanphx/json-patch/v5 v5.0.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2Vvl
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ=
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/ferryproxy/api v0.4.2 h1:2SBq/ljIzL6TeyoiM3OjO0Bnx0J2f5g+CUjoLWWyano=
github.com/ferryproxy/api v0.4.2/go.mod h1:vFqYueEfIwpU2o3Y8/ryKKn5S3WBR4wVgHgh21zwpeQ=
github.com/ferryproxy/api v0.4.3-0.20220929110018-87b27802e21a h1:FwMc7CdF8u+EWEnJMiZXEeDu3pqsjSfLn65Iun6iuuE=
github.com/ferryproxy/api v0.4.3-0.20220929110018-87b27802e21a/go.mod h1:vFqYueEfIwpU2o3Y8/ryKKn5S3WBR4wVgHgh21zwpeQ=
github.com/ferryproxy/client-go v0.4.0 h1:pTlCUc7Q77d99yNru01WbKe8Ie8sBSpDO/h4ZmMW5gk=
github.com/ferryproxy/client-go v0.4.0/go.mod h1:A0DBMIJFYM4j+qvgHxTamZH3m56xfmuDnC+8E2gOtto=
github.com/flowstack/go-jsonschema v0.1.1/go.mod h1:yL7fNggx1o8rm9RlgXv7hTBWxdBM0rVwpMwimd3F3N0=
Expand Down
22 changes: 2 additions & 20 deletions pkg/controllers/route/mapping_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package route

import (
"context"
"fmt"
"strings"
"sync"
"time"
Expand All @@ -38,8 +37,6 @@ import (
)

type HubInterface interface {
GetService(hubName string, namespace, name string) (*corev1.Service, bool)
ListServices(name string) []*corev1.Service
GetHub(name string) *v1alpha2.Hub
GetHubGateway(hubName string, forHub string) v1alpha2.HubSpecGateway
GetAuthorized(name string) string
Expand Down Expand Up @@ -420,15 +417,7 @@ func (m *MappingController) Close() {
}

func (m *MappingController) updatePort(f *v1alpha2.Route) error {
svc, ok := m.hubInterface.GetService(f.Spec.Export.HubName, f.Spec.Export.Service.Namespace, f.Spec.Export.Service.Name)
if !ok {
return fmt.Errorf("not found export service")
}

for _, port := range svc.Spec.Ports {
if port.Protocol != corev1.ProtocolTCP {
continue
}
for _, port := range f.Spec.Import.Ports {
_, err := m.hubInterface.GetPortPeer(f.Spec.Import.HubName,
f.Spec.Export.HubName, f.Spec.Export.Service.Namespace, f.Spec.Export.Service.Name, port.Port)
if err != nil {
Expand All @@ -439,14 +428,7 @@ func (m *MappingController) updatePort(f *v1alpha2.Route) error {
}

func (m *MappingController) deletePort(f *v1alpha2.Route) error {
svc, ok := m.hubInterface.GetService(f.Spec.Export.HubName, f.Spec.Export.Service.Namespace, f.Spec.Export.Service.Name)
if !ok {
return fmt.Errorf("not found export service")
}
for _, port := range svc.Spec.Ports {
if port.Protocol != corev1.ProtocolTCP {
continue
}
for _, port := range f.Spec.Import.Ports {
_, err := m.hubInterface.DeletePortPeer(f.Spec.Import.HubName,
f.Spec.Export.HubName, f.Spec.Export.Service.Namespace, f.Spec.Export.Service.Name, port.Port)
if err == nil {
Expand Down
12 changes: 12 additions & 0 deletions pkg/controllers/route_policy/mirror_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,25 @@ func buildMirrorTunnelRoute(hub *v1alpha2.Hub, importHubName string) *v1alpha2.R
Namespace: "ferry-tunnel-system",
Name: "ferry-tunnel",
},
Ports: []v1alpha2.RouteSpecRulePort{
{
Name: "http",
Port: 8080,
},
},
},
Import: v1alpha2.RouteSpecRule{
HubName: importHubName,
Service: v1alpha2.RouteSpecRuleService{
Namespace: "ferry-tunnel-system",
Name: hub.Name + "-ferry-tunnel",
},
Ports: []v1alpha2.RouteSpecRulePort{
{
Name: "http",
Port: 8080,
},
},
},
},
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/controllers/route_policy/route_policy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,16 @@ func policiesToRoutes(hubInterface HubInterface, policies []*v1alpha2.RoutePolic

policy := match.Policy

var ports []v1alpha2.RouteSpecRulePort
for _, port := range svc.Spec.Ports {
if port.Protocol == "" || port.Protocol == corev1.ProtocolTCP {
ports = append(ports, v1alpha2.RouteSpecRulePort{
Name: port.Name,
Port: port.Port,
})
}
}

suffix := hash(fmt.Sprintf("%s|%s|%s|%s|%s|%s",
exportHubName, exportNamespace, exportName,
importHubName, importNamespace, importName))
Expand All @@ -390,13 +400,15 @@ func policiesToRoutes(hubInterface HubInterface, policies []*v1alpha2.RoutePolic
Name: importName,
Namespace: importNamespace,
},
Ports: ports,
},
Export: v1alpha2.RouteSpecRule{
HubName: exportHubName,
Service: v1alpha2.RouteSpecRuleService{
Name: exportName,
Namespace: exportNamespace,
},
Ports: ports,
},
},
})
Expand Down
34 changes: 34 additions & 0 deletions pkg/ferryctl/control_plane/init_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,23 @@ spec:
hubName:
description: HubName is specifies the name of the Hub
type: string
ports:
description: The list of ports that are exposed by export service.
items:
description: RouteSpecRulePort contains information on service's
port.
properties:
name:
description: The name of this port within the service.
type: string
port:
description: The port that will be exposed by this service.
format: int32
type: integer
required:
- port
type: object
type: array
service:
description: Service is the service
properties:
Expand All @@ -577,6 +594,23 @@ spec:
hubName:
description: HubName is specifies the name of the Hub
type: string
ports:
description: The list of ports that are exposed by export service.
items:
description: RouteSpecRulePort contains information on service's
port.
properties:
name:
description: The name of this port within the service.
type: string
port:
description: The port that will be exposed by this service.
format: int32
type: integer
required:
- port
type: object
type: array
service:
description: Service is the service
properties:
Expand Down
34 changes: 10 additions & 24 deletions pkg/router/manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package router
import (
"github.com/ferryproxy/api/apis/traffic/v1alpha2"
"github.com/ferryproxy/ferry/pkg/utils/objref"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

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

func (f *dateSource) ListServices(name string) []*corev1.Service {
if name != f.exportHubName {
return nil
}
svc := &corev1.Service{

ObjectMeta: metav1.ObjectMeta{
Name: f.exportName,
Namespace: f.exportNamespace,
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
{
Port: f.port,
Protocol: corev1.ProtocolTCP,
},
},
},
}
return []*corev1.Service{
svc,
}
}
func (f *dateSource) GetHubGateway(hubName string, forHub string) v1alpha2.HubSpecGateway {
if hubName == f.importHubName {
return f.importGateway
Expand Down Expand Up @@ -156,13 +132,23 @@ func (f *Manual) BuildResource() (out map[string][]objref.KMetadata, err error)
Name: f.dateSource.importName,
Namespace: f.dateSource.importNamespace,
},
Ports: []v1alpha2.RouteSpecRulePort{
{
Port: f.dateSource.port,
},
},
},
Export: v1alpha2.RouteSpecRule{
HubName: f.dateSource.exportHubName,
Service: v1alpha2.RouteSpecRuleService{
Name: f.dateSource.exportName,
Namespace: f.dateSource.exportNamespace,
},
Ports: []v1alpha2.RouteSpecRulePort{
{
Port: f.dateSource.port,
},
},
},
},
},
Expand Down
Loading