Skip to content

Commit

Permalink
fix nil ptr
Browse files Browse the repository at this point in the history
Signed-off-by: Kirtana Ashok <[email protected]>
  • Loading branch information
kiashok committed Jul 3, 2024
1 parent bca3cd0 commit 6536a4c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions internal/hcsoci/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ func CreateContainer(ctx context.Context, createOptions *CreateOptions) (_ cow.C

// if container is process isolated, check if affinityCPUs has been set in createOptions.
// If yes, set information on the job object created for this container

if coi.HostingSystem == nil && coi.Spec.Windows != nil {
err = setCPUAffinityOnJobObject(ctx, coi.Spec, system.ID())
if err != nil {
Expand All @@ -300,7 +301,8 @@ func CreateContainer(ctx context.Context, createOptions *CreateOptions) (_ cow.C

func setCPUAffinityOnJobObject(ctx context.Context, spec *specs.Spec, computeSystemId string) error {
//
if spec.Windows.Resources == nil || spec.Windows.Resources.CPU == nil {
if spec == nil || spec.Windows == nil || spec.Windows.Resources == nil ||
spec.Windows.Resources.CPU == nil || spec.Windows.Resources.CPU.AffinityCPUs == nil {
return nil
}

Expand Down Expand Up @@ -357,7 +359,7 @@ func setCPUAffinityOnJobObject(ctx context.Context, spec *specs.Spec, computeSys
}
}
*/
numaNodeInfo := []winapi.JOBOBJECT_CPU_GROUP_AFFINITY{}
// numaNodeInfo := []winapi.JOBOBJECT_CPU_GROUP_AFFINITY{}
info := []winapi.JOBOBJECT_CPU_GROUP_AFFINITY{}
if spec.Windows.Resources.CPU.AffinityCPUs != nil {
info := make([]winapi.JOBOBJECT_CPU_GROUP_AFFINITY, len(spec.Windows.Resources.CPU.AffinityCPUs))
Expand All @@ -369,7 +371,7 @@ func setCPUAffinityOnJobObject(ctx context.Context, spec *specs.Spec, computeSys
}

if spec.Windows.Resources.CPU.AffinityPreferredNumaNodes != nil {
numaNodeInfo, err = coreinfo.GetNumaNodeToProcessorInfo()
numaNodeInfo, err := coreinfo.GetNumaNodeToProcessorInfo()
if err != nil {
return fmt.Errorf("error getting numa node info: %v", err)
}
Expand All @@ -385,7 +387,7 @@ func setCPUAffinityOnJobObject(ctx context.Context, spec *specs.Spec, computeSys
break
}
}
if doesCpuAffinityExist == false {
if !doesCpuAffinityExist {
info = append(info, numaNode)
}
}
Expand Down

0 comments on commit 6536a4c

Please sign in to comment.