Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions cmd/compute-domain-daemon/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const (

type Flags struct {
cliqueID string
nodeLocalFabricIPC bool
computeDomainUUID string
computeDomainName string
computeDomainNamespace string
Expand Down Expand Up @@ -113,6 +114,12 @@ func newApp() *cli.App {
EnvVars: []string{"CLIQUE_ID"},
Destination: &flags.cliqueID,
},
&cli.BoolFlag{
Name: "node-local-fabric-ipc-enabled",
Usage: "Whether the kubelet plugin enabled node-local IMEX for this daemon.",
EnvVars: []string{"NODE_LOCAL_FABRIC_IPC_ENABLED"},
Destination: &flags.nodeLocalFabricIPC,
},
&cli.StringFlag{
Name: "compute-domain-uuid",
Usage: "The UUID of the ComputeDomain to manage.",
Expand Down Expand Up @@ -270,13 +277,13 @@ func run(ctx context.Context, cancel context.CancelFunc, flags *Flags) error {
return fmt.Errorf("failed to add compute domain clique label to pod: %w", err)
}

// When cliqueID is empty, skip starting the controller and IMEX daemon management entirely.
// The compute-domain-controller will watch this pod's label and sync its node info to the
// ComputeDomain status. There's no clique to manage, no DNS indices to determine, and no
// IMEX daemon to run.
// A node-local domain has no NVML clique, but fabric handles still need a
// running IMEX service to broker export and import metadata.
if flags.cliqueID == "" {
if flags.nodeLocalFabricIPC && flags.computeDomainDaemonSet == "" {
return runNodeLocalIMEX(ctx, flags, imexConfigOverrides)
}
klog.Infof("no cliqueID: skipping controller and IMEX daemon management")
// Just wait for shutdown signal
<-ctx.Done()
klog.Infof("Exiting")
return nil
Expand Down Expand Up @@ -380,6 +387,23 @@ func run(ctx context.Context, cancel context.CancelFunc, flags *Flags) error {
return nil
}

func runNodeLocalIMEX(ctx context.Context, flags *Flags, configOverrides map[string]string) error {
if err := writeIMEXConfig(flags.podIP, configOverrides); err != nil {
return fmt.Errorf("failed to write node-local IMEX daemon config: %w", err)
}
daemons := []*nvapi.ComputeDomainDaemonInfo{{IPAddress: flags.podIP}}
if err := writeDaemonsConfig("", daemons); err != nil {
return fmt.Errorf("failed to write node-local IMEX nodes config: %w", err)
}

processManager := NewProcessManager([]string{imexDaemonBinaryName, "-c", imexDaemonConfigPath})
if _, err := processManager.EnsureStarted(); err != nil {
return fmt.Errorf("failed to start node-local IMEX daemon: %w", err)
}
klog.Infof("started node-local IMEX daemon for pod IP %s", flags.podIP)
return processManager.Watchdog(ctx)
}

// IMEXDaemonUpdateLoopWithIPs reacts to ComputeDomain status changes by updating the
// IMEX daemon nodes config file and (re)starting the IMEX daemon process.
func IMEXDaemonUpdateLoopWithIPs(ctx context.Context, controller *Controller, cliqueID string, pm *ProcessManager) error {
Expand Down Expand Up @@ -467,7 +491,7 @@ func IMEXDaemonUpdateLoopWithDNSNames(ctx context.Context, controller *Controlle
// check verifies if the node is IMEX capable and if so, checks if the IMEX daemon is ready.
// It returns an error if any step fails.
func check(ctx context.Context, cancel context.CancelFunc, flags *Flags) error {
if flags.cliqueID == "" {
if flags.cliqueID == "" && (!flags.nodeLocalFabricIPC || flags.computeDomainDaemonSet != "") {
fmt.Println("check succeeded (noop, clique ID is empty)")
return nil
}
Expand Down
72 changes: 72 additions & 0 deletions cmd/compute-domain-daemon/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
Copyright The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
"os/exec"
"strconv"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"sigs.k8s.io/dra-driver-nvidia-gpu/pkg/featuregates"
)

func TestCheckIMEXReadiness(t *testing.T) {
// An empty PATH makes an attempted readiness probe fail deterministically.
t.Setenv("PATH", t.TempDir())
previous := featuregates.Enabled(featuregates.NodeLocalFabricIPC)
t.Cleanup(func() {
require.NoError(t, featuregates.FeatureGates().SetFromMap(map[string]bool{
string(featuregates.NodeLocalFabricIPC): previous,
}))
})

for name, tc := range map[string]struct {
cliqueID string
daemonSetUID string
featureGateEnabled bool
injectedEligibility string
wantProbe bool
}{
"no clique, no CDI value": {},
"no clique, feature gate disabled": {injectedEligibility: "false"},
"no clique, gate on but ineligible": {featureGateEnabled: true, injectedEligibility: "false"},
"no clique, eligible": {featureGateEnabled: true, injectedEligibility: "true", wantProbe: true},
"no clique, use the CDI decision": {injectedEligibility: "true", wantProbe: true},
"static daemon without a clique": {daemonSetUID: "daemon-set-uid", injectedEligibility: "true"},
"native clique": {cliqueID: "clique-a", injectedEligibility: "false", wantProbe: true},
} {
t.Run(name, func(t *testing.T) {
t.Setenv("CLIQUE_ID", tc.cliqueID)
t.Setenv("COMPUTE_DOMAIN_DAEMONSET_UID", tc.daemonSetUID)
t.Setenv("FEATURE_GATES", "NodeLocalFabricIPC="+strconv.FormatBool(tc.featureGateEnabled))
t.Setenv("NODE_LOCAL_FABRIC_IPC_ENABLED", tc.injectedEligibility)

app := newApp()
// Kubernetes logging is configured once per process.
app.Before = nil
err := app.Run([]string{"compute-domain-daemon", "check"})
if tc.wantProbe {
assert.ErrorIs(t, err, exec.ErrNotFound)
} else {
require.NoError(t, err)
}
})
}
}
13 changes: 10 additions & 3 deletions cmd/compute-domain-kubelet-plugin/computedomain.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,11 @@ func (m *ComputeDomainManager) GetComputeDomainChannelContainerEdits(devRoot str
// GetCDIContainerEditsCommon() returns the CDI spec edits always required for
// launching the CD Daemon (whether or not it tries to launch an IMEX daemon
// internally).
func (s *ComputeDomainDaemonSettings) GetCDIContainerEditsCommon(ctx context.Context) (*cdiapi.ContainerEdits, error) {
env := []string{fmt.Sprintf("CLIQUE_ID=%s", s.manager.CliqueID())}
func (s *ComputeDomainDaemonSettings) GetCDIContainerEditsCommon(ctx context.Context, cliqueID string, nodeLocalFabricIPCEnabled bool) (*cdiapi.ContainerEdits, error) {
env := []string{
fmt.Sprintf("CLIQUE_ID=%s", cliqueID),
fmt.Sprintf("NODE_LOCAL_FABRIC_IPC_ENABLED=%t", nodeLocalFabricIPCEnabled),
}
if s.manager.config.imexConfig.StaticDaemon() {
cdds, err := s.manager.GetComputeDomainDaemonSet()
if err != nil {
Expand Down Expand Up @@ -412,7 +415,11 @@ func (m *ComputeDomainManager) isCurrentNodeReadyInStatus(cd *nvapi.ComputeDomai
// isCurrentNodeReadyInClique checks if the current node is marked as ready in
// the ComputeDomainClique of a ComputeDomain or ComputeDomainDaemonSet.
func (m *ComputeDomainManager) isCurrentNodeReadyInClique(ctx context.Context, domainUID string) bool {
cliqueName := fmt.Sprintf("%s.%s", domainUID, m.CliqueID())
cliqueID := m.CliqueID()
if cliqueID == "" {
return false
}
cliqueName := fmt.Sprintf("%s.%s", domainUID, cliqueID)

clique, err := m.config.clientsets.Nvidia.ResourceV1beta1().ComputeDomainCliques(m.config.flags.namespace).Get(ctx, cliqueName, metav1.GetOptions{})
if err != nil {
Expand Down
27 changes: 17 additions & 10 deletions cmd/compute-domain-kubelet-plugin/device_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,9 +748,10 @@ func (s *DeviceState) applyComputeDomainChannelConfigSharedDomain(ctx context.Co
channelID: channelID,
}

if s.computeDomainManager.CliqueID() == "" {
// Non-fabric node (e.g. not part of an MNNVL clique): do not inject
// IMEX channel device nodes, but let the claim succeed.
cliqueID := s.computeDomainManager.CliqueID()
if cliqueID == "" && (s.config.imexConfig.StaticDaemon() || !s.nvdevlib.nodeLocalFabricIPCEnabled) {
// Static IMEX daemons require a clique. Other nodes without IMEX
// support can also prepare claims without channel device nodes.
return &configState, nil
}

Expand All @@ -763,6 +764,9 @@ func (s *DeviceState) applyComputeDomainChannelConfigSharedDomain(ctx context.Co
} else if err := assertIMEXReady(ctx); err != nil {
return nil, err
}
if cliqueID == "" {
klog.V(1).Infof("injecting IMEX channel %d for node-local CUDA fabric IPC", channelID)
}

if channelID < 0 || channelID >= len(s.nvdevlib.nvCapImexChanDevInfos) {
return nil, fmt.Errorf("applyComputeDomainChannelConfigSharedDomain: channel %d out of range (node has %d IMEX channels)",
Expand Down Expand Up @@ -821,11 +825,11 @@ func (s *DeviceState) applyComputeDomainChannelConfigDriverManaged(ctx context.C
}
}

if s.computeDomainManager.CliqueID() == "" {
cliqueID := s.computeDomainManager.CliqueID()
if cliqueID == "" && !s.nvdevlib.nodeLocalFabricIPCEnabled {
// Do not inject IMEX channel device nodes.
return &configState, nil
}

// If explicitly requested, inject all channels instead of just one.
channels := s.nvdevlib.nvCapImexChanDevInfos
if config.AllocationMode != configapi.ComputeDomainChannelAllocationModeAll {
Expand All @@ -834,6 +838,9 @@ func (s *DeviceState) applyComputeDomainChannelConfigDriverManaged(ctx context.C
}
channels = channels[channelID : channelID+1]
}
if cliqueID == "" {
klog.V(1).Infof("injecting %d IMEX channel(s) for node-local CUDA fabric IPC", len(channels))
}
for _, info := range channels {
edits := s.computeDomainManager.GetComputeDomainChannelContainerEdits(s.cdi.devRoot, info)
configState.containerEdits = configState.containerEdits.Append(edits)
Expand Down Expand Up @@ -897,16 +904,16 @@ func (s *DeviceState) applyComputeDomainDaemonConfig(ctx context.Context, config

// Always inject CD config details into the CD daemon (regardless of clique
// ID being empty or not).
edits, err := computeDomainDaemonSettings.GetCDIContainerEditsCommon(ctx)
cliqueID := s.computeDomainManager.CliqueID()
nodeLocalFabricIPCEnabled := cliqueID == "" && !s.config.imexConfig.StaticDaemon() && s.nvdevlib.nodeLocalFabricIPCEnabled
edits, err := computeDomainDaemonSettings.GetCDIContainerEditsCommon(ctx, cliqueID, nodeLocalFabricIPCEnabled)
if err != nil {
return nil, fmt.Errorf("error getting common container edits for ComputeDomain daemon '%s': %w", config.DomainID, err)
}
configState.containerEdits = configState.containerEdits.Append(edits)

// Only inject dev nodes related to
// /proc/driver/nvidia/capabilities/fabric-imex-mgmt if IMEX is supported
// (if we want to start the IMEX daemon process in the CD daemon pod).
if s.computeDomainManager.CliqueID() != "" {
// Inject the IMEX management device whenever this daemon will run nvidia-imex.
if cliqueID != "" || nodeLocalFabricIPCEnabled {
nvcapPath := nvidiaCapFabricImexMgmtPath
if common.UsingAltProcDevices() {
nvcapPath = filepath.Join(s.config.flags.containerDriverRoot, "proc/driver/nvidia/capabilities/fabric-imex-mgmt")
Expand Down
Loading