Skip to content

Modernize sources #26830

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Modernize sources #26830

wants to merge 10 commits into from

Conversation

kolyshkin
Copy link
Contributor

Please see individual commits for details. High level overview:

  • pkg/machine/e2e: remove obsoleted comment
  • Replace interface{} with any
  • Use for range with integers
  • Use strings.CutPrefix where appropriate
  • pkg/api/handlers/compat: use strings.CutPrefix
  • Use min and max functions where appropriate
  • Use fmt.Appendf where []byte is needed
  • Use maps.Copy / maps.Clone more
  • Use maps.Clone more (unsafe cases)
  • Use slices.Contains more

Does this PR introduce a user-facing change?

NONE

The code which comment refers to was removed by commit 2e4e1bb
("podman machine ssh handling"), so the comment is no longer valid.

Remove it.

Signed-off-by: Kir Kolyshkin <[email protected]>
Since Go 1.18, any is a type alias for interface{}.

Brought to you by

	modernize -test -fix -category=efaceany ./...

Signed-off-by: Kir Kolyshkin <[email protected]>
Replace a 3-clause

	for i := 0; i < n; i++

loop by

	for i := range n

added in go1.22.

Brought to you by

	modernize -test -fix -category=rangeint ./...

(with some manual edits to libpod/lock/shm/shm_lock_test.go on top).

Signed-off-by: Kir Kolyshkin <[email protected]>
Replace some uses of HasPrefix followed by TrimPrefix with CutPrefix,
added to the strings package in go1.20.

Brought to you by

	modernize -test -fix -category stringscutprefix  ./...

Signed-off-by: Kir Kolyshkin <[email protected]>
This way we don't check the string twice.

Signed-off-by: Kir Kolyshkin <[email protected]>
Brought to you by

	modernize -test -fix -category=minmax ./...

Signed-off-by: Kir Kolyshkin <[email protected]>
Replace []byte(fmt.Sprintf...) by fmt.Appendf(nil, ...),
added in go1.19.

Brought to you by

	modernize -test -fix -category=fmtappendf ./...

Signed-off-by: Kir Kolyshkin <[email protected]>
@openshift-ci openshift-ci bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none labels Aug 15, 2025
Copy link
Contributor

openshift-ci bot commented Aug 15, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: kolyshkin
Once this PR has been reviewed and has the lgtm label, please assign luap99 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@github-actions github-actions bot added machine kind/api-change Change to remote API; merits scrutiny labels Aug 15, 2025
@kolyshkin kolyshkin marked this pull request as ready for review August 15, 2025 03:12
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 15, 2025
In general, changes where maps.Copy is now used are always safe,
and cases where maps.Clone are used are safe as long as the original
copying code was conditional to srcMap != nil or len(srcMap) != 0.

Signed-off-by: Kir Kolyshkin <[email protected]>
There is a slight functional change here that may not be safe:
 - before this patch, if the source map is nil, the destination map
   will be empty (but non-nil);
 - after this patch, the destination map is nil if the source one is.

Practically, it may or may not matter, as reading from the nil map
is ok, and only changing it is not (will result in panic).

Signed-off-by: Kir Kolyshkin <[email protected]>
Replace 'for i, elem := range s { if elem == needle { ...; break }'
by a call to slices.Contains, added in go1.21.

Brought to you by

	modernize -fix -test -category slicescontains ./...

Signed-off-by: Kir Kolyshkin <[email protected]>
rt.storageConfig.PullOptions[k] = v
}
}
rt.storageConfig.PullOptions = maps.Clone(config.PullOptions)
Copy link
Member

Choose a reason for hiding this comment

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

This is not equivalent, in case where rt.storageConfig.PullOptions is already set and config.PullOptions is nil you unset the value to nil which is not what the previos versiond oes which keeps the orignal in this case.

I think that matters because newRuntimeFromConfig() sets the default runtime.storageConfig based on the config file so it is possible that the field has a previous value.

@@ -2,6 +2,7 @@ package main

import (
"fmt"
"maps"
Copy link
Member

Choose a reason for hiding this comment

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

That is in the wrong commit at during a bisect would fail to compile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/api-change Change to remote API; merits scrutiny machine release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants