Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -3,6 +3,7 @@ package daemon |
| 3 | 3 |
import ( |
| 4 | 4 |
"context" |
| 5 | 5 |
"errors" |
| 6 |
+ "slices" |
|
| 6 | 7 |
|
| 7 | 8 |
"github.com/containerd/log" |
| 8 | 9 |
"github.com/moby/moby/api/types/container" |
| ... | ... |
@@ -42,10 +43,8 @@ func registerDeviceDriver(name string, d *deviceDriver) {
|
| 42 | 42 |
func getFirstAvailableVendor(vendorList []string) (string, error) {
|
| 43 | 43 |
knownVendors := []string{"nvidia.com", "amd.com"}
|
| 44 | 44 |
for _, vendor := range knownVendors {
|
| 45 |
- for _, available := range vendorList {
|
|
| 46 |
- if vendor == available {
|
|
| 47 |
- return vendor, nil |
|
| 48 |
- } |
|
| 45 |
+ if slices.Contains(vendorList, vendor) {
|
|
| 46 |
+ return vendor, nil |
|
| 49 | 47 |
} |
| 50 | 48 |
} |
| 51 | 49 |
return "", errors.New("no known GPU vendor found")
|
| ... | ... |
@@ -685,7 +685,7 @@ func (c *client) processEventStream(ctx context.Context, ns string) {
|
| 685 | 685 |
case *apievents.TaskDelete: |
| 686 | 686 |
c.logger.WithFields(log.Fields{
|
| 687 | 687 |
"topic": ev.Topic, |
| 688 |
- "type": reflect.TypeOf(t), |
|
| 688 |
+ "type": reflect.TypeFor[*apievents.TaskDelete](), |
|
| 689 | 689 |
"container": t.ContainerID, |
| 690 | 690 |
}).Info("received task-delete event from containerd")
|
| 691 | 691 |
default: |
| ... | ... |
@@ -47,7 +47,7 @@ func allocatePort(pa *portallocator.OSAllocator, bnd types.PortBinding) (types.P |
| 47 | 47 |
// Try up to maxAllocatePortAttempts times to get a port that's not already allocated. |
| 48 | 48 |
var allocatedPort int |
| 49 | 49 |
var err error |
| 50 |
- for i := 0; i < maxAllocatePortAttempts; i++ {
|
|
| 50 |
+ for i := range maxAllocatePortAttempts {
|
|
| 51 | 51 |
allocatedPort, err = pa.AllocateHostPort(bnd.HostIP, bnd.Proto, int(bnd.HostPort), int(bnd.HostPortEnd)) |
| 52 | 52 |
if err == nil {
|
| 53 | 53 |
break |
| ... | ... |
@@ -67,7 +67,7 @@ func (n *Network) startResolver() {
|
| 67 | 67 |
|
| 68 | 68 |
for _, subnet := range hnsresponse.Subnets {
|
| 69 | 69 |
if subnet.GatewayAddress != "" {
|
| 70 |
- for i := 0; i < 3; i++ {
|
|
| 70 |
+ for range 3 {
|
|
| 71 | 71 |
resolver := NewResolver(subnet.GatewayAddress, true, n) |
| 72 | 72 |
log.G(context.TODO()).Debugf("Binding a resolver on network %s gateway %s", n.Name(), subnet.GatewayAddress)
|
| 73 | 73 |
n.dnsCompartment = hnsresponse.DNSServerCompartment |
| ... | ... |
@@ -55,7 +55,7 @@ func GenerateFromModel[T any](options Generic) (T, error) {
|
| 55 | 55 |
|
| 56 | 56 |
modType := reflect.TypeFor[T]() |
| 57 | 57 |
|
| 58 |
- isPtr := modType.Kind() == reflect.Ptr |
|
| 58 |
+ isPtr := modType.Kind() == reflect.Pointer |
|
| 59 | 59 |
|
| 60 | 60 |
// If the model is of pointer type, we need to dereference for New. |
| 61 | 61 |
resType := modType |
| ... | ... |
@@ -430,18 +430,14 @@ func setResourcesInSpec(c *container.Container, s *specs.Spec, isHyperV bool) {
|
| 430 | 430 |
leftoverNanoCPUs := c.HostConfig.NanoCPUs % 1e9 |
| 431 | 431 |
if leftoverNanoCPUs != 0 {
|
| 432 | 432 |
cpuCount++ |
| 433 |
- cpuMaximum = uint16(c.HostConfig.NanoCPUs / int64(cpuCount) / (1e9 / 10000)) |
|
| 434 |
- if cpuMaximum < 1 {
|
|
| 433 |
+ cpuMaximum = max(uint16(c.HostConfig.NanoCPUs/int64(cpuCount)/(1e9/10000)), |
|
| 435 | 434 |
// The requested NanoCPUs is so small that we rounded to 0, use 1 instead |
| 436 |
- cpuMaximum = 1 |
|
| 437 |
- } |
|
| 435 |
+ 1) |
|
| 438 | 436 |
} |
| 439 | 437 |
} else {
|
| 440 |
- cpuMaximum = uint16(c.HostConfig.NanoCPUs / int64(runtime.NumCPU()) / (1e9 / 10000)) |
|
| 441 |
- if cpuMaximum < 1 {
|
|
| 438 |
+ cpuMaximum = max(uint16(c.HostConfig.NanoCPUs/int64(runtime.NumCPU())/(1e9/10000)), |
|
| 442 | 439 |
// The requested NanoCPUs is so small that we rounded to 0, use 1 instead |
| 443 |
- cpuMaximum = 1 |
|
| 444 |
- } |
|
| 440 |
+ 1) |
|
| 445 | 441 |
} |
| 446 | 442 |
} |
| 447 | 443 |
|
| ... | ... |
@@ -538,9 +534,9 @@ func readCredentialSpecFile(id, root, location string) (string, error) {
|
| 538 | 538 |
func setupWindowsDevices(devices []containertypes.DeviceMapping) ([]specs.WindowsDevice, error) {
|
| 539 | 539 |
var specDevices []specs.WindowsDevice |
| 540 | 540 |
for _, deviceMapping := range devices {
|
| 541 |
- if strings.HasPrefix(deviceMapping.PathOnHost, "class/") {
|
|
| 541 |
+ if after, ok := strings.CutPrefix(deviceMapping.PathOnHost, "class/"); ok {
|
|
| 542 | 542 |
specDevices = append(specDevices, specs.WindowsDevice{
|
| 543 |
- ID: strings.TrimPrefix(deviceMapping.PathOnHost, "class/"), |
|
| 543 |
+ ID: after, |
|
| 544 | 544 |
IDType: "class", |
| 545 | 545 |
}) |
| 546 | 546 |
} else {
|
| ... | ... |
@@ -24,7 +24,7 @@ func init() {
|
| 24 | 24 |
// |
| 25 | 25 |
// Note: copystructure is archived (https://github.com/mitchellh/copystructure) |
| 26 | 26 |
// and won't receive upstream fixes for this limitation. |
| 27 |
- copystructure.Copiers[reflect.TypeOf(netip.Addr{})] = func(v any) (any, error) {
|
|
| 27 |
+ copystructure.Copiers[reflect.TypeFor[netip.Addr]()] = func(v any) (any, error) {
|
|
| 28 | 28 |
return v.(netip.Addr), nil |
| 29 | 29 |
} |
| 30 | 30 |
} |
| ... | ... |
@@ -348,7 +348,7 @@ func TestWindowsNetworkEndpointManagement(t *testing.T) {
|
| 348 | 348 |
const numContainers = 3 |
| 349 | 349 |
containerIDs := make([]string, numContainers) |
| 350 | 350 |
|
| 351 |
- for i := 0; i < numContainers; i++ {
|
|
| 351 |
+ for i := range numContainers {
|
|
| 352 | 352 |
ctrName := fmt.Sprintf("endpoint-ctr-%d", i)
|
| 353 | 353 |
id := container.Run(ctx, t, c, |
| 354 | 354 |
container.WithName(ctrName), |
| ... | ... |
@@ -364,7 +364,7 @@ func TestWindowsNetworkEndpointManagement(t *testing.T) {
|
| 364 | 364 |
"Expected %d containers, got %d", numContainers, len(netInfo.Network.Containers)) |
| 365 | 365 |
|
| 366 | 366 |
// Verify each container has network connectivity to others |
| 367 |
- for i := 0; i < numContainers-1; i++ {
|
|
| 367 |
+ for i := range numContainers - 1 {
|
|
| 368 | 368 |
targetName := fmt.Sprintf("endpoint-ctr-%d", i)
|
| 369 | 369 |
pingCmd := []string{"ping", "-n", "1", "-w", "3000", targetName}
|
| 370 | 370 |
|