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

User units #1303

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

User units #1303

wants to merge 1 commit into from

Conversation

Nemric
Copy link
Contributor

@Nemric Nemric commented Jan 12, 2022

This should allow users to create user-level systemd units in ignition

I've added tests that write units in internal/exec/stages/files/units_test.go

@Nemric Nemric closed this Jan 13, 2022
@Nemric Nemric deleted the user-units branch January 13, 2022 16:00
@Nemric Nemric restored the user-units branch January 13, 2022 16:00
@bgilbert bgilbert reopened this Jan 13, 2022
@bgilbert bgilbert linked an issue Jan 14, 2022 that may be closed by this pull request
config/shared/errors/errors.go Outdated Show resolved Hide resolved
config/v3_4_experimental/types/unit.go Outdated Show resolved Hide resolved
config/v3_4_experimental/types/unit.go Outdated Show resolved Hide resolved
config/v3_4_experimental/types/unit.go Outdated Show resolved Hide resolved
internal/exec/stages/files/files.go Outdated Show resolved Hide resolved
internal/exec/util/path.go Outdated Show resolved Hide resolved
internal/exec/util/path.go Outdated Show resolved Hide resolved
internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
@Nemric Nemric force-pushed the user-units branch 2 times, most recently from f28a6b2 to 987794f Compare February 10, 2022 18:22
@Nemric
Copy link
Contributor Author

Nemric commented Feb 18, 2022

Hi,
I'd like to know how to replay ci/jenkins as it fails, at first sight, because of coreos/coreos-assembler#2701 that is now closed
Thanks :)

@dustymabe
Copy link
Member

@Nemric - I restarted the continuous-integration/jenkins/pr-merge run.

@dustymabe
Copy link
Member

I logged in and restarted it, but one easy way to restart CI if you don't have access to log in is to rebase your PR and re-push.

@dustymabe
Copy link
Member

The continuous-integration/jenkins/pr-merge passed! 🎉

Copy link
Contributor

@bgilbert bgilbert left a comment

Choose a reason for hiding this comment

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

Nice work. This is getting closer!

config/v3_4_experimental/types/unit.go Outdated Show resolved Hide resolved
config/v3_4_experimental/types/unit.go Outdated Show resolved Hide resolved
docs/configuration-v3_4_experimental.md Outdated Show resolved Hide resolved
config/v3_4_experimental/types/unit.go Show resolved Hide resolved
config/v3_4_experimental/types/unit.go Outdated Show resolved Hide resolved
if err := s.relabelPath(filepath.Join(s.DestDir, path)); err != nil {
return err
}
paths[path] = true
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't use the false and true values. paths can be a map[string]struct{}.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true or false are used here if _, value := paths[path]; !value {} to check if paths have been relabelled or not.
This prevent multiple relabel ... that could be in a separate PR as we said previously ... I'm thinking about it

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope, you're ignoring the map value (the first return value) and only checking whether the key is present (the second return value). So any map value will do, and traditionally struct{}{} is used in that case.

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 will try to manage multiple relabelling in a better way, in another PR, so this piece of code should disappear, it seems to be a better approach isn't it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cf #1324

internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
relabelPath := f.Node.Path[len(s.DestDir):]
if err := s.Logger.LogOp(
func() error { return s.PerformFetch(f) },
"writing unit %q at %q", unit.Key(), f.Node.Path,
Copy link
Contributor

Choose a reason for hiding this comment

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

Key() is not meant to be human-readable.

}
if !relabeledDropinDir {
s.relabel(filepath.Dir(relabelPath))
relabeledDropinDir = true
Copy link
Contributor

Choose a reason for hiding this comment

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

This assumes FilesFromSystemdUnitDropin returns values in sorted order.

Overall I'm wondering if it'd be better to have a separate preparatory PR that teaches the relabeling infrastructure to avoid redundant relabeling, so the rest of the codebase doesn't need to think about it anymore. These individual checks are annoying to maintain.

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 agree, that's why I did it on a previous commit : #1303 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, you did. 🙂 Since it's a cleanup that isn't directly related to this PR, and it's not a tiny change (since it'll allow some existing code to be simplified), it'd be better to move that change to a separate PR that can land first.

Copy link
Contributor Author

@Nemric Nemric Mar 4, 2022

Choose a reason for hiding this comment

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

cf #1324

}
}

func TestCreateUnits(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We generally don't have unit tests that require root or that modify the filesystem; we use blackbox tests for that. This might be okay, but I think it's surprising to have it here.

Copy link
Contributor Author

@Nemric Nemric Feb 26, 2022

Choose a reason for hiding this comment

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

I did that because I work in a Golang container that can't (or at least I don know how) run blackbox test...
I was written in the same way as

func TestUserLookup(t *testing.T) {

On the other hand, It was used for debugging purpose :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I didn't know about that code. That's a different case though; it's testing some of the C bindings, not the general behavior of some Ignition feature.

During development, of course feel free to write code however is convenient for you. Let's get this cleaned up before merging, though.

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, will remove that before merging :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for systemd user services
3 participants