-
Notifications
You must be signed in to change notification settings - Fork 362
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
Conversation
Codecov ReportBase: 21.38% // Head: 21.56% // Increases project coverage by
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
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. |
ebb6e79
to
efb15a0
Compare
72dc275
to
db2822d
Compare
cmd/sealer/cmd/cluster/apply.go
Outdated
@@ -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() |
There was a problem hiding this comment.
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]
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. |
db2822d
to
2fce24a
Compare
pkg/cluster-runtime/taint.go
Outdated
} | ||
|
||
func newTaintStruct(key, value, effect string) v1.Taint { | ||
return v1.Taint{Key: key, Value: value, Effect: v1.TaintEffect(effect)} |
There was a problem hiding this comment.
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
pkg/cluster-runtime/taint.go
Outdated
// 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 { |
There was a problem hiding this comment.
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
pkg/cluster-runtime/taint.go
Outdated
} | ||
|
||
// UpdateTaints return nil mean's needn't update taint | ||
func (l *Taint) UpdateTaints(taints []v1.Taint, ip string) []v1.Taint { |
There was a problem hiding this comment.
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.
pkg/cluster-runtime/installer.go
Outdated
@@ -188,6 +188,19 @@ func (i *Installer) Install() error { | |||
return err | |||
} | |||
|
|||
for _, ip := range all { |
There was a problem hiding this comment.
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
pkg/cluster-runtime/taint.go
Outdated
} | ||
|
||
func UpdateTaint(newTaint *Taint, ip net.IP) error { | ||
k8sClient, err := k8s.NewK8sClient() |
There was a problem hiding this comment.
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
e69bdf3
to
f87dfe2
Compare
d3ccb0b
to
d35a665
Compare
pkg/infradriver/infradriver.go
Outdated
@@ -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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
pkg/infradriver/utils.go
Outdated
// 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 { |
There was a problem hiding this comment.
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)
pkg/infradriver/utils.go
Outdated
return node, nil | ||
} | ||
|
||
func NewCreateTaints() *Taint { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need this method
pkg/infradriver/utils.go
Outdated
} | ||
|
||
// UpdateTaints return nil mean's needn't update taint | ||
func (t *Taint) UpdateTaints(taints []k8sv1.Taint, ip string) []k8sv1.Taint { |
There was a problem hiding this comment.
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.
6adcb7c
to
e1e5f5f
Compare
pkg/infradriver/ssh_infradriver.go
Outdated
@@ -57,6 +59,16 @@ func mergeList(hostEnv, globalEnv map[string]interface{}) map[string]interface{} | |||
return hostEnv | |||
} | |||
|
|||
func conversionTaints(Taints []string) []k8sv1.Taint { |
There was a problem hiding this comment.
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
pkg/infradriver/ssh_infradriver.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for _, elem := range raw{}
pkg/infradriver/ssh_infradriver.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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.
pkg/infradriver/ssh_infradriver.go
Outdated
@@ -57,6 +59,16 @@ func mergeList(hostEnv, globalEnv map[string]interface{}) map[string]interface{} | |||
return hostEnv | |||
} | |||
|
|||
func conversionTaints(Taints []string) []k8sv1.Taint { |
There was a problem hiding this comment.
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
pkg/infradriver/utils.go
Outdated
|
||
for _, v := range items { | ||
v = strings.TrimSpace(v) | ||
if strings.HasPrefix(v, "#") || v == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need this line
pkg/infradriver/utils.go
Outdated
if strings.HasPrefix(v, "#") || v == "" { | ||
continue | ||
} | ||
if strings.Contains(v, EqualSymbol) && !strings.Contains(v, EqualSymbol+ColonSymbol) { |
There was a problem hiding this comment.
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.
pkg/cluster-runtime/installer.go
Outdated
} | ||
|
||
for _, node = range nodeList.Items { | ||
for _, ip := range hosts { |
There was a problem hiding this comment.
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
pkg/cluster-runtime/installer.go
Outdated
if taints != nil { | ||
node.Spec.Taints = taints | ||
} | ||
if err := driver.Update(context.TODO(), &node); err != nil { |
There was a problem hiding this comment.
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}
1773a79
to
36bf87d
Compare
|
||
// FormatData process data in the specified format | ||
//eg: key1=value1:NoSchedule;key1:NoSchedule;key1=value1:NoSchedule | ||
func formatData(data string) (k8sv1.Taint, error) { |
There was a problem hiding this comment.
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.
pkg/cluster-runtime/installer.go
Outdated
|
||
for _, ip := range hosts { | ||
taints := i.infraDriver.GetHostTaints(ip) | ||
if taints != nil { |
There was a problem hiding this comment.
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 }
pkg/cluster-runtime/installer.go
Outdated
if k8snode, ok = nodeTaint[ip.String()]; ok { | ||
k8snode.Spec.Taints = taints | ||
} | ||
if err := driver.Update(context.TODO(), &k8snode); err != nil { |
There was a problem hiding this comment.
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.
28b4885
to
4ae01d0
Compare
) | ||
|
||
//key1=value1:NoSchedule | ||
func TestFormatData(t *testing.T) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
pkg/cluster-runtime/installer.go
Outdated
newNode := k8snode.DeepCopy() | ||
newNode.Spec.Taints = taints | ||
newNode.SetResourceVersion("") | ||
if err := driver.Update(context.TODO(), newNode); err != nil { |
There was a problem hiding this comment.
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.
ee3fb4c
to
8971351
Compare
8971351
to
3206fd0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
1ff03c0
to
3a88984
Compare
Describe what this PR does / why we need it
Does this pull request fix one issue?
Describe how you did it
Describe how to verify it
Special notes for reviews