Skip to content

Commit c68359b

Browse files
bgriddalurubgriddaluru
and
bgriddaluru
authored
[Placement Group] Add support to associate VM with placement group (#286)
* Add placement group field in Infra Machine spec and populate placement group name in VM create flow Co-authored-by: bgriddaluru <[email protected]>
1 parent 6c7cb3d commit c68359b

10 files changed

+76
-2195
lines changed

api/v1beta1/azurestackhcimachine_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ type AzureStackHCIMachineSpec struct {
6464

6565
// +optional
6666
AvailabilitySetName string `json:"availabilitySetName,omitempty"`
67+
68+
// +optional
69+
PlacementGroupName string `json:"placementGroupName,omitempty"`
6770
}
6871

6972
// AzureStackHCIMachineStatus defines the observed state of AzureStackHCIMachine

api/v1beta1/azurestackhcivirtualmachine_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ type AzureStackHCIVirtualMachineSpec struct {
6060

6161
// +optional
6262
AvailabilitySetName string `json:"availabilitySetName,omitempty"`
63+
64+
// +optional
65+
PlacementGroupName string `json:"placementGroupName,omitempty"`
6366
}
6467

6568
// AzureStackHCIVirtualMachineStatus defines the observed state of AzureStackHCIVirtualMachine

cloud/services/virtualmachines/virtualmachines.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type Spec struct {
5656
VMType compute.VMType
5757
StorageContainer string
5858
AvailabilitySetName string
59+
PlacementGroupName string
5960
}
6061

6162
// Get provides information about a virtual machine.
@@ -110,6 +111,7 @@ func (s *Service) Reconcile(ctx context.Context, spec interface{}) error {
110111
"OSDisk", vmSpec.OSDisk,
111112
"VMType", vmSpec.VMType,
112113
"AvailabilitySetName", vmSpec.AvailabilitySetName,
114+
"PlacementGroupName", vmSpec.PlacementGroupName,
113115
)
114116

115117
sshKeyData := vmSpec.SSHKeyData
@@ -193,6 +195,13 @@ func (s *Service) Reconcile(ctx context.Context, spec interface{}) error {
193195
}
194196
}
195197

