-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
rootless: fail early if prerequiresites are not satisfied #2129
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ package podman | |
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net" | ||
"os" | ||
"path/filepath" | ||
|
@@ -53,6 +54,7 @@ func NewProvider(logger log.Logger) providers.Provider { | |
// see NewProvider | ||
type provider struct { | ||
logger log.Logger | ||
info *providers.ProviderInfo | ||
} | ||
|
||
// String implements fmt.Stringer | ||
|
@@ -354,9 +356,47 @@ func (p *provider) CollectLogs(dir string, nodes []nodes.Node) error { | |
} | ||
|
||
// Info returns the provider info. | ||
// The info is cached on the first time of the execution. | ||
func (p *provider) Info() (*providers.ProviderInfo, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should probably note that this is cached. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can not change on runtime, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a comment line about that.
Right |
||
if p.info == nil { | ||
p.info = info(p.logger) | ||
} | ||
return p.info, nil | ||
} | ||
|
||
func info(logger log.Logger) *providers.ProviderInfo { | ||
euid := os.Geteuid() | ||
info := &providers.ProviderInfo{ | ||
Rootless: os.Geteuid() != 0, | ||
Rootless: euid != 0, | ||
} | ||
if _, err := os.Stat("/sys/fs/cgroup/cgroup.controllers"); err == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is going to bite us someday when someone requests remote podman 🙃 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that will be a future work, and probably needs some work on Podman side. |
||
info.Cgroup2 = true | ||
// Unlike `docker info`, `podman info` does not print available cgroup controllers. | ||
// So we parse "cgroup.subtree_control" file by ourselves. | ||
subtreeControl := "/sys/fs/cgroup/cgroup.subtree_control" | ||
if info.Rootless { | ||
// Change subtreeControl to the path of the systemd user-instance. | ||
// Non-systemd hosts are not supported. | ||
subtreeControl = fmt.Sprintf("/sys/fs/cgroup/user.slice/user-%d.slice/user@%d.service/cgroup.subtree_control", euid, euid) | ||
} | ||
if subtreeControlBytes, err := ioutil.ReadFile(subtreeControl); err != nil { | ||
logger.Warnf("failed to read %q: %+v", subtreeControl, err) | ||
} else { | ||
for _, controllerName := range strings.Fields(string(subtreeControlBytes)) { | ||
switch controllerName { | ||
case "cpu": | ||
info.SupportsCPUShares = true | ||
case "memory": | ||
info.SupportsMemoryLimit = true | ||
case "pids": | ||
info.SupportsPidsLimit = true | ||
} | ||
} | ||
} | ||
} else if !info.Rootless { | ||
info.SupportsCPUShares = true | ||
info.SupportsMemoryLimit = true | ||
info.SupportsPidsLimit = true | ||
} | ||
return info, nil | ||
return 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.
@BenTheElder I don't know if we should validate it only on
create cluster
or always inDetectNodeProvider()
,kind/pkg/cluster/provider.go
Lines 95 to 118 in 5b79090
we currently have
<provider>.IsAvailable()
Should it be
<provider>.IsAvailableAndValid()
?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 added this validation to
create.go
because deletion should not require this validation.When a user booted the host with cgroup v2, created a rootless kind cluster, and then rebooted with cgroup v1 for running some other apps that do not support cgroup v2, the user still want to be able to remove the kind cluster.
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.
my comment is more about the long term solution, Ben always wanted to model the providers API (as you can see in the comment that I pasted above)
So I'm wondering if this is the time to do it, to avoid start to grow it organically, 👍
we should also start to think in what is supported , that is an interesting use case
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 failed to click submit on my comment earlier it seems ...
Delete should not require validation indeed, the validation is wether the tagged resource exists.
It's fine for this to grow somewhat organically internally for now, we can create a better API in the future and consider it exporting it once we have a better idea what we need. It's the public APIs that we need to be more careful with (because people already depend on them and we can't refactor them easily, so we need to make any changes minimally difficult to deal with / not really remove APIs etc.). We can completely rewrite our own internal usage. I'm going to take a sledgehammer to the "actions" thing when I get some freetime someday, and the node build code ...