From 6217565c89fc7d3431db8c308a2be2bb5941ba3f Mon Sep 17 00:00:00 2001 From: Avi Deitcher Date: Sun, 9 Oct 2022 11:48:59 +0300 Subject: [PATCH 1/2] add go vet and go lint Signed-off-by: Avi Deitcher --- .github/workflows/ci.yml | 54 ++++++++++++---------------------- .github/workflows/publish.yaml | 4 +-- .github/workflows/release.yml | 10 +++---- 3 files changed, 23 insertions(+), 45 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ee3aeb64b..589712de3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,35 +35,29 @@ jobs: runs-on: ${{ matrix.target.runner }} steps: - - name: Set up Go 1.16 - uses: actions/setup-go@v2 + - name: Set up Go 1.19 + uses: actions/setup-go@v3 with: - go-version: 1.16.7 + go-version: 1.19.2 id: go - name: Check out code - uses: actions/checkout@v1 - with: - path: ./src/github.com/linuxkit/linuxkit + uses: actions/checkout@v3 - name: Set path run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH env: GOPATH: ${{runner.workspace}} - - name: Get pre-requisites + - name: golangci-lint CLI + uses: golangci/golangci-lint-action@v3 + with: + version: v1.50.0 + working-directory: src/cmd/linuxkit + args: --verbose --timeout=10m + - name: go vet CLI run: | - go get -u golang.org/x/lint/golint - go get -u github.com/gordonklaus/ineffassign - env: - GOPATH: ${{runner.workspace}} - - # - name: Lint - # run: | - # make local-check - # env: - # GOPATH: ${{runner.workspace}} - + cd src/cmd/linuxkit && go vet ./... - name: Build run: | make GOARCH=${{matrix.target.arch}} GOOS=${{matrix.target.os}} LOCAL_TARGET=$(pwd)/bin/linuxkit-${{matrix.target.suffix}} local-build @@ -99,9 +93,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code - uses: actions/checkout@v1 - with: - path: ./src/github.com/linuxkit/linuxkit + uses: actions/checkout@v3 - name: Set up binfmt # Only register arm64 as we are on amd64 already. s390x is not reliable @@ -138,9 +130,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code - uses: actions/checkout@v1 - with: - path: ./src/github.com/linuxkit/linuxkit + uses: actions/checkout@v3 - name: Install Pre-Requisites run: | @@ -194,9 +184,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code - uses: actions/checkout@v1 - with: - path: ./src/github.com/linuxkit/linuxkit + uses: actions/checkout@v3 - name: Install Pre-Requisites run: | @@ -242,9 +230,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code - uses: actions/checkout@v1 - with: - path: ./src/github.com/linuxkit/linuxkit + uses: actions/checkout@v3 - name: Install Pre-Requisites run: | @@ -290,9 +276,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code - uses: actions/checkout@v1 - with: - path: ./src/github.com/linuxkit/linuxkit + uses: actions/checkout@v3 - name: Install Pre-Requisites run: | @@ -338,9 +322,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code - uses: actions/checkout@v1 - with: - path: ./src/github.com/linuxkit/linuxkit + uses: actions/checkout@v3 - name: Install Pre-Requisites run: | diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 8717f551d..dce5d9913 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -14,9 +14,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out code - uses: actions/checkout@v1 - with: - path: ./src/github.com/linuxkit/linuxkit + uses: actions/checkout@v3 - name: Ensure bin/ directory run: mkdir -p bin - name: Download linuxkit diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3f20783c9..edcfffdce 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,16 +11,14 @@ jobs: runs-on: macos-latest steps: - - name: Set up Go 1.16 - uses: actions/setup-go@v2 + - name: Set up Go 1.19 + uses: actions/setup-go@v3 with: - go-version: 1.16.7 + go-version: 1.19.2 id: go - name: Check out code - uses: actions/checkout@v1 - with: - path: ./src/github.com/linuxkit/linuxkit + uses: actions/checkout@v3 - name: Set path run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH From 4e4d2d1f15f62ab59e3e5b74d57e091a37fa2f0e Mon Sep 17 00:00:00 2001 From: Avi Deitcher Date: Mon, 10 Oct 2022 21:28:24 +0300 Subject: [PATCH 2/2] fix all lint errors Signed-off-by: Avi Deitcher --- src/cmd/linuxkit/cache/source.go | 2 +- src/cmd/linuxkit/cache_export.go | 2 +- src/cmd/linuxkit/gcp.go | 22 ++++-- src/cmd/linuxkit/go.mod | 1 + src/cmd/linuxkit/hyperv_fallback.go | 2 + src/cmd/linuxkit/main.go | 3 - src/cmd/linuxkit/moby/output.go | 4 +- src/cmd/linuxkit/pad4/pad4.go | 4 +- src/cmd/linuxkit/pkglib/build.go | 1 - src/cmd/linuxkit/pkglib/docker.go | 8 +- src/cmd/linuxkit/pkglib/pkglib.go | 3 +- src/cmd/linuxkit/push_openstack.go | 2 +- src/cmd/linuxkit/run_hyperkit.go | 8 +- src/cmd/linuxkit/run_hyperv.go | 2 + src/cmd/linuxkit/run_openstack.go | 2 +- src/cmd/linuxkit/run_packet.go | 16 ++-- src/cmd/linuxkit/run_qemu.go | 8 +- src/cmd/linuxkit/run_vcenter.go | 10 +-- ...tualizationframework_darwin_cgo_enabled.go | 4 +- src/cmd/linuxkit/scaleway.go | 8 +- src/cmd/linuxkit/serve.go | 2 +- .../x/crypto/ssh/terminal/terminal.go | 76 ------------------- src/cmd/linuxkit/vendor/modules.txt | 2 +- 23 files changed, 67 insertions(+), 125 deletions(-) delete mode 100644 src/cmd/linuxkit/vendor/golang.org/x/crypto/ssh/terminal/terminal.go diff --git a/src/cmd/linuxkit/cache/source.go b/src/cmd/linuxkit/cache/source.go index 2c29fa602..11337d846 100644 --- a/src/cmd/linuxkit/cache/source.go +++ b/src/cmd/linuxkit/cache/source.go @@ -92,7 +92,7 @@ func (c ImageSource) V1TarReader(overrideName string) (io.ReadCloser, error) { r, w := io.Pipe() go func() { defer w.Close() - tarball.Write(refName, image, w) + _ = tarball.Write(refName, image, w) }() return r, nil } diff --git a/src/cmd/linuxkit/cache_export.go b/src/cmd/linuxkit/cache_export.go index d058f1e8d..19eb095ff 100644 --- a/src/cmd/linuxkit/cache_export.go +++ b/src/cmd/linuxkit/cache_export.go @@ -83,5 +83,5 @@ func cacheExport(args []string) { w = f } - io.Copy(w, reader) + _, _ = io.Copy(w, reader) } diff --git a/src/cmd/linuxkit/gcp.go b/src/cmd/linuxkit/gcp.go index a4b47cbaa..c4363ee1f 100644 --- a/src/cmd/linuxkit/gcp.go +++ b/src/cmd/linuxkit/gcp.go @@ -17,6 +17,7 @@ import ( "golang.org/x/oauth2/google" "google.golang.org/api/compute/v1" "google.golang.org/api/googleapi" + "google.golang.org/api/option" "google.golang.org/api/storage/v1" ) @@ -34,7 +35,6 @@ type GCPClient struct { compute *compute.Service storage *storage.Service projectName string - fileName string privKey *rsa.PrivateKey } @@ -87,12 +87,12 @@ func NewGCPClient(keys, projectName string) (*GCPClient, error) { } var err error - client.compute, err = compute.New(client.client) + client.compute, err = compute.NewService(ctx, option.WithHTTPClient(client.client)) if err != nil { return nil, err } - client.storage, err = storage.New(client.client) + client.storage, err = storage.NewService(ctx, option.WithHTTPClient(client.client)) if err != nil { return nil, err } @@ -443,19 +443,25 @@ func (g GCPClient) ConnectToInstanceSerialPort(instance, zone string) error { if err != nil { return fmt.Errorf("Unable to setup stdin for session: %v", err) } - go io.Copy(stdin, os.Stdin) + go func() { + _, _ = io.Copy(stdin, os.Stdin) + }() stdout, err := session.StdoutPipe() if err != nil { return fmt.Errorf("Unable to setup stdout for session: %v", err) } - go io.Copy(os.Stdout, stdout) + go func() { + _, _ = io.Copy(os.Stdout, stdout) + }() stderr, err := session.StderrPipe() if err != nil { return fmt.Errorf("Unable to setup stderr for session: %v", err) } - go io.Copy(os.Stderr, stderr) + go func() { + _, _ = io.Copy(os.Stderr, stderr) + }() /* c := make(chan os.Signal, 1) exit := make(chan bool, 1) @@ -487,7 +493,9 @@ func (g GCPClient) ConnectToInstanceSerialPort(instance, zone string) error { return err } - defer term.RestoreTerminal(fd, oldState) + defer func() { + _ = term.RestoreTerminal(fd, oldState) + }() winsize, err := term.GetWinsize(fd) if err != nil { diff --git a/src/cmd/linuxkit/go.mod b/src/cmd/linuxkit/go.mod index 1032b7746..b3f1ecf5d 100644 --- a/src/cmd/linuxkit/go.mod +++ b/src/cmd/linuxkit/go.mod @@ -54,6 +54,7 @@ require ( golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1 golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 golang.org/x/sys v0.0.0-20220412211240-33da011f77ad + golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect google.golang.org/api v0.57.0 gopkg.in/yaml.v2 v2.4.0 ) diff --git a/src/cmd/linuxkit/hyperv_fallback.go b/src/cmd/linuxkit/hyperv_fallback.go index da4645595..4e7764757 100644 --- a/src/cmd/linuxkit/hyperv_fallback.go +++ b/src/cmd/linuxkit/hyperv_fallback.go @@ -9,10 +9,12 @@ import ( "log" ) +//nolint:unused func hypervStartConsole(vmName string) error { log.Fatalf("This function should not be called") return nil } +//nolint:unused func hypervRestoreConsole() { } diff --git a/src/cmd/linuxkit/main.go b/src/cmd/linuxkit/main.go index a397516b6..64424aa6f 100644 --- a/src/cmd/linuxkit/main.go +++ b/src/cmd/linuxkit/main.go @@ -9,7 +9,6 @@ import ( "github.com/linuxkit/linuxkit/src/cmd/linuxkit/util" "github.com/linuxkit/linuxkit/src/cmd/linuxkit/version" - log "github.com/sirupsen/logrus" "gopkg.in/yaml.v2" ) @@ -23,8 +22,6 @@ type PkgConfig struct { } var ( - defaultLogFormatter = &log.TextFormatter{} - // Config is the global tool configuration Config = GlobalConfig{} ) diff --git a/src/cmd/linuxkit/moby/output.go b/src/cmd/linuxkit/moby/output.go index 4ff1073d4..d3b61f61e 100644 --- a/src/cmd/linuxkit/moby/output.go +++ b/src/cmd/linuxkit/moby/output.go @@ -520,7 +520,7 @@ func outputKernelSquashFS(image, base string, filesystem io.Reader) error { case strings.HasPrefix(thdr.Name, "boot/"): // skip the rest of boot/ default: - rootfs.WriteHeader(thdr) + _ = rootfs.WriteHeader(thdr) if _, err := io.Copy(rootfs, tr); err != nil { return err } @@ -575,7 +575,7 @@ func outputKernelISO(image, base string, filesystem io.Reader) error { case strings.HasPrefix(thdr.Name, "boot/"): // skip the rest of boot/ default: - rootfs.WriteHeader(thdr) + _ = rootfs.WriteHeader(thdr) if _, err := io.Copy(rootfs, tr); err != nil { return err } diff --git a/src/cmd/linuxkit/pad4/pad4.go b/src/cmd/linuxkit/pad4/pad4.go index 008153b26..e78490fbe 100644 --- a/src/cmd/linuxkit/pad4/pad4.go +++ b/src/cmd/linuxkit/pad4/pad4.go @@ -12,7 +12,7 @@ type Writer struct { } // Write writes output -func (pad Writer) Write(p []byte) (int, error) { +func (pad *Writer) Write(p []byte) (int, error) { n, err := pad.w.Write(p) if err != nil { return 0, err @@ -22,7 +22,7 @@ func (pad Writer) Write(p []byte) (int, error) { } // Close adds the padding -func (pad Writer) Close() error { +func (pad *Writer) Close() error { mod4 := pad.count & 3 if mod4 == 0 { return nil diff --git a/src/cmd/linuxkit/pkglib/build.go b/src/cmd/linuxkit/pkglib/build.go index 896c96af5..6442fe7c7 100644 --- a/src/cmd/linuxkit/pkglib/build.go +++ b/src/cmd/linuxkit/pkglib/build.go @@ -31,7 +31,6 @@ type buildOpts struct { push bool release string manifest bool - image bool targetDocker bool cacheDir string cacheProvider lktspec.CacheProvider diff --git a/src/cmd/linuxkit/pkglib/docker.go b/src/cmd/linuxkit/pkglib/docker.go index 5ce50131d..3c96d409b 100644 --- a/src/cmd/linuxkit/pkglib/docker.go +++ b/src/cmd/linuxkit/pkglib/docker.go @@ -129,6 +129,8 @@ func (dr *dockerRunnerImpl) command(stdin io.Reader, stdout, stderr io.Writer, a // versionCheck returns the client version and server version, and compares them both // against the minimum required version. +// +//nolint:unused // will be used when linuxkit cache is eliminated and we return to docker image cache func (dr *dockerRunnerImpl) versionCheck(version string) (string, string, error) { var stdout bytes.Buffer if err := dr.command(nil, &stdout, nil, "version", "--format", "json"); err != nil { @@ -325,7 +327,7 @@ func (dr *dockerRunnerImpl) builderEnsureContainer(ctx context.Context, name, im // wait for buildkit socket to be ready up to the timeout fmt.Printf("waiting for buildkit builder to be ready, up to %d seconds\n", buildkitWaitServer) timeout := time.After(buildkitWaitServer * time.Second) - ticker := time.Tick(buildkitCheckInterval * time.Second) + ticker := time.NewTicker(buildkitCheckInterval * time.Second) // Keep trying until we're timed out or get a success for { select { @@ -333,7 +335,7 @@ func (dr *dockerRunnerImpl) builderEnsureContainer(ctx context.Context, name, im case <-timeout: return nil, fmt.Errorf("could not communicate with buildkit builder at context/container %s/%s after %d seconds", dockerContext, name, buildkitWaitServer) // Got a tick, we should try again - case <-ticker: + case <-ticker.C: client, err := buildkitClient.New(ctx, fmt.Sprintf("docker-container://%s?context=%s", name, dockerContext)) if err == nil { _, err = client.Info(ctx) @@ -363,10 +365,12 @@ func (dr *dockerRunnerImpl) pull(img string) (bool, error) { } } +//nolint:unused // will be used when linuxkit cache is eliminated and we return to docker image cache func (dr dockerRunnerImpl) push(img string) error { return dr.command(nil, nil, nil, "image", "push", img) } +//nolint:unused // will be used when linuxkit cache is eliminated and we return to docker image cache func (dr *dockerRunnerImpl) pushWithManifest(img, suffix string, pushImage, pushManifest bool) error { var err error if pushImage { diff --git a/src/cmd/linuxkit/pkglib/pkglib.go b/src/cmd/linuxkit/pkglib/pkglib.go index 9f39608c7..d9564254e 100644 --- a/src/cmd/linuxkit/pkglib/pkglib.go +++ b/src/cmd/linuxkit/pkglib/pkglib.go @@ -324,6 +324,7 @@ func (p Pkg) Arches() []string { return p.arches } +//nolint:unused // will be used when linuxkit cache is eliminated and we return to docker image cache func (p Pkg) archSupported(want string) bool { for _, supp := range p.arches { if supp == want { @@ -359,7 +360,7 @@ func makeAbsSubpath(field, base, path string) (string, error) { return "", fmt.Errorf("%s must not be exactly the package directory", field) } - if !filepath.HasPrefix(p, base) { + if !strings.HasPrefix(p, base) { return "", fmt.Errorf("%s must be within package directory", field) } diff --git a/src/cmd/linuxkit/push_openstack.go b/src/cmd/linuxkit/push_openstack.go index deba95b9a..5fbd46a56 100644 --- a/src/cmd/linuxkit/push_openstack.go +++ b/src/cmd/linuxkit/push_openstack.go @@ -66,7 +66,7 @@ func createOpenStackImage(filePath string, imageName string, client *gophercloud } } - if supportedExtension == false { + if !supportedExtension { log.Fatalf("Extension [%s] is not supported", fileExtension) } diff --git a/src/cmd/linuxkit/run_hyperkit.go b/src/cmd/linuxkit/run_hyperkit.go index 166f1436b..6ec8371f1 100644 --- a/src/cmd/linuxkit/run_hyperkit.go +++ b/src/cmd/linuxkit/run_hyperkit.go @@ -12,7 +12,7 @@ import ( "strings" "github.com/google/uuid" - "github.com/moby/hyperkit/go" + hyperkit "github.com/moby/hyperkit/go" "github.com/moby/vpnkit/go/pkg/vmnet" "github.com/moby/vpnkit/go/pkg/vpnkit" log "github.com/sirupsen/logrus" @@ -412,7 +412,9 @@ func launchVPNKit(vpnkitPath, etherSock, vsockSock, portSock string) (*os.Proces return nil, err } - go cmd.Wait() // run in background + go func() { + _ = cmd.Wait() // run in background + }() return cmd.Process, nil } @@ -493,7 +495,7 @@ func vpnkitPublishPorts(h *hyperkit.HyperKit, publishFlags multipleFlag, portSoc // Return cleanup function return func() { for _, vp := range ports { - c.Unexpose(context.Background(), vp) + _ = c.Unexpose(context.Background(), vp) } }, nil } diff --git a/src/cmd/linuxkit/run_hyperv.go b/src/cmd/linuxkit/run_hyperv.go index a32cbc929..2f11d3f35 100644 --- a/src/cmd/linuxkit/run_hyperv.go +++ b/src/cmd/linuxkit/run_hyperv.go @@ -24,6 +24,8 @@ func runHyperV(args []string) { fmt.Printf("Options:\n") flags.PrintDefaults() } + //nolint:staticcheck // I honestly have no idea why this is complaining, as this does get called on + // L159, but anything to get the linter to stop complaining. keep := flags.Bool("keep", false, "Keep the VM after finishing") vmName := flags.String("name", "", "Name of the Hyper-V VM") cpus := flags.Int("cpus", 1, "Number of CPUs") diff --git a/src/cmd/linuxkit/run_openstack.go b/src/cmd/linuxkit/run_openstack.go index 8f28c0ad9..510f38da0 100644 --- a/src/cmd/linuxkit/run_openstack.go +++ b/src/cmd/linuxkit/run_openstack.go @@ -82,7 +82,7 @@ func runOpenStack(args []string) { log.Fatalf("Unable to create server: %s", err) } - servers.WaitForStatus(client, server.ID, "ACTIVE", 600) + _ = servers.WaitForStatus(client, server.ID, "ACTIVE", 600) log.Infof("Server created, UUID is %s", server.ID) fmt.Println(server.ID) diff --git a/src/cmd/linuxkit/run_packet.go b/src/cmd/linuxkit/run_packet.go index 1cda82f0b..596484dd3 100644 --- a/src/cmd/linuxkit/run_packet.go +++ b/src/cmd/linuxkit/run_packet.go @@ -20,7 +20,7 @@ import ( log "github.com/sirupsen/logrus" "golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh/agent" - "golang.org/x/crypto/ssh/terminal" + "golang.org/x/term" ) const ( @@ -120,7 +120,7 @@ func runPacket(args []string) { mux := http.NewServeMux() mux.HandleFunc(fmt.Sprintf("/%s", ipxeScriptName), func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, ipxeScript) + fmt.Fprint(w, ipxeScript) }) fs := serveFiles{[]string{fmt.Sprintf("%s-kernel", name), fmt.Sprintf("%s-initrd.img", name)}} mux.Handle("/", http.FileServer(fs)) @@ -230,7 +230,7 @@ func runPacket(args []string) { log.Debugf("Shutting down http server...") ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() - httpServer.Shutdown(ctx) + _ = httpServer.Shutdown(ctx) } if *keepFlag { @@ -331,7 +331,7 @@ func packetSOS(user, host string) error { ssh.IGNCR: 1, } - width, height, err := terminal.GetSize(0) + width, height, err := term.GetSize(0) if err != nil { log.Warningf("Error getting terminal size. Ignored. %v", err) width = 80 @@ -340,18 +340,20 @@ func packetSOS(user, host string) error { if err := s.RequestPty("vt100", width, height, modes); err != nil { return fmt.Errorf("Request for PTY failed: %v", err) } - oldState, err := terminal.MakeRaw(int(os.Stdin.Fd())) + oldState, err := term.MakeRaw(int(os.Stdin.Fd())) if err != nil { return err } - defer terminal.Restore(0, oldState) + defer func() { + _ = term.Restore(0, oldState) + }() // Start remote shell if err := s.Shell(); err != nil { return fmt.Errorf("Failed to start shell: %v", err) } - s.Wait() + _ = s.Wait() return nil } diff --git a/src/cmd/linuxkit/run_qemu.go b/src/cmd/linuxkit/run_qemu.go index 949b8cfea..5a1cfbf9c 100644 --- a/src/cmd/linuxkit/run_qemu.go +++ b/src/cmd/linuxkit/run_qemu.go @@ -385,7 +385,7 @@ func runQemuLocal(config QemuConfig) error { } // Detached mode is only supported in a container. - if config.Detached == true { + if config.Detached { return fmt.Errorf("Detached mode is only supported when running in a container, not locally") } @@ -394,7 +394,7 @@ func runQemuLocal(config QemuConfig) error { log.Debugf("%v\n", qemuCmd.Args) // If we're not using a separate window then link the execution to stdin/out - if config.GUI != true { + if !config.GUI { qemuCmd.Stdin = os.Stdin qemuCmd.Stdout = os.Stdout qemuCmd.Stderr = os.Stderr @@ -566,11 +566,11 @@ func buildQemuCmdline(config QemuConfig) (QemuConfig, []string) { qemuArgs = append(qemuArgs, "-netdev", config.NetdevConfig+forwardings) } - if config.GUI != true { + if !config.GUI { qemuArgs = append(qemuArgs, "-nographic") } - if config.USB == true { + if config.USB { qemuArgs = append(qemuArgs, "-usb") } for _, d := range config.Devices { diff --git a/src/cmd/linuxkit/run_vcenter.go b/src/cmd/linuxkit/run_vcenter.go index e19e0c7ca..2df6bc3ae 100644 --- a/src/cmd/linuxkit/run_vcenter.go +++ b/src/cmd/linuxkit/run_vcenter.go @@ -78,7 +78,7 @@ func runVcenter(args []string) { } *newVM.path = remArgs[0] - if (*newVM.guestIP == true) && *newVM.poweron != true { + if *newVM.guestIP && !*newVM.poweron { log.Fatalln("The waitForIP flag can not be used without the powerOn flag") } // Ensure an iso has been passed to the vCenter run Command @@ -140,7 +140,7 @@ func runVcenter(args []string) { addNIC(ctx, vm, net) } - if *newVM.poweron == true { + if *newVM.poweron { log.Infoln("Powering on LinuxKit VM") powerOnVM(ctx, vm) } @@ -261,7 +261,7 @@ func addNIC(ctx context.Context, vm *object.VirtualMachine, net object.NetworkRe var add []types.BaseVirtualDevice add = append(add, netdev) - if vm.AddDevice(ctx, add...); err != nil { + if err := vm.AddDevice(ctx, add...); err != nil { log.Fatalf("Unable to add new networking device to VM configuration\n%v", err) } } @@ -286,7 +286,7 @@ func addVMDK(ctx context.Context, vm *object.VirtualMachine, dss *object.Datasto log.Infof("Adding a persistent disk to the Virtual Machine") - if vm.AddDevice(ctx, add...); err != nil { + if err := vm.AddDevice(ctx, add...); err != nil { log.Fatalf("Unable to add new storage device to VM configuration\n%v", err) } } @@ -312,7 +312,7 @@ func addISO(ctx context.Context, newVM vmConfig, vm *object.VirtualMachine, dss log.Infof("Adding ISO to the Virtual Machine") - if vm.AddDevice(ctx, add...); err != nil { + if err := vm.AddDevice(ctx, add...); err != nil { log.Fatalf("Unable to add new CD-ROM device to VM configuration\n%v", err) } } diff --git a/src/cmd/linuxkit/run_virtualizationframework_darwin_cgo_enabled.go b/src/cmd/linuxkit/run_virtualizationframework_darwin_cgo_enabled.go index 3fd69b8b1..559c3f9b5 100644 --- a/src/cmd/linuxkit/run_virtualizationframework_darwin_cgo_enabled.go +++ b/src/cmd/linuxkit/run_virtualizationframework_darwin_cgo_enabled.go @@ -288,7 +288,7 @@ func setRawMode(f *os.File) { var attr unix.Termios // Get settings for terminal - termios.Tcgetattr(f.Fd(), &attr) + _ = termios.Tcgetattr(f.Fd(), &attr) // Put stdin into raw mode, disabling local echo, input canonicalization, // and CR-NL mapping. @@ -302,7 +302,7 @@ func setRawMode(f *os.File) { attr.Cc[syscall.VTIME] = 0 // reflects the changed settings - termios.Tcsetattr(f.Fd(), termios.TCSANOW, &attr) + _ = termios.Tcsetattr(f.Fd(), termios.TCSANOW, &attr) } func checkFileType(infile string) (string, error) { diff --git a/src/cmd/linuxkit/scaleway.go b/src/cmd/linuxkit/scaleway.go index 26c413597..9c90663d6 100644 --- a/src/cmd/linuxkit/scaleway.go +++ b/src/cmd/linuxkit/scaleway.go @@ -19,7 +19,7 @@ import ( "github.com/scaleway/scaleway-sdk-go/scw" log "github.com/sirupsen/logrus" "golang.org/x/crypto/ssh" - "golang.org/x/crypto/ssh/terminal" + "golang.org/x/term" ) var ( @@ -284,7 +284,7 @@ func getSSHAuth(sshKeyPath string) (ssh.Signer, error) { signer, err := ssh.ParsePrivateKey(buf) if err != nil { fmt.Print("Enter ssh key passphrase: ") - bytePassword, err := terminal.ReadPassword(int(syscall.Stdin)) + bytePassword, err := term.ReadPassword(int(syscall.Stdin)) // ReadPassword eats newline, put it back to avoid mangling logs fmt.Println() if err != nil { @@ -358,11 +358,11 @@ func (s *ScalewayClient) CopyImageToInstance(instanceID, path, sshKeyPath string } defer w.Close() fmt.Fprintln(w, "C0600", int64(len(contentBytes)), base) - io.Copy(w, bytesReader) + _, _ = io.Copy(w, bytesReader) fmt.Fprintln(w, "\x00") }() - session.Run("/usr/bin/scp -t /root/") // TODO remove hardcoded remote path? + _ = session.Run("/usr/bin/scp -t /root/") // TODO remove hardcoded remote path? return err } diff --git a/src/cmd/linuxkit/serve.go b/src/cmd/linuxkit/serve.go index 85bffb7da..a925a1609 100644 --- a/src/cmd/linuxkit/serve.go +++ b/src/cmd/linuxkit/serve.go @@ -28,7 +28,7 @@ func serve(args []string) { } portFlag := flags.String("port", ":8080", "Local port to serve on") dirFlag := flags.String("directory", ".", "Directory to serve") - flags.Parse(args) + _ = flags.Parse(args) http.Handle("/", http.FileServer(http.Dir(*dirFlag))) log.Fatal(http.ListenAndServe(*portFlag, logRequest(http.DefaultServeMux))) diff --git a/src/cmd/linuxkit/vendor/golang.org/x/crypto/ssh/terminal/terminal.go b/src/cmd/linuxkit/vendor/golang.org/x/crypto/ssh/terminal/terminal.go deleted file mode 100644 index a4d1919a9..000000000 --- a/src/cmd/linuxkit/vendor/golang.org/x/crypto/ssh/terminal/terminal.go +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright 2011 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package terminal provides support functions for dealing with terminals, as -// commonly found on UNIX systems. -// -// Deprecated: this package moved to golang.org/x/term. -package terminal - -import ( - "io" - - "golang.org/x/term" -) - -// EscapeCodes contains escape sequences that can be written to the terminal in -// order to achieve different styles of text. -type EscapeCodes = term.EscapeCodes - -// Terminal contains the state for running a VT100 terminal that is capable of -// reading lines of input. -type Terminal = term.Terminal - -// NewTerminal runs a VT100 terminal on the given ReadWriter. If the ReadWriter is -// a local terminal, that terminal must first have been put into raw mode. -// prompt is a string that is written at the start of each input line (i.e. -// "> "). -func NewTerminal(c io.ReadWriter, prompt string) *Terminal { - return term.NewTerminal(c, prompt) -} - -// ErrPasteIndicator may be returned from ReadLine as the error, in addition -// to valid line data. It indicates that bracketed paste mode is enabled and -// that the returned line consists only of pasted data. Programs may wish to -// interpret pasted data more literally than typed data. -var ErrPasteIndicator = term.ErrPasteIndicator - -// State contains the state of a terminal. -type State = term.State - -// IsTerminal returns whether the given file descriptor is a terminal. -func IsTerminal(fd int) bool { - return term.IsTerminal(fd) -} - -// ReadPassword reads a line of input from a terminal without local echo. This -// is commonly used for inputting passwords and other sensitive data. The slice -// returned does not include the \n. -func ReadPassword(fd int) ([]byte, error) { - return term.ReadPassword(fd) -} - -// MakeRaw puts the terminal connected to the given file descriptor into raw -// mode and returns the previous state of the terminal so that it can be -// restored. -func MakeRaw(fd int) (*State, error) { - return term.MakeRaw(fd) -} - -// Restore restores the terminal connected to the given file descriptor to a -// previous state. -func Restore(fd int, oldState *State) error { - return term.Restore(fd, oldState) -} - -// GetState returns the current state of a terminal which may be useful to -// restore the terminal after a signal. -func GetState(fd int) (*State, error) { - return term.GetState(fd) -} - -// GetSize returns the dimensions of the given terminal. -func GetSize(fd int) (width, height int, err error) { - return term.GetSize(fd) -} diff --git a/src/cmd/linuxkit/vendor/modules.txt b/src/cmd/linuxkit/vendor/modules.txt index 4d8a54474..ff7e64ff0 100644 --- a/src/cmd/linuxkit/vendor/modules.txt +++ b/src/cmd/linuxkit/vendor/modules.txt @@ -604,7 +604,6 @@ golang.org/x/crypto/pkcs12/internal/rc2 golang.org/x/crypto/ssh golang.org/x/crypto/ssh/agent golang.org/x/crypto/ssh/internal/bcrypt_pbkdf -golang.org/x/crypto/ssh/terminal # golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd ## explicit golang.org/x/net/context @@ -638,6 +637,7 @@ golang.org/x/sys/unix golang.org/x/sys/windows golang.org/x/sys/windows/registry # golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 +## explicit golang.org/x/term # golang.org/x/text v0.3.7 golang.org/x/text/secure/bidirule