Skip to content

Commit aaf8b0e

Browse files
authored
Merge pull request #1268 from akutz/feature/do-not-watch-guest-net
✨ Cached vm props / multi priority queues
2 parents 66c7b2a + 02f5a16 commit aaf8b0e

File tree

26 files changed

+2126
-259
lines changed

26 files changed

+2126
-259
lines changed

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ linters:
177177
pkg: github.com/vmware-tanzu/vm-operator/pkg/exit
178178
- alias: pkglog
179179
pkg: github.com/vmware-tanzu/vm-operator/pkg/log
180+
- alias: pkgnil
181+
pkg: github.com/vmware-tanzu/vm-operator/pkg/util/nil
180182
- alias: ctxop
181183
pkg: github.com/vmware-tanzu/vm-operator/pkg/context/operation
182184
- alias: pkgmgr

controllers/infra/zone/zone_controller_test.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ import (
1414

1515
"github.com/vmware/govmomi/object"
1616
vimtypes "github.com/vmware/govmomi/vim25/types"
17-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1817
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
1918
"sigs.k8s.io/controller-runtime/pkg/event"
2019
ctrlmgr "sigs.k8s.io/controller-runtime/pkg/manager"
2120

22-
vmopv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha5"
2321
"github.com/vmware-tanzu/vm-operator/controllers/infra/zone"
2422
topologyv1 "github.com/vmware-tanzu/vm-operator/external/tanzu-topology/api/v1alpha1"
2523
pkgcfg "github.com/vmware-tanzu/vm-operator/pkg/config"
@@ -187,15 +185,11 @@ var _ = Describe(
187185
})
188186
Specify("a reconcile request should be enqueued for vm", func() {
189187
chanSource := cource.FromContext(ctx, "VirtualMachine")
188+
190189
var e event.GenericEvent
191-
Eventually(chanSource).Should(Receive(&e, Equal(event.GenericEvent{
192-
Object: &vmopv1.VirtualMachine{
193-
ObjectMeta: metav1.ObjectMeta{
194-
Namespace: vcSimCtx.NSInfo.Namespace,
195-
Name: vmName,
196-
},
197-
},
198-
})))
190+
Eventually(chanSource).Should(Receive(&e))
191+
Expect(e.Object.GetNamespace()).To(Equal(vcSimCtx.NSInfo.Namespace))
192+
Expect(e.Object.GetName()).To(Equal(vmName))
199193
})
200194

201195
When("a single zone with the vm's folder is removed", func() {
@@ -241,14 +235,9 @@ var _ = Describe(
241235
Expect(t.Wait(ctx)).To(Succeed())
242236

243237
var e event.GenericEvent
244-
Eventually(chanSource).Should(Receive(&e, Equal(event.GenericEvent{
245-
Object: &vmopv1.VirtualMachine{
246-
ObjectMeta: metav1.ObjectMeta{
247-
Namespace: vcSimCtx.NSInfo.Namespace,
248-
Name: vmName,
249-
},
250-
},
251-
})))
238+
Eventually(chanSource).Should(Receive(&e))
239+
Expect(e.Object.GetNamespace()).To(Equal(vcSimCtx.NSInfo.Namespace))
240+
Expect(e.Object.GetName()).To(Equal(vmName))
252241
})
253242
})
254243

controllers/virtualmachine/virtualmachine/virtualmachine_controller.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
vmopv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha5"
2727
byokv1 "github.com/vmware-tanzu/vm-operator/external/byok/api/v1alpha1"
2828
cnsv1alpha1 "github.com/vmware-tanzu/vm-operator/external/vsphere-csi-driver/api/v1alpha1"
29-
"github.com/vmware-tanzu/vm-operator/pkg/conditions"
29+
pkgcond "github.com/vmware-tanzu/vm-operator/pkg/conditions"
3030
pkgcfg "github.com/vmware-tanzu/vm-operator/pkg/config"
3131
pkgconst "github.com/vmware-tanzu/vm-operator/pkg/constants"
3232
pkgctx "github.com/vmware-tanzu/vm-operator/pkg/context"
@@ -84,13 +84,21 @@ func AddToManager(ctx *pkgctx.ControllerManagerContext, mgr manager.Manager) err
8484
proberManager)
8585

8686
builder := ctrl.NewControllerManagedBy(mgr).
87-
For(controlledType).
87+
Named(strings.ToLower(controlledTypeName)).
8888
WithOptions(controller.Options{
8989
MaxConcurrentReconciles: ctx.MaxConcurrentReconciles,
9090
SkipNameValidation: SkipNameValidation,
9191
LogConstructor: pkglog.ControllerLogConstructor(controllerNameShort, controlledType, mgr.GetScheme()),
9292
})
9393

