Skip to content
This repository was archived by the owner on Sep 30, 2020. It is now read-only.

Commit a8ee86e

Browse files
authored
Merge pull request #756 from mumoshu/disallow-controller-taint
Explicitly disallow tainting controller nodes
2 parents 8de905a + ae901ba commit a8ee86e

File tree

8 files changed

+38
-26
lines changed

8 files changed

+38
-26
lines changed

core/controlplane/config/config.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ func NewDefaultCluster() *Cluster {
8585
Enabled: false,
8686
},
8787
},
88-
89-
Taints: model.Taints{},
9088
Dex: model.Dex{
9189
Enabled: false,
9290
Url: "https://dex.example.com",
@@ -691,7 +689,6 @@ type Experimental struct {
691689
Dex model.Dex `yaml:"dex"`
692690
DisableSecurityGroupIngress bool `yaml:"disableSecurityGroupIngress"`
693691
NodeMonitorGracePeriod string `yaml:"nodeMonitorGracePeriod"`
694-
Taints model.Taints `yaml:"taints"`
695692
model.UnknownKeys `yaml:",inline"`
696693
}
697694

@@ -1479,10 +1476,6 @@ func (e EtcdSettings) Valid() error {
14791476
}
14801477

14811478
func (c Experimental) Valid() error {
1482-
if err := c.Taints.Valid(); err != nil {
1483-
return err
1484-
}
1485-
14861479
if err := c.NodeDrainer.Valid(); err != nil {
14871480
return err
14881481
}

core/controlplane/config/templates/cloud-config-worker

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ coreos:
257257
--rkt-stage1-image=coreos.com/rkt/stage1-coreos \
258258
{{if .NodeLabels.Enabled}}--node-labels {{.NodeLabels.String}} \
259259
{{end}}--register-node=true \
260-
{{if .Experimental.Taints}}--register-with-taints={{.Experimental.Taints.String}}\
260+
{{if .Taints}}--register-with-taints={{.Taints.String}}\
261261
{{end}}--allow-privileged=true \
262262
{{if .NodeStatusUpdateFrequency}}--node-status-update-frequency={{.NodeStatusUpdateFrequency}} \
263263
{{end}}--pod-manifest-path=/etc/kubernetes/manifests \

core/controlplane/config/templates/cluster.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,11 +1245,6 @@ addons:
12451245
# username: "admin"
12461246
# userID: "08a8684b-db88-4b73-90a9-3cd1661f5466"
12471247
#
1248-
# # Kubernetes node taints to be added to controller nodes
1249-
# taints:
1250-
# - key: dedicated
1251-
# value: search
1252-
# effect: NoSchedule
12531248
# plugins:
12541249
# rbac:
12551250
# enabled: true

core/nodepool/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,10 @@ func (c ProvidedConfig) valid() error {
332332
return err
333333
}
334334

335+
if err := c.NodeSettings.Validate(); err != nil {
336+
return err
337+
}
338+
335339
clusterNamePlaceholder := "<my-cluster-name>"
336340
nestedStackNamePlaceHolder := "<my-nested-stack-name>"
337341
replacer := strings.NewReplacer(clusterNamePlaceholder, "", nestedStackNamePlaceHolder, "")

core/root/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func ConfigFromBytes(data []byte) (*Config, error) {
9191
if np == nil {
9292
return nil, fmt.Errorf("Empty nodepool definition found at index %d", i)
9393
}
94-
if err := np.Experimental.Taints.Valid(); err != nil {
94+
if err := np.Taints.Valid(); err != nil {
9595
return nil, fmt.Errorf("invalid taints for node pool at index %d: %v", i, err)
9696
}
9797

model/controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func NewDefaultController() Controller {
3838
},
3939
NodeSettings: NodeSettings{
4040
NodeLabels: NodeLabels{},
41+
Taints: Taints{},
4142
},
4243
}
4344
}
@@ -80,6 +81,9 @@ func (c Controller) Validate() error {
8081
if err := c.IAMConfig.Validate(); err != nil {
8182
return err
8283
}
84+
if len(c.Taints) > 0 {
85+
return errors.New("`controller.taints` must not be specified because tainting controller nodes breaks the cluster")
86+
}
8387
return nil
8488
}
8589

model/node_settings.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,12 @@ package model
22

33
type NodeSettings struct {
44
NodeLabels NodeLabels `yaml:"nodeLabels"`
5+
Taints Taints `yaml:"taints"`
6+
}
7+
8+
func (s NodeSettings) Validate() error {
9+
if err := s.Taints.Valid(); err != nil {
10+
return err
11+
}
12+
return nil
513
}

test/integration/maincluster_test.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ func TestMainClusterConfig(t *testing.T) {
131131
Enabled: false,
132132
DrainTimeout: 5,
133133
},
134-
Taints: model.Taints{},
135134
}
136135

137136
actual := c.Experimental
@@ -1194,10 +1193,6 @@ experimental:
11941193
plugins:
11951194
rbac:
11961195
enabled: true
1197-
taints:
1198-
- key: reservation
1199-
value: spot
1200-
effect: NoSchedule
12011196
cloudWatchLogging:
12021197
enabled: true
12031198
worker:
@@ -1285,9 +1280,6 @@ worker:
12851280
Enabled: true,
12861281
},
12871282
},
1288-
Taints: model.Taints{
1289-
{Key: "reservation", Value: "spot", Effect: "NoSchedule"},
1290-
},
12911283
}
12921284

