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

quadlet: Add a network requirement on .image and .containers units #22057

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jbtrystram
Copy link

If a container unit starts on boot with a dependency on default.target
the image unit may start too soon, before network is ready. This cause
the unit to fail to pull the image.
Add a dependency on network-online.target to make sure image pulls
don't fail.

Does this PR introduce a user-facing change?

yes

Image oneshot units generated through quadlet will now have a dependency on `network-online.target`

Fixes #21873

Copy link

Cockpit tests failed for commit aa7b604. @martinpitt, @jelly, @mvollmer please check.

Copy link

Cockpit tests failed for commit d2d5b1e. @martinpitt, @jelly, @mvollmer please check.

@rhatdan
Copy link
Member

rhatdan commented Mar 15, 2024

LGTM
@ygalblum @alexlarsson @mheon PTAL

@ygalblum
Copy link
Collaborator

The specific code LGTM. But, it addresses only the .image files. Doesn't the same rational apply for .container and .kube files?

In addition, while the documentation states that setting After= will remove this dependency, there is no test to verify it. In order for it to work, Quadlet needs to make sure the keys set by the user are placed after the ones it sets on its own. While this might be the case now, without a test, there is no guaranty that this behavior does not break in the future.

@jbtrystram
Copy link
Author

@ygalblum I am looking at adding another test to verify that After= removes the dependency, but I can't see any assertion helper to use, so I am trying to add one.

I started to add assert-key-is-last which would call UnitFile.LookupLast but then I need the key to have no arguments.
The assertion then would be assert-key-is-last-and-empty but then it becomes awfully specific !
Do you have any other idea ? It's my first contrib to podman so I don't know my way around the codebase :)

@ygalblum
Copy link
Collaborator

@jbtrystram how about assert-last-key-is-regex and pass ^$?

jbtrystram added a commit to jbtrystram/podman that referenced this pull request Mar 20, 2024
Required to test the `After=` override in [Unit] section
See containers#22057 (comment)
@jbtrystram
Copy link
Author

@ygalblum neat suggestion, thanks !
I added that. I am having synchronisation issues when running make test locally though, let's see if the CI runs the test !

jbtrystram added a commit to jbtrystram/podman that referenced this pull request Mar 20, 2024
Required to test the `After=` override in [Unit] section
See containers#22057 (comment)

Signed-off-by: jbtrystram <jbtrystram@redhat.com>
Copy link

Cockpit tests failed for commit 2b45a19. @martinpitt, @jelly, @mvollmer please check.

Copy link

Cockpit tests failed for commit c26db33. @martinpitt, @jelly, @mvollmer please check.

test/e2e/quadlet_test.go Outdated Show resolved Hide resolved
@dustymabe
Copy link
Contributor

added a comment to the issue but linking it here:

#21873 (comment)

@rhatdan
Copy link
Member

rhatdan commented Mar 29, 2024

@jbtrystram What is going on with this PR?

@jbtrystram
Copy link
Author

@rhatdan This is something i am working on my spare time and i hadn't had a lot of that lately, sorry.
I'll follow up soon

@jbtrystram jbtrystram changed the title quadlet: Add a network requirement on .image units quadlet: Add a network requirement on .image and .containers units Apr 22, 2024
jbtrystram added a commit to jbtrystram/podman that referenced this pull request Apr 22, 2024
Required to test the `After=` override in [Unit] section
See containers#22057 (comment)

Signed-off-by: jbtrystram <jbtrystram@redhat.com>
Copy link

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

jbtrystram added a commit to jbtrystram/podman that referenced this pull request Apr 23, 2024
Required to test the `After=` override in [Unit] section
See containers#22057 (comment)

Signed-off-by: jbtrystram <jbtrystram@redhat.com>
@jbtrystram

This comment was marked as off-topic.

@jbtrystram
Copy link
Author

jbtrystram commented Apr 24, 2024

@ygalblum I picked that up and fixed it. The quadlet.go code behave as expected, as quadlet --dryrun on unit-after-override.image gives :

---test.service---
## assert-last-key-is-regex "Unit" "After" "^$"

[Unit]
Wants=network-online.target
After=network-online.target
After=
SourcePath=/etc/containers/systemd/test.container
RequiresMountsFor=%t/containers

.....

However the test code with that assert-last-key-is-regex does not work yet. I'll keep working on it but still pushed, if you have some suggestions in the meanwhile i'll take them :)

I tried to add some debug statements in the test code but they're not printed when running make localintegration FOCUS_FILE=quadlet_test.go

test/e2e/quadlet_test.go Outdated Show resolved Hide resolved
@ygalblum
Copy link
Collaborator

Another two tests are failing since they already check the After key. The check assert-key-is expects all the values in the correct order. So you need to change the following:
test/e2e/quadlet/mount.container, line 13:

## assert-key-is "Unit" "After" "network-online.target" "vol2-volume.service"

test/e2e/quadlet/network.quadlet.container, line 3:

## assert-key-is "Unit" "After" "network-online.target" "basic-network.service"

jbtrystram added a commit to jbtrystram/podman that referenced this pull request Apr 25, 2024
If a container unit starts on boot with a dependency on `default.target`
the image unit may start too soon, before network is ready. This cause
the unit to fail to pull the image.
- Add a dependency on `network-online.target` to make sure image pulls
don't fail.
See containers#21873

- Document the hardcoded dependency on `network-online.target` for images unit
and explain how it can be overriden if necessary.

- tests/e2e/quadlet: Add `assert-last-key-regex`

Required to test the `After=` override in [Unit] section
See containers#22057 (comment)

- quadlet/unitfile: add a prepenUnitLine method

Requirements on networks should be inserted at the top of the
section so the user can override them.

Signed-off-by: jbtrystram <jbtrystram@redhat.com>
jbtrystram added a commit to jbtrystram/podman that referenced this pull request Apr 25, 2024
If a container unit starts on boot with a dependency on `default.target`
the image unit may start too soon, before network is ready. This cause
the unit to fail to pull the image.
- Add a dependency on `network-online.target` to make sure image pulls
don't fail.
See containers#21873

- Document the hardcoded dependency on `network-online.target` for images unit
and explain how it can be overriden if necessary.

- tests/e2e/quadlet: Add `assert-last-key-regex`

Required to test the `After=` override in [Unit] section
See containers#22057 (comment)

- quadlet/unitfile: add a prepenUnitLine method

Requirements on networks should be inserted at the top of the
section so the user can override them.

Signed-off-by: jbtrystram <jbtrystram@redhat.com>
If a container unit starts on boot with a dependency on `default.target`
the image unit may start too soon, before network is ready. This cause
the unit to fail to pull the image.
- Add a dependency on `network-online.target` to make sure image pulls
don't fail.
See containers#21873

- Document the hardcoded dependency on `network-online.target` for images unit
and explain how it can be overriden if necessary.

- tests/e2e/quadlet: Add `assert-last-key-regex`

Required to test the `After=` override in [Unit] section
See containers#22057 (comment)

- quadlet/unitfile: add a prepenUnitLine method

Requirements on networks should be inserted at the top of the
section so the user can override them.

Signed-off-by: jbtrystram <jbtrystram@redhat.com>
@jbtrystram
Copy link
Author

Thanks @ygalblum for the help.
I squashed the commits and rebased. The failing tests seem unrelated

Copy link
Contributor

openshift-ci bot commented Apr 28, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jbtrystram, 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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 28, 2024
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. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Quadlet .image file should wait for dns name resolution
4 participants