Skip to content

Commit

Permalink
Fix golangcilint
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
  • Loading branch information
kradalby committed Oct 18, 2022
1 parent 8502a0a commit 12ee9bc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 deletions.
2 changes: 1 addition & 1 deletion integration/general_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestPingAll(t *testing.T) {
allClients = append(allClients, clients...)
}

scenario.WaitForTailscaleSync()
err = scenario.WaitForTailscaleSync()
if err != nil {
t.Errorf("failed wait for tailscale clients to be in sync: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion integration/hsic/hsic.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (t *HeadscaleInContainer) WaitForReady() error {
log.Printf("waiting for headscale to be ready at %s", url)

return t.pool.Retry(func() error {
resp, err := http.Get(url)
resp, err := http.Get(url) //nolint
if err != nil {
return fmt.Errorf("headscale is not ready: %w", err)
}
Expand Down
49 changes: 26 additions & 23 deletions integration/scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
)

const scenarioHashLength = 6
const maxWait = 60 * time.Second
const headscalePort = 8080

var (
errNoHeadscaleAvailable = errors.New("no headscale available")
Expand Down Expand Up @@ -75,7 +77,7 @@ func NewScenario() (*Scenario, error) {
return nil, fmt.Errorf("could not connect to docker: %w", err)
}

pool.MaxWait = 60 * time.Second
pool.MaxWait = maxWait

networkName := fmt.Sprintf("hs-%s", hash)
if overrideNetworkName := os.Getenv("HEADSCALE_TEST_NETWORK_NAME"); overrideNetworkName != "" {
Expand Down Expand Up @@ -139,7 +141,7 @@ func (s *Scenario) Shutdown() error {

// TODO(kradalby): make port and headscale configurable, multiple instances support?
func (s *Scenario) StartHeadscale() error {
headscale, err := hsic.New(s.pool, 8080, s.network)
headscale, err := hsic.New(s.pool, headscalePort, s.network)
if err != nil {
return fmt.Errorf("failed to create headscale container: %w", err)
}
Expand All @@ -150,6 +152,7 @@ func (s *Scenario) StartHeadscale() error {
}

func (s *Scenario) Headscale() *hsic.HeadscaleInContainer {
//nolint
return s.controlServers["headscale"].(*hsic.HeadscaleInContainer)
}

Expand Down Expand Up @@ -186,33 +189,33 @@ func (s *Scenario) CreateNamespace(namespace string) error {
/// Client related stuff

func (s *Scenario) CreateTailscaleNodesInNamespace(
namespace string,
namespaceStr string,
requestedVersion string,
count int,
) error {
if ns, ok := s.namespaces[namespace]; ok {
if namespace, ok := s.namespaces[namespaceStr]; ok {
for i := 0; i < count; i++ {
version := requestedVersion
if requestedVersion == "all" {
version = TailscaleVersions[i%len(TailscaleVersions)]
}

ns.createWaitGroup.Add(1)
namespace.createWaitGroup.Add(1)

go func() {
defer ns.createWaitGroup.Done()
defer namespace.createWaitGroup.Done()

// TODO(kradalby): error handle this
ts, err := tsic.New(s.pool, version, s.network)
tsClient, err := tsic.New(s.pool, version, s.network)
if err != nil {
// return fmt.Errorf("failed to add tailscale node: %w", err)
fmt.Printf("failed to add tailscale node: %s", err)
log.Printf("failed to add tailscale node: %s", err)
}

ns.Clients[ts.Hostname] = ts
namespace.Clients[tsClient.Hostname] = tsClient
}()
}
ns.createWaitGroup.Wait()
namespace.createWaitGroup.Wait()

return nil
}
Expand All @@ -221,20 +224,20 @@ func (s *Scenario) CreateTailscaleNodesInNamespace(
}

func (s *Scenario) RunTailscaleUp(
namespace, loginServer, authKey string,
namespaceStr, loginServer, authKey string,
) error {
if ns, ok := s.namespaces[namespace]; ok {
for _, client := range ns.Clients {
ns.joinWaitGroup.Add(1)
if namespace, ok := s.namespaces[namespaceStr]; ok {
for _, client := range namespace.Clients {
namespace.joinWaitGroup.Add(1)

go func(c *tsic.TailscaleInContainer) {
defer ns.joinWaitGroup.Done()
defer namespace.joinWaitGroup.Done()

// TODO(kradalby): error handle this
_ = c.Up(loginServer, authKey)
}(client)
}
ns.joinWaitGroup.Wait()
namespace.joinWaitGroup.Wait()

return nil
}
Expand All @@ -245,8 +248,8 @@ func (s *Scenario) RunTailscaleUp(
func (s *Scenario) CountTailscale() int {
count := 0

for _, ns := range s.namespaces {
count += len(ns.Clients)
for _, namespace := range s.namespaces {
count += len(namespace.Clients)
}

return count
Expand All @@ -255,18 +258,18 @@ func (s *Scenario) CountTailscale() int {
func (s *Scenario) WaitForTailscaleSync() error {
tsCount := s.CountTailscale()

for _, ns := range s.namespaces {
for _, client := range ns.Clients {
ns.syncWaitGroup.Add(1)
for _, namespace := range s.namespaces {
for _, client := range namespace.Clients {
namespace.syncWaitGroup.Add(1)

go func(c *tsic.TailscaleInContainer) {
defer ns.syncWaitGroup.Done()
defer namespace.syncWaitGroup.Done()

// TODO(kradalby): error handle this
_ = c.WaitForPeers(tsCount)
}(client)
}
ns.syncWaitGroup.Wait()
namespace.syncWaitGroup.Wait()
}

return nil
Expand Down
12 changes: 5 additions & 7 deletions integration/tsic/tsic.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ const (
)

var (
errTailscalePingFailed = errors.New("ping failed")
errTailscaleNotLoggedIn = errors.New("tailscale not logged in")
errTailscalePingFailed = errors.New("ping failed")
errTailscaleNotLoggedIn = errors.New("tailscale not logged in")
errTailscaleWrongPeerCount = errors.New("wrong peer count")
)

type TailscaleInContainer struct {
Expand Down Expand Up @@ -207,11 +208,7 @@ func (t *TailscaleInContainer) WaitForPeers(expected int) error {
}

if peers := status.Peers(); len(peers) != expected {
return fmt.Errorf(
"tailscale client does not have the expected clients: %d out of %d",
len(peers),
expected,
)
return errTailscaleWrongPeerCount
}

return nil
Expand Down Expand Up @@ -241,6 +238,7 @@ func (t *TailscaleInContainer) Ping(ip netip.Addr) error {
ip.String(),
err,
)

return err
}

Expand Down

0 comments on commit 12ee9bc

Please sign in to comment.