Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Devinwong committed Jan 28, 2025
1 parent 1d26db3 commit 5922d6b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 4 additions & 4 deletions aks-node-controller/parser/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,27 +145,27 @@ func getKubenetTemplate() string {
}

// getContainerdConfig returns the base64 encoded containerd config depending on whether the node is with GPU or not.
func getContainerdConfig(aksnodeconfig *aksnodeconfigv1.Configuration, isGPU bool) string {
func getContainerdConfig(aksnodeconfig *aksnodeconfigv1.Configuration, noGPU bool) string {
if aksnodeconfig == nil {
return ""
}

containerdConfig, err := containerdConfigFromAKSNodeConfig(aksnodeconfig, isGPU)
containerdConfig, err := containerdConfigFromAKSNodeConfig(aksnodeconfig, noGPU)
if err != nil {
return fmt.Sprintf("error getting containerd config from node bootstrap variables: %v", err)
}

return base64.StdEncoding.EncodeToString([]byte(containerdConfig))
}

func containerdConfigFromAKSNodeConfig(aksnodeconfig *aksnodeconfigv1.Configuration, isGPU bool) (string, error) {
func containerdConfigFromAKSNodeConfig(aksnodeconfig *aksnodeconfigv1.Configuration, noGPU bool) (string, error) {
if aksnodeconfig == nil {
return "", fmt.Errorf("AKSNodeConfig is nil")
}

// the containerd config template is different based on whether the node is with GPU or not.
_template := containerdConfigTemplate
if !isGPU {
if noGPU {
_template = containerdConfigNoGPUTemplate
}

Expand Down
9 changes: 6 additions & 3 deletions aks-node-controller/parser/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ func Test_createSortedKeyValueInt32Pairs(t *testing.T) {
func Test_getContainerdConfig(t *testing.T) {
type args struct {
aksnodeconfig *aksnodeconfigv1.Configuration
noGpu bool
}
tests := []struct {
name string
Expand Down Expand Up @@ -284,14 +285,15 @@ oom_score = 0
`)),
},
{
name: "Containerd Configurations with Nvidia GPU enabled",
name: "Containerd Configurations with bool noGpu set to false",
args: args{
aksnodeconfig: &aksnodeconfigv1.Configuration{
NeedsCgroupv2: ToPtr(true),
GpuConfig: &aksnodeconfigv1.GpuConfig{
EnableNvidia: ToPtr(true),
},
},
noGpu: false,
},
want: base64.StdEncoding.EncodeToString([]byte(`version = 2
oom_score = 0
Expand All @@ -315,11 +317,12 @@ oom_score = 0
`)),
},
{
name: "Containerd Configurations with Nvidia GPU disabled",
name: "Containerd Configurations with bool noGpu set to true",
args: args{
aksnodeconfig: &aksnodeconfigv1.Configuration{
NeedsCgroupv2: ToPtr(true),
},
noGpu: true,
},
want: base64.StdEncoding.EncodeToString([]byte(`version = 2
oom_score = 0
Expand All @@ -345,7 +348,7 @@ oom_score = 0
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := getContainerdConfig(tt.args.aksnodeconfig, true); got != tt.want {
if got := getContainerdConfig(tt.args.aksnodeconfig, tt.args.noGpu); got != tt.want {
t.Errorf("getContainerdConfig() = %v, want %v", got, tt.want)
}
})
Expand Down

0 comments on commit 5922d6b

Please sign in to comment.