-
Notifications
You must be signed in to change notification settings - Fork 13
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
base: main
Are you sure you want to change the base?
Conversation
miekg
commented
Jan 23, 2021
- Check systemd supported options
- bla
Check the supported options in systemd and use what's availble. Signed-off-by: Miek Gieben <miek@miek.nl>
There was a problem hiding this 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() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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 == "" { |
There was a problem hiding this comment.
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 == "" { |
There was a problem hiding this comment.
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.
Thanks
Good point on providing alternative options. Every option that we use
should be probed. I wonder if we can take RH7's systemd's version as a base
of supported options
…On Sat, 23 Jan 2021, 20:28 Pires, ***@***.***> wrote:
***@***.**** commented on this pull request.
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.
------------------------------
In internal/provider/probe.go
<#74 (comment)>
:
> @@ -0,0 +1,39 @@
+package provider
+
+// supportedOptions contains a mappnig for supported systemd options. If an option
+// is supported the key name will be returned. Unsupported either return an
+// empty string (really not supported) or an alternative option that's better
+// than nothing at all.
+var supportedOptions = map[string]string{
+ "BindReadOnlyPaths": "BindReadOnlyPaths",
+}
+
+// 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() {
Doesn't need to be exported. Or may it does as this is moved into the unit
package where other unit stuff is?
------------------------------
In internal/provider/probe.go
<#74 (comment)>
:
> +// supported by the systemd version running on this system. It will emit Info
+// logs for each unsupported option.
+func ProbeSupportedOptions() {
+ for option := range supportedOptions {
+ ok := probe(option)
+ switch option {
+ case "BindReadOnlyPaths":
+ if !ok {
+ supportedOptions[option] = "BindPaths" // drop the RO bit
+ }
+ }
+ }
+}
+
+// probe probes system to see if option is supported.
+func probe(option string) bool {
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.
------------------------------
In internal/provider/probe.go
<#74 (comment)>
:
> + switch option {
+ case "BindReadOnlyPaths":
+ if !ok {
+ supportedOptions[option] = "BindPaths" // drop the RO bit
+ }
+ }
+ }
+}
+
+// probe probes system to see if option is supported.
+func probe(option string) bool {
+ return true
+}
+
+// Option return the option that is supported by the detected systemd.
+func Option(option string) string {
Doesn't need to be exported. Or may it does as this is moved into the unit
package where other unit stuff is?
------------------------------
In internal/provider/probe.go
<#74 (comment)>
:
> @@ -0,0 +1,39 @@
+package provider
+
+// supportedOptions contains a mappnig for supported systemd options. If an option
+// is supported the key name will be returned. Unsupported either return an
+// empty string (really not supported) or an alternative option that's better
+// than nothing at all.
+var supportedOptions = map[string]string{
+ "BindReadOnlyPaths": "BindReadOnlyPaths",
+}
+
+// ProbeSupportedOptions checks it the options in SupportedOptions are
+// supported by the systemd version running on this system. It will emit Info
I'd say warning logs.
------------------------------
In internal/provider/probe.go
<#74 (comment)>
:
> @@ -0,0 +1,39 @@
+package provider
+
+// supportedOptions contains a mappnig for supported systemd options. If an option
⬇️ Suggested change
-// supportedOptions contains a mappnig for supported systemd options. If an option
+// supportedOptions contains a mapping for supported systemd options. If an option
------------------------------
In internal/provider/probe.go
<#74 (comment)>
:
> @@ -0,0 +1,39 @@
+package provider
+
+// supportedOptions contains a mappnig for supported systemd options. If an option
+// is supported the key name will be returned. Unsupported either return an
⬇️ Suggested change
-// is supported the key name will be returned. Unsupported either return an
+// is supported, the value equals the key, otherwise the value is either an
------------------------------
In internal/provider/probe.go
<#74 (comment)>
:
> @@ -0,0 +1,39 @@
+package provider
+
+// supportedOptions contains a mappnig for supported systemd options. If an option
+// is supported the key name will be returned. Unsupported either return an
+// empty string (really not supported) or an alternative option that's better
+// than nothing at all.
It's unclear how it is *better than nothing at all*. Is the value another
option that we know is supported by older systemd versions?
------------------------------
In internal/provider/probe.go
<#74 (comment)>
:
> @@ -0,0 +1,39 @@
+package provider
+
+// supportedOptions contains a mappnig for supported systemd options. If an option
+// is supported the key name will be returned. Unsupported either return an
+// empty string (really not supported) or an alternative option that's better
+// than nothing at all.
+var supportedOptions = map[string]string{
+ "BindReadOnlyPaths": "BindReadOnlyPaths",
+}
+
+// ProbeSupportedOptions checks it the options in SupportedOptions are
⬇️ Suggested change
-// ProbeSupportedOptions checks it the options in SupportedOptions are
+// ProbeSupportedOptions checks if the options in supportedOptions are
------------------------------
In internal/provider/probe.go
<#74 (comment)>
:
> +// empty string (really not supported) or an alternative option that's better
+// than nothing at all.
+var supportedOptions = map[string]string{
+ "BindReadOnlyPaths": "BindReadOnlyPaths",
+}
+
+// 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() {
+ for option := range supportedOptions {
+ ok := probe(option)
+ switch option {
+ case "BindReadOnlyPaths":
+ if !ok {
+ supportedOptions[option] = "BindPaths" // drop the RO bit
This switch may grow a bit. Why not have another map with the
alternatives? Eg
alternativeOptions := map[string]string{
"BindReadOnlyPaths": "BindPaths",
}
for option := range supportedOptions {
if !probe(option) {
supportedOptions[option] = alternativeOptions[option]
}
}
------------------------------
In internal/provider/probe.go
<#74 (comment)>
:
> + }
+ }
+ }
+}
+
+// probe probes system to see if option is supported.
+func probe(option string) bool {
+ return true
+}
+
+// Option return the option that is supported by the detected systemd.
+func Option(option string) string {
+ opt, ok := supportedOptions[option]
+ if !ok {
+ // not found in map, return option as-is
+ return option
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?
------------------------------
In internal/unit/file.go
<#74 (comment)>
:
> @@ -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.
⬇️ Suggested change
-// If name is the empty string this is a noop.
+// If name is an empty string, this is a noop.
------------------------------
In internal/unit/file.go
<#74 (comment)>
:
> @@ -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.
⬇️ Suggested change
-// If name is the empty string this is a noop.
+// If name is an empty string, this is a noop.
------------------------------
In internal/unit/file.go
<#74 (comment)>
:
> func (u *File) Insert(section, name string, value ...string) *File {
+ if name == "" {
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.
------------------------------
In internal/unit/file.go
<#74 (comment)>
:
> func (u *File) Overwrite(section, name string, value ...string) *File {
+ if name == "" {
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.
------------------------------
In internal/provider/probe.go
<#74 (comment)>
:
> @@ -0,0 +1,39 @@
+package provider
+
+// supportedOptions contains a mappnig for supported systemd options. If an option
+// is supported the key name will be returned. Unsupported either return an
+// empty string (really not supported) or an alternative option that's better
+// than nothing at all.
+var supportedOptions = map[string]string{
+ "BindReadOnlyPaths": "BindReadOnlyPaths",
+}
+
+// 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() {
Or may it does as this is moved into the unit package where other unit
stuff is?
------------------------------
In internal/provider/probe.go
<#74 (comment)>
:
> @@ -0,0 +1,39 @@
+package provider
+
+// supportedOptions contains a mappnig for supported systemd options. If an option
+// is supported the key name will be returned. Unsupported either return an
+// empty string (really not supported) or an alternative option that's better
+// than nothing at all.
I'd also add that the actual probing doesn't happen here but, eventually,
when ProbeSupportedOptions is called.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#74 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACWIWY7HVTAFD6ORWJ2MC3S3MPMHANCNFSM4WP2ZQAQ>
.
|
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. |
For instance, |
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 |