Skip to content

Commit 947dffa

Browse files
committed
Fix annotations
Signed-off-by: Gong Zhang <[email protected]>
1 parent 2a21acc commit 947dffa

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

controllers/vmware/virtualmachinegroup_reconciler.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,20 +187,24 @@ func (r *VirtualMachineGroupReconciler) createOrUpdateVMG(ctx context.Context, c
187187
desiredVMG.Labels[clusterv1.ClusterNameLabel] = cluster.Name
188188
}
189189

190+
if desiredVMG.Annotations == nil {
191+
desiredVMG.Annotations = make(map[string]string)
192+
}
193+
190194
// Add per-md-zone label for day-2 operations once placement of a VM belongs to MachineDeployment is done
191195
// Do not update per-md-zone label once set, as placement decision should not change without user explicitly
192196
// ask.
193-
placementDecisionLabels, err := GenerateVMGPlacementAnnotations(ctx, desiredVMG, mdNames)
197+
placementDecisionAnnotations, err := GenerateVMGPlacementAnnotations(ctx, desiredVMG, mdNames)
194198
if err != nil {
195199
return err
196200
}
197-
if len(placementDecisionLabels) > 0 {
198-
for k, v := range placementDecisionLabels {
199-
if _, exists := desiredVMG.Labels[k]; exists {
201+
if len(placementDecisionAnnotations) > 0 {
202+
for k, v := range placementDecisionAnnotations {
203+
if _, exists := desiredVMG.Annotations[k]; exists {
200204
// Skip if the label already exists
201205
continue
202206
}
203-
desiredVMG.Labels[k] = v
207+
desiredVMG.Annotations[k] = v
204208
}
205209
}
206210

@@ -304,7 +308,7 @@ func GenerateVMGPlacementAnnotations(ctx context.Context, vmg *vmoprv1.VirtualMa
304308

305309
// Check if VM belongs to a Machine Deployment by name (e.g. cluster-1-np-1-vm-xxx contains np-1)
306310
// TODO: Establish membership via the machine deployment name label
307-
if strings.Contains(member.Name, "-"+md+"-") {
311+
if strings.Contains(member.Name, md+"-") {
308312
// Get the VM placement information by member status.
309313
// VMs that have undergone placement do not have Placement info set, skip.
310314
if member.Placement == nil {

controllers/vmware/virtualmachinegroup_reconciler_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ func TestGenerateVMGPlacementAnnotations(t *testing.T) {
199199
},
200200
},
201201
},
202-
machineDeployments: []string{mdName1, mdName2},
202+
machineDeployments: []string{clusterName + mdName1, clusterName + mdName2},
203203
wantAnnotations: map[string]string{
204-
fmt.Sprintf("zone.cluster.x-k8s.io/%s", mdName1): zoneA,
205-
fmt.Sprintf("zone.cluster.x-k8s.io/%s", mdName2): zoneB,
204+
fmt.Sprintf("zone.cluster.x-k8s.io/%s", clusterName+mdName1): zoneA,
205+
fmt.Sprintf("zone.cluster.x-k8s.io/%s", clusterName+mdName2): zoneB,
206206
},
207207
wantErr: false,
208208
},
@@ -215,7 +215,7 @@ func TestGenerateVMGPlacementAnnotations(t *testing.T) {
215215
},
216216
},
217217
},
218-
machineDeployments: []string{mdName1},
218+
machineDeployments: []string{clusterName + mdName1},
219219
wantAnnotations: map[string]string{},
220220
wantErr: false,
221221
},
@@ -228,7 +228,7 @@ func TestGenerateVMGPlacementAnnotations(t *testing.T) {
228228
},
229229
},
230230
},
231-
machineDeployments: []string{mdName1},
231+
machineDeployments: []string{clusterName + mdName1},
232232
wantAnnotations: map[string]string{},
233233
wantErr: false,
234234
},
@@ -244,9 +244,9 @@ func TestGenerateVMGPlacementAnnotations(t *testing.T) {
244244
},
245245
},
246246
},
247-
machineDeployments: []string{mdName1},
247+
machineDeployments: []string{clusterName + mdName1},
248248
wantAnnotations: map[string]string{
249-
fmt.Sprintf("zone.cluster.x-k8s.io/%s", mdName1): zoneA,
249+
fmt.Sprintf("zone.cluster.x-k8s.io/%s", clusterName+mdName1): zoneA,
250250
},
251251
wantErr: false,
252252
},
@@ -260,7 +260,7 @@ func TestGenerateVMGPlacementAnnotations(t *testing.T) {
260260
},
261261
},
262262
},
263-
machineDeployments: []string{mdName1},
263+
machineDeployments: []string{clusterName + mdName1},
264264
wantAnnotations: nil,
265265
wantErr: true,
266266
},

0 commit comments

Comments
 (0)