Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2475 from thedadams/add-revive-lint
Browse files Browse the repository at this point in the history
chore: add revive lint and fix related issues
  • Loading branch information
thedadams authored Feb 8, 2024
2 parents e5c17fb + 6cc288a commit 91c803e
Show file tree
Hide file tree
Showing 164 changed files with 621 additions and 650 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ linters:
- unused
- goimports
- whitespace
- revive
fast: false
max-same-issues: 50
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ setup-ci-image:
docker build -t acorn:v-ci .
docker save acorn:v-ci | docker exec -i $$(docker ps | grep k3s | awk '{print $$1}') ctr --address /run/k3s/containerd/containerd.sock images import -

GOLANGCI_LINT_VERSION ?= v1.54.2
GOLANGCI_LINT_VERSION ?= v1.55.2
setup-env:
if ! command -v golangci-lint &> /dev/null; then \
echo "Could not find golangci-lint, installing version $(GOLANGCI_LINT_VERSION)."; \
Expand Down
1 change: 1 addition & 0 deletions integration/client/apps/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ func TestAppLog(t *testing.T) {
assert.NotEqual(t, "", msg1.Line)

go func() {
//nolint:revive
for range msgs {
}
}()
Expand Down
40 changes: 20 additions & 20 deletions integration/client/credentials/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ func TestCredentialCreate(t *testing.T) {
helper.StartController(t)
restConfig := helper.StartAPI(t)

reg, close := helper.StartRegistry(t)
reg1, close1 := helper.StartRegistry(t)
defer close()
defer close1()
reg, cancel := helper.StartRegistry(t)
reg1, cancel1 := helper.StartRegistry(t)
defer cancel()
defer cancel1()

ctx := helper.GetCTX(t)
kclient := helper.MustReturn(kclient.Default)
Expand Down Expand Up @@ -60,10 +60,10 @@ func TestCredentialList(t *testing.T) {
helper.StartController(t)
restConfig := helper.StartAPI(t)

reg, close := helper.StartRegistry(t)
reg1, close1 := helper.StartRegistry(t)
defer close()
defer close1()
reg, cancel := helper.StartRegistry(t)
reg1, cancel1 := helper.StartRegistry(t)
defer cancel()
defer cancel1()

ctx := helper.GetCTX(t)
kclient := helper.MustReturn(kclient.Default)
Expand Down Expand Up @@ -110,10 +110,10 @@ func TestCredentialGet(t *testing.T) {
helper.StartController(t)
restConfig := helper.StartAPI(t)

reg, close := helper.StartRegistry(t)
reg1, close1 := helper.StartRegistry(t)
defer close()
defer close1()
reg, cancel := helper.StartRegistry(t)
reg1, cancel1 := helper.StartRegistry(t)
defer cancel()
defer cancel1()

ctx := helper.GetCTX(t)
kclient := helper.MustReturn(kclient.Default)
Expand Down Expand Up @@ -146,10 +146,10 @@ func TestCredentialUpdate(t *testing.T) {
helper.StartController(t)
restConfig := helper.StartAPI(t)

reg, close := helper.StartRegistry(t)
reg1, close1 := helper.StartRegistry(t)
defer close()
defer close1()
reg, cancel := helper.StartRegistry(t)
reg1, cancel1 := helper.StartRegistry(t)
defer cancel()
defer cancel1()

ctx := helper.GetCTX(t)
kclient := helper.MustReturn(kclient.Default)
Expand Down Expand Up @@ -189,10 +189,10 @@ func TestCredentialDelete(t *testing.T) {
helper.StartController(t)
restConfig := helper.StartAPI(t)

reg, close := helper.StartRegistry(t)
reg1, close1 := helper.StartRegistry(t)
defer close()
defer close1()
reg, cancel := helper.StartRegistry(t)
reg1, cancel1 := helper.StartRegistry(t)
defer cancel()
defer cancel1()

ctx := helper.GetCTX(t)
kclient := helper.MustReturn(kclient.Default)
Expand Down
6 changes: 3 additions & 3 deletions integration/client/imagerules/imageallowrules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import (
func TestImageAllowRules(t *testing.T) {
// TODO(@iwilltry42): Add test for auto-upgrade pattern
helper.StartController(t)
registry, close := helper.StartRegistry(t)
defer close()
registry, cancel := helper.StartRegistry(t)
defer cancel()

ctx := helper.GetCTX(t)
c, project := helper.ClientAndProject(t)
kclient := helper.MustReturn(kclient.Default)

// enable image allow rules in acorn config
helper.EnableFeatureWithRestore(t, ctx, kclient, profiles.FeatureImageAllowRules)
helper.EnableFeatureWithRestore(ctx, t, kclient, profiles.FeatureImageAllowRules)

// Delete any existing IARs from this project namespace
err := kclient.DeleteAllOf(ctx, &internalv1.ImageAllowRuleInstance{}, cclient.InNamespace(c.GetNamespace()))
Expand Down
8 changes: 4 additions & 4 deletions integration/client/imagerules/imageroleauthorizations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ var parentAcornfile []byte

func TestImageRoleAuthorizations(t *testing.T) {
helper.StartController(t)
registry, close := helper.StartRegistry(t)
defer close()
registry, cancel := helper.StartRegistry(t)
defer cancel()

ctx := helper.GetCTX(t)
c, _ := helper.ClientAndProject(t)
kclient := helper.MustReturn(kclient.Default)

// enable image role authorizations in acorn config
helper.EnableFeatureWithRestore(t, ctx, kclient, profiles.FeatureImageRoleAuthorizations)
helper.EnableFeatureWithRestore(ctx, t, kclient, profiles.FeatureImageRoleAuthorizations)

// Delete any existing rules from this project namespace
err := kclient.DeleteAllOf(ctx, &internaladminv1.ImageRoleAuthorizationInstance{}, cclient.InNamespace(c.GetNamespace()))
Expand Down Expand Up @@ -397,7 +397,7 @@ func TestImageRoleAuthorizationConsumerPerms(t *testing.T) {
kclient := helper.MustReturn(kclient.Default)

// enable image role authorizations in acorn config
helper.EnableFeatureWithRestore(t, ctx, kclient, profiles.FeatureImageRoleAuthorizations)
helper.EnableFeatureWithRestore(ctx, t, kclient, profiles.FeatureImageRoleAuthorizations)

// Delete any existing rules from this project namespace
err := kclient.DeleteAllOf(ctx, &internaladminv1.ImageRoleAuthorizationInstance{}, cclient.InNamespace(c.GetNamespace()))
Expand Down
4 changes: 2 additions & 2 deletions integration/client/imagerules/signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (

func TestImageSignVerify(t *testing.T) {
helper.StartController(t)
registry, close := helper.StartRegistry(t)
defer close()
registry, cancel := helper.StartRegistry(t)
defer cancel()

ctx := helper.GetCTX(t)
c, project := helper.ClientAndProject(t)
Expand Down
12 changes: 6 additions & 6 deletions integration/client/images/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ func TestImageTag(t *testing.T) {

func TestImagePush(t *testing.T) {
helper.StartController(t)
registry, close := helper.StartRegistry(t)
defer close()
registry, cancel := helper.StartRegistry(t)
defer cancel()
restConfig := helper.StartAPI(t)

ctx := helper.GetCTX(t)
Expand Down Expand Up @@ -193,8 +193,8 @@ func TestImagePush(t *testing.T) {

func TestImagePull(t *testing.T) {
helper.StartController(t)
registry, close := helper.StartRegistry(t)
defer close()
registry, cancel := helper.StartRegistry(t)
defer cancel()
restConfig := helper.StartAPI(t)

ctx := helper.GetCTX(t)
Expand Down Expand Up @@ -268,8 +268,8 @@ func TestImagePull(t *testing.T) {

func TestImageDetails(t *testing.T) {
helper.StartController(t)
registry, close := helper.StartRegistry(t)
defer close()
registry, cancel := helper.StartRegistry(t)
defer cancel()
restConfig := helper.StartAPI(t)

ctx := helper.GetCTX(t)
Expand Down
24 changes: 11 additions & 13 deletions integration/client/jobs/jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
client2 "github.com/acorn-io/runtime/integration/client"
"github.com/acorn-io/runtime/integration/helper"
apiv1 "github.com/acorn-io/runtime/pkg/apis/api.acorn.io/v1"
"github.com/acorn-io/runtime/pkg/client"
rclient "github.com/acorn-io/runtime/pkg/client"
kclient "github.com/acorn-io/runtime/pkg/k8sclient"
"github.com/acorn-io/runtime/pkg/publicname"
"github.com/stretchr/testify/assert"
Expand All @@ -26,7 +26,7 @@ func TestJobList(t *testing.T) {
kclient := helper.MustReturn(kclient.Default)
project := helper.TempProject(t, kclient)

c, err := client.New(restConfig, "", project.Name)
c, err := rclient.New(restConfig, "", project.Name)
require.NoError(t, err)

imageID := client2.NewImageWithJobs(t, project.Name)
Expand Down Expand Up @@ -58,7 +58,7 @@ func TestJobGet(t *testing.T) {
kclient := helper.MustReturn(kclient.Default)
project := helper.TempProject(t, kclient)

c, err := client.New(restConfig, "", project.Name)
c, err := rclient.New(restConfig, "", project.Name)
require.NoError(t, err)

imageID := client2.NewImageWithJobs(t, project.Name)
Expand Down Expand Up @@ -106,29 +106,27 @@ func TestJobRestart(t *testing.T) {
lclient, err := kclient.New(restConfig)
require.NoError(t, err)

kclient := helper.MustReturn(kclient.Default)
project := helper.TempProject(t, kclient)
client := helper.MustReturn(kclient.Default)
project := helper.TempProject(t, client)

c, err := client.New(restConfig, "", project.Name)
c, err := rclient.New(restConfig, "", project.Name)
require.NoError(t, err)

imageID := client2.NewImageWithJobs(t, project.Name)
app, err := c.AppRun(ctx, imageID, nil)
app, err := c.AppRun(ctx, client2.NewImageWithJobs(t, project.Name), nil)
require.NoError(t, err)

// Wait for the Job to initially complete
var firstCompletion *metav1.Time
helper.WaitForObject(t, lclient.Watch, &apiv1.AppList{}, app, func(app *apiv1.App) bool {
app = helper.WaitForObject(t, lclient.Watch, &apiv1.AppList{}, app, func(app *apiv1.App) bool {
firstCompletion = app.Status.AppStatus.Jobs["job"].CompletionTime
return app.Status.Namespace != "" && app.Status.AppStatus.Jobs["job"].CompletionTime != nil
return app.Status.AppStatus.Jobs["job"].CompletionTime != nil
})

require.NoError(t, c.JobRestart(ctx, publicname.ForChild(app, "job")))

// Wait for the Job to complete again by checking for a difference in the completion time
helper.WaitForObject(t, lclient.Watch, &apiv1.AppList{}, app, func(app *apiv1.App) bool {
secondCompletion := app.Status.AppStatus.Jobs["job"].CompletionTime
return app.Status.Namespace != "" && !firstCompletion.Equal(secondCompletion)
app = helper.WaitForObject(t, lclient.Watch, &apiv1.AppList{}, app, func(app *apiv1.App) bool {
return !firstCompletion.Equal(app.Status.AppStatus.Jobs["job"].CompletionTime)
})

require.NoError(t, c.JobRestart(ctx, publicname.ForChild(app, "cronjob")))
Expand Down
2 changes: 1 addition & 1 deletion integration/helper/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func Subset[V, W any, Z comparable](t *testing.T, first []V, second []W, firstLo

set := make(map[Z]int)
for _, value := range second {
set[secondLookup(value)] += 1
set[secondLookup(value)]++
}

for _, value := range first {
Expand Down
4 changes: 2 additions & 2 deletions integration/helper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
kclient "sigs.k8s.io/controller-runtime/pkg/client"
)

func EnableFeatureWithRestore(t *testing.T, ctx context.Context, kclient kclient.WithWatch, feature string) {
func EnableFeatureWithRestore(ctx context.Context, t *testing.T, kclient kclient.WithWatch, feature string) {
t.Helper()

// enable feature in acorn config
Expand Down Expand Up @@ -43,7 +43,7 @@ func EnableFeatureWithRestore(t *testing.T, ctx context.Context, kclient kclient
}
}

func SetIgnoreResourceRequirementsWithRestore(t *testing.T, ctx context.Context, kclient kclient.WithWatch) {
func SetIgnoreResourceRequirementsWithRestore(ctx context.Context, t *testing.T, kclient kclient.WithWatch) {
t.Helper()

cfg, err := config.Get(ctx, kclient)
Expand Down
1 change: 1 addition & 0 deletions integration/helper/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func doWatch[T client.Object](t *testing.T, watchFunc watchFunc, cb func(obj T)
}
defer func() {
result.Stop()
//nolint:revive
for range result.ResultChan() {
}
}()
Expand Down
8 changes: 4 additions & 4 deletions integration/run/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1425,8 +1425,8 @@ func TestCrossProjectNetworkConnection(t *testing.T) {
})

// determine pod IPs so we can test network connections
fooIP := getPodIPFromAppName(t, ctx, &kc, fooApp.Name, fooApp.Status.Namespace)
barIP := getPodIPFromAppName(t, ctx, &kc, barApp.Name, barApp.Status.Namespace)
fooIP := getPodIPFromAppName(ctx, t, &kc, fooApp.Name, fooApp.Status.Namespace)
barIP := getPodIPFromAppName(ctx, t, &kc, barApp.Name, barApp.Status.Namespace)

// build an Acorn that just runs a job with the official curl container
curlImage1, err := proj1Client.AcornImageBuild(ctx, "testdata/networkpolicy/curl.Acornfile", nil)
Expand Down Expand Up @@ -1500,7 +1500,7 @@ func TestCrossProjectNetworkConnection(t *testing.T) {
}
}

func getPodIPFromAppName(t *testing.T, ctx context.Context, kc *crClient.WithWatch, appName, namespace string) string {
func getPodIPFromAppName(ctx context.Context, t *testing.T, kc *crClient.WithWatch, appName, namespace string) string {
t.Helper()
selector, err := k8slabels.Parse(fmt.Sprintf("%s=%s", labels.AcornAppName, appName))
if err != nil {
Expand Down Expand Up @@ -1800,7 +1800,7 @@ func TestIgnoreResourceRequirements(t *testing.T) {
kc := helper.MustReturn(kclient.Default)
project := helper.TempProject(t, kc)

helper.SetIgnoreResourceRequirementsWithRestore(t, ctx, kc)
helper.SetIgnoreResourceRequirementsWithRestore(ctx, t, kc)

c, err := client.New(restConfig, project.Name, project.Name)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/admin.acorn.io/group.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package admin_acorn_io
package adminacornio

var Group = "admin.acorn.io"
2 changes: 1 addition & 1 deletion pkg/apis/api.acorn.io/group.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package api_acorn_io
package apiacornio

var Group = "api.acorn.io"
18 changes: 9 additions & 9 deletions pkg/apis/api.acorn.io/v1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
)

func convert_url_Values_To__ContainerReplicaExecOptions(in *url.Values, out *ContainerReplicaExecOptions, s conversion.Scope) error {
func convertURLlValuesToContainerReplicaExecOptions(in *url.Values, out *ContainerReplicaExecOptions, s conversion.Scope) error {
if values, ok := map[string][]string(*in)["command"]; ok && len(values) > 0 {
out.Command = *(*[]string)(unsafe.Pointer(&values))
} else {
Expand All @@ -31,11 +31,11 @@ func convert_url_Values_To__ContainerReplicaExecOptions(in *url.Values, out *Con
return nil
}

func Convert_url_Values_To__ContainerReplicaExecOptions(in, out interface{}, s conversion.Scope) error {
return convert_url_Values_To__ContainerReplicaExecOptions(in.(*url.Values), out.(*ContainerReplicaExecOptions), s)
func ConvertURLValuesToContainerReplicaExecOptions(in, out interface{}, s conversion.Scope) error {
return convertURLlValuesToContainerReplicaExecOptions(in.(*url.Values), out.(*ContainerReplicaExecOptions), s)
}

func convert_url_Values_To__LogOptions(in *url.Values, out *LogOptions, s conversion.Scope) error {
func convertURLValuesToLogOptions(in *url.Values, out *LogOptions, s conversion.Scope) error {
if values, ok := map[string][]string(*in)["tailLines"]; ok && len(values) > 0 {
out.Tail = new(int64)
if err := runtime.Convert_Slice_string_To_int64(&values, out.Tail, s); err != nil {
Expand All @@ -60,11 +60,11 @@ func convert_url_Values_To__LogOptions(in *url.Values, out *LogOptions, s conver
return nil
}

func Convert_url_Values_To__LogOptions(in, out interface{}, s conversion.Scope) error {
return convert_url_Values_To__LogOptions(in.(*url.Values), out.(*LogOptions), s)
func ConvertURLValuesToLogOptions(in, out interface{}, s conversion.Scope) error {
return convertURLValuesToLogOptions(in.(*url.Values), out.(*LogOptions), s)
}

func convert_url_Values_To__ContainerReplicaPortForwardOptions(in *url.Values, out *ContainerReplicaPortForwardOptions, s conversion.Scope) error {
func convertURLValuesToContainerReplicaPortForwardOptions(in *url.Values, out *ContainerReplicaPortForwardOptions, s conversion.Scope) error {
if values, ok := map[string][]string(*in)["port"]; ok && len(values) > 0 {
if err := runtime.Convert_Slice_string_To_int(&values, &out.Port, s); err != nil {
return err
Expand All @@ -75,6 +75,6 @@ func convert_url_Values_To__ContainerReplicaPortForwardOptions(in *url.Values, o
return nil
}

func Convert_url_Values_To__ContainerReplicaPortForwardOptions(in, out interface{}, s conversion.Scope) error {
return convert_url_Values_To__ContainerReplicaPortForwardOptions(in.(*url.Values), out.(*ContainerReplicaPortForwardOptions), s)
func ConvertURLValuesToContainerReplicaPortForwardOptions(in, out interface{}, s conversion.Scope) error {
return convertURLValuesToContainerReplicaPortForwardOptions(in.(*url.Values), out.(*ContainerReplicaPortForwardOptions), s)
}
Loading

0 comments on commit 91c803e

Please sign in to comment.