Skip to content
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

Replace strings.SplitN with strings.Cut #5239

Merged
merged 1 commit into from
Jan 3, 2024
Merged

Replace strings.SplitN with strings.Cut #5239

merged 1 commit into from
Jan 3, 2024

Conversation

serprex
Copy link
Contributor

@serprex serprex commented Dec 30, 2023

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

strings.Cut is a cleaner & more performant api relative to strings.SplitN(_, _, 2) added in go 1.18

How to verify it

No change in behavior

Which issue(s) this PR fixes:

None

Special notes for your reviewer:

Introduced in go 1.18: golang/go#46336

Does this PR introduce a user-facing change?

None

@openshift-ci openshift-ci bot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Dec 30, 2023
@@ -845,23 +838,18 @@ func (b *Executor) Build(ctx context.Context, stages imagebuilder.Stages) (image
fields := strings.Split(mountFlags, ",")
for _, field := range fields {
if strings.HasPrefix(field, "from=") {
fromField := strings.SplitN(field, "=", 2)
if len(fromField) > 1 {
Copy link
Contributor Author

@serprex serprex Dec 30, 2023

Choose a reason for hiding this comment

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

I removed this condition for 2 reasons:

  1. it can never happen, since we know = appears in field
  2. the error message in the dead else path had an out of bounds access with formField[1]

@@ -124,23 +124,20 @@ func GetBindMount(ctx *types.SystemContext, args []string, contextDir string, st
return newMount, "", fmt.Errorf("cannot pass 'relabel' option more than once: %w", errBadOptionArg)
}
setRelabel = true
if len(kv) != 2 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this check because the exact same error will be raised by the default case

@rhatdan
Copy link
Member

rhatdan commented Jan 2, 2024

@nalind @vrothberg @giuseppe @umohnani8 PTAL

Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

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

Thanks! The changes LGTM. In order to pass CI, the commit message needs magic string [NO NEW TESTS NEEDED].

The CI enforces tests which in this case aren't needed.

Copy link
Contributor

openshift-ci bot commented Jan 2, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: serprex, vrothberg

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

The pull request process is described 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

@openshift-ci openshift-ci bot added the approved label Jan 2, 2024
@rhatdan
Copy link
Member

rhatdan commented Jan 2, 2024

/lgtm
Thanks @serprex
Going to do something similar in Podman?

@serprex
Copy link
Contributor Author

serprex commented Jan 2, 2024

Sure, I'll take a look. I was looking over code while looking into podman's support for COPY --link

@serprex serprex changed the title Replace strings.SplitN with strings.Cut where applicable Replace strings.SplitN with strings.Cut Jan 2, 2024
Introduced in go 1.18: golang/go#46336

[NO NEW TESTS NEEDED]

Signed-off-by: Philip Dubé <philip@peerdb.io>
@openshift-ci openshift-ci bot removed the lgtm label Jan 2, 2024
@serprex
Copy link
Contributor Author

serprex commented Jan 2, 2024

rebased to clean up commit messages since commit subject was too long

@rhatdan
Copy link
Member

rhatdan commented Jan 2, 2024

/lgtm
/hold

@umohnani8
Copy link
Member

LGTM
/hold cancel

@openshift-merge-bot openshift-merge-bot bot merged commit e56cb8e into containers:main Jan 3, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm locked - please file new issue/PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants