Skip to content

Commit

Permalink
Fix lint error
Browse files Browse the repository at this point in the history
Signed-off-by: Kirtana Ashok <kiashok@microsoft.com>
  • Loading branch information
kiashok committed Oct 23, 2024
1 parent 648686a commit 0ef6949
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 57 deletions.
16 changes: 3 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ jobs:
matrix:
goos: [windows, linux]
root: ["", test] # cannot specify "./... ./test/..." unless in go workspace
include:
- goos: linux
root: ""
dirs: >-
./cmd/gcs/...
./cmd/gcstools/...
./internal/guest...
./internal/tools/...
./pkg/...
./ext4/...

steps:
- name: Checkout
Expand All @@ -40,15 +30,15 @@ jobs:

- uses: golangci/golangci-lint-action@v3
with:
version: v1.52
version: v1.54
args: >-
--verbose
--max-issues-per-linter=0
--max-same-issues=0
--modules-download-mode=readonly
--timeout=10m
${{ matrix.dirs }}
working-directory: ${{ matrix.root }}
--config=${{ github.workspace }}/.golangci.yml
working-directory: ${{ github.workspace }}/${{ matrix.root }}
env:
GOOS: ${{ matrix.goos }}

Expand Down
4 changes: 2 additions & 2 deletions cmd/containerd-shim-runhcs-v1/nopformatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/sirupsen/logrus"
)

type nopFormatter struct{}
type NopFormatter struct{}

// Format does nothing and returns a nil slice.
func (nopFormatter) Format(*logrus.Entry) ([]byte, error) { return nil, nil }
func (NopFormatter) Format(*logrus.Entry) ([]byte, error) { return nil, nil }
2 changes: 1 addition & 1 deletion cmd/containerd-shim-runhcs-v1/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func createPod(ctx context.Context, events publisher, req *task.CreateTaskReques
}

