Skip to content

Commit

Permalink
Validate machineset before reconciling
Browse files Browse the repository at this point in the history
Even thought the MachineSet type implements Validate() function,
it's not called by default. The validation function is responsible
for making sure every machine set matchLabels selector is matched with
machine template labels. Given the validation is not performed by default,
it is possible to create an invalid machineset that causes the machineset
controller to start creating machine object one by one without any upper
bound. Causing the machine controller to launch as many instances as
there is machine objects.
  • Loading branch information
ingvagabund committed Jan 11, 2019
1 parent e90429a commit cb8be7b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
30 changes: 30 additions & 0 deletions 0001-Validate-machineset-before-reconciliation.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
From 3200e454110d91955ab849c75db5ee60085c8991 Mon Sep 17 00:00:00 2001
From: Jan Chaloupka <[email protected]>
Date: Fri, 11 Jan 2019 12:31:06 +0100
Subject: [PATCH] Validate machineset before reconciliation

---
.../cluster-api/pkg/controller/machineset/controller.go | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/vendor/sigs.k8s.io/cluster-api/pkg/controller/machineset/controller.go b/vendor/sigs.k8s.io/cluster-api/pkg/controller/machineset/controller.go
index a1d3923..cb537bd 100644
--- a/vendor/sigs.k8s.io/cluster-api/pkg/controller/machineset/controller.go
+++ b/vendor/sigs.k8s.io/cluster-api/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)
--
2.7.5

1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ vendor:
dep ensure -v
patch -p1 < 0001-Delete-annotated-machines-first-when-scaling-down.patch
patch -p1 < 0002-Sort-machines-before-syncing.patch
patch -p1 < 0001-Validate-machineset-before-reconciliation.patch

.PHONY: generate
generate:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cb8be7b

Please sign in to comment.