Skip to content

Quadlet - allow deleting the network when stopping the service #25844

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

Merged

Conversation

ygalblum
Copy link
Contributor

@ygalblum ygalblum commented Apr 9, 2025

Does this PR introduce a user-facing change?

Yes

Quadlet - Allow deleting the network when stopping the service

Resolves: #23678

@openshift-ci openshift-ci bot added release-note approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Apr 9, 2025
Copy link

[NON-BLOCKING] Packit jobs failed. @containers/packit-build please check. Everyone else, feel free to ignore.

@ygalblum ygalblum force-pushed the quadlet-network-delete branch 2 times, most recently from bf391d8 to a343554 Compare April 10, 2025 00:57
KeyIPv6: true,
KeyInternal: true,
KeyNetworkName: true,
KeyNetworkDeleteWhenStop: true,
Copy link
Member

Choose a reason for hiding this comment

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

Would NetworkDeleteOnStop sound better?

Copy link
Member

Choose a reason for hiding this comment

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

Also I suppose since this is already part of the network section we might also be able to get rid of the Network prefix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I missed the second comment. The reason I kept Network is so that it won't be used in other unit types

@ygalblum ygalblum force-pushed the quadlet-network-delete branch from a343554 to b16d5a9 Compare April 10, 2025 12:17
@@ -940,6 +942,12 @@ func ConvertNetwork(network *parser.UnitFile, name string, unitsInfoMap map[stri
// Need the containers filesystem mounted to start podman
service.Add(UnitGroup, "RequiresMountsFor", "%t/containers")

if network.LookupBooleanWithDefault(NetworkGroup, KeyNetworkDeleteOnStop, false) {
serviceStopPostCmd := createBasePodmanCommand(network, NetworkGroup)
serviceStopPostCmd.add("network", "rm", "--force", networkName)
Copy link
Member

Choose a reason for hiding this comment

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

Sorry should have checked this earlier, do we really want force in this case? Per systemd ordering it will stopped after container are stopped but not when one runs systemctl stop manually on the network right?
It could be very unexpected if the removing the unit causes podman to force remove all container that are on the network.
Having the command error in case there still are other containers running might be a good thing.

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 tested this scenario: #23678 (comment)
From what I could tell, stopping the network unit will first stop the dependent container units and only then stop the network. So, the force flag is expected to be a noop as all containers are supposed to stop before the network is deleted.

Having said that, it will remove containers that were added to this network without a proper connection in a Quadlet unit.

Copy link
Member

Choose a reason for hiding this comment

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

Ack, thanks. So then I think it is even better to not add --force, anything else would mean we have a outside container on this network which is not managed by quadlet so I would prefer to not force remove that.
Returning an error in this case seems like the best option.

Copy link
Member

Choose a reason for hiding this comment

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

Concur, force-removal seems too aggressive - likely to cause some collateral damage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I removed the --force flag and also enhanced the test to make sure dependency works

@baude
Copy link
Member

baude commented Apr 10, 2025

LGTM after all comments addressed

@ygalblum ygalblum force-pushed the quadlet-network-delete branch from b16d5a9 to 0d4a148 Compare April 10, 2025 14:34
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

Copy link
Contributor

openshift-ci bot commented Apr 10, 2025

[APPROVALNOTIFIER] This PR is APPROVED

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

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

@ygalblum
Copy link
Contributor Author

@baude I made some small changes since your review

@baude
Copy link
Member

baude commented Apr 14, 2025

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 14, 2025
@openshift-merge-bot openshift-merge-bot bot merged commit 09c2546 into containers:main Apr 14, 2025
75 checks passed
@ygalblum ygalblum deleted the quadlet-network-delete branch April 14, 2025 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Network isn't removed when systemctl stop *-network.service
4 participants