Skip to content

Commit 76eea47

Browse files
Merge pull request #25743 from kolyshkin/freebsd-golangci-lint
Add freebsd golangci lint run; fix remaining freebsd warnings
2 parents ed66437 + b959ca3 commit 76eea47

19 files changed

+100
-124
lines changed

.cirrus.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,20 @@ freebsd_alt_build_task:
334334
ALT_NAME: 'FreeBSD Cross'
335335
freebsd_instance:
336336
image_family: freebsd-13-4
337+
# golangci-lint is a very, very hungry beast.
338+
cpu: 4
339+
memory: 8Gb
337340
setup_script:
338341
- pkg install -y gpgme bash go-md2man gmake gsed gnugrep go pkgconf zstd
342+
- go version # Downloads a new go version based on go.mod's go directive.
343+
golint_cache:
344+
folder: ~/.cache/golangci-lint
345+
reupload_on_changes: true
346+
fingerprint_script:
347+
- go version
348+
- grep GOLANGCI_LINT_VERSION Makefile | head -1
349+
lint_script:
350+
- gmake golangci-lint
339351
build_amd64_script:
340352
- gmake podman-release
341353
# This task cannot make use of the shared repo.tar.zst artifact and must

cmd/podman-testing/store_supported.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:build linux && !remote
1+
//go:build (linux || freebsd) && !remote
22

33
package main
44

hack/golangci-lint.sh

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
# Run golangci-lint with different sets of build tags.
44
set -e
@@ -8,23 +8,29 @@ set -e
88
# a very old version, where modern features (like `declare -A`) are
99
# absent.
1010

11+
declare -a EXTRA_TAGS
12+
1113
echo "Linting for GOOS=$GOOS"
12-
# Special case: for Darwin and Windows only "remote" linting is possible and required.
13-
if [[ "$GOOS" == "windows" || "$GOOS" == "darwin" ]]; then
14-
(
15-
set -x
16-
./bin/golangci-lint run --build-tags="remote,containers_image_openpgp" "$@"
17-
)
18-
exit 0
19-
fi
14+
case "$GOOS" in
15+
windows|darwin)
16+
# For Darwin and Windows, only "remote" linting is possible and required.
17+
TAGS="remote,containers_image_openpgp"
18+
;;
19+
freebsd)
20+
TAGS="containers_image_openpgp"
21+
EXTRA_TAGS=(",remote")
22+
;;
23+
*)
24+
# Assume Linux: run linter for various sets of build tags.
25+
TAGS="apparmor,seccomp,selinux"
26+
EXTRA_TAGS=(",systemd" ",remote")
27+
esac
2028

21-
# Normal case (Linux): run linter for various sets of build tags.
22-
TAGS="apparmor,seccomp,selinux"
23-
for EXTRA_TAGS in "" ",systemd" ",remote"; do
29+
for EXTRA in "" "${EXTRA_TAGS[@]}"; do
30+
# Use set -x in a subshell to make it easy for a developer to copy-paste
31+
# the command-line to focus or debug a single, specific linting category.
2432
(
25-
# Make it really easy for a developer to copy-paste the command-line
26-
# to focus or debug a single, specific linting category.
2733
set -x
28-
./bin/golangci-lint run --build-tags="${TAGS}${EXTRA_TAGS}" "$@"
34+
./bin/golangci-lint run --build-tags="${TAGS}${EXTRA}" "$@"
2935
)
3036
done

libpod/container_inspect.go

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/containers/podman/v5/libpod/driver"
1212
"github.com/containers/podman/v5/pkg/signal"
1313
"github.com/containers/podman/v5/pkg/util"
14-
"github.com/containers/storage/types"
1514
"github.com/docker/go-units"
1615
spec "github.com/opencontainers/runtime-spec/specs-go"
1716
"github.com/sirupsen/logrus"
@@ -491,17 +490,6 @@ func (c *Container) generateInspectContainerConfig(spec *spec.Spec) *define.Insp
491490
return ctrConfig
492491
}
493492

