Skip to content

Commit

Permalink
Avoid NodeHealthy condition in etcd machines
Browse files Browse the repository at this point in the history
  • Loading branch information
g-gaston committed Jul 25, 2023
1 parent 1fc9fe0 commit 99a91f2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
15 changes: 9 additions & 6 deletions internal/controllers/machine/machine_controller_noderef.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,20 @@ func (r *Reconciler) reconcileNode(ctx context.Context, cluster *clusterv1.Clust
return ctrl.Result{}, err
}

if _, ok := machine.Labels[clusterv1.MachineEtcdClusterLabelName]; ok {
// Etcd member Machines do not correspond to Kubernetes v1 Nodes; cannot get k8s node to set nodeRef
// This prevents the MachineNodeHealthyCondition from being set in etcd machines, neither true nor false.
// It makes sense since etcd machines are not kubernetes nodes and it doesn't present any issues since the
// summary ready condition doesn't depend on it.
return ctrl.Result{}, nil
}

// Check that the Machine has a valid ProviderID.
if machine.Spec.ProviderID == nil || *machine.Spec.ProviderID == "" {
log.Info("Waiting for infrastructure provider to report spec.providerID", machine.Spec.InfrastructureRef.Kind, klog.KRef(machine.Spec.InfrastructureRef.Namespace, machine.Spec.InfrastructureRef.Name))
conditions.MarkFalse(machine, clusterv1.MachineNodeHealthyCondition, clusterv1.WaitingForNodeRefReason, clusterv1.ConditionSeverityInfo, "")
return ctrl.Result{}, nil
}

if _, ok := machine.Labels[clusterv1.MachineEtcdClusterLabelName]; ok {
// Etcd member Machines do not correspond to Kubernetes v1 Nodes; cannot get k8s node to set nodeRef
return ctrl.Result{}, nil
}
}

Check failure on line 65 in internal/controllers/machine/machine_controller_noderef.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard,default (gci)

remoteClient, err := r.Tracker.GetClient(ctx, util.ObjectKey(cluster))
if err != nil {
Expand Down
43 changes: 43 additions & 0 deletions internal/controllers/machine/machine_controller_noderef_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/controllers/remote"
"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/cluster-api/util/conditions"
"sigs.k8s.io/cluster-api/util/kubeconfig"
)

Expand Down Expand Up @@ -721,3 +722,45 @@ func TestPatchNode(t *testing.T) {
})
}
}

func TestReconcileNodeForEtcdMachines(t *testing.T) {
testCases := []struct {
name string
machine *clusterv1.Machine
}{
{
name: "with providerID",
machine: &clusterv1.Machine{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
clusterv1.MachineEtcdClusterLabelName: "true",
},
},
Spec: clusterv1.MachineSpec{
ProviderID: pointer.String("ID"),
},
},
},
{
name: "without providerID",
machine: &clusterv1.Machine{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
clusterv1.MachineEtcdClusterLabelName: "true",
},
},
Spec: clusterv1.MachineSpec{},
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
g := NewWithT(t)
r := Reconciler{Client: env}

g.Expect(r.reconcileNode(ctx, &clusterv1.Cluster{}, tc.machine)).To(Equal(ctrl.Result{}))
g.Expect(conditions.Get(tc.machine, clusterv1.MachineNodeHealthyCondition)).To(BeNil())
})
}
}

0 comments on commit 99a91f2

Please sign in to comment.