Skip to content

Commit

Permalink
Fix linting issues
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Weinstock <[email protected]>
  • Loading branch information
jacobweinstock committed Oct 14, 2024
1 parent 0e7ddce commit 9b12f94
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cmd/smee/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func (c *config) dhcpHandler(ctx context.Context, log logr.Logger) (server.Handl
if _, err := url.Parse(httpScriptURL.String()); err != nil {
return nil, fmt.Errorf("invalid http ipxe script url: %w", err)
}
ipxeScript := func(d *dhcpv4.DHCPv4) *url.URL {
ipxeScript := func(*dhcpv4.DHCPv4) *url.URL {
return httpScriptURL
}
if c.dhcp.httpIpxeScript.injectMacAddress {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.22.0
toolchain go1.22.5

require (
github.com/ccoveille/go-safecast v1.1.0
github.com/fsnotify/fsnotify v1.7.0
github.com/ghodss/yaml v1.0.0
github.com/go-logr/logr v1.4.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/ccoveille/go-safecast v1.1.0 h1:iHKNWaZm+OznO7Eh6EljXPjGfGQsSfa6/sxPlIEKO+g=
github.com/ccoveille/go-safecast v1.1.0/go.mod h1:QqwNjxQ7DAqY0C721OIO9InMk9zCwcsO7tnRuHytad8=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
Expand Down
7 changes: 6 additions & 1 deletion internal/backend/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"
"sync"

"github.com/ccoveille/go-safecast"
"github.com/fsnotify/fsnotify"
"github.com/ghodss/yaml"
"github.com/go-logr/logr"
Expand Down Expand Up @@ -292,7 +293,11 @@ func (w *Watcher) translate(r dhcp) (*data.DHCP, *data.Netboot, error) {
d.VLANID = r.VLANID

// lease time
d.LeaseTime = uint32(r.LeaseTime)
// Default to one week
d.LeaseTime = 604800
if v, err := safecast.ToUint32(r.LeaseTime); err == nil {
d.LeaseTime = v
}

// arch
d.Arch = r.Arch
Expand Down
7 changes: 6 additions & 1 deletion internal/backend/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/netip"
"net/url"

"github.com/ccoveille/go-safecast"
"github.com/tinkerbell/smee/internal/dhcp/data"
"github.com/tinkerbell/tink/api/v1alpha1"
"go.opentelemetry.io/otel"
Expand Down Expand Up @@ -255,7 +256,11 @@ func toDHCPData(h *v1alpha1.DHCP) (*data.DHCP, error) {
d.Hostname = h.Hostname

// lease time required
d.LeaseTime = uint32(h.LeaseTime)
// Default to one week
d.LeaseTime = 604800
if v, err := safecast.ToUint32(d.LeaseTime); err == nil {
d.LeaseTime = v
}

// arch
d.Arch = h.Arch
Expand Down
20 changes: 10 additions & 10 deletions internal/backend/kube/kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ func TestNewBackend(t *testing.T) {
"no config": {shouldErr: true},
"failed index field": {shouldErr: true, conf: new(rest.Config), opt: func(o *cluster.Options) {
cl := fake.NewClientBuilder().Build()
o.NewClient = func(config *rest.Config, options client.Options) (client.Client, error) {
o.NewClient = func(*rest.Config, client.Options) (client.Client, error) {
return cl, nil
}
o.MapperProvider = func(c *rest.Config, httpClient *http.Client) (meta.RESTMapper, error) {
o.MapperProvider = func(*rest.Config, *http.Client) (meta.RESTMapper, error) {
return cl.RESTMapper(), nil
}
}},
Expand Down Expand Up @@ -217,7 +217,7 @@ func TestGetByIP(t *testing.T) {
if !tc.failToList {
ct = ct.WithScheme(rs)
ct = ct.WithRuntimeObjects(&v1alpha1.HardwareList{})
ct = ct.WithIndex(&v1alpha1.Hardware{}, IPAddrIndex, func(obj client.Object) []string {
ct = ct.WithIndex(&v1alpha1.Hardware{}, IPAddrIndex, func(client.Object) []string {
var list []string
for _, elem := range tc.hwObject {
list = append(list, elem.Spec.Interfaces[0].DHCP.IP.Address)
Expand All @@ -233,13 +233,13 @@ func TestGetByIP(t *testing.T) {
cl := ct.Build()

fn := func(o *cluster.Options) {
o.NewClient = func(config *rest.Config, options client.Options) (client.Client, error) {
o.NewClient = func(*rest.Config, client.Options) (client.Client, error) {
return cl, nil
}
o.MapperProvider = func(_ *rest.Config, _ *http.Client) (meta.RESTMapper, error) {
o.MapperProvider = func(*rest.Config, *http.Client) (meta.RESTMapper, error) {
return cl.RESTMapper(), nil
}
o.NewCache = func(config *rest.Config, options cache.Options) (cache.Cache, error) {
o.NewCache = func(*rest.Config, cache.Options) (cache.Cache, error) {
return &informertest.FakeInformers{Scheme: cl.Scheme()}, nil
}
}
Expand Down Expand Up @@ -315,7 +315,7 @@ func TestGetByMac(t *testing.T) {
if !tc.failToList {
ct = ct.WithScheme(rs)
ct = ct.WithRuntimeObjects(&v1alpha1.HardwareList{})
ct = ct.WithIndex(&v1alpha1.Hardware{}, MACAddrIndex, func(obj client.Object) []string {
ct = ct.WithIndex(&v1alpha1.Hardware{}, MACAddrIndex, func(client.Object) []string {
var list []string
for _, elem := range tc.hwObject {
list = append(list, elem.Spec.Interfaces[0].DHCP.MAC)
Expand All @@ -331,13 +331,13 @@ func TestGetByMac(t *testing.T) {
cl := ct.Build()

fn := func(o *cluster.Options) {
o.NewClient = func(config *rest.Config, options client.Options) (client.Client, error) {
o.NewClient = func(*rest.Config, client.Options) (client.Client, error) {
return cl, nil
}
o.MapperProvider = func(c *rest.Config, httpClient *http.Client) (meta.RESTMapper, error) {
o.MapperProvider = func(*rest.Config, *http.Client) (meta.RESTMapper, error) {
return cl.RESTMapper(), nil
}
o.NewCache = func(config *rest.Config, options cache.Options) (cache.Cache, error) {
o.NewCache = func(*rest.Config, cache.Options) (cache.Cache, error) {
return &informertest.FakeInformers{Scheme: cl.Scheme()}, nil
}
}
Expand Down
3 changes: 2 additions & 1 deletion internal/dhcp/dhcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dhcp
import (
"bytes"
"encoding/hex"
"errors"
"fmt"
"net"
"net/netip"
Expand Down Expand Up @@ -255,7 +256,7 @@ func IsNetbootClient(pkt *dhcpv4.DHCPv4) error {

func wrapNonNil(err error, format string) error {
if err == nil {
return fmt.Errorf(format)
return errors.New(format)
}

return fmt.Errorf("%w: %v", err, format)
Expand Down
2 changes: 1 addition & 1 deletion internal/ipxe/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (s *Config) ServeHTTP(ctx context.Context, addr string, handlers HandlerMap
}

func (s *Config) serveHealthchecker(rev string, start time.Time) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
return func(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "application/json")
res := struct {
GitRev string `json:"git_rev"`
Expand Down
4 changes: 2 additions & 2 deletions internal/ipxe/script/ipxe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestCustomScript(t *testing.T) {
t.Fatal(err)
}
if diff := cmp.Diff(tt.want, got); diff != "" {
t.Fatalf(diff)
t.Fatal(diff)
}
})
}
Expand Down Expand Up @@ -108,7 +108,7 @@ exit
}
if diff := cmp.Diff(tt.want, got); diff != "" {
t.Log(got)
t.Fatalf(diff)
t.Fatal(diff)
}
})
}
Expand Down

0 comments on commit 9b12f94

Please sign in to comment.