Skip to content

Commit d5b81b8

Browse files
authored
first commit for gpup (#276)
1 parent c68f25b commit d5b81b8

10 files changed

+48
-12
lines changed

api/v1beta1/azurestackhcimachine_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ type AzureStackHCIMachineSpec struct {
5151
// +optional
5252
StorageContainer string `json:"storageContainer"`
5353

54+
GpuCount int32 `json:"gpuCount,omitempty"`
55+
5456
// AllocatePublicIP allows the ability to create dynamic public ips for machines where this value is true.
5557
// +optional
5658
AllocatePublicIP bool `json:"allocatePublicIP,omitempty"`

api/v1beta1/azurestackhcivirtualmachine_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ type AzureStackHCIVirtualMachineSpec struct {
4343

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

4749
// come from the cluster scope for machine and lb controller creation path
4850
ResourceGroup string `json:"resourceGroup"`

cloud/services/virtualmachines/virtualmachines.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type Spec struct {
4848
NICName string
4949
SSHKeyData []string
5050
Size string
51+
GpuCount int32
5152
Zone string
5253
Image infrav1.Image
5354
OSDisk infrav1.OSDisk
@@ -104,6 +105,7 @@ func (s *Service) Reconcile(ctx context.Context, spec interface{}) error {
104105
"Name", vmSpec.Name,
105106
"NICName", vmSpec.NICName,
106107
"Size", vmSpec.Size,
108+
"GpuCount", vmSpec.GpuCount,
107109
"Image", vmSpec.Image,
108110
"OSDisk", vmSpec.OSDisk,
109111
"VMType", vmSpec.VMType,
@@ -169,6 +171,8 @@ func (s *Service) Reconcile(ctx context.Context, spec interface{}) error {
169171
},
170172
}
171173

174+
virtualMachine.HardwareProfile.VirtualMachineGPUs = generateGpuList(vmSpec.GpuCount)
175+
172176
if vmSpec.Image.OSType == infrav1.OSTypeWindows || vmSpec.Image.OSType == infrav1.OSTypeWindows2022 {
173177
virtualMachine.OsProfile.LinuxConfiguration = nil
174178
pass := ""
@@ -359,3 +363,18 @@ func generateComputerName(os infrav1.OSType) (string, error) {
359363

360364
return computerName, nil
361365
}
366+
367+
func generateGpuList(gpuCount int32) []*compute.VirtualMachineGPU {
368+
if gpuCount <= 0 {
369+
return nil
370+
}
371+
372+
gpuList := make([]*compute.VirtualMachineGPU, gpuCount)
373+
gpuAssignment := compute.GpuDefault
374+
for i := 0; i < int(gpuCount); i++ {
375+
gpuList[i] = &compute.VirtualMachineGPU{
376+
Assignment: &gpuAssignment,
377+
}
378+
}
379+
return gpuList
380+
}

config/crd/bases/infrastructure.cluster.x-k8s.io_azurestackhcimachines.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ spec:
5959
id:
6060
type: string
6161
type: object
62+
gpuCount:
63+
format: int32
64+
type: integer
6265
image:
6366
description: |-
6467
Image defines information about the image to use for VM creation.

config/crd/bases/infrastructure.cluster.x-k8s.io_azurestackhcimachinetemplates.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ spec:
6868
id:
6969
type: string
7070
type: object
71+
gpuCount:
72+
format: int32
73+
type: integer
7174
image:
7275
description: |-
7376
Image defines information about the image to use for VM creation.

config/crd/bases/infrastructure.cluster.x-k8s.io_azurestackhcivirtualmachines.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ spec:
6464
type: string
6565
clusterName:
6666
type: string
67+
gpuCount:
68+
description: if not specified, it's a vm without gpu
69+
format: int32
70+
type: integer
6771
identity:
6872
description: VMIdentity defines the identity of the virtual machine,
6973
if configured.

controllers/azurestackhcimachine_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ func (r *AzureStackHCIMachineReconciler) reconcileVirtualMachineNormal(machineSc
315315
image.DeepCopyInto(&vm.Spec.Image)
316316

317317
vm.Spec.VMSize = machineScope.AzureStackHCIMachine.Spec.VMSize
318+
vm.Spec.GpuCount = machineScope.AzureStackHCIMachine.Spec.GpuCount
318319
machineScope.AzureStackHCIMachine.Spec.AvailabilityZone.DeepCopyInto(&vm.Spec.AvailabilityZone)
319320
machineScope.AzureStackHCIMachine.Spec.OSDisk.DeepCopyInto(&vm.Spec.OSDisk)
320321
vm.Spec.Location = machineScope.AzureStackHCIMachine.Spec.Location

controllers/azurestackhcivirtualmachine_reconciler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ func (s *azureStackHCIVirtualMachineService) createVirtualMachine(nicName string
233233
NICName: nicName,
234234
SSHKeyData: decodedKeys,
235235
Size: s.vmScope.AzureStackHCIVirtualMachine.Spec.VMSize,
236+
GpuCount: s.vmScope.AzureStackHCIVirtualMachine.Spec.GpuCount,
236237
OSDisk: s.vmScope.AzureStackHCIVirtualMachine.Spec.OSDisk,
237238
Image: s.vmScope.AzureStackHCIVirtualMachine.Spec.Image,
238239
CustomData: *s.vmScope.AzureStackHCIVirtualMachine.Spec.BootstrapData,

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ require (
99
github.com/blang/semver v3.5.1+incompatible
1010
github.com/go-logr/logr v1.4.1
1111
github.com/golang/mock v1.6.0
12-
github.com/microsoft/moc v0.16.5
13-
github.com/microsoft/moc-sdk-for-go v0.16.3
12+
github.com/microsoft/moc v0.18.1
13+
github.com/microsoft/moc-sdk-for-go v0.18.1
1414
github.com/onsi/ginkgo/v2 v2.17.1
1515
github.com/onsi/gomega v1.32.0
1616
github.com/pkg/errors v0.9.1
@@ -81,7 +81,7 @@ require (
8181
github.com/subosito/gotenv v1.6.0 // indirect
8282
go.uber.org/multierr v1.11.0 // indirect
8383
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
84-
golang.org/x/net v0.24.0 // indirect
84+
golang.org/x/net v0.25.0 // indirect
8585
golang.org/x/oauth2 v0.18.0 // indirect
8686
golang.org/x/sys v0.18.0 // indirect
8787
golang.org/x/term v0.18.0 // indirect
@@ -91,8 +91,8 @@ require (
9191
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
9292
google.golang.org/appengine v1.6.7 // indirect
9393
google.golang.org/genproto/googleapis/api v0.0.0-20231127180814-3a041ad873d4 // indirect
94-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
95-
google.golang.org/protobuf v1.33.0 // indirect
94+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6 // indirect
95+
google.golang.org/protobuf v1.34.1 // indirect
9696
gopkg.in/inf.v0 v0.9.1 // indirect
9797
gopkg.in/ini.v1 v1.67.0 // indirect
9898
gopkg.in/yaml.v2 v2.4.0 // indirect

go.sum

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,10 +1545,10 @@ github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S
15451545
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
15461546
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
15471547
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
1548-
github.com/microsoft/moc v0.16.5 h1:NYrPfLVTzvjQxL/5j1w252HJ7J7IxMdWNPkReYwVCA0=
1549-
github.com/microsoft/moc v0.16.5/go.mod h1:13q9LzzR5I7bZdd+ty62kOfapIW2o+7exBRz77i95Dk=
1550-
github.com/microsoft/moc-sdk-for-go v0.16.3 h1:/by/qZ09q75PiRQMf3nryFitr6vmZZdX95W7/Fqn45Y=
1551-
github.com/microsoft/moc-sdk-for-go v0.16.3/go.mod h1:CH1T2Fp8bxtyB2KHdfC2w2+x7Y8SL+sroTp1l+x2sqY=
1548+
github.com/microsoft/moc v0.18.1 h1:5Gf+0KAf3rK2va9e4UTnSRvQAkf0Wms/Y2WylR0Gg2c=
1549+
github.com/microsoft/moc v0.18.1/go.mod h1:fmyIw7p8JlPIelLXTP/aF2xs8MsIspYEGk1mstMqxNM=
1550+
github.com/microsoft/moc-sdk-for-go v0.18.1 h1:EiyaW16P2Y+K7ShSCTHBNOIhYD1AmK/sHd9fAp1RewE=
1551+
github.com/microsoft/moc-sdk-for-go v0.18.1/go.mod h1:TMdd6rGvHj6UuqNeNH9e5/mNHZthvnI2BO1mwM4/r9c=
15521552
github.com/miekg/dns v1.1.25/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
15531553
github.com/minio/asm2plan9s v0.0.0-20200509001527-cdd76441f9d8/go.mod h1:mC1jAcsrzbxHt8iiaC+zU4b1ylILSosueou12R++wfY=
15541554
github.com/minio/c2goasm v0.0.0-20190812172519-36a3d3bbc4f3/go.mod h1:RagcQ7I8IeTMnF8JTXieKnO4Z6JCsikNEzj0DwauVzE=
@@ -2329,8 +2329,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20231012201019-e917dd12ba7a/go.
23292329
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:swOH3j0KzcDDgGUWr+SNpyTen5YrXjS3eyPzFYKc6lc=
23302330
google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405/go.mod h1:67X1fPuzjcrkymZzZV1vvkFeTn2Rvc6lYF9MYFGCcwE=
23312331
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f/go.mod h1:L9KNLi232K1/xB6f7AlSX692koaRnKaWSR0stBki0Yc=
2332-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda h1:LI5DOvAxUPMv/50agcLLoo+AdWc1irS9Rzz4vPuD1V4=
2333-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
2332+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6 h1:DujSIu+2tC9Ht0aPNA7jgj23Iq8Ewi5sgkQ++wdvonE=
2333+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY=
23342334
google.golang.org/grpc v1.56.3 h1:8I4C0Yq1EjstUzUJzpcRVbuYA2mODtEmpWiQoN/b2nc=
23352335
google.golang.org/grpc v1.56.3/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s=
23362336
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
@@ -2352,8 +2352,9 @@ google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw
23522352
google.golang.org/protobuf v1.29.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
23532353
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
23542354
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
2355-
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
23562355
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
2356+
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
2357+
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
23572358
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
23582359
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
23592360
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

0 commit comments

Comments
 (0)