12931285
actual := c.Experimental
@@ -1398,9 +1390,6 @@ worker:
13981390
Enabled: false,
13991391
DrainTimeout: 0,
14001392
},
1401-
Taints: model.Taints{
1402-
{Key: "reservation", Value: "spot", Effect: "NoSchedule"},
1403-
},
14041393
}
14051394
p := c.NodePools[0]
14061395
if reflect.DeepEqual(expected, p.Experimental) {
@@ -1410,11 +1399,19 @@ worker:
14101399
expectedNodeLabels := model.NodeLabels{
14111400
"kube-aws.coreos.com/role": "worker",
14121401
}
1413-
14141402
actualNodeLabels := c.NodePools[0].NodeLabels
14151403
if !reflect.DeepEqual(expectedNodeLabels, actualNodeLabels) {
14161404
t.Errorf("worker node labels didn't match: expected=%v, actual=%v", expectedNodeLabels, actualNodeLabels)
14171405
}
1406+
1407+
expectedTaints := model.Taints{
1408+
{Key: "reservation", Value: "spot", Effect: "NoSchedule"},
1409+
}
1410+
actualTaints := c.NodePools[0].Taints
1411+
if !reflect.DeepEqual(expectedTaints, actualTaints) {
1412+
t.Errorf("worker node taints didn't match: expected=%v, actual=%v", expectedTaints, actualTaints)
1413+
}
1414+
14181415
},
14191416
},
14201417
},
@@ -3616,6 +3613,17 @@ controller:
36163613
configYaml: kubeAwsSettings.withClusterName("my.cluster").minimumValidClusterYaml(),
36173614
expectedErrorMessage: "clusterName(=my.cluster) is malformed. It must consist only of alphanumeric characters, colons, or hyphens",
36183615
},
3616+
{
3617+
context: "WithControllerTaint",
3618+
configYaml: minimalValidConfigYaml + `
3619+
controller:
3620+
taints:
3621+
- key: foo
3622+
value: bar
3623+
effect: NoSchedule
3624+
`,
3625+
expectedErrorMessage: "`controller.taints` must not be specified because tainting controller nodes breaks the cluster",
3626+
},
36193627
{
36203628
context: "WithElasticFileSystemIdInSpecificNodePoolWithManagedSubnets",
36213629
configYaml: mainClusterYaml + `

0 commit comments

Comments
 (0)