Skip to content

Commit

Permalink
Merge pull request #88287 from gab-satchi/master
Browse files Browse the repository at this point in the history
Windows specific kubelet flags in kubeadm-flags.env
  • Loading branch information
k8s-ci-robot authored Mar 4, 2020
2 parents e4e3d72 + 9fabafd commit 5c5faed
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 34 deletions.
3 changes: 0 additions & 3 deletions cmd/kubeadm/app/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,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
Expand Down
3 changes: 3 additions & 0 deletions cmd/kubeadm/app/constants/constants_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
3 changes: 3 additions & 0 deletions cmd/kubeadm/app/constants/constants_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
13 changes: 11 additions & 2 deletions cmd/kubeadm/app/images/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 0 additions & 5 deletions cmd/kubeadm/app/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,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{}
Expand Down
29 changes: 29 additions & 0 deletions cmd/kubeadm/app/images/images_unix.go
Original file line number Diff line number Diff line change
@@ -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)
}
34 changes: 34 additions & 0 deletions cmd/kubeadm/app/images/images_windows.go
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 2 additions & 0 deletions cmd/kubeadm/app/phases/kubelet/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
31 changes: 7 additions & 24 deletions cmd/kubeadm/app/phases/kubelet/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
51 changes: 51 additions & 0 deletions cmd/kubeadm/app/phases/kubelet/flags_unix.go
Original file line number Diff line number Diff line change
@@ -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
}
25 changes: 25 additions & 0 deletions cmd/kubeadm/app/phases/kubelet/flags_windows.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 5c5faed

Please sign in to comment.