Skip to content

Commit afb1ea4

Browse files
committed
kubeadm: do not set deprecated '--cgroup-driver' flag in kubeadm-flags.env, this value will be set in config.yaml
1 parent d3d870f commit afb1ea4

File tree

14 files changed

+44
-191
lines changed

14 files changed

+44
-191
lines changed

cmd/kubeadm/app/apis/kubeadm/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ type ComponentConfig interface {
444444
Unmarshal(docmap DocumentMap) error
445445

446446
// Default patches the component config with kubeadm preferred defaults
447-
Default(cfg *ClusterConfiguration, localAPIEndpoint *APIEndpoint)
447+
Default(cfg *ClusterConfiguration, localAPIEndpoint *APIEndpoint, nodeRegOpts *NodeRegistrationOptions)
448448
}
449449

450450
// ComponentConfigMap is a map between a group name (as in GVK group) and a ComponentConfig

cmd/kubeadm/app/componentconfigs/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ go_library(
3232
"//staging/src/k8s.io/kubelet/config/v1beta1:go_default_library",
3333
"//vendor/github.com/pkg/errors:go_default_library",
3434
"//vendor/k8s.io/klog:go_default_library",
35+
"//vendor/k8s.io/utils/exec:go_default_library",
3536
"//vendor/k8s.io/utils/pointer:go_default_library",
3637
],
3738
)

cmd/kubeadm/app/componentconfigs/configset.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,17 @@ func ensureInitializedComponentConfigs(clusterCfg *kubeadmapi.ClusterConfigurati
139139
}
140140

