all: update deprecated Docker and xsync APIs

Update deprecated Docker SDK types and functions:
- errdefs.IsNotFound → cerrdefs.IsNotFound
- errdefs.IsConflict → cerrdefs.IsConflict
- cli.ImageInspectWithRaw → cli.ImageInspect
- client.IsErrNotFound → cerrdefs.IsNotFound
- event.ID → event.Actor.ID
- types.Container → container.Summary
- container.Stats → container.StatsResponse
- xsync.MapOf/NewMapOf → xsync.Map/NewMap

These updates align with the Docker SDK v28+ and xsync v4 API changes.
This commit is contained in:
Kristoffer Dalby 2026-01-20 14:42:02 +00:00
parent ad7669a2d4
commit 15d0efbf9d
4 changed files with 15 additions and 15 deletions

View file

@ -10,11 +10,11 @@ import (
"time"
"github.com/cenkalti/backoff/v5"
cerrdefs "github.com/containerd/errdefs"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/client"
"github.com/docker/docker/errdefs"
)
// cleanupBeforeTest performs cleanup operations before running tests.
@ -309,9 +309,9 @@ func cleanCacheVolume(ctx context.Context) error {
err = cli.VolumeRemove(ctx, volumeName, true)
if err != nil {
if errdefs.IsNotFound(err) {
if cerrdefs.IsNotFound(err) {
fmt.Printf("Go module cache volume not found: %s\n", volumeName)
} else if errdefs.IsConflict(err) {
} else if cerrdefs.IsConflict(err) {
fmt.Printf("Go module cache volume is in use and cannot be removed: %s\n", volumeName)
} else {
fmt.Printf("Failed to remove Go module cache volume %s: %v\n", volumeName, err)

View file

@ -14,6 +14,7 @@ import (
"strings"
"time"
cerrdefs "github.com/containerd/errdefs"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/mount"
@ -502,9 +503,9 @@ func getDockerSocketPath() string {
// checkImageAvailableLocally checks if the specified Docker image is available locally.
func checkImageAvailableLocally(ctx context.Context, cli *client.Client, imageName string) (bool, error) {
_, _, err := cli.ImageInspectWithRaw(ctx, imageName)
_, err := cli.ImageInspect(ctx, imageName)
if err != nil {
if client.IsErrNotFound(err) {
if cerrdefs.IsNotFound(err) {
return false, nil
}

View file

@ -12,7 +12,6 @@ import (
"sync"
"time"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/filters"
@ -153,13 +152,13 @@ func (sc *StatsCollector) monitorDockerEvents(ctx context.Context, runID string,
case event := <-events:
if event.Type == "container" && event.Action == "start" {
// Get container details
containerInfo, err := sc.client.ContainerInspect(ctx, event.ID)
containerInfo, err := sc.client.ContainerInspect(ctx, event.Actor.ID)
if err != nil {
continue
}
// Convert to types.Container format for consistency
cont := types.Container{
// Convert to container.Summary format for consistency
cont := container.Summary{
ID: containerInfo.ID,
Names: []string{containerInfo.Name},
Labels: containerInfo.Config.Labels,
@ -180,7 +179,7 @@ func (sc *StatsCollector) monitorDockerEvents(ctx context.Context, runID string,
}
// shouldMonitorContainer determines if a container should be monitored.
func (sc *StatsCollector) shouldMonitorContainer(cont types.Container, runID string) bool {
func (sc *StatsCollector) shouldMonitorContainer(cont container.Summary, runID string) bool {
// Check if it has the correct run ID label
if cont.Labels == nil || cont.Labels["hi.run-id"] != runID {
return false
@ -241,7 +240,7 @@ func (sc *StatsCollector) collectStatsForContainer(ctx context.Context, containe
decoder := json.NewDecoder(statsResponse.Body)
var prevStats *container.Stats
var prevStats *container.StatsResponse
for {
select {
@ -250,7 +249,7 @@ func (sc *StatsCollector) collectStatsForContainer(ctx context.Context, containe
case <-ctx.Done():
return
default:
var stats container.Stats
var stats container.StatsResponse
if err := decoder.Decode(&stats); err != nil {
// EOF is expected when container stops or stream ends
if err.Error() != "EOF" && verbose {
@ -299,7 +298,7 @@ func (sc *StatsCollector) collectStatsForContainer(ctx context.Context, containe
}
// calculateCPUPercent calculates CPU usage percentage from Docker stats.
func calculateCPUPercent(prevStats, stats *container.Stats) float64 {
func calculateCPUPercent(prevStats, stats *container.StatsResponse) float64 {
// CPU calculation based on Docker's implementation
cpuDelta := float64(stats.CPUStats.CPUUsage.TotalUsage) - float64(prevStats.CPUStats.CPUUsage.TotalUsage)
systemDelta := float64(stats.CPUStats.SystemUsage) - float64(prevStats.CPUStats.SystemUsage)

View file

@ -96,7 +96,7 @@ type User struct {
type Scenario struct {
// TODO(kradalby): support multiple headcales for later, currently only
// use one.
controlServers *xsync.MapOf[string, ControlServer]
controlServers *xsync.Map[string, ControlServer]
derpServers []*dsic.DERPServerInContainer
users map[string]*User
@ -180,7 +180,7 @@ func NewScenario(spec ScenarioSpec) (*Scenario, error) {
testHashPrefix := "hs-" + util.MustGenerateRandomStringDNSSafe(scenarioHashLength)
s := &Scenario{
controlServers: xsync.NewMapOf[string, ControlServer](),
controlServers: xsync.NewMap[string, ControlServer](),
users: make(map[string]*User),
pool: pool,