var parent *uvm.UtilityVM
var lopts *uvm.OptionsLCOW //nolint:staticcheck
var lopts *uvm.OptionsLCOW
if oci.IsIsolated(s) {
// Create the UVM parent
opts, err := oci.SpecToUVMCreateOpts(ctx, s, fmt.Sprintf("%s@vm", req.ID), owner)
Expand Down
2 changes: 1 addition & 1 deletion cmd/containerd-shim-runhcs-v1/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ var serveCommand = cli.Command{
case runhcsopts.Options_FILE:
panic("file log output mode is not supported")
case runhcsopts.Options_ETW:
logrus.SetFormatter(nopFormatter{})
logrus.SetFormatter(NopFormatter{})
logrus.SetOutput(io.Discard)
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/ncproxy/ncproxy_v0_service.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/ncproxy/ncproxy_v0_service_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
2 changes: 2 additions & 0 deletions cmd/ncproxy/utilities_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package main

import (
Expand Down
6 changes: 0 additions & 6 deletions internal/cmd/io_npipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"context"
"fmt"
"io"
"math/rand"
"net"
"sync"
"syscall"
Expand All @@ -20,11 +19,6 @@ import (
"golang.org/x/sys/windows"
)

func init() {
// Need to seed for the rng in backoff.NextBackoff()
rand.Seed(time.Now().UnixNano())
}

// NewNpipeIO creates connected upstream io. It is the callers responsibility to validate that `if terminal == true`, `stderr == ""`. retryTimeout
// refers to the timeout used to try and reconnect to the server end of the named pipe if the connection is severed. A value of 0 for retryTimeout
// is treated as an infinite timeout.
Expand Down
2 changes: 2 additions & 0 deletions internal/gcs/iochannel.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package gcs

import (
Expand Down
12 changes: 6 additions & 6 deletions internal/oci/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ func ParseAnnotationsBool(ctx context.Context, a map[string]string, key string,
return def
}

// parseAnnotationsUint32 searches `a` for `key` and if found verifies that the
// ParseAnnotationsUint32 searches `a` for `key` and if found verifies that the
// value is a 32 bit unsigned integer. If `key` is not found returns `def`.
func parseAnnotationsUint32(ctx context.Context, a map[string]string, key string, def uint32) uint32 {
func ParseAnnotationsUint32(ctx context.Context, a map[string]string, key string, def uint32) uint32 {
if v, ok := a[key]; ok {
countu, err := strconv.ParseUint(v, 10, 32)
if err == nil {
Expand All @@ -92,9 +92,9 @@ func parseAnnotationsUint32(ctx context.Context, a map[string]string, key string
return def
}

// parseAnnotationsUint64 searches `a` for `key` and if found verifies that the
// ParseAnnotationsUint64 searches `a` for `key` and if found verifies that the
// value is a 64 bit unsigned integer. If `key` is not found returns `def`.
func parseAnnotationsUint64(ctx context.Context, a map[string]string, key string, def uint64) uint64 {
func ParseAnnotationsUint64(ctx context.Context, a map[string]string, key string, def uint64) uint64 {
if v, ok := a[key]; ok {
countu, err := strconv.ParseUint(v, 10, 64)
if err == nil {
Expand All @@ -105,8 +105,8 @@ func parseAnnotationsUint64(ctx context.Context, a map[string]string, key string
return def
}

// parseAnnotationsString searches `a` for `key`. If `key` is not found returns `def`.
func parseAnnotationsString(a map[string]string, key string, def string) string {
// ParseAnnotationsString searches `a` for `key`. If `key` is not found returns `def`.
func ParseAnnotationsString(a map[string]string, key string, def string) string {
if v, ok := a[key]; ok {
return v
}
Expand Down
44 changes: 22 additions & 22 deletions internal/oci/uvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// not found searches `s` for the Windows CPU section. If neither are found
// returns `def`.
func ParseAnnotationsCPUCount(ctx context.Context, s *specs.Spec, annotation string, def int32) int32 {
if m := parseAnnotationsUint64(ctx, s.Annotations, annotation, 0); m != 0 {
if m := ParseAnnotationsUint64(ctx, s.Annotations, annotation, 0); m != 0 {
return int32(m)
}
if s.Windows != nil &&
Expand All @@ -38,7 +38,7 @@ func ParseAnnotationsCPUCount(ctx context.Context, s *specs.Spec, annotation str
// not found searches `s` for the Windows CPU section. If neither are found
// returns `def`.
func ParseAnnotationsCPULimit(ctx context.Context, s *specs.Spec, annotation string, def int32) int32 {
if m := parseAnnotationsUint64(ctx, s.Annotations, annotation, 0); m != 0 {
if m := ParseAnnotationsUint64(ctx, s.Annotations, annotation, 0); m != 0 {
return int32(m)
}
if s.Windows != nil &&
Expand All @@ -55,7 +55,7 @@ func ParseAnnotationsCPULimit(ctx context.Context, s *specs.Spec, annotation str
// not found searches `s` for the Windows CPU section. If neither are found
// returns `def`.
func ParseAnnotationsCPUWeight(ctx context.Context, s *specs.Spec, annotation string, def int32) int32 {
if m := parseAnnotationsUint64(ctx, s.Annotations, annotation, 0); m != 0 {
if m := ParseAnnotationsUint64(ctx, s.Annotations, annotation, 0); m != 0 {
return int32(m)
}
if s.Windows != nil &&
Expand All @@ -72,7 +72,7 @@ func ParseAnnotationsCPUWeight(ctx context.Context, s *specs.Spec, annotation st
// annotation. If not found searches `s` for the Windows Storage section. If
// neither are found returns `def`.
func ParseAnnotationsStorageIops(ctx context.Context, s *specs.Spec, annotation string, def int32) int32 {
if m := parseAnnotationsUint64(ctx, s.Annotations, annotation, 0); m != 0 {
if m := ParseAnnotationsUint64(ctx, s.Annotations, annotation, 0); m != 0 {
return int32(m)
}
if s.Windows != nil &&
Expand All @@ -89,7 +89,7 @@ func ParseAnnotationsStorageIops(ctx context.Context, s *specs.Spec, annotation
// If not found searches `s` for the Windows Storage section. If neither are
// found returns `def`.
func ParseAnnotationsStorageBps(ctx context.Context, s *specs.Spec, annotation string, def int32) int32 {
if m := parseAnnotationsUint64(ctx, s.Annotations, annotation, 0); m != 0 {
if m := ParseAnnotationsUint64(ctx, s.Annotations, annotation, 0); m != 0 {
return int32(m)
}
if s.Windows != nil &&
Expand All @@ -108,7 +108,7 @@ func ParseAnnotationsStorageBps(ctx context.Context, s *specs.Spec, annotation s
//
// Note: The returned value is in `MB`.
func ParseAnnotationsMemory(ctx context.Context, s *specs.Spec, annotation string, def uint64) uint64 {
if m := parseAnnotationsUint64(ctx, s.Annotations, annotation, 0); m != 0 {
if m := ParseAnnotationsUint64(ctx, s.Annotations, annotation, 0); m != 0 {
return m
}
if s.Windows != nil &&
Expand Down Expand Up @@ -184,7 +184,7 @@ func handleAnnotationFullyPhysicallyBacked(ctx context.Context, a map[string]str
// handleSecurityPolicy handles parsing SecurityPolicy and NoSecurityHardware and setting
// implied options from the results. Both LCOW only, not WCOW
func handleSecurityPolicy(ctx context.Context, a map[string]string, lopts *uvm.OptionsLCOW) {
lopts.SecurityPolicy = parseAnnotationsString(a, annotations.SecurityPolicy, lopts.SecurityPolicy)
lopts.SecurityPolicy = ParseAnnotationsString(a, annotations.SecurityPolicy, lopts.SecurityPolicy)
// allow actual isolated boot etc to be ignored if we have no hardware. Required for dev
// this is not a security issue as the attestation will fail without a genuine report
noSecurityHardware := ParseAnnotationsBool(ctx, a, annotations.NoSecurityHardware, false)
Expand Down Expand Up @@ -213,21 +213,21 @@ func handleSecurityPolicy(ctx context.Context, a map[string]string, lopts *uvm.O
// sets options common to both WCOW and LCOW from annotations
func specToUVMCreateOptionsCommon(ctx context.Context, opts *uvm.Options, s *specs.Spec) {
opts.MemorySizeInMB = ParseAnnotationsMemory(ctx, s, annotations.MemorySizeInMB, opts.MemorySizeInMB)
opts.LowMMIOGapInMB = parseAnnotationsUint64(ctx, s.Annotations, annotations.MemoryLowMMIOGapInMB, opts.LowMMIOGapInMB)
opts.HighMMIOBaseInMB = parseAnnotationsUint64(ctx, s.Annotations, annotations.MemoryHighMMIOBaseInMB, opts.HighMMIOBaseInMB)
opts.HighMMIOGapInMB = parseAnnotationsUint64(ctx, s.Annotations, annotations.MemoryHighMMIOGapInMB, opts.HighMMIOGapInMB)
opts.LowMMIOGapInMB = ParseAnnotationsUint64(ctx, s.Annotations, annotations.MemoryLowMMIOGapInMB, opts.LowMMIOGapInMB)
opts.HighMMIOBaseInMB = ParseAnnotationsUint64(ctx, s.Annotations, annotations.MemoryHighMMIOBaseInMB, opts.HighMMIOBaseInMB)
opts.HighMMIOGapInMB = ParseAnnotationsUint64(ctx, s.Annotations, annotations.MemoryHighMMIOGapInMB, opts.HighMMIOGapInMB)
opts.AllowOvercommit = ParseAnnotationsBool(ctx, s.Annotations, annotations.AllowOvercommit, opts.AllowOvercommit)
opts.EnableDeferredCommit = ParseAnnotationsBool(ctx, s.Annotations, annotations.EnableDeferredCommit, opts.EnableDeferredCommit)
opts.ProcessorCount = ParseAnnotationsCPUCount(ctx, s, annotations.ProcessorCount, opts.ProcessorCount)
opts.ProcessorLimit = ParseAnnotationsCPULimit(ctx, s, annotations.ProcessorLimit, opts.ProcessorLimit)
opts.ProcessorWeight = ParseAnnotationsCPUWeight(ctx, s, annotations.ProcessorWeight, opts.ProcessorWeight)
opts.StorageQoSBandwidthMaximum = ParseAnnotationsStorageBps(ctx, s, annotations.StorageQoSBandwidthMaximum, opts.StorageQoSBandwidthMaximum)
opts.StorageQoSIopsMaximum = ParseAnnotationsStorageIops(ctx, s, annotations.StorageQoSIopsMaximum, opts.StorageQoSIopsMaximum)
opts.CPUGroupID = parseAnnotationsString(s.Annotations, annotations.CPUGroupID, opts.CPUGroupID)
opts.NetworkConfigProxy = parseAnnotationsString(s.Annotations, annotations.NetworkConfigProxy, opts.NetworkConfigProxy)
opts.ProcessDumpLocation = parseAnnotationsString(s.Annotations, annotations.ContainerProcessDumpLocation, opts.ProcessDumpLocation)
opts.CPUGroupID = ParseAnnotationsString(s.Annotations, annotations.CPUGroupID, opts.CPUGroupID)
opts.NetworkConfigProxy = ParseAnnotationsString(s.Annotations, annotations.NetworkConfigProxy, opts.NetworkConfigProxy)
opts.ProcessDumpLocation = ParseAnnotationsString(s.Annotations, annotations.ContainerProcessDumpLocation, opts.ProcessDumpLocation)
opts.NoWritableFileShares = ParseAnnotationsBool(ctx, s.Annotations, annotations.DisableWritableFileShares, opts.NoWritableFileShares)
opts.DumpDirectoryPath = parseAnnotationsString(s.Annotations, annotations.DumpDirectoryPath, opts.DumpDirectoryPath)
opts.DumpDirectoryPath = ParseAnnotationsString(s.Annotations, annotations.DumpDirectoryPath, opts.DumpDirectoryPath)
}

// SpecToUVMCreateOpts parses `s` and returns either `*uvm.OptionsLCOW` or
Expand All @@ -250,16 +250,16 @@ func SpecToUVMCreateOpts(ctx context.Context, s *specs.Spec, id, owner string) (
*/

lopts.EnableColdDiscardHint = ParseAnnotationsBool(ctx, s.Annotations, annotations.EnableColdDiscardHint, lopts.EnableColdDiscardHint)
lopts.VPMemDeviceCount = parseAnnotationsUint32(ctx, s.Annotations, annotations.VPMemCount, lopts.VPMemDeviceCount)
lopts.VPMemSizeBytes = parseAnnotationsUint64(ctx, s.Annotations, annotations.VPMemSize, lopts.VPMemSizeBytes)
lopts.VPMemDeviceCount = ParseAnnotationsUint32(ctx, s.Annotations, annotations.VPMemCount, lopts.VPMemDeviceCount)
lopts.VPMemSizeBytes = ParseAnnotationsUint64(ctx, s.Annotations, annotations.VPMemSize, lopts.VPMemSizeBytes)
lopts.VPMemNoMultiMapping = ParseAnnotationsBool(ctx, s.Annotations, annotations.VPMemNoMultiMapping, lopts.VPMemNoMultiMapping)
lopts.VPCIEnabled = ParseAnnotationsBool(ctx, s.Annotations, annotations.VPCIEnabled, lopts.VPCIEnabled)
lopts.BootFilesPath = parseAnnotationsString(s.Annotations, annotations.BootFilesRootPath, lopts.BootFilesPath)
lopts.BootFilesPath = ParseAnnotationsString(s.Annotations, annotations.BootFilesRootPath, lopts.BootFilesPath)
lopts.EnableScratchEncryption = ParseAnnotationsBool(ctx, s.Annotations, annotations.EncryptedScratchDisk, lopts.EnableScratchEncryption)
lopts.SecurityPolicy = parseAnnotationsString(s.Annotations, annotations.SecurityPolicy, lopts.SecurityPolicy)
lopts.SecurityPolicyEnforcer = parseAnnotationsString(s.Annotations, annotations.SecurityPolicyEnforcer, lopts.SecurityPolicyEnforcer)
lopts.UVMReferenceInfoFile = parseAnnotationsString(s.Annotations, annotations.UVMReferenceInfoFile, lopts.UVMReferenceInfoFile)
lopts.KernelBootOptions = parseAnnotationsString(s.Annotations, annotations.KernelBootOptions, lopts.KernelBootOptions)
lopts.SecurityPolicy = ParseAnnotationsString(s.Annotations, annotations.SecurityPolicy, lopts.SecurityPolicy)
lopts.SecurityPolicyEnforcer = ParseAnnotationsString(s.Annotations, annotations.SecurityPolicyEnforcer, lopts.SecurityPolicyEnforcer)
lopts.UVMReferenceInfoFile = ParseAnnotationsString(s.Annotations, annotations.UVMReferenceInfoFile, lopts.UVMReferenceInfoFile)
lopts.KernelBootOptions = ParseAnnotationsString(s.Annotations, annotations.KernelBootOptions, lopts.KernelBootOptions)
lopts.DisableTimeSyncService = ParseAnnotationsBool(ctx, s.Annotations, annotations.DisableLCOWTimeSyncService, lopts.DisableTimeSyncService)
handleAnnotationPreferredRootFSType(ctx, s.Annotations, lopts)
handleAnnotationKernelDirectBoot(ctx, s.Annotations, lopts)
Expand All @@ -273,7 +273,7 @@ func SpecToUVMCreateOpts(ctx context.Context, s *specs.Spec, id, owner string) (
handleSecurityPolicy(ctx, s.Annotations, lopts)

// override the default GuestState filename if specified
lopts.GuestStateFile = parseAnnotationsString(s.Annotations, annotations.GuestStateFile, lopts.GuestStateFile)
lopts.GuestStateFile = ParseAnnotationsString(s.Annotations, annotations.GuestStateFile, lopts.GuestStateFile)
return lopts, nil
} else if IsWCOW(s) {
wopts := uvm.NewDefaultOptionsWCOW(id, owner)
Expand Down
2 changes: 2 additions & 0 deletions internal/uvm/constants.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package uvm

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/wclayer/baselayerreader.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package wclayer

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/wclayer/converttobaselayer.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build windows

package wclayer

import (
Expand Down
7 changes: 1 addition & 6 deletions internal/winapi/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package winapi

import (
"errors"
"reflect"
"syscall"
"unsafe"

Expand All @@ -14,11 +13,7 @@ import (
// Uint16BufferToSlice wraps a uint16 pointer-and-length into a slice
// for easier interop with Go APIs
func Uint16BufferToSlice(buffer *uint16, bufferLength int) (result []uint16) {
hdr := (*reflect.SliceHeader)(unsafe.Pointer(&result))
hdr.Data = uintptr(unsafe.Pointer(buffer))
hdr.Cap = bufferLength
hdr.Len = bufferLength

result = unsafe.Slice(buffer, bufferLength)
return
}

Expand Down

0 comments on commit 0ef6949

Please sign in to comment.