Skip to content

Commit 6886e8a

Browse files
committed
chore: upgrade golangci-lint to v1.44.2
Bump golangci-lint from v1.21.0 to v1.44.2 Removes deprecated linters and adds recommended replacement linters 'revive' and 'exportloopref'. Marks G306 and G307 as excluded until those errors can be audited seperately. Removes an instance of unused variable flagged by 'unused' linter. Updates few instances of local variable names to be inline with 'revive' naming standards. Updates few instances of exported function names to be inline with 'revive' naming standards. Fixes a couple of instances where 'append' was being used to initialize slice without using variadic operator to pass slice. Signed-off-by: Austin Vazquez <[email protected]>
1 parent 02a7a94 commit 6886e8a

File tree

8 files changed

+25
-24
lines changed

8 files changed

+25
-24
lines changed

.golangci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,16 @@ linters:
1313
- ineffassign
1414
- deadcode
1515
- typecheck
16-
- golint
1716
- gosec
1817
- unconvert
1918
- goconst
2019
- goimports
2120
- misspell
2221
- prealloc
23-
- scopelint
2422
- gocritic
25-
- interfacer # Suggests narrower interface types
26-
- scopelint # Checks for unpinned variables
2723
- gofmt
24+
- revive
25+
- exportloopref
2826

2927
issues:
3028
exclude-use-default: false
@@ -33,3 +31,5 @@ issues:
3331
- G103 # Use of unsafe calls should be audited
3432
- G204 # Subprocess launched with variable
3533
- G304 # Potential file inclusion via variable
34+
- G306 # WriteFile permissions 0600 or less to be audited
35+
- G307 # Deferring unsafe method "Close" on type "*os.File" to be audited

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ tidy:
112112
go mod tidy
113113

114114
deps:
115-
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(BINPATH) v1.21.0
115+
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(BINPATH) v1.44.2
116116
$(BINPATH)/golangci-lint --version
117117
GOBIN=$(BINPATH) GO111MODULE=off go get -u github.com/vbatts/git-validation
118118
GOBIN=$(BINPATH) GO111MODULE=off go get -u github.com/kunalkushwaha/ltag

agent/service.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ func (ts *TaskService) Create(requestCtx context.Context, req *taskAPI.CreateTas
189189
return nil
190190
})
191191

192-
isVmLocalRootFs := len(req.Rootfs) > 0 && vm.IsLocalMount(req.Rootfs[0])
192+
isVMLocalRootFs := len(req.Rootfs) > 0 && vm.IsLocalMount(req.Rootfs[0])
193193

