Skip to content

Commit 1e8a519

Browse files
committed
feat: show RootlessKit version in nerdctl version output
When running in rootless mode, nerdctl version now includes the RootlessKit version as a server component, matching the format used by docker version. The version is retrieved via the RootlessKit API socket (rootlessutil.NewRootlessKitClient + Info(ctx)) rather than shelling out to rootlesskit --version, which is more robust and avoids PATH issues. The version is only shown when rootless mode is active (i.e. when rootlessutil.IsRootless() is true). If the API socket is unavailable or the Info call fails, a warning is logged and the component is shown without a version string. Fixes #4936 Signed-off-by: Aaron Mark <64331623+amarkdotdev@users.noreply.github.com>
1 parent 1eab5e6 commit 1e8a519

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

pkg/infoutil/infoutil.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/containerd/nerdctl/v2/pkg/buildkitutil"
3636
"github.com/containerd/nerdctl/v2/pkg/inspecttypes/dockercompat"
3737
"github.com/containerd/nerdctl/v2/pkg/inspecttypes/native"
38+
"github.com/containerd/nerdctl/v2/pkg/rootlessutil"
3839
"github.com/containerd/nerdctl/v2/pkg/version"
3940
)
4041

@@ -142,6 +143,9 @@ func ServerVersion(ctx context.Context, client *containerd.Client) (*dockercompa
142143
runcVersion(),
143144
},
144145
}
146+
if rootlessutil.IsRootless() {
147+
v.Components = append(v.Components, rootlessKitVersion(ctx))
148+
}
145149
return v, nil
146150
}
147151

@@ -233,6 +237,35 @@ func parseRuncVersion(runcVersionStdout []byte) (*dockercompat.ComponentVersion,
233237
}
234238

235239
// getMobySysInfo returns the moby system info for the given cgroup manager
240+
241+
func rootlessKitVersion(ctx context.Context) dockercompat.ComponentVersion {
242+
rc, err := rootlessutil.NewRootlessKitClient()
243+
if err != nil {
244+
log.L.WithError(err).Warnf("unable to connect to RootlessKit API socket")
245+
return dockercompat.ComponentVersion{Name: "rootlesskit"}
246+
}
247+
info, err := rc.Info(ctx)
248+
if err != nil {
249+
log.L.WithError(err).Warnf("unable to retrieve RootlessKit version via API")
250+
return dockercompat.ComponentVersion{Name: "rootlesskit"}
251+
}
252+
details := map[string]string{
253+
"ApiVersion": info.APIVersion,
254+
"StateDir": info.StateDir,
255+
}
256+
if info.NetworkDriver != nil {
257+
details["NetworkDriver"] = info.NetworkDriver.Driver
258+
}
259+
if info.PortDriver != nil {
260+
details["PortDriver"] = info.PortDriver.Driver
261+
}
262+
return dockercompat.ComponentVersion{
263+
Name: "rootlesskit",
264+
Version: info.Version,
265+
Details: details,
266+
}
267+
}
268+
236269
func getMobySysInfo(cgroupManager string) *sysinfo.SysInfo {
237270
var info dockercompat.Info
238271
info.CgroupVersion = CgroupsVersion()

0 commit comments

Comments
 (0)