Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

Update gateways to support private IPs #137

Merged
merged 5 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 0 additions & 1 deletion deployer/deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/hex"
"encoding/json"
"log"
"os"
"testing"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add os


"github.com/golang/mock/gomock"
Expand Down
2 changes: 2 additions & 0 deletions deployer/gateway_fqdn_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,15 @@ func (d *GatewayFQDNDeployer) Sync(ctx context.Context, gw *workloads.GatewayFQD
gw.Name = gwWorkload.Name
gw.FQDN = gwWorkload.FQDN
gw.TLSPassthrough = gwWorkload.TLSPassthrough
gw.Network = gwWorkload.Network

if wl != nil && wl.Result.State.IsOkay() {
gwWorkload, err := workloads.NewGatewayFQDNProxyFromZosWorkload(*wl.Workload)
gw.Backends = gwWorkload.Backends
gw.Name = gwWorkload.Name
gw.FQDN = gwWorkload.FQDN
gw.TLSPassthrough = gwWorkload.TLSPassthrough
gw.Network = gwWorkload.Network

if err != nil {
return err
Expand Down
8 changes: 5 additions & 3 deletions deployer/gateway_fqdn_deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@ func TestGenerateFQDNDeployment(t *testing.T) {
Type: zos.GatewayFQDNProxyType,
Name: gridtypes.Name(gw.Name),
Data: gridtypes.MustMarshal(zos.GatewayFQDNProxy{
TLSPassthrough: gw.TLSPassthrough,
Backends: gw.Backends,
FQDN: gw.FQDN,
GatewayBase: zos.GatewayBase{
TLSPassthrough: gw.TLSPassthrough,
Backends: gw.Backends,
},
FQDN: gw.FQDN,
}),
},
})
Expand Down
4 changes: 4 additions & 0 deletions deployer/gateway_name_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,17 @@ func (d *GatewayNameDeployer) Sync(ctx context.Context, gw *workloads.GatewayNam
gw.Name = gwWorkload.Name
gw.FQDN = gwWorkload.FQDN
gw.TLSPassthrough = gwWorkload.TLSPassthrough
gw.Network = gwWorkload.Network

// if the node acknowledges it, we are golden
if wl != nil && wl.Result.State.IsOkay() {
gwWorkload, err := workloads.NewGatewayNameProxyFromZosWorkload(*wl.Workload)
gw.Backends = gwWorkload.Backends
gw.Name = gwWorkload.Name
gw.FQDN = gwWorkload.FQDN
gw.TLSPassthrough = gwWorkload.TLSPassthrough
gw.Network = gwWorkload.Network

if err != nil {
return err
}
Expand Down
8 changes: 5 additions & 3 deletions deployer/gateway_name_deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ func TestNameGenerateDeployment(t *testing.T) {
Type: zos.GatewayNameProxyType,
Name: gridtypes.Name(g.Name),
Data: gridtypes.MustMarshal(zos.GatewayNameProxy{
TLSPassthrough: g.TLSPassthrough,
Backends: g.Backends,
Name: g.Name,
GatewayBase: zos.GatewayBase{
TLSPassthrough: g.TLSPassthrough,
Backends: g.Backends,
},
Name: g.Name,
}),
},
})
Expand Down
16 changes: 10 additions & 6 deletions deployer/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ func TestLoadGatewayFQDNFromGrid(t *testing.T) {
Type: zos.GatewayFQDNProxyType,
Name: gridtypes.Name("test"),
Data: gridtypes.MustMarshal(zos.GatewayFQDNProxy{
TLSPassthrough: true,
Backends: []zos.Backend{"http://1.1.1.1"},
FQDN: "test",
GatewayBase: zos.GatewayBase{
TLSPassthrough: true,
Backends: []zos.Backend{"http://1.1.1.1"},
},
FQDN: "test",
}),
}
gateway := workloads.GatewayFQDNProxy{
Expand Down Expand Up @@ -159,9 +161,11 @@ func TestLoadGatewayNameFromGrid(t *testing.T) {
Type: zos.GatewayNameProxyType,
Name: gridtypes.Name("test"),
Data: gridtypes.MustMarshal(zos.GatewayNameProxy{
Name: "test",
TLSPassthrough: true,
Backends: []zos.Backend{"http://1.1.1.1"},
GatewayBase: zos.GatewayBase{
TLSPassthrough: true,
Backends: []zos.Backend{"http://1.1.1.1"},
},
Name: "test",
}),
Result: gridtypes.Result{
Created: 1000,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/threefoldtech/grid_proxy_server v1.6.12
github.com/threefoldtech/rmb-sdk-go v1.0.1-0.20230308130815-83a645307186
github.com/threefoldtech/substrate-client v0.1.3
github.com/threefoldtech/zos v0.5.6-0.20230224113017-e887a6ca3fc5
github.com/threefoldtech/zos v0.5.6-0.20230321103809-44426c1a69c7
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20200609130330-bd2cb7843e1b
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ github.com/threefoldtech/substrate-client v0.1.3 h1:TezGOZ4sb7hFje9lt7uzl0IM3LYm
github.com/threefoldtech/substrate-client v0.1.3/go.mod h1:ys/GJLeLmNX8E36UFMeR0yZC5Lo4PufYtfwsVX8H/AM=
github.com/threefoldtech/zos v0.5.6-0.20230224113017-e887a6ca3fc5 h1:Ts+CsUnEujm2nVLEPQ6aG+pF0oYdUByPM9vijo6mjjM=
github.com/threefoldtech/zos v0.5.6-0.20230224113017-e887a6ca3fc5/go.mod h1:l+VG8dujgdsmqQlfmgTtev8n7as5FImMbYZHQN9TtXU=
github.com/threefoldtech/zos v0.5.6-0.20230321103809-44426c1a69c7 h1:L6L9Nxwl5yqoLM956FQ+NGxBLLTgFMWlw5xIFXb2k/Y=
github.com/threefoldtech/zos v0.5.6-0.20230321103809-44426c1a69c7/go.mod h1:l+VG8dujgdsmqQlfmgTtev8n7as5FImMbYZHQN9TtXU=
github.com/tinylib/msgp v1.0.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE=
github.com/tklauser/go-sysconf v0.3.5/go.mod h1:MkWzOF4RMCshBAMXuhXJs64Rte09mITnppBXY/rYEFI=
github.com/tklauser/go-sysconf v0.3.9 h1:JeUVdAOWhhxVcU6Eqr/ATFHgXk/mmiItdKeJPev3vTo=
Expand Down
1 change: 0 additions & 1 deletion integration_tests/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/pem"
"log"
"net"
"os"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add os

"time"

"github.com/pkg/errors"
Expand Down
30 changes: 22 additions & 8 deletions workloads/gateway_fqdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ type GatewayFQDNProxy struct {

// optional
// Passthrough whether to pass tls traffic or not
TLSPassthrough bool
Description string
NodeDeploymentID map[uint32]uint64
SolutionType string
TLSPassthrough bool
// Network name to join
Network string
Description string
SolutionType string

// computed
ContractID uint64
ContractID uint64
NodeDeploymentID map[uint32]uint64
}

// NewGatewayFQDNProxyFromZosWorkload generates a gateway FQDN proxy from a zos workload
Expand All @@ -43,26 +45,38 @@ func NewGatewayFQDNProxyFromZosWorkload(wl gridtypes.Workload) (GatewayFQDNProxy
if !ok {
return GatewayFQDNProxy{}, fmt.Errorf("could not create gateway fqdn proxy workload from data %v", dataI)
}
network := ""
if data.Network != nil {
network = data.Network.String()
}

return GatewayFQDNProxy{
Name: wl.Name.String(),
TLSPassthrough: data.TLSPassthrough,
Backends: data.Backends,
FQDN: data.FQDN,
Network: network,
}, nil
}

// ZosWorkload generates a zos workload from GatewayFQDNProxy
func (g *GatewayFQDNProxy) ZosWorkload() gridtypes.Workload {
network := (*gridtypes.Name)(&g.Network)
if g.Network == "" {
network = nil
}
return gridtypes.Workload{
Version: 0,
Type: zos.GatewayFQDNProxyType,
Name: gridtypes.Name(g.Name),
// REVISE: whether description should be set here
Data: gridtypes.MustMarshal(zos.GatewayFQDNProxy{
TLSPassthrough: g.TLSPassthrough,
Backends: g.Backends,
FQDN: g.FQDN,
GatewayBase: zos.GatewayBase{
TLSPassthrough: g.TLSPassthrough,
Backends: g.Backends,
Network: network,
},
FQDN: g.FQDN,
}),
}
}
Expand Down
24 changes: 19 additions & 5 deletions workloads/gateway_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ type GatewayNameProxy struct {
// Optional
// Passthrough whether to pass tls traffic or not
TLSPassthrough bool
Description string
SolutionType string
// Network name to join
Network string
Description string
SolutionType string

// computed
// FQDN deployed on the node
Expand Down Expand Up @@ -51,25 +53,37 @@ func NewGatewayNameProxyFromZosWorkload(wl gridtypes.Workload) (GatewayNameProxy
return GatewayNameProxy{}, fmt.Errorf("could not create gateway name proxy workload from data %v", dataI)
}

network := ""
if data.Network != nil {
network = data.Network.String()
}
return GatewayNameProxy{
Name: data.Name,
TLSPassthrough: data.TLSPassthrough,
Backends: data.Backends,
FQDN: result.FQDN,
Network: network,
}, nil
}

// ZosWorkload generates a zos workload from GatewayNameProxy
func (g *GatewayNameProxy) ZosWorkload() gridtypes.Workload {
network := (*gridtypes.Name)(&g.Network)
if g.Network == "" {
network = nil
}
return gridtypes.Workload{
Version: 0,
Type: zos.GatewayNameProxyType,
Name: gridtypes.Name(g.Name),
// REVISE: whether description should be set here
Data: gridtypes.MustMarshal(zos.GatewayNameProxy{
Name: g.Name,
TLSPassthrough: g.TLSPassthrough,
Backends: g.Backends,
GatewayBase: zos.GatewayBase{
TLSPassthrough: g.TLSPassthrough,
Backends: g.Backends,
Network: network,
},
Name: g.Name,
}),
}
}
Expand Down