194194
// If the rootfs is inside the VM, then the DriveMount call didn't happen and therefore
195195
// the bundledir was not created. Create it here.
196-
if isVmLocalRootFs {
196+
if isVMLocalRootFs {
197197
if err := os.MkdirAll(bundleDir.RootfsPath(), 0700); err != nil {
198198
return nil, errors.Wrapf(err, "Failed to create bundle's rootfs path from inside the vm %q", bundleDir.RootfsPath())
199199
}
@@ -219,7 +219,7 @@ func (ts *TaskService) Create(requestCtx context.Context, req *taskAPI.CreateTas
219219
// If the rootfs is inside the VM then:
220220
// a) the rootfs mount type has a prefix that we used to identify this which needs to be stripped before passing to runc
221221
// b) we were not able to inspect the container's rootfs from the client when setting up the spec. Do that here.
222-
if isVmLocalRootFs {
222+
if isVMLocalRootFs {
223223
req.Rootfs[0] = vm.StripLocalMountIdentifier(req.Rootfs[0])
224224
rootfsMount := mount.Mount{
225225
Type: req.Rootfs[0].Type,

internal/common_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ func TestGenerateStubContent(t *testing.T) {
7070
stubContent, err := GenerateStubContent(driveID)
7171
assert.NoError(t, err)
7272

73-
expected := append(MagicStubBytes, byte(len(driveID)))
73+
expected := append([]byte{}, MagicStubBytes...)
74+
expected = append(expected, byte(len(driveID)))
7475
expected = append(expected, []byte(driveID)...)
7576
assert.Equal(t, string(expected), stubContent)
7677
}
@@ -83,7 +84,8 @@ func TestGenerateStubContent_LongID(t *testing.T) {
8384

8485
func TestParseStubContent(t *testing.T) {
8586
expectedDriveID := "foo"
86-
contents := append(MagicStubBytes, byte(len(expectedDriveID)))
87+
contents := append([]byte{}, MagicStubBytes...)
88+
contents = append(contents, byte(len(expectedDriveID)))
8789
contents = append(contents, []byte(expectedDriveID)...)
8890
contents = append(contents, []byte("junkcontent")...)
8991

internal/vm/oci.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import (
4242
)
4343

4444
// UpdateUserInSpec modifies a serialized json spec object with user information from inside the container.
45-
// If the client used firecrackeroci.WithVmLocalImageConfig or firecrakceroci.WithVmLocalUser, this
45+
// If the client used firecrackeroci.WithVMLocalImageConfig or firecrackeroci.WithVMLocalUser, this
4646
// method will do the mapping between username -> uid, group name -> gid, and lookup additional groups for the user.
4747
// This is used to split where the user configures a spec via containerd's oci methods in the client
4848
// from where the data is actually present (from the agent inside the VM)

runtime/firecrackeroci/vm.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ var (
4747
}
4848
)
4949

50-
// WithVmLocalImageConfig configures a spec with the content of the image's config.
50+
// WithVMLocalImageConfig configures a spec with the content of the image's config.
5151
// It is similar to containerd's oci.WithImageConfig except that it does not access
5252
// the image's rootfs on the host. Instead, it configures what it can on the host and
5353
// passes information to the agent running in the VM to inspect the image's rootfs.
54-
func WithVmLocalImageConfig(image containerd.Image) oci.SpecOpts {
54+
func WithVMLocalImageConfig(image containerd.Image) oci.SpecOpts {
5555
return func(ctx context.Context, client oci.Client, container *containers.Container, spec *oci.Spec) error {
5656
ic, err := image.Config(ctx)
5757
if err != nil {
@@ -85,25 +85,26 @@ func WithVmLocalImageConfig(image containerd.Image) oci.SpecOpts {
8585
}
8686
spec.Process.Env = replaceOrAppendEnvValues(defaults, spec.Process.Env)
8787
cmd := config.Cmd
88-
spec.Process.Args = append(config.Entrypoint, cmd...)
88+
spec.Process.Args = append([]string{}, config.Entrypoint...)
89+
spec.Process.Args = append(spec.Process.Args, cmd...)
8990

9091
cwd := config.WorkingDir
9192
if cwd == "" {
9293
cwd = "/"
9394
}
9495
spec.Process.Cwd = cwd
9596
if config.User != "" {
96-
WithVmLocalUser(config.User)(ctx, client, container, spec)
97+
WithVMLocalUser(config.User)(ctx, client, container, spec)
9798
}
9899
return nil
99100
}
100101
}
101102

102-
// WithVmLocalUser configures the user of the spec.
103+
// WithVMLocalUser configures the user of the spec.
103104
// It is similar to oci.WithUser except that it doesn't map
104105
// username -> uid or group name -> gid. It passes the user to the
105106
// agent running inside the VM to do that mapping.
106-
func WithVmLocalUser(user string) oci.SpecOpts {
107+
func WithVMLocalUser(user string) oci.SpecOpts {
107108
return func(ctx context.Context, client oci.Client, container *containers.Container, spec *oci.Spec) error {
108109
// This is technically an LCOW specific field, but we piggy back
109110
// to get the string user into the VM where will will do the uid/gid mapping

runtime/jailer_integ_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func TestAttachBlockDevice_Isolated(t *testing.T) {
8787
}
8888

8989
func fsSafeTestName(tb testing.TB) string {
90-
return strings.Replace(tb.Name(), "/", "-", -1)
90+
return strings.ReplaceAll(tb.Name(), "/", "-")
9191
}
9292

9393
func testJailer(t *testing.T, jailerConfig *proto.JailerConfig) {

runtime/service.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ const (
8181
defaultShutdownTimeout = 5 * time.Second
8282
defaultVSockConnectTimeout = 5 * time.Second
8383

84-
jailerStopTimeout = 3 * time.Second
85-
8684
// StartEventName is the topic published to when a VM starts
8785
StartEventName = "/firecracker-vm/start"
8886

@@ -899,7 +897,7 @@ func (s *service) GetBalloonStats(requestCtx context.Context, req *proto.GetBall
899897
return resp, nil
900898
}
901899

902-
//UpdateBalloonStats will update an existing balloon device statistics interval, before or after machine startup.
900+
// UpdateBalloonStats will update an existing balloon device statistics interval, before or after machine startup.
903901
func (s *service) UpdateBalloonStats(requestCtx context.Context, req *proto.UpdateBalloonStatsRequest) (*types.Empty, error) {
904902
defer logPanicAndDie(s.logger)
905903

@@ -1175,11 +1173,11 @@ func (s *service) Create(requestCtx context.Context, request *taskAPI.CreateTask
11751173
}
11761174
rootfsMnt := request.Rootfs[0]
11771175

1178-
isVmLocalRootfs := vm.IsLocalMount(rootfsMnt)
1176+
isVMLocalRootfs := vm.IsLocalMount(rootfsMnt)
11791177

11801178
// Only mount the container's rootfs as a block device if the mount doesn't
11811179
// signal that it is only accessible from inside the VM.
1182-
if !isVmLocalRootfs {
1180+
if !isVMLocalRootfs {
11831181
err = s.containerStubHandler.Reserve(requestCtx, request.ID,
11841182
rootfsMnt.Source, vmBundleDir.RootfsPath(), "ext4", nil, s.driveMountClient, s.machine)
11851183
if err != nil {
@@ -1216,7 +1214,7 @@ func (s *service) Create(requestCtx context.Context, request *taskAPI.CreateTask
12161214
// override the request with the bundle dir that should be used inside the VM
12171215
request.Bundle = vmBundleDir.RootPath()
12181216

1219-
if !isVmLocalRootfs {
1217+
if !isVMLocalRootfs {
12201218
// If the rootfs is not inside the VM, it is mounted via a MountDrive call,
12211219
// so unset Rootfs in the request.
12221220
// We unfortunately can't rely on just having the runc shim inside the VM do

0 commit comments

Comments
 (0)