Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ run:

formatters:
enable:
- gofmt
- gofumpt
- goimports
exclusions:
generated: disable
Expand Down
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ It is not necessary to test a single change in multiple places.

### Go Format and lint

All code changes must pass ``make validatepr``.
All code changes must pass `make validatepr`.
We are using the [`gofumpt`](https://github.com/mvdan/gofumpt) formatter for our go code, you can either use it directly or format via `golangci-lint fmt`. The `validatepr`/`validate` make targets will fail if the code is not formatted correctly.

### Integration Tests

Expand Down
4 changes: 2 additions & 2 deletions cmd/podman-mac-helper/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
)

const (
mode755 = 0755
mode644 = 0644
mode755 = 0o755
mode644 = 0o644
)

const launchConfig = `<?xml version="1.0" encoding="UTF-8"?>
Expand Down
4 changes: 1 addition & 3 deletions cmd/podman-testing/store_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import (
"github.com/containers/podman/v6/pkg/domain/entities"
)

var (
engineMode = entities.TunnelMode
)
var engineMode = entities.TunnelMode

func storeBefore() error {
return nil
Expand Down
4 changes: 1 addition & 3 deletions cmd/podman-wslkerninst/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ func setupLogging(name string) (*eventlog.Log, error) {

func installWslKernel() error {
logrus.Info("Installing WSL Kernel update")
var (
err error
)
var err error
backoff := 500 * time.Millisecond
for i := 1; i < 6; i++ {
err = wutil.SilentExec("--update")
Expand Down
20 changes: 9 additions & 11 deletions cmd/podman/artifact/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@ import (
"go.podman.io/common/pkg/completion"
)

var (
addCmd = &cobra.Command{
Use: "add [options] ARTIFACT PATH [...PATH]",
Short: "Add an OCI artifact to the local store",
Long: "Add an OCI artifact to the local store from the local filesystem",
RunE: add,
Args: cobra.MinimumNArgs(2),
ValidArgsFunction: common.AutocompleteArtifactAdd,
Example: `podman artifact add quay.io/myimage/myartifact:latest /tmp/foobar.txt
var addCmd = &cobra.Command{
Use: "add [options] ARTIFACT PATH [...PATH]",
Short: "Add an OCI artifact to the local store",
Long: "Add an OCI artifact to the local store from the local filesystem",
RunE: add,
Args: cobra.MinimumNArgs(2),
ValidArgsFunction: common.AutocompleteArtifactAdd,
Example: `podman artifact add quay.io/myimage/myartifact:latest /tmp/foobar.txt
podman artifact add --file-type text/yaml quay.io/myimage/myartifact:latest /tmp/foobar.yaml
podman artifact add --append quay.io/myimage/myartifact:latest /tmp/foobar.tar.gz`,
}
)
}

// AddOptionsWrapper wraps entities.ArtifactsAddOptions and prevents leaking
// CLI-only fields into the API types.
Expand Down
24 changes: 10 additions & 14 deletions cmd/podman/artifact/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,18 @@ import (
"go.podman.io/common/pkg/completion"
)

