mirror of
https://github.com/juanfont/headscale.git
synced 2025-05-23 01:15:27 +02:00
make Scenario.networks a list
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
586a20fbff
commit
f7f7b13faa
@ -743,7 +743,7 @@ func (s *AuthOIDCScenario) runMockOIDC(accessTTL time.Duration, users []mockoidc
|
|||||||
PortBindings: map[docker.Port][]docker.PortBinding{
|
PortBindings: map[docker.Port][]docker.PortBinding{
|
||||||
docker.Port(portNotation): {{HostPort: strconv.Itoa(port)}},
|
docker.Port(portNotation): {{HostPort: strconv.Itoa(port)}},
|
||||||
},
|
},
|
||||||
Networks: []*dockertest.Network{s.Scenario.network},
|
Networks: s.Scenario.networks,
|
||||||
Env: []string{
|
Env: []string{
|
||||||
fmt.Sprintf("MOCKOIDC_ADDR=%s", hostname),
|
fmt.Sprintf("MOCKOIDC_ADDR=%s", hostname),
|
||||||
fmt.Sprintf("MOCKOIDC_PORT=%d", port),
|
fmt.Sprintf("MOCKOIDC_PORT=%d", port),
|
||||||
@ -774,7 +774,7 @@ func (s *AuthOIDCScenario) runMockOIDC(accessTTL time.Duration, users []mockoidc
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Println("Waiting for headscale mock oidc to be ready for tests")
|
log.Println("Waiting for headscale mock oidc to be ready for tests")
|
||||||
hostEndpoint := fmt.Sprintf("%s:%d", s.mockOIDC.GetIPInNetwork(s.network), port)
|
hostEndpoint := fmt.Sprintf("%s:%d", hostname, port)
|
||||||
|
|
||||||
if err := s.pool.Retry(func() error {
|
if err := s.pool.Retry(func() error {
|
||||||
oidcConfigURL := fmt.Sprintf("http://%s/oidc/.well-known/openid-configuration", hostEndpoint)
|
oidcConfigURL := fmt.Sprintf("http://%s/oidc/.well-known/openid-configuration", hostEndpoint)
|
||||||
@ -803,7 +803,7 @@ func (s *AuthOIDCScenario) runMockOIDC(accessTTL time.Duration, users []mockoidc
|
|||||||
return &types.OIDCConfig{
|
return &types.OIDCConfig{
|
||||||
Issuer: fmt.Sprintf(
|
Issuer: fmt.Sprintf(
|
||||||
"http://%s/oidc",
|
"http://%s/oidc",
|
||||||
net.JoinHostPort(s.mockOIDC.GetIPInNetwork(s.network), strconv.Itoa(port)),
|
net.JoinHostPort(hostname, strconv.Itoa(port)),
|
||||||
),
|
),
|
||||||
ClientID: "superclient",
|
ClientID: "superclient",
|
||||||
ClientSecret: "supersecret",
|
ClientSecret: "supersecret",
|
||||||
|
@ -24,5 +24,4 @@ type ControlServer interface {
|
|||||||
ApproveRoutes(uint64, []netip.Prefix) (*v1.Node, error)
|
ApproveRoutes(uint64, []netip.Prefix) (*v1.Node, error)
|
||||||
GetCert() []byte
|
GetCert() []byte
|
||||||
GetHostname() string
|
GetHostname() string
|
||||||
GetIP() string
|
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ type DERPServerInContainer struct {
|
|||||||
|
|
||||||
pool *dockertest.Pool
|
pool *dockertest.Pool
|
||||||
container *dockertest.Resource
|
container *dockertest.Resource
|
||||||
network *dockertest.Network
|
networks []*dockertest.Network
|
||||||
|
|
||||||
stunPort int
|
stunPort int
|
||||||
derpPort int
|
derpPort int
|
||||||
@ -63,22 +63,22 @@ func WithCACert(cert []byte) Option {
|
|||||||
// isolating the DERPer, will be created. If a network is
|
// isolating the DERPer, will be created. If a network is
|
||||||
// passed, the DERPer instance will join the given network.
|
// passed, the DERPer instance will join the given network.
|
||||||
func WithOrCreateNetwork(network *dockertest.Network) Option {
|
func WithOrCreateNetwork(network *dockertest.Network) Option {
|
||||||
return func(tsic *DERPServerInContainer) {
|
return func(dsic *DERPServerInContainer) {
|
||||||
if network != nil {
|
if network != nil {
|
||||||
tsic.network = network
|
dsic.networks = append(dsic.networks, network)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
network, err := dockertestutil.GetFirstOrCreateNetwork(
|
network, err := dockertestutil.GetFirstOrCreateNetwork(
|
||||||
tsic.pool,
|
dsic.pool,
|
||||||
tsic.hostname+"-network",
|
dsic.hostname+"-network",
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to create network: %s", err)
|
log.Fatalf("failed to create network: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tsic.network = network
|
dsic.networks = append(dsic.networks, network)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ func WithExtraHosts(hosts []string) Option {
|
|||||||
func New(
|
func New(
|
||||||
pool *dockertest.Pool,
|
pool *dockertest.Pool,
|
||||||
version string,
|
version string,
|
||||||
network *dockertest.Network,
|
networks []*dockertest.Network,
|
||||||
opts ...Option,
|
opts ...Option,
|
||||||
) (*DERPServerInContainer, error) {
|
) (*DERPServerInContainer, error) {
|
||||||
hash, err := util.GenerateRandomStringDNSSafe(dsicHashLength)
|
hash, err := util.GenerateRandomStringDNSSafe(dsicHashLength)
|
||||||
@ -124,7 +124,7 @@ func New(
|
|||||||
version: version,
|
version: version,
|
||||||
hostname: hostname,
|
hostname: hostname,
|
||||||
pool: pool,
|
pool: pool,
|
||||||
network: network,
|
networks: networks,
|
||||||
tlsCert: tlsCert,
|
tlsCert: tlsCert,
|
||||||
tlsKey: tlsKey,
|
tlsKey: tlsKey,
|
||||||
stunPort: 3478, //nolint
|
stunPort: 3478, //nolint
|
||||||
@ -148,7 +148,7 @@ func New(
|
|||||||
|
|
||||||
runOptions := &dockertest.RunOptions{
|
runOptions := &dockertest.RunOptions{
|
||||||
Name: hostname,
|
Name: hostname,
|
||||||
Networks: []*dockertest.Network{dsic.network},
|
Networks: dsic.networks,
|
||||||
ExtraHosts: dsic.withExtraHosts,
|
ExtraHosts: dsic.withExtraHosts,
|
||||||
// we currently need to give us some time to inject the certificate further down.
|
// we currently need to give us some time to inject the certificate further down.
|
||||||
Entrypoint: []string{"/bin/sh", "-c", "/bin/sleep 3 ; update-ca-certificates ; derper " + cmdArgs.String()},
|
Entrypoint: []string{"/bin/sh", "-c", "/bin/sleep 3 ; update-ca-certificates ; derper " + cmdArgs.String()},
|
||||||
|
@ -210,7 +210,6 @@ func (s *EmbeddedDERPServerScenario) CreateHeadscaleEnv(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Printf("headscale server ip address: %s", hsServer.GetIP())
|
|
||||||
|
|
||||||
hash, err := util.GenerateRandomStringDNSSafe(scenarioHashLength)
|
hash, err := util.GenerateRandomStringDNSSafe(scenarioHashLength)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -56,7 +56,7 @@ type HeadscaleInContainer struct {
|
|||||||
|
|
||||||
pool *dockertest.Pool
|
pool *dockertest.Pool
|
||||||
container *dockertest.Resource
|
container *dockertest.Resource
|
||||||
network *dockertest.Network
|
networks []*dockertest.Network
|
||||||
|
|
||||||
pgContainer *dockertest.Resource
|
pgContainer *dockertest.Resource
|
||||||
|
|
||||||
@ -268,7 +268,7 @@ func WithTimezone(timezone string) Option {
|
|||||||
// New returns a new HeadscaleInContainer instance.
|
// New returns a new HeadscaleInContainer instance.
|
||||||
func New(
|
func New(
|
||||||
pool *dockertest.Pool,
|
pool *dockertest.Pool,
|
||||||
network *dockertest.Network,
|
networks []*dockertest.Network,
|
||||||
opts ...Option,
|
opts ...Option,
|
||||||
) (*HeadscaleInContainer, error) {
|
) (*HeadscaleInContainer, error) {
|
||||||
hash, err := util.GenerateRandomStringDNSSafe(hsicHashLength)
|
hash, err := util.GenerateRandomStringDNSSafe(hsicHashLength)
|
||||||
@ -282,8 +282,8 @@ func New(
|
|||||||
hostname: hostname,
|
hostname: hostname,
|
||||||
port: headscaleDefaultPort,
|
port: headscaleDefaultPort,
|
||||||
|
|
||||||
pool: pool,
|
pool: pool,
|
||||||
network: network,
|
networks: networks,
|
||||||
|
|
||||||
env: DefaultConfigEnv(),
|
env: DefaultConfigEnv(),
|
||||||
filesInContainer: []fileInContainer{},
|
filesInContainer: []fileInContainer{},
|
||||||
@ -315,7 +315,7 @@ func New(
|
|||||||
Name: fmt.Sprintf("postgres-%s", hash),
|
Name: fmt.Sprintf("postgres-%s", hash),
|
||||||
Repository: "postgres",
|
Repository: "postgres",
|
||||||
Tag: "latest",
|
Tag: "latest",
|
||||||
Networks: []*dockertest.Network{network},
|
Networks: networks,
|
||||||
Env: []string{
|
Env: []string{
|
||||||
"POSTGRES_USER=headscale",
|
"POSTGRES_USER=headscale",
|
||||||
"POSTGRES_PASSWORD=headscale",
|
"POSTGRES_PASSWORD=headscale",
|
||||||
@ -357,7 +357,7 @@ func New(
|
|||||||
runOptions := &dockertest.RunOptions{
|
runOptions := &dockertest.RunOptions{
|
||||||
Name: hsic.hostname,
|
Name: hsic.hostname,
|
||||||
ExposedPorts: append([]string{portProto, "9090/tcp"}, hsic.extraPorts...),
|
ExposedPorts: append([]string{portProto, "9090/tcp"}, hsic.extraPorts...),
|
||||||
Networks: []*dockertest.Network{network},
|
Networks: networks,
|
||||||
// Cmd: []string{"headscale", "serve"},
|
// Cmd: []string{"headscale", "serve"},
|
||||||
// TODO(kradalby): Get rid of this hack, we currently need to give us some
|
// TODO(kradalby): Get rid of this hack, we currently need to give us some
|
||||||
// to inject the headscale configuration further down.
|
// to inject the headscale configuration further down.
|
||||||
@ -630,11 +630,6 @@ func (t *HeadscaleInContainer) Execute(
|
|||||||
return stdout, nil
|
return stdout, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetIP returns the docker container IP as a string.
|
|
||||||
func (t *HeadscaleInContainer) GetIP() string {
|
|
||||||
return t.container.GetIPInNetwork(t.network)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPort returns the docker container port as a string.
|
// GetPort returns the docker container port as a string.
|
||||||
func (t *HeadscaleInContainer) GetPort() string {
|
func (t *HeadscaleInContainer) GetPort() string {
|
||||||
return fmt.Sprintf("%d", t.port)
|
return fmt.Sprintf("%d", t.port)
|
||||||
|
@ -86,8 +86,8 @@ type Scenario struct {
|
|||||||
|
|
||||||
users map[string]*User
|
users map[string]*User
|
||||||
|
|
||||||
pool *dockertest.Pool
|
pool *dockertest.Pool
|
||||||
network *dockertest.Network
|
networks []*dockertest.Network
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
@ -129,8 +129,8 @@ func NewScenario(maxWait time.Duration) (*Scenario, error) {
|
|||||||
controlServers: xsync.NewMapOf[string, ControlServer](),
|
controlServers: xsync.NewMapOf[string, ControlServer](),
|
||||||
users: make(map[string]*User),
|
users: make(map[string]*User),
|
||||||
|
|
||||||
pool: pool,
|
pool: pool,
|
||||||
network: network,
|
networks: []*dockertest.Network{network},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,14 +184,11 @@ func (s *Scenario) ShutdownAssertNoPanics(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.pool.RemoveNetwork(s.network); err != nil {
|
for _, network := range s.networks {
|
||||||
log.Printf("failed to remove network: %s", err)
|
if err := network.Close(); err != nil {
|
||||||
|
log.Printf("failed to tear down network: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(kradalby): This seem redundant to the previous call
|
|
||||||
// if err := s.network.Close(); err != nil {
|
|
||||||
// return fmt.Errorf("failed to tear down network: %w", err)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown shuts down and cleans up all the containers (ControlServer, TailscaleClient)
|
// Shutdown shuts down and cleans up all the containers (ControlServer, TailscaleClient)
|
||||||
@ -235,7 +232,7 @@ func (s *Scenario) Headscale(opts ...hsic.Option) (ControlServer, error) {
|
|||||||
opts = append(opts, hsic.WithPolicyV2())
|
opts = append(opts, hsic.WithPolicyV2())
|
||||||
}
|
}
|
||||||
|
|
||||||
headscale, err := hsic.New(s.pool, s.network, opts...)
|
headscale, err := hsic.New(s.pool, s.networks, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create headscale container: %w", err)
|
return nil, fmt.Errorf("failed to create headscale container: %w", err)
|
||||||
}
|
}
|
||||||
@ -312,7 +309,7 @@ func (s *Scenario) CreateTailscaleNode(
|
|||||||
tsClient, err := tsic.New(
|
tsClient, err := tsic.New(
|
||||||
s.pool,
|
s.pool,
|
||||||
version,
|
version,
|
||||||
s.network,
|
s.networks[0],
|
||||||
opts...,
|
opts...,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -372,7 +369,7 @@ func (s *Scenario) CreateTailscaleNodesInUser(
|
|||||||
tsClient, err := tsic.New(
|
tsClient, err := tsic.New(
|
||||||
s.pool,
|
s.pool,
|
||||||
version,
|
version,
|
||||||
s.network,
|
s.networks[0],
|
||||||
opts...,
|
opts...,
|
||||||
)
|
)
|
||||||
s.mu.Unlock()
|
s.mu.Unlock()
|
||||||
@ -670,7 +667,7 @@ func (s *Scenario) WaitForTailscaleLogout() error {
|
|||||||
|
|
||||||
// CreateDERPServer creates a new DERP server in a container.
|
// CreateDERPServer creates a new DERP server in a container.
|
||||||
func (s *Scenario) CreateDERPServer(version string, opts ...dsic.Option) (*dsic.DERPServerInContainer, error) {
|
func (s *Scenario) CreateDERPServer(version string, opts ...dsic.Option) (*dsic.DERPServerInContainer, error) {
|
||||||
derp, err := dsic.New(s.pool, version, s.network, opts...)
|
derp, err := dsic.New(s.pool, version, s.networks, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create DERP server: %w", err)
|
return nil, fmt.Errorf("failed to create DERP server: %w", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user