Skip to content

Commit 6e14aeb

Browse files
authored
Merge pull request #1635 from srm09/automated-cherry-pick-of-#1622-upstream-release-1.3
Automated cherry pick of #1622: Fixes panic when creating VSphereVM
2 parents 14519dc + 279ee94 commit 6e14aeb

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

controllers/vspheremachine_controller.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ import (
3636
"sigs.k8s.io/cluster-api/util/patch"
3737
"sigs.k8s.io/cluster-api/util/predicates"
3838
ctrl "sigs.k8s.io/controller-runtime"
39+
ctrlbldr "sigs.k8s.io/controller-runtime/pkg/builder"
3940
"sigs.k8s.io/controller-runtime/pkg/client"
4041
"sigs.k8s.io/controller-runtime/pkg/controller"
4142
ctrlutil "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
43+
"sigs.k8s.io/controller-runtime/pkg/event"
4244
"sigs.k8s.io/controller-runtime/pkg/handler"
4345
"sigs.k8s.io/controller-runtime/pkg/manager"
46+
"sigs.k8s.io/controller-runtime/pkg/predicate"
4447
"sigs.k8s.io/controller-runtime/pkg/reconcile"
4548
"sigs.k8s.io/controller-runtime/pkg/source"
4649

@@ -133,7 +136,17 @@ func AddMachineControllerToManager(ctx *context.ControllerManagerContext, mgr ma
133136
r.networkProvider = networkProvider
134137
} else {
135138
// Watch any VSphereVM resources owned by the controlled type.
136-
builder.Watches(&source.Kind{Type: &infrav1.VSphereVM{}}, &handler.EnqueueRequestForOwner{OwnerType: controlledType, IsController: false})
139+
builder.Watches(
140+
&source.Kind{Type: &infrav1.VSphereVM{}},
141+
&handler.EnqueueRequestForOwner{OwnerType: controlledType, IsController: false},
142+
ctrlbldr.WithPredicates(predicate.Funcs{
143+
// ignore creation events since this controller is responsible for
144+
// the creation of the type.
145+
CreateFunc: func(e event.CreateEvent) bool {
146+
return false
147+
},
148+
}),
149+
)
137150
}
138151

139152
c, err := builder.Build(r)

pkg/services/vimmachine.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ func (v *VimMachineService) ReconcileNormal(c context.MachineContext) (bool, err
121121
}
122122

123123
vm, err := v.createOrPatchVSPhereVM(ctx, vsphereVM)
124-
125-
if err != nil && !apierrors.IsAlreadyExists(err) {
124+
if err != nil {
125+
ctx.Logger.Error(err, "error creating or patching VM", "vsphereVM", vsphereVM)
126126
return false, err
127127
}
128128

0 commit comments

Comments
 (0)