libct: State: ensure Resources is not nil

Since opencontainers/cgroups v0.0.2 (commit b206a015), all stuct
Resources fields are annotated with "omitempty" attribute.
As a result, the loaded configuration may have Resources == nil.

It is totally OK (rootless containers may have no resources configured)
except since commit 6c5441e5, cgroup v1 fs manager requires Resources to
be set in the call to NewManager (this is a cgroup v1 deficiency,
or maybe our implementation deficiency, or both).

To work around this, let's add code to ensure Resources is never nil
after loading from state.json.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2025-06-18 16:56:00 -07:00
committed by Jared Ledvina
parent f5e8c63fdc
commit e34f6438e9

View File

@@ -164,6 +164,10 @@ func loadState(root string) (*State, error) {
if err := json.NewDecoder(f).Decode(&state); err != nil {
return nil, err
}
// Cgroup v1 fs manager expect Resources to never be nil.
if state.Config.Cgroups.Resources == nil {
state.Config.Cgroups.Resources = &cgroups.Resources{}
}
return state, nil
}