Skip to content

Commit a837268

Browse files
authored
🌱 Skip VM with zone label and address recreated VM in group placement (#1214)
This oatcg updates the VM Group controller during group placement reconciliation by: - Skipping VM members that already have the `topology.kubernetes.io/zone` label, preventing unnecessary DRS placement (VM controller already ignores the group placement result for these VMs). - Reassigning placement for VM members whose UID does not match the group member status, ensuring accurate placement status when a VM is recreated with the same name but not removed from the group. All the required API changes are backported to v1alpha2 to maintain compatibility with VKS (still on v1a2).
1 parent 16e3a77 commit a837268

12 files changed

+308
-164
lines changed

‎api/v1alpha2/virtualmachinegroup_types.go‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package v1alpha2
66

77
import (
88
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9+
"k8s.io/apimachinery/pkg/types"
910
)
1011

1112
const (
@@ -159,9 +160,6 @@ type VirtualMachineGroupPlacementDatastoreStatus struct {
159160
}
160161

161162
type VirtualMachinePlacementStatus struct {
162-
// Name is the name of VirtualMachine member of this group.
163-
Name string `json:"name"`
164-
165163
// +optional
166164

167165
// Zone describes the recommended zone for this VM.
@@ -199,6 +197,11 @@ type VirtualMachineGroupMemberStatus struct {
199197

200198
// +optional
201199

200+
// UID is the K8s metadata UID of this current member object.
201+
UID types.UID `json:"uid,omitempty"`
202+
203+
// +optional
204+
202205
// Placement describes the placement results for this member.
203206
//
204207
// Please note this field is only set for VirtualMachine members.

‎api/v1alpha2/zz_generated.conversion.go‎

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎api/v1alpha3/virtualmachinegroup_types.go‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package v1alpha3
66

77
import (
88
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9+
"k8s.io/apimachinery/pkg/types"
910
)
1011

1112
const (
@@ -159,9 +160,6 @@ type VirtualMachineGroupPlacementDatastoreStatus struct {
159160
}
160161

161162
type VirtualMachinePlacementStatus struct {
162-
// Name is the name of VirtualMachine member of this group.
163-
Name string `json:"name"`
164-
165163
// +optional
166164

167165
// Zone describes the recommended zone for this VM.
@@ -199,6 +197,11 @@ type VirtualMachineGroupMemberStatus struct {
199197

200198
// +optional
201199

200+
// UID is the K8s metadata UID of this current member object.
201+
UID types.UID `json:"uid,omitempty"`
202+
203+
// +optional
204+
202205
// Placement describes the placement results for this member.
203206
//
204207
// Please note this field is only set for VirtualMachine members.

‎api/v1alpha3/zz_generated.conversion.go‎

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎api/v1alpha4/virtualmachinegroup_types.go‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package v1alpha4
66

77
import (
88
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9+
"k8s.io/apimachinery/pkg/types"
910
)
1011

1112
const (
@@ -159,9 +160,6 @@ type VirtualMachineGroupPlacementDatastoreStatus struct {
159160
}
160161

161162
type VirtualMachinePlacementStatus struct {
162-
// Name is the name of VirtualMachine member of this group.
163-
Name string `json:"name"`
164-
165163
// +optional
166164

167165
// Zone describes the recommended zone for this VM.
@@ -199,6 +197,11 @@ type VirtualMachineGroupMemberStatus struct {
199197

200198
// +optional
201199

200+
// UID is the K8s metadata UID of this current member object.
201+
UID types.UID `json:"uid,omitempty"`
202+
203+
// +optional
204+
202205
// Placement describes the placement results for this member.
203206
//
204207
// Please note this field is only set for VirtualMachine members.

‎api/v1alpha4/zz_generated.conversion.go‎

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎api/v1alpha5/virtualmachinegroup_types.go‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package v1alpha5
66

77
import (
88
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9+
"k8s.io/apimachinery/pkg/types"
910
)
1011

1112
const (
@@ -20,11 +21,6 @@ const (
2021
// VirtualMachineGroupMemberConditionPlacementReady indicates that the
2122
// member has a placement decision ready.
2223
VirtualMachineGroupMemberConditionPlacementReady = "PlacementReady"
23-
24-
// VirtualMachineGroupMemberAlreadyPlacedReason indicates that the
25-
// group member already exists on the back-end infrastructure
26-
// (e.g., vSphere) and therefore does not require placement.
27-
VirtualMachineGroupMemberAlreadyPlacedReason = "AlreadyPlaced"
2824
)
2925

3026
// GroupMember describes a member of a VirtualMachineGroup.
@@ -164,9 +160,6 @@ type VirtualMachineGroupPlacementDatastoreStatus struct {
164160
}
165161

166162
type VirtualMachinePlacementStatus struct {
167-
// Name is the name of VirtualMachine member of this group.
168-
Name string `json:"name"`
169-
170163
// +optional
171164

172165
// Zone describes the recommended zone for this VM.
@@ -204,6 +197,11 @@ type VirtualMachineGroupMemberStatus struct {
204197

205198
// +optional
206199

200+
// UID is the K8s metadata UID of this current member object.
201+
UID types.UID `json:"uid,omitempty"`
202+
203+
// +optional
204+
207205
// Placement describes the placement results for this member.
208206
//
209207
// Please note this field is only set for VirtualMachine members.

‎config/crd/bases/vmoperator.vmware.com_virtualmachinegroups.yaml‎

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,6 @@ spec:
361361
- name
362362
type: object
363363
type: array
364-
name:
365-
description: Name is the name of VirtualMachine member of
366-
this group.
367-
type: string
368364
node:
369365
description: Node describes the recommended node for this
370366
VM.
@@ -377,8 +373,6 @@ spec:
377373
description: Zone describes the recommended zone for this
378374
VM.
379375
type: string
380-
required:
381-
- name
382376
type: object
383377
powerState:
384378
description: |-
@@ -390,6 +384,10 @@ spec:
390384
- PoweredOn
391385
- Suspended
392386
type: string
387+
uid:
388+
description: UID is the K8s metadata UID of this current member
389+
object.
390+
type: string
393391
required:
394392
- kind
395393
- name
@@ -750,10 +748,6 @@ spec:
750748
- name
751749
type: object
752750
type: array
753-
name:
754-
description: Name is the name of VirtualMachine member of
755-
this group.
756-
type: string
757751
node:
758752
description: Node describes the recommended node for this
759753
VM.
@@ -766,8 +760,6 @@ spec:
766760
description: Zone describes the recommended zone for this
767761
VM.
768762
type: string
769-
required:
770-
- name
771763
type: object
772764
powerState:
773765
description: |-
@@ -779,6 +771,10 @@ spec:
779771
- PoweredOn
780772
- Suspended
781773
type: string
774+
uid:
775+
description: UID is the K8s metadata UID of this current member
776+
object.
777+
type: string
782778
required:
783779
- kind
784780
- name
@@ -1139,10 +1135,6 @@ spec:
11391135
- name
11401136
type: object
11411137
type: array
1142-
name:
1143-
description: Name is the name of VirtualMachine member of
1144-
this group.
1145-
type: string
11461138
node:
11471139
description: Node describes the recommended node for this
11481140
VM.
@@ -1155,8 +1147,6 @@ spec:
11551147
description: Zone describes the recommended zone for this
11561148
VM.
11571149
type: string
1158-
required:
1159-
- name
11601150
type: object
11611151
powerState:
11621152
description: |-
@@ -1168,6 +1158,10 @@ spec:
11681158
- PoweredOn
11691159
- Suspended
11701160
type: string
1161+
uid:
1162+
description: UID is the K8s metadata UID of this current member
1163+
object.
1164+
type: string
11711165
required:
11721166
- kind
11731167
- name
@@ -1528,10 +1522,6 @@ spec:
15281522
- name
15291523
type: object
15301524
type: array
1531-
name:
1532-
description: Name is the name of VirtualMachine member of
1533-
this group.
1534-
type: string
15351525
node:
15361526
description: Node describes the recommended node for this
15371527
VM.
@@ -1544,8 +1534,6 @@ spec:
15441534
description: Zone describes the recommended zone for this
15451535
VM.
15461536
type: string
1547-
required:
1548-
- name
15491537
type: object
15501538
powerState:
15511539
description: |-
@@ -1557,6 +1545,10 @@ spec:
15571545
- PoweredOn
15581546
- Suspended
15591547
type: string
1548+
uid:
1549+
description: UID is the K8s metadata UID of this current member
1550+
object.
1551+
type: string
15601552
required:
15611553
- kind
15621554
- name

0 commit comments

Comments
 (0)