Skip to content

Commit

Permalink
Merge pull request #23857 from rhatdan/run
Browse files Browse the repository at this point in the history
Remove containers/common/pkg/config from pkg/util
  • Loading branch information
openshift-merge-bot[bot] authored Sep 17, 2024
2 parents 1e9464c + eb39670 commit 62c1016
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 49 deletions.
3 changes: 1 addition & 2 deletions cmd/podman/containers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package containers
import (
"github.com/containers/podman/v5/cmd/podman/registry"
"github.com/containers/podman/v5/cmd/podman/validate"
"github.com/containers/podman/v5/pkg/util"
"github.com/spf13/cobra"
)

Expand All @@ -20,7 +19,7 @@ var (
RunE: validate.SubCommandExists,
}

containerConfig = util.DefaultContainerConfig()
containerConfig = registry.PodmanConfig().ContainersConfDefaultsRO
)

func init() {
Expand Down
3 changes: 1 addition & 2 deletions cmd/podman/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package generate
import (
"github.com/containers/podman/v5/cmd/podman/registry"
"github.com/containers/podman/v5/cmd/podman/validate"
"github.com/containers/podman/v5/pkg/util"
"github.com/spf13/cobra"
)

Expand All @@ -15,7 +14,7 @@ var (
Long: "Generate structured data (e.g., Kubernetes YAML or systemd units) based on containers, pods or volumes.",
RunE: validate.SubCommandExists,
}
containerConfig = util.DefaultContainerConfig()
containerConfig = registry.PodmanConfig().ContainersConfDefaultsRO
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/images/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func load(cmd *cobra.Command, args []string) error {
if len(loadOpts.Input) > 0 {
// Download the input file if needed.
if strings.HasPrefix(loadOpts.Input, "https://") || strings.HasPrefix(loadOpts.Input, "http://") {
tmpdir, err := util.DefaultContainerConfig().ImageCopyTmpDir()
tmpdir, err := registry.PodmanConfig().ContainersConfDefaultsRO.ImageCopyTmpDir()
if err != nil {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/podman/networks/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package network
import (
"github.com/containers/podman/v5/cmd/podman/registry"
"github.com/containers/podman/v5/cmd/podman/validate"
"github.com/containers/podman/v5/pkg/util"
"github.com/spf13/cobra"
)

Expand All @@ -18,7 +17,7 @@ var (
Long: "Manage networks",
RunE: validate.SubCommandExists,
}
containerConfig = util.DefaultContainerConfig()
containerConfig = registry.PodmanConfig().ContainersConfDefaultsRO
)

func init() {
Expand Down
3 changes: 1 addition & 2 deletions cmd/podman/pods/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package pods
import (
"github.com/containers/podman/v5/cmd/podman/registry"
"github.com/containers/podman/v5/cmd/podman/validate"
"github.com/containers/podman/v5/pkg/util"
"github.com/spf13/cobra"
)

Expand All @@ -18,7 +17,7 @@ var (
Long: "Pods are a group of one or more containers sharing the same network, pid and ipc namespaces.",
RunE: validate.SubCommandExists,
}
containerConfig = util.DefaultContainerConfig()
containerConfig = registry.PodmanConfig().ContainersConfDefaultsRO
)

func init() {
Expand Down
3 changes: 1 addition & 2 deletions cmd/podman/volumes/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package volumes
import (
"github.com/containers/podman/v5/cmd/podman/registry"
"github.com/containers/podman/v5/cmd/podman/validate"
"github.com/containers/podman/v5/pkg/util"
"github.com/spf13/cobra"
)

Expand All @@ -18,7 +17,7 @@ var (
Long: "Volumes are created in and can be shared between containers",
RunE: validate.SubCommandExists,
}
containerConfig = util.DefaultContainerConfig()
containerConfig = registry.PodmanConfig().ContainersConfDefaultsRO
)

func init() {
Expand Down
16 changes: 13 additions & 3 deletions libpod/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,11 @@ func (p *Pod) podWithContainers(ctx context.Context, containers []*Container, po
stopTimeout *uint
)

cfg, err := config.Default()
if err != nil {
return nil, err
}

// Let's sort the containers in order of created time
// This will ensure that the init containers are defined in the correct order in the kube yaml
sort.Slice(containers, func(i, j int) bool { return containers[i].CreatedTime().Before(containers[j].CreatedTime()) })
Expand Down Expand Up @@ -630,7 +635,7 @@ func (p *Pod) podWithContainers(ctx context.Context, containers []*Container, po

// Pick the first container that has a stop-timeout set and use that value
// Ignore podman's default
if ctr.config.StopTimeout != util.DefaultContainerConfig().Engine.StopTimeout && stopTimeout == nil {
if ctr.config.StopTimeout != cfg.Engine.StopTimeout && stopTimeout == nil {
stopTimeout = &ctr.config.StopTimeout
}

Expand Down Expand Up @@ -736,6 +741,11 @@ func newPodObject(podName string, annotations map[string]string, initCtrs, conta
// simplePodWithV1Containers is a function used by inspect when kube yaml needs to be generated
// for a single container. we "insert" that container description in a pod.
func simplePodWithV1Containers(ctx context.Context, ctrs []*Container, getService, podmanOnly bool) (*v1.Pod, error) {
cfg, err := config.Default()
if err != nil {
return nil, err
}

kubeCtrs := make([]v1.Container, 0, len(ctrs))
kubeInitCtrs := []v1.Container{}
kubeVolumes := make([]v1.Volume, 0)
Expand Down Expand Up @@ -775,7 +785,7 @@ func simplePodWithV1Containers(ctx context.Context, ctrs []*Container, getServic

// Pick the first container that has a stop-timeout set and use that value
// Ignore podman's default
if ctr.config.StopTimeout != util.DefaultContainerConfig().Engine.StopTimeout && stopTimeout == nil {
if ctr.config.StopTimeout != cfg.Engine.StopTimeout && stopTimeout == nil {
stopTimeout = &ctr.config.StopTimeout
}

Expand All @@ -786,7 +796,7 @@ func simplePodWithV1Containers(ctx context.Context, ctrs []*Container, getServic

if ctr.config.Spec.Process != nil {
var ulimitArr []string
defaultUlimits := util.DefaultContainerConfig().Ulimits()
defaultUlimits := cfg.Ulimits()
for _, ulimit := range ctr.config.Spec.Process.Rlimits {
finalUlimit := strings.ToLower(strings.ReplaceAll(ulimit.Type, "RLIMIT_", "")) + "=" + strconv.Itoa(int(ulimit.Soft)) + ":" + strconv.Itoa(int(ulimit.Hard))
// compare ulimit with default list so we don't add it twice
Expand Down
5 changes: 4 additions & 1 deletion pkg/api/handlers/compat/images_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,10 @@ func BuildImage(w http.ResponseWriter, r *http.Request) {
AuthFilePath: authfile,
DockerAuthConfig: creds,
}
utils.PossiblyEnforceDockerHub(r, systemContext)
if err := utils.PossiblyEnforceDockerHub(r, systemContext); err != nil {
utils.Error(w, http.StatusInternalServerError, fmt.Errorf("checking to enforce DockerHub: %w", err))
return
}

if _, found := r.URL.Query()["tlsVerify"]; found {
systemContext.DockerInsecureSkipTLSVerify = types.NewOptionalBool(!query.TLSVerify)
Expand Down
10 changes: 8 additions & 2 deletions pkg/api/handlers/libpod/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@ import (
"fmt"
"net/http"

"github.com/containers/common/pkg/config"
"github.com/containers/podman/v5/libpod"
"github.com/containers/podman/v5/pkg/api/handlers/utils"
api "github.com/containers/podman/v5/pkg/api/types"
"github.com/containers/podman/v5/pkg/domain/entities"
"github.com/containers/podman/v5/pkg/domain/infra/abi"
"github.com/containers/podman/v5/pkg/util"
"github.com/gorilla/schema"
)

func GenerateSystemd(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
decoder := r.Context().Value(api.DecoderKey).(*schema.Decoder)
cfg, err := config.Default()
if err != nil {
utils.Error(w, http.StatusInternalServerError, fmt.Errorf("reading containers.conf: %w", err))
return
}

query := struct {
Name bool `schema:"useName"`
New bool `schema:"new"`
Expand All @@ -36,7 +42,7 @@ func GenerateSystemd(w http.ResponseWriter, r *http.Request) {
AdditionalEnvVariables []string `schema:"additionalEnvVariables"`
}{
StartTimeout: 0,
StopTimeout: util.DefaultContainerConfig().Engine.StopTimeout,
StopTimeout: cfg.Engine.StopTimeout,
}

if err := decoder.Decode(&query, r.URL.Query()); err != nil {
Expand Down
18 changes: 13 additions & 5 deletions pkg/api/handlers/utils/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/containers/podman/v5/libpod"
api "github.com/containers/podman/v5/pkg/api/types"
"github.com/containers/podman/v5/pkg/errorhandling"
"github.com/containers/podman/v5/pkg/util"
"github.com/containers/storage"
"github.com/docker/distribution/registry/api/errcode"
"github.com/docker/docker/pkg/jsonmessage"
Expand All @@ -30,7 +29,11 @@ import (
// request is for the compat API and if containers.conf set the specific mode.
// If nameOrID is a (short) ID for a local image, the full ID will be returned.
func NormalizeToDockerHub(r *http.Request, nameOrID string) (string, error) {
if IsLibpodRequest(r) || !util.DefaultContainerConfig().Engine.CompatAPIEnforceDockerHub {
cfg, err := config.Default()
if err != nil {
return "", err
}
if IsLibpodRequest(r) || !cfg.Engine.CompatAPIEnforceDockerHub {
return nameOrID, nil
}

Expand Down Expand Up @@ -62,11 +65,16 @@ func NormalizeToDockerHub(r *http.Request, nameOrID string) (string, error) {
// PossiblyEnforceDockerHub sets fields in the system context to enforce
// resolving short names to Docker Hub if the request is for the compat API and
// if containers.conf set the specific mode.
func PossiblyEnforceDockerHub(r *http.Request, sys *types.SystemContext) {
if IsLibpodRequest(r) || !util.DefaultContainerConfig().Engine.CompatAPIEnforceDockerHub {
return
func PossiblyEnforceDockerHub(r *http.Request, sys *types.SystemContext) error {
cfg, err := config.Default()
if err != nil {
return err
}
if IsLibpodRequest(r) || !cfg.Engine.CompatAPIEnforceDockerHub {
return nil
}
sys.PodmanOnlyShortNamesIgnoreRegistriesConfAndForceDockerHub = true
return nil
}

// IsRegistryReference checks if the specified name points to the "docker://"
Expand Down
12 changes: 6 additions & 6 deletions pkg/domain/infra/abi/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,11 @@ func (ic *ContainerEngine) playKubeJob(ctx context.Context, jobYAML *v1.Job, opt
}

func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podYAML *v1.PodTemplateSpec, options entities.PlayKubeOptions, ipIndex *int, annotations map[string]string, configMaps []v1.ConfigMap, serviceContainer *libpod.Container) (*entities.PlayKubeReport, []*notifyproxy.NotifyProxy, error) {
cfg, err := ic.Libpod.GetConfigNoCopy()
if err != nil {
return nil, nil, err
}

var (
writer io.Writer
playKubePod entities.PlayKubePod
Expand Down Expand Up @@ -831,7 +836,7 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
}

if podOpt.Infra {
infraImage := util.DefaultContainerConfig().Engine.InfraImage
infraImage := cfg.Engine.InfraImage
infraOptions := entities.NewInfraContainerCreateOptions()
infraOptions.Hostname = podSpec.PodSpecGen.PodBasicConfig.Hostname
infraOptions.ReadOnly = true
Expand Down Expand Up @@ -904,11 +909,6 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY
}
}

cfg, err := ic.Libpod.GetConfigNoCopy()
if err != nil {
return nil, nil, err
}

var readOnly types.OptionalBool
if cfg.Containers.ReadOnly {
readOnly = types.NewOptionalBool(cfg.Containers.ReadOnly)
Expand Down
9 changes: 7 additions & 2 deletions pkg/specgen/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/containers/common/libnetwork/types"
"github.com/containers/common/pkg/cgroups"
"github.com/containers/common/pkg/config"
"github.com/containers/podman/v5/libpod/define"
"github.com/containers/podman/v5/pkg/namespaces"
"github.com/containers/podman/v5/pkg/util"
Expand Down Expand Up @@ -333,14 +334,18 @@ func ParseUserNamespace(ns string) (Namespace, error) {
// If the input is nil or empty it will use the default setting from containers.conf
func ParseNetworkFlag(networks []string) (Namespace, map[string]types.PerNetworkOptions, map[string][]string, error) {
var networkOptions map[string][]string
toReturn := Namespace{}
// by default we try to use the containers.conf setting
// if we get at least one value use this instead
ns := containerConfig.Containers.NetNS
cfg, err := config.Default()
if err != nil {
return toReturn, nil, nil, err
}
ns := cfg.Containers.NetNS
if len(networks) > 0 {
ns = networks[0]
}

toReturn := Namespace{}
podmanNetworks := make(map[string]types.PerNetworkOptions)

switch {
Expand Down
3 changes: 0 additions & 3 deletions pkg/specgen/pod_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ package specgen
import (
"errors"
"fmt"

"github.com/containers/podman/v5/pkg/util"
)

var (
// ErrInvalidPodSpecConfig describes an error given when the podspecgenerator is invalid
ErrInvalidPodSpecConfig = errors.New("invalid pod spec")
// containerConfig has the default configurations defined in containers.conf
containerConfig = util.DefaultContainerConfig()
)

func exclusivePodOptions(opt1, opt2 string) error {
Expand Down
16 changes: 0 additions & 16 deletions pkg/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"time"

"github.com/BurntSushi/toml"
"github.com/containers/common/pkg/config"
"github.com/containers/image/v5/types"
"github.com/containers/podman/v5/libpod/define"
"github.com/containers/podman/v5/pkg/errorhandling"
Expand All @@ -43,17 +42,6 @@ type idMapFlags struct {
GroupMap bool // The "g" flag
}

var containerConfig *config.Config

func init() {
var err error
containerConfig, err = config.Default()
if err != nil {
logrus.Error(err)
os.Exit(1)
}
}

// Helper function to determine the username/password passed
// in the creds string. It could be either or both.
func parseCreds(creds string) (string, string) {
Expand Down Expand Up @@ -1225,10 +1213,6 @@ func ValidateSysctls(strSlice []string) (map[string]string, error) {
return sysctl, nil
}

func DefaultContainerConfig() *config.Config {
return containerConfig
}

func CreateIDFile(path string, id string) error {
idFile, err := os.Create(path)
if err != nil {
Expand Down

1 comment on commit 62c1016

@packit-as-a-service
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

podman-next COPR build failed. @containers/packit-build please check.

Please sign in to comment.