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

probe #74

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

probe #74

wants to merge 2 commits into from

Conversation

miekg
Copy link
Collaborator

@miekg miekg commented Jan 23, 2021

  • Check systemd supported options
  • bla

miekg added 2 commits January 23, 2021 18:26
Check the supported options in systemd and use what's availble.

Signed-off-by: Miek Gieben <[email protected]>
Signed-off-by: Miek Gieben <[email protected]>
Copy link
Member

@pires pires left a comment

Choose a reason for hiding this comment

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

This code can easily be covered by tests ;)

I would prefer this code to be there when actual probing takes place but since this is not a draft PR, I'm assuming you are looking to have this merged. Therefore, I did a thorough review.

// ProbeSupportedOptions checks it the options in SupportedOptions are
// supported by the systemd version running on this system. It will emit Info
// logs for each unsupported option.
func ProbeSupportedOptions() {
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't need to be exported. Or may it does as this is moved into the unit package where other unit stuff is?

Copy link
Member

Choose a reason for hiding this comment

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

Or may it does as this is moved into the unit package where other unit stuff is?

}

// probe probes system to see if option is supported.
func probe(option string) bool {
Copy link
Member

Choose a reason for hiding this comment

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

If this is something you are proposing to have merged without the actual probing (otherwise, it would be a draft PR, right?), please, state very clearly that this is a fake probe, as nothing is actually probed.

}

// Option return the option that is supported by the detected systemd.
func Option(option string) string {
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't need to be exported. Or may it does as this is moved into the unit package where other unit stuff is?

}

// ProbeSupportedOptions checks it the options in SupportedOptions are
// supported by the systemd version running on this system. It will emit Info
Copy link
Member

Choose a reason for hiding this comment

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

I'd say warning logs.

@@ -0,0 +1,39 @@
package provider

// supportedOptions contains a mappnig for supported systemd options. If an option
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// supportedOptions contains a mappnig for supported systemd options. If an option
// supportedOptions contains a mapping for supported systemd options. If an option

opt, ok := supportedOptions[option]
if !ok {
// not found in map, return option as-is
return option
Copy link
Member

Choose a reason for hiding this comment

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

Given we know exactly what options are used in systemk, supportedOptions would be complete for the purpose of probing. Why would this be a scenario?

@@ -84,7 +84,11 @@ func (u *File) String() string {
}

// Insert adds name=value to section and returns a newly parsed pointer to File.
// If name is the empty string this is a noop.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// If name is the empty string this is a noop.
// If name is an empty string, this is a noop.

@@ -98,7 +102,11 @@ func (u *File) Insert(section, name string, value ...string) *File {
}

// Overwrite overwrites name=value in the section and returns a new File.
// If name is the empty string this is a noop.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// If name is the empty string this is a noop.
// If name is an empty string, this is a noop.

func (u *File) Insert(section, name string, value ...string) *File {
if name == "" {
Copy link
Member

Choose a reason for hiding this comment

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

Please, add a comment above stating that this is empty only when the option is not supported by the current systemd and no alternative is available.

func (u *File) Overwrite(section, name string, value ...string) *File {
if name == "" {
Copy link
Member

Choose a reason for hiding this comment

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

Please, add a comment above stating that this is empty only when the option is not supported by the current systemd and no alternative is available.

@miekg
Copy link
Collaborator Author

miekg commented Jan 23, 2021 via email

@pires
Copy link
Member

pires commented Jan 23, 2021

I think it's a safe bet because it's systemd 219, a really old version. We can also not actually probe and basically do it by hand in code based on this small document.

@pires
Copy link
Member

pires commented Jan 23, 2021

For instance, TemporaryFileSystem is introduced in 238. Both BindPaths and BindReadOnlyPaths are introduced in 233.

@pires
Copy link
Member

pires commented Jan 23, 2021

Maybe the idea of alternative unit attributes needs to mature. For instance, mapping a string to an alternative string may be too limited. Say we are on RHEL7 and systemd 219 (<233) where we don't have BindPaths and BindReadOnlyPaths. Is there an alternative? And if there is, is it just another option or a combination of multiple options?

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.

2 participants