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

Handle default system connection transfer properly on machine removal #23945

Merged
merged 6 commits into from
Sep 27, 2024

Conversation

jakecorrenti
Copy link
Member

Changes system connection removal so the following case now works as expected:

  • Rootless podman machine 1 is initialized and running.
  • Rootful podman machine 2 is initialized.
  • Delete podman machine 1.
  • The rootful system connection associated with podman machine 2 now becomes the default, not the rootless.

Fixes: #22577

Does this PR introduce a user-facing change?

When a user has a rootless machine running and another rootful podman machine initialized, and the rootless machine is removed, the rootful system connection associated with the podman machine now becomes the default as expected.

Adds the function `GetAllMachinesAndRootfulness` which creates a map of
all podman machines, of any supported provider, on the system and
whether it is rootful or not.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
The `RemoveFilesAndConnections` function is not being used, so its safe
to remove it and not carry unnecessary code that we need to maintain.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
@openshift-ci openshift-ci bot added release-note approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Sep 12, 2024
@baude
Copy link
Member

baude commented Sep 13, 2024

ok , LGTM (one question)

pkg/machine/connection/connection.go Outdated Show resolved Hide resolved
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

Sorry I just realized the test is not safe/working.

logrus.Error(err)

// If there is a podman-machine-default system connection, immediately set that as the new default
const defaultMachineName = "podman-machine-default"
Copy link
Member

Choose a reason for hiding this comment

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

not blocking but this is already defined as DefaultMachineName in pkg/machine.
I know this will cause a import cycle but then it can be moved into pkg/machine/define to solve this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed!

Comment on lines 60 to 71
bm := basicMachine{}
sysConnOutput, err := mb.setCmd(bm.withPodmanCommand([]string{"system", "connection", "list", "--format", "'{{.Name}}'"})).run()
Expect(err).ToNot(HaveOccurred())
names := sysConnOutput.outputToStringSlice()
sysConnOutput, err = mb.setCmd(bm.withPodmanCommand([]string{"system", "connection", "list", "--format", "'{{.Default}}'"})).run()
Expect(err).ToNot(HaveOccurred())
defaults := sysConnOutput.outputToStringSlice()
for idx, n := range names {
if n == name {
Expect(defaults[idx]).To(Equal("true"))
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I have not tried to run it but I cannot see how this can work, and if it if it is this is super risk as it can be easily be a NOP. "'{{.Name}}'" is not correct usage because the single quote will be part of the template so it will be in the output.

As such you names loop will never match...

What you should do is something like "--format", "{{.Name}}--{{.Default}}"
And then you just match Expect(sysConnOutput.outputToString()).To(ContainSubstring(name+":true"))

Then below you do the same match again.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's much cleaner, thank you. I definitely made that more complicated than it needed to be.

Moves the `DefaultMachineName` constant out of `pkg/machine` and into
`pkg/machine/define`.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
Takes the code inside the closure in the function `RemoveConnections`
and makes it a separate function to increase readability.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
Modify `RemoveConnections` to verify the new default system connection's
rootful state matches the rootful-ness of the podman machine it is associated
with.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
Copy link

Ephemeral COPR build failed. @containers/packit-build please check.

bm := basicMachine{}
sysConnOutput, err := mb.setCmd(bm.withPodmanCommand([]string{"system", "connection", "list", "--format", "{{.Name}}--{{.Default}}"})).run()
Expect(err).ToNot(HaveOccurred())
Expect(sysConnOutput.outputToString()).To(ContainSubstring(name + ":true"))
Copy link
Member

Choose a reason for hiding this comment

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

name + "--true"

Sorry that happens if I change my mind mid comment. Or you check the format to be {{.Name}}:{{.Default}}.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry about that, forgot to run the test locally before pushing...

pkg/machine/e2e/rm_test.go Outdated Show resolved Hide resolved
@jakecorrenti
Copy link
Member Author

jakecorrenti commented Sep 25, 2024

something's wrong with my macOS env... I don't think this will end up passing the test. Looking into it

Modifies the "Remove machine" test to verify the system connections are
handled properly on removal.

Signed-off-by: Jake Correnti <jakecorrenti+github@proton.me>
Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 27, 2024
Copy link
Contributor

openshift-ci bot commented Sep 27, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jakecorrenti, Luap99

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:
  • OWNERS [Luap99,jakecorrenti]

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

@openshift-merge-bot openshift-merge-bot bot merged commit adbb735 into containers:main Sep 27, 2024
80 of 86 checks passed
@stale-locking-app stale-locking-app bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Dec 27, 2024
@stale-locking-app stale-locking-app bot locked as resolved and limited conversation to collaborators Dec 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. machine release-note
Projects
None yet
3 participants