Merge pull request #54405 from resouer/clean-docker-dep
Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. [Part 1] Remove docker dep in kubelet startup **What this PR does / why we need it**: Remove dependency of docker during kubelet start up. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: Part 1 of #54090 **Special notes for your reviewer**: Changes include: 1. Move docker client initialization into dockershim pkg. 2. Pass a docker `ClientConfig` from kubelet to dockershim 3. Pass parameters needed by `FakeDockerClient` thru `ClientConfig` to dockershim (TODO, the second part) Make dockershim tolerate when dockerd is down, otherwise it will still fail kubelet Please note after this PR, kubelet will still fail if dockerd is down, this will be fixed in the subsequent PR by making dockershim tolerate dockerd failure (initializing docker client in a separate goroutine), and refactoring cgroup and log driver detection. **Release note**: ```release-note Remove docker dependency during kubelet start up ```
This commit is contained in:
@@ -148,9 +148,41 @@ type dockerNetworkHost struct {
|
||||
|
||||
var internalLabelKeys []string = []string{containerTypeLabelKey, containerLogPathLabelKey, sandboxIDLabelKey}
|
||||
|
||||
// ClientConfig is parameters used to initialize docker client
|
||||
type ClientConfig struct {
|
||||
DockerEndpoint string
|
||||
RuntimeRequestTimeout time.Duration
|
||||
ImagePullProgressDeadline time.Duration
|
||||
|
||||
// Configuration for fake docker client
|
||||
EnableSleep bool
|
||||
WithTraceDisabled bool
|
||||
}
|
||||
|
||||
// NewDockerClientFromConfig create a docker client from given configure
|
||||
// return nil if nil configure is given.
|
||||
func NewDockerClientFromConfig(config *ClientConfig) libdocker.Interface {
|
||||
if config != nil {
|
||||
// Create docker client.
|
||||
client := libdocker.ConnectToDockerOrDie(
|
||||
config.DockerEndpoint,
|
||||
config.RuntimeRequestTimeout,
|
||||
config.ImagePullProgressDeadline,
|
||||
config.WithTraceDisabled,
|
||||
config.EnableSleep,
|
||||
)
|
||||
return client
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NOTE: Anything passed to DockerService should be eventually handled in another way when we switch to running the shim as a different process.
|
||||
func NewDockerService(client libdocker.Interface, podSandboxImage string, streamingConfig *streaming.Config,
|
||||
func NewDockerService(config *ClientConfig, podSandboxImage string, streamingConfig *streaming.Config,
|
||||
pluginSettings *NetworkPluginSettings, cgroupsName string, kubeCgroupDriver string, dockershimRootDir string, disableSharedPID bool) (DockerService, error) {
|
||||
|
||||
client := NewDockerClientFromConfig(config)
|
||||
|
||||
c := libdocker.NewInstrumentedInterface(client)
|
||||
checkpointHandler, err := NewPersistentCheckpointHandler(dockershimRootDir)
|
||||
if err != nil {
|
||||
@@ -238,6 +270,15 @@ type DockerService interface {
|
||||
Start() error
|
||||
// For serving streaming calls.
|
||||
http.Handler
|
||||
|
||||
// IsCRISupportedLogDriver checks whether the logging driver used by docker is
|
||||
// suppoted by native CRI integration.
|
||||
// TODO(resouer): remove this when deprecating unsupported log driver
|
||||
IsCRISupportedLogDriver() (bool, error)
|
||||
|
||||
// NewDockerLegacyService created docker legacy service when log driver is not supported.
|
||||
// TODO(resouer): remove this when deprecating unsupported log driver
|
||||
NewDockerLegacyService() DockerLegacyService
|
||||
}
|
||||
|
||||
type dockerService struct {
|
||||
@@ -480,8 +521,10 @@ type dockerLegacyService struct {
|
||||
client libdocker.Interface
|
||||
}
|
||||
|
||||
func NewDockerLegacyService(client libdocker.Interface) DockerLegacyService {
|
||||
return &dockerLegacyService{client: client}
|
||||
// NewDockerLegacyService created docker legacy service when log driver is not supported.
|
||||
// TODO(resouer): remove this when deprecating unsupported log driver
|
||||
func (d *dockerService) NewDockerLegacyService() DockerLegacyService {
|
||||
return &dockerLegacyService{client: d.client}
|
||||
}
|
||||
|
||||
// GetContainerLogs get container logs directly from docker daemon.
|
||||
@@ -553,8 +596,8 @@ var criSupportedLogDrivers = []string{"json-file"}
|
||||
|
||||
// IsCRISupportedLogDriver checks whether the logging driver used by docker is
|
||||
// suppoted by native CRI integration.
|
||||
func IsCRISupportedLogDriver(client libdocker.Interface) (bool, error) {
|
||||
info, err := client.Info()
|
||||
func (d *dockerService) IsCRISupportedLogDriver() (bool, error) {
|
||||
info, err := d.client.Info()
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to get docker info: %v", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user