Skip to content

Commit

Permalink
first commit for gpup (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
wenjlu-lgy authored Jun 20, 2024
1 parent c68f25b commit d5b81b8
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 12 deletions.
2 changes: 2 additions & 0 deletions api/v1beta1/azurestackhcimachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type AzureStackHCIMachineSpec struct {
// +optional
StorageContainer string `json:"storageContainer"`

GpuCount int32 `json:"gpuCount,omitempty"`

// AllocatePublicIP allows the ability to create dynamic public ips for machines where this value is true.
// +optional
AllocatePublicIP bool `json:"allocatePublicIP,omitempty"`
Expand Down
2 changes: 2 additions & 0 deletions api/v1beta1/azurestackhcivirtualmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type AzureStackHCIVirtualMachineSpec struct {

// +optional
StorageContainer string `json:"storageContainer"`
// if not specified, it's a vm without gpu
GpuCount int32 `json:"gpuCount,omitempty"`

// come from the cluster scope for machine and lb controller creation path
ResourceGroup string `json:"resourceGroup"`
Expand Down
19 changes: 19 additions & 0 deletions cloud/services/virtualmachines/virtualmachines.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Spec struct {
NICName string
SSHKeyData []string
Size string
GpuCount int32
Zone string
Image infrav1.Image
OSDisk infrav1.OSDisk
Expand Down Expand Up @@ -104,6 +105,7 @@ func (s *Service) Reconcile(ctx context.Context, spec interface{}) error {
"Name", vmSpec.Name,
"NICName", vmSpec.NICName,
"Size", vmSpec.Size,
"GpuCount", vmSpec.GpuCount,
"Image", vmSpec.Image,
"OSDisk", vmSpec.OSDisk,
"VMType", vmSpec.VMType,
Expand Down Expand Up @@ -169,6 +171,8 @@ func (s *Service) Reconcile(ctx context.Context, spec interface{}) error {
},
}

virtualMachine.HardwareProfile.VirtualMachineGPUs = generateGpuList(vmSpec.GpuCount)

if vmSpec.Image.OSType == infrav1.OSTypeWindows || vmSpec.Image.OSType == infrav1.OSTypeWindows2022 {
virtualMachine.OsProfile.LinuxConfiguration = nil
pass := ""
Expand Down Expand Up @@ -359,3 +363,18 @@ func generateComputerName(os infrav1.OSType) (string, error) {

return computerName, nil
}

func generateGpuList(gpuCount int32) []*compute.VirtualMachineGPU {
if gpuCount <= 0 {
return nil
}

gpuList := make([]*compute.VirtualMachineGPU, gpuCount)
gpuAssignment := compute.GpuDefault
for i := 0; i < int(gpuCount); i++ {
gpuList[i] = &compute.VirtualMachineGPU{
Assignment: &gpuAssignment,
}
}
return gpuList
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ spec:
id:
type: string
type: object
gpuCount:
format: int32
type: integer
image:
description: |-
Image defines information about the image to use for VM creation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ spec:
id:
type: string
type: object
gpuCount:
format: int32
type: integer
image:
description: |-
Image defines information about the image to use for VM creation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ spec:
type: string
clusterName:
type: string
gpuCount:
description: if not specified, it's a vm without gpu
format: int32
type: integer
identity:
description: VMIdentity defines the identity of the virtual machine,
if configured.
Expand Down
1 change: 1 addition & 0 deletions controllers/azurestackhcimachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ func (r *AzureStackHCIMachineReconciler) reconcileVirtualMachineNormal(machineSc
image.DeepCopyInto(&vm.Spec.Image)

vm.Spec.VMSize = machineScope.AzureStackHCIMachine.Spec.VMSize
vm.Spec.GpuCount = machineScope.AzureStackHCIMachine.Spec.GpuCount
machineScope.AzureStackHCIMachine.Spec.AvailabilityZone.DeepCopyInto(&vm.Spec.AvailabilityZone)
machineScope.AzureStackHCIMachine.Spec.OSDisk.DeepCopyInto(&vm.Spec.OSDisk)
vm.Spec.Location = machineScope.AzureStackHCIMachine.Spec.Location
Expand Down
1 change: 1 addition & 0 deletions controllers/azurestackhcivirtualmachine_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ func (s *azureStackHCIVirtualMachineService) createVirtualMachine(nicName string
NICName: nicName,
SSHKeyData: decodedKeys,
Size: s.vmScope.AzureStackHCIVirtualMachine.Spec.VMSize,
GpuCount: s.vmScope.AzureStackHCIVirtualMachine.Spec.GpuCount,
OSDisk: s.vmScope.AzureStackHCIVirtualMachine.Spec.OSDisk,
Image: s.vmScope.AzureStackHCIVirtualMachine.Spec.Image,
CustomData: *s.vmScope.AzureStackHCIVirtualMachine.Spec.BootstrapData,
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ require (
github.com/blang/semver v3.5.1+incompatible
github.com/go-logr/logr v1.4.1
github.com/golang/mock v1.6.0
github.com/microsoft/moc v0.16.5
github.com/microsoft/moc-sdk-for-go v0.16.3
github.com/microsoft/moc v0.18.1
github.com/microsoft/moc-sdk-for-go v0.18.1
github.com/onsi/ginkgo/v2 v2.17.1
github.com/onsi/gomega v1.32.0
github.com/pkg/errors v0.9.1
Expand Down Expand Up @@ -81,7 +81,7 @@ require (
github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
Expand All @@ -91,8 +91,8 @@ require (
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231127180814-3a041ad873d4 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/protobuf v1.33.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
15 changes: 8 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1545,10 +1545,10 @@ github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
github.com/microsoft/moc v0.16.5 h1:NYrPfLVTzvjQxL/5j1w252HJ7J7IxMdWNPkReYwVCA0=
github.com/microsoft/moc v0.16.5/go.mod h1:13q9LzzR5I7bZdd+ty62kOfapIW2o+7exBRz77i95Dk=
github.com/microsoft/moc-sdk-for-go v0.16.3 h1:/by/qZ09q75PiRQMf3nryFitr6vmZZdX95W7/Fqn45Y=
github.com/microsoft/moc-sdk-for-go v0.16.3/go.mod h1:CH1T2Fp8bxtyB2KHdfC2w2+x7Y8SL+sroTp1l+x2sqY=
github.com/microsoft/moc v0.18.1 h1:5Gf+0KAf3rK2va9e4UTnSRvQAkf0Wms/Y2WylR0Gg2c=
github.com/microsoft/moc v0.18.1/go.mod h1:fmyIw7p8JlPIelLXTP/aF2xs8MsIspYEGk1mstMqxNM=
github.com/microsoft/moc-sdk-for-go v0.18.1 h1:EiyaW16P2Y+K7ShSCTHBNOIhYD1AmK/sHd9fAp1RewE=
github.com/microsoft/moc-sdk-for-go v0.18.1/go.mod h1:TMdd6rGvHj6UuqNeNH9e5/mNHZthvnI2BO1mwM4/r9c=
github.com/miekg/dns v1.1.25/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8/go.mod h1:mC1jAcsrzbxHt8iiaC+zU4b1ylILSosueou12R++wfY=
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3/go.mod h1:RagcQ7I8IeTMnF8JTXieKnO4Z6JCsikNEzj0DwauVzE=
Expand Down Expand Up @@ -2329,8 +2329,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20231012201019-e917dd12ba7a/go.
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:swOH3j0KzcDDgGUWr+SNpyTen5YrXjS3eyPzFYKc6lc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405/go.mod h1:67X1fPuzjcrkymZzZV1vvkFeTn2Rvc6lYF9MYFGCcwE=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f/go.mod h1:L9KNLi232K1/xB6f7AlSX692koaRnKaWSR0stBki0Yc=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda h1:LI5DOvAxUPMv/50agcLLoo+AdWc1irS9Rzz4vPuD1V4=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6 h1:DujSIu+2tC9Ht0aPNA7jgj23Iq8Ewi5sgkQ++wdvonE=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
google.golang.org/grpc v1.56.3 h1:8I4C0Yq1EjstUzUJzpcRVbuYA2mODtEmpWiQoN/b2nc=
google.golang.org/grpc v1.56.3/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
Expand All @@ -2352,8 +2352,9 @@ google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw
google.golang.org/protobuf v1.29.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down

0 comments on commit d5b81b8

Please sign in to comment.