var (
extractCmd = &cobra.Command{
Use: "extract [options] ARTIFACT PATH",
Short: "Extract an OCI artifact to a local path",
Long: "Extract the blobs of an OCI artifact to a local file or directory",
RunE: extract,
Args: cobra.ExactArgs(2),
ValidArgsFunction: common.AutocompleteArtifactAdd,
Example: `podman artifact Extract quay.io/myimage/myartifact:latest /tmp/foobar.txt
var extractCmd = &cobra.Command{
Use: "extract [options] ARTIFACT PATH",
Short: "Extract an OCI artifact to a local path",
Long: "Extract the blobs of an OCI artifact to a local file or directory",
RunE: extract,
Args: cobra.ExactArgs(2),
ValidArgsFunction: common.AutocompleteArtifactAdd,
Example: `podman artifact Extract quay.io/myimage/myartifact:latest /tmp/foobar.txt
podman artifact Extract quay.io/myimage/myartifact:latest /home/paul/mydir`,
}
)
}

var (
extractOpts entities.ArtifactExtractOptions
)
var extractOpts entities.ArtifactExtractOptions

func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Expand Down
8 changes: 2 additions & 6 deletions cmd/podman/artifact/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ func (a artifactListOutput) CreatedAt() string {
return a.created.String()
}

var (
defaultArtifactListOutputFormat = "{{range .}}{{.Repository}}\t{{.Tag}}\t{{.Digest}}\t{{.Created}}\t{{.Size}}\n{{end -}}"
)
var defaultArtifactListOutputFormat = "{{range .}}{{.Repository}}\t{{.Tag}}\t{{.Digest}}\t{{.Created}}\t{{.Size}}\n{{end -}}"

func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Expand Down Expand Up @@ -93,9 +91,7 @@ func outputTemplate(cmd *cobra.Command, lrs []*entities.ArtifactListReport) erro
var err error
artifacts := make([]artifactListOutput, 0)
for _, lr := range lrs {
var (
tag string
)
var tag string
artifactName, err := lr.Artifact.GetName()
if err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions cmd/podman/artifact/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func rmFlags(cmd *cobra.Command) {
flags.BoolVarP(&rmOptions.All, "all", "a", false, "Remove all artifacts")
flags.BoolVarP(&rmOptions.Ignore, "ignore", "i", false, "Ignore error if artifact does not exist")
}

func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Command: rmCmd,
Expand Down
6 changes: 4 additions & 2 deletions cmd/podman/common/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ type BuildFlagsWrapper struct {

// FarmBuildHiddenFlags are the flags hidden from the farm build command because they are either not
// supported or don't make sense in the farm build use case
var FarmBuildHiddenFlags = []string{"arch", "all-platforms", "compress", "cw", "disable-content-trust",
var FarmBuildHiddenFlags = []string{
"arch", "all-platforms", "compress", "cw", "disable-content-trust",
"logsplit", "manifest", "os", "output", "platform", "sign-by", "signature-policy", "stdin",
"variant"}
"variant",
}

func DefineBuildFlags(cmd *cobra.Command, buildOpts *BuildFlagsWrapper, isFarmBuild bool) {
flags := cmd.Flags()
Expand Down
31 changes: 20 additions & 11 deletions cmd/podman/common/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -1186,8 +1186,10 @@ func AutocompletePullOption(_ *cobra.Command, _ []string, _ string) ([]string, c
// AutocompleteRestartOption - Autocomplete restart options for create and run command.
// -> "always", "no", "on-failure", "unless-stopped"
func AutocompleteRestartOption(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
restartOptions := []string{define.RestartPolicyAlways, define.RestartPolicyNo,
define.RestartPolicyOnFailure, define.RestartPolicyUnlessStopped}
restartOptions := []string{
define.RestartPolicyAlways, define.RestartPolicyNo,
define.RestartPolicyOnFailure, define.RestartPolicyUnlessStopped,
}
return restartOptions, cobra.ShellCompDirectiveNoFileComp
}

Expand Down Expand Up @@ -1595,7 +1597,8 @@ func getMethodNames(f reflect.Value, prefix string) []formatSuggestion {
// -> "container=", "event=", "image=", "pod=", "volume=", "type="
func AutocompleteEventFilter(cmd *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective) {
event := func(_ string) ([]string, cobra.ShellCompDirective) {
return []string{events.Attach.String(), events.AutoUpdate.String(), events.Checkpoint.String(), events.Cleanup.String(),
return []string{
events.Attach.String(), events.AutoUpdate.String(), events.Checkpoint.String(), events.Cleanup.String(),
events.Commit.String(), events.Create.String(), events.Exec.String(), events.ExecDied.String(),
events.Exited.String(), events.Export.String(), events.Import.String(), events.Init.String(), events.Kill.String(),
events.LoadFromArchive.String(), events.Mount.String(), events.NetworkConnect.String(),
Expand All @@ -1607,7 +1610,8 @@ func AutocompleteEventFilter(cmd *cobra.Command, _ []string, toComplete string)
}, cobra.ShellCompDirectiveNoFileComp
}
eventTypes := func(_ string) ([]string, cobra.ShellCompDirective) {
return []string{events.Container.String(), events.Image.String(), events.Network.String(),
return []string{
events.Container.String(), events.Image.String(), events.Network.String(),
events.Pod.String(), events.System.String(), events.Volume.String(), events.Secret.String(),
}, cobra.ShellCompDirectiveNoFileComp
}
Expand Down Expand Up @@ -1710,9 +1714,11 @@ func AutocompleteImageSaveFormat(_ *cobra.Command, _ []string, _ string) ([]stri
// AutocompleteWaitCondition - Autocomplete wait condition options.
// -> "unknown", "configured", "created", "running", "stopped", "paused", "exited", "removing"
func AutocompleteWaitCondition(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
states := []string{"unknown", "configured", "created", "exited",
states := []string{
"unknown", "configured", "created", "exited",
"healthy", "initialized", "paused", "removing", "running",
"stopped", "stopping", "unhealthy"}
"stopped", "stopping", "unhealthy",
}
return states, cobra.ShellCompDirectiveNoFileComp
}

Expand Down Expand Up @@ -1792,8 +1798,10 @@ func AutocompletePsFilters(cmd *cobra.Command, _ []string, toComplete string) ([
"command=": func(s string) ([]string, cobra.ShellCompDirective) { return getCommands(cmd, s) },
"exited=": nil,
"health=": func(_ string) ([]string, cobra.ShellCompDirective) {
return []string{define.HealthCheckHealthy,
define.HealthCheckUnhealthy}, cobra.ShellCompDirectiveNoFileComp
return []string{
define.HealthCheckHealthy,
define.HealthCheckUnhealthy,
}, cobra.ShellCompDirectiveNoFileComp
},
"id=": func(s string) ([]string, cobra.ShellCompDirective) { return getContainers(cmd, s, completeIDs) },
"label=": nil,
Expand Down Expand Up @@ -1832,8 +1840,10 @@ func AutocompletePodPsFilters(cmd *cobra.Command, _ []string, toComplete string)
"name=": func(s string) ([]string, cobra.ShellCompDirective) { return getPods(cmd, s, completeNames) },
"network=": func(s string) ([]string, cobra.ShellCompDirective) { return getNetworks(cmd, s, completeDefault) },
"status=": func(_ string) ([]string, cobra.ShellCompDirective) {
return []string{"stopped", "running",
"paused", "exited", "dead", "created", "degraded"}, cobra.ShellCompDirectiveNoFileComp
return []string{
"stopped", "running",
"paused", "exited", "dead", "created", "degraded",
}, cobra.ShellCompDirectiveNoFileComp
},
"until=": nil,
}
Expand Down Expand Up @@ -2002,7 +2012,6 @@ func AutocompleteSysctl(_ *cobra.Command, _ []string, toComplete string) ([]stri

return nil
})

if err != nil {
return nil, cobra.ShellCompDirectiveError
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/podman/common/completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,11 @@ func TestAutocompleteFormat(t *testing.T) {
{
"two variables struct field name",
"{{ .Car.Brand }} {{ .Car.",
[]string{"{{ .Car.Brand }} {{ .Car.Color}}", "{{ .Car.Brand }} {{ .Car.Struct.", "{{ .Car.Brand }} {{ .Car.Type}}",
[]string{
"{{ .Car.Brand }} {{ .Car.Color}}", "{{ .Car.Brand }} {{ .Car.Struct.", "{{ .Car.Brand }} {{ .Car.Type}}",
"{{ .Car.Brand }} {{ .Car.Brand}}", "{{ .Car.Brand }} {{ .Car.Stats.", "{{ .Car.Brand }} {{ .Car.Extras.",
"{{ .Car.Brand }} {{ .Car.Extras2."},
"{{ .Car.Brand }} {{ .Car.Extras2.",
},
},
{
"only dot without variable",
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/common/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *entities.ContainerCreateOptions,
timezoneFlagName, cf.Timezone,
"Set timezone in container",
)
_ = cmd.RegisterFlagCompletionFunc(timezoneFlagName, completion.AutocompleteNone) //TODO: add timezone completion
_ = cmd.RegisterFlagCompletionFunc(timezoneFlagName, completion.AutocompleteNone) // TODO: add timezone completion

umaskFlagName := "umask"
createFlags.StringVar(
Expand Down
6 changes: 2 additions & 4 deletions cmd/podman/common/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ import (
"github.com/containers/podman/v6/cmd/podman/registry"
)

var (
// Pull in configured json library
json = registry.JSONLibrary()
)
// Pull in configured json library
var json = registry.JSONLibrary()
4 changes: 1 addition & 3 deletions cmd/podman/common/netflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ func DefineNetFlags(cmd *cobra.Command) {

// NetFlagsToNetOptions parses the network flags for the given cmd.
func NetFlagsToNetOptions(opts *entities.NetOptions, flags pflag.FlagSet) (*entities.NetOptions, error) {
var (
err error
)
var err error
if opts == nil {
opts = &entities.NetOptions{}
}
Expand Down
4 changes: 1 addition & 3 deletions cmd/podman/containers/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ var (
}
)

var (
attachOpts entities.AttachOptions
)
var attachOpts entities.AttachOptions

func attachFlags(cmd *cobra.Command) {
flags := cmd.Flags()
Expand Down
8 changes: 2 additions & 6 deletions cmd/podman/containers/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ var (
}
)

var (
cleanupOptions entities.ContainerCleanupOptions
)
var cleanupOptions entities.ContainerCleanupOptions

func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Expand All @@ -62,9 +60,7 @@ func init() {
}

func cleanup(_ *cobra.Command, args []string) error {
var (
errs utils.OutputErrors
)
var errs utils.OutputErrors

if cleanupOptions.Exec != "" {
switch {
Expand Down
5 changes: 2 additions & 3 deletions cmd/podman/containers/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ var (
}
)

var (
ctrClone entities.ContainerCloneOptions
)
var ctrClone entities.ContainerCloneOptions

func cloneFlags(cmd *cobra.Command) {
flags := cmd.Flags()
Expand All @@ -43,6 +41,7 @@ func cloneFlags(cmd *cobra.Command) {
common.DefineCreateDefaults(&ctrClone.CreateOpts)
common.DefineCreateFlags(cmd, &ctrClone.CreateOpts, entities.CloneMode)
}

func init() {
registry.Commands = append(registry.Commands, registry.CliCommand{
Command: containerCloneCommand,
Expand Down
13 changes: 6 additions & 7 deletions cmd/podman/containers/cp.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package containers

import (
"errors"
"fmt"
"io"
"os"
Expand All @@ -10,8 +11,6 @@ import (
"strconv"
"strings"

"errors"

buildahCopiah "github.com/containers/buildah/copier"
"github.com/containers/podman/v6/cmd/podman/common"
"github.com/containers/podman/v6/cmd/podman/registry"
Expand Down Expand Up @@ -466,16 +465,16 @@ func resolvePathOnDestinationContainer(container string, containerPath string, i
containerInfo, err = registry.ContainerEngine().ContainerStat(registry.Context(), container, containerPath)
if err == nil {
baseName = path.Base(containerInfo.LinkTarget)
return //nolint: nilerr
return baseName, containerInfo, resolvedToParentDir, err //nolint: nilerr
}

if strings.HasSuffix(containerPath, "/") {
err = fmt.Errorf("%q could not be found on container %s: %w", containerPath, container, err)
return
return baseName, containerInfo, resolvedToParentDir, err
}
if isStdin {
err = errors.New("destination must be a directory when copying from stdin")
return
return baseName, containerInfo, resolvedToParentDir, err
}

// NOTE: containerInfo may actually be set. That happens when
Expand All @@ -492,13 +491,13 @@ func resolvePathOnDestinationContainer(container string, containerPath string, i
parentDir, err := containerParentDir(container, parentPath)
if err != nil {
err = fmt.Errorf("could not determine parent dir of %q on container %s: %w", parentPath, container, err)
return
return baseName, containerInfo, resolvedToParentDir, err
}

containerInfo, err = registry.ContainerEngine().ContainerStat(registry.Context(), container, parentDir)
if err != nil {
err = fmt.Errorf("%q could not be found on container %s: %w", containerPath, container, err)
return
return baseName, containerInfo, resolvedToParentDir, err
}

resolvedToParentDir = true
Expand Down
4 changes: 1 addition & 3 deletions cmd/podman/containers/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ var (
}
)

var (
initOptions entities.ContainerInitOptions
)
var initOptions entities.ContainerInitOptions

func initFlags(flags *pflag.FlagSet) {
flags.BoolVarP(&initOptions.All, "all", "a", false, "Initialize all containers")
Expand Down
Loading