494-
func generateIDMappings(idMappings types.IDMappingOptions) *define.InspectIDMappings {
495-
var inspectMappings define.InspectIDMappings
496-
for _, uid := range idMappings.UIDMap {
497-
inspectMappings.UIDMap = append(inspectMappings.UIDMap, fmt.Sprintf("%d:%d:%d", uid.ContainerID, uid.HostID, uid.Size))
498-
}
499-
for _, gid := range idMappings.GIDMap {
500-
inspectMappings.GIDMap = append(inspectMappings.GIDMap, fmt.Sprintf("%d:%d:%d", gid.ContainerID, gid.HostID, gid.Size))
501-
}
502-
return &inspectMappings
503-
}
504-
505493
// Generate the InspectContainerHostConfig struct for the HostConfig field of
506494
// Inspect.
507495
func (c *Container) generateInspectContainerHostConfig(ctrSpec *spec.Spec, namedVolumes []*ContainerNamedVolume, mounts []spec.Mount) (*define.InspectContainerHostConfig, error) {
@@ -659,29 +647,6 @@ func (c *Container) generateInspectContainerHostConfig(ctrSpec *spec.Spec, named
659647
return hostConfig, nil
660648
}
661649

662-
// Return true if the container is running in the host's PID NS.
663-
func (c *Container) inHostPidNS() (bool, error) {
664-
if c.config.PIDNsCtr != "" {
665-
return false, nil
666-
}
667-
ctrSpec, err := c.specFromState()
668-
if err != nil {
669-
return false, err
670-
}
671-
if ctrSpec.Linux != nil {
672-
// Locate the spec's PID namespace.
673-
// If there is none, it's pid=host.
674-
// If there is one and it has a path, it's "ns:".
675-
// If there is no path, it's default - the empty string.
676-
for _, ns := range ctrSpec.Linux.Namespaces {
677-
if ns.Type == spec.PIDNamespace {
678-
return false, nil
679-
}
680-
}
681-
}
682-
return true, nil
683-
}
684-
685650
func (c *Container) GetDevices(priv bool, ctrSpec spec.Spec, deviceNodes map[string]string) ([]define.InspectDevice, error) {
686651
devices := []define.InspectDevice{}
687652
if ctrSpec.Linux != nil && !priv {

libpod/container_inspect_linux.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/containers/common/pkg/config"
1111
"github.com/containers/podman/v5/libpod/define"
1212
"github.com/containers/podman/v5/pkg/util"
13+
"github.com/containers/storage/types"
1314
"github.com/moby/sys/capability"
1415
spec "github.com/opencontainers/runtime-spec/specs-go"
1516
"github.com/sirupsen/logrus"
@@ -309,3 +310,37 @@ func (c *Container) platformInspectContainerHostConfig(ctrSpec *spec.Spec, hostC
309310

310311
return nil
311312
}
313+
314+
func generateIDMappings(idMappings types.IDMappingOptions) *define.InspectIDMappings {
315+
var inspectMappings define.InspectIDMappings
316+
for _, uid := range idMappings.UIDMap {
317+
inspectMappings.UIDMap = append(inspectMappings.UIDMap, fmt.Sprintf("%d:%d:%d", uid.ContainerID, uid.HostID, uid.Size))
318+
}
319+
for _, gid := range idMappings.GIDMap {
320+
inspectMappings.GIDMap = append(inspectMappings.GIDMap, fmt.Sprintf("%d:%d:%d", gid.ContainerID, gid.HostID, gid.Size))
321+
}
322+
return &inspectMappings
323+
}
324+
325+
// Return true if the container is running in the host's PID NS.
326+
func (c *Container) inHostPidNS() (bool, error) {
327+
if c.config.PIDNsCtr != "" {
328+
return false, nil
329+
}
330+
ctrSpec, err := c.specFromState()
331+
if err != nil {
332+
return false, err
333+
}
334+
if ctrSpec.Linux != nil {
335+
// Locate the spec's PID namespace.
336+
// If there is none, it's pid=host.
337+
// If there is one and it has a path, it's "ns:".
338+
// If there is no path, it's default - the empty string.
339+
for _, ns := range ctrSpec.Linux.Namespaces {
340+
if ns.Type == spec.PIDNamespace {
341+
return false, nil
342+
}
343+
}
344+
}
345+
return true, nil
346+
}

libpod/container_internal_freebsd.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package libpod
44

55
import (
6+
"context"
67
"fmt"
78
"os"
89
"path/filepath"
@@ -180,7 +181,9 @@ func (c *Container) addNetworkContainer(g *generate.Generator, ctr string) error
180181
if err != nil {
181182
return fmt.Errorf("retrieving dependency %s of container %s from state: %w", ctr, c.ID(), err)
182183
}
183-
c.runtime.state.UpdateContainer(nsCtr)
184+
if err := c.runtime.state.UpdateContainer(nsCtr); err != nil {
185+
return err
186+
}
184187
if nsCtr.state.NetNS != "" {
185188
g.AddAnnotation("org.freebsd.parentJail", nsCtr.state.NetNS)
186189
}
@@ -252,10 +255,9 @@ func (c *Container) addSharedNamespaces(g *generate.Generator) error {
252255
// the user (already present in OCI spec). If we don't have a UTS ns,
253256
// set it to the host's hostname instead.
254257
hostname := c.Hostname()
255-
foundUTS := false
256258

257259
// TODO: make this optional, needs progress on adding FreeBSD section to the spec
258-
foundUTS = true
260+
foundUTS := true
259261
g.SetHostname(hostname)
260262

261263
if !foundUTS {
@@ -390,7 +392,7 @@ func (c *Container) getPlatformRunPath() (string, error) {
390392
if err != nil {
391393
return "", err
392394
}
393-
inspectData, err := image.Inspect(nil, nil)
395+
inspectData, err := image.Inspect(context.TODO(), nil)
394396
if err != nil {
395397
return "", err
396398
}

libpod/info.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,15 @@ func (r *Runtime) storeInfo() (*define.StoreInfo, error) {
231231
if err := syscall.Statfs(r.store.GraphRoot(), &grStats); err != nil {
232232
return nil, fmt.Errorf("unable to collect graph root usage for %q: %w", r.store.GraphRoot(), err)
233233
}
234-
allocated := uint64(grStats.Bsize) * grStats.Blocks
234+
bsize := uint64(grStats.Bsize) //nolint:unconvert,nolintlint // Bsize is not always uint64 on Linux.
235+
allocated := bsize * grStats.Blocks
235236
info := define.StoreInfo{
236237
ImageStore: imageInfo,
237238
ImageCopyTmpDir: os.Getenv("TMPDIR"),
238239
ContainerStore: conInfo,
239240
GraphRoot: r.store.GraphRoot(),
240241
GraphRootAllocated: allocated,
241-
GraphRootUsed: allocated - (uint64(grStats.Bsize) * grStats.Bfree),
242+
GraphRootUsed: allocated - (bsize * grStats.Bfree),
242243
RunRoot: r.store.RunRoot(),
243244
GraphDriverName: r.store.GraphDriverName(),
244245
GraphOptions: nil,

libpod/networking_freebsd.go

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ import (
99
"fmt"
1010
"net"
1111
"os/exec"
12-
"path/filepath"
1312

1413
"github.com/containers/buildah/pkg/jail"
1514
"github.com/containers/common/libnetwork/types"
1615
"github.com/containers/podman/v5/libpod/define"
17-
"github.com/containers/storage/pkg/lockfile"
1816
"github.com/sirupsen/logrus"
1917
)
2018

@@ -46,38 +44,6 @@ type NetstatAddress struct {
4644
Collisions uint64 `json:"collisions"`
4745
}
4846

49-
type RootlessNetNS struct {
50-
dir string
51-
Lock *lockfile.LockFile
52-
}
53-
54-
// getPath will join the given path to the rootless netns dir
55-
func (r *RootlessNetNS) getPath(path string) string {
56-
return filepath.Join(r.dir, path)
57-
}
58-
59-
// Do - run the given function in the rootless netns.
60-
// It does not lock the rootlessCNI lock, the caller
61-
// should only lock when needed, e.g. for network operations.
62-
func (r *RootlessNetNS) Do(toRun func() error) error {
63-
return errors.New("not supported on freebsd")
64-
}
65-
66-
// Cleanup the rootless network namespace if needed.
67-
// It checks if we have running containers with the bridge network mode.
68-
// Cleanup() expects that r.Lock is locked
69-
func (r *RootlessNetNS) Cleanup(runtime *Runtime) error {
70-
return errors.New("not supported on freebsd")
71-
}
72-
73-
// GetRootlessNetNs returns the rootless netns object. If create is set to true
74-
// the rootless network namespace will be created if it does not already exist.
75-
// If called as root it returns always nil.
76-
// On success the returned RootlessCNI lock is locked and must be unlocked by the caller.
77-
func (r *Runtime) GetRootlessNetNs(new bool) (*RootlessNetNS, error) {
78-
return nil, nil
79-
}
80-
8147
func getSlirp4netnsIP(subnet *net.IPNet) (*net.IP, error) {
8248
return nil, errors.New("not implemented GetSlirp4netnsIP")
8349
}
@@ -145,7 +111,7 @@ func (r *Runtime) createNetNS(ctr *Container) (n string, q map[string]types.Stat
145111
jconf.Set("securelevel", -1)
146112
j, err := jail.Create(jconf)
147113
if err != nil {
148-
return "", nil, fmt.Errorf("Failed to create vnet jail %s for container %s: %w", netns, ctr.ID(), err)
114+
return "", nil, fmt.Errorf("failed to create vnet jail %s for container %s: %w", netns, ctr.ID(), err)
149115
}
150116

151117
logrus.Debugf("Created vnet jail %s for container %s", netns, ctr.ID())
@@ -157,7 +123,7 @@ func (r *Runtime) createNetNS(ctr *Container) (n string, q map[string]types.Stat
157123
jconf.Set("persist", false)
158124
if err := j.Set(jconf); err != nil {
159125
// Log this error and return the error from configureNetNS
160-
logrus.Errorf("failed to destroy vnet jail %s: %w", netns, err)
126+
logrus.Errorf("failed to destroy vnet jail %s: %v", netns, err)
161127
}
162128
}
163129
return netns, networkStatus, err
@@ -258,13 +224,8 @@ func (c *Container) joinedNetworkNSPath() (string, bool) {
258224
func (c *Container) inspectJoinedNetworkNS(networkns string) (q types.StatusBlock, retErr error) {
259225
// TODO: extract interface information from the vnet jail
260226
return types.StatusBlock{}, nil
261-
262227
}
263228

264229
func (c *Container) reloadRootlessRLKPortMapping() error {
265230
return errors.New("unsupported (*Container).reloadRootlessRLKPortMapping")
266231
}
267-
268-
func (c *Container) setupRootlessNetwork() error {
269-
return nil
270-
}

libpod/oci_conmon_linux.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ func (r *ConmonOCIRuntime) withContainerSocketLabel(ctr *Container, closure func
164164
return err
165165
}
166166

167+
// Create systemd unit name for cgroup scopes.
168+
func createUnitName(prefix string, name string) string {
169+
return fmt.Sprintf("%s-%s.scope", prefix, name)
170+
}
171+
167172
// moveConmonToCgroupAndSignal gets a container's cgroupParent and moves the conmon process to that cgroup
168173
// it then signals for conmon to start by sending nonce data down the start fd
169174
func (r *ConmonOCIRuntime) moveConmonToCgroupAndSignal(ctr *Container, cmd *exec.Cmd, startFd *os.File) error {

libpod/oci_util.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ type ociError struct {
2727
Msg string `json:"msg,omitempty"`
2828
}
2929

30-
// Create systemd unit name for cgroup scopes
31-
func createUnitName(prefix string, name string) string {
32-
return fmt.Sprintf("%s-%s.scope", prefix, name)
33-
}
34-
3530
// Bind ports to keep them closed on the host
3631
func bindPorts(ports []types.PortMapping) ([]*os.File, error) {
3732
var files []*os.File

0 commit comments

Comments
 (0)