Skip to content

Commit

Permalink
Fix some bugs (#1795)
Browse files Browse the repository at this point in the history
* Fix:
1. support '|' for hook's scope
2. fix clean /var/lib/kubelet device busy bug.

Signed-off-by: huaiyou <[email protected]>

* Update annotations.

Signed-off-by: huaiyou <[email protected]>

Signed-off-by: huaiyou <[email protected]>
  • Loading branch information
VinceCui authored Oct 24, 2022
1 parent f05c753 commit 3f404f5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion pkg/cluster-runtime/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (i *Installer) runHostHook(phase Phase, hosts []net.IP) error {
sort.Sort(hookConfigList)
for _, hookConfig := range hookConfigList {
var targetHosts []net.IP
expectedHosts := i.infraDriver.GetHostIPListByRole(string(hookConfig.Scope))
expectedHosts := i.getHostIPListByScope(hookConfig.Scope)
// Make sure each host got from Scope is in the given host ip list.
for _, expected := range expectedHosts {
if netUtils.IsInIPList(expected, hosts) {
Expand Down Expand Up @@ -151,6 +151,24 @@ func (i *Installer) runClusterHook(master0 net.IP, phase Phase) error {
return nil
}

// getHostIPListByScope get ip list for scope, support use '|' to specify multiple scopes, they are ORed
func (i *Installer) getHostIPListByScope(scope Scope) []net.IP {
var ret []net.IP
scopes := strings.Split(string(scope), "|")
for _, s := range scopes {
hosts := i.infraDriver.GetHostIPListByRole(strings.TrimSpace(s))

// remove duplicates
for _, h := range hosts {
if !netUtils.IsInIPList(h, ret) {
ret = append(ret, h)
}
}
}

return ret
}

func NewShellHook() HookFunc {
return func(data string, hosts []net.IP, driver infradriver.InfraDriver) error {
rootfs := driver.GetClusterRootfsPath()
Expand Down
2 changes: 1 addition & 1 deletion pkg/runtime/kubernetes/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ rm -rf /etc/kubernetes/ && \
rm -rf /etc/systemd/system/kubelet.service.d && rm -rf /etc/systemd/system/kubelet.service && \
rm -rf /usr/bin/kubeadm && rm -rf /usr/bin/kubelet-pre-start.sh && \
rm -rf /usr/bin/kubelet && rm -rf /usr/bin/kubectl && \
rm -rf /var/lib/kubelet && rm -rf /etc/sysctl.d/k8s.conf && \
rm -rf /var/lib/kubelet/* && rm -rf /etc/sysctl.d/k8s.conf && \
rm -rf /etc/cni && rm -rf /opt/cni && \
rm -rf /var/lib/etcd && rm -rf /var/etcd
`
Expand Down

0 comments on commit 3f404f5

Please sign in to comment.