94+
// Watch VirtualMachines.
95+
builder = builder.Watches(
96+
controlledType,
97+
&kubeutil.EnqueueRequestForObject{
98+
Logger: ctrl.Log.WithName("vmqueue"),
99+
GetPriority: kubeutil.GetVirtualMachineReconcilePriority,
100+
})
101+
94102
builder = builder.Watches(&vmopv1.VirtualMachineClass{},
95103
handler.EnqueueRequestsFromMapFunc(classToVMMapperFn(ctx, r.Client)))
96104

@@ -105,7 +113,10 @@ func AddToManager(ctx *pkgctx.ControllerManagerContext, mgr manager.Manager) err
105113
if pkgcfg.FromContext(ctx).AsyncSignalEnabled {
106114
builder = builder.WatchesRawSource(source.Channel(
107115
cource.FromContextWithBuffer(ctx, "VirtualMachine", 100),
108-
&handler.EnqueueRequestForObject{}))
116+
&kubeutil.EnqueueRequestForObject{
117+
Logger: ctrl.Log.WithName("asyncvmqueue"),
118+
GetPriority: kubeutil.GetVirtualMachineReconcilePriority,
119+
}))
109120
}
110121

111122
if pkgcfg.FromContext(ctx).Features.FastDeploy {
@@ -392,7 +403,7 @@ func requeueDelay(
392403
// Create VMs on the provider. Do not queue immediately to avoid exponential
393404
// backoff.
394405
if ignoredCreateErr(err) ||
395-
!conditions.IsTrue(ctx.VM, vmopv1.VirtualMachineConditionCreated) {
406+
!pkgcond.IsTrue(ctx.VM, vmopv1.VirtualMachineConditionCreated) {
396407

397408
return pkgcfg.FromContext(ctx).CreateVMRequeueDelay
398409
}
@@ -661,7 +672,7 @@ func (r *Reconciler) isVMICacheReady(ctx *pkgctx.VirtualMachineContext) bool {
661672
}
662673

663674
// Assert the image hardware is ready.
664-
if !conditions.IsTrue(
675+
if !pkgcond.IsTrue(
665676
vmic,
666677
vmopv1.VirtualMachineImageCacheConditionHardwareReady) {
667678

@@ -695,7 +706,7 @@ func (r *Reconciler) isVMICacheReady(ctx *pkgctx.VirtualMachineContext) bool {
695706
}
696707

697708
// Assert the cached disks are ready.
698-
if locStatus == nil || !conditions.IsTrue(
709+
if locStatus == nil || !pkgcond.IsTrue(
699710
locStatus,
700711
vmopv1.ReadyConditionType) {
701712

controllers/virtualmachinepublishrequest/virtualmachinepublishrequest_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ import (
4545
"github.com/vmware-tanzu/vm-operator/pkg/patch"
4646
"github.com/vmware-tanzu/vm-operator/pkg/providers"
4747
"github.com/vmware-tanzu/vm-operator/pkg/record"
48-
pkgutil "github.com/vmware-tanzu/vm-operator/pkg/util"
4948
kubeutil "github.com/vmware-tanzu/vm-operator/pkg/util/kube"
49+
pkgnil "github.com/vmware-tanzu/vm-operator/pkg/util/nil"
5050
)
5151

5252
const (
@@ -500,7 +500,7 @@ func (r *Reconciler) checkIsTargetValid(ctx *pkgctx.VirtualMachinePublishRequest
500500
return fmt.Errorf("failed to get item %q from library: %w", targetItemName, err)
501501
}
502502

503-
if !pkgutil.IsNil(item) {
503+
if !pkgnil.IsNil(item) {
504504
objKey := client.ObjectKey{Name: vmPubReq.Spec.Target.Location.Name, Namespace: vmPubReq.Namespace}
505505
ctx.Logger.Info("target item already exists in the content library",
506506
"library", objKey, "itemName", targetItemName)
@@ -992,7 +992,7 @@ func (r *Reconciler) findCorrelatedItemIDByName(ctx *pkgctx.VirtualMachinePublis
992992
return "", fmt.Errorf("failed to get item %q from library: %w", targetItemName, err)
993993
}
994994

995-
if !pkgutil.IsNil(item) {
995+
if !pkgnil.IsNil(item) {
996996
// Item already exists in the content library, check if it is created from
997997
// this VirtualMachinePublishRequest from its description.
998998
// If VC forgets the task, or the task hadn't proceeded far enough to be submitted to VC

0 commit comments

Comments
 (0)