Skip to content

Commit 156959c

Browse files
committed
vcsim: reconcile based on v1beta1 for compatibility to clusterctl upgrade tests
1 parent 72a4130 commit 156959c

File tree

4 files changed

+83
-37
lines changed

4 files changed

+83
-37
lines changed

test/infrastructure/vcsim/controllers/virtualmachine_controller.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ import (
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2929
kerrors "k8s.io/apimachinery/pkg/util/errors"
3030
"k8s.io/klog/v2"
31-
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta2"
31+
clusterv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
3232
inmemoryruntime "sigs.k8s.io/cluster-api/test/infrastructure/inmemory/pkg/runtime"
3333
inmemoryserver "sigs.k8s.io/cluster-api/test/infrastructure/inmemory/pkg/server"
34-
capiutil "sigs.k8s.io/cluster-api/util"
3534
"sigs.k8s.io/cluster-api/util/annotations"
3635
"sigs.k8s.io/cluster-api/util/deprecated/v1beta1/patch"
3736
"sigs.k8s.io/cluster-api/util/finalizers"
@@ -98,7 +97,7 @@ func (r *VirtualMachineReconciler) Reconcile(ctx context.Context, req ctrl.Reque
9897
ctx = ctrl.LoggerInto(ctx, log)
9998

10099
// Fetch the Machine.
101-
machine, err := capiutil.GetOwnerMachine(ctx, r.Client, vSphereMachine.ObjectMeta)
100+
machine, err := getOwnerMachineV1Beta1(ctx, r.Client, vSphereMachine.ObjectMeta)
102101
if err != nil {
103102
return ctrl.Result{}, err
104103
}
@@ -110,20 +109,20 @@ func (r *VirtualMachineReconciler) Reconcile(ctx context.Context, req ctrl.Reque
110109
ctx = ctrl.LoggerInto(ctx, log)
111110

112111
// Fetch the Cluster.
113-
cluster, err := capiutil.GetClusterFromMetadata(ctx, r.Client, machine.ObjectMeta)
112+
cluster, err := getClusterV1Beta1FromMetadata(ctx, r.Client, machine.ObjectMeta)
114113
if err != nil {
115114
log.Info("VSphereMachine owner Machine is missing cluster label or cluster does not exist")
116115
return ctrl.Result{}, err
117116
}
118117
if cluster == nil {
119-
log.Info(fmt.Sprintf("Please associate this machine with a cluster using the label %s: <name of cluster>", clusterv1.ClusterNameLabel))
118+
log.Info(fmt.Sprintf("Please associate this machine with a cluster using the label %s: <name of cluster>", clusterv1beta1.ClusterNameLabel))
120119
return ctrl.Result{}, nil
121120
}
122121
log = log.WithValues("Cluster", klog.KObj(cluster))
123122
ctx = ctrl.LoggerInto(ctx, log)
124123

125124
// Return early if the object or Cluster is paused.
126-
if annotations.IsPaused(cluster, virtualMachine) {
125+
if cluster.Spec.Paused || annotations.HasPaused(virtualMachine) {
127126
log.Info("Reconciliation is paused for this object")
128127
return ctrl.Result{}, nil
129128
}
@@ -246,7 +245,7 @@ func (r *VirtualMachineReconciler) Reconcile(ctx context.Context, req ctrl.Reque
246245
return r.reconcileNormal(ctx, cluster, machine, virtualMachine, conditionsTracker)
247246
}
248247

249-
func (r *VirtualMachineReconciler) reconcileNormal(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, virtualMachine *vmoprv1.VirtualMachine, conditionsTracker *infrav1.VSphereVM) (ctrl.Result, error) {
248+
func (r *VirtualMachineReconciler) reconcileNormal(ctx context.Context, cluster *clusterv1beta1.Cluster, machine *clusterv1beta1.Machine, virtualMachine *vmoprv1.VirtualMachine, conditionsTracker *infrav1.VSphereVM) (ctrl.Result, error) {
250249
ipReconciler := r.getVMIpReconciler(cluster, virtualMachine)
251250
if ret, err := ipReconciler.ReconcileIP(ctx); !ret.IsZero() || err != nil {
252251
return ret, err
@@ -260,7 +259,7 @@ func (r *VirtualMachineReconciler) reconcileNormal(ctx context.Context, cluster
260259
return ctrl.Result{}, nil
261260
}
262261

263-
func (r *VirtualMachineReconciler) reconcileDelete(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, virtualMachine *vmoprv1.VirtualMachine, conditionsTracker *infrav1.VSphereVM) (ctrl.Result, error) {
262+
func (r *VirtualMachineReconciler) reconcileDelete(ctx context.Context, cluster *clusterv1beta1.Cluster, machine *clusterv1beta1.Machine, virtualMachine *vmoprv1.VirtualMachine, conditionsTracker *infrav1.VSphereVM) (ctrl.Result, error) {
264263
bootstrapReconciler := r.getVMBootstrapReconciler(virtualMachine)
265264
if ret, err := bootstrapReconciler.reconcileDelete(ctx, cluster, machine, conditionsTracker); !ret.IsZero() || err != nil {
266265
return ret, err
@@ -270,7 +269,7 @@ func (r *VirtualMachineReconciler) reconcileDelete(ctx context.Context, cluster
270269
return ctrl.Result{}, nil
271270
}
272271

273-
func (r *VirtualMachineReconciler) getVMIpReconciler(cluster *clusterv1.Cluster, virtualMachine *vmoprv1.VirtualMachine) *vmIPReconciler {
272+
func (r *VirtualMachineReconciler) getVMIpReconciler(cluster *clusterv1beta1.Cluster, virtualMachine *vmoprv1.VirtualMachine) *vmIPReconciler {
274273
return &vmIPReconciler{
275274
Client: r.Client,
276275

test/infrastructure/vcsim/controllers/vmbootstrap_controller.go

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ import (
3333
"k8s.io/apimachinery/pkg/util/sets"
3434
"k8s.io/klog/v2"
3535
clusterv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
36-
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta2"
3736
inmemoryruntime "sigs.k8s.io/cluster-api/test/infrastructure/inmemory/pkg/runtime"
3837
inmemoryserver "sigs.k8s.io/cluster-api/test/infrastructure/inmemory/pkg/server"
3938
capiutil "sigs.k8s.io/cluster-api/util"
4039
"sigs.k8s.io/cluster-api/util/certs"
41-
conditionsv1beta1 "sigs.k8s.io/cluster-api/util/conditions/deprecated/v1beta1"
4240
deprecatedconditions "sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions"
4341
"sigs.k8s.io/cluster-api/util/secret"
4442
ctrl "sigs.k8s.io/controller-runtime"
@@ -147,7 +145,7 @@ type vmBootstrapReconciler struct {
147145
GetProviderID func() string
148146
}
149147

150-
func (r *vmBootstrapReconciler) reconcileBoostrap(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
148+
func (r *vmBootstrapReconciler) reconcileBoostrap(ctx context.Context, cluster *clusterv1beta1.Cluster, machine *clusterv1beta1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
151149
log := ctrl.LoggerFrom(ctx)
152150

153151
if !deprecatedconditions.Has(conditionsTracker, VMProvisionedCondition) {
@@ -157,7 +155,7 @@ func (r *vmBootstrapReconciler) reconcileBoostrap(ctx context.Context, cluster *
157155
// Make sure bootstrap data is available and populated.
158156
// NOTE: we are not using bootstrap data, but we wait for it in order to simulate a real machine provisioning workflow.
159157
if machine.Spec.Bootstrap.DataSecretName == nil {
160-
if !util.IsControlPlaneMachine(machine) && !conditionsv1beta1.IsTrue(cluster, clusterv1.ControlPlaneInitializedV1Beta1Condition) {
158+
if !util.IsControlPlaneMachine(machine) && !deprecatedconditions.IsTrue(cluster, clusterv1beta1.ControlPlaneInitializedCondition) {
161159
deprecatedconditions.MarkFalse(conditionsTracker, VMProvisionedCondition, WaitingControlPlaneInitializedReason, clusterv1beta1.ConditionSeverityInfo, "")
162160
log.Info("Waiting for the control plane to be initialized")
163161
return reconcile.Result{RequeueAfter: 5 * time.Second}, nil // keep requeueing since we don't have a watch on machines // TODO: check if we can avoid this
@@ -178,7 +176,7 @@ func (r *vmBootstrapReconciler) reconcileBoostrap(ctx context.Context, cluster *
178176
}
179177

180178
// Call the inner reconciliation methods.
181-
phases := []func(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error){
179+
phases := []func(ctx context.Context, cluster *clusterv1beta1.Cluster, machine *clusterv1beta1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error){
182180
r.reconcileBoostrapNode,
183181
r.reconcileBoostrapETCD,
184182
r.reconcileBoostrapAPIServer,
@@ -204,7 +202,7 @@ func (r *vmBootstrapReconciler) reconcileBoostrap(ctx context.Context, cluster *
204202
return res, kerrors.NewAggregate(errs)
205203
}
206204

207-
func (r *vmBootstrapReconciler) reconcileBoostrapNode(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
205+
func (r *vmBootstrapReconciler) reconcileBoostrapNode(ctx context.Context, cluster *clusterv1beta1.Cluster, machine *clusterv1beta1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
208206
log := ctrl.LoggerFrom(ctx)
209207
nodeName := conditionsTracker.GetName()
210208

@@ -289,7 +287,7 @@ func (r *vmBootstrapReconciler) reconcileBoostrapNode(ctx context.Context, clust
289287
return ctrl.Result{}, nil
290288
}
291289

292-
func (r *vmBootstrapReconciler) reconcileBoostrapETCD(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
290+
func (r *vmBootstrapReconciler) reconcileBoostrapETCD(ctx context.Context, cluster *clusterv1beta1.Cluster, machine *clusterv1beta1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
293291
log := ctrl.LoggerFrom(ctx)
294292
etcdMember := fmt.Sprintf("etcd-%s", conditionsTracker.GetName())
295293

@@ -433,7 +431,7 @@ func (r *vmBootstrapReconciler) reconcileBoostrapETCD(ctx context.Context, clust
433431
return ctrl.Result{}, nil
434432
}
435433

436-
func (r *vmBootstrapReconciler) reconcileBoostrapAPIServer(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
434+
func (r *vmBootstrapReconciler) reconcileBoostrapAPIServer(ctx context.Context, cluster *clusterv1beta1.Cluster, machine *clusterv1beta1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
437435
log := ctrl.LoggerFrom(ctx)
438436
apiServer := fmt.Sprintf("kube-apiserver-%s", conditionsTracker.GetName())
439437

@@ -542,7 +540,7 @@ func (r *vmBootstrapReconciler) reconcileBoostrapAPIServer(ctx context.Context,
542540
return ctrl.Result{}, nil
543541
}
544542

545-
func (r *vmBootstrapReconciler) reconcileBoostrapScheduler(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
543+
func (r *vmBootstrapReconciler) reconcileBoostrapScheduler(ctx context.Context, cluster *clusterv1beta1.Cluster, machine *clusterv1beta1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
546544
// No-op if the machine is not a control plane machine.
547545
if !util.IsControlPlaneMachine(machine) {
548546
return ctrl.Result{}, nil
@@ -589,7 +587,7 @@ func (r *vmBootstrapReconciler) reconcileBoostrapScheduler(ctx context.Context,
589587
return ctrl.Result{}, nil
590588
}
591589

592-
func (r *vmBootstrapReconciler) reconcileBoostrapControllerManager(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
590+
func (r *vmBootstrapReconciler) reconcileBoostrapControllerManager(ctx context.Context, cluster *clusterv1beta1.Cluster, machine *clusterv1beta1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
593591
// No-op if the machine is not a control plane machine.
594592
if !util.IsControlPlaneMachine(machine) {
595593
return ctrl.Result{}, nil
@@ -636,7 +634,7 @@ func (r *vmBootstrapReconciler) reconcileBoostrapControllerManager(ctx context.C
636634
return ctrl.Result{}, nil
637635
}
638636

639-
func (r *vmBootstrapReconciler) reconcileBoostrapKubeadmObjects(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, _ ConditionsTracker) (ctrl.Result, error) {
637+
func (r *vmBootstrapReconciler) reconcileBoostrapKubeadmObjects(ctx context.Context, cluster *clusterv1beta1.Cluster, machine *clusterv1beta1.Machine, _ ConditionsTracker) (ctrl.Result, error) {
640638
// No-op if the machine is not a control plane machine.
641639
if !util.IsControlPlaneMachine(machine) {
642640
return ctrl.Result{}, nil
@@ -703,7 +701,7 @@ func (r *vmBootstrapReconciler) reconcileBoostrapKubeadmObjects(ctx context.Cont
703701
return ctrl.Result{}, nil
704702
}
705703

706-
func (r *vmBootstrapReconciler) reconcileBoostrapKubeProxy(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, _ ConditionsTracker) (ctrl.Result, error) {
704+
func (r *vmBootstrapReconciler) reconcileBoostrapKubeProxy(ctx context.Context, cluster *clusterv1beta1.Cluster, machine *clusterv1beta1.Machine, _ ConditionsTracker) (ctrl.Result, error) {
707705
// No-op if the machine is not a control plane machine.
708706
if !util.IsControlPlaneMachine(machine) {
709707
return ctrl.Result{}, nil
@@ -749,7 +747,7 @@ func (r *vmBootstrapReconciler) reconcileBoostrapKubeProxy(ctx context.Context,
749747
return ctrl.Result{}, nil
750748
}
751749

752-
func (r *vmBootstrapReconciler) reconcileBoostrapCoredns(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, _ ConditionsTracker) (ctrl.Result, error) {
750+
func (r *vmBootstrapReconciler) reconcileBoostrapCoredns(ctx context.Context, cluster *clusterv1beta1.Cluster, machine *clusterv1beta1.Machine, _ ConditionsTracker) (ctrl.Result, error) {
753751
// No-op if the machine is not a control plane machine.
754752
if !util.IsControlPlaneMachine(machine) {
755753
return ctrl.Result{}, nil
@@ -812,9 +810,9 @@ func (r *vmBootstrapReconciler) reconcileBoostrapCoredns(ctx context.Context, cl
812810
return ctrl.Result{}, nil
813811
}
814812

815-
func (r *vmBootstrapReconciler) reconcileDelete(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
813+
func (r *vmBootstrapReconciler) reconcileDelete(ctx context.Context, cluster *clusterv1beta1.Cluster, machine *clusterv1beta1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
816814
// Call the inner reconciliation methods.
817-
phases := []func(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error){
815+
phases := []func(ctx context.Context, cluster *clusterv1beta1.Cluster, machine *clusterv1beta1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error){
818816
r.reconcileDeleteNode,
819817
r.reconcileDeleteETCD,
820818
r.reconcileDeleteAPIServer,
@@ -841,7 +839,7 @@ func (r *vmBootstrapReconciler) reconcileDelete(ctx context.Context, cluster *cl
841839
return res, kerrors.NewAggregate(errs)
842840
}
843841

844-
func (r *vmBootstrapReconciler) reconcileDeleteNode(ctx context.Context, cluster *clusterv1.Cluster, _ *clusterv1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
842+
func (r *vmBootstrapReconciler) reconcileDeleteNode(ctx context.Context, cluster *clusterv1beta1.Cluster, _ *clusterv1beta1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
845843
// Compute the resource group unique name.
846844
resourceGroup := klog.KObj(cluster).String()
847845
inmemoryClient := r.InMemoryManager.GetResourceGroup(resourceGroup).GetClient()
@@ -861,7 +859,7 @@ func (r *vmBootstrapReconciler) reconcileDeleteNode(ctx context.Context, cluster
861859
return ctrl.Result{}, nil
862860
}
863861

864-
func (r *vmBootstrapReconciler) reconcileDeleteETCD(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
862+
func (r *vmBootstrapReconciler) reconcileDeleteETCD(ctx context.Context, cluster *clusterv1beta1.Cluster, machine *clusterv1beta1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
865863
// No-op if the machine is not a control plane machine.
866864
if !util.IsControlPlaneMachine(machine) {
867865
return ctrl.Result{}, nil
@@ -898,7 +896,7 @@ func (r *vmBootstrapReconciler) reconcileDeleteETCD(ctx context.Context, cluster
898896
return ctrl.Result{}, nil
899897
}
900898

901-
func (r *vmBootstrapReconciler) reconcileDeleteAPIServer(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
899+
func (r *vmBootstrapReconciler) reconcileDeleteAPIServer(ctx context.Context, cluster *clusterv1beta1.Cluster, machine *clusterv1beta1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
902900
// No-op if the machine is not a control plane machine.
903901
if !util.IsControlPlaneMachine(machine) {
904902
return ctrl.Result{}, nil
@@ -930,7 +928,7 @@ func (r *vmBootstrapReconciler) reconcileDeleteAPIServer(ctx context.Context, cl
930928
return ctrl.Result{}, nil
931929
}
932930

933-
func (r *vmBootstrapReconciler) reconcileDeleteScheduler(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
931+
func (r *vmBootstrapReconciler) reconcileDeleteScheduler(ctx context.Context, cluster *clusterv1beta1.Cluster, machine *clusterv1beta1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
934932
// No-op if the machine is not a control plane machine.
935933
if !util.IsControlPlaneMachine(machine) {
936934
return ctrl.Result{}, nil
@@ -953,7 +951,7 @@ func (r *vmBootstrapReconciler) reconcileDeleteScheduler(ctx context.Context, cl
953951
return ctrl.Result{}, nil
954952
}
955953

956-
func (r *vmBootstrapReconciler) reconcileDeleteControllerManager(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
954+
func (r *vmBootstrapReconciler) reconcileDeleteControllerManager(ctx context.Context, cluster *clusterv1beta1.Cluster, machine *clusterv1beta1.Machine, conditionsTracker ConditionsTracker) (ctrl.Result, error) {
957955
// No-op if the machine is not a control plane machine.
958956
if !util.IsControlPlaneMachine(machine) {
959957
return ctrl.Result{}, nil

0 commit comments

Comments
 (0)