-
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
[WIP] Support remote podman #2235
Changes from all commits
f25f1ae
b782a92
7634cf4
e223bfb
58bdc4e
1d8312e
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,7 +19,6 @@ package podman | |
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net" | ||
"os" | ||
"path/filepath" | ||
|
@@ -358,45 +357,46 @@ 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) { | ||
var err error | ||
if p.info == nil { | ||
p.info = info(p.logger) | ||
p.info, err = info(p.logger) | ||
} | ||
return p.info, nil | ||
return p.info, err | ||
} | ||
|
||
func info(logger log.Logger) *providers.ProviderInfo { | ||
euid := os.Geteuid() | ||
info := &providers.ProviderInfo{ | ||
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. maybe, we just need to skip this check if we can detect is a 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. let me summon the expert, 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. Not yet but I opened containers/podman#10289. @baude, do you know a workaround? 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. @afrittoli can we try with this approach? // podman_remote returns true if podman is using a remote client
// xref: https://github.com/containers/podman/issues/10289
func podman_remote() bool{
... check https://github.com/containers/podman/issues/10289#issuecomment-838302394 ...
} |
||
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 | ||
type podmanInfo struct{ | ||
Host struct { | ||
CGroupManager string `json:"cgroupManager"` | ||
CGroupVersion string `json:"cgroupVersion"` | ||
} `json:"host"` | ||
Security struct { | ||
Rootless bool `json:"rootless"` | ||
} `json:"security"` | ||
} | ||
|
||
func info(logger log.Logger) (*providers.ProviderInfo, error) { | ||
cmd := exec.Command("podman", "info", "--format", "{{json .}}") | ||
out, err := exec.Output(cmd) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "failed to get podman info") | ||
} | ||
var pInfo podmanInfo | ||
if err := json.Unmarshal(out, &pInfo); err != nil { | ||
return nil, err | ||
} | ||
info := providers.ProviderInfo{ | ||
Cgroup2: pInfo.Host.CGroupVersion == "v2", | ||
} | ||
info.Rootless = pInfo.Security.Rootless | ||
// When CgroupManager == "none", the MemoryLimit/PidsLimit/CPUShares | ||
// values are meaningless and need to be considered false. | ||
// https://github.com/moby/moby/issues/42151 | ||
// When CGroupManager is set, we leave the default "nil" which we use as "unknown" | ||
if pInfo.Host.CGroupManager == "none" { | ||
False := false | ||
info.SupportsMemoryLimit = &False | ||
info.SupportsPidsLimit = &False | ||
info.SupportsCPUShares = &False | ||
} | ||
return &info, nil | ||
} |
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.
and .... do we stop handling the local podman case?