Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VLAN ID to hardware interface spec #642

Merged
merged 11 commits into from
Sep 16, 2022
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: "1.17"
go-version: "1.18.5"

- name: make verify
run: make verify
Expand All @@ -32,7 +32,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: "1.17"
go-version: "1.18.5"

- name: Install nix
uses: cachix/install-nix-action@v16
Expand Down Expand Up @@ -83,7 +83,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: "1.17"
go-version: "1.18.5"

- run: make crosscompile -j$(nproc)

Expand Down
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ linters-settings:
- name: waitgroup-by-value

staticcheck:
go: "1.17"
go: "1.18"

unused:
go: "1.17"
go: "1.18"

output:
sort-results: true
Expand Down
5 changes: 1 addition & 4 deletions buf.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@ deps:
- remote: buf.build
owner: googleapis
repository: googleapis
branch: main
commit: 389e82394fcc4e18b2463c26674170b3
digest: b1-j-IWUPcGJWMkqbee6hR7IJCXlLF9Y5P4ARue8gLwLP0=
create_time: 2021-10-01T15:05:49.20888Z
commit: 8d7204855ec14631a499bd7393ce1970
3 changes: 2 additions & 1 deletion client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
)

// gRPC clients.
Expand Down Expand Up @@ -40,7 +41,7 @@ func NewClientConn(authority string, tls bool) (*grpc.ClientConn, error) {
if tls {
creds = grpc.WithTransportCredentials(credentials.NewTLS(nil))
} else {
creds = grpc.WithInsecure()
creds = grpc.WithTransportCredentials(insecure.NewCredentials())
}

conn, err := grpc.Dial(authority,
Expand Down
2 changes: 1 addition & 1 deletion cmd/tink-cli/cmd/delete/delete.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package delete // nolint:predeclared // package name delete has same name as predeclared identifier
package delete //nolint:predeclared // package name delete has same name as predeclared identifier

import (
"context"
Expand Down
6 changes: 3 additions & 3 deletions cmd/tink-cli/cmd/delete/delete_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package delete // nolint:predeclared // package name delete has same name as predeclared identifier
package delete //nolint:predeclared // package name delete has same name as predeclared identifier

import (
"bytes"
"context"
"io/ioutil"
"io"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -86,7 +86,7 @@ func TestNewDeleteCommand(t *testing.T) {
if err != nil {
t.Error(err)
}
out, err := ioutil.ReadAll(stdout)
out, err := io.ReadAll(stdout)
if err != nil {
t.Error(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/tink-cli/cmd/delete/doc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package delete provides a reusable implementation of the Delete command
// for the tink cli. The Delete command deletes resources. It is designed
// to be extendible and usable across resources.
package delete // nolint:predeclared // package name delete has same name as predeclared identifier
package delete //nolint:predeclared // package name delete has same name as predeclared identifier
5 changes: 2 additions & 3 deletions cmd/tink-cli/cmd/docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cmd

import (
"bytes"
"io/ioutil"
"os"
"path"
"strings"
Expand Down Expand Up @@ -63,7 +62,7 @@ func Test_docsCmd(t *testing.T) {
cmdFunc: func(t *testing.T, c *cobra.Command) {
t.Helper()

dir, err := ioutil.TempDir("", "tink-test-*")
dir, err := os.MkdirTemp("", "tink-test-*")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -95,7 +94,7 @@ func Test_docsCmd(t *testing.T) {
cmdFunc: func(t *testing.T, c *cobra.Command) {
t.Helper()

dir, err := ioutil.TempDir("", "tink-test-*")
dir, err := os.MkdirTemp("", "tink-test-*")
if err != nil {
t.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/tink-cli/cmd/get/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -234,7 +233,7 @@ func TestNewGetCommand(t *testing.T) {
if fmt.Sprint(err) != fmt.Sprint(s.ExpectError) {
t.Errorf("unexpected error: want=%v, got=%v", s.ExpectError, err)
}
out, err := ioutil.ReadAll(stdout)
out, err := io.ReadAll(stdout)
if err != nil {
t.Error(err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/tink-cli/cmd/hardware/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"io"
"io/ioutil"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -101,7 +100,7 @@ func TestGetHardware(t *testing.T) {
if err != nil {
t.Error(err)
}
out, err := ioutil.ReadAll(stdout)
out, err := io.ReadAll(stdout)
if err != nil {
t.Error(err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/tink-cli/cmd/hardware/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -82,7 +82,7 @@ func isInputFromPipe() bool {
}

func readDataFromStdin() string {
data, err := ioutil.ReadAll(os.Stdin)
data, err := io.ReadAll(os.Stdin)
if err != nil {
return ""
}
Expand All @@ -96,7 +96,7 @@ func readDataFromFile() (string, error) {
}
defer f.Close()

data, err := ioutil.ReadAll(f)
data, err := io.ReadAll(f)
if err != nil {
return "", err
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/tink-cli/cmd/template/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -64,7 +63,7 @@ $ tink template create --file /tmp/example.tmpl
}

func readAll(reader io.Reader) []byte {
data, err := ioutil.ReadAll(reader)
data, err := io.ReadAll(reader)
if err != nil {
log.Fatal(err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/tink-cli/cmd/template/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"io"
"io/ioutil"
"testing"
"time"

Expand Down Expand Up @@ -76,7 +75,7 @@ func TestGetTemplate(t *testing.T) {
if err != nil {
t.Error(err)
}
out, err := ioutil.ReadAll(stdout)
out, err := io.ReadAll(stdout)
if err != nil {
t.Error(err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/tink-cli/cmd/template/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -94,7 +93,7 @@ func readTemplateData() (string, error) {
reader = f
}

data, err := ioutil.ReadAll(reader)
data, err := io.ReadAll(reader)
if err != nil {
return "", err
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/tink-worker/worker/container_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func (m *containerManager) getLogger(ctx context.Context) *log.Logger {
if loggerIface == nil {
return &m.logger
}
return loggerIface.(*log.Logger)
l, _ := loggerIface.(*log.Logger)

return l
}

// NewContainerManager returns a new container manager.
Expand Down Expand Up @@ -89,7 +91,7 @@ func (m *containerManager) StartContainer(ctx context.Context, id string) error
func (m *containerManager) WaitForContainer(ctx context.Context, id string) (pb.State, error) {
// Inspect whether the container is in running state
if _, err := m.cli.ContainerInspect(ctx, id); err != nil {
return pb.State_STATE_FAILED, nil // nolint:nilerr // error is not nil, but it returns nil
return pb.State_STATE_FAILED, nil //nolint:nilerr // error is not nil, but it returns nil
jacobweinstock marked this conversation as resolved.
Show resolved Hide resolved
}

// send API call to wait for the container completion
Expand Down
3 changes: 2 additions & 1 deletion cmd/tink-worker/worker/container_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ func newFakeDockerClient(containerID, imagePullContent string, delay time.Durati
}

func (c *fakeDockerClient) ContainerCreate(
context.Context, *containertypes.Config, *containertypes.HostConfig, *networktypes.NetworkingConfig, *specs.Platform, string) (containertypes.ContainerCreateCreatedBody, error) {
context.Context, *containertypes.Config, *containertypes.HostConfig, *networktypes.NetworkingConfig, *specs.Platform, string,
) (containertypes.ContainerCreateCreatedBody, error) {
if c.err != nil {
return containertypes.ContainerCreateCreatedBody{}, c.err
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/tink-worker/worker/log_capturer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ func (l *DockerLogCapturer) getLogger(ctx context.Context) *log.Logger {
if loggerIface == nil {
return &l.logger
}
return loggerIface.(*log.Logger)
lg, _ := loggerIface.(*log.Logger)

return lg
}

// NewDockerLogCapturer returns a LogCapturer that can stream container logs to a given writer.
Expand Down
13 changes: 8 additions & 5 deletions cmd/tink-worker/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -127,7 +127,8 @@ func NewWorker(
containerManager ContainerManager,
logCapturer LogCapturer,
logger log.Logger,
opts ...Option) *Worker {
opts ...Option,
) *Worker {
w := &Worker{
workerID: workerID,
dataDir: defaultDataDir,
Expand All @@ -154,7 +155,9 @@ func (w Worker) getLogger(ctx context.Context) *log.Logger {
if loggerIface == nil {
return &w.logger
}
return loggerIface.(*log.Logger)
l, _ := loggerIface.(*log.Logger)

return l
}

// execute executes a workflow action, optionally capturing logs.
Expand Down Expand Up @@ -400,7 +403,7 @@ func (w *Worker) ProcessWorkflowActions(ctx context.Context) error {
if len(actions.GetActionList()) == actionIndex+1 {
l.Info("reached to end of workflow")
delete(workflowcontexts, wfID)
turn = false // nolint:wastedassign // assigned to turn, but reassigned without using the value
turn = false
break
}

Expand Down Expand Up @@ -494,7 +497,7 @@ func (w *Worker) updateWorkflowData(ctx context.Context, actionStatus *pb.Workfl
}
}()

data, err := ioutil.ReadAll(f)
data, err := io.ReadAll(f)
if err != nil {
l.Error(err)
}
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/tinkerbell.org_hardware.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ spec:
type: array
uefi:
type: boolean
vlan_id:
description:
validation pattern for VLANDID is a string
number between 0-4096
pattern: ^(([0-9][0-9]{0,2}|[1-3][0-9][0-9][0-9]|40([0-8][0-9]|9[0-6]))(,[1-9][0-9]{0,2}|[1-3][0-9][0-9][0-9]|40([0-8][0-9]|9[0-6]))*)$
type: string
type: object
netboot:
description: Netboot configuration.
Expand Down
2 changes: 1 addition & 1 deletion db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func NewPostgresDatabaseClient(ctx context.Context, t *testing.T, req NewPostgre
if err != nil {
t.Error(err)
}
t.Log(fmt.Sprintf("applied %d migrations", n))
t.Logf("applied %d migrations", n)
}
return dbCon, tinkDB, func() error {
return postgresC.Terminate(ctx)
Expand Down
13 changes: 5 additions & 8 deletions db/hardware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -364,10 +364,8 @@ func TestGetByIP(t *testing.T) {
for ii := 0; ii < 10; ii++ {
hw := readHardwareData("./testdata/hardware.json")
hw.Id = uuid.New().String()
hw.Network.Interfaces[0].Dhcp.Ip.Address =
strings.Replace(hw.Network.Interfaces[0].Dhcp.Ip.Address, "1", fmt.Sprintf("%d", ii), 1)
hw.Network.Interfaces[0].Dhcp.Mac =
strings.Replace(hw.Network.Interfaces[0].Dhcp.Mac, "00", fmt.Sprintf("0%d", ii), 1)
hw.Network.Interfaces[0].Dhcp.Ip.Address = strings.Replace(hw.Network.Interfaces[0].Dhcp.Ip.Address, "1", fmt.Sprintf("%d", ii), 1)
hw.Network.Interfaces[0].Dhcp.Mac = strings.Replace(hw.Network.Interfaces[0].Dhcp.Mac, "00", fmt.Sprintf("0%d", ii), 1)
}
return input
}(),
Expand Down Expand Up @@ -477,8 +475,7 @@ func TestGetByMAC(t *testing.T) {
for ii := 0; ii < 10; ii++ {
hw := readHardwareData("./testdata/hardware.json")
hw.Id = uuid.New().String()
hw.Network.Interfaces[0].Dhcp.Mac =
strings.Replace(hw.Network.Interfaces[0].Dhcp.Mac, "00", fmt.Sprintf("0%d", ii), 1)
hw.Network.Interfaces[0].Dhcp.Mac = strings.Replace(hw.Network.Interfaces[0].Dhcp.Mac, "00", fmt.Sprintf("0%d", ii), 1)
}
return input
}(),
Expand Down Expand Up @@ -549,7 +546,7 @@ func TestGetByMAC_WithNonExistingMAC(t *testing.T) {
}

func readHardwareData(file string) *hardware.Hardware {
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err != nil {
panic(err)
}
Expand Down
Loading