-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
use channel to manage goroutine when upgrade nodes #588
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ func (s *SealosInstaller) SendPackage() { | |
// rm old sealos in package avoid old version problem. if sealos not exist in package then skip rm | ||
kubeHook := fmt.Sprintf("cd /root && rm -rf kube && tar zxvf %s && cd /root/kube/shell && rm -f ../bin/sealos && bash init.sh", pkg) | ||
deletekubectl := `sed -i '/kubectl/d;/sealos/d' /root/.bashrc ` | ||
completion := "echo 'command -v kubectl &>/dev/null && source <(kubectl completion bash)' >> /root/.bashrc && echo 'command -v sealos &>/dev/null && source <(sealos completion bash)' >> /root/.bashrc && source /root/.bashrc" | ||
completion := "echo 'command -v kubectl &>/dev/null && source <(kubectl completion bash)' >> /root/.bashrc && echo '[ -x /usr/bin/sealos ] && source <(sealos completion bash)' >> /root/.bashrc && source /root/.bashrc" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 避免 permission deny 的问题。 如果 不能执行 sealos 就不需要执行 补全。 |
||
kubeHook = kubeHook + " && " + deletekubectl + " && " + completion | ||
PkgUrl = SendPackage(PkgUrl, s.Hosts, "/root", nil, &kubeHook) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package install | ||
|
||
import "sync" | ||
|
||
|
||
type uPool struct { | ||
queue chan int | ||
wg *sync.WaitGroup | ||
} | ||
|
||
func NewPool (size int) *uPool { | ||
if size <= 1 { | ||
size = 1 | ||
} | ||
return &uPool{ | ||
queue: make(chan int, size), | ||
wg: &sync.WaitGroup{}, | ||
} | ||
} | ||
|
||
func (p *uPool) Add(delta int) { | ||
for i := 0; i < delta; i++ { | ||
p.queue <- 1 | ||
} | ||
for i := 0; i > delta; i-- { | ||
<-p.queue | ||
} | ||
p.wg.Add(delta) | ||
} | ||
|
||
func (p *uPool) Done() { | ||
<-p.queue | ||
p.wg.Done() | ||
} | ||
|
||
func (p *uPool) Wait() { | ||
p.wg.Wait() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,10 @@ package install | |
import ( | ||
"fmt" | ||
"reflect" | ||
"runtime" | ||
"strings" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestPath(t *testing.T) { | ||
|
@@ -228,4 +230,19 @@ func TestFor120(t *testing.T) { | |
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_Example(t *testing.T) { | ||
pool := NewPool(2) | ||
println(runtime.NumGoroutine()) | ||
for i := 0; i < 10; i++ { | ||
pool.Add(1) | ||
go func(n int) { | ||
time.Sleep(time.Second) | ||
println(runtime.NumGoroutine(), n) | ||
pool.Done() | ||
}(i) | ||
} | ||
pool.Wait() | ||
println(runtime.NumGoroutine()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,7 @@ func CordonUnCordon(k8sClient *kubernetes.Clientset, nodeName string, cordoned b | |
return err | ||
} | ||
if node.Spec.Unschedulable == cordoned { | ||
logger.Alert("Node %s is already cordoned: %v", nodeName, cordoned) | ||
logger.Info("Node %s is already Uncordoned, skip...", nodeName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 如果已经是 |
||
return nil | ||
} | ||
node.Spec.Unschedulable = cordoned | ||
|
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.
如果是最后一行, 就直接break了。 所以把判断是否存在放在前面。