-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
docker.go
89 lines (70 loc) · 2.72 KB
/
docker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package components
import (
"k8s.io/kops/pkg/apis/kops"
"k8s.io/kops/upup/pkg/fi"
"k8s.io/kops/upup/pkg/fi/loader"
)
// DockerOptionsBuilder adds options for docker to the model
type DockerOptionsBuilder struct {
*OptionsContext
}
var _ loader.OptionsBuilder = &DockerOptionsBuilder{}
// BuildOptions is responsible for filling in the default setting for docker daemon
func (b *DockerOptionsBuilder) BuildOptions(o interface{}) error {
clusterSpec := o.(*kops.ClusterSpec)
if clusterSpec.Docker == nil {
clusterSpec.Docker = &kops.DockerConfig{}
}
docker := clusterSpec.Docker
// Container runtime is not Docker, should not install
if clusterSpec.ContainerRuntime != "docker" {
docker.SkipInstall = true
return nil
}
// Set the Docker version for known Kubernetes versions
if fi.ValueOf(clusterSpec.Docker.Version) == "" {
docker.Version = fi.PtrTo("20.10.17")
}
if len(clusterSpec.Docker.LogOpt) == 0 && clusterSpec.Docker.LogDriver == nil {
// Use built-in docker logging, if not configured otherwise (by the user)
logDriver := "json-file"
clusterSpec.Docker.LogDriver = &logDriver
clusterSpec.Docker.LogOpt = append(clusterSpec.Docker.LogOpt, "max-size=10m")
clusterSpec.Docker.LogOpt = append(clusterSpec.Docker.LogOpt, "max-file=5")
}
docker.LogLevel = fi.PtrTo("info")
docker.IPTables = fi.PtrTo(false)
docker.IPMasq = fi.PtrTo(false)
// Note the alternative syntax... with a comma nodeup will try each of the filesystems in turn
// TODO(justinsb): The ContainerOS image now has docker configured to use overlay2 out-of-the-box
// and it is an error to specify the flag twice.
docker.Storage = fi.PtrTo("overlay2,overlay,aufs")
// Set systemd as the default cgroup driver in docker from k8s 1.20.
if getDockerCgroupDriver(docker.ExecOpt) == "" {
docker.ExecOpt = append(docker.ExecOpt, "native.cgroupdriver=systemd")
}
return nil
}
// checks if cgroup-driver is configured or not for docker or not.
func getDockerCgroupDriver(execOpts []string) string {
for _, value := range execOpts {
if value == "native.cgroupdriver=systemd" {
return "systemd"
} else if value == "native.cgroupdriver=cgroupfs" {
return "cgroupfs"
}
}
return ""
}