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 Sep 19, 2024
1 parent b3b089f commit ca2f701
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 37 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ linters-settings:
- name: var-naming
- name: unconditional-recursion
- name: waitgroup-by-value
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#struct-tag
- name: struct-tag
arguments:
- "json,inline"
staticcheck:
go: "1.18"
unused:
Expand Down
2 changes: 1 addition & 1 deletion Tools.mk
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ KUSTOMIZE := $(TOOLS_DIR)/kustomize-$(KUSTOMIZE_VER)
SETUP_ENVTEST_VER := v0.0.0-20220304125252-9ee63fc65a97
SETUP_ENVTEST := $(TOOLS_DIR)/setup-envtest-$(SETUP_ENVTEST_VER)

GOLANGCI_LINT_VER := v1.52
GOLANGCI_LINT_VER := v1.61
GOLANGCI_LINT := $(TOOLS_DIR)/golangci-lint-$(GOLANGCI_LINT_VER)

YAMLFMT_VER := v0.6
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/workflow_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (w *Workflow) getTaskActionInfo() taskInfo {
INNER:
for ai, action := range task.Actions {
// Find the first non-successful action
switch action.Status {
switch action.Status { //nolint:exhaustive // WorkflowStatePreparing is only used in Workflows not Actions.
case WorkflowStateSuccess:
actionIndex++
continue
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/workflow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type Status struct {
// is no information available. A Reason clarifies an HTTP status
// code but does not override it.
// +optional
Reason metav1.StatusReason `json:"reason,omitempty" protobuf:"bytes,4,opt,name=reason,casttype=StatusReason"`
Reason metav1.StatusReason `json:"reason,omitempty" protobuf:"bytes,4,opt,name=reason"`
// Extended data associated with the reason. Each reason may define its
// own extended details. This field is optional and the data returned
// is not guaranteed to conform to any schema except that defined by
Expand Down
6 changes: 3 additions & 3 deletions cmd/tink-controller-v1alpha2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ func NewRootCommand() *cobra.Command {

cmd := &cobra.Command{
Use: "tink-controller",
PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {

Check warning on line 76 in cmd/tink-controller-v1alpha2/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/tink-controller-v1alpha2/main.go#L76

Added line #L76 was not covered by tests
viper, err := createViper(logger)
if err != nil {
return fmt.Errorf("config init: %w", err)
}
return applyViper(viper, cmd)
},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {

Check warning on line 83 in cmd/tink-controller-v1alpha2/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/tink-controller-v1alpha2/main.go#L83

Added line #L83 was not covered by tests
logger.Info("Starting controller version " + version)

ccfg := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
Expand Down Expand Up @@ -172,7 +172,7 @@ func applyViper(v *viper.Viper, cmd *cobra.Command) error {
for _, err := range errors {
errs = append(errs, err.Error())
}
return fmt.Errorf(strings.Join(errs, ", "))
return fmt.Errorf("%s", strings.Join(errs, ", "))

Check warning on line 175 in cmd/tink-controller-v1alpha2/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/tink-controller-v1alpha2/main.go#L175

Added line #L175 was not covered by tests
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions cmd/tink-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ func NewRootCommand() *cobra.Command {

cmd := &cobra.Command{
Use: "tink-controller",
PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {

Check warning on line 63 in cmd/tink-controller/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/tink-controller/main.go#L63

Added line #L63 was not covered by tests
viper, err := createViper(logger)
if err != nil {
return fmt.Errorf("config init: %w", err)
}
return applyViper(viper, cmd)
},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {

Check warning on line 70 in cmd/tink-controller/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/tink-controller/main.go#L70

Added line #L70 was not covered by tests
logger.Info("Starting controller version " + version)

ccfg := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
Expand Down Expand Up @@ -146,7 +146,7 @@ func applyViper(v *viper.Viper, cmd *cobra.Command) error {
for _, err := range errors {
errs = append(errs, err.Error())
}
return fmt.Errorf(strings.Join(errs, ", "))
return fmt.Errorf("%s", strings.Join(errs, ", "))

Check warning on line 149 in cmd/tink-controller/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/tink-controller/main.go#L149

Added line #L149 was not covered by tests
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions cmd/tink-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ func NewRootCommand() *cobra.Command {

cmd := &cobra.Command{
Use: "tink-server",
PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {

Check warning on line 81 in cmd/tink-server/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/tink-server/main.go#L81

Added line #L81 was not covered by tests
viper, err := createViper(logger)
if err != nil {
return err
}
return applyViper(viper, cmd)
},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {

Check warning on line 88 in cmd/tink-server/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/tink-server/main.go#L88

Added line #L88 was not covered by tests
// I am not sure if it is right for this to be here,
// but as last step I want to keep compatibility with
// what we have for a little bit and I thinik that's
Expand Down Expand Up @@ -201,7 +201,7 @@ func applyViper(v *viper.Viper, cmd *cobra.Command) error {
for _, err := range errors {
errs = append(errs, err.Error())
}
return fmt.Errorf(strings.Join(errs, ", "))
return fmt.Errorf("%s", strings.Join(errs, ", "))

Check warning on line 204 in cmd/tink-server/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/tink-server/main.go#L204

Added line #L204 was not covered by tests
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/tink-worker/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func NewRootCommand(version string) *cobra.Command {
Use: "tink-worker",
Short: "Tink Worker",
Version: version,
PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {

Check warning on line 42 in cmd/tink-worker/cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/tink-worker/cmd/root.go#L42

Added line #L42 was not covered by tests
return initViper(logger, cmd)
},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {

Check warning on line 45 in cmd/tink-worker/cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/tink-worker/cmd/root.go#L45

Added line #L45 was not covered by tests
retryInterval := viper.GetDuration("retry-interval")
retries := viper.GetInt("max-retry")
workerID := viper.GetString("id")
Expand Down
2 changes: 1 addition & 1 deletion cmd/tink-worker/worker/log_capturer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestLogCapturerContextLogger(t *testing.T) {
}

for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
t.Run(tc.name, func(_ *testing.T) {
logger := zapr.NewLogger(zap.Must(zap.NewDevelopment()))
ctx := context.Background()
if tc.logger != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/virtual-worker/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ func NewRootCommand(version string) *cobra.Command {
rootCmd := &cobra.Command{
Use: "virtual-worker",
Short: "Virtual Tink Worker",
PreRunE: func(cmd *cobra.Command, args []string) error {
PreRunE: func(cmd *cobra.Command, _ []string) error {

Check warning on line 37 in cmd/virtual-worker/cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/virtual-worker/cmd/root.go#L37

Added line #L37 was not covered by tests
return createViper(logger, cmd)
},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {

Check warning on line 40 in cmd/virtual-worker/cmd/root.go

View check run for this annotation

Codecov / codecov/patch

cmd/virtual-worker/cmd/root.go#L40

Added line #L40 was not covered by tests
retryInterval := viper.GetDuration("retry-interval")
retries := viper.GetInt("max-retry")
workerID := viper.GetString("id")
Expand Down
2 changes: 1 addition & 1 deletion cmd/virtual-worker/worker/container_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type fakeManager struct {
}

func (m *fakeManager) sleep() {
jitter := time.Duration(m.r.Int31n(int32(m.sleepJitter.Milliseconds()))) * time.Millisecond
jitter := time.Duration(m.r.Int63n(m.sleepJitter.Milliseconds())) * time.Millisecond

Check warning on line 33 in cmd/virtual-worker/worker/container_manager.go

View check run for this annotation

Codecov / codecov/patch

cmd/virtual-worker/worker/container_manager.go#L33

Added line #L33 was not covered by tests
time.Sleep(jitter + m.sleepMinimum)
}

Expand Down
6 changes: 3 additions & 3 deletions internal/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestAgent_ConcurrentWorkflows(t *testing.T) {
// Started is used to indicate the runtime has received the workflow.
started := make(chan struct{})
rntime := agent.ContainerRuntimeMock{
RunFunc: func(ctx context.Context, action workflow.Action) error {
RunFunc: func(ctx context.Context, _ workflow.Action) error {
started <- struct{}{}
<-ctx.Done()
return nil
Expand Down Expand Up @@ -412,7 +412,7 @@ message`,
trnport := transport.Noop()

rntime := agent.ContainerRuntimeMock{
RunFunc: func(ctx context.Context, action workflow.Action) error {
RunFunc: func(_ context.Context, action workflow.Action) error {
if res, ok := tc.Errors[action.ID]; ok {
return failure.NewReason(res.Message, res.Reason)
}
Expand All @@ -424,7 +424,7 @@ message`,
// to check for the last expected action.
lastEventReceived := make(chan struct{})
recorder := event.RecorderMock{
RecordEventFunc: func(contextMoqParam context.Context, event event.Event) error {
RecordEventFunc: func(_ context.Context, event event.Event) error {
if cmp.Equal(event, tc.Events[len(tc.Events)-1]) {
lastEventReceived <- struct{}{}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/agent/transport/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestFile(t *testing.T) {
defer cancel()

handler := &transport.WorkflowHandlerMock{
HandleWorkflowFunc: func(contextMoqParam context.Context, workflow workflow.Workflow, recorder event.Recorder) {
HandleWorkflowFunc: func(_ context.Context, workflow workflow.Workflow, _ event.Recorder) {
if !cmp.Equal(expect, workflow) {
t.Fatalf("Workflow diff:\n%v", cmp.Diff(expect, workflow))
}
Expand Down
4 changes: 2 additions & 2 deletions internal/agent/transport/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ func TestGRPC(t *testing.T) {
ContextFunc: context.Background,
}
client := &workflowproto.WorkflowServiceClientMock{
GetWorkflowsFunc: func(ctx context.Context, in *workflowproto.GetWorkflowsRequest, opts ...grpc.CallOption) (workflowproto.WorkflowService_GetWorkflowsClient, error) {
GetWorkflowsFunc: func(_ context.Context, _ *workflowproto.GetWorkflowsRequest, _ ...grpc.CallOption) (workflowproto.WorkflowService_GetWorkflowsClient, error) {
return stream, nil
},
}

var wg sync.WaitGroup
wg.Add(1)
handler := &transport.WorkflowHandlerMock{
HandleWorkflowFunc: func(contextMoqParam context.Context, workflow workflow.Workflow, recorder event.Recorder) {
HandleWorkflowFunc: func(_ context.Context, _ workflow.Workflow, _ event.Recorder) {
defer wg.Done()
close(responses)
},
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewAgent() *cobra.Command {
// TODO(chrisdoherty4) Handle signals
cmd := cobra.Command{
Use: "tink-agent",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {

Check warning on line 26 in internal/cli/agent.go

View check run for this annotation

Codecov / codecov/patch

internal/cli/agent.go#L26

Added line #L26 was not covered by tests
zl, err := zap.NewProduction()
if err != nil {
return fmt.Errorf("init logger: %w", err)
Expand All @@ -35,7 +35,7 @@ func NewAgent() *cobra.Command {
return fmt.Errorf("create runtime: %w", err)
}

conn, err := grpc.DialContext(cmd.Context(), opts.TinkServerAddr)
conn, err := grpc.NewClient(opts.TinkServerAddr)

Check warning on line 38 in internal/cli/agent.go

View check run for this annotation

Codecov / codecov/patch

internal/cli/agent.go#L38

Added line #L38 was not covered by tests
if err != nil {
return fmt.Errorf("dial tink server: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func NewClientConn(authority string, tlsEnabled bool, tlsInsecure bool) (*grpc.C
creds = grpc.WithTransportCredentials(insecure.NewCredentials())
}

conn, err := grpc.Dial(authority, creds, grpc.WithStatsHandler(otelgrpc.NewClientHandler()))
conn, err := grpc.NewClient(authority, creds, grpc.WithStatsHandler(otelgrpc.NewClientHandler()))

Check warning on line 21 in internal/client/client.go

View check run for this annotation

Codecov / codecov/patch

internal/client/client.go#L21

Added line #L21 was not covered by tests
if err != nil {
return nil, errors.Wrap(err, "dial tinkerbell server")
}
Expand Down
14 changes: 5 additions & 9 deletions internal/deprecated/workflow/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/tinkerbell/tink/api/v1alpha1"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/pkg/ptr"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -111,7 +110,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (reco
}

func (r *Reconciler) handleHardwareAllowPXE(ctx context.Context, stored *v1alpha1.Workflow, hardware *v1alpha1.Hardware) error {

Check warning on line 112 in internal/deprecated/workflow/reconciler.go

View check run for this annotation

Codecov / codecov/patch

internal/deprecated/workflow/reconciler.go#L112

Added line #L112 was not covered by tests

// We need to set allowPXE to true before a workflow runs.
// We need to set allowPXE to false after a workflow completes successfully.

Expand Down Expand Up @@ -206,7 +204,7 @@ func (r *Reconciler) processNewWorkflow(ctx context.Context, logger logr.Logger,
}

// netboot the hardware if requested
if stored.Spec.BootOpts.OneTimeNetboot {
if stored.Spec.BootOpts.OneTimeNetboot { //nolint:nestif // Will work on this complexity.
// check if the hardware has a bmcRef
if hardware.Spec.BMCRef == nil {
return reconcile.Result{}, fmt.Errorf("hardware %s does not have a BMC, cannot perform one time netboot", hardware.Name)

Check warning on line 210 in internal/deprecated/workflow/reconciler.go

View check run for this annotation

Codecov / codecov/patch

internal/deprecated/workflow/reconciler.go#L209-L210

Added lines #L209 - L210 were not covered by tests
Expand All @@ -227,12 +225,10 @@ func (r *Reconciler) processNewWorkflow(ctx context.Context, logger logr.Logger,
stored.Status.OneTimeNetboot.DeletionStatus = &v1alpha1.Status{Status: v1alpha1.StatusSuccess, Message: "previous existing one time netboot job deleted"}

Check warning on line 225 in internal/deprecated/workflow/reconciler.go

View check run for this annotation

Codecov / codecov/patch

internal/deprecated/workflow/reconciler.go#L225

Added line #L225 was not covered by tests

return reconcile.Result{Requeue: true}, nil
} else if errors.IsNotFound(err) {
stored.Status.OneTimeNetboot.DeletionStatus = &v1alpha1.Status{Status: v1alpha1.StatusSuccess, Message: "no existing one time netboot job found"}
} else {
if apierrors.IsNotFound(err) {
stored.Status.OneTimeNetboot.DeletionStatus = &v1alpha1.Status{Status: v1alpha1.StatusSuccess, Message: "no existing one time netboot job found"}
} else {
return reconcile.Result{Requeue: true}, err
}
return reconcile.Result{Requeue: true}, err

Check warning on line 231 in internal/deprecated/workflow/reconciler.go

View check run for this annotation

Codecov / codecov/patch

internal/deprecated/workflow/reconciler.go#L227-L231

Added lines #L227 - L231 were not covered by tests
}
}

Expand Down Expand Up @@ -329,7 +325,7 @@ func toTemplateHardwareData(hardware v1alpha1.Hardware) templateHardwareData {
return contract
}

func (r *Reconciler) processRunningWorkflow(_ context.Context, stored *v1alpha1.Workflow) reconcile.Result {
func (r *Reconciler) processRunningWorkflow(_ context.Context, stored *v1alpha1.Workflow) reconcile.Result { //nolint:unparam // This is the way controller runtime works.
// Check for global timeout expiration
if r.nowFunc().After(stored.GetStartTime().Add(time.Duration(stored.Status.GlobalTimeout) * time.Second)) {
stored.Status.State = v1alpha1.WorkflowStateTimeout
Expand Down
2 changes: 1 addition & 1 deletion internal/workflow/internal/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/rs/zerolog"
tinkv1 "github.com/tinkerbell/tink/api/v1alpha2"
"github.com/tinkerbell/tink/internal/ptr"
. "github.com/tinkerbell/tink/internal/workflow/internal"
. "github.com/tinkerbell/tink/internal/workflow/internal" //nolint:revive // Dot imports should not be used. Problem for another time though.
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down

0 comments on commit ca2f701

Please sign in to comment.