141141
// Default sets up defaulted component configs in the supplied ClusterConfiguration
142-
func Default(clusterCfg *kubeadmapi.ClusterConfiguration, localAPIEndpoint *kubeadmapi.APIEndpoint) {
142+
func Default(clusterCfg *kubeadmapi.ClusterConfiguration, localAPIEndpoint *kubeadmapi.APIEndpoint, nodeRegOpts *kubeadmapi.NodeRegistrationOptions) {
143143
ensureInitializedComponentConfigs(clusterCfg)
144144

145145
for _, handler := range known {
146146
// If the component config exists, simply default it. Otherwise, create it before defaulting.
147147
group := handler.GroupVersion.Group
148148
if componentCfg, ok := clusterCfg.ComponentConfigs[group]; ok {
149-
componentCfg.Default(clusterCfg, localAPIEndpoint)
149+
componentCfg.Default(clusterCfg, localAPIEndpoint, nodeRegOpts)
150150
} else {
151151
componentCfg := handler.CreateEmpty()
152-
componentCfg.Default(clusterCfg, localAPIEndpoint)
152+
componentCfg.Default(clusterCfg, localAPIEndpoint, nodeRegOpts)
153153
clusterCfg.ComponentConfigs[group] = componentCfg
154154
}
155155
}

cmd/kubeadm/app/componentconfigs/configset_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ import (
3535
func TestDefault(t *testing.T) {
3636
clusterCfg := &kubeadmapi.ClusterConfiguration{}
3737
localAPIEndpoint := &kubeadmapi.APIEndpoint{}
38+
nodeRegOps := &kubeadmapi.NodeRegistrationOptions{}
3839

39-
Default(clusterCfg, localAPIEndpoint)
40+
Default(clusterCfg, localAPIEndpoint, nodeRegOps)
4041

4142
if len(clusterCfg.ComponentConfigs) != len(known) {
4243
t.Errorf("missmatch between supported and defaulted type numbers:\n\tgot: %d\n\texpected: %d", len(clusterCfg.ComponentConfigs), len(known))

cmd/kubeadm/app/componentconfigs/kubelet.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@ import (
2424
"k8s.io/klog"
2525
kubeletconfig "k8s.io/kubelet/config/v1beta1"
2626
"k8s.io/kubernetes/cmd/kubeadm/app/util/initsystem"
27+
utilsexec "k8s.io/utils/exec"
2728
utilpointer "k8s.io/utils/pointer"
2829

2930
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
3031
kubeadmapiv1beta2 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta2"
3132
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
3233
"k8s.io/kubernetes/cmd/kubeadm/app/features"
34+
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
3335
)
3436

3537
const (
@@ -96,7 +98,7 @@ func (kc *kubeletConfig) Unmarshal(docmap kubeadmapi.DocumentMap) error {
9698
return kubeletHandler.Unmarshal(docmap, &kc.config)
9799
}
98100

99-
func (kc *kubeletConfig) Default(cfg *kubeadmapi.ClusterConfiguration, _ *kubeadmapi.APIEndpoint) {
101+
func (kc *kubeletConfig) Default(cfg *kubeadmapi.ClusterConfiguration, _ *kubeadmapi.APIEndpoint, nodeRegOpts *kubeadmapi.NodeRegistrationOptions) {
100102
const kind = "KubeletConfiguration"
101103

102104
if kc.config.FeatureGates == nil {
@@ -179,6 +181,21 @@ func (kc *kubeletConfig) Default(cfg *kubeadmapi.ClusterConfiguration, _ *kubead
179181
// There is no way to determine if the user has set this or not, given the field is a non-pointer.
180182
kc.config.RotateCertificates = kubeletRotateCertificates
181183

184+
// TODO: Conditionally set CgroupDriver to either `systemd` or `cgroupfs` for CRI other than Docker
185+
if nodeRegOpts.CRISocket == constants.DefaultDockerCRISocket {
186+
driver, err := kubeadmutil.GetCgroupDriverDocker(utilsexec.New())
187+
if err != nil {
188+
klog.Warningf("cannot automatically set CgroupDriver when starting the Kubelet: %v", err)
189+
} else {
190+
// if we can parse the right cgroup driver from docker info,
191+
// we should always override CgroupDriver here no matter user specifies this value explicitly or not
192+
if kc.config.CgroupDriver != "" && kc.config.CgroupDriver != driver {
193+
klog.Warningf("detected %q as the Docker cgroup driver, the provided value %q in %q will be overrided", driver, kc.config.CgroupDriver, kind)
194+
}
195+
kc.config.CgroupDriver = driver
196+
}
197+
}
198+
182199
ok, err := isServiceActive("systemd-resolved")
183200
if err != nil {
184201
klog.Warningf("cannot determine if systemd-resolved is active: %v", err)

cmd/kubeadm/app/componentconfigs/kubelet_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ func TestKubeletDefault(t *testing.T) {
323323
for _, test := range tests {
324324
t.Run(test.name, func(t *testing.T) {
325325
got := &kubeletConfig{}
326-
got.Default(&test.clusterCfg, &kubeadmapi.APIEndpoint{})
326+
got.Default(&test.clusterCfg, &kubeadmapi.APIEndpoint{}, &kubeadmapi.NodeRegistrationOptions{})
327327
if !reflect.DeepEqual(got, &test.expected) {
328328
t.Fatalf("Missmatch between expected and got:\nExpected:\n%v\n---\nGot:\n%v", test.expected, got)
329329
}

cmd/kubeadm/app/componentconfigs/kubeproxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func kubeProxyDefaultBindAddress(localAdvertiseAddress string) string {
7777
return kubeadmapiv1beta2.DefaultProxyBindAddressv6
7878
}
7979

80-
func (kp *kubeProxyConfig) Default(cfg *kubeadmapi.ClusterConfiguration, localAPIEndpoint *kubeadmapi.APIEndpoint) {
80+
func (kp *kubeProxyConfig) Default(cfg *kubeadmapi.ClusterConfiguration, localAPIEndpoint *kubeadmapi.APIEndpoint, _ *kubeadmapi.NodeRegistrationOptions) {
8181
const kind = "KubeProxyConfiguration"
8282

8383
// The below code is necessary because while KubeProxy may be defined, the user may not

cmd/kubeadm/app/componentconfigs/kubeproxy_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ func TestKubeProxyDefault(t *testing.T) {
297297
for _, test := range tests {
298298
t.Run(test.name, func(t *testing.T) {
299299
got := &kubeProxyConfig{}
300-
got.Default(&test.clusterCfg, &test.endpoint)
300+
got.Default(&test.clusterCfg, &test.endpoint, &kubeadmapi.NodeRegistrationOptions{})
301301
if !reflect.DeepEqual(got, &test.expected) {
302302
t.Fatalf("Missmatch between expected and got:\nExpected:\n%v\n---\nGot:\n%v", test.expected, got)
303303
}

cmd/kubeadm/app/phases/kubelet/BUILD

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ go_library(
66
"config.go",
77
"dynamic.go",
88
"flags.go",
9-
"flags_unix.go",
10-
"flags_windows.go",
119
"kubelet.go",
1210
],
1311
importpath = "k8s.io/kubernetes/cmd/kubeadm/app/phases/kubelet",
@@ -29,7 +27,6 @@ go_library(
2927
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
3028
"//vendor/github.com/pkg/errors:go_default_library",
3129
"//vendor/k8s.io/klog:go_default_library",
32-
"//vendor/k8s.io/utils/exec:go_default_library",
3330
],
3431
)
3532

@@ -52,8 +49,6 @@ go_test(
5249
"//staging/src/k8s.io/apimachinery/pkg/util/version:go_default_library",
5350
"//staging/src/k8s.io/client-go/kubernetes/fake:go_default_library",
5451
"//staging/src/k8s.io/client-go/testing:go_default_library",
55-
"//vendor/github.com/pkg/errors:go_default_library",
56-
"//vendor/k8s.io/utils/exec:go_default_library",
5752
],
5853
)
5954

cmd/kubeadm/app/phases/kubelet/flags.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,26 @@ package kubelet
1818

1919
import (
2020
"fmt"
21-
"github.com/pkg/errors"
2221
"io/ioutil"
22+
"os"
23+
"path/filepath"
24+
"strings"
25+
26+
"github.com/pkg/errors"
2327
"k8s.io/klog"
28+
2429
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
2530
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
2631
"k8s.io/kubernetes/cmd/kubeadm/app/features"
2732
"k8s.io/kubernetes/cmd/kubeadm/app/images"
2833
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
29-
utilsexec "k8s.io/utils/exec"
30-
"os"
31-
"path/filepath"
32-
"strings"
3334
)
3435

3536
type kubeletFlagsOpts struct {
3637
nodeRegOpts *kubeadmapi.NodeRegistrationOptions
3738
featureGates map[string]bool
3839
pauseImage string
3940
registerTaintsUsingFlags bool
40-
execer utilsexec.Interface
4141
}
4242

4343
// GetNodeNameAndHostname obtains the name for this Node using the following precedence
@@ -66,7 +66,6 @@ func WriteKubeletDynamicEnvFile(cfg *kubeadmapi.ClusterConfiguration, nodeReg *k
6666
featureGates: cfg.FeatureGates,
6767
pauseImage: images.GetPauseImage(cfg),
6868
registerTaintsUsingFlags: registerTaintsUsingFlags,
69-
execer: utilsexec.New(),
7069
}
7170
stringMap := buildKubeletArgMap(flagOpts)
7271
argList := kubeadmutil.BuildArgumentListFromMap(stringMap, nodeReg.KubeletExtraArgs)
@@ -133,3 +132,9 @@ func writeKubeletFlagBytesToDisk(b []byte, kubeletDir string) error {
133132
}
134133
return nil
135134
}
135+
136+
// buildKubeletArgMap takes a kubeletFlagsOpts object and builds based on that a string-string map with flags
137+
// that should be given to the local kubelet daemon.
138+
func buildKubeletArgMap(opts kubeletFlagsOpts) map[string]string {
139+
return buildKubeletArgMapCommon(opts)
140+
}

0 commit comments

Comments
 (0)