Skip to content

Commit

Permalink
Remove unused params or returns
Browse files Browse the repository at this point in the history
  • Loading branch information
kradalby committed Nov 14, 2021
1 parent 19cd7a4 commit c9c16c7
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 35 deletions.
5 changes: 2 additions & 3 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,20 @@ linters:
- testpackage
- stylecheck
- wrapcheck
- paralleltest
- ifshort
- gomnd
- goerr113
- errorlint
- forcetypeassert
- errname
- unparam
- makezero
- gosec
- gocritic
- forbidigo
- dupl
- goconst
- varnamelen
- makezero
- paralleltest

# We might want to enable this, but it might be a lot of work
- cyclop
Expand Down
11 changes: 1 addition & 10 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,20 +319,12 @@ func (h *Headscale) getMapResponse(
return nil, err
}

dnsConfig, err := getMapResponseDNSConfig(
dnsConfig := getMapResponseDNSConfig(
h.cfg.DNSConfig,
h.cfg.BaseDomain,
*m,
peers,
)
if err != nil {
log.Error().
Str("func", "getMapResponse").
Err(err).
Msg("Failed generate the DNSConfig")

return nil, err
}

resp := tailcfg.MapResponse{
KeepAlive: false,
Expand Down Expand Up @@ -378,7 +370,6 @@ func (h *Headscale) getMapResponse(
func (h *Headscale) getMapKeepAliveResponse(
mKey wgkey.Key,
req tailcfg.MapRequest,
m *Machine,
) ([]byte, error) {
resp := tailcfg.MapResponse{
KeepAlive: true,
Expand Down
6 changes: 1 addition & 5 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,9 @@ func NewHeadscale(cfg Config) (*Headscale, error) {
}

if h.cfg.DNSConfig != nil && h.cfg.DNSConfig.Proxied { // if MagicDNS
magicDNSDomains, err := generateMagicDNSRootDomains(
magicDNSDomains := generateMagicDNSRootDomains(
h.cfg.IPPrefix,
h.cfg.BaseDomain,
)
if err != nil {
return nil, err
}
// we might have routes already from Split DNS
if h.cfg.DNSConfig.Routes == nil {
h.cfg.DNSConfig.Routes = make(map[string][]dnstype.Resolver)
Expand Down
5 changes: 2 additions & 3 deletions cmd/headscale/cli/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ var deleteNodeCmd = &cobra.Command{

func sharingWorker(
cmd *cobra.Command,
args []string,
) (string, *v1.Machine, *v1.Namespace, error) {
output, _ := cmd.Flags().GetString("output")
namespaceStr, err := cmd.Flags().GetString("namespace")
Expand Down Expand Up @@ -324,7 +323,7 @@ var shareMachineCmd = &cobra.Command{
Use: "share",
Short: "Shares a node from the current namespace to the specified one",
Run: func(cmd *cobra.Command, args []string) {
output, machine, namespace, err := sharingWorker(cmd, args)
output, machine, namespace, err := sharingWorker(cmd)
if err != nil {
ErrorOutput(
err,
Expand Down Expand Up @@ -363,7 +362,7 @@ var unshareMachineCmd = &cobra.Command{
Use: "unshare",
Short: "Unshares a node from the specified namespace",
Run: func(cmd *cobra.Command, args []string) {
output, machine, namespace, err := sharingWorker(cmd, args)
output, machine, namespace, err := sharingWorker(cmd)
if err != nil {
ErrorOutput(
err,
Expand Down
9 changes: 4 additions & 5 deletions dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ import (
// This allows us to then calculate the subnets included in the subsequent class block and generate the entries.
func generateMagicDNSRootDomains(
ipPrefix netaddr.IPPrefix,
baseDomain string,
) ([]dnsname.FQDN, error) {
) []dnsname.FQDN {
// TODO(juanfont): we are not handing out IPv6 addresses yet
// and in fact this is Tailscale.com's range (note the fd7a:115c:a1e0: range in the fc00::/7 network)
ipv6base := dnsname.FQDN("0.e.1.a.c.5.1.1.a.7.d.f.ip6.arpa.")
Expand Down Expand Up @@ -70,15 +69,15 @@ func generateMagicDNSRootDomains(
fqdns = append(fqdns, fqdn)
}

return fqdns, nil
return fqdns
}

func getMapResponseDNSConfig(
dnsConfigOrig *tailcfg.DNSConfig,
baseDomain string,
m Machine,
peers Machines,
) (*tailcfg.DNSConfig, error) {
) *tailcfg.DNSConfig {
var dnsConfig *tailcfg.DNSConfig
if dnsConfigOrig != nil && dnsConfigOrig.Proxied { // if MagicDNS is enabled
// Only inject the Search Domain of the current namespace - shared nodes should use their full FQDN
Expand All @@ -101,5 +100,5 @@ func getMapResponseDNSConfig(
dnsConfig = dnsConfigOrig
}

return dnsConfig, nil
return dnsConfig
}
12 changes: 4 additions & 8 deletions dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (

func (s *Suite) TestMagicDNSRootDomains100(c *check.C) {
prefix := netaddr.MustParseIPPrefix("100.64.0.0/10")
domains, err := generateMagicDNSRootDomains(prefix, "foobar.headscale.net")
c.Assert(err, check.IsNil)
domains := generateMagicDNSRootDomains(prefix)

found := false
for _, domain := range domains {
Expand Down Expand Up @@ -47,8 +46,7 @@ func (s *Suite) TestMagicDNSRootDomains100(c *check.C) {

func (s *Suite) TestMagicDNSRootDomains172(c *check.C) {
prefix := netaddr.MustParseIPPrefix("172.16.0.0/16")
domains, err := generateMagicDNSRootDomains(prefix, "headscale.net")
c.Assert(err, check.IsNil)
domains := generateMagicDNSRootDomains(prefix)

found := false
for _, domain := range domains {
Expand Down Expand Up @@ -178,8 +176,7 @@ func (s *Suite) TestDNSConfigMapResponseWithMagicDNS(c *check.C) {
m1peers, err := h.getPeers(m1)
c.Assert(err, check.IsNil)

dnsConfig, err := getMapResponseDNSConfig(&dnsConfigOrig, baseDomain, *m1, m1peers)
c.Assert(err, check.IsNil)
dnsConfig := getMapResponseDNSConfig(&dnsConfigOrig, baseDomain, *m1, m1peers)
c.Assert(dnsConfig, check.NotNil)
c.Assert(len(dnsConfig.Routes), check.Equals, 2)

Expand Down Expand Up @@ -303,8 +300,7 @@ func (s *Suite) TestDNSConfigMapResponseWithoutMagicDNS(c *check.C) {
m1peers, err := h.getPeers(m1)
c.Assert(err, check.IsNil)

dnsConfig, err := getMapResponseDNSConfig(&dnsConfigOrig, baseDomain, *m1, m1peers)
c.Assert(err, check.IsNil)
dnsConfig := getMapResponseDNSConfig(&dnsConfigOrig, baseDomain, *m1, m1peers)
c.Assert(dnsConfig, check.NotNil)
c.Assert(len(dnsConfig.Routes), check.Equals, 0)
c.Assert(len(dnsConfig.Domains), check.Equals, 1)
Expand Down
2 changes: 1 addition & 1 deletion poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ func (h *Headscale) scheduledPollWorker(
return

case <-keepAliveTicker.C:
data, err := h.getMapKeepAliveResponse(mKey, req, m)
data, err := h.getMapKeepAliveResponse(mKey, req)
if err != nil {
log.Error().
Str("func", "keepAlive").
Expand Down

0 comments on commit c9c16c7

Please sign in to comment.