From 6b4362f71e50317175c2def31b98f6ac1354e5b3 Mon Sep 17 00:00:00 2001 From: Thorsten Klein Date: Mon, 12 Feb 2024 11:42:49 +0100 Subject: [PATCH] chore: make revive linter happy by replacing unused parameters with _ Signed-off-by: Thorsten Klein --- pkg/buildclient/filesyncclient.go | 2 +- pkg/cli/completion.go | 2 +- pkg/cli/run.go | 2 +- pkg/cli/run_test.go | 4 ++-- pkg/cli/version.go | 2 +- pkg/cli/volumes_test.go | 4 ++-- pkg/client/client.go | 2 +- pkg/k8schannel/websocket.go | 2 +- pkg/local/docker.go | 2 +- pkg/portforward/portforward.go | 4 ++-- pkg/ports/publish.go | 15 +++++++++++---- pkg/replace/interpolate.go | 2 +- pkg/replace/replace_test.go | 2 +- pkg/server/registry/apigroups/acorn/apps/icon.go | 6 +++--- .../registry/apigroups/acorn/builders/port.go | 2 +- .../registry/apigroups/acorn/containers/exec.go | 2 +- .../apigroups/acorn/containers/port_forward.go | 2 +- 17 files changed, 32 insertions(+), 25 deletions(-) diff --git a/pkg/buildclient/filesyncclient.go b/pkg/buildclient/filesyncclient.go index 63b152a58..753e87d41 100644 --- a/pkg/buildclient/filesyncclient.go +++ b/pkg/buildclient/filesyncclient.go @@ -172,7 +172,7 @@ func prepareSyncedDirs(localDirs map[string]string, dirNames []string, followPat } } } - resetUIDAndGID := func(p string, st *fstypes.Stat) fsutil.MapResult { + resetUIDAndGID := func(_ string, st *fstypes.Stat) fsutil.MapResult { st.Uid = 0 st.Gid = 0 return fsutil.MapResultKeep diff --git a/pkg/cli/completion.go b/pkg/cli/completion.go index 77ae4923f..971ad232a 100644 --- a/pkg/cli/completion.go +++ b/pkg/cli/completion.go @@ -281,7 +281,7 @@ func secretsCompletion(ctx context.Context, c client.Client, toComplete string) } func projectsCompletion(f ClientFactory) completionFunc { - return func(ctx context.Context, c client.Client, toComplete string) ([]string, error) { + return func(ctx context.Context, _ client.Client, toComplete string) ([]string, error) { var acornConfigFile string if f != nil { acornConfigFile = f.AcornConfigFile() diff --git a/pkg/cli/run.go b/pkg/cli/run.go index b93077a27..6ef5aa7ac 100644 --- a/pkg/cli/run.go +++ b/pkg/cli/run.go @@ -93,7 +93,7 @@ Volume Syntax } cmd.Flags().SetInterspersed(false) - cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) { + cmd.SetHelpFunc(func(cmd *cobra.Command, _ []string) { fmt.Println(cmd.Short + "\n") fmt.Println(cmd.UsageString()) }) diff --git a/pkg/cli/run_test.go b/pkg/cli/run_test.go index 00c6e7498..5dab848fe 100644 --- a/pkg/cli/run_test.go +++ b/pkg/cli/run_test.go @@ -43,7 +43,7 @@ func TestRunArgs_Env(t *testing.T) { func TestRun(t *testing.T) { baseMock := func(f *mocks.MockClient) { f.EXPECT().AppGet(gomock.Any(), gomock.Any()).DoAndReturn( - func(ctx context.Context, name string) (*apiv1.App, error) { + func(_ context.Context, name string) (*apiv1.App, error) { switch name { case "dne": return nil, fmt.Errorf("error: app %s does not exist", name) @@ -62,7 +62,7 @@ func TestRun(t *testing.T) { return nil, nil }).AnyTimes() f.EXPECT().AppRun(gomock.Any(), gomock.Any(), gomock.Any()).DoAndReturn( - func(ctx context.Context, image string, opts *client.AppRunOptions) (*apiv1.App, error) { + func(_ context.Context, image string, _ *client.AppRunOptions) (*apiv1.App, error) { switch image { case "dne": return nil, fmt.Errorf("error: app %s does not exist", image) diff --git a/pkg/cli/version.go b/pkg/cli/version.go index c49dc7883..3c0d54cf9 100644 --- a/pkg/cli/version.go +++ b/pkg/cli/version.go @@ -12,7 +12,7 @@ func NewVersion() *cobra.Command { Use: "version", Short: "Version information for acorn", Example: "acorn version", - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, _ []string) { fmt.Printf("acorn version %s\n", version.Get().String()) }, Args: cobra.NoArgs, diff --git a/pkg/cli/volumes_test.go b/pkg/cli/volumes_test.go index 1a2a4891b..448894506 100644 --- a/pkg/cli/volumes_test.go +++ b/pkg/cli/volumes_test.go @@ -36,7 +36,7 @@ func TestVolume(t *testing.T) { Status: apiv1.VolumeStatus{AppPublicName: "found", AppName: "found", VolumeName: "vol"}, }}, nil).AnyTimes() f.EXPECT().VolumeGet(gomock.Any(), gomock.Any()).DoAndReturn( - func(ctx context.Context, name string) (*apiv1.Volume, error) { + func(_ context.Context, name string) (*apiv1.Volume, error) { potentialVol := apiv1.Volume{TypeMeta: metav1.TypeMeta{}, ObjectMeta: metav1.ObjectMeta{Name: "found.vol", Labels: map[string]string{ @@ -58,7 +58,7 @@ func TestVolume(t *testing.T) { return nil, nil }).AnyTimes() f.EXPECT().VolumeDelete(gomock.Any(), gomock.Any()).DoAndReturn( - func(ctx context.Context, name string) (*apiv1.Volume, error) { + func(_ context.Context, name string) (*apiv1.Volume, error) { switch name { case "dne": return nil, nil diff --git a/pkg/client/client.go b/pkg/client/client.go index 21928c20a..9c35728ee 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -516,7 +516,7 @@ func (c *DefaultClient) KubeProxyAddress(ctx context.Context, opts *KubeProxyAdd srv := &http.Server{ Handler: handler, - BaseContext: func(listener net.Listener) context.Context { + BaseContext: func(_ net.Listener) context.Context { return ctx }, } diff --git a/pkg/k8schannel/websocket.go b/pkg/k8schannel/websocket.go index fb9317a3e..4e0c67814 100644 --- a/pkg/k8schannel/websocket.go +++ b/pkg/k8schannel/websocket.go @@ -13,7 +13,7 @@ import ( "github.com/gorilla/websocket" ) -var Upgrader = &websocket.Upgrader{CheckOrigin: func(req *http.Request) bool { +var Upgrader = &websocket.Upgrader{CheckOrigin: func(_ *http.Request) bool { return true }, HandshakeTimeout: 15 * time.Second} diff --git a/pkg/local/docker.go b/pkg/local/docker.go index 82da27080..639e2d02d 100644 --- a/pkg/local/docker.go +++ b/pkg/local/docker.go @@ -296,7 +296,7 @@ func (c *Container) Wait(ctx context.Context) error { ns.Infof("Waiting for local project") w := watcher.New[*v1.Project](kc) for { - _, err = w.ByName(ctx, "", "local", func(obj *v1.Project) (bool, error) { + _, err = w.ByName(ctx, "", "local", func(_ *v1.Project) (bool, error) { return true, nil }) if err != nil { diff --git a/pkg/portforward/portforward.go b/pkg/portforward/portforward.go index c5c1d2861..71b2af7f6 100644 --- a/pkg/portforward/portforward.go +++ b/pkg/portforward/portforward.go @@ -54,11 +54,11 @@ func PortForward(ctx context.Context, c client.Client, containerName string, add p := tcpproxy.Proxy{} p.AddRoute(listenAddress, &tcpproxy.DialProxy{ - DialContext: func(ctx context.Context, network, address string) (net.Conn, error) { + DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) { return dialer(ctx) }, }) - p.ListenFunc = func(_, laddr string) (net.Listener, error) { + p.ListenFunc = func(_, _ string) (net.Listener, error) { fmt.Printf("Forwarding %s => %d for container [%s]\n", listener.Addr().String(), port, containerName) return listener, err } diff --git a/pkg/ports/publish.go b/pkg/ports/publish.go index 5dac049fa..7a2da458e 100644 --- a/pkg/ports/publish.go +++ b/pkg/ports/publish.go @@ -198,6 +198,13 @@ func matches(binding v1.PortPublish, port v1.PortDef) bool { portMatches(binding, port) } +/* +collectPorts collects all port definitions, deduplicates them and drops disallowed combinations + + - no duplicate hostnames allowed + - same protocol on same port only allowed if using different hostnames + - only 1x UDP and 1 variant of TCP (tcp/http/http2) allowed +*/ func collectPorts(seen map[int32][]v1.PortDef, seenHostnames map[string]struct{}, ports []v1.PortDef, devMode bool) (result []v1.PortDef) { for _, port := range ports { if !devMode && port.Dev { @@ -220,11 +227,11 @@ func collectPorts(seen map[int32][]v1.PortDef, seenHostnames map[string]struct{} discard := false for _, p := range seenPortDefs { if port.TargetPort == p.TargetPort { - if port.Hostname != "" { - // OK: Same port and target port (and potentially protocol) but different hostnames, so keep both - break - } if (port.Protocol != v1.ProtocolUDP && p.Protocol != v1.ProtocolUDP) || (port.Protocol == v1.ProtocolUDP && p.Protocol == v1.ProtocolUDP) { + if port.Protocol == p.Protocol && port.Hostname != "" { + // OK: Same port and target port and protocol but different hostnames (deduplicated before), so keep both + continue + } // NOT OK: Same port, target port, and protocol (variants of TCP are considered the same, i.e. TCP/HTTP/HTTP2) // The only case that's OK is if one is UDP and the other is not (some variant of TCP) discard = true diff --git a/pkg/replace/interpolate.go b/pkg/replace/interpolate.go index 889ada399..2748e8beb 100644 --- a/pkg/replace/interpolate.go +++ b/pkg/replace/interpolate.go @@ -23,7 +23,7 @@ func Interpolate(data any, s string) (string, error) { out := json.RawMessage{} err = aml.Unmarshal([]byte(s), &out, aml.DecoderOption{ SourceName: "inline", - GlobalsLookup: func(ctx context.Context, key string, parent eval.Scope) (value.Value, bool, error) { + GlobalsLookup: func(_ context.Context, key string, _ eval.Scope) (value.Value, bool, error) { return value.Lookup(val, value.NewValue(key)) }, }) diff --git a/pkg/replace/replace_test.go b/pkg/replace/replace_test.go index c4832b8b3..0d69e3fd8 100644 --- a/pkg/replace/replace_test.go +++ b/pkg/replace/replace_test.go @@ -82,7 +82,7 @@ func TestReplace(t *testing.T) { s: "start@{inner}end", startToken: "@{", endToken: "}", - replace: func(s string) (string, bool, error) { + replace: func(_ string) (string, bool, error) { return "", false, nil }, }, diff --git a/pkg/server/registry/apigroups/acorn/apps/icon.go b/pkg/server/registry/apigroups/acorn/apps/icon.go index cb8ca05ea..86ec24dd6 100644 --- a/pkg/server/registry/apigroups/acorn/apps/icon.go +++ b/pkg/server/registry/apigroups/acorn/apps/icon.go @@ -81,18 +81,18 @@ func (i *Icon) Connect(ctx context.Context, id string, _ runtime.Object, _ rest. case ".gif": contentType = "image/gif" default: - return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { + return http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) { rw.WriteHeader(http.StatusNotFound) }), nil } if len(icon) == 0 { - return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { + return http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) { rw.WriteHeader(http.StatusNotFound) }), nil } - return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { + return http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) { rw.Header().Set("Content-Type", contentType) _, _ = rw.Write(icon) }), nil diff --git a/pkg/server/registry/apigroups/acorn/builders/port.go b/pkg/server/registry/apigroups/acorn/builders/port.go index 630a62952..afd018c8a 100644 --- a/pkg/server/registry/apigroups/acorn/builders/port.go +++ b/pkg/server/registry/apigroups/acorn/builders/port.go @@ -37,7 +37,7 @@ func NewBuilderPort(client kclient.WithWatch, transport http.RoundTripper) (*Bui proxy: httputil.ReverseProxy{ Transport: transport, FlushInterval: 200 * time.Millisecond, - Director: func(request *http.Request) {}, + Director: func(_ *http.Request) {}, }, httpClient: &http.Client{ Transport: transport, diff --git a/pkg/server/registry/apigroups/acorn/containers/exec.go b/pkg/server/registry/apigroups/acorn/containers/exec.go index 91fb18fae..a93e54d77 100644 --- a/pkg/server/registry/apigroups/acorn/containers/exec.go +++ b/pkg/server/registry/apigroups/acorn/containers/exec.go @@ -70,7 +70,7 @@ func NewContainerExec(client kclient.WithWatch, cfg *rest.Config) (*ContainerExe proxy: httputil.ReverseProxy{ FlushInterval: 200 * time.Millisecond, Transport: transport, - Director: func(request *http.Request) {}, + Director: func(_ *http.Request) {}, }, RESTClient: k8s.CoreV1().RESTClient(), rbac: apps.NewRBACValidator(client), diff --git a/pkg/server/registry/apigroups/acorn/containers/port_forward.go b/pkg/server/registry/apigroups/acorn/containers/port_forward.go index 0772fa201..2c0841156 100644 --- a/pkg/server/registry/apigroups/acorn/containers/port_forward.go +++ b/pkg/server/registry/apigroups/acorn/containers/port_forward.go @@ -50,7 +50,7 @@ func NewPortForward(client kclient.WithWatch, cfg *rest.Config) (*PortForward, e proxy: httputil.ReverseProxy{ FlushInterval: 200 * time.Millisecond, Transport: transport, - Director: func(request *http.Request) {}, + Director: func(_ *http.Request) {}, }, RESTClient: k8s.CoreV1().RESTClient(), }, nil