198+
if vmSpec.PlacementGroupName != "" {
199+
virtualMachine.VirtualMachineProperties.PlacementGroupProfile = &compute.PlacementGroupReference{
200+
Name: to.StringPtr(vmSpec.PlacementGroupName),
201+
GroupName: to.StringPtr(s.Scope.GetResourceGroup()),
202+
}
203+
}
204+
196205
_, err = s.Client.CreateOrUpdate(
197206
ctx,
198207
s.Scope.GetResourceGroup(),

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ spec:
153153
- osType
154154
- source
155155
type: object
156+
placementGroupName:
157+
type: string
156158
providerID:
157159
description: ProviderID is the unique identifier as specified by the
158160
cloud provider.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ spec:
163163
- osType
164164
- source
165165
type: object
166+
placementGroupName:
167+
type: string
166168
providerID:
167169
description: ProviderID is the unique identifier as specified
168170
by the cloud provider.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ spec:
163163
- osType
164164
- source
165165
type: object
166+
placementGroupName:
167+
type: string
166168
resourceGroup:
167169
description: come from the cluster scope for machine and lb controller
168170
creation path

controllers/azurestackhcimachine_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ func (r *AzureStackHCIMachineReconciler) reconcileVirtualMachineNormal(machineSc
324324
vm.Spec.AdditionalSSHKeys = machineScope.AzureStackHCIMachine.Spec.AdditionalSSHKeys
325325
vm.Spec.StorageContainer = machineScope.AzureStackHCIMachine.Spec.StorageContainer
326326
vm.Spec.AvailabilitySetName = machineScope.AzureStackHCIMachine.Spec.AvailabilitySetName
327+
vm.Spec.PlacementGroupName = machineScope.AzureStackHCIMachine.Spec.PlacementGroupName
327328

328329
machineScope.AzureStackHCIMachine.Spec.NetworkInterfaces.DeepCopyInto(&vm.Spec.NetworkInterfaces)
329330

controllers/azurestackhcivirtualmachine_reconciler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ func (s *azureStackHCIVirtualMachineService) createVirtualMachine(nicName string
307307
VMType: vmType,
308308
StorageContainer: s.vmScope.StorageContainer(),
309309
AvailabilitySetName: s.vmScope.AzureStackHCIVirtualMachine.Spec.AvailabilitySetName,
310+
PlacementGroupName: s.vmScope.AzureStackHCIVirtualMachine.Spec.PlacementGroupName,
310311
}
311312

312313
err = s.virtualMachinesSvc.Reconcile(s.vmScope.Context, vmSpec)

go.mod

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ 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.19.3
13-
github.com/microsoft/moc-sdk-for-go v0.19.4
12+
github.com/microsoft/moc v0.25.0
13+
github.com/microsoft/moc-sdk-for-go v0.24.2
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
1717
github.com/spf13/pflag v1.0.5
18-
golang.org/x/crypto v0.21.0
19-
google.golang.org/grpc v1.59.0
18+
golang.org/x/crypto v0.28.0
19+
google.golang.org/grpc v1.62.1
2020
k8s.io/api v0.29.3
2121
k8s.io/apimachinery v0.29.3
2222
k8s.io/client-go v0.29.3
@@ -53,7 +53,7 @@ require (
5353
github.com/google/go-cmp v0.6.0 // indirect
5454
github.com/google/gofuzz v1.2.0 // indirect
5555
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
56-
github.com/google/uuid v1.4.0 // indirect
56+
github.com/google/uuid v1.6.0 // indirect
5757
github.com/hashicorp/hcl v1.0.0 // indirect
5858
github.com/hectane/go-acl v0.0.0-20230122075934-ca0b05cb1adb // indirect
5959
github.com/imdario/mergo v0.3.13 // indirect
@@ -67,32 +67,31 @@ require (
6767
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
6868
github.com/modern-go/reflect2 v1.0.2 // indirect
6969
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
70-
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
70+
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
7171
github.com/prometheus/client_golang v1.18.0 // indirect
7272
github.com/prometheus/client_model v0.5.0 // indirect
7373
github.com/prometheus/common v0.45.0 // indirect
7474
github.com/prometheus/procfs v0.12.0 // indirect
75-
github.com/sagikazarmark/locafero v0.4.0 // indirect
75+
github.com/sagikazarmark/locafero v0.6.0 // indirect
7676
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
7777
github.com/sourcegraph/conc v0.3.0 // indirect
7878
github.com/spf13/afero v1.11.0 // indirect
79-
github.com/spf13/cast v1.6.0 // indirect
80-
github.com/spf13/viper v1.18.2 // indirect
79+
github.com/spf13/cast v1.7.0 // indirect
80+
github.com/spf13/viper v1.19.0 // indirect
8181
github.com/subosito/gotenv v1.6.0 // indirect
8282
go.uber.org/multierr v1.11.0 // indirect
83-
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
84-
golang.org/x/net v0.26.0 // indirect
83+
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect
84+
golang.org/x/net v0.31.0 // indirect
8585
golang.org/x/oauth2 v0.18.0 // indirect
86-
golang.org/x/sys v0.18.0 // indirect
86+
golang.org/x/sys v0.27.0 // indirect
8787
golang.org/x/term v0.18.0 // indirect
88-
golang.org/x/text v0.14.0 // indirect
88+
golang.org/x/text v0.20.0 // indirect
8989
golang.org/x/time v0.5.0 // indirect
90-
golang.org/x/tools v0.17.0 // indirect
90+
golang.org/x/tools v0.24.0 // indirect
9191
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
92-
google.golang.org/appengine v1.6.7 // indirect
93-
google.golang.org/genproto/googleapis/api v0.0.0-20231127180814-3a041ad873d4 // indirect
94-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240624140628-dc46fd24d27d // indirect
95-
google.golang.org/protobuf v1.34.2 // indirect
92+
google.golang.org/appengine v1.6.8 // indirect
93+
google.golang.org/genproto/googleapis/rpc v0.0.0-20241113202542-65e8d215514f // indirect
94+
google.golang.org/protobuf v1.35.2 // indirect
9695
gopkg.in/inf.v0 v0.9.1 // indirect
9796
gopkg.in/ini.v1 v1.67.0 // indirect
9897
gopkg.in/yaml.v2 v2.4.0 // indirect

0 commit comments

Comments
 (0)