mirror of
https://github.com/rancher/rke.git
synced 2025-09-18 08:06:20 +00:00
Log RKE components to a specific location
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/rancher/rke/hosts"
|
||||
"github.com/rancher/rke/log"
|
||||
"github.com/rancher/types/apis/management.cattle.io/v3"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -27,12 +28,16 @@ const (
|
||||
EtcdContainerName = "etcd"
|
||||
NginxProxyContainerName = "nginx-proxy"
|
||||
SidekickContainerName = "service-sidekick"
|
||||
LogLinkContainerName = "rke-log-linker"
|
||||
LogCleanerContainerName = "rke-log-cleaner"
|
||||
|
||||
KubeAPIPort = 6443
|
||||
SchedulerPort = 10251
|
||||
KubeControllerPort = 10252
|
||||
KubeletPort = 10250
|
||||
KubeproxyPort = 10256
|
||||
|
||||
RKELogsPath = "/var/lib/rancher/rke/log"
|
||||
)
|
||||
|
||||
func runSidekick(ctx context.Context, host *hosts.Host, prsMap map[string]v3.PrivateRegistry, sidecarProcess v3.Process) error {
|
||||
@@ -88,3 +93,40 @@ func GetHealthCheckURL(useTLS bool, port int) string {
|
||||
}
|
||||
return fmt.Sprintf("%s%s:%d%s", HTTPProtoPrefix, HealthzAddress, port, HealthzEndpoint)
|
||||
}
|
||||
|
||||
func createLogLink(ctx context.Context, host *hosts.Host, containerName, plane, image string, prsMap map[string]v3.PrivateRegistry) error {
|
||||
logrus.Debugf("[%s] Creating log link for Container [%s] on host [%s]", plane, containerName, host.Address)
|
||||
containerInspect, err := docker.InspectContainer(ctx, host.DClient, host.Address, containerName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
containerID := containerInspect.ID
|
||||
containerLogPath := containerInspect.LogPath
|
||||
containerLogLink := fmt.Sprintf("%s/%s-%s.log", RKELogsPath, containerName, containerID)
|
||||
imageCfg := &container.Config{
|
||||
Image: image,
|
||||
Tty: true,
|
||||
Cmd: []string{
|
||||
"sh",
|
||||
"-c",
|
||||
fmt.Sprintf("mkdir -p %s ; ln -s %s %s", RKELogsPath, containerLogPath, containerLogLink),
|
||||
},
|
||||
}
|
||||
hostCfg := &container.HostConfig{
|
||||
Binds: []string{
|
||||
"/var/lib:/var/lib",
|
||||
},
|
||||
Privileged: true,
|
||||
}
|
||||
if err := docker.DoRemoveContainer(ctx, host.DClient, LogLinkContainerName, host.Address); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := docker.DoRunContainer(ctx, host.DClient, imageCfg, hostCfg, LogLinkContainerName, host.Address, plane, prsMap); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := docker.DoRemoveContainer(ctx, host.DClient, LogLinkContainerName, host.Address); err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Debugf("[%s] Successfully created log link for Container [%s] on host [%s]", plane, containerName, host.Address)
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user