Files
nvke/controller/internal/server/node_sets.go
Aaron Patten 2a12d95f2d feat(controller): let a node pool update set its NVLink logical partition (#2147)
* feat(controller): let a node pool update set its NVLink logical partition

PATCH /api/nodePools/{id} now accepts nico.nvLinkLogicalPartitionID. It sets
or replaces the pool's NVLink logical partition; the all-zero UUID is
rejected, so the partition cannot be cleared. Nodes the pool creates after
the update attach to the new partition. A partition change does not create a
new node set, so no existing node is replaced.

A NicoMachine that already exists keeps the partition it was created with
when its create is retried, because CAPNICo rejects a partition change once
the instance exists.

The NICo provider guide shows how to attach a pool's existing nodes by
updating their NICo instances directly.

Signed-off-by: Aaron Patten <apatten@nvidia.com>

* docs(nico): set the NICo token and check each instance after an NVLink update

Read the NICo API path and token from the nico-credentials Secret, list pool
machines that have no instance yet, and add a step that confirms each instance
reports the partition on every GPU.

Signed-off-by: Aaron Patten <apatten@nvidia.com>

* fix(controller): create a node set when a pool's NVLink partition changes

Treat the NVLink logical partition like the other editable node
configuration: a change creates a new current node set, and each node gets
the partition of its own node set instead of the pool's live value. Nodes
created after the change attach to the new partition; existing nodes stay in
the earlier node set until they are replaced or patched in NICo.

A retried create renders from the same node set, so the separate retry guard
is no longer needed and is removed.

Node sets backfilled when the nico payload columns were added never carried
the partition. A migration copies each pool's partition into its node sets
that lack it, so the upgrade creates no node sets and new nodes keep their
partition. Before this change the partition was fixed at creation, so the
pool's value is the one every node set was created with.

The node set API reports the partition, and the NICo provider guide describes
the node set and recycling behavior.

Signed-off-by: Aaron Patten <apatten@nvidia.com>

* test(nico): render a node's NVLink partition from its node set across retries

Signed-off-by: Aaron Patten <apatten@nvidia.com>

* docs(nico): keep the NICo token off the curl command line in the NVLink procedure

Read the Authorization header from a file only the operator can read, build
the request body once and reject a GPU count below 1, print the response body
of a failed update and say which failures a retry can fix.

Signed-off-by: Aaron Patten <apatten@nvidia.com>

* docs: move the NVLink partition procedure to its own operate page

Changing a node pool's NVLink partition and attaching its existing nodes is an
operational task, not part of configuring the NICo provider at install. Give it
a how-to page in the Operate section that also shows the pool update itself,
and link to it from the NICo identifiers table.

Signed-off-by: Aaron Patten <apatten@nvidia.com>

* docs: stop on a failed pool update and skip attached instances

Signed-off-by: Aaron Patten <apatten@nvidia.com>

---------

Signed-off-by: Aaron Patten <apatten@nvidia.com>
2026-11-10 10:21:46 -07:00

167 lines
5.4 KiB
Go

// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package server
import (
"context"
"errors"
"fmt"
"log/slog"
"github.com/google/uuid"
"go.temporal.io/sdk/client"
"github.com/dsx-ai-factory/nvke/controller/api"
"github.com/dsx-ai-factory/nvke/controller/internal/db"
)
type nodeSetService struct {
logger *slog.Logger
db db.DB
temporalClient client.Client
}
func NewNodeSetService(logger *slog.Logger, database db.DB, temporalClient client.Client) *nodeSetService {
return &nodeSetService{
logger: logger,
db: database,
temporalClient: temporalClient,
}
}
func (s *nodeSetService) ListNodeSets(ctx context.Context, req api.ListNodeSetsRequestObject) (api.ListNodeSetsResponseObject, error) {
filters := db.NodeSetFilters{
NodePoolID: req.Params.NodePoolID,
}
dbNodeSets, err := s.db.ListNodeSets(ctx, filters)
if err != nil {
return nil, fmt.Errorf("failed to list node sets: %w", err)
}
apiNodeSets := make([]api.NodeSet, len(dbNodeSets))
for i := range dbNodeSets {
apiNodeSets[i], err = apiNodeSetFromDB(&dbNodeSets[i])
if err != nil {
return nil, fmt.Errorf("failed to convert node set to API model: %w", err)
}
}
return api.ListNodeSets200JSONResponse{NodeSets: apiNodeSets}, nil
}
func (s *nodeSetService) GetNodeSet(ctx context.Context, req api.GetNodeSetRequestObject) (api.GetNodeSetResponseObject, error) {
dbNodeSet, err := s.db.GetNodeSet(ctx, req.NodeSetID)
if err != nil {
if errors.Is(err, db.ErrNotFound) {
return api.GetNodeSet404Response{}, nil
}
return nil, fmt.Errorf("failed to get node set: %w", err)
}
apiNodeSet, err := apiNodeSetFromDB(&dbNodeSet)
if err != nil {
return nil, fmt.Errorf("failed to convert node set to API model: %w", err)
}
return api.GetNodeSet200JSONResponse(apiNodeSet), nil
}
// apiNodeSetFromDB converts a database NodeSet to an API NodeSet
func apiNodeSetFromDB(dbNodeSet *db.NodeSet) (api.NodeSet, error) {
if dbNodeSet == nil {
return api.NodeSet{}, nil
}
if dbNodeSet.Capi != nil {
if _, err := objectFromRawManifest(dbNodeSet.Capi.InfraMachineTemplate); err != nil {
return api.NodeSet{}, fmt.Errorf(
"objectFromRawManifest failed for infra.machineTemplate on node set %s (nodePoolID=%s, preview=%q): %w",
dbNodeSet.ID,
dbNodeSet.NodePoolID,
truncateManifestForLog(dbNodeSet.Capi.InfraMachineTemplate, 200),
err,
)
}
}
var kubeReservedMemory *string
if dbNodeSet.KubeReservedMemory != "" {
kubeReservedMemory = &dbNodeSet.KubeReservedMemory
}
return api.NodeSet{
ID: dbNodeSet.ID,
NodePoolID: dbNodeSet.NodePoolID,
DesiredCount: dbNodeSet.DesiredCount,
SystemReservedMemory: dbNodeSet.SystemReservedMemory,
KubeReservedMemory: kubeReservedMemory,
KubernetesVersion: dbNodeSet.KubernetesVersion,
TeleportEnabled: &dbNodeSet.TeleportEnabled,
Nico: apiNicoNodeSetProviderFromDB(dbNodeSet.Nico),
Infra: apiInfraNodeSetProviderFromDB(dbNodeSet.Capi),
LaunchLayer: apiLaunchLayerNodeSetProviderFromDB(dbNodeSet.LaunchLayer),
}, nil
}
func apiLaunchLayerNodeSetProviderFromDB(provider *db.LaunchLayerNodePoolProvider) *api.LaunchLayerNodeSetProvider {
if provider == nil {
return nil
}
out := &api.LaunchLayerNodeSetProvider{
InstanceType: provider.InstanceType,
HostOSProfile: provider.HostOSProfile,
VMProfile: provider.VMProfile,
}
if provider.FulfillmentStrategy != "" {
strategy := api.LaunchLayerNodeSetProviderFulfillmentStrategy(provider.FulfillmentStrategy)
out.FulfillmentStrategy = &strategy
}
if len(provider.SecurityGroupRefs.PrimaryNetworkInterface) > 0 || len(provider.SecurityGroupRefs.GPUNetworkInterface) > 0 {
out.SecurityGroupRefs = &api.LaunchLayerSecurityGroupRefs{
PrimaryNetworkInterface: provider.SecurityGroupRefs.PrimaryNetworkInterface,
GpuNetworkInterface: provider.SecurityGroupRefs.GPUNetworkInterface,
}
}
out.SecurityGroups = apiLaunchLayerSecurityGroupsFromDB(provider.SecurityGroups)
return out
}
func apiInfraNodeSetProviderFromDB(capiNodeSetProvider *db.CAPINodePoolProvider) *api.InfraNodeSetProvider {
if capiNodeSetProvider == nil {
return nil
}
obj, err := objectFromRawManifest(capiNodeSetProvider.InfraMachineTemplate)
if err != nil {
obj = nil
}
out := &api.InfraNodeSetProvider{
MachineTemplate: obj,
PreKubeadmCommands: append([]string(nil), capiNodeSetProvider.PreKubeadmCommands...),
}
if apiFiles := apiCloudInitFilesFromDB(capiNodeSetProvider.BootstrapFiles); apiFiles != nil {
out.BootstrapFiles = *apiFiles
}
return out
}
func apiNicoNodeSetProviderFromDB(nicoNodeSetProvider *db.NicoNodePoolProvider) *api.NicoNodeSetProvider {
if nicoNodeSetProvider == nil {
return nil
}
return &api.NicoNodeSetProvider{
SubnetIDs: append([]uuid.UUID(nil), nicoNodeSetProvider.SubnetIDs...),
VpcPrefixIDs: append([]uuid.UUID(nil), nicoNodeSetProvider.VpcPrefixIDs...),
Release: nicoNodeSetProvider.Release,
ConfigProfile: nicoNodeSetProvider.ConfigProfile,
DiskSelectionStrategy: api.DiskSelectionStrategyCreate(nicoNodeSetProvider.DiskSelectionStrategy),
NvLinkLogicalPartitionID: clonePtr(nicoNodeSetProvider.NvLinkLogicalPartitionID),
}
}
func truncateManifestForLog(raw []byte, limit int) string {
if len(raw) <= limit {
return string(raw)
}
return string(raw[:limit]) + "..."
}