Skip to content

Commit 465f813

Browse files
authored
Update VirtualMachineGroupPublishRequest controller to use UID instead of name in managed-by label (#1483)
This PR updates the VirtualMachineGroupPublishRequest controller to use the VirtualMachineGroupPublishRequest's UID in place of its name when creating child VirtualMachinePublishRequests with the virtualmachinepublishrequest-managed-by label. There is a 63 character limit on label keys. We have and will continue to hit this limit when using the Group Publish Request's name. We, instead, use the Group Publish Request's UID as it will fit nicely within this limit.
1 parent 08d748a commit 465f813

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

controllers/virtualmachinegrouppublishrequest/virtualmachinegrouppublishrequest_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func (r *Reconciler) getVMPublishRequests(
216216
reqs,
217217
client.InNamespace(ctx.VMGroupPublishRequest.Namespace),
218218
client.MatchingLabels{
219-
vmopv1.VirtualMachinePublishRequestManagedByLabelKey: ctx.VMGroupPublishRequest.Name,
219+
vmopv1.VirtualMachinePublishRequestManagedByLabelKey: string(ctx.VMGroupPublishRequest.UID),
220220
}); err != nil {
221221
ctx.Logger.Error(err, "failed to list VirtualMachinePublishRequest")
222222
return nil, nil, nil, err
@@ -293,7 +293,7 @@ func (r *Reconciler) reconcileNewPublishRequests(
293293
*metav1.NewControllerRef(ctx.VMGroupPublishRequest, vmGroupPubReqGvk),
294294
},
295295
Labels: map[string]string{
296-
vmopv1.VirtualMachinePublishRequestManagedByLabelKey: ctx.VMGroupPublishRequest.Name,
296+
vmopv1.VirtualMachinePublishRequestManagedByLabelKey: string(ctx.VMGroupPublishRequest.UID),
297297
},
298298
},
299299
Spec: vmopv1.VirtualMachinePublishRequestSpec{

controllers/virtualmachinegrouppublishrequest/virtualmachinegrouppublishrequest_controller_intg_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func intgTestsReconcile() {
5353
getVMPubReqs := func(ctx *builder.IntegrationTestContext, ns string) []vmopv1.VirtualMachinePublishRequest {
5454
reqs := &vmopv1.VirtualMachinePublishRequestList{}
5555
Expect(ctx.Client.List(ctx, reqs, client.InNamespace(ns), client.MatchingLabels{
56-
vmopv1.VirtualMachinePublishRequestManagedByLabelKey: vmGroupPubReq.Name,
56+
vmopv1.VirtualMachinePublishRequestManagedByLabelKey: string(vmGroupPubReq.UID),
5757
})).NotTo(HaveOccurred())
5858
return reqs.Items
5959
}

controllers/virtualmachinegrouppublishrequest/virtualmachinegrouppublishrequest_controller_unit_test.go

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

77
import (
88
"fmt"
9-
109
. "github.com/onsi/ginkgo/v2"
1110
. "github.com/onsi/gomega"
1211
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -51,6 +50,7 @@ func unitTestsReconcile() {
5150
builder.DummyNamespaceName,
5251
[]string{builder.DummyVirtualMachineName + "-0", builder.DummyVirtualMachineName + "-1"})
5352
controllerutil.AddFinalizer(vmGroupPubReq, finalizerName)
53+
vmGroupPubReq.UID = "test-vm-group-pubreq-uid"
5454
})
5555

5656
JustBeforeEach(func() {
@@ -197,7 +197,7 @@ func getVMPublishRequests(
197197
reqs,
198198
client.InNamespace(vmGroupPubReq.Namespace),
199199
client.MatchingLabels{
200-
vmopv1.VirtualMachinePublishRequestManagedByLabelKey: vmGroupPubReq.Name,
200+
vmopv1.VirtualMachinePublishRequestManagedByLabelKey: string(vmGroupPubReq.UID),
201201
})).NotTo(HaveOccurred())
202202
Expect(reqs.Items).To(HaveLen(expectedPendingCnt))
203203
return reqs.Items
@@ -206,7 +206,7 @@ func getVMPublishRequests(
206206
func verifyRequest(req vmopv1.VirtualMachinePublishRequest, vmGroupPub *vmopv1.VirtualMachineGroupPublishRequest) {
207207
Expect(req.Name).To(ContainSubstring(vmGroupPub.Name))
208208
Expect(metav1.HasLabel(req.ObjectMeta, vmopv1.VirtualMachinePublishRequestManagedByLabelKey)).To(BeTrue())
209-
Expect(req.Labels).To(HaveKeyWithValue(vmopv1.VirtualMachinePublishRequestManagedByLabelKey, vmGroupPub.Name))
209+
Expect(req.Labels).To(HaveKeyWithValue(vmopv1.VirtualMachinePublishRequestManagedByLabelKey, string(vmGroupPub.UID)))
210210
Expect(metav1.IsControlledBy(&req, vmGroupPub)).To(BeTrue())
211211
Expect(req.Spec.Source.Kind).To(Equal("VirtualMachine"))
212212
Expect(req.Spec.Source.Name).To(ContainSubstring("dummy-vm"))

webhooks/virtualmachinepublishrequest/validation/virtualmachinepublishrequest_validator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ func (v validator) validateCreateVMGroupPublishRequestOwnership(vmPub *vmopv1.Vi
195195

196196
for _, ownerRef := range vmPub.OwnerReferences {
197197
if ownerRef.Kind == "VirtualMachineGroupPublishRequest" &&
198-
ownerRef.Name == vmPub.Labels[vmopv1.VirtualMachinePublishRequestManagedByLabelKey] {
198+
string(ownerRef.UID) == vmPub.Labels[vmopv1.VirtualMachinePublishRequestManagedByLabelKey] {
199199
return nil
200200
}
201201
}

0 commit comments

Comments
 (0)