diff --git a/cmd/podman/containers/port.go b/cmd/podman/containers/port.go index 672960d087..4ecb680b4f 100644 --- a/cmd/podman/containers/port.go +++ b/cmd/podman/containers/port.go @@ -125,8 +125,7 @@ func port(_ *cobra.Command, args []string) error { if hostIP == "" { hostIP = "0.0.0.0" } - protocols := strings.Split(v.Protocol, ",") - for _, protocol := range protocols { + for protocol := range strings.SplitSeq(v.Protocol, ",") { // If not searching by port or port/proto, then dump what we see if port == "" { for i := uint16(0); i < v.Range; i++ { diff --git a/cmd/podman/parse/net.go b/cmd/podman/parse/net.go index d797ef8745..3f6806e18f 100644 --- a/cmd/podman/parse/net.go +++ b/cmd/podman/parse/net.go @@ -39,8 +39,7 @@ func ValidateExtraHost(val string) (string, error) { } // Split the hostnames by semicolon and validate each one - nameList := strings.Split(names, ";") - for _, name := range nameList { + for name := range strings.SplitSeq(names, ";") { if len(name) == 0 { return "", fmt.Errorf("hostname in add-host %q is empty", val) } diff --git a/cmd/rootlessport/main.go b/cmd/rootlessport/main.go index b03f8a187c..53123d1c12 100644 --- a/cmd/rootlessport/main.go +++ b/cmd/rootlessport/main.go @@ -294,8 +294,7 @@ func handler(ctx context.Context, conn io.Reader, pm rkport.Manager) error { func exposePorts(pm rkport.Manager, portMappings []types.PortMapping, childIP string) error { ctx := context.TODO() for _, port := range portMappings { - protocols := strings.Split(port.Protocol, ",") - for _, protocol := range protocols { + for protocol := range strings.SplitSeq(port.Protocol, ",") { hostIP := port.HostIP if hostIP == "" { hostIP = "0.0.0.0" diff --git a/cmd/winpath/main.go b/cmd/winpath/main.go index cc9f67f730..b0c6267ecd 100644 --- a/cmd/winpath/main.go +++ b/cmd/winpath/main.go @@ -96,7 +96,7 @@ func addPathToRegistry(dir string) error { } // Is this directory already on the windows path? - for _, element := range strings.Split(existing, ";") { + for element := range strings.SplitSeq(existing, ";") { if strings.EqualFold(element, dir) { // Path already added return nil @@ -147,7 +147,7 @@ func removePathFromRegistry(path string) error { // No point preallocating we can't know how big the array needs to be. //nolint:prealloc var elements []string - for _, element := range strings.Split(existing, ";") { + for element := range strings.SplitSeq(existing, ";") { if strings.EqualFold(element, path) { continue } diff --git a/hack/podman-registry-go/registry.go b/hack/podman-registry-go/registry.go index fb2c81f9a9..912fa2745a 100644 --- a/hack/podman-registry-go/registry.go +++ b/hack/podman-registry-go/registry.go @@ -72,7 +72,7 @@ func StartWithOptions(options *Options) (*Registry, error) { // Parse the output. registry := Registry{} - for _, s := range strings.Split(out, "\n") { + for s := range strings.SplitSeq(out, "\n") { if s == "" { continue } diff --git a/libpod/container_top_linux.go b/libpod/container_top_linux.go index 021bd1ee87..a169816278 100644 --- a/libpod/container_top_linux.go +++ b/libpod/container_top_linux.go @@ -201,7 +201,7 @@ func (c *Container) Top(descriptors []string) ([]string, error) { // Also support comma-separated input. psgoDescriptors := []string{} for _, d := range descriptors { - for _, s := range strings.Split(d, ",") { + for s := range strings.SplitSeq(d, ",") { if s != "" { psgoDescriptors = append(psgoDescriptors, s) } diff --git a/libpod/kube.go b/libpod/kube.go index c63e8f72e8..60fb511940 100644 --- a/libpod/kube.go +++ b/libpod/kube.go @@ -1084,8 +1084,7 @@ func containerToV1Container(ctx context.Context, c *Container, getService bool) func portMappingToContainerPort(portMappings []types.PortMapping, getService bool) ([]v1.ContainerPort, error) { containerPorts := make([]v1.ContainerPort, 0, len(portMappings)) for _, p := range portMappings { - protocols := strings.Split(p.Protocol, ",") - for _, proto := range protocols { + for proto := range strings.SplitSeq(p.Protocol, ",") { var protocol v1.Protocol switch strings.ToUpper(proto) { case "TCP": @@ -1360,7 +1359,7 @@ func generateKubeSecurityContext(c *Container) (*v1.SecurityContext, bool, error } var selinuxOpts v1.SELinuxOptions selinuxHasData := false - for _, label := range strings.Split(c.config.Spec.Annotations[define.InspectAnnotationLabel], ",label=") { + for label := range strings.SplitSeq(c.config.Spec.Annotations[define.InspectAnnotationLabel], ",label=") { opt, val, hasVal := strings.Cut(label, ":") if hasVal { switch opt { diff --git a/libpod/oci_conmon_common.go b/libpod/oci_conmon_common.go index 8ef3e47f7c..b972b357c0 100644 --- a/libpod/oci_conmon_common.go +++ b/libpod/oci_conmon_common.go @@ -363,8 +363,7 @@ func (r *ConmonOCIRuntime) StopContainer(ctr *Container, timeout uint, all bool) // Before handling error from KillContainer, convert STDERR to a []string // (one string per line of output) and print it. - stderrLines := strings.Split(stderr.String(), "\n") - for _, line := range stderrLines { + for line := range strings.SplitSeq(stderr.String(), "\n") { if line != "" { fmt.Fprintf(os.Stderr, "%s\n", line) } diff --git a/libpod/oci_conmon_linux.go b/libpod/oci_conmon_linux.go index 4290670a9f..757eb7537a 100644 --- a/libpod/oci_conmon_linux.go +++ b/libpod/oci_conmon_linux.go @@ -81,7 +81,7 @@ func (r *ConmonOCIRuntime) createRootlessContainer(ctr *Container, restoreOption for dir := filepath.Dir(rootPath); ; dir = filepath.Dir(dir) { if m, found := byMountpoint[dir]; found { parentMount = dir - for _, o := range strings.Split(m.Optional, ",") { + for o := range strings.SplitSeq(m.Optional, ",") { opt := strings.Split(o, ":") if opt[0] == "shared" { isShared = true diff --git a/libpod/util.go b/libpod/util.go index 7d53e36669..4d53c339a8 100644 --- a/libpod/util.go +++ b/libpod/util.go @@ -205,8 +205,7 @@ func writeHijackHeader(r *http.Request, conn io.Writer, tty bool) { func makeInspectPortBindings(bindings []types.PortMapping) map[string][]define.InspectHostPort { portBindings := make(map[string][]define.InspectHostPort) for _, port := range bindings { - protocols := strings.Split(port.Protocol, ",") - for _, protocol := range protocols { + for protocol := range strings.SplitSeq(port.Protocol, ",") { for i := uint16(0); i < port.Range; i++ { key := fmt.Sprintf("%d/%s", port.ContainerPort+i, protocol) hostPorts := portBindings[key] diff --git a/pkg/domain/infra/abi/parse/parse.go b/pkg/domain/infra/abi/parse/parse.go index 268610716c..41771bb887 100644 --- a/pkg/domain/infra/abi/parse/parse.go +++ b/pkg/domain/infra/abi/parse/parse.go @@ -24,9 +24,8 @@ func VolumeOptions(opts map[string]string) ([]libpod.VolumeCreateOption, error) case "o": // o has special handling to parse out UID, GID. // These are separate Libpod options. - splitVal := strings.Split(value, ",") finalVal := []string{} - for _, o := range splitVal { + for o := range strings.SplitSeq(value, ",") { // Options will be formatted as either "opt" or // "opt=value" opt, val, hasVal := strings.Cut(o, "=") diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go index 3c602494c0..a549b7e59a 100644 --- a/pkg/domain/infra/abi/play.go +++ b/pkg/domain/infra/abi/play.go @@ -135,7 +135,7 @@ func (ic *ContainerEngine) prepareAutomountImages(ctx context.Context, forContai return nil, nil } - for _, imageName := range strings.Split(automount, ";") { + for imageName := range strings.SplitSeq(automount, ";") { img, fullName, err := ic.Libpod.LibimageRuntime().LookupImage(imageName, nil) if err != nil { return nil, fmt.Errorf("image %s from container %s does not exist in local storage, cannot automount: %w", imageName, forContainer, err) diff --git a/pkg/machine/e2e/config_test.go b/pkg/machine/e2e/config_test.go index 28d30e2498..11e07bac63 100644 --- a/pkg/machine/e2e/config_test.go +++ b/pkg/machine/e2e/config_test.go @@ -75,7 +75,7 @@ func (ms *machineSession) Bytes() []byte { func (ms *machineSession) outputToStringSlice() []string { var results []string output := string(ms.Out.Contents()) - for _, line := range strings.Split(output, "\n") { + for line := range strings.SplitSeq(output, "\n") { if line != "" { results = append(results, line) } diff --git a/pkg/namespaces/namespaces.go b/pkg/namespaces/namespaces.go index 9464d9d485..ca2c8ed3b8 100644 --- a/pkg/namespaces/namespaces.go +++ b/pkg/namespaces/namespaces.go @@ -71,7 +71,7 @@ func (n UsernsMode) GetKeepIDOptions() (*KeepIDUserNsOptions, error) { if !hasOpts { return &options, nil } - for _, o := range strings.Split(nsopts, ",") { + for o := range strings.SplitSeq(nsopts, ",") { opt, val, hasVal := strings.Cut(o, "=") if !hasVal { return nil, fmt.Errorf("invalid option specified: %q", o) diff --git a/pkg/rctl/rctl_freebsd.go b/pkg/rctl/rctl_freebsd.go index 2615aff74d..e7e3671923 100644 --- a/pkg/rctl/rctl_freebsd.go +++ b/pkg/rctl/rctl_freebsd.go @@ -26,9 +26,8 @@ func GetRacct(filter string) (map[string]uint64, error) { return nil, fmt.Errorf("error calling rctl_get_racct with filter %s: %v", filter, errno) } len := bytes.IndexByte(buf[:], byte(0)) - entries := strings.Split(string(buf[:len]), ",") res := make(map[string]uint64) - for _, entry := range entries { + for entry := range strings.SplitSeq(string(buf[:len]), ",") { key, valstr, _ := strings.Cut(entry, "=") val, err := strconv.ParseUint(valstr, 10, 0) if err != nil { diff --git a/pkg/rootless/rootless_linux.go b/pkg/rootless/rootless_linux.go index 1180f4e5b3..40169bc863 100644 --- a/pkg/rootless/rootless_linux.go +++ b/pkg/rootless/rootless_linux.go @@ -230,7 +230,7 @@ func becomeRootInUserNS(pausePid string) (_ bool, _ int, retErr error) { for _, m := range mounts { if m.Mountpoint == "/" { isShared := false - for _, o := range strings.Split(m.Optional, ",") { + for o := range strings.SplitSeq(m.Optional, ",") { if strings.HasPrefix(o, "shared:") { isShared = true break diff --git a/pkg/specgen/generate/kube/kube.go b/pkg/specgen/generate/kube/kube.go index c3c9959024..0d09801ab8 100644 --- a/pkg/specgen/generate/kube/kube.go +++ b/pkg/specgen/generate/kube/kube.go @@ -293,8 +293,7 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener ulimitVal, ok := opts.Annotations[define.UlimitAnnotation] if ok { - ulimits := strings.Split(ulimitVal, ",") - for _, ul := range ulimits { + for ul := range strings.SplitSeq(ulimitVal, ",") { parsed, err := units.ParseUlimit(ul) if err != nil { return nil, err diff --git a/pkg/specgen/generate/ports.go b/pkg/specgen/generate/ports.go index 699779a0f8..c280a1cbfe 100644 --- a/pkg/specgen/generate/ports.go +++ b/pkg/specgen/generate/ports.go @@ -378,9 +378,8 @@ func createPortMappings(s *specgen.SpecGenerator, imageData *libimage.ImageData) // Check a string to ensure it is a comma-separated set of valid protocols func checkProtocol(protocol string) ([]string, error) { protocols := make(map[string]struct{}) - splitProto := strings.Split(protocol, ",") // Don't error on duplicates - just deduplicate - for _, p := range splitProto { + for p := range strings.SplitSeq(protocol, ",") { p = strings.ToLower(p) switch p { case protoTCP, "": diff --git a/pkg/specgenutil/specgen.go b/pkg/specgenutil/specgen.go index 06efa443d5..effd9accbd 100644 --- a/pkg/specgenutil/specgen.go +++ b/pkg/specgenutil/specgen.go @@ -1263,7 +1263,7 @@ func parseLinuxResourcesDeviceAccess(device string) (specs.LinuxDeviceCgroup, er minor = &m } access = value[2] - for _, c := range strings.Split(access, "") { + for c := range strings.SplitSeq(access, "") { if !cgroupDeviceAccess[c] { return specs.LinuxDeviceCgroup{}, fmt.Errorf("invalid device access in device-access-add: %s", c) } diff --git a/pkg/systemd/notifyproxy/notifyproxy.go b/pkg/systemd/notifyproxy/notifyproxy.go index c8ea4748be..069e5fdd20 100644 --- a/pkg/systemd/notifyproxy/notifyproxy.go +++ b/pkg/systemd/notifyproxy/notifyproxy.go @@ -145,7 +145,7 @@ func (p *NotifyProxy) listen() { sBuilder.Write(buffer[:n]) var isBarrier, isReady bool - for _, line := range strings.Split(sBuilder.String(), "\n") { + for line := range strings.SplitSeq(sBuilder.String(), "\n") { switch line { case _notifyRdyMsg: isReady = true diff --git a/test/utils/utils.go b/test/utils/utils.go index 3643c86e75..316061a3be 100644 --- a/test/utils/utils.go +++ b/test/utils/utils.go @@ -288,7 +288,7 @@ func (s *PodmanSession) OutputToString() string { func (s *PodmanSession) OutputToStringArray() []string { var results []string output := string(s.Out.Contents()) - for _, line := range strings.Split(output, "\n") { + for line := range strings.SplitSeq(output, "\n") { if line != "" { results = append(results, line) }