Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support taint cluster node through clusterfile #1894

Merged
merged 1 commit into from
Dec 15, 2022

Conversation

Stevent-fei
Copy link
Collaborator

@Stevent-fei Stevent-fei commented Nov 28, 2022

Describe what this PR does / why we need it

  1. add taint to cluster type
  2. ClusterFile supports configuring node taint support taint cluster node through clusterfile #1889

Does this pull request fix one issue?

Describe how you did it

Describe how to verify it

Special notes for reviews

@codecov-commenter
Copy link

codecov-commenter commented Nov 28, 2022

Codecov Report

Base: 21.38% // Head: 21.56% // Increases project coverage by +0.18% 🎉

Coverage data is based on head (3a88984) compared to base (3897332).
Patch coverage: 35.29% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1894      +/-   ##
==========================================
+ Coverage   21.38%   21.56%   +0.18%     
==========================================
  Files          78       79       +1     
  Lines        7300     7401     +101     
==========================================
+ Hits         1561     1596      +35     
- Misses       5531     5591      +60     
- Partials      208      214       +6     
Impacted Files Coverage Δ
pkg/cluster-runtime/installer.go 0.00% <0.00%> (ø)
pkg/cluster-runtime/scale.go 0.00% <0.00%> (ø)
pkg/infradriver/ssh_infradriver.go 40.00% <35.29%> (-0.49%) ⬇️
pkg/infradriver/utils.go 61.22% <61.22%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Stevent-fei Stevent-fei force-pushed the support_add_node_taint branch from ebb6e79 to efb15a0 Compare November 28, 2022 03:56
@Stevent-fei Stevent-fei changed the title [WIP]ClusterFile supports configuring node taint ClusterFile supports configuring node taint Nov 28, 2022
@Stevent-fei Stevent-fei linked an issue Nov 28, 2022 that may be closed by this pull request
@Stevent-fei Stevent-fei changed the title ClusterFile supports configuring node taint Add Clusterfile Configure the taint function Nov 28, 2022
@Stevent-fei Stevent-fei force-pushed the support_add_node_taint branch from 72dc275 to db2822d Compare November 28, 2022 05:47
@@ -175,7 +175,9 @@ func createNewCluster(clusterImageName string, infraDriver infradriver.InfraDriv
if applyMode == common.ApplyModeLoadImage {
logrus.Infof("start to apply with mode(%s)", applyMode)

if err = distributor.DistributeRegistry(infraDriver.GetHostIPList()[0], infraDriver.GetClusterRootfsPath()); err != nil {
cluster := cf.GetCluster()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the difference between cf.GetCluster().GetMaster0IP() and infraDriver.GetHostIPListByRole(common.MASTER)[0]

@starnop
Copy link
Collaborator

starnop commented Nov 30, 2022

How about splitting this PR into three PRs, we should try to ensure that a PR only does one thing, which is convenient to be reviewed and merged quickly.

@Stevent-fei Stevent-fei force-pushed the support_add_node_taint branch from db2822d to 2fce24a Compare December 1, 2022 02:39
}

func newTaintStruct(key, value, effect string) v1.Taint {
return v1.Taint{Key: key, Value: value, Effect: v1.TaintEffect(effect)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need new struct Taint to do this

// FormatData key1=value1:NoSchedule;key1=value1:NoSchedule-;
//key1:NoSchedule;key1:NoSchedule-;
//key1=:NoSchedule-;key1=value1:NoSchedule
func (l *Taint) FormatData(ip net.IP, data string) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do FormatData in infra driver

}

// UpdateTaints return nil mean's needn't update taint
func (l *Taint) UpdateTaints(taints []v1.Taint, ip string) []v1.Taint {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update taints should be a class functions of installer.

@@ -188,6 +188,19 @@ func (i *Installer) Install() error {
return err
}

for _, ip := range all {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if the new joined node need to do some taint issues ? if so ,we also need to do it in join

}

func UpdateTaint(newTaint *Taint, ip net.IP) error {
k8sClient, err := k8s.NewK8sClient()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use runtime driver to do update

@Stevent-fei Stevent-fei changed the title Add Clusterfile Configure the taint function support taint cluster node through clusterfile Dec 2, 2022
@Stevent-fei Stevent-fei force-pushed the support_add_node_taint branch 2 times, most recently from e69bdf3 to f87dfe2 Compare December 2, 2022 10:58
@Stevent-fei Stevent-fei changed the title support taint cluster node through clusterfile [WIP]support taint cluster node through clusterfile Dec 3, 2022
@Stevent-fei Stevent-fei force-pushed the support_add_node_taint branch 3 times, most recently from d3ccb0b to d35a665 Compare December 3, 2022 10:18
@Stevent-fei Stevent-fei changed the title [WIP]support taint cluster node through clusterfile support taint cluster node through clusterfile Dec 3, 2022
@@ -23,6 +23,9 @@ import (
// InfraDriver treat the entire cluster as an operating system kernel,
// interface function here is the target system call.
type InfraDriver interface {
// GetHostTaint return host taint
GetHostTaint(host net.IP) []string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetHostTaints(host net.IP)[]Taint

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need the formatted data from raw sting list to taint struct.

// FormatData key1=value1:NoSchedule;key1=value1:NoSchedule-;
//key1:NoSchedule;key1:NoSchedule-;
//key1=:NoSchedule-;key1=value1:NoSchedule
func (t *Taint) FormatData(ip net.IP, data string) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FormatData should be a utils func , FormatData(data []string)([]taint,error)

return node, nil
}

func NewCreateTaints() *Taint {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need this method

}

// UpdateTaints return nil mean's needn't update taint
func (t *Taint) UpdateTaints(taints []k8sv1.Taint, ip string) []k8sv1.Taint {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UpdateTaints and UpdateNodeTaint should in installer struct.

@Stevent-fei Stevent-fei force-pushed the support_add_node_taint branch from 6adcb7c to e1e5f5f Compare December 5, 2022 10:24
@Stevent-fei
Copy link
Collaborator Author

image

@@ -57,6 +59,16 @@ func mergeList(hostEnv, globalEnv map[string]interface{}) map[string]interface{}
return hostEnv
}

func conversionTaints(Taints []string) []k8sv1.Taint {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convertTaints(raw []string) []k8sv1.Taint

@@ -57,6 +59,16 @@ func mergeList(hostEnv, globalEnv map[string]interface{}) map[string]interface{}
return hostEnv
}

func conversionTaints(Taints []string) []k8sv1.Taint {
for _, taint := range Taints {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for _, elem := range raw{}

@@ -57,6 +59,16 @@ func mergeList(hostEnv, globalEnv map[string]interface{}) map[string]interface{}
return hostEnv
}

func conversionTaints(Taints []string) []k8sv1.Taint {
for _, taint := range Taints {
data, err := FormatData(taint)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should return err if format failed.

@@ -57,6 +59,16 @@ func mergeList(hostEnv, globalEnv map[string]interface{}) map[string]interface{}
return hostEnv
}

func conversionTaints(Taints []string) []k8sv1.Taint {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need a []k8sv1.Taint type to return


for _, v := range items {
v = strings.TrimSpace(v)
if strings.HasPrefix(v, "#") || v == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need this line

if strings.HasPrefix(v, "#") || v == "" {
continue
}
if strings.Contains(v, EqualSymbol) && !strings.Contains(v, EqualSymbol+ColonSymbol) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use switch case to do it.

}

for _, node = range nodeList.Items {
for _, ip := range hosts {
Copy link
Member

@kakaZhou719 kakaZhou719 Dec 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug: hosts is a subset for nodelist ,so we need to find the target node by host ip to do taint action

if taints != nil {
node.Spec.Taints = taints
}
if err := driver.Update(context.TODO(), &node); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if taints != nil {do update node}

@Stevent-fei Stevent-fei force-pushed the support_add_node_taint branch 2 times, most recently from 1773a79 to 36bf87d Compare December 6, 2022 03:34

// FormatData process data in the specified format
//eg: key1=value1:NoSchedule;key1:NoSchedule;key1=value1:NoSchedule
func formatData(data string) (k8sv1.Taint, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need UT test for this func.


for _, ip := range hosts {
taints := i.infraDriver.GetHostTaints(ip)
if taints != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if len(taints)==0{continue }

if k8snode, ok = nodeTaint[ip.String()]; ok {
k8snode.Spec.Taints = taints
}
if err := driver.Update(context.TODO(), &k8snode); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug: should update node if node ip in nodeTaint. Otherwise , no need to do update.

@github-actions github-actions bot added the test label Dec 6, 2022
@Stevent-fei Stevent-fei force-pushed the support_add_node_taint branch 2 times, most recently from 28b4885 to 4ae01d0 Compare December 7, 2022 01:58
)

//key1=value1:NoSchedule
func TestFormatData(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test case too few.

value can be empty.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added more ut.

newNode := k8snode.DeepCopy()
newNode.Spec.Taints = taints
newNode.SetResourceVersion("")
if err := driver.Update(context.TODO(), newNode); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update should retry, if some other agent, like kubelet, update the node object at the same time, this update will fail.

@Stevent-fei Stevent-fei force-pushed the support_add_node_taint branch 4 times, most recently from ee3fb4c to 8971351 Compare December 9, 2022 09:33
@Stevent-fei Stevent-fei force-pushed the support_add_node_taint branch from 8971351 to 3206fd0 Compare December 15, 2022 09:18
Copy link
Collaborator

@VinceCui VinceCui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Stevent-fei Stevent-fei force-pushed the support_add_node_taint branch from 1ff03c0 to 3a88984 Compare December 15, 2022 09:24
@VinceCui VinceCui merged commit 9751ea8 into sealerio:main Dec 15, 2022
jsparter pushed a commit to jsparter/sealer that referenced this pull request Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support taint cluster node through clusterfile
5 participants