Skip to content

Commit 2816a63

Browse files
committed
gofumpt final round
1 parent 60e6ae4 commit 2816a63

25 files changed

Lines changed: 57 additions & 104 deletions

File tree

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ formatters:
7272
- gofumpt
7373
- goimports
7474
settings:
75+
gofumpt:
76+
extra-rules: true
7577
goimports:
7678
local-prefixes:
7779
- github.com/cocoonstack/cocoon

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ lint: golangci-lint ## Run golangci-lint for all target platforms
7676
GOOS=darwin GOARCH=amd64 $(GOLANGCILINT) run
7777

7878
fmt: gofumpt goimports ## Format code with gofumpt and goimports
79-
$(GOFMT) -l -w .
79+
$(GOFMT) -extra -l -w .
8080
$(GOIMPORTS) -l -w --local 'github.com/cocoonstack/cocoon' .
8181

8282
fmt-check: gofumpt goimports ## Check formatting (fails if files need formatting)
83-
@test -z "$$($(GOFMT) -l .)" || { echo "Files need formatting (gofumpt):"; $(GOFMT) -l .; exit 1; }
83+
@test -z "$$($(GOFMT) -extra -l .)" || { echo "Files need formatting (gofumpt):"; $(GOFMT) -extra -l .; exit 1; }
8484
@test -z "$$($(GOIMPORTS) -l .)" || { echo "Files need formatting (goimports):"; $(GOIMPORTS) -l .; exit 1; }
8585

8686
# --- Maintenance ---

hypervisor/backend.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -417,20 +417,6 @@ func (b *Backend) GCCollect(ctx context.Context, ids []string) error {
417417
return errors.Join(errs...)
418418
}
419419

420-
// killOrphanProcess terminates a leftover hypervisor process if the PID
421-
// file exists and the process matches the expected binary name.
422-
func (b *Backend) killOrphanProcess(ctx context.Context, runDir string) {
423-
pid, err := utils.ReadPIDFile(b.PIDFilePath(runDir))
424-
if err != nil {
425-
return
426-
}
427-
sockPath := SocketPath(runDir)
428-
if !utils.VerifyProcessCmdline(pid, b.Conf.BinaryName(), sockPath) {
429-
return
430-
}
431-
_ = utils.TerminateProcess(ctx, pid, b.Conf.BinaryName(), sockPath, b.Conf.TerminateGracePeriod())
432-
}
433-
434420
func (b *Backend) PIDFilePath(runDir string) string {
435421
return filepath.Join(runDir, b.Conf.PIDFileName())
436422
}
@@ -564,6 +550,20 @@ func (b *Backend) HandleStopResult(ctx context.Context, id, runDir string, runti
564550
return nil
565551
}
566552

553+
// killOrphanProcess terminates a leftover hypervisor process if the PID
554+
// file exists and the process matches the expected binary name.
555+
func (b *Backend) killOrphanProcess(ctx context.Context, runDir string) {
556+
pid, err := utils.ReadPIDFile(b.PIDFilePath(runDir))
557+
if err != nil {
558+
return
559+
}
560+
sockPath := SocketPath(runDir)
561+
if !utils.VerifyProcessCmdline(pid, b.Conf.BinaryName(), sockPath) {
562+
return
563+
}
564+
_ = utils.TerminateProcess(ctx, pid, b.Conf.BinaryName(), sockPath, b.Conf.TerminateGracePeriod())
565+
}
566+
567567
func SocketPath(runDir string) string { return filepath.Join(runDir, APISocketName) }
568568

569569
func ConsoleSockPath(runDir string) string { return filepath.Join(runDir, ConsoleSockName) }

hypervisor/cloudhypervisor/cloudhypervisor.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ var (
1818
_ hypervisor.Watchable = (*CloudHypervisor)(nil)
1919
)
2020

21-
const (
22-
typ = "cloud-hypervisor"
23-
)
21+
const typ = "cloud-hypervisor"
2422

2523
// CloudHypervisor implements hypervisor.Hypervisor.
2624
type CloudHypervisor struct {

hypervisor/cloudhypervisor/create.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ import (
1515
)
1616

1717
// CowSerial is re-exported for backward compatibility with cmd/vm/debug.go.
18-
const (
19-
CowSerial = hypervisor.CowSerial
20-
)
18+
const CowSerial = hypervisor.CowSerial
2119

2220
// Create reserves a VM record, prepares disks, and leaves the VM in Created state.
2321
func (ch *CloudHypervisor) Create(ctx context.Context, id string, vmCfg *types.VMConfig, storageConfigs []*types.StorageConfig, networkConfigs []*types.NetworkConfig, bootCfg *types.BootConfig) (_ *types.VM, err error) {

hypervisor/firecracker/clone.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ import (
1515
"github.com/cocoonstack/cocoon/utils"
1616
)
1717

18-
const (
19-
cloneBackupSuffix = ".cocoon-clone-backup"
20-
)
18+
const cloneBackupSuffix = ".cocoon-clone-backup"
2119

2220
// driveRedirect records a temporary symlink replacing a source drive path.
2321
type driveRedirect struct {

hypervisor/firecracker/firecracker.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ var (
1818
_ hypervisor.Direct = (*Firecracker)(nil)
1919
)
2020

21-
const (
22-
typ = "firecracker"
23-
)
21+
const typ = "firecracker"
2422

2523
// Firecracker implements hypervisor.Hypervisor using the Firecracker VMM.
2624
// Only OCI images (direct kernel boot) are supported — no UEFI, no cloudimg, no Windows.

images/cloudimg/cloudimg.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,9 @@ import (
1717
"github.com/cocoonstack/cocoon/utils"
1818
)
1919

20-
// compile-time interface check.
21-
var (
22-
_ images.Images = (*CloudImg)(nil)
23-
)
20+
var _ images.Images = (*CloudImg)(nil)
2421

25-
const (
26-
typ = "cloudimg"
27-
)
22+
const typ = "cloudimg"
2823

2924
// CloudImg stores cloud image blobs for UEFI boot under Cloud Hypervisor.
3025
type CloudImg struct {

images/index.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ import (
1414
"github.com/cocoonstack/cocoon/utils"
1515
)
1616

17-
const (
18-
minHexLen = 12
19-
)
17+
const minHexLen = 12
2018

2119
// Entry defines the common behavior of an image index (*entry).
2220
// Both OCI and cloudimg imageEntry types implement this with value receivers.

images/oci/commit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ func bootFilesPresent(results []pullLayerResult) (hasKernel, hasInitrd bool) {
4242
hasInitrd = true
4343
}
4444
if hasKernel && hasInitrd {
45-
return
45+
return hasKernel, hasInitrd
4646
}
4747
}
48-
return
48+
return hasKernel, hasInitrd
4949
}
5050

5151
func commitAndRecord(conf *Config, idx *imageIndex, ref string, manifestDigest images.Digest, results []pullLayerResult) error {

0 commit comments

Comments
 (0)