Skip to content

Commit

Permalink
Merge pull request #21753 from mheon/mac_lint
Browse files Browse the repository at this point in the history
Enable lint for Darwin and fix identified issues
  • Loading branch information
openshift-merge-bot[bot] authored Feb 26, 2024
2 parents 2313569 + 19b676f commit 25cbff1
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ osx_alt_build_task:
# The previous task may have been canceled or aborted.
prep_script: &mac_cleanup "contrib/cirrus/mac_cleanup.sh"
lint_script:
- make lint || true # TODO: Enable when code passes check
- make golangci-lint
basic_build_script:
- make .install.ginkgo
- make podman-remote
Expand Down
12 changes: 6 additions & 6 deletions cmd/podman-mac-helper/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
)

const (
rwx_rx_rx = 0755
rw_r_r = 0644
mode755 = 0755
mode644 = 0644
)

const launchConfig = `<?xml version="1.0" encoding="UTF-8"?>
Expand Down Expand Up @@ -109,7 +109,7 @@ func install(cmd *cobra.Command, args []string) error {
return err
}

file, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE|os.O_EXCL, rw_r_r)
file, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE|os.O_EXCL, mode644)
if err != nil {
return fmt.Errorf("creating helper plist file: %w", err)
}
Expand Down Expand Up @@ -138,7 +138,7 @@ func restrictRecursive(targetDir string, until string) error {
if err = os.Chown(targetDir, 0, 0); err != nil {
return fmt.Errorf("could not update ownership of helper path: %w", err)
}
if err = os.Chmod(targetDir, rwx_rx_rx|fs.ModeSticky); err != nil {
if err = os.Chmod(targetDir, mode755|fs.ModeSticky); err != nil {
return fmt.Errorf("could not update permissions of helper path: %w", err)
}
targetDir = filepath.Dir(targetDir)
Expand Down Expand Up @@ -205,7 +205,7 @@ func installExecutable(user string) (string, error) {
}

targetDir := filepath.Join(installPrefix, "podman", "helper", user)
if err := os.MkdirAll(targetDir, rwx_rx_rx); err != nil {
if err := os.MkdirAll(targetDir, mode755); err != nil {
return "", fmt.Errorf("could not create helper directory structure: %w", err)
}

Expand All @@ -220,7 +220,7 @@ func installExecutable(user string) (string, error) {
}
install := filepath.Join(targetDir, filepath.Base(exec))

return install, copyFile(install, exec, rwx_rx_rx)
return install, copyFile(install, exec, mode755)
}

func copyFile(dest string, source string, perms fs.FileMode) error {
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman-mac-helper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func getUserInfo(name string) (string, string, string, error) {
entry := readCapped(output)
elements := strings.Split(entry, ":")
if len(elements) < 9 || elements[0] != name {
return "", "", "", errors.New("Could not look up user")
return "", "", "", errors.New("could not look up user")
}

return elements[0], elements[2], elements[8], nil
Expand Down
6 changes: 3 additions & 3 deletions cmd/podman-mac-helper/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
package main

import (
"errors"
"fmt"
"io/fs"
"os"
"os/exec"
"path/filepath"
"io/fs"
"errors"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -67,7 +67,7 @@ func uninstall(cmd *cobra.Command, args []string) error {
return fmt.Errorf("could not stat dockerSock: %v", err)
}
if target, err := os.Readlink(dockerSock); err != nil {
//Return an error if unable to read the symlink
// Return an error if unable to read the symlink
return fmt.Errorf("could not read dockerSock symlink: %v", err)
} else {
// Check if the target of the symlink matches the expected target
Expand Down
2 changes: 1 addition & 1 deletion pkg/machine/applehv/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func generateSystemDFilesForVirtiofsMounts(mounts []machine.VirtIoFs) []ignition
// for automatic mounting on boot, and a "preparatory" service file that disables FCOS security, performs
// the mkdir of the mount point, and then re-enables security. This must be done for each mount.

var unitFiles []ignition.Unit
unitFiles := make([]ignition.Unit, 0, len(mounts))
for _, mnt := range mounts {
// Here we are looping the mounts and for each mount, we are adding two unit files
// for virtiofs. One unit file is the mount itself and the second is to automount it
Expand Down
2 changes: 1 addition & 1 deletion pkg/machine/applehv/stubber.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (a AppleHVStubber) CreateVM(opts define.CreateVMOpts, mc *vmconfigs.Machine
}
mc.AppleHypervisor.Vfkit.Endpoint = localhostURI + ":" + strconv.Itoa(randPort)

var virtiofsMounts []machine.VirtIoFs
virtiofsMounts := make([]machine.VirtIoFs, 0, len(mc.Mounts))
for _, mnt := range mc.Mounts {
virtiofsMounts = append(virtiofsMounts, machine.MountToVirtIOFs(mnt))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/machine/applehv/vfkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func getIgnitionVsockDevice(path string) (vfConfig.VirtioDevice, error) {
}

func virtIOFsToVFKitVirtIODevice(mounts []*vmconfigs.Mount) ([]vfConfig.VirtioDevice, error) {
var virtioDevices []vfConfig.VirtioDevice
virtioDevices := make([]vfConfig.VirtioDevice, 0, len(mounts))
for _, vol := range mounts {
virtfsDevice, err := vfConfig.VirtioFsNew(vol.Source, vol.Tag)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/machine/applehv/vfkit/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ func (vf *VfkitHelper) stateChange(newState rest.StateChange) error {
return err
}
payload := bytes.NewReader(b)
_, err = vf.post(vf.Endpoint+state, payload)
serverResponse, err := vf.post(vf.Endpoint+state, payload)
_ = serverResponse.Body.Close()
return err
}

Expand Down

0 comments on commit 25cbff1

Please sign in to comment.