-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(nodeadm): rework containerd template mixin interface #2135
Open
ndbaker1
wants to merge
1
commit into
awslabs:main
Choose a base branch
from
ndbaker1:ctrd-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package containerd | ||
|
||
import ( | ||
"os" | ||
"slices" | ||
"strings" | ||
|
||
"github.com/awslabs/amazon-eks-ami/nodeadm/internal/api" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type nvidiaModifier struct { | ||
pcieDevicesPath string | ||
} | ||
|
||
func NewNvidiaModifier() *nvidiaModifier { | ||
return &nvidiaModifier{ | ||
pcieDevicesPath: "/proc/bus/pci/devices", | ||
} | ||
} | ||
|
||
func (m *nvidiaModifier) Matches(cfg *api.NodeConfig) bool { | ||
return m.matchesInstanceType(cfg.Status.Instance.Type) || m.matchesPCIeVendor() | ||
} | ||
|
||
func (*nvidiaModifier) Modify(ctrdTemplate *containerdTemplateVars) { | ||
zap.L().Info("Configuring NVIDIA runtime..") | ||
ctrdTemplate.RuntimeName = "nvidia" | ||
ctrdTemplate.RuntimeBinaryName = "/usr/bin/nvidia-container-runtime" | ||
} | ||
|
||
var nvidiaInstanceFamilies = []string{ | ||
"p3", "p3dn", | ||
"p4d", "p4de", | ||
"p5", "p5e", "p5en", | ||
"g4", "g4dn", | ||
"g5", "g5g", | ||
"g6", "g6e", | ||
} | ||
|
||
// TODO: deprecate to avoid manual instance type tracking. | ||
func (*nvidiaModifier) matchesInstanceType(instanceType string) bool { | ||
family := strings.Split(instanceType, ".")[0] | ||
return slices.Contains(nvidiaInstanceFamilies, family) | ||
} | ||
|
||
func (m *nvidiaModifier) matchesPCIeVendor() bool { | ||
devices, err := os.ReadFile(m.pcieDevicesPath) | ||
if err != nil { | ||
zap.L().Error("Failed to read PCIe devices", zap.Error(err)) | ||
return false | ||
} | ||
// The contents of '/proc/bus/pci/devices' looks like the following, where | ||
// the last column contains the vendor name if present. | ||
// | ||
// something like the following: | ||
// | ||
// 0018 1d0f1111 0 c1000008 0 0 0 0 0 c0002 400000 0 0 0 0 0 20000 | ||
// 0020 1d0f8061 b c1508000 0 0 0 0 0 0 4000 0 0 0 0 0 0 nvme | ||
// 0028 1d0fec20 0 c1504000 0 c1400008 0 0 0 0 4000 0 100000 0 0 0 0 ena | ||
// 00f0 10de1eb8 a c0000000 44000000c 0 45000000c 0 0 0 1000000 10000000 0 2000000 0 0 0 nvidia | ||
// 00f8 1d0fcd01 0 c1500000 0 c150c008 0 0 0 0 4000 0 2000 0 0 0 0 nvme | ||
// 0030 1d0fec20 0 c1510000 0 c1600008 0 0 0 0 4000 0 100000 0 0 0 0 ena | ||
return strings.Contains(string(devices), "nvidia") | ||
ndbaker1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package containerd | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/awslabs/amazon-eks-ami/nodeadm/internal/api" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNvidiaConfigurator(t *testing.T) { | ||
|
||
t.Run("IsNvidiaUsingInstanceType", func(t *testing.T) { | ||
configurator := nvidiaModifier{} | ||
template := containerdTemplateVars{} | ||
assert.True(t, configurator.Matches(nvidiaInstanceTypeNodeConfig("p5.48xlarge"))) | ||
configurator.Modify(&template) | ||
assert.Equal(t, "nvidia", template.RuntimeName) | ||
assert.Equal(t, "/usr/bin/nvidia-container-runtime", template.RuntimeBinaryName) | ||
}) | ||
|
||
t.Run("IsNvidiaUsingPCIe", func(t *testing.T) { | ||
configurator := nvidiaModifier{pcieDevicesPath: filepath.Join(t.TempDir(), "pcie-devices")} | ||
os.WriteFile(configurator.pcieDevicesPath, []byte("nvidia"), 0777) | ||
template := containerdTemplateVars{} | ||
assert.True(t, configurator.Matches(nvidiaInstanceTypeNodeConfig("xxx.xxxxx"))) | ||
configurator.Modify(&template) | ||
assert.Equal(t, "nvidia", template.RuntimeName) | ||
assert.Equal(t, "/usr/bin/nvidia-container-runtime", template.RuntimeBinaryName) | ||
}) | ||
|
||
t.Run("IsNotNvidia", func(t *testing.T) { | ||
configurator := nvidiaModifier{} | ||
assert.False(t, configurator.Matches(nvidiaInstanceTypeNodeConfig("m5.large"))) | ||
}) | ||
} | ||
|
||
func nvidiaInstanceTypeNodeConfig(instanceType string) *api.NodeConfig { | ||
return &api.NodeConfig{ | ||
Status: api.NodeConfigStatus{ | ||
Instance: api.InstanceDetails{ | ||
Type: instanceType, | ||
}, | ||
}, | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this about? Doesn't seem related to the other changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The top level daemon config calls should contain separate components and i didn't like how the
runtime spec
was nested inside theconfig.toml
call.i think the kubelet daemon sets the right precedent
amazon-eks-ami/nodeadm/internal/kubelet/daemon.go
Lines 28 to 44 in 28f65e2