mirror of
https://github.com/rancher/rke.git
synced 2025-10-20 18:40:43 +00:00
Remove container dead log links on cluster remove
This commit is contained in:
committed by
Alena Prokharchyk
parent
1da390d846
commit
48faa8bf35
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/rancher/rke/docker"
|
||||
@@ -40,14 +41,16 @@ type Host struct {
|
||||
}
|
||||
|
||||
const (
|
||||
ToCleanEtcdDir = "/var/lib/etcd/"
|
||||
ToCleanSSLDir = "/etc/kubernetes/"
|
||||
ToCleanCNIConf = "/etc/cni/"
|
||||
ToCleanCNIBin = "/opt/cni/"
|
||||
ToCleanCNILib = "/var/lib/cni/"
|
||||
ToCleanCalicoRun = "/var/run/calico/"
|
||||
ToCleanTempCertPath = "/etc/kubernetes/.tmp/"
|
||||
CleanerContainerName = "kube-cleaner"
|
||||
ToCleanEtcdDir = "/var/lib/etcd/"
|
||||
ToCleanSSLDir = "/etc/kubernetes/"
|
||||
ToCleanCNIConf = "/etc/cni/"
|
||||
ToCleanCNIBin = "/opt/cni/"
|
||||
ToCleanCNILib = "/var/lib/cni/"
|
||||
ToCleanCalicoRun = "/var/run/calico/"
|
||||
ToCleanTempCertPath = "/etc/kubernetes/.tmp/"
|
||||
CleanerContainerName = "kube-cleaner"
|
||||
LogCleanerContainerName = "rke-log-cleaner"
|
||||
RKELogsPath = "/var/lib/rancher/rke/log"
|
||||
|
||||
B2DOS = "Boot2Docker"
|
||||
B2DPrefixPath = "/mnt/sda1/rke"
|
||||
@@ -134,6 +137,10 @@ func (h *Host) CleanUp(ctx context.Context, toCleanPaths []string, cleanerImage
|
||||
if err := docker.RemoveContainer(ctx, h.DClient, h.Address, CleanerContainerName); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infof(ctx, "[hosts] Removing dead container logs on host [%s]", h.Address)
|
||||
if err := DoRunLogCleaner(ctx, h, cleanerImage, prsMap); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infof(ctx, "[hosts] Successfully cleaned up host [%s]", h.Address)
|
||||
return nil
|
||||
}
|
||||
@@ -308,3 +315,33 @@ func GetPrefixPath(osType, ClusterPrefixPath string) string {
|
||||
}
|
||||
return prefixPath
|
||||
}
|
||||
|
||||
func DoRunLogCleaner(ctx context.Context, host *Host, alpineImage string, prsMap map[string]v3.PrivateRegistry) error {
|
||||
logrus.Debugf("[cleanup] Starting log link cleanup on host [%s]", host.Address)
|
||||
imageCfg := &container.Config{
|
||||
Image: alpineImage,
|
||||
Tty: true,
|
||||
Cmd: []string{
|
||||
"sh",
|
||||
"-c",
|
||||
fmt.Sprintf("find %s -type l ! -exec test -e {} \\; -print -delete", RKELogsPath),
|
||||
},
|
||||
}
|
||||
hostCfg := &container.HostConfig{
|
||||
Binds: []string{
|
||||
"/var/lib:/var/lib",
|
||||
},
|
||||
Privileged: true,
|
||||
}
|
||||
if err := docker.DoRemoveContainer(ctx, host.DClient, LogCleanerContainerName, host.Address); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := docker.DoRunContainer(ctx, host.DClient, imageCfg, hostCfg, LogCleanerContainerName, host.Address, "cleanup", prsMap); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := docker.DoRemoveContainer(ctx, host.DClient, LogCleanerContainerName, host.Address); err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Debugf("[cleanup] Successfully cleaned up log links on host [%s]", host.Address)
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user