diff --git a/cmd/kubeadm/app/constants/constants.go b/cmd/kubeadm/app/constants/constants.go index 44f6b64d6e9..16fc98ff052 100644 --- a/cmd/kubeadm/app/constants/constants.go +++ b/cmd/kubeadm/app/constants/constants.go @@ -265,9 +265,6 @@ const ( // DefaultEtcdVersion indicates the default etcd version that kubeadm uses DefaultEtcdVersion = "3.4.3-0" - // PauseVersion indicates the default pause image version for kubeadm - PauseVersion = "3.2" - // Etcd defines variable used internally when referring to etcd component Etcd = "etcd" // KubeAPIServer defines variable used internally when referring to kube-apiserver component diff --git a/cmd/kubeadm/app/constants/constants_unix.go b/cmd/kubeadm/app/constants/constants_unix.go index 16ff72d5556..b024348c29a 100644 --- a/cmd/kubeadm/app/constants/constants_unix.go +++ b/cmd/kubeadm/app/constants/constants_unix.go @@ -21,4 +21,7 @@ package constants const ( // DefaultDockerCRISocket defines the default Docker CRI socket DefaultDockerCRISocket = "/var/run/dockershim.sock" + + // PauseVersion indicates the default pause image version for kubeadm + PauseVersion = "3.2" ) diff --git a/cmd/kubeadm/app/constants/constants_windows.go b/cmd/kubeadm/app/constants/constants_windows.go index 6daae0a1fff..8c3727e97cd 100644 --- a/cmd/kubeadm/app/constants/constants_windows.go +++ b/cmd/kubeadm/app/constants/constants_windows.go @@ -21,4 +21,7 @@ package constants const ( // DefaultDockerCRISocket defines the default Docker CRI socket DefaultDockerCRISocket = "npipe:////./pipe/docker_engine" + + // PauseVersion indicates the default pause image version for kubeadm + PauseVersion = "1.3.0" ) diff --git a/cmd/kubeadm/app/images/BUILD b/cmd/kubeadm/app/images/BUILD index c66a9c039ec..3db25d644f4 100644 --- a/cmd/kubeadm/app/images/BUILD +++ b/cmd/kubeadm/app/images/BUILD @@ -8,14 +8,23 @@ load( go_library( name = "go_default_library", - srcs = ["images.go"], + srcs = [ + "images.go", + "images_unix.go", + "images_windows.go", + ], importpath = "k8s.io/kubernetes/cmd/kubeadm/app/images", deps = [ "//cmd/kubeadm/app/apis/kubeadm:go_default_library", "//cmd/kubeadm/app/constants:go_default_library", "//cmd/kubeadm/app/util:go_default_library", "//vendor/k8s.io/klog:go_default_library", - ], + ] + select({ + "@io_bazel_rules_go//go/platform:windows": [ + "//cmd/kubeadm/app/apis/kubeadm/v1beta2:go_default_library", + ], + "//conditions:default": [], + }), ) go_test( diff --git a/cmd/kubeadm/app/images/images.go b/cmd/kubeadm/app/images/images.go index 61cca5f34ad..6e3e30b355c 100644 --- a/cmd/kubeadm/app/images/images.go +++ b/cmd/kubeadm/app/images/images.go @@ -84,11 +84,6 @@ func GetEtcdImage(cfg *kubeadmapi.ClusterConfiguration) string { return GetGenericImage(etcdImageRepository, constants.Etcd, etcdImageTag) } -// GetPauseImage returns the image for the "pause" container -func GetPauseImage(cfg *kubeadmapi.ClusterConfiguration) string { - return GetGenericImage(cfg.ImageRepository, "pause", constants.PauseVersion) -} - // GetControlPlaneImages returns a list of container images kubeadm expects to use on a control plane node func GetControlPlaneImages(cfg *kubeadmapi.ClusterConfiguration) []string { imgs := []string{} diff --git a/cmd/kubeadm/app/images/images_unix.go b/cmd/kubeadm/app/images/images_unix.go new file mode 100644 index 00000000000..43fa63e88cf --- /dev/null +++ b/cmd/kubeadm/app/images/images_unix.go @@ -0,0 +1,29 @@ +// +build !windows + +/* +Copyright 2020 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 images + +import ( + kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm" + "k8s.io/kubernetes/cmd/kubeadm/app/constants" +) + +// GetPauseImage returns the image for the "pause" container +func GetPauseImage(cfg *kubeadmapi.ClusterConfiguration) string { + return GetGenericImage(cfg.ImageRepository, "pause", constants.PauseVersion) +} diff --git a/cmd/kubeadm/app/images/images_windows.go b/cmd/kubeadm/app/images/images_windows.go new file mode 100644 index 00000000000..f3c084a9483 --- /dev/null +++ b/cmd/kubeadm/app/images/images_windows.go @@ -0,0 +1,34 @@ +// +build windows + +/* +Copyright 2020 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 images + +import ( + kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm" + kubeadmapiv1beta2 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta2" + "k8s.io/kubernetes/cmd/kubeadm/app/constants" +) + +// GetPauseImage returns the image for the "pause" container +func GetPauseImage(cfg *kubeadmapi.ClusterConfiguration) string { + //If user has configured the cluster to use a different image repository, use that for the Windows pause image. + if cfg.ImageRepository != kubeadmapiv1beta2.DefaultImageRepository { + return GetGenericImage(cfg.ImageRepository, "pause", constants.PauseVersion) + } + return GetGenericImage("mcr.microsoft.com/oss/kubernetes", "pause", constants.PauseVersion) +} diff --git a/cmd/kubeadm/app/phases/kubelet/BUILD b/cmd/kubeadm/app/phases/kubelet/BUILD index dd6d78090d2..44d9b8cf8da 100644 --- a/cmd/kubeadm/app/phases/kubelet/BUILD +++ b/cmd/kubeadm/app/phases/kubelet/BUILD @@ -6,6 +6,8 @@ go_library( "config.go", "dynamic.go", "flags.go", + "flags_unix.go", + "flags_windows.go", "kubelet.go", ], importpath = "k8s.io/kubernetes/cmd/kubeadm/app/phases/kubelet", diff --git a/cmd/kubeadm/app/phases/kubelet/flags.go b/cmd/kubeadm/app/phases/kubelet/flags.go index 0c370efe2ae..047304dbe52 100644 --- a/cmd/kubeadm/app/phases/kubelet/flags.go +++ b/cmd/kubeadm/app/phases/kubelet/flags.go @@ -18,12 +18,8 @@ package kubelet import ( "fmt" - "io/ioutil" - "os" - "path/filepath" - "strings" - "github.com/pkg/errors" + "io/ioutil" "k8s.io/klog" kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm" "k8s.io/kubernetes/cmd/kubeadm/app/constants" @@ -32,6 +28,9 @@ import ( kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util" "k8s.io/kubernetes/cmd/kubeadm/app/util/initsystem" utilsexec "k8s.io/utils/exec" + "os" + "path/filepath" + "strings" ) type kubeletFlagsOpts struct { @@ -85,20 +84,14 @@ func WriteKubeletDynamicEnvFile(cfg *kubeadmapi.ClusterConfiguration, nodeReg *k return writeKubeletFlagBytesToDisk([]byte(envFileContent), kubeletDir) } -// buildKubeletArgMap takes a kubeletFlagsOpts object and builds based on that a string-string map with flags -// that should be given to the local kubelet daemon. -func buildKubeletArgMap(opts kubeletFlagsOpts) map[string]string { +//buildKubeletArgMapCommon takes a kubeletFlagsOpts object and builds based on that a string-string map with flags +//that are common to both Linux and Windows +func buildKubeletArgMapCommon(opts kubeletFlagsOpts) map[string]string { kubeletFlags := map[string]string{} if opts.nodeRegOpts.CRISocket == constants.DefaultDockerCRISocket { // These flags should only be set when running docker kubeletFlags["network-plugin"] = "cni" - driver, err := kubeadmutil.GetCgroupDriverDocker(opts.execer) - if err != nil { - klog.Warningf("cannot automatically assign a '--cgroup-driver' value when starting the Kubelet: %v\n", err) - } else { - kubeletFlags["cgroup-driver"] = driver - } if opts.pauseImage != "" { kubeletFlags["pod-infra-container-image"] = opts.pauseImage } @@ -116,14 +109,6 @@ func buildKubeletArgMap(opts kubeletFlagsOpts) map[string]string { kubeletFlags["register-with-taints"] = strings.Join(taintStrs, ",") } - ok, err := opts.isServiceActiveFunc("systemd-resolved") - if err != nil { - klog.Warningf("cannot determine if systemd-resolved is active: %v\n", err) - } - if ok { - kubeletFlags["resolv-conf"] = "/run/systemd/resolve/resolv.conf" - } - // Pass the "--hostname-override" flag to the kubelet only if it's different from the hostname nodeName, hostname, err := GetNodeNameAndHostname(opts.nodeRegOpts) if err != nil { @@ -134,8 +119,6 @@ func buildKubeletArgMap(opts kubeletFlagsOpts) map[string]string { kubeletFlags["hostname-override"] = nodeName } - // TODO: Conditionally set `--cgroup-driver` to either `systemd` or `cgroupfs` for CRI other than Docker - // TODO: The following code should be removed after dual-stack is GA. // Note: The user still retains the ability to explicitly set feature-gates and that value will overwrite this base value. if enabled, present := opts.featureGates[features.IPv6DualStack]; present { diff --git a/cmd/kubeadm/app/phases/kubelet/flags_unix.go b/cmd/kubeadm/app/phases/kubelet/flags_unix.go new file mode 100644 index 00000000000..c514832a1b1 --- /dev/null +++ b/cmd/kubeadm/app/phases/kubelet/flags_unix.go @@ -0,0 +1,51 @@ +// +build !windows + +/* +Copyright 2020 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 kubelet + +import ( + "k8s.io/klog" + "k8s.io/kubernetes/cmd/kubeadm/app/constants" + kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util" +) + +// buildKubeletArgMap takes a kubeletFlagsOpts object and builds based on that a string-string map with flags +// that should be given to the local Linux kubelet daemon. +func buildKubeletArgMap(opts kubeletFlagsOpts) map[string]string { + kubeletFlags := buildKubeletArgMapCommon(opts) + + // TODO: Conditionally set `--cgroup-driver` to either `systemd` or `cgroupfs` for CRI other than Docker + if opts.nodeRegOpts.CRISocket == constants.DefaultDockerCRISocket { + driver, err := kubeadmutil.GetCgroupDriverDocker(opts.execer) + if err != nil { + klog.Warningf("cannot automatically assign a '--cgroup-driver' value when starting the Kubelet: %v\n", err) + } else { + kubeletFlags["cgroup-driver"] = driver + } + } + + ok, err := opts.isServiceActiveFunc("systemd-resolved") + if err != nil { + klog.Warningf("cannot determine if systemd-resolved is active: %v\n", err) + } + if ok { + kubeletFlags["resolv-conf"] = "/run/systemd/resolve/resolv.conf" + } + + return kubeletFlags +} diff --git a/cmd/kubeadm/app/phases/kubelet/flags_windows.go b/cmd/kubeadm/app/phases/kubelet/flags_windows.go new file mode 100644 index 00000000000..5300224cecc --- /dev/null +++ b/cmd/kubeadm/app/phases/kubelet/flags_windows.go @@ -0,0 +1,25 @@ +// +build windows + +/* +Copyright 2020 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 kubelet + +// buildKubeletArgMap takes a kubeletFlagsOpts object and builds based on that a string-string map with flags +// that should be given to the local Windows kubelet daemon. +func buildKubeletArgMap(opts kubeletFlagsOpts) map[string]string { + return buildKubeletArgMapCommon(opts) +}