diff --git a/pkg/controller/machineset/controller.go b/pkg/controller/machineset/controller.go index a1d3923bec8a..cb537bd4d190 100644 --- a/pkg/controller/machineset/controller.go +++ b/pkg/controller/machineset/controller.go @@ -150,6 +150,13 @@ func (r *ReconcileMachineSet) Reconcile(request reconcile.Request) (reconcile.Re } klog.V(4).Infof("Reconcile machineset %v", machineSet.Name) + + if errList := machineSet.Validate(); len(errList) > 0 { + err := fmt.Errorf("%q machineset validation failed: %v", machineSet.Name, errList.ToAggregate().Error()) + klog.Error(err) + return reconcile.Result{}, err + } + allMachines := &clusterv1alpha1.MachineList{} err = r.Client.List(context.Background(), client.InNamespace(machineSet.Namespace), allMachines) diff --git a/pkg/controller/machineset/machineset_controller_test.go b/pkg/controller/machineset/machineset_controller_test.go index 153a51e9aa11..87d94ab8503b 100644 --- a/pkg/controller/machineset/machineset_controller_test.go +++ b/pkg/controller/machineset/machineset_controller_test.go @@ -37,11 +37,18 @@ const timeout = time.Second * 5 func TestReconcile(t *testing.T) { replicas := int32(2) + labels := map[string]string{"foo": "bar"} instance := &clusterv1alpha1.MachineSet{ ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "default"}, Spec: clusterv1alpha1.MachineSetSpec{ Replicas: &replicas, + Selector: metav1.LabelSelector{ + MatchLabels: labels, + }, Template: clusterv1alpha1.MachineTemplateSpec{ + ObjectMeta: metav1.ObjectMeta{ + Labels: labels, + }, Spec: clusterv1alpha1.MachineSpec{ Versions: clusterv1alpha1.MachineVersionInfo{Kubelet: "1.10.3"}, },