|
| 1 | +// Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package main |
| 16 | + |
| 17 | +import ( |
| 18 | + "fmt" |
| 19 | + "log/slog" |
| 20 | + |
| 21 | + "github.com/NVIDIA/aicr/pkg/errors" |
| 22 | + "github.com/NVIDIA/aicr/validators" |
| 23 | + "github.com/NVIDIA/aicr/validators/internal/gkenet" |
| 24 | + apierrors "k8s.io/apimachinery/pkg/api/errors" |
| 25 | +) |
| 26 | + |
| 27 | +// tcpxoComponent is the recipe componentRef that supplies GPUDirect TCPXO. |
| 28 | +const tcpxoComponent = "gke-nccl-tcpxo" |
| 29 | + |
| 30 | +// checkGKEGPUNICNetworks verifies the cluster has the GKE multi-NIC networking |
| 31 | +// objects GPUDirect TCPXO depends on. |
| 32 | +// |
| 33 | +// The gke-nccl-tcpxo component ships two DaemonSets, and both roll out cleanly |
| 34 | +// on a cluster that has zero Network / GKENetworkParamSet objects — so the |
| 35 | +// component's health check reports Synced+Healthy while TCPXO cannot function. |
| 36 | +// Without this check the gap surfaces hours later as a performance-phase abort |
| 37 | +// in the NCCL benchmark's own discovery, with no bandwidth number produced. |
| 38 | +// |
| 39 | +// The Network CRs are infrastructure: creating and binding them belongs to |
| 40 | +// cluster provisioning, not AICR. This check only detects their absence and |
| 41 | +// names the prerequisite, at the deployment phase where it is actionable. |
| 42 | +func checkGKEGPUNICNetworks(ctx *validators.Context) error { |
| 43 | + if ctx.DynamicClient == nil { |
| 44 | + return errors.New(errors.ErrCodeInvalidRequest, "dynamic client is not available") |
| 45 | + } |
| 46 | + |
| 47 | + slog.Info("listing GKE networks", "gvr", gkenet.NetworkGVR.String()) |
| 48 | + |
| 49 | + gpuNICs, listErr := gkenet.DiscoverGPUNICNetworks(ctx.Ctx, ctx.DynamicClient) |
| 50 | + |
| 51 | + capability := validators.Capability{ |
| 52 | + Component: tcpxoComponent, |
| 53 | + Subject: "GKE Networks (networks.networking.gke.io)", |
| 54 | + AbsentMsg: absentPrerequisiteMsg("the cluster does not serve the networks.networking.gke.io " + |
| 55 | + "API at all, so it has 0"), |
| 56 | + InapplicableMsg: tcpxoComponent + " not declared in recipe and the cluster has no GKE Network " + |
| 57 | + "API — cluster does not use GPUDirect TCPXO", |
| 58 | + } |
| 59 | + |
| 60 | + // An ABSENT Network API is clean absence, not an infrastructure failure: the |
| 61 | + // CRD arrives with --enable-multi-networking, so a cluster created without it |
| 62 | + // legitimately does not serve this GVR. Route that shape through Require, |
| 63 | + // which is declaration-gated — an undeclared recipe skips, a declared one gets |
| 64 | + // the actionable message. RequireList would classify it as a blocking INTERNAL |
| 65 | + // error, which both false-fails an undeclared recipe and hides the missing |
| 66 | + // prerequisite behind "failed to read" on a declared one. |
| 67 | + if apierrors.IsNotFound(listErr) { |
| 68 | + // present is unused here: Require consults it only when probeErr is nil. |
| 69 | + return capability.Require(ctx, listErr, false) |
| 70 | + } |
| 71 | + |
| 72 | + // Every other list error blocks regardless of declaration — an RBAC denial or |
| 73 | + // an apiserver hiccup is not evidence that TCPXO is inapplicable. |
| 74 | + if err := capability.RequireList(listErr); err != nil { |
| 75 | + return err |
| 76 | + } |
| 77 | + |
| 78 | + // The prerequisite belongs to gke-nccl-tcpxo: a recipe that does not declare |
| 79 | + // the component is not asking for TCPXO, so its cluster's networking is not |
| 80 | + // this check's business. This also covers the #1327 standalone-run boundary, |
| 81 | + // where there is no recipe context at all. |
| 82 | + if !validators.RecipeDeclares(ctx, tcpxoComponent) { |
| 83 | + return validators.Skip( |
| 84 | + tcpxoComponent + " not declared in recipe — GPUDirect TCPXO networking is inapplicable") |
| 85 | + } |
| 86 | + |
| 87 | + // Evidence to stdout. |
| 88 | + fmt.Printf("Found %d GPU NIC network(s) (need %d):\n", len(gpuNICs), gkenet.RequiredGPUNICNetworks) |
| 89 | + for _, name := range gpuNICs { |
| 90 | + fmt.Printf(" %s\n", name) |
| 91 | + } |
| 92 | + |
| 93 | + if len(gpuNICs) < gkenet.RequiredGPUNICNetworks { |
| 94 | + return errors.New(errors.ErrCodeNotFound, absentPrerequisiteMsg(fmt.Sprintf( |
| 95 | + "the cluster has %d of %d", len(gpuNICs), gkenet.RequiredGPUNICNetworks))) |
| 96 | + } |
| 97 | + |
| 98 | + return nil |
| 99 | +} |
| 100 | + |
| 101 | +// absentPrerequisiteMsg builds the operator-facing message for a missing GPU NIC |
| 102 | +// networking prerequisite. detail names what was actually observed; the rest is |
| 103 | +// the constant remediation, kept in one place so the absent-API path and the |
| 104 | +// short-count path cannot drift. |
| 105 | +// |
| 106 | +// The message names the required naming convention because it is a real way to |
| 107 | +// hit a zero count on an otherwise correctly provisioned cluster: discovery |
| 108 | +// matches the substring against the NETWORK name only, and Google's own sample |
| 109 | +// manifests name the Device networks vpc1..vpc8. |
| 110 | +func absentPrerequisiteMsg(detail string) string { |
| 111 | + return fmt.Sprintf( |
| 112 | + "recipe declares %s but %s GPU NIC networks — GPUDirect TCPXO requires one Network "+ |
| 113 | + "per GPU NIC, each bound to a GKENetworkParamSet and each with %q in its own "+ |
| 114 | + "metadata.name (this check counts Network names; it does not verify the "+ |
| 115 | + "GKENetworkParamSet binding or readiness). "+ |
| 116 | + "These are provisioned with the cluster, not by AICR, and multi-networking "+ |
| 117 | + "(--enable-multi-networking) cannot be enabled after cluster creation. "+ |
| 118 | + "Verify with: kubectl get network.networking.gke.io "+ |
| 119 | + "(see docs/integrator/gke-tcpxo-networking.md)", |
| 120 | + tcpxoComponent, detail, gkenet.GPUNICNameSubstring) |
| 121 | +} |
0 commit comments