Skip to content

Commit

Permalink
feat: support taints for master and worker
Browse files Browse the repository at this point in the history
  • Loading branch information
QianChenglong committed Apr 13, 2020
1 parent 82b048a commit af5e105
Show file tree
Hide file tree
Showing 14 changed files with 559 additions and 446 deletions.
30 changes: 30 additions & 0 deletions api/openapi/zz_generated.openapi.go

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

3 changes: 3 additions & 0 deletions api/platform/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package platform

import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -63,6 +64,7 @@ type ClusterMachine struct {
PrivateKey []byte
PassPhrase []byte
Labels map[string]string
Taints []corev1.Taint
}

// ClusterSpec is a description of a cluster.
Expand Down Expand Up @@ -1286,6 +1288,7 @@ type MachineSpec struct {
PrivateKey []byte
PassPhrase []byte
Labels map[string]string
Taints []corev1.Taint
}

// MachineStatus represents information about the status of an machine.
Expand Down
735 changes: 429 additions & 306 deletions api/platform/v1/generated.pb.go

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions api/platform/v1/generated.proto

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

7 changes: 7 additions & 0 deletions api/platform/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package v1

import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -67,6 +68,9 @@ type ClusterMachine struct {
PassPhrase []byte `json:"passPhrase,omitempty" protobuf:"bytes,6,opt,name=passPhrase"`
// +optional
Labels map[string]string `json:"labels,omitempty" protobuf:"bytes,7,opt,name=labels"`
// If specified, the node's taints.
// +optional
Taints []corev1.Taint `json:"taints,omitempty" protobuf:"bytes,8,opt,name=taints"`
}

// ClusterSpec is a description of a cluster.
Expand Down Expand Up @@ -1298,6 +1302,9 @@ type MachineSpec struct {
PassPhrase []byte `json:"passPhrase,omitempty" protobuf:"bytes,10,opt,name=passPhrase"`
// +optional
Labels map[string]string `json:"labels,omitempty" protobuf:"bytes,11,opt,name=labels"`
// If specified, the node's taints.
// +optional
Taints []corev1.Taint `json:"taints,omitempty" protobuf:"bytes,12,opt,name=taints"`
}

// MachineStatus represents information about the status of an machine.
Expand Down
4 changes: 3 additions & 1 deletion api/platform/v1/types_swagger_doc_generated.go

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

5 changes: 5 additions & 0 deletions api/platform/v1/zz_generated.conversion.go

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

15 changes: 15 additions & 0 deletions api/platform/v1/zz_generated.deepcopy.go

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

15 changes: 15 additions & 0 deletions api/platform/zz_generated.deepcopy.go

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

31 changes: 17 additions & 14 deletions pkg/platform/provider/baremetal/cluster/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import (
"strings"
"time"

"tkestack.io/tke/pkg/util/template"
"github.com/thoas/go-funk"

"tkestack.io/tke/pkg/util/apiclient"

"github.com/pkg/errors"
"github.com/segmentio/ksuid"
Expand All @@ -48,11 +50,11 @@ import (
"tkestack.io/tke/pkg/platform/provider/baremetal/phases/kubeadm"
"tkestack.io/tke/pkg/platform/provider/baremetal/phases/kubeconfig"
"tkestack.io/tke/pkg/platform/provider/baremetal/phases/kubelet"
"tkestack.io/tke/pkg/platform/provider/baremetal/phases/markcontrolplane"
"tkestack.io/tke/pkg/platform/provider/baremetal/preflight"
"tkestack.io/tke/pkg/platform/provider/baremetal/util/hosts"
"tkestack.io/tke/pkg/util/log"
"tkestack.io/tke/pkg/util/ssh"
"tkestack.io/tke/pkg/util/template"
)

const (
Expand Down Expand Up @@ -662,20 +664,21 @@ func (p *Provider) EnsureMarkControlPlane(c *Cluster) error {
return err
}

option := &markcontrolplane.Option{}
if !c.Spec.Features.EnableMasterSchedule {
option.Taints = []corev1.Taint{
{
Key: "node-role.kubernetes.io/master",
for _, machine := range c.Spec.Machines {
if machine.Labels == nil {
machine.Labels = make(map[string]string)
machine.Labels[constants.LabelNodeRoleMaster] = ""
}
if !c.Spec.Features.EnableMasterSchedule {
taint := corev1.Taint{
Key: constants.LabelNodeRoleMaster,
Effect: corev1.TaintEffectNoSchedule,
},
}
if !funk.Contains(machine.Taints, taint) {
machine.Taints = append(machine.Taints, taint)
}
}
}

for _, machine := range c.Spec.Machines {
option.NodeName = machine.IP
option.Labels = machine.Labels
err := markcontrolplane.Install(clientset, option)
err := apiclient.MarkNode(clientset, machine.IP, machine.Labels, machine.Taints)
if err != nil {
return errors.Wrap(err, machine.IP)
}
Expand Down
13 changes: 3 additions & 10 deletions pkg/platform/provider/baremetal/machine/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"strings"
"time"

"tkestack.io/tke/pkg/util/apiclient"

platformv1 "tkestack.io/tke/api/platform/v1"

corev1 "k8s.io/api/core/v1"
Expand All @@ -38,7 +40,6 @@ import (
"tkestack.io/tke/pkg/platform/provider/baremetal/phases/kubeadm"
"tkestack.io/tke/pkg/platform/provider/baremetal/phases/kubeconfig"
"tkestack.io/tke/pkg/platform/provider/baremetal/phases/kubelet"
"tkestack.io/tke/pkg/platform/provider/baremetal/phases/marknode"
"tkestack.io/tke/pkg/platform/provider/baremetal/preflight"
"tkestack.io/tke/pkg/platform/provider/baremetal/util"
"tkestack.io/tke/pkg/platform/provider/baremetal/util/hosts"
Expand Down Expand Up @@ -294,15 +295,7 @@ func (p *Provider) EnsureJoinNode(m *Machine) error {
}

func (p *Provider) EnsureMarkNode(m *Machine) error {
if len(m.Spec.Labels) == 0 {
return nil
}

option := &marknode.Option{
NodeName: m.Spec.IP,
Labels: m.Spec.Labels,
}
err := marknode.Install(m.ClientSet, option)
err := apiclient.MarkNode(m.ClientSet, m.Spec.IP, m.Spec.Labels, m.Spec.Taints)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit af5e105

Please sign in to comment.