Merge pull request #65068 from ashleyschuett/fix/nodetaints

Automatic merge from submit-queue (batch tested with PRs 64796, 65068). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Fix kubeadm taints to not override existing node taints

**What this PR does / why we need it**:
If a node has existing taints they are being replaced with taints from the kubeadm config. 

An example of this is that the `uninitialized` taint that kubelet sets for external cloud provider is being removed, and replaces with the master taint if set, or removed leaving the nodes taints empty if `noTaintMaster=true` . 

```release-note
None
```
This commit is contained in:
Kubernetes Submit Queue 2018-06-15 14:42:10 -07:00 committed by GitHub
commit 9a4263de75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 4 deletions

View File

@ -43,8 +43,24 @@ func MarkMaster(client clientset.Interface, masterName string, taints []v1.Taint
})
}
func taintExists(taint v1.Taint, taints []v1.Taint) bool {
for _, t := range taints {
if t == taint {
return true
}
}
return false
}
func markMasterNode(n *v1.Node, taints []v1.Taint) {
n.ObjectMeta.Labels[constants.LabelNodeRoleMaster] = ""
// TODO: Append taints, don't override?
for _, nt := range n.Spec.Taints {
if !taintExists(nt, taints) {
taints = append(taints, nt)
}
}
n.Spec.Taints = taints
}

View File

@ -82,11 +82,28 @@ func TestMarkMaster(t *testing.T) {
"{}",
},
{
"nothing missing but taint unwanted",
"has taint and no new taints wanted",
kubeadmconstants.LabelNodeRoleMaster,
[]v1.Taint{kubeadmconstants.MasterTaint},
[]v1.Taint{
{
Key: "node.cloudprovider.kubernetes.io/uninitialized",
Effect: v1.TaintEffectNoSchedule,
},
},
nil,
"{\"spec\":{\"taints\":null}}",
"{}",
},
{
"has taint and should merge with wanted taint",
kubeadmconstants.LabelNodeRoleMaster,
[]v1.Taint{
{
Key: "node.cloudprovider.kubernetes.io/uninitialized",
Effect: v1.TaintEffectNoSchedule,
},
},
[]v1.Taint{kubeadmconstants.MasterTaint},
"{\"spec\":{\"taints\":[{\"effect\":\"NoSchedule\",\"key\":\"node-role.kubernetes.io/master\"},{\"effect\":\"NoSchedule\",\"key\":\"node.cloudprovider.kubernetes.io/uninitialized\"}]}}",
},
}