From 80d82a5b2431f700ec7585b5e74dfb8c514a1e8d Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Sat, 5 Dec 2026 01:28:51 -0800 Subject: [PATCH] specs-go: keep CPUAffinity type backward compatible PR 1296 renamed the CPUAffinity type (used by Process.ExecCPUAffinity) to ExecCPUAffinity, and reused the CPUAffinity name for a new type with different fields (used by the new Process.CPUAffinity). While the JSON format is backward compatible, this breaks the Go API: existing code like spec.Process.ExecCPUAffinity = &specs.CPUAffinity{Initial: cpus} no longer compiles. Known users include runc and cri-o. Since Go uses minimal version selection, such breakage can come transitively, and it can only be fixed by the code that uses the type (similar to what was reported in issue 1305). Restore the original CPUAffinity type and Process.ExecCPUAffinity field type, and name the new type ProcessCPUAffinity instead. With this, the specs-go changes since v1.3.0 are purely additive. Fixes: 1296 Signed-off-by: Kir Kolyshkin --- specs-go/config.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/specs-go/config.go b/specs-go/config.go index a91fd1c79..903ab2798 100644 --- a/specs-go/config.go +++ b/specs-go/config.go @@ -100,9 +100,9 @@ type Process struct { // // Deprecated: use [Process.CPUAffinity] instead, which allows more granular control // during the create, start and exec phases. - ExecCPUAffinity *ExecCPUAffinity `json:"execCPUAffinity,omitempty" platform:"linux"` + ExecCPUAffinity *CPUAffinity `json:"execCPUAffinity,omitempty" platform:"linux"` // CPUAffinity specifies CPU affinity for executing processes - CPUAffinity *CPUAffinity `json:"cpuAffinity,omitempty" platform:"linux"` + CPUAffinity *ProcessCPUAffinity `json:"cpuAffinity,omitempty" platform:"linux"` } // LinuxCapabilities specifies the list of allowed capabilities that are kept for a process. @@ -136,14 +136,16 @@ const ( IOPRIO_CLASS_IDLE IOPriorityClass = "IOPRIO_CLASS_IDLE" ) -// ExecCPUAffinity specifies process' CPU affinity during runtime exec operation. -type ExecCPUAffinity struct { +// CPUAffinity specifies process' CPU affinity during runtime exec operation. +// It is only used by the deprecated [Process.ExecCPUAffinity] field. +type CPUAffinity struct { Initial string `json:"initial,omitempty"` Final string `json:"final,omitempty"` } -// CPUAffinity specifies process' CPU affinity. -type CPUAffinity struct { +// ProcessCPUAffinity specifies process' CPU affinity during various +// stages of the container lifecycle. +type ProcessCPUAffinity struct { CreateRuntime string `json:"createRuntime,omitempty"` CreateContainer string `json:"createContainer,omitempty"` StartContainer string `json:"startContainer,omitempty"`