From 31d310a4b1441fb383d4e1cf1ce6d5b17b4c07b5 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Thu, 19 May 2022 10:45:28 +0200 Subject: linter: enable unconvert linter Detects unneccessary type conversions and helps in keeping the code base cleaner. Signed-off-by: Valentin Rothberg --- pkg/api/handlers/compat/containers.go | 6 +++--- pkg/api/handlers/compat/images_build.go | 2 +- pkg/bindings/images/build_unix.go | 4 ++-- pkg/domain/infra/abi/containers.go | 2 +- pkg/domain/infra/abi/parse/parse.go | 2 +- pkg/domain/infra/abi/system.go | 6 +++--- pkg/k8s.io/apimachinery/pkg/api/resource/amount.go | 2 +- pkg/k8s.io/apimachinery/pkg/api/resource/quantity.go | 4 ++-- pkg/specgen/generate/config_linux.go | 2 +- pkg/specgen/generate/container.go | 16 ++++++++-------- pkg/specgen/generate/oci.go | 2 +- 11 files changed, 24 insertions(+), 24 deletions(-) (limited to 'pkg') diff --git a/pkg/api/handlers/compat/containers.go b/pkg/api/handlers/compat/containers.go index 1c339730e..e3d51fadf 100644 --- a/pkg/api/handlers/compat/containers.go +++ b/pkg/api/handlers/compat/containers.go @@ -254,7 +254,7 @@ func KillContainer(w http.ResponseWriter, r *http.Request) { utils.InternalServerError(w, err) return } - if sig == 0 || syscall.Signal(sig) == syscall.SIGKILL { + if sig == 0 || sig == syscall.SIGKILL { opts := entities.WaitOptions{ Condition: []define.ContainerStatus{define.ContainerStateExited, define.ContainerStateStopped}, Interval: time.Millisecond * 250, @@ -341,8 +341,8 @@ func LibpodToContainer(l *libpod.Container, sz bool) (*handlers.Container, error for idx, portMapping := range portMappings { ports[idx] = types.Port{ IP: portMapping.HostIP, - PrivatePort: uint16(portMapping.ContainerPort), - PublicPort: uint16(portMapping.HostPort), + PrivatePort: portMapping.ContainerPort, + PublicPort: portMapping.HostPort, Type: portMapping.Protocol, } } diff --git a/pkg/api/handlers/compat/images_build.go b/pkg/api/handlers/compat/images_build.go index f0d07f492..da5216040 100644 --- a/pkg/api/handlers/compat/images_build.go +++ b/pkg/api/handlers/compat/images_build.go @@ -568,7 +568,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { Output: output, OutputFormat: format, PullPolicy: pullPolicy, - PullPushRetryDelay: time.Duration(2 * time.Second), + PullPushRetryDelay: 2 * time.Second, Quiet: query.Quiet, Registry: registry, RemoveIntermediateCtrs: query.Rm, diff --git a/pkg/bindings/images/build_unix.go b/pkg/bindings/images/build_unix.go index 67a5e2998..32e2ba9af 100644 --- a/pkg/bindings/images/build_unix.go +++ b/pkg/bindings/images/build_unix.go @@ -11,7 +11,7 @@ import ( func checkHardLink(fi os.FileInfo) (devino, bool) { st := fi.Sys().(*syscall.Stat_t) return devino{ - Dev: uint64(st.Dev), - Ino: uint64(st.Ino), + Dev: uint64(st.Dev), // nolint: unconvert + Ino: st.Ino, }, st.Nlink > 1 } diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go index 5ca678d6f..0bca103e5 100644 --- a/pkg/domain/infra/abi/containers.go +++ b/pkg/domain/infra/abi/containers.go @@ -1107,7 +1107,7 @@ func (ic *ContainerEngine) GetContainerExitCode(ctx context.Context, ctr *libpod time.Sleep(250 * time.Millisecond) continue } - return int(event.ContainerExitCode) + return event.ContainerExitCode } logrus.Errorf("Could not retrieve exit code from event: %v", err) return define.ExecErrorCodeNotFound diff --git a/pkg/domain/infra/abi/parse/parse.go b/pkg/domain/infra/abi/parse/parse.go index 3bac2ef99..66794e592 100644 --- a/pkg/domain/infra/abi/parse/parse.go +++ b/pkg/domain/infra/abi/parse/parse.go @@ -43,7 +43,7 @@ func VolumeOptions(opts map[string]string) ([]libpod.VolumeCreateOption, error) if err != nil { return nil, errors.Wrapf(err, "cannot convert inodes %s to integer", splitO[1]) } - libpodOptions = append(libpodOptions, libpod.WithVolumeInodes(uint64(inodes))) + libpodOptions = append(libpodOptions, libpod.WithVolumeInodes(inodes)) finalVal = append(finalVal, o) // set option "INODES": "$size" volumeOptions["INODES"] = splitO[1] diff --git a/pkg/domain/infra/abi/system.go b/pkg/domain/infra/abi/system.go index 17df0e3f8..10f3e70b1 100644 --- a/pkg/domain/infra/abi/system.go +++ b/pkg/domain/infra/abi/system.go @@ -216,9 +216,9 @@ func (ic *ContainerEngine) SystemDf(ctx context.Context, options entities.System Tag: stat.Tag, ImageID: stat.ID, Created: stat.Created, - Size: int64(stat.Size), - SharedSize: int64(stat.SharedSize), - UniqueSize: int64(stat.UniqueSize), + Size: stat.Size, + SharedSize: stat.SharedSize, + UniqueSize: stat.UniqueSize, Containers: stat.Containers, } dfImages = append(dfImages, &report) diff --git a/pkg/k8s.io/apimachinery/pkg/api/resource/amount.go b/pkg/k8s.io/apimachinery/pkg/api/resource/amount.go index 9f76f9154..d05984dac 100644 --- a/pkg/k8s.io/apimachinery/pkg/api/resource/amount.go +++ b/pkg/k8s.io/apimachinery/pkg/api/resource/amount.go @@ -221,7 +221,7 @@ func (a int64Amount) AsCanonicalBytes(out []byte) (result []byte, exponent int32 exponent = int32(a.scale) amount, times := removeInt64Factors(mantissa, 10) - exponent += int32(times) + exponent += times // make sure exponent is a multiple of 3 var ok bool diff --git a/pkg/k8s.io/apimachinery/pkg/api/resource/quantity.go b/pkg/k8s.io/apimachinery/pkg/api/resource/quantity.go index 965d2ccaf..dcc5df219 100644 --- a/pkg/k8s.io/apimachinery/pkg/api/resource/quantity.go +++ b/pkg/k8s.io/apimachinery/pkg/api/resource/quantity.go @@ -293,7 +293,7 @@ func ParseQuantity(str string) (Quantity, error) { switch { case exponent >= 0 && len(denom) == 0: // only handle positive binary numbers with the fast path - mantissa = int64(int64(mantissa) << uint64(exponent)) + mantissa <<= uint64(exponent) // 1Mi (2^20) has ~6 digits of decimal precision, so exponent*3/10 -1 is roughly the precision precision = 15 - int32(len(num)) - int32(float32(exponent)*3/10) - 1 default: @@ -313,7 +313,7 @@ func ParseQuantity(str string) (Quantity, error) { if err != nil { return Quantity{}, ErrNumeric } - if result, ok := int64Multiply(value, int64(mantissa)); ok { + if result, ok := int64Multiply(value, mantissa); ok { if !positive { result = -result } diff --git a/pkg/specgen/generate/config_linux.go b/pkg/specgen/generate/config_linux.go index 8f83fc09b..ed2e5408d 100644 --- a/pkg/specgen/generate/config_linux.go +++ b/pkg/specgen/generate/config_linux.go @@ -327,7 +327,7 @@ func deviceFromPath(path string) (*spec.LinuxDevice, error) { var ( devType string mode = stat.Mode - devNumber = uint64(stat.Rdev) + devNumber = uint64(stat.Rdev) // nolint: unconvert m = os.FileMode(mode) ) diff --git a/pkg/specgen/generate/container.go b/pkg/specgen/generate/container.go index 63caaa77c..e3523dfd2 100644 --- a/pkg/specgen/generate/container.go +++ b/pkg/specgen/generate/container.go @@ -302,8 +302,8 @@ func FinishThrottleDevices(s *specgen.SpecGenerator) error { if err := unix.Stat(k, &statT); err != nil { return err } - v.Major = (int64(unix.Major(uint64(statT.Rdev)))) - v.Minor = (int64(unix.Minor(uint64(statT.Rdev)))) + v.Major = (int64(unix.Major(uint64(statT.Rdev)))) // nolint: unconvert + v.Minor = (int64(unix.Minor(uint64(statT.Rdev)))) // nolint: unconvert if s.ResourceLimits.BlockIO == nil { s.ResourceLimits.BlockIO = new(spec.LinuxBlockIO) } @@ -316,8 +316,8 @@ func FinishThrottleDevices(s *specgen.SpecGenerator) error { if err := unix.Stat(k, &statT); err != nil { return err } - v.Major = (int64(unix.Major(uint64(statT.Rdev)))) - v.Minor = (int64(unix.Minor(uint64(statT.Rdev)))) + v.Major = (int64(unix.Major(uint64(statT.Rdev)))) // nolint: unconvert + v.Minor = (int64(unix.Minor(uint64(statT.Rdev)))) // nolint: unconvert s.ResourceLimits.BlockIO.ThrottleWriteBpsDevice = append(s.ResourceLimits.BlockIO.ThrottleWriteBpsDevice, v) } } @@ -327,8 +327,8 @@ func FinishThrottleDevices(s *specgen.SpecGenerator) error { if err := unix.Stat(k, &statT); err != nil { return err } - v.Major = (int64(unix.Major(uint64(statT.Rdev)))) - v.Minor = (int64(unix.Minor(uint64(statT.Rdev)))) + v.Major = (int64(unix.Major(uint64(statT.Rdev)))) // nolint: unconvert + v.Minor = (int64(unix.Minor(uint64(statT.Rdev)))) // nolint: unconvert s.ResourceLimits.BlockIO.ThrottleReadIOPSDevice = append(s.ResourceLimits.BlockIO.ThrottleReadIOPSDevice, v) } } @@ -338,8 +338,8 @@ func FinishThrottleDevices(s *specgen.SpecGenerator) error { if err := unix.Stat(k, &statT); err != nil { return err } - v.Major = (int64(unix.Major(uint64(statT.Rdev)))) - v.Minor = (int64(unix.Minor(uint64(statT.Rdev)))) + v.Major = (int64(unix.Major(uint64(statT.Rdev)))) // nolint: unconvert + v.Minor = (int64(unix.Minor(uint64(statT.Rdev)))) // nolint: unconvert s.ResourceLimits.BlockIO.ThrottleWriteIOPSDevice = append(s.ResourceLimits.BlockIO.ThrottleWriteIOPSDevice, v) } } diff --git a/pkg/specgen/generate/oci.go b/pkg/specgen/generate/oci.go index b77c00f50..081df0441 100644 --- a/pkg/specgen/generate/oci.go +++ b/pkg/specgen/generate/oci.go @@ -377,7 +377,7 @@ func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runt if err := unix.Stat(k, &statT); err != nil { return nil, errors.Wrapf(err, "failed to inspect '%s' in --blkio-weight-device", k) } - g.AddLinuxResourcesBlockIOWeightDevice((int64(unix.Major(uint64(statT.Rdev)))), (int64(unix.Minor(uint64(statT.Rdev)))), *v.Weight) + g.AddLinuxResourcesBlockIOWeightDevice((int64(unix.Major(uint64(statT.Rdev)))), (int64(unix.Minor(uint64(statT.Rdev)))), *v.Weight) // nolint: unconvert } BlockAccessToKernelFilesystems(s.Privileged, s.PidNS.IsHost(), s.Mask, s.Unmask, &g) -- cgit v1.2.3-54-g00ecf