Skip to content

Commit 22604bf

Browse files
committed
Fix UT errors
Signed-off-by: Gong Zhang <[email protected]>
1 parent 8cc8e8a commit 22604bf

File tree

7 files changed

+143
-65
lines changed

7 files changed

+143
-65
lines changed

controllers/vmware/virtualmachinegroup_controller.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import (
2121

2222
vmoprv1 "github.com/vmware-tanzu/vm-operator/api/v1alpha2"
2323
apitypes "k8s.io/apimachinery/pkg/types"
24-
vmwarev1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/vmware/v1beta1"
25-
capvcontext "sigs.k8s.io/cluster-api-provider-vsphere/pkg/context"
2624
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
2725
"sigs.k8s.io/cluster-api/util/predicates"
2826
ctrl "sigs.k8s.io/controller-runtime"
@@ -34,6 +32,9 @@ import (
3432
"sigs.k8s.io/controller-runtime/pkg/manager"
3533
"sigs.k8s.io/controller-runtime/pkg/predicate"
3634
"sigs.k8s.io/controller-runtime/pkg/reconcile"
35+
36+
vmwarev1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/vmware/v1beta1"
37+
capvcontext "sigs.k8s.io/cluster-api-provider-vsphere/pkg/context"
3738
)
3839

3940
// +kubebuilder:rbac:groups=cluster.x-k8s.io,resources=clusters,verbs=get;list;watch
@@ -77,7 +78,7 @@ func AddVirtualMachineGroupControllerToManager(ctx context.Context, controllerMa
7778
handler.EnqueueRequestsFromMapFunc(reconciler.VSphereMachineToVirtualMachineGroup),
7879
ctrlbldr.WithPredicates(
7980
predicate.Funcs{
80-
UpdateFunc: func(e event.UpdateEvent) bool { return false },
81+
UpdateFunc: func(event.UpdateEvent) bool { return false },
8182
CreateFunc: func(event.CreateEvent) bool { return true },
8283
DeleteFunc: func(event.DeleteEvent) bool { return true },
8384
GenericFunc: func(event.GenericEvent) bool { return false },
@@ -89,7 +90,7 @@ func AddVirtualMachineGroupControllerToManager(ctx context.Context, controllerMa
8990
}
9091

9192
// ClusterToVirtualMachineGroup maps Cluster events to VirtualMachineGroup reconcile requests.
92-
func (r *VirtualMachineGroupReconciler) ClusterToVirtualMachineGroup(ctx context.Context, a ctrlclient.Object) []reconcile.Request {
93+
func (r *VirtualMachineGroupReconciler) ClusterToVirtualMachineGroup(_ context.Context, a ctrlclient.Object) []reconcile.Request {
9394
cluster, ok := a.(*clusterv1.Cluster)
9495
if !ok {
9596
return nil

controllers/vmware/virtualmachinegroup_reconciler.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3131
"k8s.io/client-go/tools/record"
3232
"k8s.io/klog/v2"
33+
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
3334
"sigs.k8s.io/cluster-api/util/conditions"
3435
ctrl "sigs.k8s.io/controller-runtime"
3536
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -38,7 +39,6 @@ import (
3839

3940
vmwarev1 "sigs.k8s.io/cluster-api-provider-vsphere/apis/vmware/v1beta1"
4041
infrautilv1 "sigs.k8s.io/cluster-api-provider-vsphere/pkg/util"
41-
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
4242
)
4343

4444
const (
@@ -72,6 +72,7 @@ func (r *VirtualMachineGroupReconciler) Reconcile(ctx context.Context, req ctrl.
7272
}
7373

7474
log = log.WithValues("Cluster", klog.KObj(cluster))
75+
7576
// If Cluster is deleted, just return as VirtualMachineGroup will be GCed and no extra processing needed.
7677
if !cluster.DeletionTimestamp.IsZero() {
7778
return reconcile.Result{}, nil
@@ -86,10 +87,9 @@ func (r *VirtualMachineGroupReconciler) Reconcile(ctx context.Context, req ctrl.
8687

8788
// Continue with the main logic.
8889
return r.createOrUpdateVMG(ctx, cluster)
89-
9090
}
9191

92-
// createOrUpdateVMG Create or Update VirtualMachineGroup
92+
// createOrUpdateVMG Create or Update VirtualMachineGroup.
9393
func (r *VirtualMachineGroupReconciler) createOrUpdateVMG(ctx context.Context, cluster *clusterv1.Cluster) (_ reconcile.Result, reterr error) {
9494
log := ctrl.LoggerFrom(ctx)
9595

@@ -228,8 +228,7 @@ func (r *VirtualMachineGroupReconciler) createOrUpdateVMG(ctx context.Context, c
228228
return reconcile.Result{}, err
229229
}
230230

231-
// getExpectedVSphereMachines returns the total number of replicas across all
232-
// MachineDeployments belonging to the Cluster
231+
// MachineDeployments belonging to the Cluster.
233232
func getExpectedVSphereMachines(ctx context.Context, kubeClient client.Client, cluster *clusterv1.Cluster) (int32, error) {
234233
var mdList clusterv1.MachineDeploymentList
235234
if err := kubeClient.List(
@@ -329,8 +328,8 @@ func GenerateVMGPlacementAnnotations(ctx context.Context, vmg *vmoprv1.VirtualMa
329328
return annotations, nil
330329
}
331330

332-
// Duplicated this logic from pkg/services/vmoperator/vmopmachine.go
333331
// GenerateVirtualMachineName generates the name of a VirtualMachine based on the naming strategy.
332+
// Duplicated this logic from pkg/services/vmoperator/vmopmachine.go.
334333
func GenerateVirtualMachineName(machineName string, namingStrategy *vmwarev1.VirtualMachineNamingStrategy) (string, error) {
335334
// Per default the name of the VirtualMachine should be equal to the Machine name (this is the same as "{{ .machine.name }}")
336335
if namingStrategy == nil || namingStrategy.Template == nil {

0 commit comments

Comments
 (0)