mirror of https://github.com/k3s-io/k3s
Merge pull request #42195 from Random-Liu/cri-support-non-json-logging
Automatic merge from submit-queue (batch tested with PRs 41931, 39821, 41841, 42197, 42195) Use `docker logs` directly if the docker logging driver is not `json-file` Fixes https://github.com/kubernetes/kubernetes/issues/41996. Post the PR first, I still need to manually test this, because we don't have test coverage for journald logging pluggin. @yujuhong @dchen1107 /cc @kubernetes/sig-node-pr-reviewspull/6/head
commit
fa0387c9fe
|
@ -18,6 +18,7 @@ package dockershim
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -416,3 +417,46 @@ func toAPIProtocol(protocol Protocol) v1.Protocol {
|
||||||
glog.Warningf("Unknown protocol %q: defaulting to TCP", protocol)
|
glog.Warningf("Unknown protocol %q: defaulting to TCP", protocol)
|
||||||
return v1.ProtocolTCP
|
return v1.ProtocolTCP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DockerLegacyService interface embeds some legacy methods for backward compatibility.
|
||||||
|
type DockerLegacyService interface {
|
||||||
|
// GetContainerLogs gets logs for a specific container.
|
||||||
|
GetContainerLogs(*v1.Pod, kubecontainer.ContainerID, *v1.PodLogOptions, io.Writer, io.Writer) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// dockerLegacyService implements the DockerLegacyService. We add this for non json-log driver
|
||||||
|
// support. (See #41996)
|
||||||
|
type dockerLegacyService struct {
|
||||||
|
client dockertools.DockerInterface
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDockerLegacyService(client dockertools.DockerInterface) DockerLegacyService {
|
||||||
|
return &dockerLegacyService{client: client}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetContainerLogs get container logs directly from docker daemon.
|
||||||
|
func (d *dockerLegacyService) GetContainerLogs(pod *v1.Pod, containerID kubecontainer.ContainerID, logOptions *v1.PodLogOptions, stdout, stderr io.Writer) error {
|
||||||
|
container, err := d.client.InspectContainer(containerID.ID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return dockertools.GetContainerLogs(d.client, pod, containerID, logOptions, stdout, stderr, container.Config.Tty)
|
||||||
|
}
|
||||||
|
|
||||||
|
// criSupportedLogDrivers are log drivers supported by native CRI integration.
|
||||||
|
var criSupportedLogDrivers = []string{"json-file"}
|
||||||
|
|
||||||
|
// IsCRISupportedLogDriver checks whether the logging driver used by docker is
|
||||||
|
// suppoted by native CRI integration.
|
||||||
|
func IsCRISupportedLogDriver(client dockertools.DockerInterface) (bool, error) {
|
||||||
|
info, err := client.Info()
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("failed to get docker info: %v", err)
|
||||||
|
}
|
||||||
|
for _, driver := range criSupportedLogDrivers {
|
||||||
|
if info.LoggingDriver == driver {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
|
@ -570,6 +570,15 @@ func NewMainKubelet(kubeCfg *componentconfig.KubeletConfiguration, kubeDeps *Kub
|
||||||
if err := server.Start(); err != nil {
|
if err := server.Start(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create dockerLegacyService when the logging driver is not supported.
|
||||||
|
supported, err := dockershim.IsCRISupportedLogDriver(klet.dockerClient)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !supported {
|
||||||
|
klet.dockerLegacyService = dockershim.NewDockerLegacyService(klet.dockerClient)
|
||||||
|
}
|
||||||
case "remote":
|
case "remote":
|
||||||
// No-op.
|
// No-op.
|
||||||
break
|
break
|
||||||
|
@ -1099,6 +1108,10 @@ type Kubelet struct {
|
||||||
|
|
||||||
// GPU Manager
|
// GPU Manager
|
||||||
gpuManager gpu.GPUManager
|
gpuManager gpu.GPUManager
|
||||||
|
|
||||||
|
// dockerLegacyService contains some legacy methods for backward compatibility.
|
||||||
|
// It should be set only when docker is using non json-file logging driver.
|
||||||
|
dockerLegacyService dockershim.DockerLegacyService
|
||||||
}
|
}
|
||||||
|
|
||||||
// setupDataDirs creates:
|
// setupDataDirs creates:
|
||||||
|
|
|
@ -1006,6 +1006,12 @@ func (kl *Kubelet) GetKubeletContainerLogs(podFullName, containerName string, lo
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if kl.dockerLegacyService != nil {
|
||||||
|
// dockerLegacyService should only be non-nil when we actually need it, so
|
||||||
|
// inject it into the runtimeService.
|
||||||
|
// TODO(random-liu): Remove this hack after deprecating unsupported log driver.
|
||||||
|
return kl.dockerLegacyService.GetContainerLogs(pod, containerID, logOptions, stdout, stderr)
|
||||||
|
}
|
||||||
return kl.containerRuntime.GetContainerLogs(pod, containerID, logOptions, stdout, stderr)
|
return kl.containerRuntime.GetContainerLogs(pod, containerID, logOptions, stdout, stderr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue