Skip to content

Commit

Permalink
address nits
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziopandini committed Jun 22, 2023
1 parent fc5a845 commit 91fdaf0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
11 changes: 7 additions & 4 deletions controlplane/kubeadm/internal/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.

// Initialize the control plane scope; this includes also checking for orphan machines and
// adopt them if necessary.
controlPlane, machineAdopted, err := r.initControlPlaneScope(ctx, cluster, kcp)
controlPlane, adoptableMachineFound, err := r.initControlPlaneScope(ctx, cluster, kcp)
if err != nil {
return ctrl.Result{}, err
}
if machineAdopted {
if adoptableMachineFound {
// if there are no errors but at least one CP machine has been adopted, then requeue and
// wait for the update event for the ownership to be set.
return ctrl.Result{}, nil
Expand Down Expand Up @@ -253,6 +253,8 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.

// initControlPlaneScope initializes the control plane scope; this includes also checking for orphan machines and
// adopt them if necessary.
// The func also returns a boolean indicating if adoptableMachine have been found and processed, but this doesn't imply those machines
// have been actually adopted).
func (r *KubeadmControlPlaneReconciler) initControlPlaneScope(ctx context.Context, cluster *clusterv1.Cluster, kcp *controlplanev1.KubeadmControlPlane) (*internal.ControlPlane, bool, error) {
log := ctrl.LoggerFrom(ctx)

Expand Down Expand Up @@ -281,8 +283,9 @@ func (r *KubeadmControlPlaneReconciler) initControlPlaneScope(ctx context.Contex

ownedMachines := controlPlaneMachines.Filter(collections.OwnedMachines(kcp))
if kcp.ObjectMeta.DeletionTimestamp.IsZero() && len(ownedMachines) != len(controlPlaneMachines) {
log.Info("Not all control plane machines are owned by this KubeadmControlPlane, refusing to operate in mixed management mode")
return nil, false, errors.New("Not all control plane machines are owned by this KubeadmControlPlane, refusing to operate in mixed management mode")
err := errors.New("not all control plane machines are owned by this KubeadmControlPlane, refusing to operate in mixed management mode")
log.Error(err, "KCP cannot reconcile")
return nil, false, err
}

controlPlane, err := internal.NewControlPlane(ctx, r.managementCluster, r.Client, cluster, kcp, ownedMachines)
Expand Down
16 changes: 8 additions & 8 deletions controlplane/kubeadm/internal/controllers/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,9 @@ func TestKubeadmControlPlaneReconciler_adoption(t *testing.T) {
managementClusterUncached: fmc,
}

_, hasAdopted, err := r.initControlPlaneScope(ctx, cluster, kcp)
_, adoptableMachineFound, err := r.initControlPlaneScope(ctx, cluster, kcp)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(hasAdopted).To(BeTrue())
g.Expect(adoptableMachineFound).To(BeTrue())

machineList := &clusterv1.MachineList{}
g.Expect(fakeClient.List(ctx, machineList, client.InNamespace(cluster.Namespace))).To(Succeed())
Expand Down Expand Up @@ -616,9 +616,9 @@ func TestKubeadmControlPlaneReconciler_adoption(t *testing.T) {
managementClusterUncached: fmc,
}

_, hasAdopted, err := r.initControlPlaneScope(ctx, cluster, kcp)
_, adoptableMachineFound, err := r.initControlPlaneScope(ctx, cluster, kcp)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(hasAdopted).To(BeTrue())
g.Expect(adoptableMachineFound).To(BeTrue())

machineList := &clusterv1.MachineList{}
g.Expect(fakeClient.List(ctx, machineList, client.InNamespace(cluster.Namespace))).To(Succeed())
Expand Down Expand Up @@ -702,9 +702,9 @@ func TestKubeadmControlPlaneReconciler_adoption(t *testing.T) {
managementClusterUncached: fmc,
}

_, hasAdopted, err := r.initControlPlaneScope(ctx, cluster, kcp)
_, adoptableMachineFound, err := r.initControlPlaneScope(ctx, cluster, kcp)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(hasAdopted).To(BeFalse())
g.Expect(adoptableMachineFound).To(BeFalse())

machineList := &clusterv1.MachineList{}
g.Expect(fakeClient.List(ctx, machineList, client.InNamespace(cluster.Namespace))).To(Succeed())
Expand Down Expand Up @@ -756,9 +756,9 @@ func TestKubeadmControlPlaneReconciler_adoption(t *testing.T) {
managementClusterUncached: fmc,
}

_, hasAdopted, err := r.initControlPlaneScope(ctx, cluster, kcp)
_, adoptableMachineFound, err := r.initControlPlaneScope(ctx, cluster, kcp)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(hasAdopted).To(BeTrue())
g.Expect(adoptableMachineFound).To(BeTrue())

// Message: Warning AdoptionFailed Could not adopt Machine test/test0: its version ("v1.15.0") is outside supported +/- one minor version skew from KCP's ("v1.17.0")
g.Expect(recorder.Events).To(Receive(ContainSubstring("minor version")))
Expand Down
4 changes: 2 additions & 2 deletions controlplane/kubeadm/internal/controllers/scale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ func TestKubeadmControlPlaneReconciler_scaleUpControlPlane(t *testing.T) {
disableInPlacePropagation: true,
}

controlPlane, hasAdopted, err := r.initControlPlaneScope(ctx, cluster, kcp)
controlPlane, adoptableMachineFound, err := r.initControlPlaneScope(ctx, cluster, kcp)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(hasAdopted).To(BeFalse())
g.Expect(adoptableMachineFound).To(BeFalse())

result, err := r.reconcile(context.Background(), controlPlane)
g.Expect(err).ToNot(HaveOccurred())
Expand Down

0 comments on commit 91fdaf0

Please sign in to comment.