Skip to content
Permalink
Browse files

Check existance of MachineContrtolPlaneLabelName label instead of value

  • Loading branch information...
tahsinrahman committed Nov 7, 2019
1 parent 9b14be0 commit 66abf9c65fe08ac0f2236b3ca6ec4fef369a38c3
@@ -202,7 +202,7 @@ func (r *KubeadmConfigReconciler) Reconcile(req ctrl.Request) (_ ctrl.Result, re
if !cluster.Status.ControlPlaneInitialized {
// if it's NOT a control plane machine, requeue
if !util.IsControlPlaneMachine(machine) {
log.Info(fmt.Sprintf("Machine is not a control plane. If it should be a control plane, add `%s: true` as a label to the Machine", clusterv1.MachineControlPlaneLabelName))
log.Info(fmt.Sprintf("Machine is not a control plane. If it should be a control plane, add the label `%s: \"\"` to the Machine", clusterv1.MachineControlPlaneLabelName))
return ctrl.Result{RequeueAfter: 30 * time.Second}, nil
}

@@ -1477,7 +1477,7 @@ func newWorkerMachine(cluster *clusterv1.Cluster) *clusterv1.Machine {

func newControlPlaneMachine(cluster *clusterv1.Cluster, name string) *clusterv1.Machine {
m := newMachine(cluster, name)
m.Labels[clusterv1.MachineControlPlaneLabelName] = "true"
m.Labels[clusterv1.MachineControlPlaneLabelName] = ""
return m
}

@@ -1478,7 +1478,7 @@ func generateTestControlPlaneMachines(cluster *clusterv1.Cluster, ns string, nam
for _, name := range names {
machine := generateTestNodeMachine(cluster, ns, name)
machine.ObjectMeta.Labels = map[string]string{
clusterv1.MachineControlPlaneLabelName: "true",
clusterv1.MachineControlPlaneLabelName: "",
}
machines = append(machines, machine)
}
@@ -279,7 +279,7 @@ var _ = Describe("Cluster Reconciler", func() {
GenerateName: "test6-",
Namespace: v1.NamespaceDefault,
Labels: map[string]string{
clusterv1.MachineControlPlaneLabelName: "true",
clusterv1.MachineControlPlaneLabelName: "",
},
},
Spec: clusterv1.MachineSpec{
@@ -344,7 +344,7 @@ func TestClusterReconciler_machineToCluster(t *testing.T) {
Name: "controlPlaneWithNoderef",
Labels: map[string]string{
clusterv1.ClusterLabelName: cluster.Name,
clusterv1.MachineControlPlaneLabelName: cluster.Name,
clusterv1.MachineControlPlaneLabelName: "",
},
},
Status: clusterv1.MachineStatus{
@@ -362,7 +362,7 @@ func TestClusterReconciler_machineToCluster(t *testing.T) {
Name: "controlPlaneWithoutNoderef",
Labels: map[string]string{
clusterv1.ClusterLabelName: cluster.Name,
clusterv1.MachineControlPlaneLabelName: cluster.Name,
clusterv1.MachineControlPlaneLabelName: "",
},
},
}
@@ -526,7 +526,7 @@ func (b *machineBuilder) ownedBy(c *clusterv1.Cluster) *machineBuilder {
}

func (b *machineBuilder) controlPlane() *machineBuilder {
b.m.Labels = map[string]string{clusterv1.MachineControlPlaneLabelName: "true"}
b.m.Labels = map[string]string{clusterv1.MachineControlPlaneLabelName: ""}
return b
}

@@ -55,7 +55,7 @@ var _ = Describe("Reconcile Machine Phases", func() {
Name: "machine-test",
Namespace: "default",
Labels: map[string]string{
clusterv1.MachineControlPlaneLabelName: "true",
clusterv1.MachineControlPlaneLabelName: "",
},
},
Spec: clusterv1.MachineSpec{
@@ -347,7 +347,7 @@ func TestReconcileRequest(t *testing.T) {
Name: "deleted",
Namespace: "default",
Labels: map[string]string{
clusterv1.MachineControlPlaneLabelName: "true",
clusterv1.MachineControlPlaneLabelName: "",
},
Finalizers: []string{clusterv1.MachineFinalizer, metav1.FinalizerDeleteDependents},
DeletionTimestamp: &time,
@@ -55,3 +55,8 @@
to

`func NewClusterClient(c client.Client, cluster *clusterv1.Cluster, scheme runtime.Scheme) (client.Client, error)`

## A Machine is now considered a control plane if it has `cluster.x-k8s.io/control-plane` set, regardless of value

- Previously examples and tests were setting/checking for the label to be set to `true`.
- The function `util.IsControlPlaneMachine` was previously checking for any value other than empty string, while now we only check if the associated label exists.
@@ -138,7 +138,8 @@ func GetMachineIfExists(c client.Client, namespace, name string) (*clusterv1.Mac

// IsControlPlaneMachine checks machine is a control plane node.
func IsControlPlaneMachine(machine *clusterv1.Machine) bool {
return machine.ObjectMeta.Labels[clusterv1.MachineControlPlaneLabelName] != ""
_, ok := machine.ObjectMeta.Labels[clusterv1.MachineControlPlaneLabelName]
return ok
}

// IsNodeReady returns true if a node is ready.

0 comments on commit 66abf9c

Please sign in to comment.
You can’t perform that action at this time.