From d5b81b8c7f8590ce2211b194dcff78718b0222c2 Mon Sep 17 00:00:00 2001 From: wenjlu-lgy <51814679+wenjlu-lgy@users.noreply.github.com> Date: Thu, 20 Jun 2024 20:44:43 +0800 Subject: [PATCH] first commit for gpup (#276) --- api/v1beta1/azurestackhcimachine_types.go | 2 ++ .../azurestackhcivirtualmachine_types.go | 2 ++ .../virtualmachines/virtualmachines.go | 19 +++++++++++++++++++ ...luster.x-k8s.io_azurestackhcimachines.yaml | 3 +++ ...-k8s.io_azurestackhcimachinetemplates.yaml | 3 +++ ...x-k8s.io_azurestackhcivirtualmachines.yaml | 4 ++++ .../azurestackhcimachine_controller.go | 1 + .../azurestackhcivirtualmachine_reconciler.go | 1 + go.mod | 10 +++++----- go.sum | 15 ++++++++------- 10 files changed, 48 insertions(+), 12 deletions(-) diff --git a/api/v1beta1/azurestackhcimachine_types.go b/api/v1beta1/azurestackhcimachine_types.go index 45dcb60..a463d10 100644 --- a/api/v1beta1/azurestackhcimachine_types.go +++ b/api/v1beta1/azurestackhcimachine_types.go @@ -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"` diff --git a/api/v1beta1/azurestackhcivirtualmachine_types.go b/api/v1beta1/azurestackhcivirtualmachine_types.go index 83d48b7..9b51f0b 100644 --- a/api/v1beta1/azurestackhcivirtualmachine_types.go +++ b/api/v1beta1/azurestackhcivirtualmachine_types.go @@ -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"` diff --git a/cloud/services/virtualmachines/virtualmachines.go b/cloud/services/virtualmachines/virtualmachines.go index 7387df5..df3e17c 100644 --- a/cloud/services/virtualmachines/virtualmachines.go +++ b/cloud/services/virtualmachines/virtualmachines.go @@ -48,6 +48,7 @@ type Spec struct { NICName string SSHKeyData []string Size string + GpuCount int32 Zone string Image infrav1.Image OSDisk infrav1.OSDisk @@ -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, @@ -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 := "" @@ -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 +} diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_azurestackhcimachines.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_azurestackhcimachines.yaml index 3682d28..003b522 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_azurestackhcimachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_azurestackhcimachines.yaml @@ -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. diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_azurestackhcimachinetemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_azurestackhcimachinetemplates.yaml index f17dcf0..afc15c4 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_azurestackhcimachinetemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_azurestackhcimachinetemplates.yaml @@ -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. diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_azurestackhcivirtualmachines.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_azurestackhcivirtualmachines.yaml index 713186e..7c550e2 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_azurestackhcivirtualmachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_azurestackhcivirtualmachines.yaml @@ -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. diff --git a/controllers/azurestackhcimachine_controller.go b/controllers/azurestackhcimachine_controller.go index 7aaf710..c90e2b4 100644 --- a/controllers/azurestackhcimachine_controller.go +++ b/controllers/azurestackhcimachine_controller.go @@ -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 diff --git a/controllers/azurestackhcivirtualmachine_reconciler.go b/controllers/azurestackhcivirtualmachine_reconciler.go index dca2073..2b338e5 100644 --- a/controllers/azurestackhcivirtualmachine_reconciler.go +++ b/controllers/azurestackhcivirtualmachine_reconciler.go @@ -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, diff --git a/go.mod b/go.mod index 98b27d0..0bdd6ad 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 @@ -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 diff --git a/go.sum b/go.sum index c4c01b9..cee89da 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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=