Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes image repository flags when using CRI-O and containerd runtime #5447

Merged
merged 12 commits into from
Oct 2, 2019
11 changes: 5 additions & 6 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func runStart(cmd *cobra.Command, args []string) {
mRunner, preExists, machineAPI, host := startMachine(&config)
defer machineAPI.Close()
// configure the runtime (docker, containerd, crio)
cr := configureRuntimes(mRunner, driver)
cr := configureRuntimes(mRunner, driver, config.KubernetesConfig)
showVersionInfo(k8sVersion, cr)
waitCacheImages(&cacheGroup)

Expand Down Expand Up @@ -552,9 +552,8 @@ func selectImageRepository(mirrorCountry string, k8sVersion string) (bool, strin
}

checkRepository := func(repo string) error {
podInfraContainerImage, _ := images.CachedImages(repo, k8sVersion)

ref, err := name.ParseReference(podInfraContainerImage, name.WeakValidation)
pauseImage := images.PauseImage(repo, k8sVersion)
ref, err := name.ParseReference(pauseImage, name.WeakValidation)
if err != nil {
return err
}
Expand Down Expand Up @@ -993,8 +992,8 @@ func setupKubeAdm(mAPI libmachine.API, kc cfg.KubernetesConfig) bootstrapper.Boo
}

// configureRuntimes does what needs to happen to get a runtime going.
func configureRuntimes(runner cruntime.CommandRunner, driver string) cruntime.Manager {
config := cruntime.Config{Type: viper.GetString(containerRuntime), Runner: runner}
func configureRuntimes(runner cruntime.CommandRunner, driver string, k8s cfg.KubernetesConfig) cruntime.Manager {
config := cruntime.Config{Type: viper.GetString(containerRuntime), Runner: runner, ImageRepository: k8s.ImageRepository, KubernetesVersion: k8s.KubernetesVersion}
cr, err := cruntime.New(config)
if err != nil {
exit.WithError("Failed runtime", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/bootstrapper/bootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func GetCachedBinaryList(bootstrapper string) []string {
func GetCachedImageList(imageRepository string, version string, bootstrapper string) []string {
switch bootstrapper {
case BootstrapperTypeKubeadm:
_, images := images.CachedImages(imageRepository, version)
images := images.CachedImages(imageRepository, version)
return images
default:
return []string{}
Expand Down
66 changes: 53 additions & 13 deletions pkg/minikube/bootstrapper/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,35 @@ import (
minikubeVersion "k8s.io/minikube/pkg/version"
)

// CachedImages gets the images to cache for kubeadm for a version
func CachedImages(imageRepository string, kubernetesVersionStr string) (string, []string) {
minikubeRepository := imageRepository
// getImageRepositories returns either the k8s image registry on GCR or a mirror if specified
func getImageRepository(imageRepository string) string {
if imageRepository == "" {
imageRepository = "k8s.gcr.io"
minikubeRepository = "gcr.io/k8s-minikube"
}
if !strings.HasSuffix(imageRepository, "/") {
imageRepository += "/"
}

return imageRepository
}

func getMinikubeRepository(imageRepository string) string {
minikubeRepository := imageRepository
if minikubeRepository == "" {
minikubeRepository = "gcr.io/k8s-minikube"
}
if !strings.HasSuffix(minikubeRepository, "/") {
minikubeRepository += "/"
}

return minikubeRepository
}

// CachedImages gets the images to cache for kubeadm for a version
func CachedImages(imageRepository string, kubernetesVersionStr string) []string {
imageRepository = getImageRepository(imageRepository)
minikubeRepository := getMinikubeRepository(imageRepository)

v1_16plus := semver.MustParseRange(">=1.16.0")
v1_14plus := semver.MustParseRange(">=1.14.0 <1.16.0")
v1_13 := semver.MustParseRange(">=1.13.0 <1.14.0")
Expand Down Expand Up @@ -67,9 +83,8 @@ func CachedImages(imageRepository string, kubernetesVersionStr string) (string,
}...)
}

var podInfraContainerImage string
podInfraContainerImage := PauseImage(imageRepository, kubernetesVersionStr)
if v1_16plus(kubernetesVersion) {
podInfraContainerImage = imageRepository + "pause:3.1"
images = append(images, []string{
podInfraContainerImage,
imageRepository + "k8s-dns-kube-dns" + ArchTag(true) + "1.14.13",
Expand All @@ -80,7 +95,6 @@ func CachedImages(imageRepository string, kubernetesVersionStr string) (string,
}...)

} else if v1_14plus(kubernetesVersion) {
podInfraContainerImage = imageRepository + "pause:3.1"
images = append(images, []string{
podInfraContainerImage,
imageRepository + "k8s-dns-kube-dns" + ArchTag(true) + "1.14.13",
Expand All @@ -91,7 +105,6 @@ func CachedImages(imageRepository string, kubernetesVersionStr string) (string,
}...)

} else if v1_13(kubernetesVersion) {
podInfraContainerImage = imageRepository + "pause" + ArchTag(false) + "3.1"
images = append(images, []string{
podInfraContainerImage,
imageRepository + "k8s-dns-kube-dns" + ArchTag(true) + "1.14.8",
Expand All @@ -102,7 +115,6 @@ func CachedImages(imageRepository string, kubernetesVersionStr string) (string,
}...)

} else if v1_12(kubernetesVersion) {
podInfraContainerImage = imageRepository + "pause:3.1"
images = append(images, []string{
podInfraContainerImage,
imageRepository + "k8s-dns-kube-dns" + ArchTag(true) + "1.14.8",
Expand All @@ -113,7 +125,6 @@ func CachedImages(imageRepository string, kubernetesVersionStr string) (string,
}...)

} else if v1_11(kubernetesVersion) {
podInfraContainerImage = imageRepository + "pause" + ArchTag(false) + "3.1"
images = append(images, []string{
podInfraContainerImage,
imageRepository + "k8s-dns-kube-dns" + ArchTag(true) + "1.14.8",
Expand All @@ -122,8 +133,6 @@ func CachedImages(imageRepository string, kubernetesVersionStr string) (string,
imageRepository + "etcd" + ArchTag(true) + "3.2.18",
imageRepository + "coredns:1.1.3",
}...)
} else {
podInfraContainerImage = imageRepository + "pause" + ArchTag(false) + "3.0"
}

images = append(images, []string{
Expand All @@ -132,7 +141,38 @@ func CachedImages(imageRepository string, kubernetesVersionStr string) (string,
minikubeRepository + "storage-provisioner" + ArchTag(false) + "v1.8.1",
}...)

return podInfraContainerImage, images
return images
}

func PauseImage(imageRepository string, kubernetesVersionStr string) string {
imageRepository = getImageRepository(imageRepository)

v1_16plus := semver.MustParseRange(">=1.16.0")
v1_14plus := semver.MustParseRange(">=1.14.0 <1.16.0")
v1_13 := semver.MustParseRange(">=1.13.0 <1.14.0")
v1_12 := semver.MustParseRange(">=1.12.0 <1.13.0")
v1_11 := semver.MustParseRange(">=1.11.0 <1.12.0")

kubernetesVersion, err := semver.Make(strings.TrimPrefix(kubernetesVersionStr, minikubeVersion.VersionPrefix))
if err != nil {
glog.Errorln("Error parsing version semver: ", err)
}

var podInfraContainerImage string
if v1_16plus(kubernetesVersion) {
laozc marked this conversation as resolved.
Show resolved Hide resolved
podInfraContainerImage = imageRepository + "pause:3.1"
} else if v1_14plus(kubernetesVersion) {
podInfraContainerImage = imageRepository + "pause:3.1"
} else if v1_13(kubernetesVersion) {
podInfraContainerImage = imageRepository + "pause" + ArchTag(false) + "3.1"
} else if v1_12(kubernetesVersion) {
podInfraContainerImage = imageRepository + "pause:3.1"
} else if v1_11(kubernetesVersion) {
podInfraContainerImage = imageRepository + "pause" + ArchTag(false) + "3.1"
} else {
podInfraContainerImage = imageRepository + "pause" + ArchTag(false) + "3.0"
}
return podInfraContainerImage
}

// ArchTag returns the archtag for images
Expand Down
8 changes: 4 additions & 4 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,9 @@ func NewKubeletConfig(k8s config.KubernetesConfig, r cruntime.Manager) ([]byte,
extraOpts["node-ip"] = k8s.NodeIP
}

podInfraContainerImage, _ := images.CachedImages(k8s.ImageRepository, k8s.KubernetesVersion)
if _, ok := extraOpts["pod-infra-container-image"]; !ok && k8s.ImageRepository != "" && podInfraContainerImage != "" {
extraOpts["pod-infra-container-image"] = podInfraContainerImage
pauseImage := images.PauseImage(k8s.ImageRepository, k8s.KubernetesVersion)
if _, ok := extraOpts["pod-infra-container-image"]; !ok && k8s.ImageRepository != "" && pauseImage != "" && k8s.ContainerRuntime != constants.RemoteContainerRuntime {
extraOpts["pod-infra-container-image"] = pauseImage
}

// parses a map of the feature gates for kubelet
Expand Down Expand Up @@ -586,7 +586,7 @@ func NewKubeletConfig(k8s config.KubernetesConfig, r cruntime.Manager) ([]byte,

// UpdateCluster updates the cluster
func (k *Bootstrapper) UpdateCluster(cfg config.KubernetesConfig) error {
_, images := images.CachedImages(cfg.ImageRepository, cfg.KubernetesVersion)
images := images.CachedImages(cfg.ImageRepository, cfg.KubernetesVersion)
if cfg.ShouldLoadCachedImages {
if err := machine.LoadImages(k.c, images, constants.ImageCacheDir); err != nil {
out.FailureT("Unable to load cached images: {{.error}}", out.V{"error": err})
Expand Down
10 changes: 10 additions & 0 deletions pkg/minikube/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ const (
KubeletSystemdConfFile = "/etc/systemd/system/kubelet.service.d/10-kubeadm.conf"
// DefaultCNIConfigPath is the path to the CNI configuration
DefaultCNIConfigPath = "/etc/cni/net.d/k8s.conf"
// CRIOConfFile is the path to the CRI-O configuration
CRIOConfFile = "/etc/crio/crio.conf"
// ContainerdConfFile is the path to the containerd configuration
ContainerdConfFile = "/etc/containerd/config.toml"

// GuestAddonsDir is the default path of the addons configuration
GuestAddonsDir = "/etc/kubernetes/addons"
Expand Down Expand Up @@ -216,3 +220,9 @@ const (
// GvisorURL is the url to download gvisor
GvisorURL = "https://storage.googleapis.com/gvisor/releases/nightly/2019-01-14/runsc"
)

const (
// Container runtimes
DockerContainerRuntime = "docker"
RemoteContainerRuntime = "remote"
)
102 changes: 100 additions & 2 deletions pkg/minikube/cruntime/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,96 @@ limitations under the License.
package cruntime

import (
"bytes"
"encoding/base64"
"fmt"
"path"
"strings"
"text/template"

"github.com/golang/glog"
"k8s.io/minikube/pkg/minikube/bootstrapper/images"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/out"
)

const containerdConfigTemplate = `root = "/var/lib/containerd"
state = "/run/containerd"
oom_score = 0

[grpc]
address = "/run/containerd/containerd.sock"
uid = 0
gid = 0
max_recv_message_size = 16777216
max_send_message_size = 16777216

[debug]
address = ""
uid = 0
gid = 0
level = ""

[metrics]
address = ""
grpc_histogram = false

[cgroup]
path = ""

[plugins]
[plugins.cgroups]
no_prometheus = false
[plugins.cri]
stream_server_address = ""
stream_server_port = "10010"
enable_selinux = false
sandbox_image = "{{ .PodInfraContainerImage }}"
stats_collect_period = 10
systemd_cgroup = false
enable_tls_streaming = false
max_container_log_line_size = 16384
[plugins.cri.containerd]
snapshotter = "overlayfs"
no_pivot = true
[plugins.cri.containerd.default_runtime]
runtime_type = "io.containerd.runtime.v1.linux"
runtime_engine = ""
runtime_root = ""
[plugins.cri.containerd.untrusted_workload_runtime]
runtime_type = ""
runtime_engine = ""
runtime_root = ""
[plugins.cri.cni]
bin_dir = "/opt/cni/bin"
conf_dir = "/etc/cni/net.d"
conf_template = ""
[plugins.cri.registry]
[plugins.cri.registry.mirrors]
[plugins.cri.registry.mirrors."docker.io"]
endpoint = ["https://registry-1.docker.io"]
[plugins.diff-service]
default = ["walking"]
[plugins.linux]
shim = "containerd-shim"
runtime = "runc"
runtime_root = ""
no_shim = false
shim_debug = false
[plugins.scheduler]
pause_threshold = 0.02
deletion_threshold = 0
mutation_threshold = 100
schedule_delay = "0s"
startup_delay = "100ms"
`

// Containerd contains containerd runtime state
type Containerd struct {
Socket string
Runner CommandRunner
Socket string
Runner CommandRunner
ImageRepository string
KubernetesVersion string
}

// Name is a human readable name for containerd
Expand Down Expand Up @@ -79,6 +158,22 @@ func (r *Containerd) Available() error {
return r.Runner.Run("command -v containerd")
}

// generateContainerdConfig sets up /etc/containerd/config.toml
func generateContainerdConfig(cr CommandRunner, imageRepository string, k8sVersion string) error {
cPath := constants.ContainerdConfFile
t, err := template.New("containerd.config.toml").Parse(containerdConfigTemplate)
if err != nil {
return err
}
pauseImage := images.PauseImage(imageRepository, k8sVersion)
opts := struct{ PodInfraContainerImage string }{PodInfraContainerImage: pauseImage}
var b bytes.Buffer
if err := t.Execute(&b, opts); err != nil {
return err
}
return cr.Run(fmt.Sprintf("sudo mkdir -p %s && printf %%s \"%s\" | base64 -d | sudo tee %s", path.Dir(cPath), base64.StdEncoding.EncodeToString(b.Bytes()), cPath))
}

// Enable idempotently enables containerd on a host
func (r *Containerd) Enable(disOthers bool) error {
if disOthers {
Expand All @@ -89,6 +184,9 @@ func (r *Containerd) Enable(disOthers bool) error {
if err := populateCRIConfig(r.Runner, r.SocketPath()); err != nil {
return err
}
if err := generateContainerdConfig(r.Runner, r.ImageRepository, r.KubernetesVersion); err != nil {
return err
}
if err := enableIPForwarding(r.Runner); err != nil {
return err
}
Expand Down
Loading